text
stringlengths
81
112k
Print progress events def _progress_ret(self, progress, out): ''' Print progress events ''' import salt.output # Get the progress bar if not hasattr(self, 'progress_bar'): try: self.progress_bar = salt.output.get_progress(self.config, out, pro...
Print the output from a single return to the terminal def _output_ret(self, ret, out, retcode=0): ''' Print the output from a single return to the terminal ''' import salt.output # Handle special case commands if self.config['fun'] == 'sys.doc' and not isinstance(ret, Ex...
Take the full return data and format it to simple output def _format_ret(self, full_ret): ''' Take the full return data and format it to simple output ''' ret = {} out = '' retcode = 0 for key, data in six.iteritems(full_ret): ret[key] = data['ret'] ...
Determine a retcode for a given return def _get_retcode(self, ret): ''' Determine a retcode for a given return ''' retcode = 0 # if there is a dict with retcode, use that if isinstance(ret, dict) and ret.get('retcode', 0) != 0: if isinstance(ret.get('retcode'...
Print out the docstrings for all of the functions on the minions def _print_docs(self, ret): ''' Print out the docstrings for all of the functions on the minions ''' import salt.output docs = {} if not ret: self.exit(2, 'No minions found to gather docs from\n...
Make text into a double-quoted YAML string with correct escaping for special characters. Includes the opening and closing double quote characters. def yaml_dquote(text): ''' Make text into a double-quoted YAML string with correct escaping for special characters. Includes the opening and closing d...
Make text into a single-quoted YAML string with correct escaping for special characters. Includes the opening and closing single quote characters. def yaml_squote(text): ''' Make text into a single-quoted YAML string with correct escaping for special characters. Includes the opening and closing s...
A simple YAML encode that can take a single-element datatype and return a string representation. def yaml_encode(data): ''' A simple YAML encode that can take a single-element datatype and return a string representation. ''' yrepr = yaml.representer.SafeRepresenter() ynode = yrepr.represent...
Recursively try to decrypt any object. If the object is a six.string_types (string or unicode), and it contains a valid NACLENC pretext, decrypt it, otherwise keep going until a string is found. def _decrypt_object(obj, **kwargs): ''' Recursively try to decrypt any object. If the object is a six.string...
Execute queries against MySQL, merge and return as a dict def ext_pillar(minion_id, pillar, *args, **kwargs): ''' Execute queries against MySQL, merge and return as a dict ''' return MySQLExtPillar().fetch(minion_id, pillar, *args, **kwargs)
Returns options used for the MySQL connection. def _get_options(self): ''' Returns options used for the MySQL connection. ''' defaults = {'host': 'localhost', 'user': 'salt', 'pass': 'salt', 'db': 'salt', 'p...
Yield a MySQL cursor def _get_cursor(self): ''' Yield a MySQL cursor ''' _options = self._get_options() conn = MySQLdb.connect(host=_options['host'], user=_options['user'], passwd=_options['pass'], ...
This function normalizes the config block into a set of queries we can use. The return is a list of consistently laid out dicts. def extract_queries(self, args, kwargs): ''' This function normalizes the config block into a set of queries we can use. The return is a list of...
Retrieves an option based on key, merging all matches. Same as ``option()`` except that it merges all matches, rather than taking the first match. CLI Example: .. code-block:: bash salt '*' config.merge schedule def merge(value, default='', omit_opts=False, omi...
.. versionadded: 0.14.0 Attempt to retrieve the named value from opts, pillar, grains of the master config, if the named value is not available return the passed default. The default return is an empty string. The value can also represent a value in a nested dict using a ":" delimiter for the dict...
Creates Zabbix Action object or if differs update it according defined parameters :param name: Zabbix Action name :param params: Definition of the Zabbix Action :param _connection_user: Optional - zabbix user (can also be set in opts or pillar, see module's docstring) :param _connection_password: Optio...
Return True if the named service is available. CLI Example: .. code-block:: bash salt '*' service.available sshd def available(name): ''' Return True if the named service is available. CLI Example: .. code-block:: bash salt '*' service.available sshd ''' cmd = '{0}...
Return all installed services. CLI Example: .. code-block:: bash salt '*' service.get_all def get_all(): ''' Return all installed services. CLI Example: .. code-block:: bash salt '*' service.get_all ''' ret = [] service = _cmd() for svc in __salt__['cmd.run...
Return the status for a service, returns a bool whether the service is running. CLI Example: .. code-block:: bash salt '*' service.status <service name> def status(name, sig=None): ''' Return the status for a service, returns a bool whether the service is running. CLI Example: ...
Enable the named service to start at boot. flags : None Set optional flags to run the service with. service.flags can be used to change the default flags. CLI Example: .. code-block:: bash salt '*' service.enable <service name> salt '*' service.enable <service name> flags=<f...
Return True if the named service is enabled at boot and the provided flags match the configured ones (if any). Return False otherwise. name Service name CLI Example: .. code-block:: bash salt '*' service.enabled <service name> salt '*' service.enabled <service name> flags=<fl...
Creates a longer list of accepted users on the device. def _expand_users(device_users, common_users): '''Creates a longer list of accepted users on the device.''' expected_users = deepcopy(common_users) expected_users.update(device_users) return expected_users
Checks if the input dictionary of users is valid. def _check_users(users): '''Checks if the input dictionary of users is valid.''' messg = '' valid = True for user, user_details in six.iteritems(users): if not user_details: valid = False messg += 'Please provide detai...
Computes the differences between the actual config and the expected config def _compute_diff(configured, expected): '''Computes the differences between the actual config and the expected config''' diff = { 'add': {}, 'update': {}, 'remove': {} } configured_users = set(configu...
Manages the configuration of the users on the device, as specified in the state SLS file. Users not defined in that file will be remove whilst users not configured on the device, will be added. SLS Example: .. code-block:: yaml netusers_example: netusers.managed: - us...
Checks if the client has sent a ready message. A ready message causes ``send()`` to be called on the ``parent end`` of the pipe. Clients need to ensure that the pipe assigned to ``self.pipe`` is the ``parent end`` of a pipe. This ensures completion of the underlying websocket c...
Prints an info on CLI with the title. Useful for infos, general errors etc. :param data: :param title: :return: def cli_info(data, title='Info'): ''' Prints an info on CLI with the title. Useful for infos, general errors etc. :param data: :param title: :return: ''' wr...
List users belonging to this account CLI Example: salt myminion pagerduty.get_users def get_users(profile='pagerduty', subdomain=None, api_key=None): ''' List users belonging to this account CLI Example: salt myminion pagerduty.get_users ''' return _list_items( 'use...
List services belonging to this account CLI Example: salt myminion pagerduty.get_services def get_services(profile='pagerduty', subdomain=None, api_key=None): ''' List services belonging to this account CLI Example: salt myminion pagerduty.get_services ''' return _list_item...
List schedules belonging to this account CLI Example: salt myminion pagerduty.get_schedules def get_schedules(profile='pagerduty', subdomain=None, api_key=None): ''' List schedules belonging to this account CLI Example: salt myminion pagerduty.get_schedules ''' return _list...
List escalation_policies belonging to this account CLI Example: salt myminion pagerduty.get_escalation_policies def get_escalation_policies(profile='pagerduty', subdomain=None, api_key=None): ''' List escalation_policies belonging to this account CLI Example: salt myminion pagerduty...
List items belonging to an API call. This method should be in utils.pagerduty. def _list_items(action, key, profile=None, subdomain=None, api_key=None): ''' List items belonging to an API call. This method should be in utils.pagerduty. ''' items = _query( profile=profile, subd...
Query the PagerDuty API. This method should be in utils.pagerduty. def _query(method='GET', profile=None, url=None, path='api/v1', action=None, api_key=None, service=None, params=None, data=None, subdomain=None, verify_ssl=True): ''' Query the PagerDuty API. This method should b...
Get any single pagerduty resource by key. We allow flexible lookup by any of a list of identifier_fields. So, for example, you can look up users by email address or name by calling: get_resource('users', key, ['name', 'email'], ...) This method is mainly used to translate state sls into pager...
create or update any pagerduty resource Helper method for present(). Determining if two resources are the same is different for different PD resource, so this method accepts a diff function. The diff function will be invoked as diff(state_information, object_returned_from_pagerduty), and should return ...
delete any pagerduty resource Helper method for absent() example: delete_resource("users", key, ["id","name","email"]) # delete by id or name or email def delete_resource(resource_name, key, identifier_fields, profile='pagerduty', subdomain=None, api_key=None): ''' delete any pagerduty re...
Generic resource.present state method. Pagerduty state modules should be a thin wrapper over this method, with a custom diff function. This method calls create_or_update_resource() and formats the result as a salt state return value. example: resource_present("users", ["id","name","email"]) ...
Generic resource.absent state method. Pagerduty state modules should be a thin wrapper over this method, with a custom diff function. This method calls delete_resource() and formats the result as a salt state return value. example: resource_absent("users", ["id","name","email"]) def resourc...
Ensures that the artifact from nexus exists at given location. If it doesn't exist, then it will be downloaded. If it already exists then the checksum of existing file is checked against checksum in nexus. If it is different then the step will fail. artifact Details of the artifact to be downloaded...
Return the currently configured jobs. def _jobs(): ''' Return the currently configured jobs. ''' response = salt.utils.http.query( "{0}/scheduler/jobs".format(_base_url()), decode_type='json', decode=True, ) jobs = {} for job in response['dict']: jobs[job.pop...
Update the specified job with the given configuration. CLI Example: .. code-block:: bash salt chronos-minion-id chronos.update_job my-job '<config yaml>' def update_job(name, config): ''' Update the specified job with the given configuration. CLI Example: .. code-block:: bash ...
Remove the specified job from the server. CLI Example: .. code-block:: bash salt chronos-minion-id chronos.rm_job my-job def rm_job(name): ''' Remove the specified job from the server. CLI Example: .. code-block:: bash salt chronos-minion-id chronos.rm_job my-job ''' ...
Return iSCSI IQN def iscsi_iqn(): ''' Return iSCSI IQN ''' grains = {} grains['iscsi_iqn'] = False if salt.utils.platform.is_linux(): grains['iscsi_iqn'] = _linux_iqn() elif salt.utils.platform.is_windows(): grains['iscsi_iqn'] = _windows_iqn() elif salt.utils.platform.i...
Return iSCSI IQN from a Linux host. def _linux_iqn(): ''' Return iSCSI IQN from a Linux host. ''' ret = [] initiator = '/etc/iscsi/initiatorname.iscsi' try: with salt.utils.files.fopen(initiator, 'r') as _iscsi: for line in _iscsi: line = line.strip() ...
Return iSCSI IQN from an AIX host. def _aix_iqn(): ''' Return iSCSI IQN from an AIX host. ''' ret = [] aix_cmd = 'lsattr -E -l iscsi0 | grep initiator_name' aix_ret = salt.modules.cmdmod.run(aix_cmd) if aix_ret[0].isalpha(): try: ret.append(aix_ret.split()[1].rstrip())...
Return iSCSI IQN from a Windows host. def _windows_iqn(): ''' Return iSCSI IQN from a Windows host. ''' ret = [] wmic = salt.utils.path.which('wmic') if not wmic: return ret namespace = r'\\root\WMI' path = 'MSiSCSIInitiator_MethodClass' get = 'iSCSINodeName' cmd_ret...
Return the information for a specified job id CLI Example: .. code-block:: bash salt '*' ret.get_jid redis 20421104181954700505 def get_jid(returner, jid): ''' Return the information for a specified job id CLI Example: .. code-block:: bash salt '*' ret.get_jid redis 204211...
Return info about last time fun was called on each minion CLI Example: .. code-block:: bash salt '*' ret.get_fun mysql network.interfaces def get_fun(returner, fun): ''' Return info about last time fun was called on each minion CLI Example: .. code-block:: bash salt '*' re...
Return a list of all job ids CLI Example: .. code-block:: bash salt '*' ret.get_jids mysql def get_jids(returner): ''' Return a list of all job ids CLI Example: .. code-block:: bash salt '*' ret.get_jids mysql ''' returners = salt.loader.returners(__opts__, __salt_...
Return a list of all minions CLI Example: .. code-block:: bash salt '*' ret.get_minions mysql def get_minions(returner): ''' Return a list of all minions CLI Example: .. code-block:: bash salt '*' ret.get_minions mysql ''' returners = salt.loader.returners(__opts__...
Enforces the TXT record maximum length of 255 characters. TXT record length includes key, value, and '='. :param str key: Key of the TXT record :param str value: Value of the TXT record :rtype: str :return: The value of the TXT record. It may be truncated if it exceeds the maximum per...
Broadcast values via zeroconf If the announced values are static, it is advised to set run_once: True (do not poll) on the beacon configuration. The following are required configuration settings: - ``servicetype`` - The service type to announce - ``port`` - The port of the service to announce ...
Return the docstrings for all modules. Optionally, specify a module or a function to narrow the selection. The strings are aggregated into a single document on the master for easy reading. Multiple modules/functions can be specified. CLI Example: .. code-block:: bash salt '*' sys.do...
Return the docstrings for all states. Optionally, specify a state or a function to narrow the selection. The strings are aggregated into a single document on the master for easy reading. Multiple states/functions can be specified. .. versionadded:: 2014.7.0 CLI Example: .. code-block:: ...
Return the docstrings for all runners. Optionally, specify a runner or a function to narrow the selection. The strings are aggregated into a single document on the master for easy reading. Multiple runners/functions can be specified. .. versionadded:: 2014.7.0 CLI Example: .. code-block...
Return the docstrings for all returners. Optionally, specify a returner or a function to narrow the selection. The strings are aggregated into a single document on the master for easy reading. Multiple returners/functions can be specified. .. versionadded:: 2014.7.0 CLI Example: .. code...
Return the docstrings for all renderers. Optionally, specify a renderer or a function to narrow the selection. The strings are aggregated into a single document on the master for easy reading. Multiple renderers can be specified. .. versionadded:: 2015.5.0 CLI Example: .. code-block:: b...
.. versionadded:: Neon Return the docstrings for all utils modules. Optionally, specify a module or a function to narrow the selection. The strings are aggregated into a single document on the master for easy reading. Multiple modules/functions can be specified. CLI Example: .. code-blo...
List the functions for all modules. Optionally, specify a module or modules from which to list. CLI Example: .. code-block:: bash salt '*' sys.list_functions salt '*' sys.list_functions sys salt '*' sys.list_functions sys user Function names can be specified as globs. .....
List the modules loaded on the minion .. versionadded:: 2015.5.0 CLI Example: .. code-block:: bash salt '*' sys.list_modules Module names can be specified as globs. .. code-block:: bash salt '*' sys.list_modules 's*' def list_modules(*args): ''' List the modules loade...
Return the argument specification of functions in Salt state modules. .. versionadded:: 2015.5.0 CLI Example: .. code-block:: bash salt '*' sys.state_argspec pkg.installed salt '*' sys.state_argspec file salt '*' sys.state_argspec State names can be specified as globs. ...
Return the argument specification of functions in Salt returner modules. .. versionadded:: 2015.5.0 CLI Example: .. code-block:: bash salt '*' sys.returner_argspec xmpp salt '*' sys.returner_argspec xmpp smtp salt '*' sys.returner_argspec Returner names can be specified ...
Return the argument specification of functions in Salt runner modules. .. versionadded:: 2015.5.0 CLI Example: .. code-block:: bash salt '*' sys.runner_argspec state salt '*' sys.runner_argspec http salt '*' sys.runner_argspec Runner names can be specified as globs. ...
List the functions for all state modules. Optionally, specify a state module or modules from which to list. .. versionadded:: 2014.7.0 CLI Example: .. code-block:: bash salt '*' sys.list_state_functions salt '*' sys.list_state_functions file salt '*' sys.list_state_functions ...
List the modules loaded on the minion .. versionadded:: 2014.7.0 CLI Example: .. code-block:: bash salt '*' sys.list_state_modules State module names can be specified as globs. .. versionadded:: 2015.5.0 .. code-block:: bash salt '*' sys.list_state_modules 'mysql_*' def ...
List the runners loaded on the minion .. versionadded:: 2014.7.0 CLI Example: .. code-block:: bash salt '*' sys.list_runners Runner names can be specified as globs. .. versionadded:: 2015.5.0 .. code-block:: bash salt '*' sys.list_runners 'm*' def list_runners(*args): ...
List the functions for all runner modules. Optionally, specify a runner module or modules from which to list. .. versionadded:: 2014.7.0 CLI Example: .. code-block:: bash salt '*' sys.list_runner_functions salt '*' sys.list_runner_functions state salt '*' sys.list_runner_func...
List the returners loaded on the minion .. versionadded:: 2014.7.0 CLI Example: .. code-block:: bash salt '*' sys.list_returners Returner names can be specified as globs. .. versionadded:: 2015.5.0 .. code-block:: bash salt '*' sys.list_returners 's*' def list_returners(...
List the functions for all returner modules. Optionally, specify a returner module or modules from which to list. .. versionadded:: 2014.7.0 CLI Example: .. code-block:: bash salt '*' sys.list_returner_functions salt '*' sys.list_returner_functions mysql salt '*' sys.list_ret...
List the renderers loaded on the minion .. versionadded:: 2015.5.0 CLI Example: .. code-block:: bash salt '*' sys.list_renderers Render names can be specified as globs. .. code-block:: bash salt '*' sys.list_renderers 'yaml*' def list_renderers(*args): ''' List the re...
Return a JSON Schema for the given state function(s) .. versionadded:: 2016.3.0 CLI Example: .. code-block:: bash salt '*' sys.state_schema salt '*' sys.state_schema pkg.installed def state_schema(module=''): ''' Return a JSON Schema for the given state function(s) .. versi...
... versionadded:: 2016.3.2 Helper function to locate various psql related binaries def _find_pg_binary(util): ''' ... versionadded:: 2016.3.2 Helper function to locate various psql related binaries ''' pg_bin_dir = __salt__['config.option']('postgres.bins_dir') util_bin = salt.utils.pa...
Helper function to call psql, because the password requirement makes this too much code to be repeated in each function below def _run_psql(cmd, runas=None, password=None, host=None, port=None, user=None): ''' Helper function to call psql, because the password requirement makes this too much code to be...
Helper function to call initdb def _run_initdb(name, auth='password', user=None, password=None, encoding='UTF8', locale=None, runas=None, waldir=None, checksums=False): ''' Helper function to call initdb ''' if runas is None: if 'F...
Return the version of a Postgres server. CLI Example: .. code-block:: bash salt '*' postgres.version def version(user=None, host=None, port=None, maintenance_db=None, password=None, runas=None): ''' Return the version of a Postgres server. CLI Example: .. code-block:: b...
Returns the server version properly parsed and int casted for internal use. If the Postgres server does not respond, None will be returned. def _parsed_version(user=None, host=None, port=None, maintenance_db=None, password=None, runas=None): ''' Returns the server version properly pars...
Returns a tuple of (user, host, port, db) with config, pillar, or default values assigned to missing values. def _connection_defaults(user=None, host=None, port=None, maintenance_db=None): ''' Returns a tuple of (user, host, port, db) with config, pillar, or default values assigned to missing values. ...
Return string with fully composed psql command. Accepts optional keyword arguments: user, host, port and maintenance_db, as well as any number of positional arguments to be added to the end of the command. def _psql_cmd(*args, **kwargs): ''' Return string with fully composed psql command. Acc...
Run an SQL-Query and return the results as a list. This command only supports SELECT statements. This limitation can be worked around with a query like this: WITH updated AS (UPDATE pg_authid SET rolconnlimit = 2000 WHERE rolname = 'rolename' RETURNING rolconnlimit) SELECT * FROM updated; query ...
Return dictionary with information about databases of a Postgres server. CLI Example: .. code-block:: bash salt '*' postgres.db_list def db_list(user=None, host=None, port=None, maintenance_db=None, password=None, runas=None): ''' Return dictionary with information about database...
Checks if a database exists on the Postgres server. CLI Example: .. code-block:: bash salt '*' postgres.db_exists 'dbname' def db_exists(name, user=None, host=None, port=None, maintenance_db=None, password=None, runas=None): ''' Checks if a database exists on the Postgres serve...
Adds a databases to the Postgres server. CLI Example: .. code-block:: bash salt '*' postgres.db_create 'dbname' salt '*' postgres.db_create 'dbname' template=template_postgis def db_create(name, user=None, host=None, port=None, mainten...
Change tablespace or/and owner of database. CLI Example: .. code-block:: bash salt '*' postgres.db_alter dbname owner=otheruser def db_alter(name, user=None, host=None, port=None, maintenance_db=None, password=None, tablespace=None, owner=None, owner_recurse=False, runas=No...
Return dictionary with information about tablespaces of a Postgres server. CLI Example: .. code-block:: bash salt '*' postgres.tablespace_list .. versionadded:: 2015.8.0 def tablespace_list(user=None, host=None, port=None, maintenance_db=None, password=None, runas=None): ...
Checks if a tablespace exists on the Postgres server. CLI Example: .. code-block:: bash salt '*' postgres.tablespace_exists 'dbname' .. versionadded:: 2015.8.0 def tablespace_exists(name, user=None, host=None, port=None, maintenance_db=None, password=None, runas=None): ''' ...
Adds a tablespace to the Postgres server. CLI Example: .. code-block:: bash salt '*' postgres.tablespace_create tablespacename '/path/datadir' .. versionadded:: 2015.8.0 def tablespace_create(name, location, options=None, owner=None, user=None, host=None, port=None, mainte...
Change tablespace name, owner, or options. CLI Example: .. code-block:: bash salt '*' postgres.tablespace_alter tsname new_owner=otheruser salt '*' postgres.tablespace_alter index_space new_name=fast_raid salt '*' postgres.tablespace_alter test set_option="{'seq_page_cost': '1.1'}" ...
Removes a tablespace from the Postgres server. CLI Example: .. code-block:: bash salt '*' postgres.tablespace_remove tsname .. versionadded:: 2015.8.0 def tablespace_remove(name, user=None, host=None, port=None, maintenance_db=None, password=None, runas=None): ''' ...
Return a dict with information about users of a Postgres server. Set return_password to True to get password hash in the result. CLI Example: .. code-block:: bash salt '*' postgres.user_list def user_list(user=None, host=None, port=None, maintenance_db=None, password=None, runas=N...
Return a dict with information about users of a Postgres server. Set return_password to True to get password hash in the result. CLI Example: .. code-block:: bash salt '*' postgres.role_get postgres def role_get(name, user=None, host=None, port=None, maintenance_db=None, password=N...
Checks if a user exists on the Postgres server. CLI Example: .. code-block:: bash salt '*' postgres.user_exists 'username' def user_exists(name, user=None, host=None, port=None, maintenance_db=None, password=None, runas=None): ''' Checks if a u...
pgsql passwords are md5 hashes of the string: 'md5{password}{rolename}' def _maybe_encrypt_password(role, password, encrypted=_DEFAULT_PASSWORDS_ENCRYPTION): ''' pgsql passwords are md5 hashes of the string: 'md5{password}{rolename}' ''' if passwo...
Creates a Postgres role. Users and Groups are both roles in postgres. However, users can login, groups cannot. def _role_create(name, user=None, host=None, port=None, maintenance_db=None, password=None, createdb=N...
Creates a Postgres user. CLI Examples: .. code-block:: bash salt '*' postgres.user_create 'username' user='user' \\ host='hostname' port='port' password='password' \\ rolepassword='rolepassword' valid_until='valid_until' def user_create(username, user=...
Updates a postgres role. def _role_update(name, user=None, host=None, port=None, maintenance_db=None, password=None, createdb=None, typ_='role', createroles=None, inh...
Removes a role from the Postgres Server def _role_remove(name, user=None, host=None, port=None, maintenance_db=None, password=None, runas=None): ''' Removes a role from the Postgres Server ''' # check if user exists if not user_exists(name, user, host, port, maintenance_db, ...
List installed postgresql extensions CLI Example: .. code-block:: bash salt '*' postgres.installed_extensions def installed_extensions(user=None, host=None, port=None, maintenance_db=None, password=No...
Get info about an available postgresql extension CLI Example: .. code-block:: bash salt '*' postgres.get_available_extension plpgsql def get_available_extension(name, user=None, host=None, port=None, ...
Get info about an installed postgresql extension CLI Example: .. code-block:: bash salt '*' postgres.get_installed_extension plpgsql def get_installed_extension(name, user=None, host=None, port=None, ...
Test if a specific extension is available CLI Example: .. code-block:: bash salt '*' postgres.is_available_extension def is_available_extension(name, user=None, host=None, port=None, maintenan...