text
stringlengths
81
112k
Return the name of the package that owns the file. Multiple file paths can be passed. Like :mod:`pkg.version <salt.modules.opkg.version`, if a single path is passed, a string will be returned, and if multiple paths are passed, a dictionary of file/package name pairs will be returned. If the file is not...
send a email to inform user of account creation def _send_email(name, email): "send a email to inform user of account creation" config = __salt__['config.option']('splunk') email_object = config.get('email') if email_object: cc = email_object.get('cc') subject = email_object.get('subjec...
Return the splunk client, cached into __context__ for performance def _get_splunk(profile): ''' Return the splunk client, cached into __context__ for performance ''' config = __salt__['config.option'](profile) key = "splunk.{0}:{1}:{2}:{3}".format( config.get('host'), config.get('p...
List all users in the splunk DB CLI Example: salt myminion splunk.list_users def list_users(profile="splunk"): ''' List all users in the splunk DB CLI Example: salt myminion splunk.list_users ''' config = __salt__['config.option'](profile) key = "splunk.users.{0}".forma...
Get a splunk user by name/email CLI Example: salt myminion splunk.get_user 'user@example.com' user_details=false salt myminion splunk.get_user 'user@example.com' user_details=true def get_user(email, profile="splunk", **kwargs): ''' Get a splunk user by name/email CLI Example: ...
create a splunk user by name/email CLI Example: salt myminion splunk.create_user user@example.com roles=['user'] realname="Test User" name=testuser def create_user(email, profile="splunk", **kwargs): ''' create a splunk user by name/email CLI Example: salt myminion splunk.create_use...
Create a splunk user by email CLI Example: salt myminion splunk.update_user example@domain.com roles=['user'] realname="Test User" def update_user(email, profile="splunk", **kwargs): ''' Create a splunk user by email CLI Example: salt myminion splunk.update_user example@domain.com r...
Delete a splunk user by email CLI Example: salt myminion splunk_user.delete 'user@example.com' def delete_user(email, profile="splunk"): ''' Delete a splunk user by email CLI Example: salt myminion splunk_user.delete 'user@example.com' ''' client = _get_splunk(profile) ...
Return the default shell to use on this system def shell(): ''' Return the default shell to use on this system ''' # Provides: # shell if salt.utils.platform.is_windows(): env_var = 'COMSPEC' default = r'C:\Windows\system32\cmd.exe' else: env_var = 'SHELL' ...
Return the grains set in the grains file def config(): ''' Return the grains set in the grains file ''' if 'conf_file' not in __opts__: return {} if os.path.isdir(__opts__['conf_file']): if salt.utils.platform.is_proxy(): gfn = os.path.join( __opts__[...
Get the output volume (range 0 to 100) CLI Example: .. code-block:: bash salt '*' desktop.get_output_volume def get_output_volume(): ''' Get the output volume (range 0 to 100) CLI Example: .. code-block:: bash salt '*' desktop.get_output_volume ''' cmd = 'osascript...
Set the volume of sound. volume The level of volume. Can range from 0 to 100. CLI Example: .. code-block:: bash salt '*' desktop.set_output_volume <volume> def set_output_volume(volume): ''' Set the volume of sound. volume The level of volume. Can range from 0 to 10...
Launch the screensaver. CLI Example: .. code-block:: bash salt '*' desktop.screensaver def screensaver(): ''' Launch the screensaver. CLI Example: .. code-block:: bash salt '*' desktop.screensaver ''' cmd = 'open /System/Library/Frameworks/ScreenSaver.framework/Ver...
Say some words. words The words to execute the say command with. CLI Example: .. code-block:: bash salt '*' desktop.say <word0> <word1> ... <wordN> def say(*words): ''' Say some words. words The words to execute the say command with. CLI Example: .. code-b...
Check the output of the cmd.run_all function call. def _check_cmd(call): ''' Check the output of the cmd.run_all function call. ''' if call['retcode'] != 0: comment = '' std_err = call.get('stderr') std_out = call.get('stdout') if std_err: comment += std_err ...
r''' Create a list of Counter objects to be used in the pdh query Args: counter_list (list): A list of tuples containing counter information. Each tuple should contain the object, instance, and counter name. For example, to get the ``% Processor Time`` counter for al...
Get the values for all counters available to a Counter object Args: obj (str): The name of the counter object. You can get a list of valid names using the ``list_objects`` function instance_list (list): A list of instances to return. Use this to narrow down the...
Get the values for the passes list of counters Args: counter_list (list): A list of counters to lookup Returns: dict: A dictionary of counters and their values def get_counters(counter_list): ''' Get the values for the passes list of counters Args: counter_lis...
r''' Makes a fully resolved counter path. Counter names are formatted like this: ``\Processor(*)\% Processor Time`` The above breaks down like this: obj = 'Processor' instance = '*' counter = '% Processor Time' Args: obj (str):...
Add the current path to the query Args: query (obj): The handle to the query to add the counter def add_to_query(self, query): ''' Add the current path to the query Args: query (obj): The handle to the query to add the counter ...
Get information about the counter .. note:: GetCounterInfo sometimes crashes in the wrapper code. Fewer crashes if this is called after sampling data. def get_info(self): ''' Get information about the counter .. note:: GetCounterInfo sometimes crash...
Return the counter value Returns: long: The counter value def value(self): ''' Return the counter value Returns: long: The counter value ''' (counter_type, value) = win32pdh.GetFormattedCounterValue( self.handle, win32pdh.PDH_FMT_DOU...
Returns the names of the flags that are set in the Type field It can be used to format the counter. def type_string(self): ''' Returns the names of the flags that are set in the Type field It can be used to format the counter. ''' type = self.get_info()['type'] ...
Add the directory to the system PATH at index location index Position where the directory should be placed in the PATH. This is 0-indexed, so 0 means to prepend at the very start of the PATH. .. note:: If the index is not specified, and the directory needs to be added ...
Return a unique ID for this proxy minion. This ID MUST NOT CHANGE. If it changes while the proxy is running the salt-master will get really confused and may stop talking to this minion def id(opts): ''' Return a unique ID for this proxy minion. This ID MUST NOT CHANGE. If it changes while the pro...
Get the grains from the proxied device def grains(): ''' Get the grains from the proxied device ''' if not DETAILS.get('grains_cache', {}): r = salt.utils.http.query(DETAILS['url']+'info', decode_type='json', decode=True) DETAILS['grains_cache'] = r['dict'] return DETAILS['grains_ca...
Start a "service" on the REST server def service_start(name): ''' Start a "service" on the REST server ''' r = salt.utils.http.query(DETAILS['url']+'service/start/'+name, decode_type='json', decode=True) return r['dict']
List "services" on the REST server def service_list(): ''' List "services" on the REST server ''' r = salt.utils.http.query(DETAILS['url']+'service/list', decode_type='json', decode=True) return r['dict']
Install a "package" on the REST server def package_install(name, **kwargs): ''' Install a "package" on the REST server ''' cmd = DETAILS['url']+'package/install/'+name if kwargs.get('version', False): cmd += '/'+kwargs['version'] else: cmd += '/1.0' r = salt.utils.http.query...
Is the REST server up? def ping(): ''' Is the REST server up? ''' r = salt.utils.http.query(DETAILS['url']+'ping', decode_type='json', decode=True) try: return r['dict'].get('ret', False) except Exception: return False
Make sure the given attributes exist on the file/directory name The path to the file/directory attributes The attributes that should exist on the file/directory, this is accepted as an array, with key and value split with an equals sign, if you want to specify a hex value then ...
Make sure the given attributes are deleted from the file/directory name The path to the file/directory attributes The attributes that should be removed from the file/directory, this is accepted as an array. def delete(name, attributes): ''' Make sure the given attributes are d...
Check if a given path is writeable by the current user. :param path: The path to check :param check_parent: If the path to check does not exist, check for the ability to write to the parent directory instead :returns: True or False def is_writeable(path, check_parent=False): ''' Check i...
Check if a given path is readable by the current user. :param path: The path to check :returns: True or False def is_readable(path): ''' Check if a given path is readable by the current user. :param path: The path to check :returns: True or False ''' if os.access(path, os.F_OK) and o...
This function will parse the raw syslog data, dynamically create the topic according to the topic specified by the user (if specified) and decide whether to send the syslog data as an event on the master bus, based on the constraints given by the user. :param data: The raw syslog event ...
This function identifies whether the engine is running on the master or the minion and sends the data to the master event bus accordingly. :param result: It's a dictionary which has the final data and topic. def send_event_to_salt(self, result): ''' This function identifies whether the...
Get a value from a db, using a uri in the form of ``sdb://<profile>/<key>``. If the uri provided does not start with ``sdb://``, then it will be returned as-is. def sdb_get(uri, opts, utils=None): ''' Get a value from a db, using a uri in the form of ``sdb://<profile>/<key>``. If the uri provided does ...
Check if value exists in sdb. If it does, return, otherwise generate a random string and store it. This can be used for storing secrets in a centralized place. def sdb_get_or_set_hash(uri, opts, length=8, chars='abcdefghijklmnopqrstuvwxy...
List all users. profile Configuration profile used to connect to the Grafana instance. Default is 'grafana'. CLI Example: .. code-block:: bash salt '*' grafana4.get_users def get_users(profile='grafana'): ''' List all users. profile Configuration profile use...
Show a single user. login Login of the user. profile Configuration profile used to connect to the Grafana instance. Default is 'grafana'. CLI Example: .. code-block:: bash salt '*' grafana4.get_user <login> def get_user(login, profile='grafana'): ''' Show a ...
Update an existing user. userid Id of the user. login Optional - Login of the user. email Optional - Email of the user. name Optional - Full name of the user. orgid Optional - Default Organization of the user. profile Configuration profile us...
Switch the current organization. name Name of the organization to switch to. profile Configuration profile used to connect to the Grafana instance. Default is 'grafana'. CLI Example: .. code-block:: bash salt '*' grafana4.switch_org <name> def switch_org(orgname, pr...
Update user role in the organization. userid Id of the user. loginOrEmail Login or email of the user. role Role of the user for this organization. Should be one of: - Admin - Editor - Read Only Editor - Viewer orgname Na...
Show a single datasource in an organisation. name Name of the datasource. orgname Name of the organization. profile Configuration profile used to connect to the Grafana instance. Default is 'grafana'. CLI Example: .. code-block:: bash salt '*' grafana4.g...
Delete a datasource. datasourceid Id of the datasource. profile Configuration profile used to connect to the Grafana instance. Default is 'grafana'. CLI Example: .. code-block:: bash salt '*' grafana4.delete_datasource <datasource_id> def delete_datasource(datasourc...
Read in the generated libvirt keys def ext_pillar(minion_id, pillar, # pylint: disable=W0613 command): # pylint: disable=W0613 ''' Read in the generated libvirt keys ''' key_dir = os.path.join( __opts__['pki_dir'], 'libvirt', minion_id...
Generate the keys to be used by libvirt hypervisors, this routine gens the keys and applies them to the pillar for the hypervisor minions def gen_hyper_keys(minion_id, country='US', state='Utah', locality='Salt Lake City', organization='Sa...
Ensure key pair is present. def key_present(name, save_private=None, upload_public=None, region=None, key=None, keyid=None, profile=None): ''' Ensure key pair is present. ''' ret = {'name': name, 'result': True, 'comment': '', 'changes': {} } ...
Deletes a key pair def key_absent(name, region=None, key=None, keyid=None, profile=None): ''' Deletes a key pair ''' ret = {'name': name, 'result': True, 'comment': '', 'changes': {} } exists = __salt__['boto_ec2.get_key'](name, region, key, keyid, profil...
Ensure the EC2 ENI exists. .. versionadded:: 2016.3.0 name Name tag associated with the ENI. subnet_id The VPC subnet ID the ENI will exist within. subnet_name The VPC subnet name the ENI will exist within. private_ip_address The private ip address to use for thi...
Ensure the EC2 ENI is absent. .. versionadded:: 2016.3.0 name Name tag associated with the ENI. release_eip True/False - release any EIP associated with the ENI region Region to connect to. key Secret key to be used. keyid Access key to be used. ...
Create a snapshot from the given instance .. versionadded:: 2016.3.0 def snapshot_created(name, ami_name, instance_name, wait_until_available=True, wait_timeout_seconds=300, **kwargs): ''' Create a snapshot from the given instance .. versionadded:: 2016.3.0 ''' ret = {'name': name, ...
Ensure an EC2 instance is running with the given attributes and state. name (string) - The name of the state definition. Recommended that this match the instance_name attribute (generally the FQDN of the instance). instance_name (string) - The name of the instance, generally its FQDN. ...
Ensure an EC2 instance does not exist (is stopped and removed). .. versionchanged:: 2016.11.0 name (string) - The name of the state definition. instance_name (string) - The name of the instance. instance_id (string) - The ID of the instance. release_eip (bool) - R...
Ensure the EC2 volume is detached and absent. .. versionadded:: 2016.11.0 name State definition name. volume_name Name tag associated with the volume. For safety, if this matches more than one volume, the state will refuse to apply. volume_id Resource ID of the volum...
Ensure EC2 volume(s) matching the given filters have the defined tags. .. versionadded:: 2016.11.0 name State definition name. tag_maps List of dicts of filters and tags, where 'filters' is a dict suitable for passing to the 'filters' argument of boto_ec2.get_all_volumes(), and 't...
Ensure the EC2 volume is present and attached. .. name State definition name. volume_name The Name tag value for the volume. If no volume with that matching name tag is found, a new volume will be created. If multiple volumes are matched, the state will fail. volume_id ...
Ensure an ENI has secondary private ip addresses associated with it name (String) - State definition name network_interface_id (String) - The EC2 network interface id, example eni-123456789 private_ip_addresses (List or String) - The secondary private ip address(es) that should be p...
Ensure an ENI does not have secondary private ip addresses associated with it name (String) - State definition name network_interface_id (String) - The EC2 network interface id, example eni-123456789 private_ip_addresses (List or String) - The secondary private ip address(es) that s...
Additional network-specific post-translation processing def _post_processing(kwargs, skip_translate, invalid): # pylint: disable=unused-argument ''' Additional network-specific post-translation processing ''' # If any defaults were not expicitly passed, add them for item in DEFAULTS: if it...
.. versionadded:: 2014.7.0 Read in the config and return the correct LocalClient object based on the configured transport :param IOLoop io_loop: io_loop used for events. Pass in an io_loop if you want asynchronous operation for obtaining events. Eg use...
Read in the rotating master authentication key def __read_master_key(self): ''' Read in the rotating master authentication key ''' key_user = self.salt_user if key_user == 'root': if self.opts.get('user', 'root') != 'root': key_user = self.opts.get('u...
convert a seco.range range into a list target def _convert_range_to_list(self, tgt): ''' convert a seco.range range into a list target ''' range_ = seco.range.Range(self.opts['range_server']) try: return range_.expand(tgt) except seco.range.RangeException as ...
Return the timeout to use def _get_timeout(self, timeout): ''' Return the timeout to use ''' if timeout is None: return self.opts['timeout'] if isinstance(timeout, int): return timeout if isinstance(timeout, six.string_types): try: ...
Return the information about a given job def gather_job_info(self, jid, tgt, tgt_type, listen=True, **kwargs): ''' Return the information about a given job ''' log.debug('Checking whether jid %s is still running', jid) timeout = int(kwargs.get('gather_job_timeout', self.opts['ga...
Common checks on the pub_data data structure returned from running pub def _check_pub_data(self, pub_data, listen=True): ''' Common checks on the pub_data data structure returned from running pub ''' if pub_data == '': # Failed to authenticate, this could be a bunch of thing...
Asynchronously send a command to connected minions Prep the job directory and publish a command to any targeted minions. :return: A dictionary of (validated) ``pub_data`` or an empty dictionary on failure. The ``pub_data`` contains the job ID and a list of all minions that are ...
Asynchronously send a command to connected minions Prep the job directory and publish a command to any targeted minions. :return: A dictionary of (validated) ``pub_data`` or an empty dictionary on failure. The ``pub_data`` contains the job ID and a list of all minions that are ...
Asynchronously send a command to connected minions The function signature is the same as :py:meth:`cmd` with the following exceptions. :returns: A job ID or 0 on failure. .. code-block:: python >>> local.cmd_async('*', 'test.sleep', [300]) '2013121921592185771...
Execute a command on a random subset of the targeted systems The function signature is the same as :py:meth:`cmd` with the following exceptions. :param sub: The number of systems to execute on :param cli: When this is set to True, a generator is returned, otherwise ...
Iteratively execute a command on subsets of minions at a time The function signature is the same as :py:meth:`cmd` with the following exceptions. :param batch: The batch identifier of systems to execute on :returns: A generator of minion returns .. code-block:: python ...
Synchronously execute a command on targeted minions The cmd method will execute and wait for the timeout period for all minions to reply, then it will return all minion data at once. .. code-block:: python >>> import salt.client >>> local = salt.client.LocalClient() ...
Used by the :command:`salt` CLI. This method returns minion returns as they come back and attempts to block until all minions return. The function signature is the same as :py:meth:`cmd` with the following exceptions. :param verbose: Print extra information about the running command ...
Yields the individual minion returns as they come in The function signature is the same as :py:meth:`cmd` with the following exceptions. Normally :py:meth:`cmd_iter` does not yield results for minions that are not connected. If you want it to return results for disconnected min...
Yields the individual minion returns as they come in, or None when no returns are available. The function signature is the same as :py:meth:`cmd` with the following exceptions. :returns: A generator yielding the individual minion returns, or None when no returns are ava...
Execute a salt command and return def cmd_full_return( self, tgt, fun, arg=(), timeout=None, tgt_type='glob', ret='', verbose=False, kwarg=None, **kwargs): ''' Execute a salt command ...
Starts a watcher looking at the return data for a specified JID :returns: all of the information for the JID def get_cli_returns( self, jid, minions, timeout=None, tgt='*', tgt_type='glob', verbose=False, show_jid=...
Raw function to just return events of jid excluding timeout logic Yield either the raw event data or None Pass a list of additional regular expressions as `tags_regex` to search the event bus for non-return data, such as minion lists returned from syndics. def get_returns_no_block( ...
Watch the event system and return job data as it comes in :returns: all of the information for the JID def get_iter_returns( self, jid, minions, timeout=None, tgt='*', tgt_type='glob', expect_minions=False, block=T...
Get the returns for the command line interface via the event system def get_returns( self, jid, minions, timeout=None): ''' Get the returns for the command line interface via the event system ''' minions = set(minions) if timeout i...
This method starts off a watcher looking at the return data for a specified jid, it returns all of the information for the jid def get_full_returns(self, jid, minions, timeout=None): ''' This method starts off a watcher looking at the return data for a specified jid, it returns all of t...
Execute a single pass to gather the contents of the job cache def get_cache_returns(self, jid): ''' Execute a single pass to gather the contents of the job cache ''' ret = {} try: data = self.returners['{0}.get_jid'.format(self.opts['master_job_cache'])](jid) ...
Get the returns for the command line interface via the event system def get_cli_static_event_returns( self, jid, minions, timeout=None, tgt='*', tgt_type='glob', verbose=False, show_timeout=False, show_jid=False...
Get the returns for the command line interface via the event system def get_cli_event_returns( self, jid, minions, timeout=None, tgt='*', tgt_type='glob', verbose=False, progress=False, show_timeout=False, ...
Gather the return data from the event system, break hard when timeout is reached. def get_event_iter_returns(self, jid, minions, timeout=None): ''' Gather the return data from the event system, break hard when timeout is reached. ''' log.trace('entered - function get_eve...
Set up the payload_kwargs to be sent down to the master def _prep_pub(self, tgt, fun, arg, tgt_type, ret, jid, timeout, **kwargs): ''' Set up the payload_kwarg...
Take the required arguments and publish the given command. Arguments: tgt: The tgt is a regex or a glob used to match up the ids on the minions. Salt works by always publishing every command to all of the minions and then the minions determine if ...
Find out what functions are available on the minion def __load_functions(self): ''' Find out what functions are available on the minion ''' return set(self.local.cmd(self.minion, 'sys.list_functions').get(self.minion, []))
Return a function that executes the arguments passed via the local client def run_key(self, key): ''' Return a function that executes the arguments passed via the local client ''' def func(*args, **kwargs): ''' Run a remote call ''' ...
Call an execution module with the given arguments and keyword arguments .. versionchanged:: 2015.8.0 Added the ``cmd`` method for consistency with the other Salt clients. The existing ``function`` and ``sminion.functions`` interfaces still exist but have been removed from th...
Call a single salt function def function(self, fun, *args, **kwargs): ''' Call a single salt function ''' func = self.sminion.functions[fun] args, kwargs = salt.minion.load_args_and_kwargs( func, salt.utils.args.parse_input(args, kwargs=kwargs),) ...
Call an execution module with the given arguments and keyword arguments .. code-block:: python caller.cmd('test.arg', 'Foo', 'Bar', baz='Baz') caller.cmd('event.send', 'myco/myevent/something', data={'foo': 'Foo'}, with_env=['GIT_COMMIT'], with_grains=True) def cmd(se...
Get the value of the setting for the provided class. def _get_wmi_setting(wmi_class_name, setting, server): ''' Get the value of the setting for the provided class. ''' with salt.utils.winapi.Com(): try: connection = wmi.WMI(namespace=_WMI_NAMESPACE) wmi_class = getattr(...
Set the value of the setting for the provided class. def _set_wmi_setting(wmi_class_name, setting, value, server): ''' Set the value of the setting for the provided class. ''' with salt.utils.winapi.Com(): try: connection = wmi.WMI(namespace=_WMI_NAMESPACE) wmi_class = g...
Get all available log format names and ids. :return: A dictionary of the log format names and ids. :rtype: dict CLI Example: .. code-block:: bash salt '*' win_smtp_server.get_log_format_types def get_log_format_types(): ''' Get all available log format names and ids. :return: A...
Get the SMTP virtual server names. :return: A list of the SMTP virtual servers. :rtype: list CLI Example: .. code-block:: bash salt '*' win_smtp_server.get_servers def get_servers(): ''' Get the SMTP virtual server names. :return: A list of the SMTP virtual servers. :rtype:...
Get the value of the setting for the SMTP virtual server. :param str settings: A list of the setting names. :param str server: The SMTP server name. :return: A dictionary of the provided settings and their values. :rtype: dict CLI Example: .. code-block:: bash salt '*' win_smtp_serv...
Set the value of the setting for the SMTP virtual server. .. note:: The setting names are case-sensitive. :param str settings: A dictionary of the setting names and their values. :param str server: The SMTP server name. :return: A boolean representing whether all changes succeeded. :rtyp...
Get the active log format for the SMTP virtual server. :param str server: The SMTP server name. :return: A string of the log format name. :rtype: str CLI Example: .. code-block:: bash salt '*' win_smtp_server.get_log_format def get_log_format(server=_DEFAULT_SERVER): ''' Get th...
Set the active log format for the SMTP virtual server. :param str log_format: The log format name. :param str server: The SMTP server name. :return: A boolean representing whether the change succeeded. :rtype: bool CLI Example: .. code-block:: bash salt '*' win_smtp_server.set_log_f...