INSTRUCTION
stringlengths
1
8.43k
RESPONSE
stringlengths
75
104k
.. versionadded:: 2016. 3. 0
def file_exists(path, saltenv=None): ''' .. versionadded:: 2016.3.0 This is a master-only function. Calling from the minion is not supported. Use the given path and search relative to the pillar environments to see if a file exists at that path. If the ``saltenv`` argument is given, restrict ...
.. versionadded:: 2017. 7. 0
def filter_by(lookup_dict, pillar, merge=None, default='default', base=None): ''' .. versionadded:: 2017.7.0 Look up the given pillar in a given dictionary and return the result :param lookup_dict: A dictionary, keyed by a pillar, containing a va...
Get Pure Storage FlashArray configuration
def _get_system(): ''' Get Pure Storage FlashArray configuration 1) From the minion config pure_tags: fa: san_ip: management vip or hostname for the FlashArray api_token: A valid api token for the FlashArray being managed 2) From environment (PUREFA_IP and PURE...
Private function to check snapshot
def _get_snapshot(name, suffix, array): '''Private function to check snapshot''' snapshot = name + '.' + suffix try: for snap in array.get_volume(name, snap=True): if snap['name'] == snapshot: return snapshot except purestorage.PureError: return None
Private function to check protection group
def _get_pgroup(name, array): '''Private function to check protection group''' pgroup = None for temp in array.list_pgroups(): if temp['name'] == name: pgroup = temp break return pgroup
Private function to check hostgroup
def _get_hgroup(name, array): '''Private function to check hostgroup''' hostgroup = None for temp in array.list_hgroups(): if temp['name'] == name: hostgroup = temp break return hostgroup
Private function to check host
def _get_host(name, array): '''Private function to check host''' host = None for temp in array.list_hosts(): if temp['name'] == name: host = temp break return host
Ensure the SNS topic exists.
def present( name, subscriptions=None, region=None, key=None, keyid=None, profile=None): ''' Ensure the SNS topic exists. name Name of the SNS topic. subscriptions List of SNS subscriptions. Each subscription is a dictionary with...
Ensure the named sns topic is deleted.
def absent( name, region=None, key=None, keyid=None, profile=None, unsubscribe=False): ''' Ensure the named sns topic is deleted. name Name of the SNS topic. region Region to connect to. key Secret key to be used. keyid ...
List all available locations
def avail_locations(call=None): ''' List all available locations ''' if call == 'action': raise SaltCloudSystemExit( 'The avail_locations function must be called with ' '-f or --function, or with the --list-locations option' ) ret = {} conn = get_conn(ser...
Return a dict of all available VM images on the cloud provider.
def avail_images(call=None): ''' Return a dict of all available VM images on the cloud provider. ''' if call == 'action': raise SaltCloudSystemExit( 'The avail_images function must be called with ' '-f or --function, or with the --list-images option' ) ret = ...
Create a single VM from a data dict
def create(vm_): ''' Create a single VM from a data dict ''' try: # Check for required profile parameters before sending any API calls. if vm_['profile'] and config.is_profile_configured(__opts__, __active_provider_name__ or 'sof...
Return a list of the VMs that are on the provider
def list_nodes_full(mask='mask[id, hostname, primaryIpAddress, \ primaryBackendIpAddress, processorPhysicalCoreAmount, memoryCount]', call=None): ''' Return a list of the VMs that are on the provider ''' if call == 'action': raise SaltCloudSystemExit( 'The list_nodes_...
Show pricing for a particular profile. This is only an estimate based on unofficial pricing sources.
def show_pricing(kwargs=None, call=None): ''' Show pricing for a particular profile. This is only an estimate, based on unofficial pricing sources. CLI Examples: .. code-block:: bash salt-cloud -f show_pricing my-softlayerhw-config profile=my-profile If pricing sources have not been ...
Return a dict of all prices on the cloud provider.
def show_all_prices(call=None, kwargs=None): ''' Return a dict of all prices on the cloud provider. ''' if call == 'action': raise SaltCloudSystemExit( 'The show_all_prices function must be called with -f or --function.' ) if kwargs is None: kwargs = {} conn...
Return a dict of all available categories on the cloud provider.
def show_all_categories(call=None): ''' Return a dict of all available categories on the cloud provider. .. versionadded:: 2016.3.0 ''' if call == 'action': raise SaltCloudSystemExit( 'The show_all_categories function must be called with -f or --function.' ) conn = ...
wrap authentication credentials here
def _connect(**kwargs): ''' wrap authentication credentials here ''' connargs = dict() def _connarg(name, key=None, get_opts=True): ''' Add key to connargs, only if name exists in our kwargs or, if get_opts is true, as mysql.<name> in __opts__ or __pillar__ If get_o...
r Return an identifier name ( column table database etc ) escaped for MySQL
def quote_identifier(identifier, for_grants=False): r''' Return an identifier name (column, table, database, etc) escaped for MySQL This means surrounded by "`" character and escaping this character inside. It also means doubling the '%' character for MySQLdb internal usage. :param identifier: the...
Internal wrapper around MySQLdb cursor. execute () function
def _execute(cur, qry, args=None): ''' Internal wrapper around MySQLdb cursor.execute() function MySQLDb does not apply the same filters when arguments are used with the query. For example '%' characters on the query must be encoded as '%%' and will be restored as '%' when arguments are applied. Bu...
Run an arbitrary SQL query and return the results or the number of affected rows.
def query(database, query, **connection_args): ''' Run an arbitrary SQL query and return the results or the number of affected rows. CLI Example: .. code-block:: bash salt '*' mysql.query mydb "UPDATE mytable set myfield=1 limit 1" Return data: .. code-block:: python {'...
Run an arbitrary SQL query from the specified file and return the the number of affected rows.
def file_query(database, file_name, **connection_args): ''' Run an arbitrary SQL query from the specified file and return the the number of affected rows. .. versionadded:: 2017.7.0 database database to run script inside file_name File name of the script. This can be on the...
Return the status of a MySQL server using the output from the SHOW STATUS query.
def status(**connection_args): ''' Return the status of a MySQL server using the output from the ``SHOW STATUS`` query. CLI Example: .. code-block:: bash salt '*' mysql.status ''' dbc = _connect(**connection_args) if dbc is None: return {} cur = dbc.cursor() qr...
Return the version of a MySQL server using the output from the SELECT VERSION () query.
def version(**connection_args): ''' Return the version of a MySQL server using the output from the ``SELECT VERSION()`` query. CLI Example: .. code-block:: bash salt '*' mysql.version ''' dbc = _connect(**connection_args) if dbc is None: return '' cur = dbc.cursor(...
Return the number of seconds that a slave SQL server is lagging behind the master if the host is not a slave it will return - 1. If the server is configured to be a slave for replication but slave IO is not running then - 2 will be returned. If there was an error connecting to the database or checking the slave status ...
def slave_lag(**connection_args): ''' Return the number of seconds that a slave SQL server is lagging behind the master, if the host is not a slave it will return -1. If the server is configured to be a slave for replication but slave IO is not running then -2 will be returned. If there was an erro...
Frees a slave from its master. This is a WIP do not use.
def free_slave(**connection_args): ''' Frees a slave from its master. This is a WIP, do not use. CLI Example: .. code-block:: bash salt '*' mysql.free_slave ''' slave_db = _connect(**connection_args) if slave_db is None: return '' slave_cur = slave_db.cursor(MySQLdb.c...
Return a list of databases of a MySQL server using the output from the SHOW DATABASES query.
def db_list(**connection_args): ''' Return a list of databases of a MySQL server using the output from the ``SHOW DATABASES`` query. CLI Example: .. code-block:: bash salt '*' mysql.db_list ''' dbc = _connect(**connection_args) if dbc is None: return [] cur = dbc.c...
Modify database using ALTER DATABASE % ( dbname ) s CHARACTER SET % ( charset ) s COLLATE % ( collation ) s ; query.
def alter_db(name, character_set=None, collate=None, **connection_args): ''' Modify database using ``ALTER DATABASE %(dbname)s CHARACTER SET %(charset)s COLLATE %(collation)s;`` query. CLI Example: .. code-block:: bash salt '*' mysql.alter_db testdb charset='latin1' ''' dbc = _con...
Return a list of databases of a MySQL server using the output from the SELECT DEFAULT_CHARACTER_SET_NAME DEFAULT_COLLATION_NAME FROM INFORMATION_SCHEMA. SCHEMATA WHERE SCHEMA_NAME = dbname ; query.
def db_get(name, **connection_args): ''' Return a list of databases of a MySQL server using the output from the ``SELECT DEFAULT_CHARACTER_SET_NAME, DEFAULT_COLLATION_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME='dbname';`` query. CLI Example: .. code-block:: bash salt '*' ...
Shows the tables in the given MySQL database ( if exists )
def db_tables(name, **connection_args): ''' Shows the tables in the given MySQL database (if exists) CLI Example: .. code-block:: bash salt '*' mysql.db_tables 'database' ''' if not db_exists(name, **connection_args): log.info('Database \'%s\' does not exist', name) re...
Checks if a database exists on the MySQL server.
def db_exists(name, **connection_args): ''' Checks if a database exists on the MySQL server. CLI Example: .. code-block:: bash salt '*' mysql.db_exists 'dbname' ''' dbc = _connect(**connection_args) if dbc is None: return False cur = dbc.cursor() # Warn: here db id...
Adds a databases to the MySQL server.
def db_create(name, character_set=None, collate=None, **connection_args): ''' Adds a databases to the MySQL server. name The name of the database to manage character_set The character set, if left empty the MySQL default will be used collate The collation, if left empty th...
Removes a databases from the MySQL server.
def db_remove(name, **connection_args): ''' Removes a databases from the MySQL server. CLI Example: .. code-block:: bash salt '*' mysql.db_remove 'dbname' ''' # check if db exists if not db_exists(name, **connection_args): log.info('DB \'%s\' does not exist', name) ...
Return a list of users on a MySQL server
def user_list(**connection_args): ''' Return a list of users on a MySQL server CLI Example: .. code-block:: bash salt '*' mysql.user_list ''' dbc = _connect(**connection_args) if dbc is None: return [] cur = dbc.cursor(MySQLdb.cursors.DictCursor) try: qry =...
Checks if a user exists on the MySQL server. A login can be checked to see if passwordless login is permitted by omitting password and password_hash and using passwordless = True.
def user_exists(user, host='localhost', password=None, password_hash=None, passwordless=False, unix_socket=False, password_column=None, **connection_args): ''' Checks if a user exists on the MySQL ser...
Get full info on a MySQL user
def user_info(user, host='localhost', **connection_args): ''' Get full info on a MySQL user CLI Example: .. code-block:: bash salt '*' mysql.user_info root localhost ''' dbc = _connect(**connection_args) if dbc is None: return False cur = dbc.cursor(MySQLdb.cursors.Di...
Creates a MySQL user
def user_create(user, host='localhost', password=None, password_hash=None, allow_passwordless=False, unix_socket=False, password_column=None, **connection_args): ''' Creates a MySQL user host ...
Change password for a MySQL user
def user_chpass(user, host='localhost', password=None, password_hash=None, allow_passwordless=False, unix_socket=None, password_column=None, **connection_args): ''' Change password for a MySQL user ...
Delete MySQL user
def user_remove(user, host='localhost', **connection_args): ''' Delete MySQL user CLI Example: .. code-block:: bash salt '*' mysql.user_remove frank localhost ''' dbc = _connect(**connection_args) if dbc is None: return False cur = dbc....
Repairs the full database or just a given table
def db_check(name, table=None, **connection_args): ''' Repairs the full database or just a given table CLI Example: .. code-block:: bash salt '*' mysql.db_check dbname salt '*' mysql.db_check dbname dbtable ''' ret = [] if table is None: #...
Repairs the full database or just a given table
def db_repair(name, table=None, **connection_args): ''' Repairs the full database or just a given table CLI Example: .. code-block:: bash salt '*' mysql.db_repair dbname ''' ret = [] if table is None: # we need to repair all tables table...
Optimizes the full database or just a given table
def db_optimize(name, table=None, **connection_args): ''' Optimizes the full database or just a given table CLI Example: .. code-block:: bash salt '*' mysql.db_optimize dbname ''' ret = [] if table is None: # we need to optimize all tables ...
Validate grants and build the query that could set the given grants
def __grant_generate(grant, database, user, host='localhost', grant_option=False, escape=True, ssl_option=False): ''' Validate grants and build the query that could set the given grants N...
Shows the grants for the given MySQL user ( if it exists )
def user_grants(user, host='localhost', **connection_args): ''' Shows the grants for the given MySQL user (if it exists) CLI Example: .. code-block:: bash salt '*' mysql.user_grants 'frank' 'localhost' ''' if not user_exists(user, host, **connection_args): log....
Checks to see if a grant exists in the database
def grant_exists(grant, database, user, host='localhost', grant_option=False, escape=True, **connection_args): ''' Checks to see if a grant exists in the database CLI Example: .. code-block:: bash ...
Adds a grant to the MySQL server.
def grant_add(grant, database, user, host='localhost', grant_option=False, escape=True, ssl_option=False, **connection_args): ''' Adds a grant to the MySQL server. For database, make sure you specify database....
Removes a grant from the MySQL server.
def grant_revoke(grant, database, user, host='localhost', grant_option=False, escape=True, **connection_args): ''' Removes a grant from the MySQL server. CLI Example: .. code-block:: bash sal...
Retrieves the processlist from the MySQL server via SHOW FULL PROCESSLIST.
def processlist(**connection_args): ''' Retrieves the processlist from the MySQL server via "SHOW FULL PROCESSLIST". Returns: a list of dicts, with each dict representing a process: .. code-block:: python {'Command': 'Query', 'Host': 'localhost', 'Id': 39, 'Info': ...
Perform the query that is passed to it ( sql_str ).
def __do_query_into_hash(conn, sql_str): ''' Perform the query that is passed to it (sql_str). Returns: results in a dict. ''' mod = sys._getframe().f_code.co_name log.debug('%s<--(%s)', mod, sql_str) rtn_results = [] try: cursor = conn.cursor() except MySQLdb.MySQ...
Retrieves the master status from the minion.
def get_master_status(**connection_args): ''' Retrieves the master status from the minion. Returns:: {'host.domain.com': {'Binlog_Do_DB': '', 'Binlog_Ignore_DB': '', 'File': 'mysql-bin.000021', 'Position': 107}} CLI Ex...
Attempt to login using the provided credentials. If successful return true. Otherwise return False.
def verify_login(user, password=None, **connection_args): ''' Attempt to login using the provided credentials. If successful, return true. Otherwise, return False. CLI Example: .. code-block:: bash salt '*' mysql.verify_login root password ''' # Override the connection args for u...
Backwards compatibility
def call_func(self, fun, **kwargs): ''' Backwards compatibility ''' return self.low(fun, kwargs, print_event=kwargs.get('print_event', True), full_return=kwargs.get('full_return', False))
Execute a wheel function through the master network interface ( eauth ).
def master_call(self, **kwargs): ''' Execute a wheel function through the master network interface (eauth). ''' load = kwargs load['cmd'] = 'wheel' interface = self.opts['interface'] if interface == '0.0.0.0': interface = '127.0.0.1' master_uri...
Execute a function asynchronously ; eauth is respected
def cmd_async(self, low): ''' Execute a function asynchronously; eauth is respected This function requires that :conf_master:`external_auth` is configured and the user is authorized .. code-block:: python >>> wheel.cmd_async({ 'fun': 'key.finger', ...
Execute a function
def cmd(self, fun, arg=None, pub_data=None, kwarg=None, print_event=True, full_return=False): ''' Execute a function .. code-block:: python >>> wheel.cmd('key.finger', ['jerry']) {'minions': {'jerry': '5d:f6:79:43:5e:d4:42:3f:57:b8:45:a8:7e:a4:6e:ca'}} ''' ...
Add a new var to the make. conf. If using layman the source line for the layman make. conf needs to be at the very end of the config. This ensures that the new var will be above the source line.
def _add_var(var, value): ''' Add a new var to the make.conf. If using layman, the source line for the layman make.conf needs to be at the very end of the config. This ensures that the new var will be above the source line. ''' makeconf = _get_makeconf() layman = 'source /var/lib/layman/...
Set a variable in the make. conf
def set_var(var, value): ''' Set a variable in the make.conf Return a dict containing the new value for variable:: {'<variable>': {'old': '<old-value>', 'new': '<new-value>'}} CLI Example: .. code-block:: bash salt '*' makeconf.set_var 'LINGUAS' 'en' ...
Remove a variable from the make. conf
def remove_var(var): ''' Remove a variable from the make.conf Return a dict containing the new value for the variable:: {'<variable>': {'old': '<old-value>', 'new': '<new-value>'}} CLI Example: .. code-block:: bash salt '*' makeconf.remove_var 'LINGUAS' ...
Add to or create a new variable in the make. conf
def append_var(var, value): ''' Add to or create a new variable in the make.conf Return a dict containing the new value for variable:: {'<variable>': {'old': '<old-value>', 'new': '<new-value>'}} CLI Example: .. code-block:: bash salt '*' makeconf.append_...
Remove a value from a variable in the make. conf
def trim_var(var, value): ''' Remove a value from a variable in the make.conf Return a dict containing the new value for variable:: {'<variable>': {'old': '<old-value>', 'new': '<new-value>'}} CLI Example: .. code-block:: bash salt '*' makeconf.trim_var '...
Get the value of a variable in make. conf
def get_var(var): ''' Get the value of a variable in make.conf Return the value of the variable or None if the variable is not in make.conf CLI Example: .. code-block:: bash salt '*' makeconf.get_var 'LINGUAS' ''' makeconf = _get_makeconf() # Open makeconf with salt.u...
Verify if variable contains a value in make. conf
def var_contains(var, value): ''' Verify if variable contains a value in make.conf Return True if value is set for var CLI Example: .. code-block:: bash salt '*' makeconf.var_contains 'LINGUAS' 'en' ''' setval = get_var(var) # Remove any escaping that was needed to past throu...
Context manager to ensure the clean creation and destruction of a socket.
def _carbon(host, port): ''' Context manager to ensure the clean creation and destruction of a socket. host The IP or hostname of the carbon server port The port that carbon is listening on ''' carbon_sock = None try: carbon_sock = socket.socket(socket.AF_INET, sock...
Format metrics for the carbon pickle protocol
def _send_picklemetrics(metrics): ''' Format metrics for the carbon pickle protocol ''' metrics = [(metric_name, (timestamp, value)) for (metric_name, value, timestamp) in metrics] data = cPickle.dumps(metrics, -1) payload = struct.pack(b'!L', len(data)) + data return paylo...
Format metrics for the carbon plaintext protocol
def _send_textmetrics(metrics): ''' Format metrics for the carbon plaintext protocol ''' data = [' '.join(map(six.text_type, metric)) for metric in metrics] + [''] return '\n'.join(data)
Recursively include metrics from * value *.
def _walk(path, value, metrics, timestamp, skip): ''' Recursively include metrics from *value*. path The dot-separated path of the metric. value A dictionary or value from a dictionary. If a dictionary, ``_walk`` will be called again with the each key/value pair as a new set of ...
Send the data to carbon
def _send(saltdata, metric_base, opts): ''' Send the data to carbon ''' host = opts.get('host') port = opts.get('port') skip = opts.get('skip') metric_base_pattern = opts.get('carbon.metric_base_pattern') mode = opts.get('mode').lower() if 'mode' in opts else 'text' log.debug('Carb...
Return event data to remote carbon server
def event_return(events): ''' Return event data to remote carbon server Provide a list of events to be stored in carbon ''' opts = _get_options({}) # Pass in empty ret, since this is a list of events opts['skip'] = True for event in events: log.trace('Carbon returner received event...
Return data to a remote carbon server using the text metric protocol
def returner(ret): ''' Return data to a remote carbon server using the text metric protocol Each metric will look like:: [module].[function].[minion_id].[metric path [...]].[metric name] ''' opts = _get_options(ret) metric_base = ret['fun'] # Strip the hostname from the carbon bas...
Check to see if a stack exists.
def exists(name, region=None, key=None, keyid=None, profile=None): ''' Check to see if a stack exists. CLI Example: .. code-block:: bash salt myminion boto_cfn.exists mystack region=us-east-1 ''' conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile) try: ...
Describe a stack.
def describe(name, region=None, key=None, keyid=None, profile=None): ''' Describe a stack. .. versionadded:: 2015.8.0 CLI Example: .. code-block:: bash salt myminion boto_cfn.describe mystack region=us-east-1 ''' conn = _get_conn(region=region, key=key, keyid=keyid, profile=profi...
Create a CFN stack.
def create(name, template_body=None, template_url=None, parameters=None, notification_arns=None, disable_rollback=None, timeout_in_minutes=None, capabilities=None, tags=None, on_failure=None, stack_policy_body=None, stack_policy_url=None, region=None, key=None, keyid=None, profile=None): ''' ...
Update a CFN stack.
def update_stack(name, template_body=None, template_url=None, parameters=None, notification_arns=None, disable_rollback=False, timeout_in_minutes=None, capabilities=None, tags=None, use_previous_template=None, stack_policy_during_update_body=None, stack_policy_during_update_url=None, ...
Delete a CFN stack.
def delete(name, region=None, key=None, keyid=None, profile=None): ''' Delete a CFN stack. CLI Example: .. code-block:: bash salt myminion boto_cfn.delete mystack region=us-east-1 ''' conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile) try: return conn....
Check to see if attributes are set on a CFN stack.
def get_template(name, region=None, key=None, keyid=None, profile=None): ''' Check to see if attributes are set on a CFN stack. CLI Example: .. code-block:: bash salt myminion boto_cfn.get_template mystack ''' conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile) ...
Validate cloudformation template
def validate_template(template_body=None, template_url=None, region=None, key=None, keyid=None, profile=None): ''' Validate cloudformation template .. versionadded:: 2015.8.0 CLI Example: .. code-block:: bash salt myminion boto_cfn.validate_template mystack-template ''' conn = _g...
Run the specified service with an action.
def run(name, action): ''' Run the specified service with an action. .. versionadded:: 2015.8.1 name Service name. action Action name (like start, stop, reload, restart). CLI Example: .. code-block:: bash salt '*' service.run apache2 reload salt '*' s...
Return the status for a service. If the name contains globbing a dict mapping service name to PID or empty string is returned.
def status(name, sig=None): ''' 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 ser...
Return a list of all available services
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__.get('os'), '/etc/init.d')): return [] return sorted(os.listdir(_GRAINMAP.get(__grains__.get('os'), '/etc/...
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.tenant'], 'auth_url': c...
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.list_networks() for netw...
Ensure that the named database is present with the specified options
def present(name, containment='NONE', options=None, **kwargs): ''' 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 dictionar...
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': client = 'pillar' return { 'remote': RemoteClient, 'local': FSCli...
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 these types. ''' if not six.PY3 or not isinstance(src, dict): return src output = {} for key, val in six.iteritems(src):...
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)) file_path, saltenv = salt.utils.url.parse(path) return file_pa...
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() for root, dirs, files in salt.utils.path.os_walk(...
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(cachedir, 'files', ...
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 local files or master depending on implementation ''' rais...
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( path, '', True, saltenv, cachedir=cachedir, source_hash=source_hash)
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(paths, six.string_types): paths = paths.split(',') for path in paths: ...
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( self.cache_file( salt.utils.url.create(path...
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(salt.utils.data.decode(path)) # We want to m...
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 = os.path.dirname(dest) if not os.path.isdir(destdi...
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['cachedir'], 'localfiles') fdest = self._file_local_lis...
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 ''' if path.startswith('salt://'): path, senv = salt.utils.url.parse(path) if senv: ...
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 == '': # Local file path return url if proto == 'salt': ...
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): if salt.utils.platform.is_windows(): path = path.replace('\\', '/') ...
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 '.' in sls: sls = sls.replace('.', '/') sls_url = salt.utils.url.create(sls + '.sls') ...
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('/') # Break up the path into a list containi...
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.join( url_data.net...
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 ''' if 'env' in kwargs: ...