INSTRUCTION
stringlengths
1
46.3k
RESPONSE
stringlengths
75
80.2k
Save the current in-memory rules to disk CLI Example: .. code-block:: bash salt '*' nftables.save /etc/nftables
def save(filename=None, family='ipv4'): ''' Save the current in-memory rules to disk CLI Example: .. code-block:: bash salt '*' nftables.save /etc/nftables ''' if _conf() and not filename: filename = _conf() nft_families = ['ip', 'ip6', 'arp', 'bridge'] rules = "#! nf...
Get the handle for a particular rule This function accepts a rule in a standard nftables command format, starting with the chain. Trying to force users to adapt to a new method of creating rules would be irritating at best, and we already have a parser that can handle it. CLI Example: ...
def get_rule_handle(table='filter', chain=None, rule=None, family='ipv4'): ''' Get the handle for a particular rule This function accepts a rule in a standard nftables command format, starting with the chain. Trying to force users to adapt to a new method of creating rules would be irritati...
Check for the existence of a rule in the table and chain This function accepts a rule in a standard nftables command format, starting with the chain. Trying to force users to adapt to a new method of creating rules would be irritating at best, and we already have a parser that can handle it...
def check(table='filter', chain=None, rule=None, family='ipv4'): ''' Check for the existence of a rule in the table and chain This function accepts a rule in a standard nftables command format, starting with the chain. Trying to force users to adapt to a new method of creating rules would b...
Check for the existence of a table CLI Example:: salt '*' nftables.check_table nat
def check_table(table=None, family='ipv4'): ''' Check for the existence of a table CLI Example:: salt '*' nftables.check_table nat ''' ret = {'comment': '', 'result': False} if not table: ret['comment'] = 'Table needs to be specified' return ret nft_fam...
.. versionadded:: 2014.7.0 Create new chain to the specified table. CLI Example: .. code-block:: bash salt '*' nftables.new_chain filter input salt '*' nftables.new_chain filter input \\ table_type=filter hook=input priority=0 salt '*' nftables.new_chain filter ...
def new_chain(table='filter', chain=None, table_type=None, hook=None, priority=None, family='ipv4'): ''' .. versionadded:: 2014.7.0 Create new chain to the specified table. CLI Example: .. code-block:: bash salt '*' nftables.new_chain filter input salt '*' nftables.new_chain fil...
Flush the chain in the specified table, flush all chains in the specified table if chain is not specified. CLI Example: .. code-block:: bash salt '*' nftables.flush filter salt '*' nftables.flush filter input IPv6: salt '*' nftables.flush filter input family=ipv6
def flush(table='filter', chain='', family='ipv4'): ''' Flush the chain in the specified table, flush all chains in the specified table if chain is not specified. CLI Example: .. code-block:: bash salt '*' nftables.flush filter salt '*' nftables.flush filter input IPv6: ...
Rewrite all state declarations that look like this:: state_id_decl: state.func into:: state_id_decl: state.func: []
def rewrite_single_shorthand_state_decl(data): # pylint: disable=C0103 ''' Rewrite all state declarations that look like this:: state_id_decl: state.func into:: state_id_decl: state.func: [] ''' for sid, states in six.iteritems(data): if isinstance(states, six...
Convert ``relative`` sls reference into absolute, relative to ``sls``.
def _relative_to_abs_sls(relative, sls): ''' Convert ``relative`` sls reference into absolute, relative to ``sls``. ''' levels, suffix = re.match(r'^(\.+)(.*)$', relative).groups() level_count = len(levels) p_comps = sls.split('.') if level_count > len(p_comps): raise SaltRenderError...
Given a list of items:: - whatever - name1: value1 - name2: - key: value - key: value return a generator that yields each (item, key, value) tuple, skipping items that are not name-value's(dictionaries) or those not in the list of matching names. The item in the...
def nvlist(thelist, names=None): ''' Given a list of items:: - whatever - name1: value1 - name2: - key: value - key: value return a generator that yields each (item, key, value) tuple, skipping items that are not name-value's(dictionaries) or those not in th...
Like nvlist but applied one more time to each returned value. So, given a list, args, of arguments to a state like this:: - name: echo test - cwd: / - require: - file: test.sh nvlist2(args, ['require']) would yield the tuple, (dict_item, 'file', 'test.sh') where dict_item is the...
def nvlist2(thelist, names=None): ''' Like nvlist but applied one more time to each returned value. So, given a list, args, of arguments to a state like this:: - name: echo test - cwd: / - require: - file: test.sh nvlist2(args, ['require']) would yield the tuple, (dict_i...
Retrieve the API params from the config file.
def _get_api_params(api_url=None, page_id=None, api_key=None, api_version=None): ''' Retrieve the API params from the config file. ''' statuspage_cfg = __salt__['config.get']('statuspage') if not statuspage_cfg: statuspage_cfg = {} ...
Validate the API params as specified in the config file.
def _validate_api_params(params): ''' Validate the API params as specified in the config file. ''' # page_id and API key are mandatory and they must be string/unicode return (isinstance(params['api_page_id'], (six.string_types, six.text_type)) and isinstance(params['api_key'], (six.strin...
Make the HTTP request and return the body as python object.
def _http_request(url, method='GET', headers=None, data=None): ''' Make the HTTP request and return the body as python object. ''' req = requests.request(method, url, headers=headers, ...
Retrieve a specific endpoint from the Statuspage API. endpoint: incidents Request a specific endpoint. page_id Page ID. Can also be specified in the config file. api_key API key. Can also be specified in the config file. api_version: 1 API version. Can also be specifi...
def retrieve(endpoint='incidents', api_url=None, page_id=None, api_key=None, api_version=None): ''' Retrieve a specific endpoint from the Statuspage API. endpoint: incidents Request a specific endpoint. page_id Page ID. Can also be sp...
Update attribute(s) of a specific endpoint. id The unique ID of the enpoint entry. endpoint: incidents Endpoint name. page_id Page ID. Can also be specified in the config file. api_key API key. Can also be specified in the config file. api_version: 1 API ...
def update(endpoint='incidents', id=None, api_url=None, page_id=None, api_key=None, api_version=None, **kwargs): ''' Update attribute(s) of a specific endpoint. id The unique ID of the enpoint entry. endpoint: incidents ...
Remove an entry from an endpoint. endpoint: incidents Request a specific endpoint. page_id Page ID. Can also be specified in the config file. api_key API key. Can also be specified in the config file. api_version: 1 API version. Can also be specified in the config fil...
def delete(endpoint='incidents', id=None, api_url=None, page_id=None, api_key=None, api_version=None): ''' Remove an entry from an endpoint. endpoint: incidents Request a specific endpoint. page_id Page ID. Can also be specified in...
Return a list of tuples to seed the "env" list, which is used to set environment variables for any pkg_add commands that are spawned. If ``fromrepo`` or ``packagesite`` are None, then their corresponding config parameter will be looked up with config.get. If both ``fromrepo`` and ``packagesite`` are N...
def _get_repo_options(fromrepo=None, packagesite=None): ''' Return a list of tuples to seed the "env" list, which is used to set environment variables for any pkg_add commands that are spawned. If ``fromrepo`` or ``packagesite`` are None, then their corresponding config parameter will be looked up ...
Since pkg_delete requires the full "pkgname-version" string, this function will attempt to match the package name with its version. Returns a list of partial matches and package names that match the "pkgname-version" string required by pkg_delete, and a list of errors encountered.
def _match(names): ''' Since pkg_delete requires the full "pkgname-version" string, this function will attempt to match the package name with its version. Returns a list of partial matches and package names that match the "pkgname-version" string required by pkg_delete, and a list of errors encounte...
List the packages currently installed as a dict:: {'<package_name>': '<version>'} with_origin : False Return a nested dictionary containing both the origin name and version for each installed package. .. versionadded:: 2014.1.0 CLI Example: .. code-block:: bash ...
def list_pkgs(versions_as_list=False, with_origin=False, **kwargs): ''' List the packages currently installed as a dict:: {'<package_name>': '<version>'} with_origin : False Return a nested dictionary containing both the origin name and version for each installed package. ...
Install package(s) using ``pkg_add(1)`` name The name of the package to be installed. refresh Whether or not to refresh the package database before installing. fromrepo or packageroot Specify a package repository from which to install. Overrides the system default, as well...
def install(name=None, refresh=False, fromrepo=None, pkgs=None, sources=None, **kwargs): ''' Install package(s) using ``pkg_add(1)`` name The name of the package to be installed. refresh Whether or not to refresh the package d...
Remove packages using ``pkg_delete(1)`` name The name of the package to be deleted. Multiple Package Options: pkgs A list of packages to delete. Must be passed as a python list. The ``name`` parameter will be ignored if this option is passed. .. versionadded:: 0.16.0 R...
def remove(name=None, pkgs=None, **kwargs): ''' Remove packages using ``pkg_delete(1)`` name The name of the package to be deleted. Multiple Package Options: pkgs A list of packages to delete. Must be passed as a python list. The ``name`` parameter will be ignored if this...
List the files that belong to a package, grouped by package. Not specifying any packages will return a list of _every_ file on the system's package database (not generally recommended). CLI Examples: .. code-block:: bash salt '*' pkg.file_list httpd salt '*' pkg.file_list httpd postfi...
def file_dict(*packages, **kwargs): ''' List the files that belong to a package, grouped by package. Not specifying any packages will return a list of _every_ file on the system's package database (not generally recommended). CLI Examples: .. code-block:: bash salt '*' pkg.file_list h...
Redefine (clone) a function under a different globals() namespace scope preserve_context: Allow keeping the context taken from orignal namespace, and extend it with globals() taken from new targetted namespace.
def namespaced_function(function, global_dict, defaults=None, preserve_context=False): ''' Redefine (clone) a function under a different globals() namespace scope preserve_context: Allow keeping the context taken from orignal namespace, and extend it with globals() taken from ...
Copy a function
def alias_function(fun, name, doc=None): ''' Copy a function ''' alias_fun = types.FunctionType(fun.__code__, fun.__globals__, str(name), # future lint: disable=blacklisted-function fun.__defaults__...
Configure the DNS server list in the specified interface Example: .. code-block:: yaml config_dns_servers: win_dns_client.dns_exists: - replace: True #remove any servers not in the "servers" list, default is False - servers: - 8.8.8.8 - 8....
def dns_exists(name, servers=None, interface='Local Area Connection', replace=False): ''' Configure the DNS server list in the specified interface Example: .. code-block:: yaml config_dns_servers: win_dns_client.dns_exists: - replace: True #remove any servers not in the ...
Configure the DNS server list from DHCP Server
def dns_dhcp(name, interface='Local Area Connection'): ''' Configure the DNS server list from DHCP Server ''' ret = {'name': name, 'result': True, 'changes': {}, 'comment': ''} # Check the config config = __salt__['win_dns_client.get_dns_config'](interface) ...
.. versionadded:: 2014.7.0 Configure the global primary DNS suffix of a DHCP client. suffix : None The suffix which is advertised for this client when acquiring a DHCP lease When none is set, the explicitly configured DNS suffix will be removed. updates : False Allow syncing the D...
def primary_suffix(name, suffix=None, updates=False): ''' .. versionadded:: 2014.7.0 Configure the global primary DNS suffix of a DHCP client. suffix : None The suffix which is advertised for this client when acquiring a DHCP lease When none is set, the explicitly confi...
.. versionadded:: 2014.1.0 Insert a rule into a chain name A user-defined name to call this rule by in another part of a state or formula. This should not be an actual rule. table The table that owns the chain that should be modified family Networking family, either i...
def insert(name, table='filter', family='ipv4', **kwargs): ''' .. versionadded:: 2014.1.0 Insert a rule into a chain name A user-defined name to call this rule by in another part of a state or formula. This should not be an actual rule. table The table that owns the chain ...
.. versionadded:: 2014.1.0 Delete a rule to a chain name A user-defined name to call this rule by in another part of a state or formula. This should not be an actual rule. table The table that owns the chain that should be modified family Networking family, either ipv...
def delete(name, table='filter', family='ipv4', **kwargs): ''' .. versionadded:: 2014.1.0 Delete a rule to a chain name A user-defined name to call this rule by in another part of a state or formula. This should not be an actual rule. table The table that owns the chain th...
.. versionadded:: 2014.1.0 Sets the default policy for iptables firewall tables table The table that owns the chain that should be modified family Networking family, either ipv4 or ipv6 policy The requested table policy
def set_policy(name, table='filter', family='ipv4', **kwargs): ''' .. versionadded:: 2014.1.0 Sets the default policy for iptables firewall tables table The table that owns the chain that should be modified family Networking family, either ipv4 or ipv6 policy The requ...
.. versionadded:: 2014.1.0 Flush current iptables state table The table that owns the chain that should be modified family Networking family, either ipv4 or ipv6
def flush(name, table='filter', family='ipv4', **kwargs): ''' .. versionadded:: 2014.1.0 Flush current iptables state table The table that owns the chain that should be modified family Networking family, either ipv4 or ipv6 ''' ret = {'name': name, 'changes': {...
The mod_aggregate function which looks up all rules in the available low chunks and merges them into a single rules ref in the present low data
def mod_aggregate(low, chunks, running): ''' The mod_aggregate function which looks up all rules in the available low chunks and merges them into a single rules ref in the present low data ''' rules = [] agg_enabled = [ 'append', 'insert', ] if low.get('fun') not ...
Monitor the memory usage of the minion Specify thresholds for percent used and only emit a beacon if it is exceeded. .. code-block:: yaml beacons: memusage: - percent: 63%
def beacon(config): ''' Monitor the memory usage of the minion Specify thresholds for percent used and only emit a beacon if it is exceeded. .. code-block:: yaml beacons: memusage: - percent: 63% ''' ret = [] _config = {} list(map(_config.update, con...
Format the function name
def format_name(self): ''' Format the function name ''' if not hasattr(self.module, '__func_alias__'): # Resume normal sphinx.ext.autodoc operation return super(FunctionDocumenter, self).format_name() if not self.objpath: # Resume normal sphin...
Manage NTP servers servers A list of NTP servers
def managed(name, servers=None): ''' Manage NTP servers servers A list of NTP servers ''' ret = {'name': name, 'changes': {}, 'result': True, 'comment': 'NTP servers already configured as specified'} if not _check_servers(servers): ret['result']...
Return correct command based on the family, e.g. ipv4 or ipv6
def _iptables_cmd(family='ipv4'): ''' Return correct command based on the family, e.g. ipv4 or ipv6 ''' if family == 'ipv6': return salt.utils.path.which('ip6tables') else: return salt.utils.path.which('iptables')
Return truth of whether iptables has `option`. For example: .. code-block:: python _has_option('--wait') _has_option('--check', family='ipv6')
def _has_option(option, family='ipv4'): ''' Return truth of whether iptables has `option`. For example: .. code-block:: python _has_option('--wait') _has_option('--check', family='ipv6') ''' cmd = '{0} --help'.format(_iptables_cmd(family)) if option in __salt__['cmd.run'](cmd,...
Some distros have a specific location for config files
def _conf(family='ipv4'): ''' Some distros have a specific location for config files ''' if __grains__['os_family'] == 'RedHat': if family == 'ipv6': return '/etc/sysconfig/ip6tables' else: return '/etc/sysconfig/iptables' elif __grains__['os_family'] == 'Arch...
Return string with `save_filter` regex entries removed. For example: If `filters` is not provided, it will be pulled from minion config, minion grains, minion pillar, or master config. Default return value if no filters found is the original cmd_output string. .. code-block:: python _regex_i...
def _regex_iptables_save(cmd_output, filters=None): ''' Return string with `save_filter` regex entries removed. For example: If `filters` is not provided, it will be pulled from minion config, minion grains, minion pillar, or master config. Default return value if no filters found is the original ...
Return version from iptables --version CLI Example: .. code-block:: bash salt '*' iptables.version IPv6: salt '*' iptables.version family=ipv6
def version(family='ipv4'): ''' Return version from iptables --version CLI Example: .. code-block:: bash salt '*' iptables.version IPv6: salt '*' iptables.version family=ipv6 ''' cmd = '{0} --version' . format(_iptables_cmd(family)) out = __salt__['cmd.run'](cmd)....
Build a well-formatted iptables rule based on kwargs. A `table` and `chain` are not required, unless `full` is True. If `full` is `True`, then `table`, `chain` and `command` are required. `command` may be specified as either a short option ('I') or a long option (`--insert`). This will return the iptab...
def build_rule(table='filter', chain=None, command=None, position='', full=None, family='ipv4', **kwargs): ''' Build a well-formatted iptables rule based on kwargs. A `table` and `chain` are not required, unless `full` is True. If `full` is `True`, then `table`, `chain` and `command` are...
Return the current policy for the specified table/chain CLI Examples: .. code-block:: bash salt '*' iptables.get_saved_policy filter INPUT salt '*' iptables.get_saved_policy filter INPUT \\ conf_file=/etc/iptables.saved IPv6: salt '*' iptables.get_saved_policy fil...
def get_saved_policy(table='filter', chain=None, conf_file=None, family='ipv4'): ''' Return the current policy for the specified table/chain CLI Examples: .. code-block:: bash salt '*' iptables.get_saved_policy filter INPUT salt '*' iptables.get_saved_policy filter INPUT \\ ...
Return the current policy for the specified table/chain CLI Example: .. code-block:: bash salt '*' iptables.get_policy filter INPUT IPv6: salt '*' iptables.get_policy filter INPUT family=ipv6
def get_policy(table='filter', chain=None, family='ipv4'): ''' Return the current policy for the specified table/chain CLI Example: .. code-block:: bash salt '*' iptables.get_policy filter INPUT IPv6: salt '*' iptables.get_policy filter INPUT family=ipv6 ''' if not ch...
Set the current policy for the specified table/chain CLI Example: .. code-block:: bash salt '*' iptables.set_policy filter INPUT ACCEPT IPv6: salt '*' iptables.set_policy filter INPUT ACCEPT family=ipv6
def set_policy(table='filter', chain=None, policy=None, family='ipv4'): ''' Set the current policy for the specified table/chain CLI Example: .. code-block:: bash salt '*' iptables.set_policy filter INPUT ACCEPT IPv6: salt '*' iptables.set_policy filter INPUT ACCEPT family=ip...
Save the current in-memory rules to disk CLI Example: .. code-block:: bash salt '*' iptables.save /etc/sysconfig/iptables IPv6: salt '*' iptables.save /etc/sysconfig/iptables family=ipv6
def save(filename=None, family='ipv4'): ''' Save the current in-memory rules to disk CLI Example: .. code-block:: bash salt '*' iptables.save /etc/sysconfig/iptables IPv6: salt '*' iptables.save /etc/sysconfig/iptables family=ipv6 ''' if _conf() and not filename: ...
Check for the existence of a rule in the table and chain This function accepts a rule in a standard iptables command format, starting with the chain. Trying to force users to adapt to a new method of creating rules would be irritating at best, and we already have a parser that can handle it...
def check(table='filter', chain=None, rule=None, family='ipv4'): ''' Check for the existence of a rule in the table and chain This function accepts a rule in a standard iptables command format, starting with the chain. Trying to force users to adapt to a new method of creating rules would b...
.. versionadded:: 2014.1.0 Check for the existence of a chain in the table CLI Example: .. code-block:: bash salt '*' iptables.check_chain filter INPUT IPv6: salt '*' iptables.check_chain filter INPUT family=ipv6
def check_chain(table='filter', chain=None, family='ipv4'): ''' .. versionadded:: 2014.1.0 Check for the existence of a chain in the table CLI Example: .. code-block:: bash salt '*' iptables.check_chain filter INPUT IPv6: salt '*' iptables.check_chain filter INPUT family...
.. versionadded:: 2014.1.0 Create new custom chain to the specified table. CLI Example: .. code-block:: bash salt '*' iptables.new_chain filter CUSTOM_CHAIN IPv6: salt '*' iptables.new_chain filter CUSTOM_CHAIN family=ipv6
def new_chain(table='filter', chain=None, family='ipv4'): ''' .. versionadded:: 2014.1.0 Create new custom chain to the specified table. CLI Example: .. code-block:: bash salt '*' iptables.new_chain filter CUSTOM_CHAIN IPv6: salt '*' iptables.new_chain filter CUSTOM_CHAI...
Append a rule to the specified table/chain. This function accepts a rule in a standard iptables command format, starting with the chain. Trying to force users to adapt to a new method of creating rules would be irritating at best, and we already have a parser that can handle it. CLI Ex...
def append(table='filter', chain=None, rule=None, family='ipv4'): ''' Append a rule to the specified table/chain. This function accepts a rule in a standard iptables command format, starting with the chain. Trying to force users to adapt to a new method of creating rules would be irritating...
Insert a rule into the specified table/chain, at the specified position. This function accepts a rule in a standard iptables command format, starting with the chain. Trying to force users to adapt to a new method of creating rules would be irritating at best, and we already have a parser th...
def insert(table='filter', chain=None, position=None, rule=None, family='ipv4'): ''' Insert a rule into the specified table/chain, at the specified position. This function accepts a rule in a standard iptables command format, starting with the chain. Trying to force users to adapt to a new ...
Delete a rule from the specified table/chain, specifying either the rule in its entirety, or the rule's position in the chain. This function accepts a rule in a standard iptables command format, starting with the chain. Trying to force users to adapt to a new method of creating rules would ...
def delete(table, chain=None, position=None, rule=None, family='ipv4'): ''' Delete a rule from the specified table/chain, specifying either the rule in its entirety, or the rule's position in the chain. This function accepts a rule in a standard iptables command format, starting with the ch...
Flush the chain in the specified table, flush all chains in the specified table if not specified chain. CLI Example: .. code-block:: bash salt '*' iptables.flush filter INPUT IPv6: salt '*' iptables.flush filter INPUT family=ipv6
def flush(table='filter', chain='', family='ipv4'): ''' Flush the chain in the specified table, flush all chains in the specified table if not specified chain. CLI Example: .. code-block:: bash salt '*' iptables.flush filter INPUT IPv6: salt '*' iptables.flush filter INPU...
If a file is not passed in, and the correct one for this OS is not detected, return False
def _parse_conf(conf_file=None, in_mem=False, family='ipv4'): ''' If a file is not passed in, and the correct one for this OS is not detected, return False ''' if _conf() and not conf_file and not in_mem: conf_file = _conf(family) rules = '' if conf_file: with salt.utils.fil...
This function attempts to list all the options documented in the iptables(8) and iptables-extensions(8) man pages. They will not all be used by all parts of the module; use them intelligently and appropriately.
def _parser(): ''' This function attempts to list all the options documented in the iptables(8) and iptables-extensions(8) man pages. They will not all be used by all parts of the module; use them intelligently and appropriately. ''' add_arg = None if sys.version.startswith('2.6'): ...
Return a dict of the changes required for a group if the group is present, otherwise return False.
def _changes(name, gid=None, addusers=None, delusers=None, members=None): ''' Return a dict of the changes required for a group if the group is present, otherwise return False. ''' lgrp = __salt__['group.info'](name) if not lgrp: return...
r''' Ensure that a group is present Args: name (str): The name of the group to manage gid (str): The group id to assign to the named group; if left empty, then the next available group id will be assigned. Ignored on Windows system (bool): ...
def present(name, gid=None, system=False, addusers=None, delusers=None, members=None): r''' Ensure that a group is present Args: name (str): The name of the group to manage gid (str): The group id to assig...
Just a convenience function for ``__salt__['cmd.run_all'](cmd)``
def _run(cmd): ''' Just a convenience function for ``__salt__['cmd.run_all'](cmd)`` ''' return __salt__['cmd.run_all'](cmd, env={'HOME': os.path.expanduser('~{0}'.format(__opts__['user']))})
nix-env with quiet option. By default, nix is extremely verbose and prints the build log of every package to stderr. This tells nix to only show changes.
def _nix_env(): ''' nix-env with quiet option. By default, nix is extremely verbose and prints the build log of every package to stderr. This tells nix to only show changes. ''' nixhome = os.path.join(os.path.expanduser('~{0}'.format(__opts__['user'])), '.nix-profile/bin/') return [os.path.join(...
Make sure we get the right nix-store, too.
def _nix_collect_garbage(): ''' Make sure we get the right nix-store, too. ''' nixhome = os.path.join(os.path.expanduser('~{0}'.format(__opts__['user'])), '.nix-profile/bin/') return [os.path.join(nixhome, 'nix-collect-garbage')]
intersperse x into ys, with an extra element at the beginning.
def _zip_flatten(x, ys): ''' intersperse x into ys, with an extra element at the beginning. ''' return itertools.chain.from_iterable( zip(itertools.repeat(x), ys))
gets a list of all the packages that were affected by ``operation``, splits it up (there can be multiple packages on a line), and then flattens that list. We make it to a list for easier parsing.
def _output_format(out, operation): ''' gets a list of all the packages that were affected by ``operation``, splits it up (there can be multiple packages on a line), and then flattens that list. We make it to a list for easier parsing. ''' return [s.split()[1:] for s in out ...
Runs an update operation on the specified packages, or all packages if none is specified. :type pkgs: list(str) :param pkgs: List of packages to update :return: The upgraded packages. Example element: ``['libxslt-1.1.0', 'libxslt-1.1.10']`` :rtype: list(tuple(str, str)) .. code-block:: ba...
def upgrade(*pkgs): ''' Runs an update operation on the specified packages, or all packages if none is specified. :type pkgs: list(str) :param pkgs: List of packages to update :return: The upgraded packages. Example element: ``['libxslt-1.1.0', 'libxslt-1.1.10']`` :rtype: list(tuple(st...
Installs a single or multiple packages via nix :type pkgs: list(str) :param pkgs: packages to update :param bool attributes: Pass the list of packages or single package as attribues, not package names. default: False :return: Installed packages. Example element: ``gcc-3.3.2`` ...
def install(*pkgs, **kwargs): ''' Installs a single or multiple packages via nix :type pkgs: list(str) :param pkgs: packages to update :param bool attributes: Pass the list of packages or single package as attribues, not package names. default: False :return: Installed ...
Lists installed packages. Due to how nix works, it defaults to just doing a ``nix-env -q``. :param bool installed: list only installed packages. This can be a very long list (12,000+ elements), so caution is advised. Default: True :param bool attributes: show the attributes of the pack...
def list_pkgs(installed=True, attributes=True): ''' Lists installed packages. Due to how nix works, it defaults to just doing a ``nix-env -q``. :param bool installed: list only installed packages. This can be a very long list (12,000+ elements), so caution is advised. Default:...
Erases a package from the current nix profile. Nix uninstalls work differently than other package managers, and the symlinks in the profile are removed, while the actual package remains. There is also a ``nix.purge`` function, to clear the package cache of unused packages. :type pkgs: list(str) :param ...
def uninstall(*pkgs): ''' Erases a package from the current nix profile. Nix uninstalls work differently than other package managers, and the symlinks in the profile are removed, while the actual package remains. There is also a ``nix.purge`` function, to clear the package cache of unused packages. ...
Completely removed all currently 'uninstalled' packages in the nix store. Tells the user how many store paths were removed and how much space was freed. :return: How much space was freed and how many derivations were removed :rtype: str .. warning:: This is a destructive action on the nix stor...
def collect_garbage(): ''' Completely removed all currently 'uninstalled' packages in the nix store. Tells the user how many store paths were removed and how much space was freed. :return: How much space was freed and how many derivations were removed :rtype: str .. warning:: This is a...
Collect minion external pillars from a RethinkDB database Arguments: * `table`: The RethinkDB table containing external pillar information. Defaults to ``'pillar'`` * `id_field`: Field in document containing the minion id. If blank then we assume the table index matches minion ids * `field`...
def ext_pillar(minion_id, pillar, table='pillar', id_field=None, field=None, pillar_key=None): ''' Collect minion external pillars from a RethinkDB database Arguments: * `table`: The RethinkDB table containing external pillar in...
Same as original _proc_function in AsyncClientMixin, except it calls "low" without firing a print event.
def _proc_function(self, fun, low, user, tag, jid, daemonize=True): ''' Same as original _proc_function in AsyncClientMixin, except it calls "low" without firing a print event. ''' if daemonize and not salt.utils.platform.is_windows(): salt.log.setup.shutdown_multipro...
Execute a puppet run and return a dict with the stderr, stdout, return code, etc. The first positional argument given is checked as a subcommand. Following positional arguments should be ordered with arguments required by the subcommand first, followed by non-keyword arguments. Tags are specified by a t...
def run(*args, **kwargs): ''' Execute a puppet run and return a dict with the stderr, stdout, return code, etc. The first positional argument given is checked as a subcommand. Following positional arguments should be ordered with arguments required by the subcommand first, followed by non-keyword ar...
.. versionadded:: 2014.7.0 Enable the puppet agent CLI Example: .. code-block:: bash salt '*' puppet.enable
def enable(): ''' .. versionadded:: 2014.7.0 Enable the puppet agent CLI Example: .. code-block:: bash salt '*' puppet.enable ''' puppet = _Puppet() if os.path.isfile(puppet.disabled_lockfile): try: os.remove(puppet.disabled_lockfile) except (IOEr...
.. versionadded:: 2014.7.0 Disable the puppet agent message .. versionadded:: 2015.5.2 Disable message to send to puppet CLI Example: .. code-block:: bash salt '*' puppet.disable salt '*' puppet.disable 'Disabled, contact XYZ before enabling'
def disable(message=None): ''' .. versionadded:: 2014.7.0 Disable the puppet agent message .. versionadded:: 2015.5.2 Disable message to send to puppet CLI Example: .. code-block:: bash salt '*' puppet.disable salt '*' puppet.disable 'Disabled, contact XYZ b...
.. versionadded:: 2014.7.0 Display puppet agent status CLI Example: .. code-block:: bash salt '*' puppet.status
def status(): ''' .. versionadded:: 2014.7.0 Display puppet agent status CLI Example: .. code-block:: bash salt '*' puppet.status ''' puppet = _Puppet() if os.path.isfile(puppet.disabled_lockfile): return 'Administratively disabled' if os.path.isfile(puppet.run_...
.. versionadded:: 2014.7.0 Show a summary of the last puppet agent run CLI Example: .. code-block:: bash salt '*' puppet.summary
def summary(): ''' .. versionadded:: 2014.7.0 Show a summary of the last puppet agent run CLI Example: .. code-block:: bash salt '*' puppet.summary ''' puppet = _Puppet() try: with salt.utils.files.fopen(puppet.lastrunfile, 'r') as fp_: report = salt.uti...
Run facter and return the results CLI Example: .. code-block:: bash salt '*' puppet.facts
def facts(puppet=False): ''' Run facter and return the results CLI Example: .. code-block:: bash salt '*' puppet.facts ''' ret = {} opt_puppet = '--puppet' if puppet else '' cmd_ret = __salt__['cmd.run_all']('facter {0}'.format(opt_puppet)) if cmd_ret['retcode'] != 0: ...
Run facter for a specific fact CLI Example: .. code-block:: bash salt '*' puppet.fact kernel
def fact(name, puppet=False): ''' Run facter for a specific fact CLI Example: .. code-block:: bash salt '*' puppet.fact kernel ''' opt_puppet = '--puppet' if puppet else '' ret = __salt__['cmd.run_all']( 'facter {0} {1}'.format(opt_puppet, name), python_she...
Read in arguments for the current subcommand. These are added to the cmd line without '--' appended. Any others are redirected as standard options with the double hyphen prefixed.
def arguments(self, args=None): ''' Read in arguments for the current subcommand. These are added to the cmd line without '--' appended. Any others are redirected as standard options with the double hyphen prefixed. ''' # permits deleting elements rather than using slices...
.. versionadded:: 2015.8.0 Ensure the IAM access keys are present. name (string) The name of the new user. number (int) Number of keys that user should have. save_dir (string) The directory that the key/keys will be saved. Keys are saved to a file named according to t...
def keys_present(name, number, save_dir, region=None, key=None, keyid=None, profile=None, save_format="{2}\n{0}\n{3}\n{1}\n"): ''' .. versionadded:: 2015.8.0 Ensure the IAM access keys are present. name (string) The name of the new user. number (int) Number of key...
Change account policy. .. versionadded:: 2015.8.0 name (string) The name of the account policy allow_users_to_change_password (bool) Allows all IAM users in your account to use the AWS Management Console to change their own passwords. hard_expiry (bool) Prevents IAM u...
def account_policy(name=None, allow_users_to_change_password=None, hard_expiry=None, max_password_age=None, minimum_password_length=None, password_reuse_prevention=None, require_lowercase_characters=None, require_numbers=None, require_symbols=N...
Crete server certificate. .. versionadded:: 2015.8.0 name (string) The name for the server certificate. Do not include the path in this value. public_key (string) The contents of the public key certificate in PEM-encoded format. private_key (string) The contents of the privat...
def server_cert_present(name, public_key, private_key, cert_chain=None, path=None, region=None, key=None, keyid=None, profile=None): ''' Crete server certificate. .. versionadded:: 2015.8.0 name (string) The name for the server certificate. Do not include the path in th...
.. versionadded:: 2016.11.0 Ensure the SAML provider with the specified name is absent. name (string) The name of the SAML provider. saml_metadata_document (string) The xml document of the SAML provider. region (string) Region to connect to. key (string) Secret k...
def saml_provider_absent(name, region=None, key=None, keyid=None, profile=None): ''' .. versionadded:: 2016.11.0 Ensure the SAML provider with the specified name is absent. name (string) The name of the SAML provider. saml_metadata_document (string) The xml document of the SAML pr...
Provides the BGP configuration on the device. :param group: Name of the group selected to display the configuration. :param neighbor: IP Address of the neighbor to display the configuration. If the group parameter is not specified, the neighbor setting will be ignored. :return: A dictionar...
def config(group=None, neighbor=None, **kwargs): ''' Provides the BGP configuration on the device. :param group: Name of the group selected to display the configuration. :param neighbor: IP Address of the neighbor to display the configuration. If the group parameter is not specified, the neigh...
Execute a salt function on a specific minion Special kwargs: salt_target target to exec things on salt_timeout timeout for jobs salt_job_poll poll interval to wait for job finish result
def _salt(fun, *args, **kw): '''Execute a salt function on a specific minion Special kwargs: salt_target target to exec things on salt_timeout timeout for jobs salt_job_poll poll interval to wait for job finish result ''' ...
Return a list of the VMs that are on the provider, with select fields
def list_nodes_select(call=None): ''' Return a list of the VMs that are on the provider, with select fields ''' if not call: call = 'select' if not get_configured_provider(): return info = ['id', 'name', 'image', 'size', 'state', 'public_ips', 'private_ips'] return salt.utils...
Destroy a lxc container
def destroy(vm_, call=None): '''Destroy a lxc container''' destroy_opt = __opts__.get('destroy', False) profiles = __opts__.get('profiles', {}) profile = __opts__.get('profile', __opts__.get('internal_lxc_profile', [])) path = None if profile and profile in profiles: ...
Create an lxc Container. This function is idempotent and will try to either provision or finish the provision of an lxc container. NOTE: Most of the initialization code has been moved and merged with the lxc runner and lxc.init functions
def create(vm_, call=None): '''Create an lxc Container. This function is idempotent and will try to either provision or finish the provision of an lxc container. NOTE: Most of the initialization code has been moved and merged with the lxc runner and lxc.init functions ''' prov = get_configu...
Return the contextual provider of None if no configured one can be found.
def get_configured_provider(vm_=None): ''' Return the contextual provider of None if no configured one can be found. ''' if vm_ is None: vm_ = {} dalias, driver = __active_provider_name__.split(':') data = None tgt = 'unknown' img_provider = __opts__.get('list_images', '') ...
Write a launchd plist for managing salt-master or salt-minion CLI Example: .. code-block:: bash salt-run launchd.write_launchd_plist salt-master
def write_launchd_plist(program): ''' Write a launchd plist for managing salt-master or salt-minion CLI Example: .. code-block:: bash salt-run launchd.write_launchd_plist salt-master ''' plist_sample_text = ''' <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//D...
Return some CPU information on Windows minions
def _windows_cpudata(): ''' Return some CPU information on Windows minions ''' # Provides: # num_cpus # cpu_model grains = {} if 'NUMBER_OF_PROCESSORS' in os.environ: # Cast to int so that the logic isn't broken when used as a # conditional in templating. Also follows...
Return some CPU information for Linux minions
def _linux_cpudata(): ''' Return some CPU information for Linux minions ''' # Provides: # num_cpus # cpu_model # cpu_flags grains = {} cpuinfo = '/proc/cpuinfo' # Parse over the cpuinfo file if os.path.isfile(cpuinfo): with salt.utils.files.fopen(cpuinfo, 'r') a...
num_gpus: int gpus: - vendor: nvidia|amd|ati|... model: string
def _linux_gpu_data(): ''' num_gpus: int gpus: - vendor: nvidia|amd|ati|... model: string ''' if __opts__.get('enable_lspci', True) is False: return {} if __opts__.get('enable_gpu_grains', True) is False: return {} lspci = salt.utils.path.which('lspci') if...
num_gpus: int gpus: - vendor: nvidia|amd|ati|... model: string
def _netbsd_gpu_data(): ''' num_gpus: int gpus: - vendor: nvidia|amd|ati|... model: string ''' known_vendors = ['nvidia', 'amd', 'ati', 'intel', 'cirrus logic', 'vmware', 'matrox', 'aspeed'] gpus = [] try: pcictl_out = __salt__['cmd.run']('pcictl pci0 list') f...
num_gpus: int gpus: - vendor: nvidia|amd|ati|... model: string
def _osx_gpudata(): ''' num_gpus: int gpus: - vendor: nvidia|amd|ati|... model: string ''' gpus = [] try: pcictl_out = __salt__['cmd.run']('system_profiler SPDisplaysDataType') for line in pcictl_out.splitlines(): fieldname, _, fieldval = line.partitio...
Return CPU information for BSD-like systems
def _bsd_cpudata(osdata): ''' Return CPU information for BSD-like systems ''' # Provides: # cpuarch # num_cpus # cpu_model # cpu_flags sysctl = salt.utils.path.which('sysctl') arch = salt.utils.path.which('arch') cmds = {} if sysctl: cmds.update({ ...
Return the CPU information for Solaris-like systems
def _sunos_cpudata(): ''' Return the CPU information for Solaris-like systems ''' # Provides: # cpuarch # num_cpus # cpu_model # cpu_flags grains = {} grains['cpu_flags'] = [] grains['cpuarch'] = __salt__['cmd.run']('isainfo -k') psrinfo = '/usr/sbin/psrinfo 2>/d...
Return CPU information for AIX systems
def _aix_cpudata(): ''' Return CPU information for AIX systems ''' # Provides: # cpuarch # num_cpus # cpu_model # cpu_flags grains = {} cmd = salt.utils.path.which('prtconf') if cmd: data = __salt__['cmd.run']('{0}'.format(cmd)) + os.linesep for dest, ...
Return the memory information for Linux-like systems
def _linux_memdata(): ''' Return the memory information for Linux-like systems ''' grains = {'mem_total': 0, 'swap_total': 0} meminfo = '/proc/meminfo' if os.path.isfile(meminfo): with salt.utils.files.fopen(meminfo, 'r') as ifile: for line in ifile: comps = ...
Return the memory information for BSD-like systems
def _osx_memdata(): ''' Return the memory information for BSD-like systems ''' grains = {'mem_total': 0, 'swap_total': 0} sysctl = salt.utils.path.which('sysctl') if sysctl: mem = __salt__['cmd.run']('{0} -n hw.memsize'.format(sysctl)) swap_total = __salt__['cmd.run']('{0} -n vm...
Return the memory information for SunOS-like systems
def _sunos_memdata(): ''' Return the memory information for SunOS-like systems ''' grains = {'mem_total': 0, 'swap_total': 0} prtconf = '/usr/sbin/prtconf 2>/dev/null' for line in __salt__['cmd.run'](prtconf, python_shell=True).splitlines(): comps = line.split(' ') if comps[0].s...
Return the memory information for BSD-like systems
def _bsd_memdata(osdata): ''' Return the memory information for BSD-like systems ''' grains = {'mem_total': 0, 'swap_total': 0} sysctl = salt.utils.path.which('sysctl') if sysctl: mem = __salt__['cmd.run']('{0} -n hw.physmem'.format(sysctl)) if osdata['kernel'] == 'NetBSD' and m...
Return the memory information for AIX systems
def _aix_memdata(): ''' Return the memory information for AIX systems ''' grains = {'mem_total': 0, 'swap_total': 0} prtconf = salt.utils.path.which('prtconf') if prtconf: for line in __salt__['cmd.run'](prtconf, python_shell=True).splitlines(): comps = [x for x in line.strip...