text
stringlengths
81
112k
Remove a cluster on a Postgres server. By default it doesn't try to stop the cluster. CLI Example: .. code-block:: bash salt '*' postgres.cluster_remove '9.3' salt '*' postgres.cluster_remove '9.3' 'main' salt '*' postgres.cluster_remove '9.3' 'main' stop=True def cluster_remov...
Helper function to parse the output of pg_lscluster def _parse_pg_lscluster(output): ''' Helper function to parse the output of pg_lscluster ''' cluster_dict = {} for line in output.splitlines(): version, name, port, status, user, datadir, log = ( line.split()) cluster_d...
Cycle through all the possible credentials and return the first one that works. def _find_credentials(host): ''' Cycle through all the possible credentials and return the first one that works. ''' user_names = [__pillar__['proxy'].get('username', 'root')] passwords = __pillar__['proxy']['pa...
Get the grains from the proxied device. def _grains(): ''' Get the grains from the proxied device. ''' try: host = __pillar__['proxy']['host'] if host: username, password = _find_credentials(host) protocol = __pillar__['proxy'].get('protocol') port = ...
Check etcd for all data def ext_pillar(minion_id, pillar, # pylint: disable=W0613 conf): ''' Check etcd for all data ''' comps = conf.split() profile = None if comps[0]: profile = comps[0] client = salt.utils.etcd_util.get_conn(__opts__, profile) ...
Ensure iptable is not present. name The ip address or CIDR for the rule. method The type of rule. Either 'allow' or 'deny'. port Optional port to be open or closed for the iptables rule. proto The protocol. Either 'tcp', 'udp'. Only applicable if port...
Ensure ports are open for a protocol, in a direction. e.g. - proto='tcp', direction='in' would set the values for TCP_IN in the csf.conf file. ports A list of ports that should be open. proto The protocol. May be one of 'tcp', 'udp', 'tcp6', or 'udp6'. direction Ch...
Alias for :mod:`csf.nics_skipped <salt.states.csf.nics_skipped>` def nics_skip(name, nics, ipv6): ''' Alias for :mod:`csf.nics_skipped <salt.states.csf.nics_skipped>` ''' return nics_skipped(name, nics=nics, ipv6=ipv6)
name Meaningless arg, but required for state. nics A list of nics to skip. ipv6 Boolean. Set to true if you want to skip the ipv6 interface. Default false (ipv4). def nics_skipped(name, nics, ipv6=False): ''' name Meaningless arg, but required for state. n...
Ensure the state of a particular option/setting in csf. name The option name in csf.conf value The value it should be set to. reload Boolean. If set to true, csf will be reloaded after. def option_present(name, value, reload=False): ''' Ensure the state of a particular op...
Allow top level cfg to be YAML def _parse_stack_cfg(content): ''' Allow top level cfg to be YAML ''' try: obj = salt.utils.yaml.safe_load(content) if isinstance(obj, list): return obj except Exception as e: pass return content.splitlines()
Remove the cached pip version def _clear_context(bin_env=None): ''' Remove the cached pip version ''' contextkey = 'pip.version' if bin_env is not None: contextkey = '{0}.{1}'.format(contextkey, bin_env) __context__.pop(contextkey, None)
Locate the pip binary, either from `bin_env` as a virtualenv, as the executable itself, or from searching conventional filesystem locations def _get_pip_bin(bin_env): ''' Locate the pip binary, either from `bin_env` as a virtualenv, as the executable itself, or from searching conventional filesystem lo...
Get the location of a cached requirements file; caching if necessary. def _get_cached_requirements(requirements, saltenv): ''' Get the location of a cached requirements file; caching if necessary. ''' req_file, senv = salt.utils.url.parse(requirements) if senv: saltenv = senv if req_f...
Return the path to the activate binary def _get_env_activate(bin_env): ''' Return the path to the activate binary ''' if not bin_env: raise CommandNotFoundError('Could not find a `activate` binary') if os.path.isdir(bin_env): if salt.utils.platform.is_windows(): activat...
Return an array of requirements file paths that can be used to complete the no_chown==False && user != None conundrum def _resolve_requirements_chain(requirements): ''' Return an array of requirements file paths that can be used to complete the no_chown==False && user != None conundrum ''' cha...
Process the requirements argument def _process_requirements(requirements, cmd, cwd, saltenv, user): ''' Process the requirements argument ''' cleanup_requirements = [] if requirements is not None: if isinstance(requirements, six.string_types): requirements = [r.strip() for r in...
Install packages with pip Install packages individually or from a pip requirements file. Install packages globally or to a virtualenv. pkgs Comma separated list of packages to install requirements Path to requirements bin_env Path to pip (or to a virtualenv). This can be ...
Uninstall packages individually or from a pip requirements file pkgs comma separated list of packages to install requirements Path to requirements file bin_env Path to pip (or to a virtualenv). This can be used to specify the path to the pip to use when more than one Pytho...
Return a list of installed packages either globally or in the specified virtualenv bin_env Path to pip (or to a virtualenv). This can be used to specify the path to the pip to use when more than one Python release is installed (e.g. ``/usr/bin/pip-2.7`` or ``/usr/bin/pip-2.6``. If a dir...
Filter list of installed apps from ``freeze`` and check to see if ``prefix`` exists in the list of packages installed. .. note:: If the version of pip available is older than 8.0.3, the packages ``wheel``, ``setuptools``, and ``distribute`` will not be reported by this function even if...
.. versionadded:: 0.17.0 Returns the version of pip. Use ``bin_env`` to specify the path to a virtualenv and get the version of pip in that virtualenv. If unable to detect the pip version, returns ``None``. CLI Example: .. code-block:: bash salt '*' pip.version def version(bin_env=None...
Check whether or not an upgrade is available for all packages CLI Example: .. code-block:: bash salt '*' pip.list_upgrades def list_upgrades(bin_env=None, user=None, cwd=None): ''' Check whether or not an upgrade is available for all packages CLI Exam...
.. versionadded:: 2018.3.0 Filter list of installed apps from ``freeze`` and return True or False if ``pkgname`` exists in the list of packages installed. .. note:: If the version of pip available is older than 8.0.3, the packages wheel, setuptools, and distribute will not be reported by ...
.. versionadded:: 2015.5.0 Check whether or not an upgrade is available for a given package CLI Example: .. code-block:: bash salt '*' pip.upgrade_available <package name> def upgrade_available(pkg, bin_env=None, user=None, cwd=N...
.. versionadded:: 2015.5.0 Upgrades outdated pip packages. .. note:: On Windows you can't update salt from pip using salt, so salt will be skipped Returns a dict containing the changes. {'<package>': {'old': '<old-version>', 'new': '<new-version>'}} ...
.. versionadded:: 2017.7.3 List all available versions of a pip package pkg The package to check bin_env Path to pip (or to a virtualenv). This can be used to specify the path to the pip to use when more than one Python release is installed (e.g. ``/usr/bin/pip-2.7`` or ``...
Sanity checking for the specified SSL certificates def verify_certs(*args): ''' Sanity checking for the specified SSL certificates ''' msg = ("Could not find a certificate: {0}\n" "If you want to quickly generate a self-signed certificate, " "use the tls.create_self_signed_cert ...
Start the server loop def start(): ''' Start the server loop ''' from . import app root, apiopts, conf = app.get_app(__opts__) if not apiopts.get('disable_ssl', False): if 'ssl_crt' not in apiopts or 'ssl_key' not in apiopts: logger.error("Not starting '%s'. Options 'ssl_cr...
Get the os architecture using rpm --eval def get_osarch(): ''' Get the os architecture using rpm --eval ''' if salt.utils.path.which('rpm'): ret = subprocess.Popen( 'rpm --eval "%{_host_cpu}"', shell=True, close_fds=True, stdout=subprocess.PIPE, ...
Returns True if both the OS arch and the passed arch are 32-bit def check_32(arch, osarch=None): ''' Returns True if both the OS arch and the passed arch are 32-bit ''' if osarch is None: osarch = get_osarch() return all(x in ARCHES_32 for x in (osarch, arch))
Build and return a pkginfo namedtuple def pkginfo(name, version, arch, repoid, install_date=None, install_date_time_t=None): ''' Build and return a pkginfo namedtuple ''' pkginfo_tuple = collections.namedtuple( 'PkgInfo', ('name', 'version', 'arch', 'repoid', 'install_date', 'i...
Resolve the package name and arch into a unique name referred to by salt. For example, on a 64-bit OS, a 32-bit package will be pkgname.i386. def resolve_name(name, arch, osarch=None): ''' Resolve the package name and arch into a unique name referred to by salt. For example, on a 64-bit OS, a 32-bit pa...
A small helper to parse an rpm/repoquery command's output. Returns a pkginfo namedtuple. def parse_pkginfo(line, osarch=None): ''' A small helper to parse an rpm/repoquery command's output. Returns a pkginfo namedtuple. ''' try: name, epoch, version, release, arch, repoid, install_time ...
Given a list of comments, strings, a single comment or a single string, return a single string of text containing all of the comments, prepending the '#' and joining with newlines as necessary. def combine_comments(comments): ''' Given a list of comments, strings, a single comment or a single string, ...
Split the package version string into epoch, version and release. Return this as tuple. The epoch is always not empty. The version and the release can be an empty string if such a component could not be found in the version string. "2:1.0-1.2" => ('2', '1.0', '1.2) "1.0" => ('0', '1.0', '') ""...
Ensure the security group exists with the specified rules. name Name of the security group. description A description of this security group. vpc_id The ID of the VPC to create the security group in, if any. Exclusive with vpc_name. vpc_name The name of the VPC to cre...
given a group name or a group name and vpc id (or vpc name): 1. determine if the group exists 2. if the group does not exist, creates the group 3. return the group's configuration and any changes made def _security_group_present(name, description, vpc_id=None, vpc_name=None, reg...
Split rules with lists into individual rules. We accept some attributes as lists or strings. The data we get back from the execution module lists rules as individual rules. We need to split the provided rules into individual rules to compare them. def _split_rules(rules): ''' Split rules with list...
Check to see if two rules are the same. Needed to compare rules fetched from boto, since they may not completely match rules defined in sls files but may be functionally equivalent. def _check_rule(rule, _rule): ''' Check to see if two rules are the same. Needed to compare rules fetched from boto, ...
given a list of desired rules (rules) and existing rules (_rules) return a list of rules to delete (to_delete) and to create (to_create) def _get_rule_changes(rules, _rules): ''' given a list of desired rules (rules) and existing rules (_rules) return a list of rules to delete (to_delete) and to create...
given a group name or group name and vpc_id (or vpc name): 1. get lists of desired rule changes (using _get_rule_changes) 2. authorize/create rules missing rules 3. if delete_ingress_rules is True, delete/revoke non-requested rules 4. return 'old' and 'new' group rules def _rules_present(name, rules, d...
Ensure a security group with the specified name does not exist. name Name of the security group. vpc_id The ID of the VPC to remove the security group from, if any. Exclusive with vpc_name. vpc_name The name of the VPC to remove the security group from, if any. Exclusive with vpc_...
helper function to validate tags are correct def _tags_present(name, tags, vpc_id=None, vpc_name=None, region=None, key=None, keyid=None, profile=None): ''' helper function to validate tags are correct ''' ret = {'result': True, 'comment': '', 'changes': {}} if tags: sg = ...
Convert ordered dictionary to a dictionary def _ordereddict2dict(input_ordered_dict): ''' Convert ordered dictionary to a dictionary ''' return salt.utils.json.loads(salt.utils.json.dumps(input_ordered_dict))
Quorum state This state checks the mon daemons are in quorum. It does not alter the cluster but can be used in formula as a dependency for many cluster operations. Example usage in sls file: .. code-block:: yaml quorum: sesceph.quorum: - require: - ses...
Check consul for all data def ext_pillar(minion_id, pillar, # pylint: disable=W0613 conf): ''' Check consul for all data ''' opts = {} temp = conf target_re = re.compile('target="(.*?)"') match = target_re.search(temp) if match: opts['target'] = ma...
Query consul for all keys/values within base path def consul_fetch(client, path): ''' Query consul for all keys/values within base path ''' # Unless the root path is blank, it needs a trailing slash for # the kv get from Consul to work as expected return client.kv.get('' if not path else path.r...
Grab data from consul, trim base path and remove any keys which are folders. Take the remaining data and send it to be formatted in such a way as to be used as pillar data. def fetch_tree(client, path, expand_keys): ''' Grab data from consul, trim base path and remove any keys which are folders. Ta...
Perform data formatting to be used as pillar data and merge it with the current pillar data def pillar_format(ret, keys, value, expand_keys): ''' Perform data formatting to be used as pillar data and merge it with the current pillar data ''' # if value is empty in Consul then it's None here - s...
Return a client object for accessing consul def get_conn(opts, profile): ''' Return a client object for accessing consul ''' opts_pillar = opts.get('pillar', {}) opts_master = opts_pillar.get('master', {}) opts_merged = {} opts_merged.update(opts_master) opts_merged.update(opts_pillar...
If ``dc`` is a string - return it as is. If it's a dict then sort it in descending order by key length and try to use keys as RegEx patterns to match against ``pillarenv``. The value for matched pattern should be a string (that can use ``str.format`` syntax togetehr with captured variables from pattern...
Gather group members def _gather_group_members(group, groups, users): ''' Gather group members ''' _group = __salt__['group.info'](group) if not _group: log.warning('Group %s does not exist, ignoring.', group) return for member in _group['members']: if member not in us...
Check time range def _check_time_range(time_range, now): ''' Check time range ''' if _TIME_SUPPORTED: _start = dateutil_parser.parse(time_range['start']) _end = dateutil_parser.parse(time_range['end']) return bool(_start <= now <= _end) else: log.error('Dateutil is ...
Read the last btmp file and return information on the failed logins def beacon(config): ''' Read the last btmp file and return information on the failed logins ''' ret = [] users = {} groups = {} defaults = None for config_item in config: if 'users' in config_item: ...
Sprinkle with grains of salt, that is convert 'test {id} test {host} ' types of strings :param config_str: The string to be sprinkled :return: The string sprinkled def _sprinkle(config_str): ''' Sprinkle with grains of salt, that is convert 'test {id} test {host} ' types of strings :param c...
Prepare the payload for Slack :param author_icon: The url for the thumbnail to be displayed :param title: The title of the message :param report: A dictionary with the report of the Salt function :return: The payload ready for Slack def _generate_payload(author_icon, title, report): ''' Prepare...
Generate a report of the Salt function :param ret: The Salt return :param show_tasks: Flag to show the name of the changed and failed states :return: The report def _generate_report(ret, show_tasks): ''' Generate a report of the Salt function :param ret: The Salt return :param show_tasks: F...
Send a message to a Slack room through a webhook :param webhook: The url of the incoming webhook :param author_icon: The thumbnail image to be displayed on the right side of the message :param title: The title of the message :param report: The report of the function state :return: ...
Send a slack message with the data through a webhook :param ret: The Salt return :return: The result of the post def returner(ret): ''' Send a slack message with the data through a webhook :param ret: The Salt return :return: The result of the post ''' _options = _get_options(ret) ...
Checkout git repos containing :ref:`Windows Software Package Definitions <windows-package-manager>`. .. important:: This function requires `Git for Windows`_ to be installed in order to work. When installing, make sure to select an installation option which permits the git executable to...
r''' .. versionadded:: 2015.8.0 Display the rendered software definition from a specific sls file in the local winrepo cache. This will parse all Jinja. Run pkg.refresh_db to pull the latest software definitions from the master. .. note:: This function does not ask a master for an sls file...
Return the actual lxc client version .. versionadded:: 2015.8.0 CLI Example: .. code-block:: bash salt '*' lxc.version def version(): ''' Return the actual lxc client version .. versionadded:: 2015.8.0 CLI Example: .. code-block:: bash salt '*' lxc.version '...
Clear any lxc variables set in __context__ def _clear_context(): ''' Clear any lxc variables set in __context__ ''' for var in [x for x in __context__ if x.startswith('lxc.')]: log.trace('Clearing __context__[\'%s\']', var) __context__.pop(var, None)
Ip sorting def _ip_sort(ip): '''Ip sorting''' idx = '001' if ip == '127.0.0.1': idx = '200' if ip == '::1': idx = '201' elif '::' in ip: idx = '100' return '{0}___{1}'.format(idx, ip)
Search which bridges are potentially available as LXC bridges CLI Example: .. code-block:: bash salt '*' lxc.search_lxc_bridges def search_lxc_bridges(): ''' Search which bridges are potentially available as LXC bridges CLI Example: .. code-block:: bash salt '*' lxc.search...
Interface between salt.cloud.lxc driver and lxc.init ``vm_`` is a mapping of vm opts in the salt.cloud format as documented for the lxc driver. This can be used either: - from the salt cloud driver - because you find the argument to give easier here than using directly lxc.init .. warni...
Return a random subset of cpus for the cpuset config def _rand_cpu_str(cpu): ''' Return a random subset of cpus for the cpuset config ''' cpu = int(cpu) avail = __salt__['status.nproc']() if cpu < avail: return '0-{0}'.format(avail) to_set = set() while len(to_set) < cpu: ...
Network configuration defaults network_profile as for containers, we can either call this function either with a network_profile dict or network profile name in the kwargs nic_opts overrides or extra nics in the form {nic_name: {set: tings} def _network_...
Return a list of dicts from the salt level configurations conf_tuples _LXCConfig compatible list of entries which can contain - string line - tuple (lxc config param,value) - dict of one entry: {lxc config param: value) only_net by default we add to the tup...
Parse the nic setup inside lxc conf tuples back to a dictionary indexed by network interface def _get_veths(net_data): ''' Parse the nic setup inside lxc conf tuples back to a dictionary indexed by network interface ''' if isinstance(net_data, dict): net_data = list(net_data.items()) ...
If the needed base does not exist, then create it, if it does exist create nothing and return the name of the base lxc container so it can be cloned. def _get_base(**kwargs): ''' If the needed base does not exist, then create it, if it does exist create nothing and return the name of the base lxc c...
Initialize a new container. This is a partial idempotent function as if it is already provisioned, we will reset a bit the lxc configuration file but much of the hard work will be escaped as markers will prevent re-execution of harmful tasks. name Name of the container image A tar...
Thin wrapper to lxc.init to be used from the saltcloud lxc driver name Name of the container may be None and then guessed from saltcloud mapping `vm_` saltcloud mapping defaults for the vm CLI Example: .. code-block:: bash salt '*' lxc.cloud_init foo def cloud_init(n...
.. versionadded:: 2015.5.0 List the available images for LXC's ``download`` template. dist : None Filter results to a single Linux distribution CLI Examples: .. code-block:: bash salt myminion lxc.images salt myminion lxc.images dist=centos def images(dist=None): ''' ...
.. versionadded:: 2015.5.0 List the available LXC template scripts installed on the minion CLI Examples: .. code-block:: bash salt myminion lxc.templates def templates(): ''' .. versionadded:: 2015.5.0 List the available LXC template scripts installed on the minion CLI Example...
Create a new container. name Name of the container config The config file to use for the container. Defaults to system-wide config (usually in /etc/lxc/lxc.conf). profile Profile to use in container creation (see :mod:`lxc.get_container_profile <salt.module...
Create a new container as a clone of another container name Name of the container orig Name of the original container to be cloned profile Profile to use in container cloning (see :mod:`lxc.get_container_profile <salt.modules.lxc.get_container_profile>`). Values in...
Return a list of the containers available on the minion path path to the container parent directory default: /var/lib/lxc (system) .. versionadded:: 2015.8.0 active If ``True``, return only active (i.e. running) containers .. versionadded:: 2015.5.0 CLI Example: ...
List containers classified by state extra Also get per-container specific info. This will change the return data. Instead of returning a list of containers, a dictionary of containers and each container's output from :mod:`lxc.info <salt.modules.lxc.info>`. path path to...
Raise an exception if the container does not exist def _ensure_exists(name, path=None): ''' Raise an exception if the container does not exist ''' if not exists(name, path=path): raise CommandExecutionError( 'Container \'{0}\' does not exist'.format(name) )
If the container is not currently running, start it. This function returns the state that the container was in before changing path path to the container parent directory default: /var/lib/lxc (system) .. versionadded:: 2015.8.0 def _ensure_running(name, no_start=False, path=None): ...
.. versionadded:: 2015.5.0 Restart the named container. If the container was not running, the container will merely be started. name The name of the container path path to the container parent directory default: /var/lib/lxc (system) .. versionadded:: 2015.8.0 lx...
Start the named container path path to the container parent directory default: /var/lib/lxc (system) .. versionadded:: 2015.8.0 lxc_config path to a lxc config file config file will be guessed from container name otherwise .. versionadded:: 2015.8.0 use_v...
Stop the named container path path to the container parent directory default: /var/lib/lxc (system) .. versionadded:: 2015.8.0 kill: False Do not wait for the container to stop, kill all tasks in the container. Older LXC versions will stop containers like this irrespec...
Freeze the named container path path to the container parent directory default: /var/lib/lxc (system) .. versionadded:: 2015.8.0 start : False If ``True`` and the container is stopped, the container will be started before attempting to freeze. .. versionadded:...
Unfreeze the named container. path path to the container parent directory default: /var/lib/lxc (system) .. versionadded:: 2015.8.0 use_vt run the command through VT .. versionadded:: 2015.8.0 CLI Example: .. code-block:: bash salt '*' lxc.unfreeze ...
Destroy the named container. .. warning:: Destroys all data associated with the container. path path to the container parent directory (default: /var/lib/lxc) .. versionadded:: 2015.8.0 stop : False If ``True``, the container will be destroyed even if it is runni...
Returns whether the named container exists. path path to the container parent directory (default: /var/lib/lxc) .. versionadded:: 2015.8.0 CLI Example: .. code-block:: bash salt '*' lxc.exists name def exists(name, path=None): ''' Returns whether the named container ex...
Returns the state of a container. path path to the container parent directory (default: /var/lib/lxc) .. versionadded:: 2015.8.0 CLI Example: .. code-block:: bash salt '*' lxc.state name def state(name, path=None): ''' Returns the state of a container. path ...
Returns the value of a cgroup parameter for a container path path to the container parent directory default: /var/lib/lxc (system) .. versionadded:: 2015.8.0 CLI Example: .. code-block:: bash salt '*' lxc.get_parameter container_name memory.limit_in_bytes def get_parame...
Set the value of a cgroup parameter for a container. path path to the container parent directory default: /var/lib/lxc (system) .. versionadded:: 2015.8.0 CLI Example: .. code-block:: bash salt '*' lxc.set_parameter name parameter value def set_parameter(name, parameter...
Returns information about a container path path to the container parent directory default: /var/lib/lxc (system) .. versionadded:: 2015.8.0 CLI Example: .. code-block:: bash salt '*' lxc.info name def info(name, path=None): ''' Returns information about a contai...
.. versionchanged:: 2015.5.0 Function renamed from ``set_pass`` to ``set_password``. Additionally, this function now supports (and defaults to using) a password hash instead of a plaintext password. Set the password of one or more system users inside containers users Comma-sep...
Edit LXC configuration options path path to the container parent default: /var/lib/lxc (system default) .. versionadded:: 2015.8.0 CLI Example: .. code-block:: bash salt myminion lxc.update_lxc_conf ubuntu \\ lxc_conf="[{'network.ipv4.ip':'10.0.3.5'}]" \\...
.. versionchanged:: 2015.5.0 The ``dnsservers`` and ``searchdomains`` parameters can now be passed as a comma-separated list. Update /etc/resolv.confo path path to the container parent default: /var/lib/lxc (system default) .. versionadded:: 2015.8.0 CLI Example:...
Determine if systemD is running path path to the container parent .. versionadded:: 2015.8.0 CLI Example: .. code-block:: bash salt '*' lxc.running_systemd ubuntu def running_systemd(name, cache=True, path=None): ''' Determine if systemD is running path pat...
Get the operational state of a systemd based container path path to the container parent default: /var/lib/lxc (system default) .. versionadded:: 2015.8.0 CLI Example: .. code-block:: bash salt myminion lxc.systemd_running_state ubuntu def systemd_running_state(name, pa...
Check that the system has fully inited This is actually very important for systemD based containers see https://github.com/saltstack/salt/issues/23847 path path to the container parent default: /var/lib/lxc (system default) .. versionadded:: 2015.8.0 CLI Example: .. cod...
Return True if the named container can be attached to via the lxc-attach command path path to the container parent default: /var/lib/lxc (system default) .. versionadded:: 2015.8.0 CLI Example: .. code-block:: bash salt 'minion' lxc.attachable ubuntu def attachable(...