INSTRUCTION
stringlengths
1
46.3k
RESPONSE
stringlengths
75
80.2k
Updates the APT database to latest packages based upon repositories Returns a dict, with the keys being package databases and the values being the result of the update attempt. Values can be one of the following: - ``True``: Database updated successfully - ``False``: Problem updating database - ``...
def refresh_db(cache_valid_time=0, failhard=False, **kwargs): ''' Updates the APT database to latest packages based upon repositories Returns a dict, with the keys being package databases and the values being the result of the update attempt. Values can be one of the following: - ``True``: Databas...
.. 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 apt-get/dpkg commands spawned...
def install(name=None, refresh=False, fromrepo=None, skip_verify=False, debconf=None, pkgs=None, sources=None, reinstall=False, ignore_epoch=False, **kwargs): ''' .. versionchanged:: 2015.8.12,2016.3.3,20...
remove and purge do identical things but with different apt-get commands, this function performs the common logic.
def _uninstall(action='remove', name=None, pkgs=None, **kwargs): ''' remove and purge do identical things but with different apt-get commands, this function performs the common logic. ''' try: pkg_params = __salt__['pkg_resource.parse_targets'](name, pkgs)[0] except MinionError as exc: ...
.. versionadded:: 2015.5.0 Remove packages not required by another package using ``apt-get autoremove``. list_only : False Only retrieve the list of packages to be auto-removed, do not actually perform the auto-removal. purge : False Also remove package config data when autore...
def autoremove(list_only=False, purge=False): ''' .. versionadded:: 2015.5.0 Remove packages not required by another package using ``apt-get autoremove``. list_only : False Only retrieve the list of packages to be auto-removed, do not actually perform the auto-removal. purge :...
.. 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 apt-get/dpkg commands spawned...
def remove(name=None, pkgs=None, **kwargs): ''' .. 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 system...
.. 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 apt-get/dpkg commands spawned...
def purge(name=None, pkgs=None, **kwargs): ''' .. 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...
.. 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 apt-get/dpkg commands spawned...
def upgrade(refresh=True, dist_upgrade=False, **kwargs): ''' .. 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 t...
.. versionadded:: 2014.7.0 Set package in 'hold' state, meaning it will not be upgraded. name The name of the package, e.g., 'tmux' CLI Example: .. code-block:: bash salt '*' pkg.hold <package name> pkgs A list of packages to hold. Must be passed as a python...
def hold(name=None, pkgs=None, sources=None, **kwargs): # pylint: disable=W0613 ''' .. versionadded:: 2014.7.0 Set package in 'hold' state, meaning it will not be upgraded. name The name of the package, e.g., 'tmux' CLI Example: .. code-block:: bash salt '*' pkg...
List the packages currently installed in a dict:: {'<package_name>': '<version>'} removed If ``True``, then only packages which have been removed (but not purged) will be returned. purge_desired If ``True``, then only packages which have been marked to be purged, but c...
def list_pkgs(versions_as_list=False, removed=False, purge_desired=False, **kwargs): # pylint: disable=W0613 ''' List the packages currently installed in a dict:: {'<package_name>': '<version>'} removed If ``True``, then only packages which have b...
Utility function to get upgradable packages Sample return data: { 'pkgname': '1.2.3-45', ... }
def _get_upgradable(dist_upgrade=True, **kwargs): ''' Utility function to get upgradable packages Sample return data: { 'pkgname': '1.2.3-45', ... } ''' cmd = ['apt-get', '--just-print'] if dist_upgrade: cmd.append('dist-upgrade') else: cmd.append('upgrade') try: ...
List all available package upgrades. refresh Whether to refresh the package database before listing upgrades. Default: True. cache_valid_time .. versionadded:: 2016.11.0 Skip refreshing the package database if refresh has already occurred within <value> seconds d...
def list_upgrades(refresh=True, dist_upgrade=True, **kwargs): ''' List all available package upgrades. refresh Whether to refresh the package database before listing upgrades. Default: True. cache_valid_time .. versionadded:: 2016.11.0 Skip refreshing the package data...
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 .. versionadded:: 2015.8.10,2016.3.2 ...
def version_cmp(pkg1, pkg2, ignore_epoch=False, **kwargs): ''' 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 whe...
Return APT source entry as a tuple.
def _split_repo_str(repo): ''' Return APT source entry as a tuple. ''' split = sourceslist.SourceEntry(repo) return split.type, split.architectures, split.uri, split.dist, split.comps
Consolidate APT sources.
def _consolidate_repo_sources(sources): ''' Consolidate APT sources. ''' if not isinstance(sources, sourceslist.SourcesList): raise TypeError( '\'{0}\' not a \'{1}\''.format( type(sources), sourceslist.SourcesList ) ) consolida...
.. versionadded:: 2017.7.0 Returns all available packages. Optionally, package names (and name globs) can be passed and the results will be filtered to packages matching those names. This function can be helpful in discovering the version or repo to specify in a :mod:`pkg.installed <salt.states.pk...
def list_repo_pkgs(*args, **kwargs): # pylint: disable=unused-import ''' .. versionadded:: 2017.7.0 Returns all available packages. Optionally, package names (and name globs) can be passed and the results will be filtered to packages matching those names. This function can be helpful in disco...
Decide to skip source or not. :param source: :return:
def _skip_source(source): ''' Decide to skip source or not. :param source: :return: ''' if source.invalid: if source.uri and source.type and source.type in ("deb", "deb-src", "rpm", "rpm-src"): pieces = source.mysplit(source.line) if pieces[1].strip()[0] == "[": ...
Lists all repos in the sources.list (and sources.lists.d) files CLI Example: .. code-block:: bash salt '*' pkg.list_repos salt '*' pkg.list_repos disabled=True
def list_repos(**kwargs): ''' Lists all repos in the sources.list (and sources.lists.d) files CLI Example: .. code-block:: bash salt '*' pkg.list_repos salt '*' pkg.list_repos disabled=True ''' _check_apt() repos = {} sources = sourceslist.SourcesList() for source in...
Display a repo from the sources.list / sources.list.d The repo passed in needs to be a complete repo entry. CLI Examples: .. code-block:: bash salt '*' pkg.get_repo "myrepo definition"
def get_repo(repo, **kwargs): ''' Display a repo from the sources.list / sources.list.d The repo passed in needs to be a complete repo entry. CLI Examples: .. code-block:: bash salt '*' pkg.get_repo "myrepo definition" ''' _check_apt() ppa_auth = kwargs.get('ppa_auth', None) ...
Delete a repo from the sources.list / sources.list.d If the .list file is in the sources.list.d directory and the file that the repo exists in does not contain any other repo configuration, the file itself will be deleted. The repo passed in must be a fully formed repository definition string. ...
def del_repo(repo, **kwargs): ''' Delete a repo from the sources.list / sources.list.d If the .list file is in the sources.list.d directory and the file that the repo exists in does not contain any other repo configuration, the file itself will be deleted. The repo passed in must be a fully fo...
.. versionadded:: 2017.7.0 List known repo key details. :return: A dictionary containing the repo keys. :rtype: dict CLI Examples: .. code-block:: bash salt '*' pkg.get_repo_keys
def get_repo_keys(): ''' .. versionadded:: 2017.7.0 List known repo key details. :return: A dictionary containing the repo keys. :rtype: dict CLI Examples: .. code-block:: bash salt '*' pkg.get_repo_keys ''' ret = dict() repo_keys = list() # The double usage of ...
.. versionadded:: 2017.7.0 Add a repo key using ``apt-key add``. :param str path: The path of the key file to import. :param str text: The key data to import, in string form. :param str keyserver: The server to download the repo key specified by the keyid. :param str keyid: The key id of the repo ...
def add_repo_key(path=None, text=None, keyserver=None, keyid=None, saltenv='base'): ''' .. versionadded:: 2017.7.0 Add a repo key using ``apt-key add``. :param str path: The path of the key file to import. :param str text: The key data to import, in string form. :param str keyserver: The serve...
.. versionadded:: 2015.8.0 Remove a repo key using ``apt-key del`` name Repo from which to remove the key. Unnecessary if ``keyid`` is passed. keyid The KeyID of the GPG key to remove keyid_ppa : False If set to ``True``, the repo's GPG key ID will be looked up from p...
def del_repo_key(name=None, **kwargs): ''' .. versionadded:: 2015.8.0 Remove a repo key using ``apt-key del`` name Repo from which to remove the key. Unnecessary if ``keyid`` is passed. keyid The KeyID of the GPG key to remove keyid_ppa : False If set to ``True``, the...
Take a repository definition and expand it to the full pkg repository dict that can be used for comparison. This is a helper function to make the Debian/Ubuntu apt sources sane for comparison in the pkgrepo states. This is designed to be called from pkgrepo states and will have little use being called...
def expand_repo_def(**kwargs): ''' Take a repository definition and expand it to the full pkg repository dict that can be used for comparison. This is a helper function to make the Debian/Ubuntu apt sources sane for comparison in the pkgrepo states. This is designed to be called from pkgrepo state...
Parses the format from ``dpkg --get-selections`` and return a format that pkg.get_selections and pkg.set_selections work with.
def _parse_selections(dpkgselection): ''' Parses the format from ``dpkg --get-selections`` and return a format that pkg.get_selections and pkg.set_selections work with. ''' ret = {} if isinstance(dpkgselection, six.string_types): dpkgselection = dpkgselection.split('\n') for line in ...
View package state from the dpkg database. Returns a dict of dicts containing the state, and package names: .. code-block:: python {'<host>': {'<state>': ['pkg1', ... ] }, ... } CLI Example: .. code...
def get_selections(pattern=None, state=None): ''' View package state from the dpkg database. Returns a dict of dicts containing the state, and package names: .. code-block:: python {'<host>': {'<state>': ['pkg1', ... ] }...
Change package state in the dpkg database. The state can be any one of, documented in ``dpkg(1)``: - install - hold - deinstall - purge This command is commonly used to mark specific packages to be held from being upgraded, that is, to be kept at a certain version. When a state is cha...
def set_selections(path=None, selection=None, clear=False, saltenv='base'): ''' Change package state in the dpkg database. The state can be any one of, documented in ``dpkg(1)``: - install - hold - deinstall - purge This command is commonly used to mark specific packages to be held fr...
Installs missing dependencies and marks them as auto installed so they are removed when no more manually installed packages depend on them. .. versionadded:: 2014.7.0 :depends: - python-apt module
def _resolve_deps(name, pkgs, **kwargs): ''' Installs missing dependencies and marks them as auto installed so they are removed when no more manually installed packages depend on them. .. versionadded:: 2014.7.0 :depends: - python-apt module ''' missing_deps = [] for pkg_file in pkgs...
.. versionadded:: 2019.2.0 Runs an ``apt-cache show`` on the passed package names, and returns the results in a nested dictionary. The top level of the return data will be the package name, with each package name mapping to a dictionary of version numbers to any additional information returned by ``apt...
def show(*names, **kwargs): ''' .. versionadded:: 2019.2.0 Runs an ``apt-cache show`` on the passed package names, and returns the results in a nested dictionary. The top level of the return data will be the package name, with each package name mapping to a dictionary of version numbers to any ...
Return the information of the named package(s) installed on the system. .. versionadded:: 2015.8.1 names The names of the packages for which to return information. failhard Whether to throw an exception if none of the packages are installed. Defaults to True. .. versionad...
def info_installed(*names, **kwargs): ''' Return the information of the named package(s) installed on the system. .. versionadded:: 2015.8.1 names The names of the packages for which to return information. failhard Whether to throw an exception if none of the packages are installe...
Returns the http_proxy_url if proxy_username, proxy_password, proxy_host, and proxy_port config values are set. Returns a string.
def _get_http_proxy_url(): ''' Returns the http_proxy_url if proxy_username, proxy_password, proxy_host, and proxy_port config values are set. Returns a string. ''' http_proxy_url = '' host = __salt__['config.option']('proxy_host') port = __salt__['config.option']('proxy_port') user...
If Zabbix template is to be updated then list of assigned hosts must be provided in all or nothing manner to prevent some externally assigned hosts to be detached. :param defined: list of hosts defined in sls :param existing: list of hosts taken from live Zabbix :return: list to be updated (combinated ...
def _diff_and_merge_host_list(defined, existing): ''' If Zabbix template is to be updated then list of assigned hosts must be provided in all or nothing manner to prevent some externally assigned hosts to be detached. :param defined: list of hosts defined in sls :param existing: list of hosts taken...
Make a list of given component type not inherited from other templates because Zabbix API returns only list of all and list of inherited component items so we have to do a difference list. :param component: Template component (application, item, etc...) :param parent_id: ID of existing template the compone...
def _get_existing_template_c_list(component, parent_id, **kwargs): ''' Make a list of given component type not inherited from other templates because Zabbix API returns only list of all and list of inherited component items so we have to do a difference list. :param component: Template component (appli...
For creation or update of object that have attribute which contains a list Zabbix awaits plain list of IDs while querying Zabbix for same object returns list of dicts :param obj: Zabbix object parameters
def _adjust_object_lists(obj): ''' For creation or update of object that have attribute which contains a list Zabbix awaits plain list of IDs while querying Zabbix for same object returns list of dicts :param obj: Zabbix object parameters ''' for subcomp in TEMPLATE_COMPONENT_DEF: if su...
Takes particular component list, compares it with existing, call appropriate API methods - create, update, delete. :param component: component name :param parent_id: ID of parent entity under which component should be created :param defined: list of defined items of named component :param existing: lis...
def _manage_component(component, parent_id, defined, existing, template_id=None, **kwargs): ''' Takes particular component list, compares it with existing, call appropriate API methods - create, update, delete. :param component: component name :param parent_id: ID of parent entity under which component...
Check if Zabbix Template already exists. :param name: Zabbix Template name :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 or pillar, see module's docstring) :par...
def is_present(name, **kwargs): ''' Check if Zabbix Template already exists. :param name: Zabbix Template name :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...
Creates Zabbix Template object or if differs update it according defined parameters. See Zabbix API documentation. Zabbix API version: >3.0 :param name: Zabbix Template name :param params: Additional parameters according to Zabbix API documentation :param static_host_list: If hosts assigned to the tem...
def present(name, params, static_host_list=True, **kwargs): ''' Creates Zabbix Template object or if differs update it according defined parameters. See Zabbix API documentation. Zabbix API version: >3.0 :param name: Zabbix Template name :param params: Additional parameters according to Zabbix API...
Makes the Zabbix Template to be absent (either does not exist or delete it). :param name: Zabbix Template name :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 or pill...
def absent(name, **kwargs): ''' Makes the Zabbix Template to be absent (either does not exist or delete it). :param name: Zabbix Template name :param _connection_user: Optional - zabbix user (can also be set in opts or pillar, see module's docstring) :param _connection_password: Optional - zabbix p...
Change the gid for a named group CLI Example: .. code-block:: bash salt '*' group.chgid foo 4376
def chgid(name, gid): ''' Change the gid for a named group CLI Example: .. code-block:: bash salt '*' group.chgid foo 4376 ''' pre_gid = __salt__['file.group_to_gid'](name) if gid == pre_gid: return True cmd = 'groupmod -g {0} {1}'.format(gid, name) __salt__['cmd.r...
Generate and return an private_key. If a ``dns_name`` is passed in, the private_key will be cached under that name. The type of key and the parameters used to generate the key are based on the default certificate use policy associated with the specified zone. CLI Example: .. code-block:: bash ...
def gen_key(minion_id, dns_name=None, zone='default', password=None): ''' Generate and return an private_key. If a ``dns_name`` is passed in, the private_key will be cached under that name. The type of key and the parameters used to generate the key are based on the default certificate use policy as...
Generate a csr using the host's private_key. Analogous to: .. code-block:: bash VCert gencsr -cn [CN Value] -o "Beta Organization" -ou "Beta Group" \ -l "Palo Alto" -st "California" -c US CLI Example: .. code-block:: bash salt-run venafi.gen_csr <minion_id> <dns_name>
def gen_csr( minion_id, dns_name, zone='default', country=None, state=None, loc=None, org=None, org_unit=None, password=None, ): ''' Generate a csr using the host's private_key. Analogous to: .. code-block:: bash VCert...
Request a new certificate Uses the following command: .. code-block:: bash VCert enroll -z <zone> -k <api key> -cn <domain name> CLI Example: .. code-block:: bash salt-run venafi.request <minion_id> <dns_name>
def request( minion_id, dns_name=None, zone='default', request_id=None, country='US', state='California', loc='Palo Alto', org='Beta Organization', org_unit='Beta Group', password=None, zone_id=None, ): ''' Request a new...
Register a new user account CLI Example: .. code-block:: bash salt-run venafi.register email@example.com
def register(email): ''' Register a new user account CLI Example: .. code-block:: bash salt-run venafi.register email@example.com ''' data = __utils__['http.query']( '{0}/useraccounts'.format(_base_url()), method='POST', data=salt.utils.json.dumps({ ...
Show company information, especially the company id CLI Example: .. code-block:: bash salt-run venafi.show_company example.com
def show_company(domain): ''' Show company information, especially the company id CLI Example: .. code-block:: bash salt-run venafi.show_company example.com ''' data = __utils__['http.query']( '{0}/companies/domain/{1}'.format(_base_url(), domain), status=True, ...
Show certificate requests for this API key CLI Example: .. code-block:: bash salt-run venafi.show_cert 01234567-89ab-cdef-0123-456789abcdef
def show_cert(id_): ''' Show certificate requests for this API key CLI Example: .. code-block:: bash salt-run venafi.show_cert 01234567-89ab-cdef-0123-456789abcdef ''' data = __utils__['http.query']( '{0}/certificaterequests/{1}/certificate'.format(_base_url(), id_), p...
List domains that have been cached CLI Example: .. code-block:: bash salt-run venafi.list_domain_cache
def list_domain_cache(): ''' List domains that have been cached CLI Example: .. code-block:: bash salt-run venafi.list_domain_cache ''' cache = salt.cache.Cache(__opts__, syspaths.CACHE_DIR) return cache.list('venafi/domains')
Delete cached domains from the master CLI Example: .. code-block:: bash salt-run venafi.del_cached_domain domain1.example.com,domain2.example.com
def del_cached_domain(domains): ''' Delete cached domains from the master CLI Example: .. code-block:: bash salt-run venafi.del_cached_domain domain1.example.com,domain2.example.com ''' cache = salt.cache.Cache(__opts__, syspaths.CACHE_DIR) if isinstance(domains, six.string_types)...
Ensure a user is present with the specified groups name Name of user password Encrypted or Plain Text password for user roles List of roles the user should be assigned. Any roles not in this list will be removed encrypted Whether the password is encrypted already or ...
def user_present(name, password=None, roles=None, encrypted=False, crypt_salt=None, algorithm='sha256'): ''' Ensure a user is present with the specified groups name Name of user password Encrypted or Plain Text password for user roles List of roles the user should be assig...
Ensure a user is not present name username to remove if it exists Examples: .. code-block:: yaml delete: onyx.user_absent: - name: daniel
def user_absent(name): ''' Ensure a user is not present name username to remove if it exists Examples: .. code-block:: yaml delete: onyx.user_absent: - name: daniel ''' ret = {'name': name, 'result': False, 'changes': {}, ...
Ensure a specific configuration line exists in the running config name config line to set Examples: .. code-block:: yaml add snmp group: onyx.config_present: - names: - snmp-server community randoSNMPstringHERE group network-operator - sn...
def config_present(name): ''' Ensure a specific configuration line exists in the running config name config line to set Examples: .. code-block:: yaml add snmp group: onyx.config_present: - names: - snmp-server community randoSNMPstringHERE gro...
Ensure a specific configuration line does not exist in the running config name config line to remove Examples: .. code-block:: yaml add snmp group: onyx.config_absent: - names: - snmp-server community randoSNMPstringHERE group network-operator ...
def config_absent(name): ''' Ensure a specific configuration line does not exist in the running config name config line to remove Examples: .. code-block:: yaml add snmp group: onyx.config_absent: - names: - snmp-server community randoSNMPstrin...
Replace all instances of a string or full line in the running config name String to replace repl The replacement text full_match Whether `name` will match the full line or only a subset of the line. Defaults to False. When False, .* is added around `name` for matching ...
def replace(name, repl, full_match=False): ''' Replace all instances of a string or full line in the running config name String to replace repl The replacement text full_match Whether `name` will match the full line or only a subset of the line. Defaults to False. ...
Checks existance of the named login. If not present, creates the login with the specified roles and options. name The name of the login to manage password Creates a SQL Server authentication login Since hashed passwords are varbinary values, if the new_login_password is 'lon...
def present(name, password=None, domain=None, server_roles=None, options=None, **kwargs): ''' Checks existance of the named login. If not present, creates the login with the specified roles and options. name The name of the login to manage password Creates a SQL Server authenticatio...
Re-interpret the state returned by salt.state.run using our protocol.
def _reinterpreted_state(state): ''' Re-interpret the state returned by salt.state.run using our protocol. ''' ret = state['changes'] state['changes'] = {} state['comment'] = '' out = ret.get('stdout') if not out: if ret.get('stderr'): state['comment'] = ret['stderr'...
Execute the onlyif and unless logic. Return a result dict if: * onlyif failed (onlyif != 0) * unless succeeded (unless == 0) else return True
def mod_run_check(cmd_kwargs, onlyif, unless, creates): ''' Execute the onlyif and unless logic. Return a result dict if: * onlyif failed (onlyif != 0) * unless succeeded (unless == 0) else return True ''' # never use VT for onlyif/unless executions because this will lead # to quote ...
Run the given command only if the watch statement calls it. .. note:: Use :mod:`cmd.run <salt.states.cmd.run>` together with :mod:`onchanges </ref/states/requisites#onchanges>` instead of :mod:`cmd.wait <salt.states.cmd.wait>`. name The command to execute, remember that the command wi...
def wait(name, onlyif=None, unless=None, creates=None, cwd=None, root=None, runas=None, shell=None, env=(), stateful=False, umask=None, output_loglevel='debug', hide_output=False, use_vt=False, ...
Download a script from a remote source and execute it only if a watch statement calls it. source The source script being downloaded to the minion, this source script is hosted on the salt master server. If the file is located on the master in the directory named spam, and is called egg...
def wait_script(name, source=None, template=None, onlyif=None, unless=None, cwd=None, runas=None, shell=None, env=None, stateful=False, umask=None, ...
Run a command if certain circumstances are met. Use ``cmd.wait`` if you want to use the ``watch`` requisite. name The command to execute, remember that the command will execute with the path and permissions of the salt-minion. onlyif A command to run as a check, run the named comm...
def run(name, onlyif=None, unless=None, creates=None, cwd=None, root=None, runas=None, shell=None, env=None, prepend_path=None, stateful=False, umask=None, output_loglevel='debug', hide_output=False, timeout=...
Download a script and execute it with specified arguments. source The location of the script to download. If the file is located on the master in the directory named spam, and is called eggs, the source string is salt://spam/eggs template If this setting is applied then the nam...
def script(name, source=None, template=None, onlyif=None, unless=None, creates=None, cwd=None, runas=None, shell=None, env=None, stateful=False, umask=None, timeout=None, use_vt...
Invoke a pre-defined Python function with arguments specified in the state declaration. This function is mainly used by the :mod:`salt.renderers.pydsl` renderer. The interpretation of ``onlyif`` and ``unless`` arguments are identical to those of :mod:`cmd.run <salt.states.cmd.run>`, and all other a...
def call(name, func, args=(), kws=None, onlyif=None, unless=None, creates=None, output_loglevel='debug', hide_output=False, use_vt=False, **kwargs): ''' Invoke a pre-defined Python function with arguments specified in the ...
Execute a cmd function based on a watch call .. note:: This state exists to support special handling of the ``watch`` :ref:`requisite <requisites>`. It should not be called directly. Parameters for this function should be set by the state being triggered.
def mod_watch(name, **kwargs): ''' Execute a cmd function based on a watch call .. note:: This state exists to support special handling of the ``watch`` :ref:`requisite <requisites>`. It should not be called directly. Parameters for this function should be set by the state being tr...
Check version of novaclient
def check_nova(): ''' Check version of novaclient ''' if HAS_NOVA: novaclient_ver = _LooseVersion(novaclient.__version__) min_ver = _LooseVersion(NOVACLIENT_MINVER) if min_ver <= novaclient_ver: return HAS_NOVA log.debug('Newer novaclient version required. Mi...
Exctract API version from provided URL
def _get_version_from_url(self, url): ''' Exctract API version from provided URL ''' regex = re.compile(r"^https?:\/\/.*\/(v[0-9])(\.[0-9])?(\/)?$") try: ver = regex.match(url) if ver.group(1): retver = ver.group(1) if ver.g...
Keystone API version discovery
def _discover_ks_version(self, url): ''' Keystone API version discovery ''' result = salt.utils.http.query(url, backend='requests', status=True, decode=True, decode_type='json') versions = json.loads(result['body']) try: links = [ver['links'] for ver in versio...
Make output look like libcloud output for consistency
def server_show_libcloud(self, uuid): ''' Make output look like libcloud output for consistency ''' server_info = self.server_show(uuid) server = next(six.itervalues(server_info)) server_name = next(six.iterkeys(server_info)) if not hasattr(self, 'password'): ...
Boot a cloud server.
def boot(self, name, flavor_id=0, image_id=0, timeout=300, **kwargs): ''' Boot a cloud server. ''' nt_ks = self.compute_conn kwargs['name'] = name kwargs['flavor'] = flavor_id kwargs['image'] = image_id or None ephemeral = kwargs.pop('ephemeral', []) ...
Change server(uuid's) root password
def root_password(self, server_id, password): ''' Change server(uuid's) root password ''' nt_ks = self.compute_conn nt_ks.servers.change_password(server_id, password)
Find a server by its name
def server_by_name(self, name): ''' Find a server by its name ''' return self.server_show_libcloud( self.server_list().get(name, {}).get('id', '') )
List all block volumes
def volume_list(self, search_opts=None): ''' List all block volumes ''' if self.volume_conn is None: raise SaltCloudSystemExit('No cinder endpoint available') nt_ks = self.volume_conn volumes = nt_ks.volumes.list(search_opts=search_opts) response = {} ...
Organize information about a volume from the volume_id
def _volume_get(self, volume_id): ''' Organize information about a volume from the volume_id ''' if self.volume_conn is None: raise SaltCloudSystemExit('No cinder endpoint available') nt_ks = self.volume_conn volume = nt_ks.volumes.get(volume_id) respo...
Show one volume
def volume_show(self, name): ''' Show one volume ''' if self.volume_conn is None: raise SaltCloudSystemExit('No cinder endpoint available') nt_ks = self.volume_conn volumes = self.volume_list( search_opts={'display_name': name}, ) v...
Create a block device
def volume_create(self, name, size=100, snapshot=None, voltype=None, availability_zone=None): ''' Create a block device ''' if self.volume_conn is None: raise SaltCloudSystemExit('No cinder endpoint available') nt_ks = self.volume_conn re...
Delete a block device
def volume_delete(self, name): ''' Delete a block device ''' if self.volume_conn is None: raise SaltCloudSystemExit('No cinder endpoint available') nt_ks = self.volume_conn try: volume = self.volume_show(name) except KeyError as exc: ...
Detach a block device
def volume_detach(self, name, timeout=300): ''' Detach a block device ''' try: volume = self.volume_show(name) except KeyError as exc: raise SaltCloudSystemExit('Unable to find {0} volume: {1}'.format(name, exc))...
Attach a block device
def volume_attach(self, name, server_name, device='/dev/xvdb', timeout=300): ''' Attach a block device ''' try: volume = self.volume_show(name) except KeyError as exc: ...
Resume a server
def resume(self, instance_id): ''' Resume a server ''' nt_ks = self.compute_conn response = nt_ks.servers.resume(instance_id) return True
Suspend a server
def suspend(self, instance_id): ''' Suspend a server ''' nt_ks = self.compute_conn response = nt_ks.servers.suspend(instance_id) return True
Lock an instance
def lock(self, instance_id): ''' Lock an instance ''' nt_ks = self.compute_conn response = nt_ks.servers.lock(instance_id) return True
Delete a server
def delete(self, instance_id): ''' Delete a server ''' nt_ks = self.compute_conn response = nt_ks.servers.delete(instance_id) return True
Return a list of available flavors (nova flavor-list)
def flavor_list(self, **kwargs): ''' Return a list of available flavors (nova flavor-list) ''' nt_ks = self.compute_conn ret = {} for flavor in nt_ks.flavors.list(**kwargs): links = {} for link in flavor.links: links[link['rel']] = ...
Create a flavor
def flavor_create(self, name, # pylint: disable=C0103 flavor_id=0, # pylint: disable=C0103 ram=0, disk=0, vcpus=1, is_public=True): ''' Create a flavor ...
Delete a flavor
def flavor_delete(self, flavor_id): # pylint: disable=C0103 ''' Delete a flavor ''' nt_ks = self.compute_conn nt_ks.flavors.delete(flavor_id) return 'Flavor deleted: {0}'.format(flavor_id)
Return a list of project IDs assigned to flavor ID
def flavor_access_list(self, **kwargs): ''' Return a list of project IDs assigned to flavor ID ''' flavor_id = kwargs.get('flavor_id') nt_ks = self.compute_conn ret = {flavor_id: []} flavor_accesses = nt_ks.flavor_access.list(flavor=flavor_id, **kwargs) fo...
Add a project to the flavor access list
def flavor_access_add(self, flavor_id, project_id): ''' Add a project to the flavor access list ''' nt_ks = self.compute_conn ret = {flavor_id: []} flavor_accesses = nt_ks.flavor_access.add_tenant_access(flavor_id, project_id) for project in flavor_accesses: ...
Remove a project from the flavor access list
def flavor_access_remove(self, flavor_id, project_id): ''' Remove a project from the flavor access list ''' nt_ks = self.compute_conn ret = {flavor_id: []} flavor_accesses = nt_ks.flavor_access.remove_tenant_access(flavor_id, project_id) for project in flavor_acce...
List keypairs
def keypair_list(self): ''' List keypairs ''' nt_ks = self.compute_conn ret = {} for keypair in nt_ks.keypairs.list(): ret[keypair.name] = { 'name': keypair.name, 'fingerprint': keypair.fingerprint, 'public_key':...
Add a keypair
def keypair_add(self, name, pubfile=None, pubkey=None): ''' Add a keypair ''' nt_ks = self.compute_conn if pubfile: with salt.utils.files.fopen(pubfile, 'r') as fp_: pubkey = salt.utils.stringutils.to_unicode(fp_.read()) if not pubkey: ...
Delete a keypair
def keypair_delete(self, name): ''' Delete a keypair ''' nt_ks = self.compute_conn nt_ks.keypairs.delete(name) return 'Keypair deleted: {0}'.format(name)
Show image details and metadata
def image_show(self, image_id): ''' Show image details and metadata ''' nt_ks = self.compute_conn image = nt_ks.images.get(image_id) links = {} for link in image.links: links[link['rel']] = link['href'] ret = { 'name': image.name, ...
List server images
def image_list(self, name=None): ''' List server images ''' nt_ks = self.compute_conn ret = {} for image in nt_ks.images.list(): links = {} for link in image.links: links[link['rel']] = link['href'] ret[image.name] = { ...
Set image metadata
def image_meta_set(self, image_id=None, name=None, **kwargs): # pylint: disable=C0103 ''' Set image metadata ''' nt_ks = self.compute_conn if name: for image in nt_ks.images.list(): ...
Delete image metadata
def image_meta_delete(self, image_id=None, # pylint: disable=C0103 name=None, keys=None): ''' Delete image metadata ''' nt_ks = self.compute_conn if name: for image in nt_ks.images.list(...
List servers
def server_list(self): ''' List servers ''' nt_ks = self.compute_conn ret = {} for item in nt_ks.servers.list(): try: ret[item.name] = { 'id': item.id, 'name': item.name, 'state': item...
List minimal information about servers
def server_list_min(self): ''' List minimal information about servers ''' nt_ks = self.compute_conn ret = {} for item in nt_ks.servers.list(detailed=False): try: ret[item.name] = { 'id': item.id, 'state':...
Detailed list of servers
def server_list_detailed(self): ''' Detailed list of servers ''' nt_ks = self.compute_conn ret = {} for item in nt_ks.servers.list(): try: ret[item.name] = { 'OS-EXT-SRV-ATTR': {}, 'OS-EXT-STS': {}, ...
Show details of one server
def server_show(self, server_id): ''' Show details of one server ''' ret = {} try: servers = self.server_list_detailed() except AttributeError: raise SaltCloudSystemExit('Corrupt server in server_list_detailed. Remove corrupt servers.') for...
Create a security group
def secgroup_create(self, name, description): ''' Create a security group ''' nt_ks = self.compute_conn nt_ks.security_groups.create(name, description) ret = {'name': name, 'description': description} return ret
Delete a security group
def secgroup_delete(self, name): ''' Delete a security group ''' nt_ks = self.compute_conn for item in nt_ks.security_groups.list(): if item.name == name: nt_ks.security_groups.delete(item.id) return {name: 'Deleted security group: {0}'...
List security groups
def secgroup_list(self): ''' List security groups ''' nt_ks = self.compute_conn ret = {} for item in nt_ks.security_groups.list(): ret[item.name] = { 'name': item.name, 'description': item.description, 'id': item...
List items
def _item_list(self): ''' List items ''' nt_ks = self.compute_conn ret = [] for item in nt_ks.items.list(): ret.append(item.__dict__) return ret
Parse the returned network list
def _network_show(self, name, network_lst): ''' Parse the returned network list ''' for net in network_lst: if net.label == name: return net.__dict__ return {}