text
stringlengths
81
112k
Returns true if the named container exists CLI Example: .. code-block:: bash salt myminion nspawn.exists <name> def exists(name): ''' Returns true if the named container exists CLI Example: .. code-block:: bash salt myminion nspawn.exists <name> ''' contextkey = 'n...
Return state of container (running or stopped) CLI Example: .. code-block:: bash salt myminion nspawn.state <name> def state(name): ''' Return state of container (running or stopped) CLI Example: .. code-block:: bash salt myminion nspawn.state <name> ''' try: ...
Return info about a container .. note:: The container must be running for ``machinectl`` to gather information about it. If the container is stopped, then this function will start it. start : False If ``True``, then the container will be started to retrieve the info. A ...
Set the named container to be launched at boot CLI Example: .. code-block:: bash salt myminion nspawn.enable <name> def enable(name): ''' Set the named container to be launched at boot CLI Example: .. code-block:: bash salt myminion nspawn.enable <name> ''' cmd = '...
Start the named container CLI Example: .. code-block:: bash salt myminion nspawn.start <name> def start(name): ''' Start the named container CLI Example: .. code-block:: bash salt myminion nspawn.start <name> ''' if _sd_version() >= 219: ret = _machinectl('...
This is a compatibility function which provides the logic for nspawn.poweroff and nspawn.terminate. def stop(name, kill=False): ''' This is a compatibility function which provides the logic for nspawn.poweroff and nspawn.terminate. ''' if _sd_version() >= 219: if kill: actio...
Reboot the container by sending a SIGINT to its init process. Equivalent to running ``machinectl reboot`` on the named container. For convenience, running ``nspawn.restart`` (as shown in the CLI examples below) is equivalent to running ``nspawn.reboot``. .. note:: ``machinectl reboot`` is onl...
Remove the named container .. warning:: This function will remove all data associated with the container. It will not, however, remove the btrfs subvolumes created by pulling container images (:mod:`nspawn.pull_raw <salt.modules.nspawn.pull_raw>`, :mod:`nspawn.pull_tar <sal...
Copy a file from the host into a container name Container name source File to be copied to the container dest Destination on the container. Must be an absolute path. overwrite : False Unless this option is set to ``True``, then if a file exists at the location...
Common logic for machinectl pull-* commands def _pull_image(pull_type, image, name, **kwargs): ''' Common logic for machinectl pull-* commands ''' _ensure_systemd(219) if exists(name): raise SaltInvocationError( 'Container \'{0}\' already exists'.format(name) ) if pu...
Execute a ``machinectl pull-raw`` to download a .qcow2 or raw disk image, and add it to /var/lib/machines as a new container. .. note:: **Requires systemd >= 219** url URL from which to download the container name Name for the new container verify : False Perform...
Execute a ``machinectl pull-raw`` to download a .tar container image, and add it to /var/lib/machines as a new container. .. note:: **Requires systemd >= 219** url URL from which to download the container name Name for the new container verify : False Perform sig...
Prepares the ACL returned from the AWS API for comparison with a given one. def _prep_acl_for_compare(ACL): ''' Prepares the ACL returned from the AWS API for comparison with a given one. ''' ret = copy.deepcopy(ACL) ret['Owner'] = _normalize_user(ret['Owner']) for item in ret.get('Grants', ())...
ACLs can be specified using macro-style names that get expanded to something more complex. There's no predictable way to reverse it. So expand all syntactic sugar in our input, and compare against that rather than the input itself. def _compare_acl(current, desired, region, key, keyid, profile): ''' ...
Replication accepts a non-ARN role name, but always returns an ARN def _compare_replication(current, desired, region, key, keyid, profile): ''' Replication accepts a non-ARN role name, but always returns an ARN ''' if desired is not None and desired.get('Role'): desired = copy.deepcopy(desired)...
Ensure bucket exists. name The name of the state definition Bucket Name of the bucket. LocationConstraint 'EU'|'eu-west-1'|'us-west-1'|'us-west-2'|'ap-southeast-1'|'ap-southeast-2'|'ap-northeast-1'|'sa-east-1'|'cn-north-1'|'eu-central-1' ACL The permissions on a bucke...
Looks to see if pkgin is present on the system, return full path def _check_pkgin(): ''' Looks to see if pkgin is present on the system, return full path ''' ppath = salt.utils.path.which('pkgin') if ppath is None: # pkgin was not found in $PATH, try to find it via LOCALBASE try: ...
Get the pkgin version def _get_version(): ''' Get the pkgin version ''' version_string = __salt__['cmd.run']( [_check_pkgin(), '-v'], output_loglevel='trace') if version_string is None: # Dunno why it would, but... return False version_match = VERSION_MATCH.sear...
Searches for an exact match using pkgin ^package$ CLI Example: .. code-block:: bash salt '*' pkg.search 'mysql-server' def search(pkg_name, **kwargs): ''' Searches for an exact match using pkgin ^package$ CLI Example: .. code-block:: bash salt '*' pkg.search 'mysql-server'...
Use pkg update to get latest pkg_summary force Pass -f so that the cache is always refreshed. .. versionadded:: 2018.3.0 CLI Example: .. code-block:: bash salt '*' pkg.refresh_db def refresh_db(force=False, **kwargs): ''' Use pkg update to get latest pkg_summary f...
.. versionchanged: 2016.3.0 List the packages currently installed as a dict:: {'<package_name>': '<version>'} CLI Example: .. code-block:: bash salt '*' pkg.list_pkgs def list_pkgs(versions_as_list=False, **kwargs): ''' .. versionchanged: 2016.3.0 List the packages current...
List all available package upgrades. .. versionadded:: 2018.3.0 refresh Whether or not to refresh the package database before installing. CLI Example: .. code-block:: bash salt '*' pkg.list_upgrades def list_upgrades(refresh=True, **kwargs): ''' List all available package u...
Install the passed package name The name of the package to be installed. refresh Whether or not to refresh the package database before installing. fromrepo Specify a package repository to install from. Multiple Package Installation Options: pkgs A list of packag...
Run pkg upgrade, if pkgin used. Otherwise do nothing refresh Whether or not to refresh the package database before installing. Multiple Package Upgrade Options: pkgs A list of packages to upgrade from a software repository. Must be passed as a python list. CLI Example: ...
name The name of the package to be deleted. Multiple Package Options: pkgs A list of packages to delete. Must be passed as a python list. The ``name`` parameter will be ignored if this option is passed. .. versionadded:: 0.16.0 Returns a list containing the removed packages...
List the files that belong to a package. CLI Examples: .. code-block:: bash salt '*' pkg.file_list nginx def file_list(package, **kwargs): ''' List the files that belong to a package. CLI Examples: .. code-block:: bash salt '*' pkg.file_list nginx ''' ret = file_di...
.. versionchanged: 2016.3.0 List the files that belong to a package. CLI Examples: .. code-block:: bash salt '*' pkg.file_dict nginx salt '*' pkg.file_dict nginx varnish def file_dict(*packages, **kwargs): ''' .. versionchanged: 2016.3.0 List the files that belong to a pack...
Verify that a device is mounted name The path to the location where the device is to be mounted device The device name, typically the device node, such as ``/dev/sdb1`` or ``UUID=066e0200-2867-4ebe-b9e6-f30026ca2314`` or ``LABEL=DATA`` fstype The filesystem type, this will...
Activates a swap device .. code-block:: yaml /root/swapfile: mount.swap .. note:: ``swap`` does not currently support LABEL def swap(name, persist=True, config='/etc/fstab'): ''' Activates a swap device .. code-block:: yaml /root/swapfile: mount.swap...
.. versionadded:: 0.17.0 Verify that a device is not mounted name The path to the location where the device is to be unmounted from device The device to be unmounted. This is optional because the device could be mounted in multiple places. .. versionadded:: 2015.5.0 ...
The mounted watcher, called to invoke the watch command. .. note:: This state exists to support special handling of the ``watch`` :ref:`requisite <requisites>`. It should not be called directly. Parameters for this function should be set by the state being triggered. name The ...
Convert a device name, UUID or LABEL to a device name, UUID or LABEL. Return the fs_spec required for fstab. def _convert_to(maybe_device, convert_to): ''' Convert a device name, UUID or LABEL to a device name, UUID or LABEL. Return the fs_spec required for fstab. ''' # Fast path. I...
Makes sure that a fstab mount point is pressent. name The name of block device. Can be any valid fs_spec value. fs_file Mount point (target) for the filesystem. fs_vfstype The type of the filesystem (e.g. ext4, xfs, btrfs, ...) fs_mntops The mount options associated w...
Makes sure that a fstab mount point is absent. name The name of block device. Can be any valid fs_spec value. fs_file Mount point (target) for the filesystem. mount_by Select the final value for fs_spec. Can be [``None``, ``device``, ``label``, ``uuid``, ``partlabel``, ...
Determine the value of the SNMP sysContact, sysLocation, and sysServices settings. Returns: dict: A dictionary of the agent settings. CLI Example: .. code-block:: bash salt '*' win_snmp.get_agent_settings def get_agent_settings(): ''' Determine the value of the SNMP sysConta...
Manage the SNMP sysContact, sysLocation, and sysServices settings. Args: contact (str, optional): The SNMP contact. location (str, optional): The SNMP location. services (list, optional): A list of selected services. The possible service names can be found via ``win_snmp.get_a...
Manage the sending of authentication traps. Args: status (bool): True to enable traps. False to disable. Returns: bool: True if successful, otherwise False CLI Example: .. code-block:: bash salt '*' win_snmp.set_auth_traps_enabled status='True' def set_auth_traps_enabled(st...
Get the current accepted SNMP community names and their permissions. If community names are being managed by Group Policy, those values will be returned instead like this: .. code-block:: bash TestCommunity: Managed by GPO Community names managed normally will denote the permissi...
Manage the SNMP accepted community names and their permissions. .. note:: Settings managed by Group Policy will always take precedence over those set using the SNMP interface. Therefore if this function finds Group Policy settings it will raise a CommandExecutionError Args: com...
Shallow copy and merge dicts together, giving precedence to last in. def _merge_dicts(*args): ''' Shallow copy and merge dicts together, giving precedence to last in. ''' ret = dict() for arg in args: ret.update(arg) return ret
Convert setting values that has been improperly converted to a dict back to a string. def _normalize_server_settings(**settings): ''' Convert setting values that has been improperly converted to a dict back to a string. ''' ret = dict() settings = salt.utils.args.clean_kwargs(**settings) for s...
Ensure the value is set for the specified setting. .. note:: The setting names are case-sensitive. :param str settings: A dictionary of the setting names and their values. :param str server: The SMTP server name. Example of usage: .. code-block:: yaml smtp-settings: ...
Manage the active log format for the SMTP server. :param str log_format: The log format name. :param str server: The SMTP server name. Example of usage: .. code-block:: yaml smtp-log-format: win_smtp_server.active_log_format: - log_format: Microsoft IIS Log File F...
Manage IP list for SMTP connections. :param str addresses: A dictionary of IP + subnet pairs. :param bool grant_by_default: Whether the addresses should be a blacklist or whitelist. :param str server: The SMTP server name. Example of usage for creating a whitelist: .. code-block:: yaml s...
Manage IP list for SMTP relay connections. Due to the unusual way that Windows stores the relay IPs, it is advisable to retrieve the existing list you wish to set from a pre-configured server. For example, setting '127.0.0.1' as an allowed relay IP through the GUI would generate an actual relay IP lis...
run commands from __proxy__ :mod:`salt.proxy.onyx<salt.proxy.onyx>` command function from `salt.proxy.onyx` to run args positional args to pass to `command` function kwargs key word arguments to pass to `command` function .. code-block:: bash salt '*' onyx.cmd se...
Wrapper to assist with paginated responses from Digicert's REST API. def _paginate(url, topkey, *args, **kwargs): ''' Wrapper to assist with paginated responses from Digicert's REST API. ''' ret = salt.utils.http.query(url, **kwargs) if 'errors' in ret['dict']: return ret['dict'] lim ...
List domains that CertCentral knows about. You can filter by container_id (also known as "Division") by passing a container_id. CLI Example: .. code-block:: bash salt-run digicert.list_domains def list_domains(container_id=None): ''' List domains that CertCentral knows about. You can fil...
List certificate requests made to CertCentral. You can filter by status: ``pending``, ``approved``, ``rejected`` CLI Example: .. code-block:: bash salt-run digicert.list_requests pending def list_requests(status=None): ''' List certificate requests made to CertCentral. You can filter by ...
Retrieve a certificate by order_id or certificate_id and write it to stdout or a filename. A list of permissible cert_formats is here: https://www.digicert.com/services/v2/documentation/appendix-certificate-formats CLI Example: .. code-block:: bash salt-run digicert.get_certificate order...
List organizations that CertCentral knows about. You can filter by container_id (also known as "Division") by passing a container_id. This function returns validation information by default; pass ``include_validation=False`` to turn it off. CLI Example: .. code-block:: bash salt-run digic...
Order a certificate. Requires that an Organization has been created inside Digicert's CertCentral. See here for API documentation: https://www.digicert.com/services/v2/documentation/order/order-ssl-determinator CLI Example: .. code-block:: bash salt-run digicert.order_certificate my_minioni...
Generate and return a private_key. If a ``dns_name`` is passed in, the private_key will be cached under that name. CLI Example: .. code-block:: bash salt-run digicert.gen_key <minion_id> [dns_name] [password] def gen_key(minion_id, dns_name=None, password=None, key_len=2048): ''' Generat...
Return the details for an organization CLI Example: .. code-block:: bash salt-run digicert.get_org_details 34 Returns a dictionary with the org details, or with 'error' and 'status' keys. def get_org_details(organization_id): ''' Return the details for an organization CLI Example: ...
Maintain a relationship between a minion and a dns name def _id_map(minion_id, dns_name): ''' Maintain a relationship between a minion and a dns name ''' bank = 'digicert/minions' cache = salt.cache.Cache(__opts__, syspaths.CACHE_DIR) dns_names = cache.fetch(bank, minion_id) if not isinstan...
Show certificate requests for this API key CLI Example: .. code-block:: bash salt-run digicert.show_csrs def show_csrs(): ''' Show certificate requests for this API key CLI Example: .. code-block:: bash salt-run digicert.show_csrs ''' data = salt.utils.http.query( ...
Show a private RSA key CLI Example: .. code-block:: bash salt-run digicert.show_rsa myminion domain.example.com def show_rsa(minion_id, dns_name): ''' Show a private RSA key CLI Example: .. code-block:: bash salt-run digicert.show_rsa myminion domain.example.com ''' ...
Return a list of accepted, denied, unaccepted and rejected keys. This is the same output as `salt-key -L` CLI Example: .. code-block:: bash salt 'master' minion.list def list_(): ''' Return a list of accepted, denied, unaccepted and rejected keys. This is the same output as `salt-key...
Return the minion keys directory paths. This function is a copy of salt.key.Key._check_minions_directories. def _check_minions_directories(pki_dir): ''' Return the minion keys directory paths. This function is a copy of salt.key.Key._check_minions_directories. ''' minions_accepted = os.path.j...
Kill the salt minion. timeout int seconds to wait for the minion to die. If you have a monitor that restarts ``salt-minion`` when it dies then this is a great way to restart after a minion upgrade. CLI example:: >$ salt minion[12] minion.kill minion1: ---------- ...
Kill and restart the salt minion. The configuration key ``minion_restart_command`` is an argv list for the command to restart the minion. If ``minion_restart_command`` is not specified or empty then the ``argv`` of the current process will be used. if the configuration value ``minion_restart_command`...
Runs :py:func:`state.apply <salt.modules.state.apply>` with given options to set up test data. Intended to be used for optional test setup or teardown Reference the :py:func:`state.apply <salt.modules.state.apply>` module documentation for arguments and usage options CLI Example: .. code-block:: bash...
generate test results output list def _generate_out_list(results): ''' generate test results output list ''' passed = 0 failed = 0 skipped = 0 missing_tests = 0 total_time = 0.0 for state in results: if not results[state].items(): missing_tests = missing_tests + ...
Determine if a function is valid for a module def _is_valid_function(module_name, function): ''' Determine if a function is valid for a module ''' try: functions = __salt__['sys.list_functions'](module_name) except salt.exceptions.SaltException: functions = ["unable to look up funct...
Equivalent to a salt cli: salt web state.show_top def _get_top_states(saltenv='base'): ''' Equivalent to a salt cli: salt web state.show_top ''' alt_states = [] try: returned = __salt__['state.show_top']() for i in returned[saltenv]: alt_states.append(i) except Excep...
Generic call of salt Caller command def _call_salt_command(self, fun, args, kwargs, assertion_section=None): ''' Generic call of salt Caller command ''' value = False try:...
Determine the type of variable returned Cast the expected to the type of variable returned def _cast_expected_to_returned_type(expected, returned): ''' Determine the type of variable returned Cast the expected to the type of variable returned ''' ret_type = type(returned...
Test if two objects are equal def __assert_equal(expected, returned, assert_print_result=True): ''' Test if two objects are equal ''' result = "Pass" try: if assert_print_result: assert (expected == returned), "{0} is not equal to {1}".format(expecte...
Test if an boolean is True def __assert_true(returned): ''' Test if an boolean is True ''' result = "Pass" try: assert (returned is True), "{0} not True".format(returned) except AssertionError as err: result = "Fail: " + six.text_type(err) ...
Test if an boolean is False def __assert_false(returned): ''' Test if an boolean is False ''' result = "Pass" if isinstance(returned, str): try: returned = bool(returned) except ValueError: raise try: as...
Test if a value is less than the returned value def __assert_less(expected, returned): ''' Test if a value is less than the returned value ''' result = "Pass" try: assert (expected < returned), "{0} not False".format(returned) except AssertionError as err: ...
Test if a returned value is empty def __assert_empty(returned): ''' Test if a returned value is empty ''' result = "Pass" try: assert (not returned), "{0} is not empty".format(returned) except AssertionError as err: result = "Fail: " + six.text_ty...
Test if a returned value is not empty def __assert_not_empty(returned): ''' Test if a returned value is not empty ''' result = "Pass" try: assert (returned), "value is empty" except AssertionError as err: result = "Fail: " + six.text_type(err) ...
For the state file system, return a list of paths to search for states def get_state_search_path_list(saltenv='base'): ''' For the state file system, return a list of paths to search for states ''' # state cache should be updated before running this method search_list = [] ...
Mount VirtualBox Guest Additions CD to the temp directory. To connect VirtualBox Guest Additions via VirtualBox graphical interface press 'Host+D' ('Host' is usually 'Right Ctrl'). CLI Example: .. code-block:: bash salt '*' vbox_guest.additions_mount :return: True or OSError exception ...
Unmount VirtualBox Guest Additions CD from the temp directory. CLI Example: .. code-block:: bash salt '*' vbox_guest.additions_umount :param mount_point: directory VirtualBox Guest Additions is mounted to :return: True or an string with error def additions_umount(mount_point): ''' U...
Install VirtualBox Guest Additions. Uses the CD, connected by VirtualBox. To connect VirtualBox Guest Additions via VirtualBox graphical interface press 'Host+D' ('Host' is usually 'Right Ctrl'). See https://www.virtualbox.org/manual/ch04.html#idp52733088 for more details. CLI Example: .. code-b...
Remove VirtualBox Guest Additions. It uses the CD, connected by VirtualBox. def _additions_remove_use_cd(**kwargs): ''' Remove VirtualBox Guest Additions. It uses the CD, connected by VirtualBox. ''' with _additions_mounted() as mount_point: kernel = __grains__.get('kernel', '') ...
Remove VirtualBox Guest Additions. Firstly it tries to uninstall itself by executing '/opt/VBoxGuestAdditions-VERSION/uninstall.run uninstall'. It uses the CD, connected by VirtualBox if it failes. CLI Example: .. code-block:: bash salt '*' vbox_guest.additions_remove salt '*' vb...
Check VirtualBox Guest Additions version. CLI Example: .. code-block:: bash salt '*' vbox_guest.additions_version :return: version of VirtualBox Guest Additions or False if they are not installed def additions_version(): ''' Check VirtualBox Guest Additions version. CLI Example: ...
Grant access to auto-mounted shared folders to the users. User is specified by it's name. To grant access for several users use argument `users`. Access will be denied to the users not listed in `users` argument. See https://www.virtualbox.org/manual/ch04.html#sf_mount_auto for more details. CLI Exam...
Get a size of a disk. def _get_disk_size(self, device): ''' Get a size of a disk. ''' out = __salt__['cmd.run_all']("df {0}".format(device)) if out['retcode']: msg = "Disk size info error: {0}".format(out['stderr']) log.error(msg) raise SIExce...
Get available file systems and their types. def _get_fs(self): ''' Get available file systems and their types. ''' data = dict() for dev, dev_data in salt.utils.fsutils._blkid().items(): dev = self._get_disk_size(dev) device = dev.pop('device') ...
Get available CPU information. def _get_cpu(self): ''' Get available CPU information. ''' # CPU data in grains is OK-ish, but lscpu is still better in this case out = __salt__['cmd.run_all']("lscpu") salt.utils.fsutils._verify_run(out) data = dict() for d...
Get memory. def _get_mem(self): ''' Get memory. ''' out = __salt__['cmd.run_all']("vmstat -s") if out['retcode']: raise SIException("Memory info error: {0}".format(out['stderr'])) ret = dict() for line in out['stdout'].split(os.linesep): ...
Get network configuration. def _get_network(self): ''' Get network configuration. ''' data = dict() data['interfaces'] = salt.utils.network.interfaces() data['subnets'] = salt.utils.network.subnets() return data
Get operating system summary def _get_os(self): ''' Get operating system summary ''' return { 'name': self._grain('os'), 'family': self._grain('os_family'), 'arch': self._grain('osarch'), 'release': self._grain('osrelease'), }
Return configuration files. def _configuration(self, *args, **kwargs): ''' Return configuration files. ''' data = dict() self.db.open() for pkg in self.db.get(Package): configs = list() for pkg_cfg in self.db.get(PackageCfgFile, eq={'pkgid': pkg....
Return all known local accounts to the system. def _get_local_users(self, disabled=None): ''' Return all known local accounts to the system. ''' users = dict() path = '/etc/passwd' with salt.utils.files.fopen(path, 'r') as fp_: for line in fp_: ...
Return all known local groups to the system. def _get_local_groups(self): ''' Return all known local groups to the system. ''' groups = dict() path = '/etc/group' with salt.utils.files.fopen(path, 'r') as fp_: for line in fp_: line = line.stri...
Return all known accounts, excluding local accounts. def _get_external_accounts(self, locals): ''' Return all known accounts, excluding local accounts. ''' users = dict() out = __salt__['cmd.run_all']("passwd -S -a") if out['retcode']: # System does not suppo...
Local users and groups. accounts Can be either 'local', 'remote' or 'all' (equal to "local,remote"). Remote accounts cannot be resolved on all systems, but only those, which supports 'passwd -S -a'. disabled True (or False, default) to return only disabl...
This basically calls grains items and picks out only necessary information in a certain structure. :param args: :param kwargs: :return: def _system(self, *args, **kwargs): ''' This basically calls grains items and picks out only necessary information in a certai...
Return installed software. def _software(self, *args, **kwargs): ''' Return installed software. ''' data = dict() if 'exclude' in kwargs: excludes = kwargs['exclude'].split(",") else: excludes = list() os_family = __grains__.get("os_famil...
Resolve local users and groups. :param iid: :param named: :param uid: :return: def _id_resolv(self, iid, named=True, uid=True): ''' Resolve local users and groups. :param iid: :param named: :param uid: :return: ''' if no...
Find all unmanaged files. Returns maximum 1000 values. Parameters: * **filter**: Include only results which path starts from the filter string. * **time**: Display time in Unix ticks or format according to the configured TZ (default) Values: ticks, tz (default) * **...
Return all the summary of the particular system. def _all(self, *args, **kwargs): ''' Return all the summary of the particular system. ''' data = dict() data['software'] = self._software(**kwargs) data['system'] = self._system(**kwargs) data['services'] = self._s...
Create vm from file def _create_update_from_file(mode='create', uuid=None, path=None): ''' Create vm from file ''' ret = {} if not os.path.isfile(path) or path is None: ret['Error'] = 'File ({0}) does not exists!'.format(path) return ret # vmadm validate create|update [-f <filen...
Create vm from configuration def _create_update_from_cfg(mode='create', uuid=None, vmcfg=None): ''' Create vm from configuration ''' ret = {} # write json file vmadm_json_file = __salt__['temp.file'](prefix='vmadm-') with salt.utils.files.fopen(vmadm_json_file, 'w') as vmadm_json: ...
Start a vm vm : string vm to be started options : string optional additional options key : string [uuid|alias|hostname] value type of 'vm' parameter CLI Example: .. code-block:: bash salt '*' vmadm.start 186da9ab-7392-4f55-91a5-b8f1fe770543 salt '*' vmadm....