INSTRUCTION stringlengths 1 46.3k | RESPONSE stringlengths 75 80.2k |
|---|---|
Return server version (``apachectl -v``)
CLI Example:
.. code-block:: bash
salt '*' apache.version | def version():
'''
Return server version (``apachectl -v``)
CLI Example:
.. code-block:: bash
salt '*' apache.version
'''
cmd = '{0} -v'.format(_detect_os())
out = __salt__['cmd.run'](cmd).splitlines()
ret = out[0].split(': ')
return ret[1] |
Get the path to the directory on the minion where CIB's are saved | def _get_cibpath():
'''
Get the path to the directory on the minion where CIB's are saved
'''
cibpath = os.path.join(__opts__['cachedir'], 'pcs', __env__)
log.trace('cibpath: %s', cibpath)
return cibpath |
Return list of modules compiled into the server (``apachectl -l``)
CLI Example:
.. code-block:: bash
salt '*' apache.servermods | def servermods():
'''
Return list of modules compiled into the server (``apachectl -l``)
CLI Example:
.. code-block:: bash
salt '*' apache.servermods
'''
cmd = '{0} -l'.format(_detect_os())
ret = []
out = __salt__['cmd.run'](cmd).splitlines()
for line in out:
if no... |
this presenter magic makes yaml.safe_dump
work with the objects returned from
boto.describe_alarms() | def _safe_dump(data):
'''
this presenter magic makes yaml.safe_dump
work with the objects returned from
boto.describe_alarms()
'''
custom_dumper = __utils__['yaml.get_dumper']('SafeOrderedDumper')
def boto_listelement_presenter(dumper, data):
return dumper.represent_list(list(data))... |
Return cloud client | def _get_client():
'''
Return cloud client
'''
client = salt.cloud.CloudClient(
os.path.join(os.path.dirname(__opts__['conf_file']), 'cloud')
)
return client |
Make sure that a gem source is added.
name
The URL of the gem source to be added
ruby: None
For RVM or rbenv installations: the ruby version and gemset to target.
user: None
The user under which to run the ``gem`` command
.. versionadded:: 0.17.0 | def sources_add(name, ruby=None, user=None):
'''
Make sure that a gem source is added.
name
The URL of the gem source to be added
ruby: None
For RVM or rbenv installations: the ruby version and gemset to target.
user: None
The user under which to run the ``gem`` command
... |
Return list of directives together with expected arguments
and places where the directive is valid (``apachectl -L``)
CLI Example:
.. code-block:: bash
salt '*' apache.directives | def directives():
'''
Return list of directives together with expected arguments
and places where the directive is valid (``apachectl -L``)
CLI Example:
.. code-block:: bash
salt '*' apache.directives
'''
cmd = '{0} -L'.format(_detect_os())
ret = {}
out = __salt__['cmd.run... |
.. versionadded:: 2014.7.0
Verify the set exists.
name
A user-defined set name.
set_type
The type for the set.
family
Networking family, either ipv4 or ipv6 | def set_present(name, set_type, family='ipv4', **kwargs):
'''
.. versionadded:: 2014.7.0
Verify the set exists.
name
A user-defined set name.
set_type
The type for the set.
family
Networking family, either ipv4 or ipv6
'''
ret = {'name': name,
'cha... |
Convert a list of strings into actual arns. Converts convenience names such
as 'scaling_policy:...'
CLI Example::
salt '*' convert_to_arn 'scaling_policy:' | def convert_to_arn(arns, region=None, key=None, keyid=None, profile=None):
'''
Convert a list of strings into actual arns. Converts convenience names such
as 'scaling_policy:...'
CLI Example::
salt '*' convert_to_arn 'scaling_policy:'
'''
results = []
for arn in arns:
if ar... |
Show the settings as parsed from the config file (currently
only shows the virtualhost settings) (``apachectl -S``).
Because each additional virtual host adds to the execution
time, this command may require a long timeout be specified
by using ``-t 10``.
CLI Example:
.. code-block:: bash
... | def vhosts():
'''
Show the settings as parsed from the config file (currently
only shows the virtualhost settings) (``apachectl -S``).
Because each additional virtual host adds to the execution
time, this command may require a long timeout be specified
by using ``-t 10``.
CLI Example:
... |
Signals httpd to start, restart, or stop.
CLI Example:
.. code-block:: bash
salt '*' apache.signal restart | def signal(signal=None):
'''
Signals httpd to start, restart, or stop.
CLI Example:
.. code-block:: bash
salt '*' apache.signal restart
'''
no_extra_args = ('configtest', 'status', 'fullstatus')
valid_signals = ('start', 'stop', 'restart', 'graceful', 'graceful-stop')
if sign... |
Add HTTP user using the ``htpasswd`` command. If the ``htpasswd`` file does not
exist, it will be created. Valid options that can be passed are:
.. code-block:: text
n Don't update file; display results on stdout.
m Force MD5 hashing of the password (default).
d Force CRYPT(3) hashi... | def useradd(pwfile, user, password, opts=''):
'''
Add HTTP user using the ``htpasswd`` command. If the ``htpasswd`` file does not
exist, it will be created. Valid options that can be passed are:
.. code-block:: text
n Don't update file; display results on stdout.
m Force MD5 hashing ... |
Get Information from the Apache server-status handler
.. note::
The server-status handler is disabled by default.
In order for this function to work it needs to be enabled.
See http://httpd.apache.org/docs/2.2/mod/mod_status.html
The following configuration needs to exists in pillar/g... | def server_status(profile='default'):
'''
Get Information from the Apache server-status handler
.. note::
The server-status handler is disabled by default.
In order for this function to work it needs to be enabled.
See http://httpd.apache.org/docs/2.2/mod/mod_status.html
The f... |
Recursively goes through config structure and builds final Apache configuration
:param conf: defined config structure
:param slot: name of section container if needed | def _parse_config(conf, slot=None):
'''
Recursively goes through config structure and builds final Apache configuration
:param conf: defined config structure
:param slot: name of section container if needed
'''
ret = cStringIO()
if isinstance(conf, six.string_types):
if slot:
... |
Create VirtualHost configuration files
name
File for the virtual host
config
VirtualHost configurations
.. note::
This function is not meant to be used from the command line.
Config is meant to be an ordered dict of all of the apache configs.
CLI Example:
.. code... | def config(name, config, edit=True):
'''
Create VirtualHost configuration files
name
File for the virtual host
config
VirtualHost configurations
.. note::
This function is not meant to be used from the command line.
Config is meant to be an ordered dict of all of t... |
Ensure the SQS queue exists.
name
Name of the SQS queue.
attributes
A dict of key/value SQS attributes.
region
Region to connect to.
key
Secret key to be used.
keyid
Access key to be used.
profile
A dict with region, key and keyid, or a pilla... | def present(
name,
attributes=None,
region=None,
key=None,
keyid=None,
profile=None,
):
'''
Ensure the SQS queue exists.
name
Name of the SQS queue.
attributes
A dict of key/value SQS attributes.
region
Region to connect to.
... |
Ensure the named sqs queue is deleted.
name
Name of the SQS queue.
region
Region to connect to.
key
Secret key to be used.
keyid
Access key to be used.
profile
A dict with region, key and keyid, or a pillar key (string)
that contains a dict with r... | def absent(
name,
region=None,
key=None,
keyid=None,
profile=None,
):
'''
Ensure the named sqs queue is deleted.
name
Name of the SQS queue.
region
Region to connect to.
key
Secret key to be used.
keyid
Access key to be ... |
Determine if the groups need to be changed | def _group_changes(cur, wanted, remove=False):
'''
Determine if the groups need to be changed
'''
old = set(cur)
new = set(wanted)
if (remove and old != new) or (not remove and not new.issubset(old)):
return True
return False |
Return a dict of the changes required for a user if the user is present,
otherwise return False.
Updated in 2015.8.0 to include support for windows homedrive, profile,
logonscript, and description fields.
Updated in 2014.7.0 to include support for shadow attributes, all
attributes supported as int... | def _changes(name,
uid=None,
gid=None,
groups=None,
optional_groups=None,
remove_groups=True,
home=None,
createhome=True,
password=None,
enforce_password=True,
empty_password=False,
... |
Ensure that the named user is present with the specified properties
name
The name of the user to manage
uid
The user id to assign. If not specified, and the user does not exist,
then the next available uid will be assigned.
gid
The id of the default group to assign to the ... | def present(name,
uid=None,
gid=None,
usergroup=None,
groups=None,
optional_groups=None,
remove_groups=True,
home=None,
createhome=True,
password=None,
hash_password=False,
enforce_passwor... |
Ensure that the named user is absent
name
The name of the user to remove
purge
Set purge to True to delete all of the user's files as well as the user,
Default is ``False``.
force
If the user is logged in, the absent state will fail. Set the force
option to True to... | def absent(name, purge=False, force=False):
'''
Ensure that the named user is absent
name
The name of the user to remove
purge
Set purge to True to delete all of the user's files as well as the user,
Default is ``False``.
force
If the user is logged in, the absent ... |
Parse a salt:// URL; return the path and a possible saltenv query. | def parse(url):
'''
Parse a salt:// URL; return the path and a possible saltenv query.
'''
if not url.startswith('salt://'):
return url, None
# urlparse will split on valid filename chars such as '?' and '&'
resource = url.split('salt://', 1)[-1]
if '?env=' in resource:
# "... |
join `path` and `saltenv` into a 'salt://' URL. | def create(path, saltenv=None):
'''
join `path` and `saltenv` into a 'salt://' URL.
'''
if salt.utils.platform.is_windows():
path = salt.utils.path.sanitize_win_path(path)
path = salt.utils.data.decode(path)
query = 'saltenv={0}'.format(saltenv) if saltenv else ''
url = salt.utils.d... |
test whether `url` is escaped with `|` | def is_escaped(url):
'''
test whether `url` is escaped with `|`
'''
scheme = urlparse(url).scheme
if not scheme:
return url.startswith('|')
elif scheme == 'salt':
path, saltenv = parse(url)
if salt.utils.platform.is_windows() and '|' in url:
return path.starts... |
add escape character `|` to `url` | def escape(url):
'''
add escape character `|` to `url`
'''
if salt.utils.platform.is_windows():
return url
scheme = urlparse(url).scheme
if not scheme:
if url.startswith('|'):
return url
else:
return '|{0}'.format(url)
elif scheme == 'salt':
... |
remove escape character `|` from `url` | def unescape(url):
'''
remove escape character `|` from `url`
'''
scheme = urlparse(url).scheme
if not scheme:
return url.lstrip('|')
elif scheme == 'salt':
path, saltenv = parse(url)
if salt.utils.platform.is_windows() and '|' in url:
return create(path.lstri... |
append `saltenv` to `url` as a query parameter to a 'salt://' url | def add_env(url, saltenv):
'''
append `saltenv` to `url` as a query parameter to a 'salt://' url
'''
if not url.startswith('salt://'):
return url
path, senv = parse(url)
return create(path, saltenv) |
remove the saltenv query parameter from a 'salt://' url | def split_env(url):
'''
remove the saltenv query parameter from a 'salt://' url
'''
if not url.startswith('salt://'):
return url, None
path, senv = parse(url)
return create(path), senv |
Return a string with http basic auth incorporated into it | def add_http_basic_auth(url,
user=None,
password=None,
https_only=False):
'''
Return a string with http basic auth incorporated into it
'''
if user is None and password is None:
return url
else:
urltuple = urlpar... |
Remove HTTP user and password | def redact_http_basic_auth(output):
'''
Remove HTTP user and password
'''
# We can't use re.compile because re.compile(someregex).sub() doesn't
# support flags even in Python 2.7.
url_re = '(https?)://.*@'
redacted = r'\1://<redacted>@'
if sys.version_info >= (2, 7):
# re.sub() s... |
Resolve a package name from a line containing the hold expression. If the
regex is not matched, None is returned.
yum ==> 2:vim-enhanced-7.4.629-5.el6.*
dnf ==> vim-enhanced-2:7.4.827-1.fc22.* | def _get_hold(line, pattern=__HOLD_PATTERN, full=True):
'''
Resolve a package name from a line containing the hold expression. If the
regex is not matched, None is returned.
yum ==> 2:vim-enhanced-7.4.629-5.el6.*
dnf ==> vim-enhanced-2:7.4.827-1.fc22.*
'''
if full:
if _yum() == 'dnf... |
Determine package manager name (yum or dnf),
depending on the system version. | def _yum():
'''
Determine package manager name (yum or dnf),
depending on the system version.
'''
contextkey = 'yum_bin'
if contextkey not in __context__:
if ('fedora' in __grains__['os'].lower()
and int(__grains__['osrelease']) >= 22):
__context__[contextkey] = 'd... |
Call yum/dnf. | def _call_yum(args, **kwargs):
'''
Call yum/dnf.
'''
params = {'output_loglevel': 'trace',
'python_shell': False,
'env': salt.utils.environment.get_module_environment(globals())}
params.update(kwargs)
cmd = []
if salt.utils.systemd.has_scope(__context__) and __sal... |
Parse yum/dnf output (which could contain irregular line breaks if package
names are long) retrieving the name, version, etc., and return a list of
pkginfo namedtuples. | def _yum_pkginfo(output):
'''
Parse yum/dnf output (which could contain irregular line breaks if package
names are long) retrieving the name, version, etc., and return a list of
pkginfo namedtuples.
'''
cur = {}
keys = itertools.cycle(('name', 'version', 'repoid'))
values = salt.utils.it... |
Ensure that the appropriate versionlock plugin is present | def _check_versionlock():
'''
Ensure that the appropriate versionlock plugin is present
'''
if _yum() == 'dnf':
if int(__grains__.get('osmajorrelease')) >= 26:
if six.PY3:
vl_plugin = 'python3-dnf-plugin-versionlock'
else:
vl_plugin = 'pyth... |
Returns a list of options to be used in the yum/dnf command, based on the
kwargs passed. | def _get_options(**kwargs):
'''
Returns a list of options to be used in the yum/dnf command, based on the
kwargs passed.
'''
# Get repo options from the kwargs
fromrepo = kwargs.pop('fromrepo', '')
repo = kwargs.pop('repo', '')
disablerepo = kwargs.pop('disablerepo', '')
enablerepo =... |
Returns a dict representing the yum config options and values.
We try to pull all of the yum config options into a standard dict object.
This is currently only used to get the reposdir settings, but could be used
for other things if needed.
If the yum python library is available, use that, which will ... | def _get_yum_config():
'''
Returns a dict representing the yum config options and values.
We try to pull all of the yum config options into a standard dict object.
This is currently only used to get the reposdir settings, but could be used
for other things if needed.
If the yum python library ... |
Look for a specific config variable and return its value | def _get_yum_config_value(name):
'''
Look for a specific config variable and return its value
'''
conf = _get_yum_config()
if name in conf.keys():
return conf.get(name)
return None |
Takes a basedir argument as a string or a list. If the string or list is
empty, then look up the default from the 'reposdir' option in the yum
config.
Returns a list of directories. | def _normalize_basedir(basedir=None):
'''
Takes a basedir argument as a string or a list. If the string or list is
empty, then look up the default from the 'reposdir' option in the yum
config.
Returns a list of directories.
'''
# if we are passed a string (for backward compatibility), conve... |
Strips the architecture from the specified package name, if necessary.
Circumstances where this would be done include:
* If the arch is 32 bit and the package name ends in a 32-bit arch.
* If the arch matches the OS arch, or is ``noarch``.
CLI Example:
.. code-block:: bash
salt '*' pkg.n... | def normalize_name(name):
'''
Strips the architecture from the specified package name, if necessary.
Circumstances where this would be done include:
* If the arch is 32 bit and the package name ends in a 32-bit arch.
* If the arch matches the OS arch, or is ``noarch``.
CLI Example:
.. cod... |
.. versionadded:: 2015.5.4
Do a cmp-style comparison on two packages. Return -1 if pkg1 < pkg2, 0 if
pkg1 == pkg2, and 1 if pkg1 > pkg2. Return None if there was a problem
making the comparison.
ignore_epoch : False
Set to ``True`` to ignore the epoch when comparing versions
.. versio... | def version_cmp(pkg1, pkg2, ignore_epoch=False, **kwargs):
'''
.. versionadded:: 2015.5.4
Do a cmp-style comparison on two packages. Return -1 if pkg1 < pkg2, 0 if
pkg1 == pkg2, and 1 if pkg1 > pkg2. Return None if there was a problem
making the comparison.
ignore_epoch : False
Set to ... |
.. versionadded:: 2014.1.0
.. versionchanged:: 2014.7.0
All available versions of each package are now returned. This required
a slight modification to the structure of the return dict. The return
data shown below reflects the updated return dict structure. Note that
packages which a... | def list_repo_pkgs(*args, **kwargs):
'''
.. versionadded:: 2014.1.0
.. versionchanged:: 2014.7.0
All available versions of each package are now returned. This required
a slight modification to the structure of the return dict. The return
data shown below reflects the updated return d... |
Check whether or not an upgrade is available for all packages
The ``fromrepo``, ``enablerepo``, and ``disablerepo`` arguments are
supported, as used in pkg states, and the ``disableexcludes`` option is
also supported.
.. versionadded:: 2014.7.0
Support for the ``disableexcludes`` option
C... | def list_upgrades(refresh=True, **kwargs):
'''
Check whether or not an upgrade is available for all packages
The ``fromrepo``, ``enablerepo``, and ``disablerepo`` arguments are
supported, as used in pkg states, and the ``disableexcludes`` option is
also supported.
.. versionadded:: 2014.7.0
... |
.. versionadded:: 2017.7.0
List prefetched packages downloaded by Yum in the local disk.
CLI example:
.. code-block:: bash
salt '*' pkg.list_downloaded | def list_downloaded(**kwargs):
'''
.. versionadded:: 2017.7.0
List prefetched packages downloaded by Yum in the local disk.
CLI example:
.. code-block:: bash
salt '*' pkg.list_downloaded
'''
CACHE_DIR = os.path.join('/var/cache/', _yum())
ret = {}
for root, dirnames, fil... |
.. versionadded:: 2015.8.1
Return the information of the named package(s), installed on the system.
:param all_versions:
Include information for all versions of the packages installed on the minion.
CLI example:
.. code-block:: bash
salt '*' pkg.info_installed <package1>
sal... | def info_installed(*names, **kwargs):
'''
.. versionadded:: 2015.8.1
Return the information of the named package(s), installed on the system.
:param all_versions:
Include information for all versions of the packages installed on the minion.
CLI example:
.. code-block:: bash
... |
Check the yum repos for updated packages
Returns:
- ``True``: Updates are available
- ``False``: An error occurred
- ``None``: No updates are available
repo
Refresh just the specified repo
disablerepo
Do not refresh the specified repo
enablerepo
Refresh a disable... | def refresh_db(**kwargs):
'''
Check the yum repos for updated packages
Returns:
- ``True``: Updates are available
- ``False``: An error occurred
- ``None``: No updates are available
repo
Refresh just the specified repo
disablerepo
Do not refresh the specified repo
... |
.. versionchanged:: 2015.8.12,2016.3.3,2016.11.0
On minions running systemd>=205, `systemd-run(1)`_ is now used to
isolate commands which modify installed packages from the
``salt-minion`` daemon's control group. This is done to keep systemd
from killing any yum/dnf commands spawned by S... | def install(name=None,
refresh=False,
skip_verify=False,
pkgs=None,
sources=None,
downloadonly=False,
reinstall=False,
normalize=True,
update_holds=False,
saltenv='base',
ignore_epoch=False,
... |
Run a full system upgrade (a ``yum upgrade`` or ``dnf upgrade``), or
upgrade specified packages. If the packages aren't installed, they will
not be installed.
.. versionchanged:: 2014.7.0
.. versionchanged:: 2015.8.12,2016.3.3,2016.11.0
On minions running systemd>=205, `systemd-run(1)`_ is now ... | def upgrade(name=None,
pkgs=None,
refresh=True,
skip_verify=False,
normalize=True,
minimal=False,
obsoletes=True,
**kwargs):
'''
Run a full system upgrade (a ``yum upgrade`` or ``dnf upgrade``), or
upgrade specified packages... |
.. versionadded:: 2019.2.0
Calls :py:func:`pkg.upgrade <salt.modules.yumpkg.upgrade>` with
``obsoletes=False``. Mirrors the CLI behavior of ``yum update``.
See :py:func:`pkg.upgrade <salt.modules.yumpkg.upgrade>` for
further documentation.
.. code-block:: bash
salt '*' pkg.update | def update(name=None,
pkgs=None,
refresh=True,
skip_verify=False,
normalize=True,
minimal=False,
obsoletes=False,
**kwargs):
'''
.. versionadded:: 2019.2.0
Calls :py:func:`pkg.upgrade <salt.modules.yumpkg.upgrade>` with
``obso... |
.. versionchanged:: 2015.8.12,2016.3.3,2016.11.0
On minions running systemd>=205, `systemd-run(1)`_ is now used to
isolate commands which modify installed packages from the
``salt-minion`` daemon's control group. This is done to keep systemd
from killing any yum/dnf commands spawned by S... | def remove(name=None, pkgs=None, **kwargs): # pylint: disable=W0613
'''
.. versionchanged:: 2015.8.12,2016.3.3,2016.11.0
On minions running systemd>=205, `systemd-run(1)`_ is now used to
isolate commands which modify installed packages from the
``salt-minion`` daemon's control group. Th... |
.. versionadded:: 2014.7.0
Version-lock packages
.. note::
Requires the appropriate ``versionlock`` plugin package to be installed:
- On RHEL 5: ``yum-versionlock``
- On RHEL 6 & 7: ``yum-plugin-versionlock``
- On Fedora: ``python-dnf-plugins-extras-versionlock``
name
... | def hold(name=None, pkgs=None, sources=None, normalize=True, **kwargs): # pylint: disable=W0613
'''
.. versionadded:: 2014.7.0
Version-lock packages
.. note::
Requires the appropriate ``versionlock`` plugin package to be installed:
- On RHEL 5: ``yum-versionlock``
- On RHEL 6... |
.. versionadded:: 2014.7.0
Remove version locks
.. note::
Requires the appropriate ``versionlock`` plugin package to be installed:
- On RHEL 5: ``yum-versionlock``
- On RHEL 6 & 7: ``yum-plugin-versionlock``
- On Fedora: ``python-dnf-plugins-extras-versionlock``
name
... | def unhold(name=None, pkgs=None, sources=None, **kwargs): # pylint: disable=W0613
'''
.. versionadded:: 2014.7.0
Remove version locks
.. note::
Requires the appropriate ``versionlock`` plugin package to be installed:
- On RHEL 5: ``yum-versionlock``
- On RHEL 6 & 7: ``yum-plu... |
r'''
.. versionchanged:: 2016.3.0,2015.8.4,2015.5.10
Function renamed from ``pkg.get_locked_pkgs`` to ``pkg.list_holds``.
List information on locked packages
.. note::
Requires the appropriate ``versionlock`` plugin package to be installed:
- On RHEL 5: ``yum-versionlock``
... | def list_holds(pattern=__HOLD_PATTERN, full=True):
r'''
.. versionchanged:: 2016.3.0,2015.8.4,2015.5.10
Function renamed from ``pkg.get_locked_pkgs`` to ``pkg.list_holds``.
List information on locked packages
.. note::
Requires the appropriate ``versionlock`` plugin package to be insta... |
.. versionadded:: 2014.1.0
Lists all groups known by yum on this system
CLI Example:
.. code-block:: bash
salt '*' pkg.group_list | def group_list():
'''
.. versionadded:: 2014.1.0
Lists all groups known by yum on this system
CLI Example:
.. code-block:: bash
salt '*' pkg.group_list
'''
ret = {'installed': [],
'available': [],
'installed environments': [],
'available environme... |
.. versionadded:: 2014.1.0
.. versionchanged:: 2016.3.0,2015.8.4,2015.5.10
The return data has changed. A new key ``type`` has been added to
distinguish environment groups from package groups. Also, keys for the
group name and group ID have been added. The ``mandatory packages``,
``o... | def group_info(name, expand=False):
'''
.. versionadded:: 2014.1.0
.. versionchanged:: 2016.3.0,2015.8.4,2015.5.10
The return data has changed. A new key ``type`` has been added to
distinguish environment groups from package groups. Also, keys for the
group name and group ID have bee... |
.. versionadded:: 2014.1.0
.. versionchanged:: 2016.3.0,2015.8.4,2015.5.10
Environment groups are now supported. The key names have been renamed,
similar to the changes made in :py:func:`pkg.group_info
<salt.modules.yumpkg.group_info>`.
Lists which of a group's packages are installed an... | def group_diff(name):
'''
.. versionadded:: 2014.1.0
.. versionchanged:: 2016.3.0,2015.8.4,2015.5.10
Environment groups are now supported. The key names have been renamed,
similar to the changes made in :py:func:`pkg.group_info
<salt.modules.yumpkg.group_info>`.
Lists which of a... |
Lists all repos in <basedir> (default: all dirs in `reposdir` yum option).
CLI Example:
.. code-block:: bash
salt '*' pkg.list_repos
salt '*' pkg.list_repos basedir=/path/to/dir
salt '*' pkg.list_repos basedir=/path/to/dir,/path/to/another/dir | def list_repos(basedir=None, **kwargs):
'''
Lists all repos in <basedir> (default: all dirs in `reposdir` yum option).
CLI Example:
.. code-block:: bash
salt '*' pkg.list_repos
salt '*' pkg.list_repos basedir=/path/to/dir
salt '*' pkg.list_repos basedir=/path/to/dir,/path/to/a... |
.. versionadded:: 2014.1.0
Install the passed package group(s). This is basically a wrapper around
:py:func:`pkg.install <salt.modules.yumpkg.install>`, which performs
package group resolution for the user. This function is currently
considered experimental, and should be expected to undergo changes.
... | def group_install(name,
skip=(),
include=(),
**kwargs):
'''
.. versionadded:: 2014.1.0
Install the passed package group(s). This is basically a wrapper around
:py:func:`pkg.install <salt.modules.yumpkg.install>`, which performs
package group res... |
Display a repo from <basedir> (default basedir: all dirs in ``reposdir``
yum option).
CLI Examples:
.. code-block:: bash
salt '*' pkg.get_repo myrepo
salt '*' pkg.get_repo myrepo basedir=/path/to/dir
salt '*' pkg.get_repo myrepo basedir=/path/to/dir,/path/to/another/dir | def get_repo(name, basedir=None, **kwargs): # pylint: disable=W0613
'''
Display a repo from <basedir> (default basedir: all dirs in ``reposdir``
yum option).
CLI Examples:
.. code-block:: bash
salt '*' pkg.get_repo myrepo
salt '*' pkg.get_repo myrepo basedir=/path/to/dir
... |
Delete a repo from <basedir> (default basedir: all dirs in `reposdir` yum
option).
If the .repo file in which the repo exists does not contain any other repo
configuration, the file itself will be deleted.
CLI Examples:
.. code-block:: bash
salt '*' pkg.del_repo myrepo
salt '*' p... | def del_repo(repo, basedir=None, **kwargs): # pylint: disable=W0613
'''
Delete a repo from <basedir> (default basedir: all dirs in `reposdir` yum
option).
If the .repo file in which the repo exists does not contain any other repo
configuration, the file itself will be deleted.
CLI Examples:
... |
Modify one or more values for a repo. If the repo does not exist, it will
be created, so long as the following values are specified:
repo
name by which the yum refers to the repo
name
a human-readable name for the repo
baseurl
the URL for yum to reference
mirrorlist
... | def mod_repo(repo, basedir=None, **kwargs):
'''
Modify one or more values for a repo. If the repo does not exist, it will
be created, so long as the following values are specified:
repo
name by which the yum refers to the repo
name
a human-readable name for the repo
baseurl
... |
Turn a single repo file into a dict | def _parse_repo_file(filename):
'''
Turn a single repo file into a dict
'''
parsed = configparser.ConfigParser()
config = {}
try:
parsed.read(filename)
except configparser.MissingSectionHeaderError as err:
log.error(
'Failed to parse file %s, error: %s',
... |
.. versionadded:: 2014.7.0
Return the name of the package that owns the file. Multiple file paths can
be passed. Like :mod:`pkg.version <salt.modules.yumpkg.version>`, if a
single path is passed, a string will be returned, and if multiple paths are
passed, a dictionary of file/package name pairs will b... | def owner(*paths, **kwargs):
'''
.. versionadded:: 2014.7.0
Return the name of the package that owns the file. Multiple file paths can
be passed. Like :mod:`pkg.version <salt.modules.yumpkg.version>`, if a
single path is passed, a string will be returned, and if multiple paths are
passed, a dic... |
Return a formatted diff between current files and original in a package.
NOTE: this function includes all files (configuration and not), but does
not work on binary content.
:param path: Full path to the installed file
:return: Difference string or raises and exception if examined file is binary.
... | def diff(*paths, **kwargs):
'''
Return a formatted diff between current files and original in a package.
NOTE: this function includes all files (configuration and not), but does
not work on binary content.
:param path: Full path to the installed file
:return: Difference string or raises and exc... |
.. versionadded:: 2015.5.0
Download packages to the local disk. Requires ``yumdownloader`` from
``yum-utils`` package.
.. note::
``yum-utils`` will already be installed on the minion if the package
was installed from the Fedora / EPEL repositories.
CLI example:
.. code-block:: b... | def download(*packages, **kwargs):
'''
.. versionadded:: 2015.5.0
Download packages to the local disk. Requires ``yumdownloader`` from
``yum-utils`` package.
.. note::
``yum-utils`` will already be installed on the minion if the package
was installed from the Fedora / EPEL reposit... |
.. versionadded:: Fluorine
Execute ``yum-complete-transaction``, which is provided by the ``yum-utils`` package.
cleanup_only
Specify if the ``--cleanup-only`` option should be supplied.
recursive
Specify if ``yum-complete-transaction`` should be called recursively
(it only comple... | def complete_transaction(cleanup_only=False, recursive=False, max_attempts=3):
'''
.. versionadded:: Fluorine
Execute ``yum-complete-transaction``, which is provided by the ``yum-utils`` package.
cleanup_only
Specify if the ``--cleanup-only`` option should be supplied.
recursive
S... |
List all known patches in repos. | def _get_patches(installed_only=False):
'''
List all known patches in repos.
'''
patches = {}
cmd = [_yum(), '--quiet', 'updateinfo', 'list', 'all']
ret = __salt__['cmd.run_stdout'](
cmd,
python_shell=False
)
for line in salt.utils.itertools.split(ret, os.linesep):
... |
.. versionadded:: Fluorine
Called from ``complete_transaction`` to protect the arguments
used for tail recursion, ``run_count`` and ``cmd_ret_list``. | def _complete_transaction(cleanup_only, recursive, max_attempts, run_count, cmd_ret_list):
'''
.. versionadded:: Fluorine
Called from ``complete_transaction`` to protect the arguments
used for tail recursion, ``run_count`` and ``cmd_ret_list``.
'''
cmd = ['yum-complete-transaction']
if cle... |
Ensure the Route53 record is present.
name
Name of the record.
value
Value of the record. As a special case, you can pass in:
`private:<Name tag>` to have the function autodetermine the private IP
`public:<Name tag>` to have the function autodetermine the public IP
... | def present(name, value, zone, record_type, ttl=None, identifier=None, region=None, key=None,
keyid=None, profile=None, wait_for_sync=True, split_dns=False, private_zone=False):
'''
Ensure the Route53 record is present.
name
Name of the record.
value
Value of the record. A... |
Ensure the Route53 record is deleted.
name
Name of the record.
zone
The zone to delete the record from.
record_type
The record type (A, NS, MX, TXT, etc.)
identifier
An identifier to match for deletion.
region
The region to connect to.
key
Se... | def absent(
name,
zone,
record_type,
identifier=None,
region=None,
key=None,
keyid=None,
profile=None,
wait_for_sync=True,
split_dns=False,
private_zone=False):
'''
Ensure the Route53 record is deleted.
name
Nam... |
Ensure a hosted zone exists with the given attributes. Note that most
things cannot be modified once a zone is created - it must be deleted and
re-spun to update these attributes:
- private_zone (AWS API limitation).
- comment (the appropriate call exists in the AWS API and in boto3, but has
not,... | def hosted_zone_present(name, domain_name=None, private_zone=False, caller_ref=None, comment='',
vpc_id=None, vpc_name=None, vpc_region=None, region=None, key=None,
keyid=None, profile=None):
'''
Ensure a hosted zone exists with the given attributes. Note that mos... |
Ensure the Route53 Hostes Zone described is absent
name
The name of the state definition.
domain_name
The FQDN (including final period) of the zone you wish absent. If not
provided, the value of name will be used. | def hosted_zone_absent(name, domain_name=None, region=None, key=None,
keyid=None, profile=None):
'''
Ensure the Route53 Hostes Zone described is absent
name
The name of the state definition.
domain_name
The FQDN (including final period) of the zone you wish absen... |
Find out localhost outside IP.
:return: | def get_self_ip():
'''
Find out localhost outside IP.
:return:
'''
sck = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
try:
sck.connect(('1.255.255.255', 1)) # Does not needs to be reachable
ip_addr = sck.getsockname()[0]
except Except... |
On multi-master environments, running on the same machine,
transport sending to the destination can be allowed only at once.
Since every machine will immediately respond, high chance to
get sending fired at the same time, which will result to a PermissionError
at socket level. We are att... | def _sendto(self, data, addr=None, attempts=10):
'''
On multi-master environments, running on the same machine,
transport sending to the destination can be allowed only at once.
Since every machine will immediately respond, high chance to
get sending fired at the same time, which... |
On datagram receive.
:param data:
:param addr:
:return: | def datagram_received(self, data, addr):
'''
On datagram receive.
:param data:
:param addr:
:return:
'''
message = salt.utils.stringutils.to_unicode(data)
if message.startswith(self.signature):
try:
timestamp = float(message[le... |
Create datagram connection.
Based on code from Python 3.5 version, this method is used
only in Python 2.7+ versions, since Trollius library did not
ported UDP packets broadcast. | def create_datagram_endpoint(loop, protocol_factory, local_addr=None, remote_addr=None, family=0, proto=0, flags=0):
'''
Create datagram connection.
Based on code from Python 3.5 version, this method is used
only in Python 2.7+ versions, since Trollius library did not
ported UDP... |
Run server.
:return: | def run(self):
'''
Run server.
:return:
'''
listen_ip = self._config.get(self.LISTEN_IP, self.DEFAULTS[self.LISTEN_IP])
port = self._config.get(self.PORT, self.DEFAULTS[self.PORT])
self.log.info('Starting service discovery listener on udp://%s:%s', listen_ip, port... |
Query the broadcast for defined services.
:return: | def _query(self):
'''
Query the broadcast for defined services.
:return:
'''
query = salt.utils.stringutils.to_bytes(
"{}{}".format(self.signature, time.time()))
self._socket.sendto(query, ('<broadcast>', self.port))
return query |
Collect masters map from the network.
:return: | def _collect_masters_map(self, response):
'''
Collect masters map from the network.
:return:
'''
while True:
try:
data, addr = self._socket.recvfrom(0x400)
if data:
if addr not in response:
re... |
Gather the information of currently declared servers.
:return: | def discover(self):
'''
Gather the information of currently declared servers.
:return:
'''
response = {}
masters = {}
self.log.info("Looking for a server discovery")
self._query()
self._collect_masters_map(response)
if not response:
... |
Ensures that the user exists, eventually creates new user.
NOTE: use argument firstname instead of name to not mess values with name from salt sls.
.. versionadded:: 2016.3.0
:param alias: user alias
:param passwd: user's password
:param usrgrps: user groups to add the user to
:param medias: O... | def present(alias, passwd, usrgrps, medias=None, password_reset=False, **kwargs):
'''
Ensures that the user exists, eventually creates new user.
NOTE: use argument firstname instead of name to not mess values with name from salt sls.
.. versionadded:: 2016.3.0
:param alias: user alias
:param p... |
Initial change of Zabbix Admin password to password taken from one of the sources (only the most prioritized one):
1. 'password' parameter
2. '_connection_password' parameter
3. pillar 'zabbix.password' setting
1) Tries to log in as Admin with password found in state password parameter or _... | def admin_password_present(name, password=None, **kwargs):
'''
Initial change of Zabbix Admin password to password taken from one of the sources (only the most prioritized one):
1. 'password' parameter
2. '_connection_password' parameter
3. pillar 'zabbix.password' setting
1) Tries ... |
Ensures that the user does not exist, eventually delete user.
.. versionadded:: 2016.3.0
:param name: user alias
:param _connection_user: Optional - zabbix user (can also be set in opts or pillar, see module's docstring)
:param _connection_password: Optional - zabbix password (can also be set in opts ... | def absent(name, **kwargs):
'''
Ensures that the user does not exist, eventually delete user.
.. versionadded:: 2016.3.0
:param name: user alias
:param _connection_user: Optional - zabbix user (can also be set in opts or pillar, see module's docstring)
:param _connection_password: Optional - z... |
PushOver object method function to construct and execute on the API URL.
:param token: The PushOver api key.
:param api_version: The PushOver API version to use, defaults to version 1.
:param function: The PushOver api function to perform.
:param method: The HTTP method, e.g. GET or POST.... | def query(function,
token=None,
api_version='1',
method='POST',
header_dict=None,
data=None,
query_params=None,
opts=None):
'''
PushOver object method function to construct and execute on the API URL.
:param token: The PushOver api... |
Send a message to a Pushover user or group.
:param sound: The sound that we want to verify
:param token: The PushOver token. | def validate_sound(sound,
token):
'''
Send a message to a Pushover user or group.
:param sound: The sound that we want to verify
:param token: The PushOver token.
'''
ret = {
'message': 'Sound is invalid',
'res': False
}
param... |
Send a message to a Pushover user or group.
:param user: The user or group name, either will work.
:param device: The device for the user.
:param token: The PushOver token. | def validate_user(user,
device,
token):
'''
Send a message to a Pushover user or group.
:param user: The user or group name, either will work.
:param device: The device for the user.
:param token: The PushOver token.
'''
res = {
... |
Check if PID is still alive. | def is_alive(pidfile):
'''
Check if PID is still alive.
'''
try:
with salt.utils.files.fopen(pidfile) as fp_:
os.kill(int(fp_.read().strip()), 0)
return True
except Exception as ex:
if os.access(pidfile, os.W_OK) and os.path.isfile(pidfile):
os.unlink(... |
Main analyzer routine. | def main(dbfile, pidfile, mode):
'''
Main analyzer routine.
'''
Inspector(dbfile, pidfile).reuse_snapshot().snapshot(mode) |
Call an external system command. | def _syscall(self, command, input=None, env=None, *params):
'''
Call an external system command.
'''
return Popen([command] + list(params), stdout=PIPE, stdin=PIPE, stderr=STDOUT,
env=env or os.environ).communicate(input=input) |
Package scanner switcher between the platforms.
:return: | def _get_cfg_pkgs(self):
'''
Package scanner switcher between the platforms.
:return:
'''
if self.grains_core.os_data().get('os_family') == 'Debian':
return self.__get_cfg_pkgs_dpkg()
elif self.grains_core.os_data().get('os_family') in ['Suse', 'redhat']:
... |
Get packages with configuration files on Dpkg systems.
:return: | def __get_cfg_pkgs_dpkg(self):
'''
Get packages with configuration files on Dpkg systems.
:return:
'''
# Get list of all available packages
data = dict()
for pkg_name in salt.utils.stringutils.to_str(self._syscall('dpkg-query', None, None,
... |
Get packages with configuration files on RPM systems. | def __get_cfg_pkgs_rpm(self):
'''
Get packages with configuration files on RPM systems.
'''
out, err = self._syscall('rpm', None, None, '-qa', '--configfiles',
'--queryformat', '%{name}-%{version}-%{release}\\n')
data = dict()
pkg_name = N... |
Filter out unchanged packages on the Debian or RPM systems.
:param data: Structure {package-name -> [ file .. file1 ]}
:return: Same structure as data, except only files that were changed. | def _get_changed_cfg_pkgs(self, data):
'''
Filter out unchanged packages on the Debian or RPM systems.
:param data: Structure {package-name -> [ file .. file1 ]}
:return: Same structure as data, except only files that were changed.
'''
f_data = dict()
for pkg_nam... |
Save configuration packages. (NG)
:param data:
:return: | def _save_cfg_packages(self, data):
'''
Save configuration packages. (NG)
:param data:
:return:
'''
pkg_id = 0
pkg_cfg_id = 0
for pkg_name, pkg_configs in data.items():
pkg = Package()
pkg.id = pkg_id
pkg.name = pkg_nam... |
Save payload (unmanaged files)
:param files:
:param directories:
:param links:
:return: | def _save_payload(self, files, directories, links):
'''
Save payload (unmanaged files)
:param files:
:param directories:
:param links:
:return:
'''
idx = 0
for p_type, p_list in (('f', files), ('d', directories), ('l', links,),):
for ... |
Build a in-memory data of all managed files. | def _get_managed_files(self):
'''
Build a in-memory data of all managed files.
'''
if self.grains_core.os_data().get('os_family') == 'Debian':
return self.__get_managed_files_dpkg()
elif self.grains_core.os_data().get('os_family') in ['Suse', 'redhat']:
re... |
Get a list of all system files, belonging to the Debian package manager. | def __get_managed_files_dpkg(self):
'''
Get a list of all system files, belonging to the Debian package manager.
'''
dirs = set()
links = set()
files = set()
for pkg_name in salt.utils.stringutils.to_str(self._syscall("dpkg-query", None, None,
... |
Get a list of all system files, belonging to the RedHat package manager. | def __get_managed_files_rpm(self):
'''
Get a list of all system files, belonging to the RedHat package manager.
'''
dirs = set()
links = set()
files = set()
for line in salt.utils.stringutils.to_str(self._syscall("rpm", None, None, '-qlav')[0]).split(os.linesep):... |
Walk implementation. Version in python 2.x and 3.x works differently. | def _get_all_files(self, path, *exclude):
'''
Walk implementation. Version in python 2.x and 3.x works differently.
'''
files = list()
dirs = list()
links = list()
if os.access(path, os.R_OK):
for obj in os.listdir(path):
obj = os.path... |
Get the intersection between all files and managed files. | def _get_unmanaged_files(self, managed, system_all):
'''
Get the intersection between all files and managed files.
'''
m_files, m_dirs, m_links = managed
s_files, s_dirs, s_links = system_all
return (sorted(list(set(s_files).difference(m_files))),
sorted(... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.