text
stringlengths
81
112k
Do the DRY thing and only call subprocess.Popen() once def _run(cmd, cwd=None, stdin=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE, output_encoding=None, output_loglevel='debug', log_callback=None, runas=None, group=None, ...
Helper for running commands quietly for minion startup def _run_quiet(cmd, cwd=None, stdin=None, output_encoding=None, runas=None, shell=DEFAULT_SHELL, python_shell=False, env=None, template=None, ...
Check if we are running in the globalzone def _is_globalzone(): ''' Check if we are running in the globalzone ''' if not __grains__['kernel'] == 'SunOS': return False zonename = __salt__['cmd.run_all']('zonename') if zonename['retcode']: return False if zonename['stdout'] =...
List all zones verbose : boolean display additional zone information installed : boolean include installed zones in output configured : boolean include configured zones in output hide_global : boolean do not include global zone CLI Example: .. code-block:: bash...
Boot (or activate) the specified zone. zone : string name or uuid of the zone single : boolean boots only to milestone svc:/milestone/single-user:default. altinit : string valid path to an alternative executable to be the primordial process. smf_options : string include ...
Attach the specified zone. zone : string name of the zone force : boolean force the zone into the "installed" state with no validation brand_opts : string brand specific options to pass CLI Example: .. code-block:: bash salt '*' zoneadm.attach lawrence sal...
Prepares a zone for running applications. zone : string name or uuid of the zone CLI Example: .. code-block:: bash salt '*' zoneadm.ready clementine def ready(zone): ''' Prepares a zone for running applications. zone : string name or uuid of the zone CLI Exampl...
Check to make sure the configuration of the specified zone can safely be installed on the machine. zone : string name of the zone CLI Example: .. code-block:: bash salt '*' zoneadm.verify dolores def verify(zone): ''' Check to make sure the configuration of the specified ...
Move zone to new zonepath. zone : string name or uuid of the zone zonepath : string new zonepath CLI Example: .. code-block:: bash salt '*' zoneadm.move meave /sweetwater/meave def move(zone, zonepath): ''' Move zone to new zonepath. zone : string name o...
Install the specified zone from the system. zone : string name of the zone nodataset : boolean do not create a ZFS file system brand_opts : string brand specific options to pass CLI Example: .. code-block:: bash salt '*' zoneadm.install dolores salt '*' zo...
Install a zone by copying an existing installed zone. zone : string name of the zone source : string zone to clone from snapshot : string optional name of snapshot to use as source CLI Example: .. code-block:: bash salt '*' zoneadm.clone clementine dolores def cl...
Search the environment for the relative path def find_file(path, saltenv='base', **kwargs): ''' Search the environment for the relative path ''' fnd = {'path': '', 'rel': ''} for container in __opts__.get('azurefs', []): if container.get('saltenv', 'base') != saltenv: ...
Each container configuration can have an environment setting, or defaults to base def envs(): ''' Each container configuration can have an environment setting, or defaults to base ''' saltenvs = [] for container in __opts__.get('azurefs', []): saltenvs.append(container.get('saltenv'...
Return a chunk from a file based on the data received def serve_file(load, fnd): ''' Return a chunk from a file based on the data received ''' ret = {'data': '', 'dest': ''} required_load_keys = ('path', 'loc', 'saltenv') if not all(x in load for x in required_load_keys): log...
Update caches of the storage containers. Compares the md5 of the files on disk to the md5 of the blobs in the container, and only updates if necessary. Also processes deletions by walking the container caches and comparing with the list of blobs in the container def update(): ''' Update cache...
Return a file hash based on the hash type set in the master config def file_hash(load, fnd): ''' Return a file hash based on the hash type set in the master config ''' if not all(x in load for x in ('path', 'saltenv')): return '', None ret = {'hash_type': __opts__['hash_type']} relpath ...
Return a list of all files in a specified environment def file_list(load): ''' Return a list of all files in a specified environment ''' ret = set() try: for container in __opts__['azurefs']: if container.get('saltenv', 'base') != load['saltenv']: continue ...
Return a list of all directories in a specified environment def dir_list(load): ''' Return a list of all directories in a specified environment ''' ret = set() files = file_list(load) for f in files: dirname = f while dirname: dirname = os.path.dirname(dirname) ...
Get the cache path for the container in question Cache paths are generate by combining the account name, container name, and saltenv, separated by underscores def _get_container_path(container): ''' Get the cache path for the container in question Cache paths are generate by combining the account...
Get the azure block blob service for the container in question Try account_key, sas_token, and no auth in that order def _get_container_service(container): ''' Get the azure block blob service for the container in question Try account_key, sas_token, and no auth in that order ''' if 'account_...
Validate azurefs config, return False if it doesn't validate def _validate_config(): ''' Validate azurefs config, return False if it doesn't validate ''' if not isinstance(__opts__['azurefs'], list): log.error('azurefs configuration is not formed as a list, skipping azurefs') return Fal...
Return useful information from a SmartOS compute node def _smartos_computenode_data(): ''' Return useful information from a SmartOS compute node ''' # Provides: # vms_total # vms_running # vms_stopped # vms_type # sdc_version # vm_capable # vm_hw_virt grai...
Return useful information from a SmartOS zone def _smartos_zone_data(): ''' Return useful information from a SmartOS zone ''' # Provides: # zoneid # zonename # imageversion grains = { 'zoneid': __salt__['cmd.run']('zoneadm list -p | awk -F: \'{ print $1 }\'', python_shell...
SmartOS zone pkgsrc information def _smartos_zone_pkgsrc_data(): ''' SmartOS zone pkgsrc information ''' # Provides: # pkgsrcversion # pkgsrcpath grains = { 'pkgsrcversion': 'Unknown', 'pkgsrcpath': 'Unknown', } pkgsrcversion = re.compile('^release:\\s(.+)') ...
SmartOS zone pkgsrc information def _smartos_zone_pkgin_data(): ''' SmartOS zone pkgsrc information ''' # Provides: # pkgin_repositories grains = { 'pkgin_repositories': [], } pkginrepo = re.compile('^(?:https|http|ftp|file)://.*$') if os.path.isfile('/opt/local/etc/pkgi...
Provide grains for SmartOS def smartos(): ''' Provide grains for SmartOS ''' grains = {} if salt.utils.platform.is_smartos_zone(): grains = salt.utils.dictupdate.update(grains, _smartos_zone_data(), merge_lists=True) grains = salt.utils.dictupdate.update(grains, _smartos_zone_pkgsr...
Listen to salt events and forward them to Logentries def start(endpoint='data.logentries.com', port=10000, token=None, tag='salt/engines/logentries'): ''' Listen to salt events and forward them to Logentries ''' if __opts__.get('id').endswith('_master'): event_bus ...
Check if node is peered. name The remote host with which to peer. .. code-block:: yaml peer-cluster: glusterfs.peered: - name: two peer-clusters: glusterfs.peered: - names: - one - two - three ...
Ensure that the volume exists name name of the volume bricks list of brick paths replica replica count for volume arbiter use every third brick as arbiter (metadata only) .. versionadded:: 2019.2.0 start ensure that the volume is also started ...
Check if volume has been started name name of the volume .. code-block:: yaml mycluster: glusterfs.started: [] def started(name): ''' Check if volume has been started name name of the volume .. code-block:: yaml mycluster: glusterfs.star...
Add brick(s) to an existing volume name Volume name bricks List of bricks to add to the volume .. code-block:: yaml myvolume: glusterfs.add_volume_bricks: - bricks: - host1:/srv/gluster/drive1 - host2:/srv/gluster/drive2 ...
.. versionadded:: 2019.2.0 Add brick(s) to an existing volume name Volume name version Version to which the cluster.op-version should be set .. code-block:: yaml myvolume: glusterfs.op_version: - name: volume1 - version: 30707 def op_versio...
.. versionadded:: 2019.2.0 Add brick(s) to an existing volume name Volume name .. code-block:: yaml myvolume: glusterfs.max_op_version: - name: volume1 - version: 30707 def max_op_version(name): ''' .. versionadded:: 2019.2.0 Add brick(s) t...
Get the requests options from salt. def _prepare_xml(options=None, state=None): ''' Get the requests options from salt. ''' if state: _state = '0' else: _state = '2' xml = "<?xml version='1.0'?>\n<checkresults>\n" # No service defined then we set the status of the hostnam...
Simple function to return value from XML def _getText(nodelist): ''' Simple function to return value from XML ''' rc = [] for node in nodelist: if node.nodeType == node.TEXT_NODE: rc.append(node.data) return ''.join(rc)
Post data to Nagios NRDP def _post_data(options=None, xml=None): ''' Post data to Nagios NRDP ''' params = {'token': options['token'].strip(), 'cmd': 'submitcheck', 'XMLDATA': xml} res = salt.utils.http.query( url=options['url'], method='POST', params=params, data='...
Send a message to Nagios with the data def returner(ret): ''' Send a message to Nagios with the data ''' _options = _get_options(ret) log.debug('_options %s', _options) _options['hostname'] = ret.get('id') if 'url' not in _options or _options['url'] == '': log.error('nagios_nrdp.u...
Return an influxdb client object def _get_serv(ret=None): ''' Return an influxdb client object ''' _options = _get_options(ret) host = _options.get('host') port = _options.get('port') database = _options.get('db') user = _options.get('user') password = _options.get('password') v...
Return data to a influxdb data store def returner(ret): ''' Return data to a influxdb data store ''' serv = _get_serv(ret) # strip the 'return' key to avoid data duplication in the database json_return = salt.utils.json.dumps(ret['return']) del ret['return'] json_full_ret = salt.utils....
Save the load to the specified jid def save_load(jid, load, minions=None): ''' Save the load to the specified jid ''' serv = _get_serv(ret=None) # create legacy request in case an InfluxDB 0.8.x version is used if "influxdb08" in serv.__module__: req = [ { '...
Return the load data that marks a specified jid def get_load(jid): ''' Return the load data that marks a specified jid ''' serv = _get_serv(ret=None) sql = "select load from jids where jid = '{0}'".format(jid) log.debug(">> Now in get_load %s", jid) data = serv.query(sql) log.debug(">>...
Return the information returned when the specified job id was executed def get_jid(jid): ''' Return the information returned when the specified job id was executed ''' serv = _get_serv(ret=None) sql = "select id, full_ret from returns where jid = '{0}'".format(jid) data = serv.query(sql) ...
Return a dict of the last function called for all minions def get_fun(fun): ''' Return a dict of the last function called for all minions ''' serv = _get_serv(ret=None) sql = '''select first(id) as fid, first(full_ret) as fret from returns where fun = '{0}' grou...
Return a list of all job ids def get_jids(): ''' Return a list of all job ids ''' serv = _get_serv(ret=None) sql = "select distinct(jid) from jids group by load" # [{u'points': [[0, jid, load], # [0, jid, load]], # u'name': u'jids', # u'columns': [u'time', u'disti...
Return a list of minions def get_minions(): ''' Return a list of minions ''' serv = _get_serv(ret=None) sql = "select distinct(id) from returns" data = serv.query(sql) ret = [] if data: for jid in data[0]['points']: ret.append(jid[1]) return ret
Return the running jobs on the master def get_running_jobs(opts): ''' Return the running jobs on the master ''' ret = [] proc_dir = os.path.join(opts['cachedir'], 'proc') if not os.path.isdir(proc_dir): return ret for fn_ in os.listdir(proc_dir): path = os.path.join(proc_di...
Return a dict of JID metadata, or None def read_proc_file(path, opts): ''' Return a dict of JID metadata, or None ''' serial = salt.payload.Serial(opts) with salt.utils.files.fopen(path, 'rb') as fp_: try: data = serial.load(fp_) except Exception as err: # ne...
This is a health check that will confirm the PID is running and executed by salt. If pusutil is available: * all architectures are checked if psutil is not available: * Linux/Solaris/etc: archs with `/proc/cmdline` available are checked * AIX/Windows: assume PID is healhty and retu...
Check a whitelist and/or blacklist to see if the value matches it. def get_values_of_matching_keys(pattern_dict, user_name): ''' Check a whitelist and/or blacklist to see if the value matches it. ''' ret = [] for expr in pattern_dict: if salt.utils.stringutils.expr_match(user_name, expr): ...
Get pillar data for the targeted minions, either by fetching the cached minion data on the master, or by compiling the minion's pillar data on the master. For runner modules that need access minion pillar data, this function should be used instead of getting the pillar data by e...
Get grains data for the targeted minions, either by fetching the cached minion data on the master, or by fetching the grains directly on the minion. By default, this function tries hard to get the grains data: - Try to get the cached minion grains if the master has m...
Get cached mine data for the targeted minions. def get_cached_mine_data(self): ''' Get cached mine data for the targeted minions. ''' mine_data = {} minion_ids = self._tgt_to_list() log.debug('Getting cached mine data for: %s', minion_ids) mine_data = self._get_c...
Clear the cached data/files for the targeted minions. def clear_cached_minion_data(self, clear_pillar=False, clear_grains=False, clear_mine=False, clear_mine_func=None): ''' ...
main loop that fires the event every second def run(self): ''' main loop that fires the event every second ''' context = zmq.Context() # the socket for outgoing timer events socket = context.socket(zmq.PUB) socket.setsockopt(zmq.LINGER, 100) socket.bind('...
Gather currently connected minions and update the cache def run(self): ''' Gather currently connected minions and update the cache ''' new_mins = list(salt.utils.minions.CkMinions(self.opts).connected_ids()) cc = cache_cli(self.opts) cc.get_cached() cc.put_cache(...
remove sockets on shutdown def cleanup(self): ''' remove sockets on shutdown ''' log.debug('ConCache cleaning up') if os.path.exists(self.cache_sock): os.remove(self.cache_sock) if os.path.exists(self.update_sock): os.remove(self.update_sock) ...
secure the sockets for root-only access def secure(self): ''' secure the sockets for root-only access ''' log.debug('ConCache securing sockets') if os.path.exists(self.cache_sock): os.chmod(self.cache_sock, 0o600) if os.path.exists(self.update_sock): ...
shutdown cache process def stop(self): ''' shutdown cache process ''' # avoid getting called twice self.cleanup() if self.running: self.running = False self.timer_stop.set() self.timer.join()
Main loop of the ConCache, starts updates in intervals and answers requests from the MWorkers def run(self): ''' Main loop of the ConCache, starts updates in intervals and answers requests from the MWorkers ''' context = zmq.Context() # the socket for incoming ca...
Return a response in an SMS message def returner(ret): ''' Return a response in an SMS message ''' _options = _get_options(ret) sid = _options.get('sid', None) token = _options.get('token', None) sender = _options.get('from', None) receiver = _options.get('to', None) if sid is Non...
Returns: None if group wasn't found, otherwise a group object def _common(kwargs): ''' Returns: None if group wasn't found, otherwise a group object ''' search_kwargs = {'name': kwargs['name']} if 'domain' in kwargs: domain = __salt__['keystoneng.get_entity']( 'dom...
Ensure group does not exist name Name of the group domain The name or id of the domain def absent(name, auth=None, **kwargs): ''' Ensure group does not exist name Name of the group domain The name or id of the domain ''' ret = {'name': name, ...
Return a dict of the files located with the given path and environment def find(path, saltenv='base'): ''' Return a dict of the files located with the given path and environment ''' # Return a list of paths + text or bin ret = [] if saltenv not in __opts__['pillar_roots']: return ret ...
Return all of the file paths found in an environment def list_env(saltenv='base'): ''' Return all of the file paths found in an environment ''' ret = {} if saltenv not in __opts__['pillar_roots']: return ret for f_root in __opts__['pillar_roots'][saltenv]: ret[f_root] = {} ...
Return all of the files names in all available environments def list_roots(): ''' Return all of the files names in all available environments ''' ret = {} for saltenv in __opts__['pillar_roots']: ret[saltenv] = [] ret[saltenv].append(list_env(saltenv)) return ret
Read the contents of a text file, if the file is binary then def read(path, saltenv='base'): ''' Read the contents of a text file, if the file is binary then ''' # Return a dict of paths + content ret = [] files = find(path, saltenv) for fn_ in files: full = next(six.iterkeys(fn_)) ...
Write the named file, by default the first file found is written, but the index of the file can be specified to write to a lower priority file root def write(data, path, saltenv='base', index=0): ''' Write the named file, by default the first file found is written, but the index of the file can be spec...
.. versionadded:: 2019.2.0 Ensure a resource group exists. :param name: Name of the resource group. :param location: The Azure location in which to create the resource group. This value cannot be updated once the resource group is created. :param managed_by: The ID of...
.. versionadded:: 2019.2.0 Ensure a resource group does not exist in the current subscription. :param name: Name of the resource group. :param connection_auth: A dict with subscription and authentication parameters to be used in connecting to the Azure Resource Manager API. def r...
.. versionadded:: 2019.2.0 Ensure a security policy definition exists. :param name: Name of the policy definition. :param policy_rule: A YAML dictionary defining the policy rule. See `Azure Policy Definition documentation <https://docs.microsoft.com/en-us/azure/azure-policy/policy...
.. versionadded:: 2019.2.0 Ensure a policy definition does not exist in the current subscription. :param name: Name of the policy definition. :param connection_auth: A dict with subscription and authentication parameters to be used in connecting to the Azure Resource Manager API. ...
.. versionadded:: 2019.2.0 Ensure a security policy assignment exists. :param name: Name of the policy assignment. :param scope: The scope of the policy assignment. :param definition_name: The name of the policy definition to assign. :param display_name: The disp...
Send an xmpp message with the data def returner(ret): ''' Send an xmpp message with the data ''' _options = _get_options(ret) from_jid = _options.get('from_jid') password = _options.get('password') recipient_jid = _options.get('recipient_jid') if not from_jid: log.error('xmpp...
Combine the host header, IP address, and TCP port into bindingInformation format. def _get_binding_info(hostheader='', ipaddress='*', port=80): ''' Combine the host header, IP address, and TCP port into bindingInformation format. ''' ret = r'{0}:{1}:{2}'.format(ipaddress, port, hostheader.replace(' ', ...
Ensure the website has been deployed. .. note: This function only validates against the site name, and will return True even if the site already exists with a different configuration. It will not modify the configuration of an existing site. :param str name: The IIS site name. :pa...
Delete a website from IIS. :param str name: The IIS site name. Usage: .. code-block:: yaml defaultwebsite-remove: win_iis.remove_site: - name: Default Web Site def remove_site(name): ''' Delete a website from IIS. :param str name: The IIS site name. ...
Create an IIS binding. .. note: This function only validates against the binding ipaddress:port:hostheader combination, and will return True even if the binding already exists with a different configuration. It will not modify the configuration of an existing binding. :param str site:...
Remove an IIS binding. :param str site: The IIS site name. :param str hostheader: The host header of the binding. :param str ipaddress: The IP address of the binding. :param str port: The TCP port of the binding. Example of usage with only the required arguments: .. code-block:: yaml ...
Assign a certificate to an IIS binding. .. note: The web binding that the certificate is being assigned to must already exist. :param str name: The thumbprint of the certificate. :param str site: The IIS site name. :param str hostheader: The host header of the binding. :param str ipaddres...
Remove a certificate from an IIS binding. .. note: This function only removes the certificate from the web binding. It does not remove the web binding itself. :param str name: The thumbprint of the certificate. :param str site: The IIS site name. :param str hostheader: The host header...
Create an IIS application pool. .. note: This function only validates against the application pool name, and will return True even if the application pool already exists with a different configuration. It will not modify the configuration of an existing application pool. :param str na...
Remove an IIS application pool. :param str name: The name of the IIS application pool. Usage: .. code-block:: yaml defaultapppool-remove: win_iis.remove_apppool: - name: DefaultAppPool def remove_apppool(name): # Remove IIS AppPool ''' Remove an IIS appli...
Set the value of the setting for an IIS container. :param str name: The name of the IIS container. :param str container: The type of IIS container. The container types are: AppPools, Sites, SslBindings :param str settings: A dictionary of the setting names and their values. Example of usage...
Create an IIS application. .. note: This function only validates against the application name, and will return True even if the application already exists with a different configuration. It will not modify the configuration of an existing application. :param str name: The IIS applicat...
Remove an IIS application. :param str name: The application name. :param str site: The IIS site name. Usage: .. code-block:: yaml site0-v1-app-remove: win_iis.remove_app: - name: v1 - site: site0 def remove_app(name, site): ''' Remove an I...
Create an IIS virtual directory. .. note: This function only validates against the virtual directory name, and will return True even if the virtual directory already exists with a different configuration. It will not modify the configuration of an existing virtual directory. :param st...
Remove an IIS virtual directory. :param str name: The virtual directory name. :param str site: The IIS site name. :param str app: The IIS application. Example of usage with only the required arguments: .. code-block:: yaml site0-foo-vdir-remove: win_iis.remove_vdir: ...
.. versionadded:: 2017.7.0 Set the value of the setting for an IIS web application. .. note:: This function only configures existing app. Params are case sensitive. :param str name: The IIS application. :param str site: The IIS site name. :param str settings: A dictionary of the setting n...
r''' Set the value of webconfiguration settings. :param str name: The name of the IIS PSPath containing the settings. Possible PSPaths are : MACHINE, MACHINE/WEBROOT, IIS:\, IIS:\Sites\sitename, ... :param str location: The location of the settings. :param dict settings: Dictionaries of...
Tries to guess the url of zabbix frontend. .. versionadded:: 2016.3.0 def _frontend_url(): ''' Tries to guess the url of zabbix frontend. .. versionadded:: 2016.3.0 ''' hostname = socket.gethostname() frontend_url = 'http://' + hostname + '/zabbix/api_jsonrpc.php' try: try: ...
JSON request to Zabbix API. .. versionadded:: 2016.3.0 :param method: actual operation to perform via the API :param params: parameters required for specific method :param url: url of zabbix api :param auth: auth token for zabbix api (only for methods with required authentication) :return: Re...
Log in to the API and generate the authentication token. .. versionadded:: 2016.3.0 :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...
Extends the params dictionary by values from keyword arguments. .. versionadded:: 2016.3.0 :param params: Dictionary with parameters for zabbix API. :param _ignore_name: Salt State module is passing first line as 'name' parameter. If API uses optional parameter 'name' (for ex. host_create, user_create...
.. versionadded:: 2017.7 Go through Zabbix object params specification and if needed get given object ID from Zabbix API and put it back as a value. Definition of the object is done via dict with keys "query_object" and "query_name". :param input_object: Zabbix object type specified in state file :par...
.. versionadded:: 2017.7 Compares Zabbix object definition against existing Zabbix object. :param defined: Zabbix object definition taken from sls file. :param existing: Existing Zabbix object taken from result of an API call. :param return_old_value: Default False. If True, returns dict("old"=old_val...
.. versionadded:: 2017.7 Get ID of single Zabbix object specified by its name. :param obj: Zabbix object type :param params: Parameters by which object is uniquely identified :param _connection_user: Optional - zabbix user (can also be set in opts or pillar, see module's docstring) :param _connect...
Retrieve the version of the Zabbix API. .. versionadded:: 2016.3.0 :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) :param _con...
.. versionadded:: 2016.3.0 Create new zabbix user .. note:: This function accepts all standard user properties: keyword argument names differ depending on your zabbix version, see here__. .. __: https://www.zabbix.com/documentation/2.0/manual/appendix/api/user/definitions#user :p...
Delete zabbix users. .. versionadded:: 2016.3.0 :param users: array of users (userids) to delete :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 m...
Checks if user with given alias exists. .. versionadded:: 2016.3.0 :param alias: user alias :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...