INSTRUCTION
stringlengths
1
46.3k
RESPONSE
stringlengths
75
80.2k
Given a valid config, create a policy. Returns {created: true} if the policy was created and returns {created: False} if the policy was not created. CLI Example: .. code-block:: bash salt myminion boto_iot.create_policy my_policy \\ '{"Version":"2015-12-12",\\ "St...
def create_policy(policyName, policyDocument, region=None, key=None, keyid=None, profile=None): ''' Given a valid config, create a policy. Returns {created: true} if the policy was created and returns {created: False} if the policy was not created. CLI Example: .. code-block:: bas...
Given a policy name describe its properties. Returns a dictionary of interesting properties. CLI Example: .. code-block:: bash salt myminion boto_iot.describe_policy mypolicy
def describe_policy(policyName, region=None, key=None, keyid=None, profile=None): ''' Given a policy name describe its properties. Returns a dictionary of interesting properties. CLI Example: .. code-block:: bash salt myminion boto_iot.describe_policy mypolicy ''' ...
Given a policy name and version ID, check to see if the given policy version exists. Returns True if the given policy version exists and returns False if the given policy version does not exist. CLI Example: .. code-block:: bash salt myminion boto_iot.policy_version_exists mypolicy versionid
def policy_version_exists(policyName, policyVersionId, region=None, key=None, keyid=None, profile=None): ''' Given a policy name and version ID, check to see if the given policy version exists. Returns True if the given policy version exists and returns False if the given policy version does...
Given a policy name and version, delete it. Returns {deleted: true} if the policy version was deleted and returns {deleted: false} if the policy version was not deleted. CLI Example: .. code-block:: bash salt myminion boto_iot.delete_policy_version mypolicy version
def delete_policy_version(policyName, policyVersionId, region=None, key=None, keyid=None, profile=None): ''' Given a policy name and version, delete it. Returns {deleted: true} if the policy version was deleted and returns {deleted: false} if the policy version was not deleted. CLI Exa...
Given a policy name and version describe its properties. Returns a dictionary of interesting properties. CLI Example: .. code-block:: bash salt myminion boto_iot.describe_policy_version mypolicy version
def describe_policy_version(policyName, policyVersionId, region=None, key=None, keyid=None, profile=None): ''' Given a policy name and version describe its properties. Returns a dictionary of interesting properties. CLI Example: .. code-block:: bash salt myminion boto_iot.de...
List all policies Returns list of policies CLI Example: .. code-block:: bash salt myminion boto_iot.list_policies Example Return: .. code-block:: yaml policies: - {...} - {...}
def list_policies(region=None, key=None, keyid=None, profile=None): ''' List all policies Returns list of policies CLI Example: .. code-block:: bash salt myminion boto_iot.list_policies Example Return: .. code-block:: yaml policies: - {...} - {...} ...
List the versions available for the given policy. CLI Example: .. code-block:: bash salt myminion boto_iot.list_policy_versions mypolicy Example Return: .. code-block:: yaml policyVersions: - {...} - {...}
def list_policy_versions(policyName, region=None, key=None, keyid=None, profile=None): ''' List the versions available for the given policy. CLI Example: .. code-block:: bash salt myminion boto_iot.list_policy_versions mypolicy Example Return: .. code-block:: yaml ...
Given a rule name, check to see if the given rule exists. Returns True if the given rule exists and returns False if the given rule does not exist. CLI Example: .. code-block:: bash salt myminion boto_iot.topic_rule_exists myrule
def topic_rule_exists(ruleName, region=None, key=None, keyid=None, profile=None): ''' Given a rule name, check to see if the given rule exists. Returns True if the given rule exists and returns False if the given rule does not exist. CLI Example: .. code-block:: bash salt ...
Given a valid config, create a topic rule. Returns {created: true} if the rule was created and returns {created: False} if the rule was not created. CLI Example: .. code-block:: bash salt myminion boto_iot.create_topic_rule my_rule "SELECT * FROM 'some/thing'" \\ '[{"lambda":{"fu...
def create_topic_rule(ruleName, sql, actions, description, ruleDisabled=False, region=None, key=None, keyid=None, profile=None): ''' Given a valid config, create a topic rule. Returns {created: true} if the rule was created and returns {created: False} if the rule was not create...
Given a rule name, delete it. Returns {deleted: true} if the rule was deleted and returns {deleted: false} if the rule was not deleted. CLI Example: .. code-block:: bash salt myminion boto_iot.delete_rule myrule
def delete_topic_rule(ruleName, region=None, key=None, keyid=None, profile=None): ''' Given a rule name, delete it. Returns {deleted: true} if the rule was deleted and returns {deleted: false} if the rule was not deleted. CLI Example: .. code-block:: bash salt myminion bo...
Given a topic rule name describe its properties. Returns a dictionary of interesting properties. CLI Example: .. code-block:: bash salt myminion boto_iot.describe_topic_rule myrule
def describe_topic_rule(ruleName, region=None, key=None, keyid=None, profile=None): ''' Given a topic rule name describe its properties. Returns a dictionary of interesting properties. CLI Example: .. code-block:: bash salt myminion boto_iot.describe_topic_rule myrule '...
List all rules (for a given topic, if specified) Returns list of rules CLI Example: .. code-block:: bash salt myminion boto_iot.list_topic_rules Example Return: .. code-block:: yaml rules: - {...} - {...}
def list_topic_rules(topic=None, ruleDisabled=None, region=None, key=None, keyid=None, profile=None): ''' List all rules (for a given topic, if specified) Returns list of rules CLI Example: .. code-block:: bash salt myminion boto_iot.list_topic_rules Example Return: ...
Returns a unique service status
def _get_svc(rcd, service_status): ''' Returns a unique service status ''' ena = None lines = __salt__['cmd.run']('{0} rcvar'.format(rcd)).splitlines() for rcvar in lines: if rcvar.startswith('$') and '={0}'.format(service_status) in rcvar: ena = 'yes' elif rcvar.star...
Returns all service statuses
def _get_svc_list(service_status): ''' Returns all service statuses ''' prefix = '/etc/rc.d/' ret = set() lines = glob.glob('{0}*'.format(prefix)) for line in lines: svc = _get_svc(line, service_status) if svc is not None: ret.add(svc) return sorted(ret)
Modifies /etc/rc.conf so a service is started or not at boot time and can be started via /etc/rc.d/<service>
def _rcconf_status(name, service_status): ''' Modifies /etc/rc.conf so a service is started or not at boot time and can be started via /etc/rc.d/<service> ''' rcconf = '/etc/rc.conf' rxname = '^{0}=.*'.format(name) newstatus = '{0}={1}'.format(name, service_status) ret = __salt__['cmd.re...
Return a conn object for the passed VM data
def get_conn(): ''' Return a conn object for the passed VM data ''' return ProfitBricksService( username=config.get_cloud_config_value( 'username', get_configured_provider(), __opts__, search_global=False ), password=config.get_clou...
Return a dict of all available VM locations on the cloud provider with relevant data
def avail_locations(call=None): ''' Return a dict of all available VM locations on the cloud provider with relevant data ''' if call == 'action': raise SaltCloudSystemExit( 'The avail_images function must be called with ' '-f or --function, or with the --list-location...
Return a list of the images that are on the provider
def avail_images(call=None): ''' Return a list of the images that are on the provider ''' if call == 'action': raise SaltCloudSystemExit( 'The avail_images function must be called with ' '-f or --function, or with the --list-images option' ) ret = {} conn...
List all the images with alias by location CLI Example: .. code-block:: bash salt-cloud -f list_images my-profitbricks-config location=us/las
def list_images(call=None, kwargs=None): ''' List all the images with alias by location CLI Example: .. code-block:: bash salt-cloud -f list_images my-profitbricks-config location=us/las ''' if call != 'function': raise SaltCloudSystemExit( 'The list_images functio...
Return the VM's size object
def get_size(vm_): ''' Return the VM's size object ''' vm_size = config.get_cloud_config_value('size', vm_, __opts__) sizes = avail_sizes() if not vm_size: return sizes['Small Instance'] for size in sizes: combinations = (six.text_type(sizes[size]['id']), six.text_type(size...
Return datacenter ID from provider configuration
def get_datacenter_id(): ''' Return datacenter ID from provider configuration ''' datacenter_id = config.get_cloud_config_value( 'datacenter_id', get_configured_provider(), __opts__, search_global=False ) conn = get_conn() try: conn.get_datacenter(da...
Return a list of the loadbalancers that are on the provider
def list_loadbalancers(call=None): ''' Return a list of the loadbalancers that are on the provider ''' if call == 'action': raise SaltCloudSystemExit( 'The avail_images function must be called with ' '-f or --function, or with the --list-loadbalancers option' ) ...
Creates a loadbalancer within the datacenter from the provider config. CLI Example: .. code-block:: bash salt-cloud -f create_loadbalancer profitbricks name=mylb
def create_loadbalancer(call=None, kwargs=None): ''' Creates a loadbalancer within the datacenter from the provider config. CLI Example: .. code-block:: bash salt-cloud -f create_loadbalancer profitbricks name=mylb ''' if call != 'function': raise SaltCloudSystemExit( ...
Return the datacenter from the config provider datacenter ID
def get_datacenter(conn): ''' Return the datacenter from the config provider datacenter ID ''' datacenter_id = get_datacenter_id() for item in conn.list_datacenters()['items']: if item['id'] == datacenter_id: return item raise SaltCloudNotFound( 'The specified datac...
Creates a virtual datacenter based on supplied parameters. CLI Example: .. code-block:: bash salt-cloud -f create_datacenter profitbricks name=mydatacenter location=us/las description="my description"
def create_datacenter(call=None, kwargs=None): ''' Creates a virtual datacenter based on supplied parameters. CLI Example: .. code-block:: bash salt-cloud -f create_datacenter profitbricks name=mydatacenter location=us/las description="my description" ''' if call != 'function'...
List all the data centers CLI Example: .. code-block:: bash salt-cloud -f list_datacenters my-profitbricks-config
def list_datacenters(conn=None, call=None): ''' List all the data centers CLI Example: .. code-block:: bash salt-cloud -f list_datacenters my-profitbricks-config ''' if call != 'function': raise SaltCloudSystemExit( 'The list_datacenters function must be called wit...
Return a list of VMs that are on the provider
def list_nodes(conn=None, call=None): ''' Return a list of VMs that are on the provider ''' if call == 'action': raise SaltCloudSystemExit( 'The list_nodes function must be called with -f or --function.' ) if not conn: conn = get_conn() ret = {} datacent...
Reserve the IP Block
def reserve_ipblock(call=None, kwargs=None): ''' Reserve the IP Block ''' if call == 'action': raise SaltCloudSystemExit( 'The reserve_ipblock function must be called with -f or ' '--function.' ) conn = get_conn() if kwargs is None: kwargs = {} ...
Return a list of the VMs that are on the provider, with all fields
def list_nodes_full(conn=None, call=None): ''' Return a list of the VMs that are on the provider, with all fields ''' if call == 'action': raise SaltCloudSystemExit( 'The list_nodes_full function must be called with -f or ' '--function.' ) if not conn: ...
Return a node for the named VM
def get_node(conn, name): ''' Return a node for the named VM ''' datacenter_id = get_datacenter_id() for item in conn.list_servers(datacenter_id)['items']: if item['properties']['name'] == name: node = {'id': item['id']} node.update(item['properties']) re...
Create network interfaces on appropriate LANs as defined in cloud profile.
def _get_nics(vm_): ''' Create network interfaces on appropriate LANs as defined in cloud profile. ''' nics = [] if 'public_lan' in vm_: firewall_rules = [] # Set LAN to public if it already exists, otherwise create a new # public LAN. if 'public_firewall_rules' in vm...
Enables public Internet access for the specified public_lan. If no public LAN is available, then a new public LAN is created.
def set_public_lan(lan_id): ''' Enables public Internet access for the specified public_lan. If no public LAN is available, then a new public LAN is created. ''' conn = get_conn() datacenter_id = get_datacenter_id() try: lan = conn.get_lan(datacenter_id=datacenter_id, lan_id=lan_id)...
Retrieve list of SSH public keys.
def get_public_keys(vm_): ''' Retrieve list of SSH public keys. ''' key_filename = config.get_cloud_config_value( 'ssh_public_key', vm_, __opts__, search_global=False, default=None ) if key_filename is not None: key_filename = os.path.expanduser(key_filename) if not os.pa...
Check SSH private key file and return absolute path if exists.
def get_key_filename(vm_): ''' Check SSH private key file and return absolute path if exists. ''' key_filename = config.get_cloud_config_value( 'ssh_private_key', vm_, __opts__, search_global=False, default=None ) if key_filename is not None: key_filename = os.path.expanduser(key...
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 ...
destroy a machine by name :param name: name given to the machine :param call: call value in this case is 'action' :return: array of booleans , true if successfully stopped and true if successfully removed CLI Example: .. code-block:: bash salt-cloud -d vm_name
def destroy(name, call=None): ''' destroy a machine by name :param name: name given to the machine :param call: call value in this case is 'action' :return: array of booleans , true if successfully stopped and true if successfully removed CLI Example: .. code-block:: bash ...
reboot a machine by name :param name: name given to the machine :param call: call value in this case is 'action' :return: true if successful CLI Example: .. code-block:: bash salt-cloud -a reboot vm_name
def reboot(name, call=None): ''' reboot a machine by name :param name: name given to the machine :param call: call value in this case is 'action' :return: true if successful CLI Example: .. code-block:: bash salt-cloud -a reboot vm_name ''' datacenter_id = get_datacenter_i...
stop a machine by name :param name: name given to the machine :param call: call value in this case is 'action' :return: true if successful CLI Example: .. code-block:: bash salt-cloud -a stop vm_name
def stop(name, call=None): ''' stop a machine by name :param name: name given to the machine :param call: call value in this case is 'action' :return: true if successful CLI Example: .. code-block:: bash salt-cloud -a stop vm_name ''' datacenter_id = get_datacenter_id() ...
start a machine by name :param name: name given to the machine :param call: call value in this case is 'action' :return: true if successful CLI Example: .. code-block:: bash salt-cloud -a start vm_name
def start(name, call=None): ''' start a machine by name :param name: name given to the machine :param call: call value in this case is 'action' :return: true if successful CLI Example: .. code-block:: bash salt-cloud -a start vm_name ''' datacenter_id = get_datacenter_id(...
Apply any extra component overrides to VM from the cloud profile.
def _override_size(vm_): ''' Apply any extra component overrides to VM from the cloud profile. ''' vm_size = get_size(vm_) if 'cores' in vm_: vm_size['cores'] = vm_['cores'] if 'ram' in vm_: vm_size['ram'] = vm_['ram'] return vm_size
Construct server instance from cloud profile config
def _get_server(vm_, volumes, nics): ''' Construct server instance from cloud profile config ''' # Apply component overrides to the size from the cloud profile config vm_size = _override_size(vm_) # Set the server availability zone from the cloud profile config availability_zone = config.ge...
Construct VM system volume list from cloud profile config
def _get_system_volume(vm_): ''' Construct VM system volume list from cloud profile config ''' # Override system volume size if 'disk_size' is defined in cloud profile disk_size = get_size(vm_)['disk'] if 'disk_size' in vm_: disk_size = vm_['disk_size'] # Construct the system volum...
Construct a list of optional data volumes from the cloud profile
def _get_data_volumes(vm_): ''' Construct a list of optional data volumes from the cloud profile ''' ret = [] volumes = vm_['volumes'] for key, value in six.iteritems(volumes): # Verify the required 'disk_size' property is present in the cloud # profile config if 'disk_si...
Construct a list of optional firewall rules from the cloud profile.
def _get_firewall_rules(firewall_rules): ''' Construct a list of optional firewall rules from the cloud profile. ''' ret = [] for key, value in six.iteritems(firewall_rules): # Verify the required 'protocol' property is present in the cloud # profile config if 'protocol' not ...
Poll request status until resource is provisioned.
def _wait_for_completion(conn, promise, wait_timeout, msg): ''' Poll request status until resource is provisioned. ''' if not promise: return wait_timeout = time.time() + wait_timeout while wait_timeout > time.time(): time.sleep(5) operation_result = conn.get_request( ...
Determine if a package or runtime is installed. Args: name (str): The name of the package or the runtime. Returns: bool: True if the specified package or runtime is installed. CLI Example: .. code-block:: bash salt '*' flatpak.is_installed org.gimp.GIMP
def is_installed(name): ''' Determine if a package or runtime is installed. Args: name (str): The name of the package or the runtime. Returns: bool: True if the specified package or runtime is installed. CLI Example: .. code-block:: bash salt '*' flatpak.is_installed...
Uninstall the specified package. Args: pkg (str): The package name. Returns: dict: The ``result`` and ``output``. CLI Example: .. code-block:: bash salt '*' flatpak.uninstall org.gimp.GIMP
def uninstall(pkg): ''' Uninstall the specified package. Args: pkg (str): The package name. Returns: dict: The ``result`` and ``output``. CLI Example: .. code-block:: bash salt '*' flatpak.uninstall org.gimp.GIMP ''' ret = {'result': None, 'output': ''} ...
Adds a new location to install flatpak packages from. Args: name (str): The repository's name. location (str): The location of the repository. Returns: dict: The ``result`` and ``output``. CLI Example: .. code-block:: bash salt '*' flatpak.add_remote flathub https://...
def add_remote(name, location): ''' Adds a new location to install flatpak packages from. Args: name (str): The repository's name. location (str): The location of the repository. Returns: dict: The ``result`` and ``output``. CLI Example: .. code-block:: bash ...
Determines if a remote exists. Args: remote (str): The remote's name. Returns: bool: True if the remote has already been added. CLI Example: .. code-block:: bash salt '*' flatpak.is_remote_added flathub
def is_remote_added(remote): ''' Determines if a remote exists. Args: remote (str): The remote's name. Returns: bool: True if the remote has already been added. CLI Example: .. code-block:: bash salt '*' flatpak.is_remote_added flathub ''' out = __salt__['cmd...
Compatibility helper function to make __utils__ available on demand.
def pack_dunder(name): ''' Compatibility helper function to make __utils__ available on demand. ''' # TODO: Deprecate starting with Beryllium mod = sys.modules[name] if not hasattr(mod, '__utils__'): setattr(mod, '__utils__', salt.loader.utils(mod.__opts__))
Compatibility helper function to allow copy.deepcopy copy bound methods which is broken on Python 2.6, due to the following bug: https://bugs.python.org/issue1515 Warnings: - This method will mutate the global deepcopy dispatcher, which means that this function is NOT threadsafe! -...
def deepcopy_bound(name): ''' Compatibility helper function to allow copy.deepcopy copy bound methods which is broken on Python 2.6, due to the following bug: https://bugs.python.org/issue1515 Warnings: - This method will mutate the global deepcopy dispatcher, which means that this ...
Check if there is an upgrade available for a certain package CLI Example: .. code-block:: bash salt '*' pkgutil.upgrade_available CSWpython
def upgrade_available(name): ''' Check if there is an upgrade available for a certain package CLI Example: .. code-block:: bash salt '*' pkgutil.upgrade_available CSWpython ''' version_num = None cmd = '/opt/csw/bin/pkgutil -c --parse --single {0}'.format( name) out = ...
List all available package upgrades on this system CLI Example: .. code-block:: bash salt '*' pkgutil.list_upgrades
def list_upgrades(refresh=True, **kwargs): # pylint: disable=W0613 ''' List all available package upgrades on this system CLI Example: .. code-block:: bash salt '*' pkgutil.list_upgrades ''' if salt.utils.data.is_true(refresh): refresh_db() upgrades = {} lines = __sal...
Upgrade all of the packages to the latest available version. Returns a dict containing the changes:: {'<package>': {'old': '<old-version>', 'new': '<new-version>'}} CLI Example: .. code-block:: bash salt '*' pkgutil.upgrade
def upgrade(refresh=True): ''' Upgrade all of the packages to the latest available version. Returns a dict containing the changes:: {'<package>': {'old': '<old-version>', 'new': '<new-version>'}} CLI Example: .. code-block:: bash salt '*' pkgutil.upgrade ...
Install packages using the pkgutil tool. CLI Example: .. code-block:: bash salt '*' pkg.install <package_name> salt '*' pkg.install SMClgcc346 Multiple Package Installation Options: pkgs A list of packages to install from OpenCSW. Must be passed as a python list. ...
def install(name=None, refresh=False, version=None, pkgs=None, **kwargs): ''' Install packages using the pkgutil tool. CLI Example: .. code-block:: bash salt '*' pkg.install <package_name> salt '*' pkg.install SMClgcc346 Multiple Package Installation Options: pkgs A...
Remove a package and all its dependencies which are not in use by other packages. 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...
def remove(name=None, pkgs=None, **kwargs): ''' Remove a package and all its dependencies which are not in use by other packages. 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 ...
Ensure a device is monitored. The 'name' given will be used for Zenoss device name and should be resolvable. .. code-block:: yaml enable_monitoring: zenoss.monitored: - name: web01.example.com - device_class: /Servers/Linux - collector: localhost -...
def monitored(name, device_class=None, collector='localhost', prod_state=None): ''' Ensure a device is monitored. The 'name' given will be used for Zenoss device name and should be resolvable. .. code-block:: yaml enable_monitoring: zenoss.monitored: - name: web01.example.com...
Find volume by name on minion
def _find_volume(name): ''' Find volume by name on minion ''' docker_volumes = __salt__['docker.volumes']()['Volumes'] if docker_volumes: volumes = [v for v in docker_volumes if v['Name'] == name] if volumes: return volumes[0] return None
Ensure that a volume is present. .. versionadded:: 2015.8.4 .. versionchanged:: 2015.8.6 This state no longer deletes and re-creates a volume if the existing volume's driver does not match the ``driver`` parameter (unless the ``force`` parameter is set to ``True``). .. versionchange...
def present(name, driver=None, driver_opts=None, force=False): ''' Ensure that a volume is present. .. versionadded:: 2015.8.4 .. versionchanged:: 2015.8.6 This state no longer deletes and re-creates a volume if the existing volume's driver does not match the ``driver`` parameter (unles...
Ensure that a volume is absent. .. versionadded:: 2015.8.4 .. versionchanged:: 2017.7.0 This state was renamed from **docker.volume_absent** to **docker_volume.absent** name Name of the volume Usage Examples: .. code-block:: yaml volume_foo: docker_volume.absen...
def absent(name, driver=None): ''' Ensure that a volume is absent. .. versionadded:: 2015.8.4 .. versionchanged:: 2017.7.0 This state was renamed from **docker.volume_absent** to **docker_volume.absent** name Name of the volume Usage Examples: .. code-block:: yaml ...
Generates a list of salt://<formula>/defaults.(json|yaml) files and fetches them from the Salt master. Returns first defaults file as python dict.
def _load(formula): ''' Generates a list of salt://<formula>/defaults.(json|yaml) files and fetches them from the Salt master. Returns first defaults file as python dict. ''' # Compute possibilities _mk_client() paths = [] for ext in ('yaml', 'json'): source_url = salt.util...
defaults.get is used much like pillar.get except that it will read a default value for a pillar from defaults.json or defaults.yaml files that are stored in the root of a salt formula. CLI Example: .. code-block:: bash salt '*' defaults.get core:users:root The defaults is computed from p...
def get(key, default=''): ''' defaults.get is used much like pillar.get except that it will read a default value for a pillar from defaults.json or defaults.yaml files that are stored in the root of a salt formula. CLI Example: .. code-block:: bash salt '*' defaults.get core:users:roo...
defaults.merge Allows deep merging of dicts in formulas. merge_lists : False If True, it will also merge lists instead of replace their items. in_place : True If True, it will merge into dest dict, if not it will make a new copy from that dict and return it. CLI Exampl...
def merge(dest, src, merge_lists=False, in_place=True): ''' defaults.merge Allows deep merging of dicts in formulas. merge_lists : False If True, it will also merge lists instead of replace their items. in_place : True If True, it will merge into dest dict, if not it wi...
defaults.update Allows to set defaults for group of data set e.g. group for nodes. This function is a combination of defaults.merge and defaults.deepcopy to avoid redundant in jinja. Example: .. code-block:: yaml group01: defaults: en...
def update(dest, defaults, merge_lists=True, in_place=True): ''' defaults.update Allows to set defaults for group of data set e.g. group for nodes. This function is a combination of defaults.merge and defaults.deepcopy to avoid redundant in jinja. Example: .. code-bloc...
Copied from win_system.py (_get_date_time_format) Function that detects the date/time format for the string passed. :param str dt_string: A date/time string :return: The format of the passed dt_string :rtype: str
def _get_date_time_format(dt_string): ''' Copied from win_system.py (_get_date_time_format) Function that detects the date/time format for the string passed. :param str dt_string: A date/time string :return: The format of the passed dt_string :rtype: str ''' valid_formats = [ ...
Lookup the key in a dictionary by it's value. Will return the first match. :param dict dictionary: The dictionary to search :param str value: The value to search for. :return: Returns the first key to match the value :rtype: str
def _reverse_lookup(dictionary, value): ''' Lookup the key in a dictionary by it's value. Will return the first match. :param dict dictionary: The dictionary to search :param str value: The value to search for. :return: Returns the first key to match the value :rtype: str ''' value_in...
Lookup the first value given a key. Returns the first value if the key refers to a list or the value itself. :param dict dictionary: The dictionary to search :param str key: The key to get :return: Returns the first value available for the key :rtype: str
def _lookup_first(dictionary, key): ''' Lookup the first value given a key. Returns the first value if the key refers to a list or the value itself. :param dict dictionary: The dictionary to search :param str key: The key to get :return: Returns the first value available for the key :rtyp...
Internal function to save the task definition. :param str name: The name of the task. :param str task_folder: The object representing the folder in which to save the task :param str task_definition: The object representing the task to be saved :param str user_name: The user_account under which t...
def _save_task_definition(name, task_folder, task_definition, user_name, password, logon_type): ''' Internal function to save the task definition. :param str name: The name of t...
r''' List all tasks located in a specific location in the task scheduler. :param str location: A string value representing the folder from which you want to list tasks. Default is '\\' which is the root for the task scheduler (C:\Windows\System32\tasks). :return: Returns a list of tasks. ...
def list_tasks(location='\\'): r''' List all tasks located in a specific location in the task scheduler. :param str location: A string value representing the folder from which you want to list tasks. Default is '\\' which is the root for the task scheduler (C:\Windows\System32\tasks). ...
r''' List all folders located in a specific location in the task scheduler. :param str location: A string value representing the folder from which you want to list tasks. Default is '\\' which is the root for the task scheduler (C:\Windows\System32\tasks). :return: Returns a list of folder...
def list_folders(location='\\'): r''' List all folders located in a specific location in the task scheduler. :param str location: A string value representing the folder from which you want to list tasks. Default is '\\' which is the root for the task scheduler (C:\Windows\System32\tasks). ...
r''' List all triggers that pertain to a task in the specified location. :param str name: The name of the task for which list triggers. :param str location: A string value representing the location of the task from which to list triggers. Default is '\\' which is the root for the task sche...
def list_triggers(name, location='\\'): r''' List all triggers that pertain to a task in the specified location. :param str name: The name of the task for which list triggers. :param str location: A string value representing the location of the task from which to list triggers. Default is '\\'...
r''' List all actions that pertain to a task in the specified location. :param str name: The name of the task for which list actions. :param str location: A string value representing the location of the task from which to list actions. Default is '\\' which is the root for the task schedul...
def list_actions(name, location='\\'): r''' List all actions that pertain to a task in the specified location. :param str name: The name of the task for which list actions. :param str location: A string value representing the location of the task from which to list actions. Default is '\\' whi...
r''' Create a new task in the designated location. This function has many keyword arguments that are not listed here. For additional arguments see: - :py:func:`edit_task` - :py:func:`add_action` - :py:func:`add_trigger` :param str name: The name of the task. This will be displayed in the task ...
def create_task(name, location='\\', user_name='System', password=None, force=False, **kwargs): r''' Create a new task in the designated location. This function has many keyword arguments that are not listed here. For additional...
r''' Create a task based on XML. Source can be a file or a string of XML. :param str name: The name of the task. This will be displayed in the task scheduler. :param str location: A string value representing the location in which to create the task. Default is '\\' which is the root for th...
def create_task_from_xml(name, location='\\', xml_text=None, xml_path=None, user_name='System', password=None): r''' Create a task based on XML. Source can be a file or a string of XML. ...
r''' Create a folder in which to create tasks. :param str name: The name of the folder. This will be displayed in the task scheduler. :param str location: A string value representing the location in which to create the folder. Default is '\\' which is the root for the task schedule...
def create_folder(name, location='\\'): r''' Create a folder in which to create tasks. :param str name: The name of the folder. This will be displayed in the task scheduler. :param str location: A string value representing the location in which to create the folder. Default is '\\' whi...
r''' Edit the parameters of a task. Triggers and Actions cannot be edited yet. :param str name: The name of the task. This will be displayed in the task scheduler. :param str location: A string value representing the location in which to create the task. Default is '\\' which is the root f...
def edit_task(name=None, location='\\', # General Tab user_name=None, password=None, description=None, enabled=None, hidden=None, # Conditions Tab run_if_idle=None, idle_duration=N...
r''' Delete a task from the task scheduler. :param str name: The name of the task to delete. :param str location: A string value representing the location of the task. Default is '\\' which is the root for the task scheduler (C:\Windows\System32\tasks). :return: True if successful, Fa...
def delete_task(name, location='\\'): r''' Delete a task from the task scheduler. :param str name: The name of the task to delete. :param str location: A string value representing the location of the task. Default is '\\' which is the root for the task scheduler (C:\Windows\System32\ta...
r''' Run a scheduled task manually. :param str name: The name of the task to run. :param str location: A string value representing the location of the task. Default is '\\' which is the root for the task scheduler (C:\Windows\System32\tasks). :return: True if successful, False if unsu...
def run(name, location='\\'): r''' Run a scheduled task manually. :param str name: The name of the task to run. :param str location: A string value representing the location of the task. Default is '\\' which is the root for the task scheduler (C:\Windows\System32\tasks). :return:...
r''' Run a scheduled task and return when the task finishes :param str name: The name of the task to run. :param str location: A string value representing the location of the task. Default is '\\' which is the root for the task scheduler (C:\Windows\System32\tasks). :return: True if s...
def run_wait(name, location='\\'): r''' Run a scheduled task and return when the task finishes :param str name: The name of the task to run. :param str location: A string value representing the location of the task. Default is '\\' which is the root for the task scheduler (C:\Windows\S...
r''' Determine the status of a task. Is it Running, Queued, Ready, etc. :param str name: The name of the task for which to return the status :param str location: A string value representing the location of the task. Default is '\\' which is the root for the task scheduler (C:\Windows\Syste...
def status(name, location='\\'): r''' Determine the status of a task. Is it Running, Queued, Ready, etc. :param str name: The name of the task for which to return the status :param str location: A string value representing the location of the task. Default is '\\' which is the root for the tas...
r''' Get the details about a task in the task scheduler. :param str name: The name of the task for which to return the status :param str location: A string value representing the location of the task. Default is '\\' which is the root for the task scheduler (C:\Windows\System32\tasks). ...
def info(name, location='\\'): r''' Get the details about a task in the task scheduler. :param str name: The name of the task for which to return the status :param str location: A string value representing the location of the task. Default is '\\' which is the root for the task scheduler ...
r''' Add an action to a task. :param str name: The name of the task to which to add the action. :param str location: A string value representing the location of the task. Default is '\\' which is the root for the task scheduler (C:\Windows\System32\tasks). :param str action_type: The ...
def add_action(name=None, location='\\', action_type='Execute', **kwargs): r''' Add an action to a task. :param str name: The name of the task to which to add the action. :param str location: A string value representing the location of the task. Def...
r''' :param str name: The name of the task to which to add the trigger. :param str location: A string value representing the location of the task. Default is '\\' which is the root for the task scheduler (C:\Windows\System32\tasks). :param str trigger_type: The type of trigger to create. T...
def add_trigger(name=None, location='\\', trigger_type=None, trigger_enabled=True, start_date=None, start_time=None, end_date=None, end_time=None, random_delay=None, repeat_int...
r''' Remove all triggers from the task. :param str name: The name of the task from which to clear all triggers. :param str location: A string value representing the location of the task. Default is '\\' which is the root for the task scheduler (C:\Windows\System32\tasks). :return: Tru...
def clear_triggers(name, location='\\'): r''' Remove all triggers from the task. :param str name: The name of the task from which to clear all triggers. :param str location: A string value representing the location of the task. Default is '\\' which is the root for the task scheduler (...
Get a connection to CouchDB
def _get_conn(profile): ''' Get a connection to CouchDB ''' DEFAULT_BASE_URL = _construct_uri(profile) or 'http://localhost:5984' server = couchdb.Server() if profile['database'] not in server: server.create(profile['database']) return server
Set a key/value pair in couchdb
def set_(key, value, profile=None): ''' Set a key/value pair in couchdb ''' db = _get_db(profile) return db.save({'_id': uuid4().hex, key: value})
Generate a key for use with salt-ssh
def gen_key(path): ''' Generate a key for use with salt-ssh ''' cmd = 'ssh-keygen -P "" -f {0} -t rsa -q'.format(path) if not os.path.isdir(os.path.dirname(path)): os.makedirs(os.path.dirname(path)) subprocess.call(cmd, shell=True)
Return the correct shell interface for the target system
def gen_shell(opts, **kwargs): ''' Return the correct shell interface for the target system ''' if kwargs['winrm']: try: import saltwinshell shell = saltwinshell.Shell(opts, **kwargs) except ImportError: log.error('The saltwinshell library is not avail...
Parse out an error and return a targeted error string
def get_error(self, errstr): ''' Parse out an error and return a targeted error string ''' for line in errstr.split('\n'): if line.startswith('ssh:'): return line if line.startswith('Pseudo-terminal'): continue if 'to th...
Return options for the ssh command base for Salt to call
def _key_opts(self): ''' Return options for the ssh command base for Salt to call ''' options = [ 'KbdInteractiveAuthentication=no', ] if self.passwd: options.append('PasswordAuthentication=yes') else: options....
Return options to pass to ssh
def _passwd_opts(self): ''' Return options to pass to ssh ''' # TODO ControlMaster does not work without ControlPath # user could take advantage of it if they set ControlPath in their # ssh config. Also, ControlPersist not widely available. options = ['ControlMas...
Return the string to execute ssh-copy-id
def _copy_id_str_old(self): ''' Return the string to execute ssh-copy-id ''' if self.passwd: # Using single quotes prevents shell expansion and # passwords containing '$' return "{0} {1} '{2} -p {3} {4} {5}@{6}'".format( 'ssh-copy-i...
Execute ssh-copy-id to plant the id file on the target
def copy_id(self): ''' Execute ssh-copy-id to plant the id file on the target ''' stdout, stderr, retcode = self._run_cmd(self._copy_id_str_old()) if salt.defaults.exitcodes.EX_OK != retcode and 'Usage' in stderr: stdout, stderr, retcode = self._run_cmd(self._copy_id_...
Return the cmd string to execute
def _cmd_str(self, cmd, ssh='ssh'): ''' Return the cmd string to execute ''' # TODO: if tty, then our SSH_SHIM cannot be supplied from STDIN Will # need to deliver the SHIM to the remote host and execute it there command = [ssh] if ssh != 'scp': comm...
Cleanly execute the command string
def _old_run_cmd(self, cmd): ''' Cleanly execute the command string ''' try: proc = subprocess.Popen( cmd, shell=True, stderr=subprocess.PIPE, stdout=subprocess.PIPE, ) data = proc.commun...
cmd iterator
def _run_nb_cmd(self, cmd): ''' cmd iterator ''' try: proc = salt.utils.nb_popen.NonBlockingPopen( cmd, shell=True, stderr=subprocess.PIPE, stdout=subprocess.PIPE, ) while True: ...
Yield None until cmd finished
def exec_nb_cmd(self, cmd): ''' Yield None until cmd finished ''' r_out = [] r_err = [] rcode = None cmd = self._cmd_str(cmd) logmsg = 'Executing non-blocking command: {0}'.format(cmd) if self.passwd: logmsg = logmsg.replace(self.passw...
Execute a remote command
def exec_cmd(self, cmd): ''' Execute a remote command ''' cmd = self._cmd_str(cmd) logmsg = 'Executing command: {0}'.format(cmd) if self.passwd: logmsg = logmsg.replace(self.passwd, ('*' * 6)) if 'decode("base64")' in logmsg or 'base64.b64decode(' in ...
scp a file or files to a remote system
def send(self, local, remote, makedirs=False): ''' scp a file or files to a remote system ''' if makedirs: self.exec_cmd('mkdir -p {0}'.format(os.path.dirname(remote))) # scp needs [<ipv6} host = self.host if ':' in host: host = '[{0}]'.fo...
Execute a shell command via VT. This is blocking and assumes that ssh is being run
def _run_cmd(self, cmd, key_accept=False, passwd_retries=3): ''' Execute a shell command via VT. This is blocking and assumes that ssh is being run ''' if not cmd: return '', 'No command or passphrase', 245 term = salt.utils.vt.Terminal( cmd, ...