text
stringlengths
81
112k
Set a single key .. note:: This will strip comments from your config file def apply(key, value): ''' Set a single key .. note:: This will strip comments from your config file ''' path = __opts__['conf_file'] if os.path.isdir(path): path = os.path.join(path, 'mast...
Update master config with ``yaml_contents``. Writes ``yaml_contents`` to a file named ``file_name.conf`` under the folder specified by ``default_include``. This folder is named ``master.d`` by default. Please look at :conf_master:`include-configuration` for more information. Exampl...
Idea from softwareproperties.ppa. Uses urllib2 which sacrifices server cert verification. This is used as fall-back code or for secure PPAs :param owner_name: :param ppa_name: :return: def _get_ppa_info_from_launchpad(owner_name, ppa_name): ''' Idea from softwareproperties.ppa. Uses u...
Call apt* utilities. def _call_apt(args, scope=True, **kwargs): ''' Call apt* utilities. ''' cmd = [] if scope and salt.utils.systemd.has_scope(__context__) and __salt__['config.get']('systemd.scope', True): cmd.extend(['systemd-run', '--scope']) cmd.extend(args) params = {'output_...
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 - ``...
.. 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...
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. ...
.. 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...
.. 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...
.. 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...
.. 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...
.. 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...
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...
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'] ...
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...
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 ...
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 ...
.. 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...
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.m...
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-b...
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 ...
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. ...
.. 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:...
.. 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 ...
.. 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...
Modify one or more values for a repo. If the repo does not exist, it will be created, so long as the definition is well formed. For Ubuntu the ``ppa:<project>/repo`` format is acceptable. ``ppa:`` format can only be used to create a new repository. The following options are available to modify a repo...
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...
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. '''...
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...
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...
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 ...
.. 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...
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...
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. ...
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 ...
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...
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 cont...
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...
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...
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...
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...
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'](n...
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 ...
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> d...
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='de...
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.que...
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 e...
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 012345...
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(_...
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...
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 ...
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...
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...
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 ...
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 ...
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...
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: ...
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...
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...
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...
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...
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...
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...
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): ...
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 nov...
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...
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 =...
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(serve...
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(...
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', '') )
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 ...
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...
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}, ...
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...
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 ...
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: ...
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 KeyErr...
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
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
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...
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): ''' Cr...
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.flavo...
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) ...
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, ...
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, ...
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 p...
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 = { ...
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'] r...
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 imag...
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, ...
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...
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': {}, ...
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 co...