text
stringlengths
81
112k
Return the status for a service. If the name contains globbing, a dict mapping service name to PID or empty string is returned. .. versionchanged:: 2018.3.0 The service name can now be a glob (e.g. ``salt*``) Args: name (str): The name of the service to check sig (str): Signatu...
Return a list of all available services CLI Example: .. code-block:: bash salt '*' service.get_all def get_all(): ''' Return a list of all available services CLI Example: .. code-block:: bash salt '*' service.get_all ''' if not os.path.isdir(_GRAINMAP.get(__grains_...
Set up neutron credentials def _auth(profile=None): ''' Set up neutron credentials ''' credentials = __salt__['config.option'](profile) kwargs = { 'username': credentials['keystone.user'], 'password': credentials['keystone.password'], 'tenant_name': credentials['keystone.ten...
Check neutron for all data def ext_pillar(minion_id, pillar, # pylint: disable=W0613 conf): ''' Check neutron for all data ''' comps = conf.split() profile = None if comps[0]: profile = comps[0] conn = _auth(profile) ret = {} networks = conn....
Ensure that the named database is present with the specified options name The name of the database to manage containment Defaults to NONE options Can be a list of strings, a dictionary, or a list of dictionaries def present(name, containment='NONE', options=None, **kwargs): '''...
Read in the ``file_client`` option and return the correct type of file server def get_file_client(opts, pillar=False): ''' Read in the ``file_client`` option and return the correct type of file server ''' client = opts.get('file_client', 'remote') if pillar and client == 'local': cl...
Convert top level keys from bytes to strings if possible. This is necessary because Python 3 makes a distinction between these types. def decode_dict_keys_to_str(src): ''' Convert top level keys from bytes to strings if possible. This is necessary because Python 3 makes a distinction between th...
Make sure that this path is intended for the salt master and trim it def _check_proto(self, path): ''' Make sure that this path is intended for the salt master and trim it ''' if not path.startswith('salt://'): raise MinionError('Unsupported path: {0}'.format(path)) ...
Helper util to return a list of files in a directory def _file_local_list(self, dest): ''' Helper util to return a list of files in a directory ''' if os.path.isdir(dest): destdir = dest else: destdir = os.path.dirname(dest) filelist = set() ...
Return the local location to cache the file, cache dirs will be made def _cache_loc(self, path, saltenv='base', cachedir=None): ''' Return the local location to cache the file, cache dirs will be made ''' cachedir = self.get_cachedir(cachedir) dest = salt.utils.path.join(cachedi...
Copies a file from the local files or master depending on implementation def get_file(self, path, dest='', makedirs=False, saltenv='base', gzip=None, cachedir=None): ''' Copies a file from the ...
Pull a file down from the file server and store it in the minion file cache def cache_file(self, path, saltenv='base', cachedir=None, source_hash=None): ''' Pull a file down from the file server and store it in the minion file cache ''' return self.get_url( p...
Download a list of files stored on the master and put them in the minion file cache def cache_files(self, paths, saltenv='base', cachedir=None): ''' Download a list of files stored on the master and put them in the minion file cache ''' ret = [] if isinstance(pat...
Download and cache all files on a master in a specified environment def cache_master(self, saltenv='base', cachedir=None): ''' Download and cache all files on a master in a specified environment ''' ret = [] for path in self.file_list(saltenv): ret.append( ...
Download all of the files in a subdir of the master def cache_dir(self, path, saltenv='base', include_empty=False, include_pat=None, exclude_pat=None, cachedir=None): ''' Download all of the files in a subdir of the master ''' ret = [] path = self._check_proto...
Cache a local file on the minion in the localfiles cache def cache_local_file(self, path, **kwargs): ''' Cache a local file on the minion in the localfiles cache ''' dest = os.path.join(self.opts['cachedir'], 'localfiles', path.lstrip('/')) destdir = ...
List files in the local minion files and localfiles caches def file_local_list(self, saltenv='base'): ''' List files in the local minion files and localfiles caches ''' filesdest = os.path.join(self.opts['cachedir'], 'files', saltenv) localfilesdest = os.path.join(self.opts['cac...
Returns the full path to a file if it is cached locally on the minion otherwise returns a blank string def is_cached(self, path, saltenv='base', cachedir=None): ''' Returns the full path to a file if it is cached locally on the minion otherwise returns a blank string ''' ...
Return the expected cache location for the specified URL and environment. def cache_dest(self, url, saltenv='base', cachedir=None): ''' Return the expected cache location for the specified URL and environment. ''' proto = urlparse(url).scheme if proto == '': ...
Return a list of all available sls modules on the master for a given environment def list_states(self, saltenv): ''' Return a list of all available sls modules on the master for a given environment ''' states = set() for path in self.file_list(saltenv): ...
Get a state file from the master and store it in the local minion cache; return the location of the file def get_state(self, sls, saltenv, cachedir=None): ''' Get a state file from the master and store it in the local minion cache; return the location of the file ''' if ...
Get a directory recursively from the salt-master def get_dir(self, path, dest='', saltenv='base', gzip=None, cachedir=None): ''' Get a directory recursively from the salt-master ''' ret = [] # Strip trailing slash path = self._check_proto(path).rstrip('/'...
Get a single file from a URL. def get_url(self, url, dest, makedirs=False, saltenv='base', no_cache=False, cachedir=None, source_hash=None): ''' Get a single file from a URL. ''' url_data = urlparse(url) url_scheme = url_data.scheme url_path = os.path.joi...
Cache a file then process it as a template def get_template( self, url, dest, template='jinja', makedirs=False, saltenv='base', cachedir=None, **kwargs): ''' Cache a file then process it as a template ...
Return the extrn_filepath for a given url def _extrn_path(self, url, saltenv, cachedir=None): ''' Return the extrn_filepath for a given url ''' url_data = urlparse(url) if salt.utils.platform.is_windows(): netloc = salt.utils.path.sanitize_win_path(url_data.netloc) ...
Locate the file path def _find_file(self, path, saltenv='base'): ''' Locate the file path ''' fnd = {'path': '', 'rel': ''} if salt.utils.url.is_escaped(path): # The path arguments are escaped path = salt.utils.url.unescape(path) f...
Copies a file from the local files directory into :param:`dest` gzip compression settings are ignored for local files def get_file(self, path, dest='', makedirs=False, saltenv='base', gzip=None, cachedir=None)...
Return a list of files in the given environment with optional relative prefix path to limit directory traversal def file_list(self, saltenv='base', prefix=''): ''' Return a list of files in the given environment with optional relative prefix path to limit directory traversal '''...
Return either a file path or the result of a remote find_file call. def __get_file_path(self, path, saltenv='base'): ''' Return either a file path or the result of a remote find_file call. ''' try: path = self._check_proto(path) except MinionError as err: ...
Return the hash of a file, to get the hash of a file in the pillar_roots prepend the path with salt://<file on server> otherwise, prepend the file with / for a local file. def hash_file(self, path, saltenv='base'): ''' Return the hash of a file, to get the hash of a file in the pillar_r...
Return the hash of a file, to get the hash of a file in the pillar_roots prepend the path with salt://<file on server> otherwise, prepend the file with / for a local file. Additionally, return the stat result of the file, or None if no stat results were found. def hash_and_stat_file(se...
Return the available environments def envs(self): ''' Return the available environments ''' ret = [] for saltenv in self.opts['pillar_roots']: ret.append(saltenv) return ret
Reset the channel, in the event of an interruption def _refresh_channel(self): ''' Reset the channel, in the event of an interruption ''' self.channel = salt.transport.client.ReqChannel.factory(self.opts) return self.channel
Get a single file from the salt-master path must be a salt server location, aka, salt://path/to/file, if dest is omitted, then the downloaded file will be placed in the minion cache def get_file(self, path, dest='', makedirs=False, ...
List the dirs on the master def dir_list(self, saltenv='base', prefix=''): ''' List the dirs on the master ''' load = {'saltenv': saltenv, 'prefix': prefix, 'cmd': '_dir_list'} return salt.utils.data.decode(self.channel.send(load)) if six.PY2 \ ...
Common code for hashing and stating files def __hash_and_stat_file(self, path, saltenv='base'): ''' Common code for hashing and stating files ''' try: path = self._check_proto(path) except MinionError as err: if not os.path.isfile(path): l...
The same as hash_file, but also return the file's mode, or None if no mode data is present. def hash_and_stat_file(self, path, saltenv='base'): ''' The same as hash_file, but also return the file's mode, or None if no mode data is present. ''' hash_result = self.hash_fil...
Return a list of the files in the file server's specified environment def list_env(self, saltenv='base'): ''' Return a list of the files in the file server's specified environment ''' load = {'saltenv': saltenv, 'cmd': '_file_list'} return salt.utils.data.decode(...
Return a list of available environments def envs(self): ''' Return a list of available environments ''' load = {'cmd': '_file_envs'} return salt.utils.data.decode(self.channel.send(load)) if six.PY2 \ else self.channel.send(load)
Return the metadata derived from the master_tops system def master_tops(self): ''' Return the metadata derived from the master_tops system ''' log.debug( 'The _ext_nodes master function has been renamed to _master_tops. ' 'To ensure compatibility when using older...
Check destination for the archives. :return: def check_destination(self, location, group): ''' Check destination for the archives. :return: ''' # Pre-create destination, since rsync will # put one file named as group try: destination = os.path...
Sync archives to a central place. :param name: :param group: :param filename: :param host: :param location: :param move: :param all: :return: def collected(self, group, filename=None, host=None, location=None, move=True, all=True): ''' Sy...
Takes minion support config data. :param profile: :param pillar: :param archive: :param output: :return: def taken(self, profile='default', pillar=None, archive=None, output='nested'): ''' Takes minion support config data. :param profile: :param...
Create a VMM disk with the specified `name` and `size`. size: Size in megabytes, or use a specifier such as M, G, T. CLI Example: .. code-block:: bash salt '*' vmctl.create_disk /path/to/disk.img size=10G def create_disk(name, size): ''' Create a VMM disk with the specified `nam...
Load additional configuration from the specified file. path Path to the configuration file. CLI Example: .. code-block:: bash salt '*' vmctl.load path=/etc/vm.switches.conf def load(path): ''' Load additional configuration from the specified file. path Path to the c...
Remove all stopped VMs and reload configuration from the default configuration file. CLI Example: .. code-block:: bash salt '*' vmctl.reload def reload(): ''' Remove all stopped VMs and reload configuration from the default configuration file. CLI Example: .. code-block:: bash ...
Reset the running state of VMM or a subsystem. all: Reset the running state. switches: Reset the configured switches. vms: Reset and terminate all VMs. CLI Example: .. code-block:: bash salt '*' vmctl.reset all=True def reset(all=False, vms=False, switches=Fal...
Starts a VM defined by the specified parameters. When both a name and id are provided, the id is ignored. name: Name of the defined VM. id: VM id. bootpath: Path to a kernel or BIOS image to load. disk: Path to a single disk to use. disks: List of mul...
List VMs running on the host, or only the VM specified by ``id``. When both a name and id are provided, the id is ignored. name: Name of the defined VM. id: VM id. CLI Example: .. code-block:: bash salt '*' vmctl.status # to list all VMs salt '*' vmctl...
Stop (terminate) the VM identified by the given id or name. When both a name and id are provided, the id is ignored. name: Name of the defined VM. id: VM id. CLI Example: .. code-block:: bash salt '*' vmctl.stop name=alpine def stop(name=None, id=None): ''' Stop...
Run one or more named munin plugins CLI Example: .. code-block:: bash salt '*' munin.run uptime salt '*' munin.run uptime,cpu,load,memory def run(plugins): ''' Run one or more named munin plugins CLI Example: .. code-block:: bash salt '*' munin.run uptime s...
Run all the munin plugins CLI Example: .. code-block:: bash salt '*' munin.run_all def run_all(): ''' Run all the munin plugins CLI Example: .. code-block:: bash salt '*' munin.run_all ''' plugins = list_plugins() ret = {} for plugin in plugins: ret...
List all the munin plugins CLI Example: .. code-block:: bash salt '*' munin.list_plugins def list_plugins(): ''' List all the munin plugins CLI Example: .. code-block:: bash salt '*' munin.list_plugins ''' pluginlist = os.listdir(PLUGINDIR) ret = [] for plu...
Return a list of all installed kernels. CLI Example: .. code-block:: bash salt '*' kernelpkg.list_installed def list_installed(): ''' Return a list of all installed kernels. CLI Example: .. code-block:: bash salt '*' kernelpkg.list_installed ''' result = __salt__['...
Upgrade the kernel and optionally reboot the system. reboot : False Request a reboot if a new kernel is available. at_time : immediate Schedule the reboot at some point in the future. This argument is ignored if ``reboot=False``. See :py:func:`~salt.modules.system.reboot` for m...
Remove a specific version of the kernel. release The release number of an installed kernel. This must be the entire release number as returned by :py:func:`~salt.modules.kernelpkg_linux_yum.list_installed`, not the package name. CLI Example: .. code-block:: bash salt '*' ...
A decorator to be used module functions which need to cache their context. To evaluate a __context__ and re-hydrate it if a given key is empty or contains no items, pass a list of keys to evaulate. def context_cache(func): ''' A decorator to be used module functions which need to cache their c...
Enforce the TTL to a specific key, delete if its past TTL def _enforce_ttl_key(self, key): ''' Enforce the TTL to a specific key, delete if its past TTL ''' if key not in self._key_cache_time or self._ttl == 0: return if time.time() - self._key_cache_time[key] > self...
Enforce the TTL to a specific key, delete if its past TTL def _enforce_ttl_key(self, key): ''' Enforce the TTL to a specific key, delete if its past TTL ''' if key not in self._key_cache_time or self._ttl == 0: return if time.time() - self._key_cache_time[key] > self...
Read in from disk def _read(self): ''' Read in from disk ''' if msgpack is None: log.error('Cache cannot be read from the disk: msgpack is missing') elif not os.path.exists(self._path): log.debug('Cache path does not exist for reading: %s', self._path) ...
Write content of the entire cache to disk def store(self): ''' Write content of the entire cache to disk ''' if msgpack is None: log.error('Cache cannot be stored on disk: msgpack is missing') else: # TODO Dir hashing? try: wit...
published the given minions to the ConCache def put_cache(self, minions): ''' published the given minions to the ConCache ''' self.cupd_out.send(self.serial.dumps(minions))
queries the ConCache for a list of currently connected minions def get_cached(self): ''' queries the ConCache for a list of currently connected minions ''' msg = self.serial.dumps('minions') self.creq_out.send(msg) min_list = self.serial.loads(self.creq_out.recv()) ...
Sweep the cache and remove the outdated or least frequently used entries def sweep(self): ''' Sweep the cache and remove the outdated or least frequently used entries ''' if self.max_age < time.time() - self.timestamp: self.clear() self.timestamp ...
Get a compiled regular expression object based on pattern and cache it when it is not in the cache already def get(self, pattern): ''' Get a compiled regular expression object based on pattern and cache it when it is not in the cache already ''' try: self.cac...
Cache the given context to disk def cache_context(self, context): ''' Cache the given context to disk ''' if not os.path.isdir(os.path.dirname(self.cache_path)): os.mkdir(os.path.dirname(self.cache_path)) with salt.utils.files.fopen(self.cache_path, 'w+b') as cache: ...
Retrieve a context cache from disk def get_cache_context(self): ''' Retrieve a context cache from disk ''' with salt.utils.files.fopen(self.cache_path, 'rb') as cache: return salt.utils.data.decode(self.serial.load(cache))
Strip/replace reStructuredText directives in docstrings def strip_rst(docs): ''' Strip/replace reStructuredText directives in docstrings ''' for func, docstring in six.iteritems(docs): log.debug('Stripping docstring for %s', func) if not docstring: continue docstring...
Parse a docstring into its parts. Currently only parses dependencies, can be extended to parse whatever is needed. Parses into a dictionary: { 'full': full docstring, 'deps': list of dependencies (empty list if none) } def parse_docstring(docstring): ''' Pa...
Ensure the cache cluster exists. name Name of the cache cluster (cache cluster id). engine The name of the cache engine to be used for this cache cluster. Valid values are memcached or redis. cache_node_type The compute and memory capacity of the nodes in the cache cluster...
Ensure ElastiCache subnet group exists. .. versionadded:: 2015.8.0 name The name for the ElastiCache subnet group. This value is stored as a lowercase string. subnet_ids A list of VPC subnet IDs for the cache subnet group. Exclusive with subnet_names. subnet_names A list of ...
Ensure the a replication group is create. name Name of replication group wait Waits for the group to be available primary_cluster_id Name of the master cache node replication_group_description Description for the group region Region to connect to. ke...
Eliminates None entries from the features of the endpoint dict. def _clear_dict(endpoint_props): ''' Eliminates None entries from the features of the endpoint dict. ''' return dict( (prop_name, prop_val) for prop_name, prop_val in six.iteritems(endpoint_props) if prop_val is not...
Ignores some keys that might be different without any important info. These keys are defined under _DO_NOT_COMPARE_FIELDS. def _ignore_keys(endpoint_props): ''' Ignores some keys that might be different without any important info. These keys are defined under _DO_NOT_COMPARE_FIELDS. ''' return ...
Returns an unique list of dictionaries given a list that may contain duplicates. def _unique(list_of_dicts): ''' Returns an unique list of dictionaries given a list that may contain duplicates. ''' unique_list = [] for ele in list_of_dicts: if ele not in unique_list: unique_list...
Both _clear_dict and _ignore_keys in a single iteration. def _clear_ignore(endpoint_props): ''' Both _clear_dict and _ignore_keys in a single iteration. ''' return dict( (prop_name, prop_val) for prop_name, prop_val in six.iteritems(endpoint_props) if prop_name not in _DO_NOT_CO...
Find a matching element in a list. def _find_match(ele, lst): ''' Find a matching element in a list. ''' for _ele in lst: for match_key in _MATCH_KEYS: if _ele.get(match_key) == ele.get(match_key): return ele
Return a dict with fields that differ between two dicts. def _update_on_fields(prev_ele, new_ele): ''' Return a dict with fields that differ between two dicts. ''' fields_update = dict( (prop_name, prop_val) for prop_name, prop_val in six.iteritems(new_ele) if new_ele.get(prop_n...
Compares configured endpoints with the expected configuration and returns the differences. def _compute_diff(expected_endpoints, configured_endpoints): ''' Compares configured endpoints with the expected configuration and returns the differences. ''' new_endpoints = [] update_endpoints = [] rem...
Insert a new entry under a specific endpoint. endpoint: incidents Insert under this specific endpoint. page_id Page ID. Can also be specified in the config file. api_key API key. Can also be specified in the config file. api_version: 1 API version. Can also be specifi...
Update attribute(s) of a specific endpoint. id The unique ID of the enpoint entry. endpoint: incidents Endpoint name. page_id Page ID. Can also be specified in the config file. api_key API key. Can also be specified in the config file. api_version: 1 API ...
Remove an entry from an endpoint. endpoint: incidents Request a specific endpoint. page_id Page ID. Can also be specified in the config file. api_key API key. Can also be specified in the config file. api_version: 1 API version. Can also be specified in the config fil...
Manage the StatusPage configuration. config Dictionary with the expected configuration of the StatusPage. The main level keys of this dictionary represent the endpoint name. If a certain endpoint does not exist in this structure, it will be ignored / not configured. page_id Pag...
Ensure a user is present .. code-block:: yaml ensure example test user 1: splunk.user_present: - realname: 'Example TestUser1' - name: 'exampleuser' - email: 'example@domain.com' - roles: ['user'] The following parameters are...
Ensure a splunk user is absent .. code-block:: yaml ensure example test user 1: splunk.absent: - email: 'example@domain.com' - name: 'exampleuser' The following parameters are required: email This is the email of the user in splunk name ...
Set the keyboard layout for the system name The keyboard layout to use def system(name): ''' Set the keyboard layout for the system name The keyboard layout to use ''' ret = {'name': name, 'changes': {}, 'result': None, 'comment': ''} if __...
Set the keyboard layout for XOrg layout The keyboard layout to use def xorg(name): ''' Set the keyboard layout for XOrg layout The keyboard layout to use ''' ret = {'name': name, 'changes': {}, 'result': None, 'comment': ''} if __salt__['ke...
Helper function that will wait for the status of the service to match the provided status before an end time expires. Used for service stop and start .. versionadded:: 2017.7.9,2018.3.4 Args: service_name (str): The name of the service end_time (float): A future ti...
r''' Helper function to properly format the path to the binary for the service Must be wrapped in double quotes to account for paths that have spaces. For example: ``"C:\Program Files\Path\to\bin.exe"`` Args: cmd (str): Full path to the binary Returns: str: Properly quoted pat...
Return a list of enabled services. Enabled is defined as a service that is marked to Auto Start. Returns: list: A list of enabled services CLI Example: .. code-block:: bash salt '*' service.get_enabled def get_enabled(): ''' Return a list of enabled services. Enabled is defi...
Check if a service is available on the system. Args: name (str): The name of the service to check Returns: bool: ``True`` if the service is available, ``False`` otherwise CLI Example: .. code-block:: bash salt '*' service.available <service name> def available(name): ''...
Returns a list of all services on the system. def _get_services(): ''' Returns a list of all services on the system. ''' handle_scm = win32service.OpenSCManager( None, None, win32service.SC_MANAGER_ENUMERATE_SERVICE) try: services = win32service.EnumServicesStatusEx(handle_scm) ...
Return all installed services Returns: list: Returns a list of all services on the system. CLI Example: .. code-block:: bash salt '*' service.get_all def get_all(): ''' Return all installed services Returns: list: Returns a list of all services on the system. C...
The Display Name is what is displayed in Windows when services.msc is executed. Each Display Name has an associated Service Name which is the actual name of the service. This function allows you to discover the Service Name by returning a dictionary of Display Names and Service Names, or filter by add...
Get information about a service on the system Args: name (str): The name of the service. This is not the display name. Use ``get_service_name`` to find the service name. Returns: dict: A dictionary containing information about the service. CLI Example: .. code-block:: bas...
Start the specified service. .. warning:: You cannot start a disabled service in Windows. If the service is disabled, it will be changed to ``Manual`` start. Args: name (str): The name of the service to start timeout (int): The time in seconds to wait for the servi...
Stop the specified service Args: name (str): The name of the service to stop timeout (int): The time in seconds to wait for the service to stop before returning. Default is 90 seconds .. versionadded:: 2017.7.9,2018.3.4 with_deps (bool): If...
Restart the named service. This issues a stop command followed by a start. Args: name: The name of the service to restart. .. note:: If the name passed is ``salt-minion`` a scheduled task is created and executed to restart the salt-minion service. timeo...
Create a task in Windows task scheduler to enable restarting the salt-minion Returns: bool: ``True`` if successful, otherwise ``False`` CLI Example: .. code-block:: bash salt '*' service.create_win_salt_restart_task() def create_win_salt_restart_task(): ''' Create a task in Wind...
Return the status for a service. If the name contains globbing, a dict mapping service name to True/False values is returned. .. versionchanged:: 2018.3.0 The service name can now be a glob (e.g. ``salt*``) Args: name (str): The name of the service to check Returns: bool: ...