INSTRUCTION
stringlengths
1
46.3k
RESPONSE
stringlengths
75
80.2k
Ensures that the host does not exists, eventually deletes host. .. versionadded:: 2016.3.0 :param: name: technical name of the host :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 a...
def absent(name, **kwargs): """ Ensures that the host does not exists, eventually deletes host. .. versionadded:: 2016.3.0 :param: name: technical name of the host :param _connection_user: Optional - zabbix user (can also be set in opts or pillar, see module's docstring) :param _connection_pas...
Ensures that templates are assigned to the host. .. versionadded:: 2017.7.0 :param host: technical name of the host :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 op...
def assign_templates(host, templates, **kwargs): ''' Ensures that templates are assigned to the host. .. versionadded:: 2017.7.0 :param host: technical name of the host :param _connection_user: Optional - zabbix user (can also be set in opts or pillar, see module's docstring) :param _connectio...
This function gets called when the proxy starts up.
def init(opts): ''' This function gets called when the proxy starts up. ''' if 'host' not in opts['proxy']: log.critical('No \'host\' key found in pillar for this proxy.') return False if 'username' not in opts['proxy']: log.critical('No \'username\' key found in pillar for t...
The configConfMo method configures the specified managed object in a single subtree (for example, DN).
def set_config_modify(dn=None, inconfig=None, hierarchical=False): ''' The configConfMo method configures the specified managed object in a single subtree (for example, DN). ''' ret = {} cookie = logon() # Declare if the search contains hierarchical results. h = "false" if hierarchical ...
Logs into the cimc device and returns the session cookie.
def logon(): ''' Logs into the cimc device and returns the session cookie. ''' content = {} payload = "<aaaLogin inName='{0}' inPassword='{1}'></aaaLogin>".format(DETAILS['username'], DETAILS['password']) r = __utils__['http.query'](DETAILS['url'], data=payload, ...
Closes the session with the device.
def logout(cookie=None): ''' Closes the session with the device. ''' payload = '<aaaLogout cookie="{0}" inCookie="{0}"></aaaLogout>'.format(cookie) __utils__['http.query'](DETAILS['url'], data=payload, method='POST', ...
Converts the etree to dict
def prepare_return(x): ''' Converts the etree to dict ''' ret = {} for a in list(x): if a.tag not in ret: ret[a.tag] = [] ret[a.tag].append(prepare_return(a)) for a in x.attrib: ret[a] = x.attrib[a] return ret
Get the grains from the proxied device
def grains(): ''' Get the grains from the proxied device ''' if not DETAILS.get('grains_cache', {}): DETAILS['grains_cache'] = GRAINS_CACHE try: compute_rack = get_config_resolver_class('computeRackUnit', False) DETAILS['grains_cache'] = compute_rack['outConfigs']...
Returns true if the device is reachable, else false.
def ping(): ''' Returns true if the device is reachable, else false. ''' try: cookie = logon() logout(cookie) except salt.exceptions.CommandExecutionError: return False except Exception as err: log.debug(err) return False return True
Guess an archive type (tar, zip, or rar) by its file extension
def guess_archive_type(name): ''' Guess an archive type (tar, zip, or rar) by its file extension ''' name = name.lower() for ending in ('tar', 'tar.gz', 'tgz', 'tar.bz2', 'tbz2', 'tbz', 'tar.xz', 'txz', 'tar.lzma', 'tlz'): if name.ends...
Helper function which does exactly what ``tempfile.mkstemp()`` does but accepts another argument, ``close_fd``, which, by default, is true and closes the fd before returning the file path. Something commonly done throughout Salt's code.
def mkstemp(*args, **kwargs): ''' Helper function which does exactly what ``tempfile.mkstemp()`` does but accepts another argument, ``close_fd``, which, by default, is true and closes the fd before returning the file path. Something commonly done throughout Salt's code. ''' if 'prefix' not i...
Recursively copy the source directory to the destination, leaving files with the source does not explicitly overwrite. (identical to cp -r on a unix machine)
def recursive_copy(source, dest): ''' Recursively copy the source directory to the destination, leaving files with the source does not explicitly overwrite. (identical to cp -r on a unix machine) ''' for root, _, files in salt.utils.path.os_walk(source): path_from_source = root.replace(...
Copy files from a source to a destination in an atomic way, and if specified cache the file.
def copyfile(source, dest, backup_mode='', cachedir=''): ''' Copy files from a source to a destination in an atomic way, and if specified cache the file. ''' if not os.path.isfile(source): raise IOError( '[Errno 2] No such file or directory: {0}'.format(source) ) if n...
On Windows, os.rename() will fail with a WindowsError exception if a file exists at the destination path. This function checks for this error and if found, it deletes the destination path first.
def rename(src, dst): ''' On Windows, os.rename() will fail with a WindowsError exception if a file exists at the destination path. This function checks for this error and if found, it deletes the destination path first. ''' try: os.rename(src, dst) except OSError as exc: if ...
Common code for raising exceptions when reading a file fails The ignore argument can be an iterable of integer error codes (or a single integer error code) that should be ignored.
def process_read_exception(exc, path, ignore=None): ''' Common code for raising exceptions when reading a file fails The ignore argument can be an iterable of integer error codes (or a single integer error code) that should be ignored. ''' if ignore is not None: if isinstance(ignore, si...
Obtain a write lock. If one exists, wait for it to release first
def wait_lock(path, lock_fn=None, timeout=5, sleep=0.1, time_start=None): ''' Obtain a write lock. If one exists, wait for it to release first ''' if not isinstance(path, six.string_types): raise FileLockError('path must be a string') if lock_fn is None: lock_fn = path + '.w' if ...
Temporarily set the umask and restore once the contextmanager exits
def set_umask(mask): ''' Temporarily set the umask and restore once the contextmanager exits ''' if mask is None or salt.utils.platform.is_windows(): # Don't attempt on Windows, or if no mask was passed yield else: try: orig_mask = os.umask(mask) # pylint: disabl...
Wrapper around open() built-in to set CLOEXEC on the fd. This flag specifies that the file descriptor should be closed when an exec function is invoked; When a file descriptor is allocated (as with open or dup), this bit is initially cleared on the new file descriptor, meaning that descriptor will ...
def fopen(*args, **kwargs): ''' Wrapper around open() built-in to set CLOEXEC on the fd. This flag specifies that the file descriptor should be closed when an exec function is invoked; When a file descriptor is allocated (as with open or dup), this bit is initially cleared on the new file desc...
Shortcut for fopen with lock and context manager.
def flopen(*args, **kwargs): ''' Shortcut for fopen with lock and context manager. ''' filename, args = args[0], args[1:] writing = 'wa' with fopen(filename, *args, **kwargs) as f_handle: try: if is_fcntl_available(check_sunos=True): lock_type = fcntl.LOCK_SH ...
Shortcut for fopen with extra uid, gid, and mode options. Supported optional Keyword Arguments: mode Explicit mode to set. Mode is anything os.chmod would accept as input for mode. Works only on unix/unix-like systems. uid The uid to set, if not set, or it is None or -1 no changes...
def fpopen(*args, **kwargs): ''' Shortcut for fopen with extra uid, gid, and mode options. Supported optional Keyword Arguments: mode Explicit mode to set. Mode is anything os.chmod would accept as input for mode. Works only on unix/unix-like systems. uid The uid to set, i...
A clone of the python os.walk function with some checks for recursive symlinks. Unlike os.walk this follows symlinks by default.
def safe_walk(top, topdown=True, onerror=None, followlinks=True, _seen=None): ''' A clone of the python os.walk function with some checks for recursive symlinks. Unlike os.walk this follows symlinks by default. ''' if _seen is None: _seen = set() # We may not have read permission for to...
Platform-independent recursive delete. Includes code from http://stackoverflow.com/a/2656405
def rm_rf(path): ''' Platform-independent recursive delete. Includes code from http://stackoverflow.com/a/2656405 ''' def _onerror(func, path, exc_info): ''' Error handler for `shutil.rmtree`. If the error is due to an access error (read only file) it attempts to add...
Simple function to check if the ``fcntl`` module is available or not. If ``check_sunos`` is passed as ``True`` an additional check to see if host is SunOS is also made. For additional information see: http://goo.gl/159FF8
def is_fcntl_available(check_sunos=False): ''' Simple function to check if the ``fcntl`` module is available or not. If ``check_sunos`` is passed as ``True`` an additional check to see if host is SunOS is also made. For additional information see: http://goo.gl/159FF8 ''' if check_sunos and sal...
Input the basename of a file, without the directory tree, and returns a safe name to use i.e. only the required characters are converted by urllib.quote If the input is a PY2 String, output a PY2 String. If input is Unicode output Unicode. For consistency all platforms are treated the same. Hard coded to ut...
def safe_filename_leaf(file_basename): ''' Input the basename of a file, without the directory tree, and returns a safe name to use i.e. only the required characters are converted by urllib.quote If the input is a PY2 String, output a PY2 String. If input is Unicode output Unicode. For consistency a...
Input the full path and filename, splits on directory separator and calls safe_filename_leaf for each part of the path. dir_sep allows coder to force a directory separate to a particular character .. versionadded:: 2017.7.2 :codeauthor: Damon Atkins <https://github.com/damon-atkins>
def safe_filepath(file_path_name, dir_sep=None): ''' Input the full path and filename, splits on directory separator and calls safe_filename_leaf for each part of the path. dir_sep allows coder to force a directory separate to a particular character .. versionadded:: 2017.7.2 :codeauthor: Damon At...
Uses heuristics to guess whether the given file is text or binary, by reading a single block of bytes from the file. If more than 30% of the chars in the block are non-text, or there are NUL ('\x00') bytes in the block, assume this is a binary file.
def is_text(fp_, blocksize=512): ''' Uses heuristics to guess whether the given file is text or binary, by reading a single block of bytes from the file. If more than 30% of the chars in the block are non-text, or there are NUL ('\x00') bytes in the block, assume this is a binary file. ''' i...
Detects if the file is a binary, returns bool. Returns True if the file is a bin, False if the file is not and None if the file is not available.
def is_binary(path): ''' Detects if the file is a binary, returns bool. Returns True if the file is a bin, False if the file is not and None if the file is not available. ''' if not os.path.isfile(path): return False try: with fopen(path, 'rb') as fp_: try: ...
Runs os.remove(path) and suppresses the OSError if the file doesn't exist
def remove(path): ''' Runs os.remove(path) and suppresses the OSError if the file doesn't exist ''' try: os.remove(path) except OSError as exc: if exc.errno != errno.ENOENT: raise
Return a list of all files found under directory (and its subdirectories)
def list_files(directory): ''' Return a list of all files found under directory (and its subdirectories) ''' ret = set() ret.add(directory) for root, dirs, files in safe_walk(directory): for name in files: ret.add(os.path.join(root, name)) for name in dirs: ...
Return a mode value, normalized to a string and containing a leading zero if it does not have one. Allow "keep" as a valid mode (used by file state/module to preserve mode from the Salt fileserver in file states).
def normalize_mode(mode): ''' Return a mode value, normalized to a string and containing a leading zero if it does not have one. Allow "keep" as a valid mode (used by file state/module to preserve mode from the Salt fileserver in file states). ''' if mode is None: return None if...
Convert human-readable units to bytes
def human_size_to_bytes(human_size): ''' Convert human-readable units to bytes ''' size_exp_map = {'K': 1, 'M': 2, 'G': 3, 'T': 4, 'P': 5} human_size_str = six.text_type(human_size) match = re.match(r'^(\d+)([KMGTP])?$', human_size_str) if not match: raise ValueError( 'Si...
Backup a file on the minion
def backup_minion(path, bkroot): ''' Backup a file on the minion ''' dname, bname = os.path.split(path) if salt.utils.platform.is_windows(): src_dir = dname.replace(':', '_') else: src_dir = dname[1:] if not salt.utils.platform.is_windows(): fstat = os.stat(path) ...
Detect a file's encoding using the following: - Check for Byte Order Marks (BOM) - Check for UTF-8 Markers - Check System Encoding - Check for ascii Args: path (str): The path to the file to check Returns: str: The encoding of the file Raises: CommandExecutionErro...
def get_encoding(path): ''' Detect a file's encoding using the following: - Check for Byte Order Marks (BOM) - Check for UTF-8 Markers - Check System Encoding - Check for ascii Args: path (str): The path to the file to check Returns: str: The encoding of the file ...
Ensure the named grafana dashboard is absent. name Name of the grafana dashboard. orgname Name of the organization in which the dashboard should be present. profile Configuration profile used to connect to the Grafana instance. Default is 'grafana'.
def absent(name, orgname=None, profile='grafana'): ''' Ensure the named grafana dashboard is absent. name Name of the grafana dashboard. orgname Name of the organization in which the dashboard should be present. profile Configuration profile used to connect to the Grafana ...
Provide grains about zpools
def _zfs_pool_data(): ''' Provide grains about zpools ''' grains = {} # collect zpool data zpool_list_cmd = __utils__['zfs.zpool_command']( 'list', flags=['-H'], opts={'-o': 'name,size'}, ) for zpool in __salt__['cmd.run'](zpool_list_cmd, ignore_retcode=True).spl...
Provide grains for zfs/zpool
def zfs(): ''' Provide grains for zfs/zpool ''' grains = {} grains['zfs_support'] = __utils__['zfs.is_supported']() grains['zfs_feature_flags'] = __utils__['zfs.has_feature_flags']() if grains['zfs_support']: grains = salt.utils.dictupdate.update(grains, _zfs_pool_data(), merge_lists...
Send a "Magic Packet" to wake up a list of Minions. This list must contain one MAC hardware address per line CLI Example: .. code-block:: bash salt-run network.wollist '/path/to/maclist' salt-run network.wollist '/path/to/maclist' 255.255.255.255 7 salt-run network.wollist '/path/...
def wollist(maclist, bcast='255.255.255.255', destport=9): ''' Send a "Magic Packet" to wake up a list of Minions. This list must contain one MAC hardware address per line CLI Example: .. code-block:: bash salt-run network.wollist '/path/to/maclist' salt-run network.wollist '/path...
Send a "Magic Packet" to wake up a Minion CLI Example: .. code-block:: bash salt-run network.wol 08-00-27-13-69-77 salt-run network.wol 080027136977 255.255.255.255 7 salt-run network.wol 08:00:27:13:69:77 255.255.255.255 7
def wol(mac, bcast='255.255.255.255', destport=9): ''' Send a "Magic Packet" to wake up a Minion CLI Example: .. code-block:: bash salt-run network.wol 08-00-27-13-69-77 salt-run network.wol 080027136977 255.255.255.255 7 salt-run network.wol 08:00:27:13:69:77 255.255.255.255 ...
Send a "Magic Packet" to wake up Minions that are matched in the grains cache CLI Example: .. code-block:: bash salt-run network.wolmatch minion_id salt-run network.wolmatch 192.168.0.0/16 tgt_type='ipcidr' bcast=255.255.255.255 destport=7
def wolmatch(tgt, tgt_type='glob', bcast='255.255.255.255', destport=9): ''' Send a "Magic Packet" to wake up Minions that are matched in the grains cache CLI Example: .. code-block:: bash salt-run network.wolmatch minion_id salt-run network.wolmatch 192.168.0.0/16 tgt_type='ipcidr' b...
Return a conn object for accessing memcached
def get_conn(opts, profile=None, host=None, port=None): ''' Return a conn object for accessing memcached ''' if not (host and port): opts_pillar = opts.get('pillar', {}) opts_master = opts_pillar.get('master', {}) opts_merged = {} opts_merged.update(opts_master) ...
Set a key on the memcached server, overwriting the value if it exists.
def set_(conn, key, value, time=DEFAULT_TIME, min_compress_len=DEFAULT_MIN_COMPRESS_LEN): ''' Set a key on the memcached server, overwriting the value if it exists. ''' if not isinstance(time, integer_types): raise SaltInvocationError('\'time\' must be an inte...
Returns the HTTP auth header
def _get_auth(username, password): ''' Returns the HTTP auth header ''' if username and password: return requests.auth.HTTPBasicAuth(username, password) else: return None
Returns the URL of the endpoint
def _get_url(ssl, url, port, path): ''' Returns the URL of the endpoint ''' if ssl: return 'https://{0}:{1}/management/domain/{2}'.format(url, port, path) else: return 'http://{0}:{1}/management/domain/{2}'.format(url, port, path)
Removes SaltStack params from **kwargs
def _clean_data(data): ''' Removes SaltStack params from **kwargs ''' for key in list(data): if key.startswith('__pub'): del data[key] return data
Check response status code + success_code returned by glassfish
def _api_response(response): ''' Check response status code + success_code returned by glassfish ''' if response.status_code == 404: __context__['retcode'] = salt.defaults.exitcodes.SALT_BUILD_FAIL raise CommandExecutionError('Element doesn\'t exists') if response.status_code == 401:...
Do a GET request to the API
def _api_get(path, server=None): ''' Do a GET request to the API ''' server = _get_server(server) response = requests.get( url=_get_url(server['ssl'], server['url'], server['port'], path), auth=_get_auth(server['user'], server['password']), headers=_get_headers(),...
Do a POST request to the API
def _api_post(path, data, server=None): ''' Do a POST request to the API ''' server = _get_server(server) response = requests.post( url=_get_url(server['ssl'], server['url'], server['port'], path), auth=_get_auth(server['user'], server['password']), headers=_get_h...
Do a DELETE request to the API
def _api_delete(path, data, server=None): ''' Do a DELETE request to the API ''' server = _get_server(server) response = requests.delete( url=_get_url(server['ssl'], server['url'], server['port'], path), auth=_get_auth(server['user'], server['password']), headers=...
Enum elements
def _enum_elements(name, server=None): ''' Enum elements ''' elements = [] data = _api_get(name, server) if any(data['extraProperties']['childResources']): for element in data['extraProperties']['childResources']: elements.append(element) return elements return N...
Get an element's properties
def _get_element_properties(name, element_type, server=None): ''' Get an element's properties ''' properties = {} data = _api_get('{0}/{1}/property'.format(element_type, name), server) # Get properties into a dict if any(data['extraProperties']['properties']): for element in data['e...
Get an element with or without properties
def _get_element(name, element_type, server=None, with_properties=True): ''' Get an element with or without properties ''' element = {} name = quote(name, safe='') data = _api_get('{0}/{1}'.format(element_type, name), server) # Format data, get properties if asked, and return the whole thin...
Create a new element
def _create_element(name, element_type, data, server=None): ''' Create a new element ''' # Define property and id from name and properties + remove SaltStack parameters if 'properties' in data: data['property'] = '' for key, value in data['properties'].items(): if not dat...
Update an element, including it's properties
def _update_element(name, element_type, data, server=None): ''' Update an element, including it's properties ''' # Urlencode the name (names may have slashes) name = quote(name, safe='') # Update properties first if 'properties' in data: properties = [] for key, value in dat...
Delete an element
def _delete_element(name, element_type, data, server=None): ''' Delete an element ''' _api_delete('{0}/{1}'.format(element_type, quote(name, safe='')), data, server) return name
Create a connection pool
def create_connector_c_pool(name, server=None, **kwargs): ''' Create a connection pool ''' defaults = { 'connectionDefinitionName': 'javax.jms.ConnectionFactory', 'resourceAdapterName': 'jmsra', 'associateWithThread': False, 'connectionCreationRetryAttempts': 0, '...
Update a connection pool
def update_connector_c_pool(name, server=None, **kwargs): ''' Update a connection pool ''' if 'transactionSupport' in kwargs and kwargs['transactionSupport'] not in ( 'XATransaction', 'LocalTransaction', 'NoTransaction' ): raise CommandExecutio...
Delete a connection pool
def delete_connector_c_pool(name, target='server', cascade=True, server=None): ''' Delete a connection pool ''' data = {'target': target, 'cascade': cascade} return _delete_element(name, 'resources/connector-connection-pool', data, server)
Create a connection resource
def create_connector_resource(name, server=None, **kwargs): ''' Create a connection resource ''' defaults = { 'description': '', 'enabled': True, 'id': name, 'poolName': '', 'objectType': 'user', 'target': 'server' } # Data = defaults + merge kwar...
Update a connection resource
def update_connector_resource(name, server=None, **kwargs): ''' Update a connection resource ''' # You're not supposed to update jndiName, if you do so, it will crash, silently if 'jndiName' in kwargs: del kwargs['jndiName'] return _update_element(name, 'resources/connector-resource', kw...
Create a JMS destination
def create_admin_object_resource(name, server=None, **kwargs): ''' Create a JMS destination ''' defaults = { 'description': '', 'className': 'com.sun.messaging.Queue', 'enabled': True, 'id': name, 'resAdapter': 'jmsra', 'resType': 'javax.jms.Queue', ...
Update a JMS destination
def update_admin_object_resource(name, server=None, **kwargs): ''' Update a JMS destination ''' if 'jndiName' in kwargs: del kwargs['jndiName'] return _update_element(name, 'resources/admin-object-resource', kwargs, server)
Create a connection resource
def create_jdbc_connection_pool(name, server=None, **kwargs): ''' Create a connection resource ''' defaults = { 'allowNonComponentCallers': False, 'associateWithThread': False, 'connectionCreationRetryAttempts': '0', 'connectionCreationRetryIntervalInSeconds': '10', ...
Delete a JDBC pool
def delete_jdbc_connection_pool(name, target='server', cascade=False, server=None): ''' Delete a JDBC pool ''' data = {'target': target, 'cascade': cascade} return _delete_element(name, 'resources/jdbc-connection-pool', data, server)
Create a JDBC resource
def create_jdbc_resource(name, server=None, **kwargs): ''' Create a JDBC resource ''' defaults = { 'description': '', 'enabled': True, 'id': name, 'poolName': '', 'target': 'server' } # Data = defaults + merge kwargs + poolname data = defaults dat...
Update a JDBC resource
def update_jdbc_resource(name, server=None, **kwargs): ''' Update a JDBC resource ''' # You're not supposed to update jndiName, if you do so, it will crash, silently if 'jndiName' in kwargs: del kwargs['jndiName'] return _update_element(name, 'resources/jdbc-resource', kwargs, server)
Get system properties
def get_system_properties(server=None): ''' Get system properties ''' properties = {} data = _api_get('system-properties', server) # Get properties into a dict if any(data['extraProperties']['systemProperties']): for element in data['extraProperties']['systemProperties']: ...
Ensure a network exists and is up-to-date name Name of the network provider A dict of network provider options. shared Set the network as shared. external Whether this network is externally accessible. admin_state_up Set the network administrative state ...
def present(name, auth=None, **kwargs): ''' Ensure a network exists and is up-to-date name Name of the network provider A dict of network provider options. shared Set the network as shared. external Whether this network is externally accessible. admin_sta...
Ensure a network does not exists name Name of the network
def absent(name, auth=None, **kwargs): ''' Ensure a network does not exists name Name of the network ''' ret = {'name': name, 'changes': {}, 'result': True, 'comment': ''} kwargs = __utils__['args.clean_kwargs'](**kwargs) __salt__['neutronng.setup...
Split a smartos docker uuid into repo and tag
def _split_docker_uuid(uuid): ''' Split a smartos docker uuid into repo and tag ''' if uuid: uuid = uuid.split(':') if len(uuid) == 2: tag = uuid[1] repo = uuid[0] return repo, tag return None, None
Check if uuid is a valid smartos uuid Example: e69a0918-055d-11e5-8912-e3ceb6df4cf8
def _is_uuid(uuid): ''' Check if uuid is a valid smartos uuid Example: e69a0918-055d-11e5-8912-e3ceb6df4cf8 ''' if uuid and list((len(x) for x in uuid.split('-'))) == [8, 4, 4, 4, 12]: return True return False
Return imgadm version CLI Example: .. code-block:: bash salt '*' imgadm.version
def version(): ''' Return imgadm version CLI Example: .. code-block:: bash salt '*' imgadm.version ''' ret = {} cmd = 'imgadm --version' res = __salt__['cmd.run'](cmd).splitlines() ret = res[0].split() return ret[-1]
Get the image uuid from an imported docker image .. versionadded:: 2019.2.0
def docker_to_uuid(uuid): ''' Get the image uuid from an imported docker image .. versionadded:: 2019.2.0 ''' if _is_uuid(uuid): return uuid if _is_docker_uuid(uuid): images = list_installed(verbose=True) for image_uuid in images: if 'name' not in images[imag...
Return a list of available images search : string search keyword verbose : boolean (False) toggle verbose output CLI Example: .. code-block:: bash salt '*' imgadm.avail [percona] salt '*' imgadm.avail verbose=True
def avail(search=None, verbose=False): ''' Return a list of available images search : string search keyword verbose : boolean (False) toggle verbose output CLI Example: .. code-block:: bash salt '*' imgadm.avail [percona] salt '*' imgadm.avail verbose=True ...
Show manifest of a given image uuid : string uuid of image CLI Example: .. code-block:: bash salt '*' imgadm.show e42f8c84-bbea-11e2-b920-078fab2aab1f salt '*' imgadm.show plexinc/pms-docker:plexpass
def show(uuid): ''' Show manifest of a given image uuid : string uuid of image CLI Example: .. code-block:: bash salt '*' imgadm.show e42f8c84-bbea-11e2-b920-078fab2aab1f salt '*' imgadm.show plexinc/pms-docker:plexpass ''' ret = {} if _is_uuid(uuid) or _is_d...
Import an image from the repository uuid : string uuid to import verbose : boolean (False) toggle verbose output CLI Example: .. code-block:: bash salt '*' imgadm.import e42f8c84-bbea-11e2-b920-078fab2aab1f [verbose=True]
def import_image(uuid, verbose=False): ''' Import an image from the repository uuid : string uuid to import verbose : boolean (False) toggle verbose output CLI Example: .. code-block:: bash salt '*' imgadm.import e42f8c84-bbea-11e2-b920-078fab2aab1f [verbose=True] ...
Remove an installed image uuid : string Specifies uuid to import CLI Example: .. code-block:: bash salt '*' imgadm.delete e42f8c84-bbea-11e2-b920-078fab2aab1f
def delete(uuid): ''' Remove an installed image uuid : string Specifies uuid to import CLI Example: .. code-block:: bash salt '*' imgadm.delete e42f8c84-bbea-11e2-b920-078fab2aab1f ''' ret = {} cmd = 'imgadm delete {0}'.format(uuid) res = __salt__['cmd.run_all'](c...
Remove unused images verbose : boolean (False) toggle verbose output CLI Example: .. code-block:: bash salt '*' imgadm.vacuum [verbose=True]
def vacuum(verbose=False): ''' Remove unused images verbose : boolean (False) toggle verbose output CLI Example: .. code-block:: bash salt '*' imgadm.vacuum [verbose=True] ''' ret = {} cmd = 'imgadm vacuum -f' res = __salt__['cmd.run_all'](cmd) retcode = res['...
Return a list of available sources verbose : boolean (False) toggle verbose output .. versionadded:: 2019.2.0 CLI Example: .. code-block:: bash salt '*' imgadm.sources
def sources(verbose=False): ''' Return a list of available sources verbose : boolean (False) toggle verbose output .. versionadded:: 2019.2.0 CLI Example: .. code-block:: bash salt '*' imgadm.sources ''' ret = {} cmd = 'imgadm sources -j' res = __salt__['cmd....
Delete a source source : string source url to delete .. versionadded:: 2019.2.0 CLI Example: .. code-block:: bash salt '*' imgadm.source_delete https://updates.joyent.com
def source_delete(source): ''' Delete a source source : string source url to delete .. versionadded:: 2019.2.0 CLI Example: .. code-block:: bash salt '*' imgadm.source_delete https://updates.joyent.com ''' ret = {} cmd = 'imgadm sources -d {0}'.format(source) ...
Add a new source source : string source url to add source_trype : string (imgapi) source type, either imgapi or docker .. versionadded:: 2019.2.0 CLI Example: .. code-block:: bash salt '*' imgadm.source_add https://updates.joyent.com salt '*' imgadm.source_add ht...
def source_add(source, source_type='imgapi'): ''' Add a new source source : string source url to add source_trype : string (imgapi) source type, either imgapi or docker .. versionadded:: 2019.2.0 CLI Example: .. code-block:: bash salt '*' imgadm.source_add https:...
Helper function for instantiating a Flags object Args: instantiated (bool): True to return an instantiated object, False to return the object definition. Use False if inherited by another class. Default is True. Returns: object: An instance of the Flags obj...
def flags(instantiated=True): ''' Helper function for instantiating a Flags object Args: instantiated (bool): True to return an instantiated object, False to return the object definition. Use False if inherited by another class. Default is True. Returns: ...
Helper function for instantiating a Dacl class. Args: obj_name (str): The full path to the object. If None, a blank DACL will be created. Default is None. obj_type (str): The type of object. Default is 'File' Returns: object: An instantiated Dacl o...
def dacl(obj_name=None, obj_type='file'): ''' Helper function for instantiating a Dacl class. Args: obj_name (str): The full path to the object. If None, a blank DACL will be created. Default is None. obj_type (str): The type of object. Default is 'File...
Converts a username to a sid, or verifies a sid. Required for working with the DACL. Args: principal(str): The principal to lookup the sid. Can be a sid or a username. Returns: PySID Object: A sid Usage: .. code-block:: python # Get a user's sid salt...
def get_sid(principal): ''' Converts a username to a sid, or verifies a sid. Required for working with the DACL. Args: principal(str): The principal to lookup the sid. Can be a sid or a username. Returns: PySID Object: A sid Usage: .. code-block:: python ...
Converts a PySID object to a string SID. Args: principal(str): The principal to lookup the sid. Must be a PySID object. Returns: str: A string sid Usage: .. code-block:: python # Get a PySID object py_sid = salt.utils.win_dacl.get_sid('jsnuffy') ...
def get_sid_string(principal): ''' Converts a PySID object to a string SID. Args: principal(str): The principal to lookup the sid. Must be a PySID object. Returns: str: A string sid Usage: .. code-block:: python # Get a PySID object py_sid = salt...
Gets the name from the specified principal. Args: principal (str): Find the Normalized name based on this. Can be a PySID object, a SID string, or a user name in any capitalization. .. note:: Searching based on the user name can be slow on hosts connect...
def get_name(principal): ''' Gets the name from the specified principal. Args: principal (str): Find the Normalized name based on this. Can be a PySID object, a SID string, or a user name in any capitalization. .. note:: Searching based on the u...
r''' Gets the owner of the passed object Args: obj_name (str): The path for which to obtain owner information. The format of this parameter is different depending on the ``obj_type`` obj_type (str): The type of object to query. This value changes the format...
def get_owner(obj_name, obj_type='file'): r''' Gets the owner of the passed object Args: obj_name (str): The path for which to obtain owner information. The format of this parameter is different depending on the ``obj_type`` obj_type (str): The type of ...
r''' Gets the primary group of the passed object Args: obj_name (str): The path for which to obtain primary group information obj_type (str): The type of object to query. This value changes the format of the ``obj_name`` parameter as follows: -...
def get_primary_group(obj_name, obj_type='file'): r''' Gets the primary group of the passed object Args: obj_name (str): The path for which to obtain primary group information obj_type (str): The type of object to query. This value changes the format of the ...
Set the owner of an object. This can be a file, folder, registry key, printer, service, etc... Args: obj_name (str): The object for which to set owner. This can be the path to a file or folder, a registry key, printer, etc. For more information about how to format t...
def set_owner(obj_name, principal, obj_type='file'): ''' Set the owner of an object. This can be a file, folder, registry key, printer, service, etc... Args: obj_name (str): The object for which to set owner. This can be the path to a file or folder, a registry key, pri...
Set the permissions of an object. This can be a file, folder, registry key, printer, service, etc... Args: obj_name (str): The object for which to set permissions. This can be the path to a file or folder, a registry key, printer, etc. For more information about how...
def set_permissions(obj_name, principal, permissions, access_mode='grant', applies_to=None, obj_type='file', reset_perms=False, protected=None): ''' Set the permissions of ...
r''' Remove a user's ACE from an object. This can be a file, folder, registry key, printer, service, etc... Args: obj_name (str): The object from which to remove the ace. This can be the path to a file or folder, a registry key, printer, etc. For more informatio...
def rm_permissions(obj_name, principal, ace_type='all', obj_type='file'): r''' Remove a user's ACE from an object. This can be a file, folder, registry key, printer, service, etc... Args: obj_name (str): The object from which...
Get the permissions for the passed object Args: obj_name (str): The name of or path to the object. principal (Optional[str]): The name of the user or group for which to get permissions. Can also pass a SID. If None, all ACEs defined on the object will be ...
def get_permissions(obj_name, principal=None, obj_type='file'): ''' Get the permissions for the passed object Args: obj_name (str): The name of or path to the object. principal (Optional[str]): The name of the user or group for which to get permissions. Can also ...
r''' Check if the object has a permission Args: obj_name (str): The name of or path to the object. principal (str): The name of the user or group for which to get permissions. Can also pass a SID. permission (str): The permission to ver...
def has_permission(obj_name, principal, permission, access_mode='grant', obj_type='file', exact=True): r''' Check if the object has a permission Args: obj_name (str): The name of or path to t...
Enable or disable an objects inheritance. Args: obj_name (str): The name of the object enabled (bool): True to enable inheritance, False to disable obj_type (Optional[str]): The type of object. Only three objects allow inheritance. Valid ob...
def set_inheritance(obj_name, enabled, obj_type='file', clear=False): ''' Enable or disable an objects inheritance. Args: obj_name (str): The name of the object enabled (bool): True to enable inheritance, False to disable obj_type (Optional[str]): ...
Get an object's inheritance. Args: obj_name (str): The name of the object obj_type (Optional[str]): The type of object. Only three object types allow inheritance. Valid objects are: - file (default): This is a file or directory - regist...
def get_inheritance(obj_name, obj_type='file'): ''' Get an object's inheritance. Args: obj_name (str): The name of the object obj_type (Optional[str]): The type of object. Only three object types allow inheritance. Valid objects are: - file...
r''' Copy the security descriptor of the Source to the Target. You can specify a specific portion of the security descriptor to copy using one of the `copy_*` parameters. .. note:: At least one `copy_*` parameter must be ``True`` .. note:: The user account running this command must...
def copy_security(source, target, obj_type='file', copy_owner=True, copy_group=True, copy_dacl=True, copy_sacl=True): r''' Copy the security descriptor of the Source to the Target. You can specify a s...
Helper function used by ``check_perms`` for checking and setting Grant and Deny permissions. Args: obj_name (str): The name or full path to the object obj_type (Optional[str]): The type of object for which to check permissions. Default is 'file' new_perms (dic...
def _check_perms(obj_name, obj_type, new_perms, cur_perms, access_mode, ret): ''' Helper function used by ``check_perms`` for checking and setting Grant and Deny permissions. Args: obj_name (str): The name or full path to the object obj_type (Optional[str]): Th...
Check owner and permissions for the passed directory. This function checks the permissions and sets them, returning the changes made. .. versionadded:: 2019.2.0 Args: obj_name (str): The name or full path to the object obj_type (Optional[str]): The type of object ...
def check_perms(obj_name, obj_type='file', ret=None, owner=None, grant_perms=None, deny_perms=None, inheritance=True, reset=False): ''' Check owner and permissions for the passed directory. This funct...
Set permissions for the given path .. versionadded:: 2019.2.0 Args: obj_name (str): The name or full path to the object obj_type (Optional[str]): The type of object for which to check permissions. Default is 'file' grant_perms (dict): A dictionary...
def set_perms(obj_name, obj_type='file', grant_perms=None, deny_perms=None, inheritance=True, reset=False): ''' Set permissions for the given path .. versionadded:: 2019.2.0 Args: obj_name (str): The name or ful...
Read a file and return content
def _file_read(path): ''' Read a file and return content ''' content = False if os.path.exists(path): with salt.utils.files.fopen(path, 'r+') as fp_: content = salt.utils.stringutils.to_unicode(fp_.read()) fp_.close() return content
List all of the local package repositories. :param str config_path: The path to the configuration file for the aptly instance. :param bool with_packages: Return a list of packages in the repo. :return: A dictionary of the repositories. :rtype: dict CLI Example: .. code-block:: bash ...
def list_repos(config_path=_DEFAULT_CONFIG_PATH, with_packages=False): ''' List all of the local package repositories. :param str config_path: The path to the configuration file for the aptly instance. :param bool with_packages: Return a list of packages in the repo. :return: A dictionary of the r...