INSTRUCTION
stringlengths
1
46.3k
RESPONSE
stringlengths
75
80.2k
sets up the sentry handler
def setup_handlers(): ''' sets up the sentry handler ''' __grains__ = salt.loader.grains(__opts__) __salt__ = salt.loader.minion_mods(__opts__) if 'sentry_handler' not in __opts__: log.debug('No \'sentry_handler\' key was found in the configuration') return False options = {}...
Bind with binddn and bindpw only for searching LDAP :param anonymous: Try binding anonymously :param opts: Pass in when __opts__ is not available :return: LDAPConnection object
def _bind_for_search(anonymous=False, opts=None): ''' Bind with binddn and bindpw only for searching LDAP :param anonymous: Try binding anonymously :param opts: Pass in when __opts__ is not available :return: LDAPConnection object ''' # Get config params; create connection dictionary con...
Render config template, substituting username where found.
def _render_template(param, username): ''' Render config template, substituting username where found. ''' env = Environment() template = env.from_string(param) variables = {'username': username} return template.render(variables)
Simple LDAP auth
def auth(username, password): ''' Simple LDAP auth ''' if not HAS_LDAP: log.error('LDAP authentication requires python-ldap module') return False bind = None # If bind credentials are configured, verify that we receive a valid bind if _config('binddn', mandatory=False) and ...
Authenticate against an LDAP group Behavior is highly dependent on if Active Directory is in use. AD handles group membership very differently than OpenLDAP. See the :ref:`External Authentication <acl-eauth>` documentation for a thorough discussion of available parameters for customizing the search. ...
def groups(username, **kwargs): ''' Authenticate against an LDAP group Behavior is highly dependent on if Active Directory is in use. AD handles group membership very differently than OpenLDAP. See the :ref:`External Authentication <acl-eauth>` documentation for a thorough discussion of availa...
Query LDAP, retrieve list of minion_ids from an OU or other search. For each minion_id returned from the LDAP search, copy the perms matchers into the auth dictionary :param auth_list: :param opts: __opts__ for when __opts__ is not injected :return: Modified auth list.
def process_acl(auth_list, opts=None): ''' Query LDAP, retrieve list of minion_ids from an OU or other search. For each minion_id returned from the LDAP search, copy the perms matchers into the auth dictionary :param auth_list: :param opts: __opts__ for when __opts__ is not injected :return:...
Check for Netmiko arguments that were passed in as NAPALM optional arguments. Return a dictionary of these optional args that will be passed into the Netmiko ConnectHandler call. .. note:: This is a port of the NAPALM helper for backwards compatibility with older versions of NAPALM, and s...
def _get_netmiko_args(optional_args): ''' Check for Netmiko arguments that were passed in as NAPALM optional arguments. Return a dictionary of these optional args that will be passed into the Netmiko ConnectHandler call. .. note:: This is a port of the NAPALM helper for backwards compatib...
Reconnect the NAPALM proxy when the connection is dropped by the network device. The connection can be forced to be restarted using the ``force`` argument. .. note:: This function can be used only when running proxy minions. CLI Example: .. code-block:: bash salt '*' napalm....
def reconnect(force=False, **kwargs): # pylint: disable=unused-argument ''' Reconnect the NAPALM proxy when the connection is dropped by the network device. The connection can be forced to be restarted using the ``force`` argument. .. note:: This function can be used only when running...
Execute arbitrary methods from the NAPALM library. To see the expected output, please consult the NAPALM documentation. .. note:: This feature is not recommended to be used in production. It should be used for testing only! CLI Example: .. code-block:: bash salt '*' napalm.c...
def call(method, *args, **kwargs): ''' Execute arbitrary methods from the NAPALM library. To see the expected output, please consult the NAPALM documentation. .. note:: This feature is not recommended to be used in production. It should be used for testing only! CLI Example: ...
Return the compliance report. filepath The absolute path to the validation file. .. versionchanged:: 2019.2.0 Beginning with release codename ``2019.2.0``, this function has been enhanced, to be able to leverage the multi-engine template rendering of Salt, besides the poss...
def compliance_report(filepath=None, string=None, renderer='jinja|yaml', **kwargs): ''' Return the compliance report. filepath The absolute path to the validation file. .. versionchanged:: 2019.2.0 Beginning with re...
.. versionadded:: 2019.2.0 Return the key-value arguments used for the authentication arguments for the netmiko module. When running in a non-native NAPALM driver (e.g., ``panos``, `f5``, ``mos`` - either from https://github.com/napalm-automation-community or defined in user's own environment, one...
def netmiko_args(**kwargs): ''' .. versionadded:: 2019.2.0 Return the key-value arguments used for the authentication arguments for the netmiko module. When running in a non-native NAPALM driver (e.g., ``panos``, `f5``, ``mos`` - either from https://github.com/napalm-automation-community or de...
.. versionadded:: 2019.2.0 Call an arbitrary function from the :mod:`Netmiko<salt.modules.netmiko_mod>` module, passing the authentication details from the existing NAPALM connection. fun The name of the function from the :mod:`Netmiko<salt.modules.netmiko_mod>` to invoke. args ...
def netmiko_fun(fun, *args, **kwargs): ''' .. versionadded:: 2019.2.0 Call an arbitrary function from the :mod:`Netmiko<salt.modules.netmiko_mod>` module, passing the authentication details from the existing NAPALM connection. fun The name of the function from the :mod:`Netmiko<salt.mo...
.. versionadded:: 2019.2.0 Execute an arbitrary Netmiko method, passing the authentication details from the existing NAPALM connection. method The name of the Netmiko method to execute. args List of arguments to send to the Netmiko method specified in ``method``. kwargs K...
def netmiko_call(method, *args, **kwargs): ''' .. versionadded:: 2019.2.0 Execute an arbitrary Netmiko method, passing the authentication details from the existing NAPALM connection. method The name of the Netmiko method to execute. args List of arguments to send to the Netmik...
.. versionadded:: 2019.2.0 Execute a list of arbitrary Netmiko methods, passing the authentication details from the existing NAPALM connection. methods List of dictionaries with the following keys: - ``name``: the name of the Netmiko function to invoke. - ``args``: list of argumen...
def netmiko_multi_call(*methods, **kwargs): ''' .. versionadded:: 2019.2.0 Execute a list of arbitrary Netmiko methods, passing the authentication details from the existing NAPALM connection. methods List of dictionaries with the following keys: - ``name``: the name of the Netmiko...
.. versionadded:: 2019.2.0 Invoke one or more commands to be executed on the remote device, via Netmiko. Returns a list of strings, with the output from each command. commands A list of commands to be executed. expect_string Regular expression pattern to use for determining end of out...
def netmiko_commands(*commands, **kwargs): ''' .. versionadded:: 2019.2.0 Invoke one or more commands to be executed on the remote device, via Netmiko. Returns a list of strings, with the output from each command. commands A list of commands to be executed. expect_string Regul...
.. versionadded:: 2019.2.0 Load a list of configuration commands on the remote device, via Netmiko. .. warning:: Please remember that ``netmiko`` does not have any rollback safeguards and any configuration change will be directly loaded into the running config if the platform doesn't ...
def netmiko_config(*config_commands, **kwargs): ''' .. versionadded:: 2019.2.0 Load a list of configuration commands on the remote device, via Netmiko. .. warning:: Please remember that ``netmiko`` does not have any rollback safeguards and any configuration change will be directly loa...
.. versionadded:: 2019.2.0 Execute an RPC request on the remote Junos device. cmd The RPC request to the executed. To determine the RPC request, you can check the from the command line of the device, by executing the usual command followed by ``| display xml rpc``, e.g., ``show...
def junos_rpc(cmd=None, dest=None, format=None, **kwargs): ''' .. versionadded:: 2019.2.0 Execute an RPC request on the remote Junos device. cmd The RPC request to the executed. To determine the RPC request, you can check the from the command line of the device, by executing the usual ...
.. versionadded:: 2019.2.0 Installs the given image on the device. path The image file source. This argument supports the following URIs: - Absolute path on the Minion. - ``salt://`` to fetch from the Salt fileserver. - ``http://`` and ``https://`` - ``ftp://`` ...
def junos_install_os(path=None, **kwargs): ''' .. versionadded:: 2019.2.0 Installs the given image on the device. path The image file source. This argument supports the following URIs: - Absolute path on the Minion. - ``salt://`` to fetch from the Salt fileserver. - ``...
.. versionadded:: 2019.2.0 The complete list of Junos facts collected by ``junos-eznc``. CLI Example: .. code-block:: bash salt '*' napalm.junos_facts
def junos_facts(**kwargs): ''' .. versionadded:: 2019.2.0 The complete list of Junos facts collected by ``junos-eznc``. CLI Example: .. code-block:: bash salt '*' napalm.junos_facts ''' prep = _junos_prep_fun(napalm_device) # pylint: disable=undefined-variable if not prep['r...
.. versionadded:: 2019.2.0 Execute a CLI command and return the output in the specified format. command The command to execute on the Junos CLI. format: ``text`` Format in which to get the CLI output (either ``text`` or ``xml``). dev_timeout: ``30`` The NETCONF RPC timeout (i...
def junos_cli(command, format=None, dev_timeout=None, dest=None, **kwargs): ''' .. versionadded:: 2019.2.0 Execute a CLI command and return the output in the specified format. command The command to execute on the Junos CLI. format: ``text`` Format in which to get the CLI output (...
.. versionadded:: 2019.2.0 Copies the file on the remote Junos device. src The source file path. This argument accepts the usual Salt URIs (e.g., ``salt://``, ``http://``, ``https://``, ``s3://``, ``ftp://``, etc.). dst The destination path on the device where to copy the file. ...
def junos_copy_file(src, dst, **kwargs): ''' .. versionadded:: 2019.2.0 Copies the file on the remote Junos device. src The source file path. This argument accepts the usual Salt URIs (e.g., ``salt://``, ``http://``, ``https://``, ``s3://``, ``ftp://``, etc.). dst The dest...
.. versionadded:: 2019.2.0 Execute an arbitrary function from the :mod:`junos execution module <salt.module.junos>`. To check what ``args`` and ``kwargs`` you must send to the function, please consult the appropriate documentation. fun The name of the function. E.g., ``set_hostname``. ...
def junos_call(fun, *args, **kwargs): ''' .. versionadded:: 2019.2.0 Execute an arbitrary function from the :mod:`junos execution module <salt.module.junos>`. To check what ``args`` and ``kwargs`` you must send to the function, please consult the appropriate documentation. fun The ...
.. versionadded:: 2019.2.0 Return the key-value arguments used for the authentication arguments for the :mod:`pyeapi execution module <salt.module.arista_pyeapi>`. CLI Example: .. code-block:: bash salt '*' napalm.pyeapi_nxos_api_args
def pyeapi_nxos_api_args(**prev_kwargs): ''' .. versionadded:: 2019.2.0 Return the key-value arguments used for the authentication arguments for the :mod:`pyeapi execution module <salt.module.arista_pyeapi>`. CLI Example: .. code-block:: bash salt '*' napalm.pyeapi_nxos_api_args ...
.. versionadded:: 2019.2.0 Invoke an arbitrary method from the ``pyeapi`` library. This function forwards the existing connection details to the :mod:`pyeapi.run_commands <salt.module.arista_pyeapi.run_commands>` execution function. method The name of the ``pyeapi`` method to invoke. ...
def pyeapi_call(method, *args, **kwargs): ''' .. versionadded:: 2019.2.0 Invoke an arbitrary method from the ``pyeapi`` library. This function forwards the existing connection details to the :mod:`pyeapi.run_commands <salt.module.arista_pyeapi.run_commands>` execution function. method ...
.. versionadded:: 2019.2.0 Configures the Arista switch with the specified commands, via the ``pyeapi`` library. This function forwards the existing connection details to the :mod:`pyeapi.run_commands <salt.module.arista_pyeapi.run_commands>` execution function. commands The list of config...
def pyeapi_config(commands=None, config_file=None, template_engine='jinja', context=None, defaults=None, saltenv='base', **kwargs): ''' .. versionadded:: 2019.2.0 Configures the Arista switch with th...
.. versionadded:: 2019.2.0 Execute an arbitrary RPC request via the Nexus API. commands The RPC commands to be executed. method: ``cli`` The type of the response, i.e., raw text (``cli_ascii``) or structured document (``cli``). Defaults to ``cli`` (structured data). CLI Examp...
def nxos_api_rpc(commands, method='cli', **kwargs): ''' .. versionadded:: 2019.2.0 Execute an arbitrary RPC request via the Nexus API. commands The RPC commands to be executed. method: ``cli`` The type of the response, i.e., raw text (``cli_ascii`...
.. versionadded:: 2019.2.0 Configures the Nexus switch with the specified commands, via the NX-API. commands The list of configuration commands to load on the Nexus switch. .. note:: This argument is ignored when ``config_file`` is specified. config_file The source fi...
def nxos_api_config(commands=None, config_file=None, template_engine='jinja', context=None, defaults=None, saltenv='base', **kwargs): ''' .. versionadded:: 2019.2.0 Configures the Nexus ...
.. versionadded:: 2019.2.0 Execute one or more show (non-configuration) commands. commands The commands to be executed. raw_text: ``True`` Whether to return raw text or structured data. CLI Example: .. code-block:: bash salt '*' napalm.nxos_api_show 'show version' ...
def nxos_api_show(commands, raw_text=True, **kwargs): ''' .. versionadded:: 2019.2.0 Execute one or more show (non-configuration) commands. commands The commands to be executed. raw_text: ``True`` Whether to return raw text or structured data. CLI Example: .. code-block:...
.. versionadded:: 2019.2.0 This is a wrapper to execute RPC requests on various network operating systems supported by NAPALM, invoking the following functions for the NAPALM native drivers: - :py:func:`napalm.junos_rpc <salt.modules.napalm_mod.junos_rpc>` for ``junos`` - :py:func:`napalm.pyeapi_r...
def rpc(command, **kwargs): ''' .. versionadded:: 2019.2.0 This is a wrapper to execute RPC requests on various network operating systems supported by NAPALM, invoking the following functions for the NAPALM native drivers: - :py:func:`napalm.junos_rpc <salt.modules.napalm_mod.junos_rpc>` for `...
r''' .. versionadded:: 2019.2.0 Return the configuration lines that match the regular expressions from the ``regex`` argument. The configuration is read from the network device interrogated. regex The regular expression to match the configuration lines against. source: ``running`` ...
def config_find_lines(regex, source='running'): r''' .. versionadded:: 2019.2.0 Return the configuration lines that match the regular expressions from the ``regex`` argument. The configuration is read from the network device interrogated. regex The regular expression to match the confi...
r''' .. versionadded:: 2019.2.0 Return the configuration lines that match the regular expressions from the ``parent_regex`` argument, having child lines matching ``child_regex``. The configuration is read from the network device interrogated. .. note:: This function is only available only...
def config_lines_w_child(parent_regex, child_regex, source='running'): r''' .. versionadded:: 2019.2.0 Return the configuration lines that match the regular expressions from the ``parent_regex`` argument, having child lines matching ``child_regex``. The configuration is read from the network devic...
.. versionadded:: 2019.2.0 Return the configuration lines that match the regular expressions from the ``parent_regex`` argument, having the child lines *not* matching ``child_regex``. The configuration is read from the network device interrogated. .. note:: This function is only available ...
def config_lines_wo_child(parent_regex, child_regex, source='running'): ''' .. versionadded:: 2019.2.0 Return the configuration lines that match the regular expressions from the ``parent_regex`` argument, having the child lines *not* matching ``child_regex``. The configuration is read from th...
r''' .. versionadded:: 2019.2.0 Return a list of detailed matches, for the configuration blocks (parent-child relationship) whose parent respects the regular expressions configured via the ``parent_regex`` argument, and the child matches the ``child_regex`` regular expression. The result is a list ...
def config_filter_lines(parent_regex, child_regex, source='running'): r''' .. versionadded:: 2019.2.0 Return a list of detailed matches, for the configuration blocks (parent-child relationship) whose parent respects the regular expressions configured via the ``parent_regex`` argument, and the child...
.. versionadded:: 2019.2.0 Transform Cisco IOS style configuration to structured Python dictionary. Depending on the value of the ``with_tags`` argument, this function may provide different views, valuable in different situations. source: ``running`` The configuration type to retrieve from the...
def config_tree(source='running', with_tags=False): ''' .. versionadded:: 2019.2.0 Transform Cisco IOS style configuration to structured Python dictionary. Depending on the value of the ``with_tags`` argument, this function may provide different views, valuable in different situations. source:...
.. versionadded:: 2019.2.0 Return the merge tree of the ``initial_config`` with the ``merge_config``, as a Python dictionary. source: ``running`` The configuration type to retrieve from the network device. Default: ``running``. Available options: ``running``, ``startup``, ``candidate``. ...
def config_merge_tree(source='running', merge_config=None, merge_path=None, saltenv='base'): ''' .. versionadded:: 2019.2.0 Return the merge tree of the ``initial_config`` with the ``merge_config``, as a Python dictionary. source: `...
.. versionadded:: 2019.2.0 Return the merge result of the configuration from ``source`` with the merge configuration, as plain text (without loading the config on the device). source: ``running`` The configuration type to retrieve from the network device. Default: ``running``. Availabl...
def config_merge_text(source='running', merge_config=None, merge_path=None, saltenv='base'): ''' .. versionadded:: 2019.2.0 Return the merge result of the configuration from ``source`` with the merge configuration, as plain text (without...
.. versionadded:: 2019.2.0 Return the merge diff, as text, after merging the merge config into the configuration source requested (without loading the config on the device). source: ``running`` The configuration type to retrieve from the network device. Default: ``running``. Available opti...
def config_merge_diff(source='running', merge_config=None, merge_path=None, saltenv='base'): ''' .. versionadded:: 2019.2.0 Return the merge diff, as text, after merging the merge config into the configuration source requested (without l...
.. versionadded:: 2019.2.0 Return the diff, as Python dictionary, between two different sources. The sources can be either specified using the ``source1`` and ``source2`` arguments when retrieving from the managed network device. source1: ``candidate`` The source from where to retrieve the con...
def config_diff_tree(source1='candidate', candidate_path=None, source2='running', running_path=None): ''' .. versionadded:: 2019.2.0 Return the diff, as Python dictionary, between two different sources. The sources can be either specified u...
.. versionadded:: 2019.2.0 Transfer files and directories from remote network device to the localhost of the Minion. .. note:: This function is only available only when the underlying library `scp <https://github.com/jbardin/scp.py>`_ is installed. See :mod:`scp module <sal...
def scp_get(remote_path, local_path='', recursive=False, preserve_times=False, **kwargs): ''' .. versionadded:: 2019.2.0 Transfer files and directories from remote network device to the localhost of the Minion. .. note:: This function is only...
.. versionadded:: 2019.2.0 Transfer files and directories to remote network device. .. note:: This function is only available only when the underlying library `scp <https://github.com/jbardin/scp.py>`_ is installed. See :mod:`scp module <salt.modules.scp_mod>` for more ...
def scp_put(files, remote_path=None, recursive=False, preserve_times=False, saltenv='base', **kwargs): ''' .. versionadded:: 2019.2.0 Transfer files and directories to remote network device. .. note:: This function is only available o...
Return configuration
def _get_config(**kwargs): ''' Return configuration ''' config = { 'box_type': 'sealedbox', 'sk': None, 'sk_file': os.path.join(kwargs['opts'].get('pki_dir'), 'master/nacl'), 'pk': None, 'pk_file': os.path.join(kwargs['opts'].get('pki_dir'), 'master/nacl.pub'), ...
Return sk
def _get_sk(**kwargs): ''' Return sk ''' config = _get_config(**kwargs) key = salt.utils.stringutils.to_str(config['sk']) sk_file = config['sk_file'] if not key and sk_file: with salt.utils.files.fopen(sk_file, 'rb') as keyf: key = salt.utils.stringutils.to_unicode(keyf.r...
Return pk
def _get_pk(**kwargs): ''' Return pk ''' config = _get_config(**kwargs) pubkey = salt.utils.stringutils.to_str(config['pk']) pk_file = config['pk_file'] if not pubkey and pk_file: with salt.utils.files.fopen(pk_file, 'rb') as keyf: pubkey = salt.utils.stringutils.to_unico...
Use libnacl to generate a keypair. If no `sk_file` is defined return a keypair. If only the `sk_file` is defined `pk_file` will use the same name with a postfix `.pub`. When the `sk_file` is already existing, but `pk_file` is not. The `pk_file` will be generated using the `sk_file`. CLI Examples...
def keygen(sk_file=None, pk_file=None, **kwargs): ''' Use libnacl to generate a keypair. If no `sk_file` is defined return a keypair. If only the `sk_file` is defined `pk_file` will use the same name with a postfix `.pub`. When the `sk_file` is already existing, but `pk_file` is not. The `pk_file...
This is a helper function to encrypt a file and return its contents. You can provide an optional output file using `out` `name` can be a local file or when not using `salt-run` can be a url like `salt://`, `https://` etc. CLI Examples: .. code-block:: bash salt-run nacl.enc_file name=/tmp/i...
def enc_file(name, out=None, **kwargs): ''' This is a helper function to encrypt a file and return its contents. You can provide an optional output file using `out` `name` can be a local file or when not using `salt-run` can be a url like `salt://`, `https://` etc. CLI Examples: .. code-bloc...
Alias to `{box_type}_decrypt` box_type: secretbox, sealedbox(default)
def dec(data, **kwargs): ''' Alias to `{box_type}_decrypt` box_type: secretbox, sealedbox(default) ''' if 'keyfile' in kwargs: salt.utils.versions.warn_until( 'Neon', 'The \'keyfile\' argument has been deprecated and will be removed in Salt ' '{version}. ...
Encrypt data using a public key generated from `nacl.keygen`. The encryptd data can be decrypted using `nacl.sealedbox_decrypt` only with the secret key. CLI Examples: .. code-block:: bash salt-run nacl.sealedbox_encrypt datatoenc salt-call --local nacl.sealedbox_encrypt datatoenc pk_file...
def sealedbox_encrypt(data, **kwargs): ''' Encrypt data using a public key generated from `nacl.keygen`. The encryptd data can be decrypted using `nacl.sealedbox_decrypt` only with the secret key. CLI Examples: .. code-block:: bash salt-run nacl.sealedbox_encrypt datatoenc salt-ca...
Decrypt data using a secret key that was encrypted using a public key with `nacl.sealedbox_encrypt`. CLI Examples: .. code-block:: bash salt-call nacl.sealedbox_decrypt pEXHQM6cuaF7A= salt-call --local nacl.sealedbox_decrypt data='pEXHQM6cuaF7A=' sk_file=/etc/salt/pki/master/nacl salt...
def sealedbox_decrypt(data, **kwargs): ''' Decrypt data using a secret key that was encrypted using a public key with `nacl.sealedbox_encrypt`. CLI Examples: .. code-block:: bash salt-call nacl.sealedbox_decrypt pEXHQM6cuaF7A= salt-call --local nacl.sealedbox_decrypt data='pEXHQM6cuaF...
Encrypt data using a secret key generated from `nacl.keygen`. The same secret key can be used to decrypt the data using `nacl.secretbox_decrypt`. CLI Examples: .. code-block:: bash salt-run nacl.secretbox_encrypt datatoenc salt-call --local nacl.secretbox_encrypt datatoenc sk_file=/etc/sa...
def secretbox_encrypt(data, **kwargs): ''' Encrypt data using a secret key generated from `nacl.keygen`. The same secret key can be used to decrypt the data using `nacl.secretbox_decrypt`. CLI Examples: .. code-block:: bash salt-run nacl.secretbox_encrypt datatoenc salt-call --loc...
Decrypt data that was encrypted using `nacl.secretbox_encrypt` using the secret key that was generated from `nacl.keygen`. CLI Examples: .. code-block:: bash salt-call nacl.secretbox_decrypt pEXHQM6cuaF7A= salt-call --local nacl.secretbox_decrypt data='pEXHQM6cuaF7A=' sk_file=/etc/salt/pk...
def secretbox_decrypt(data, **kwargs): ''' Decrypt data that was encrypted using `nacl.secretbox_encrypt` using the secret key that was generated from `nacl.keygen`. CLI Examples: .. code-block:: bash salt-call nacl.secretbox_decrypt pEXHQM6cuaF7A= salt-call --local nacl.secretbox...
Ensure the grafana dashboard exists and is managed. name Name of the grafana dashboard. base_dashboards_from_pillar A pillar key that contains a list of dashboards to inherit from base_panels_from_pillar A pillar key that contains a list of panels to inherit from base_rows_fr...
def present(name, base_dashboards_from_pillar=None, base_panels_from_pillar=None, base_rows_from_pillar=None, dashboard=None, profile='grafana'): ''' Ensure the grafana dashboard exists and is managed. name Name of the grafana dashboard. ...
Ensure the named grafana dashboard is absent. name Name of the grafana dashboard. profile A pillar key or dict that contains grafana information
def absent(name, profile='grafana'): ''' Ensure the named grafana dashboard is absent. name Name of the grafana dashboard. profile A pillar key or dict that contains grafana information ''' ret = {'name': name, 'result': True, 'comment': '', 'changes': {}} if isinstance(pr...
Return a copy without fields that can differ.
def _cleaned(_dashboard): '''Return a copy without fields that can differ.''' dashboard = copy.deepcopy(_dashboard) for ignored_dashboard_field in _IGNORED_DASHBOARD_FIELDS: dashboard.pop(ignored_dashboard_field, None) for row in dashboard.get('rows', []): for ignored_row_field in _IGNO...
Return a dashboard with properties from parents.
def _inherited_dashboard(dashboard, base_dashboards_from_pillar, ret): '''Return a dashboard with properties from parents.''' base_dashboards = [] for base_dashboard_from_pillar in base_dashboards_from_pillar: base_dashboard = __salt__['pillar.get'](base_dashboard_from_pillar) if base_dashbo...
Return a row with properties from parents.
def _inherited_row(row, base_rows_from_pillar, ret): '''Return a row with properties from parents.''' base_rows = [] for base_row_from_pillar in base_rows_from_pillar: base_row = __salt__['pillar.get'](base_row_from_pillar) if base_row: base_rows.append(base_row) elif bas...
Return a panel with properties from parents.
def _inherited_panel(panel, base_panels_from_pillar, ret): '''Return a panel with properties from parents.''' base_panels = [] for base_panel_from_pillar in base_panels_from_pillar: base_panel = __salt__['pillar.get'](base_panel_from_pillar) if base_panel: base_panels.append(base...
Adjust panel spans to take up the available width. For each group of panels that would be laid out on the same level, scale up the unspecified panel spans to fill up the level.
def _auto_adjust_panel_spans(dashboard): '''Adjust panel spans to take up the available width. For each group of panels that would be laid out on the same level, scale up the unspecified panel spans to fill up the level. ''' for row in dashboard.get('rows', []): levels = [] current_...
Pin rows to the top of the dashboard.
def _ensure_pinned_rows(dashboard): '''Pin rows to the top of the dashboard.''' pinned_row_titles = __salt__['pillar.get'](_PINNED_ROWS_PILLAR) if not pinned_row_titles: return pinned_row_titles_lower = [] for title in pinned_row_titles: pinned_row_titles_lower.append(title.lower())...
Assign panels auto-incrementing IDs.
def _ensure_panel_ids(dashboard): '''Assign panels auto-incrementing IDs.''' panel_id = 1 for row in dashboard.get('rows', []): for panel in row.get('panels', []): panel['id'] = panel_id panel_id += 1
Explode annotation_tags into annotations.
def _ensure_annotations(dashboard): '''Explode annotation_tags into annotations.''' if 'annotation_tags' not in dashboard: return tags = dashboard['annotation_tags'] annotations = { 'enable': True, 'list': [], } for tag in tags: annotations['list'].append({ ...
Get a specific dashboard.
def _get(url, profile): '''Get a specific dashboard.''' request_url = "{0}/api/dashboards/{1}".format(profile.get('grafana_url'), url) response = requests.get( request_url, headers={ "Accept": "application/json", "Auth...
Delete a specific dashboard.
def _delete(url, profile): '''Delete a specific dashboard.''' request_url = "{0}/api/dashboards/{1}".format(profile.get('grafana_url'), url) response = requests.delete( request_url, headers={ "Accept": "application/json", ...
Update a specific dashboard.
def _update(dashboard, profile): '''Update a specific dashboard.''' payload = { 'dashboard': dashboard, 'overwrite': True } request_url = "{0}/api/dashboards/db".format(profile.get('grafana_url')) response = requests.post( request_url, headers={ "Authoriza...
Return a dictionary of changes between dashboards.
def _dashboard_diff(_new_dashboard, _old_dashboard): '''Return a dictionary of changes between dashboards.''' diff = {} # Dashboard diff new_dashboard = copy.deepcopy(_new_dashboard) old_dashboard = copy.deepcopy(_old_dashboard) dashboard_diff = DictDiffer(new_dashboard, old_dashboard) diff...
Strip falsey entries.
def _stripped(d): '''Strip falsey entries.''' ret = {} for k, v in six.iteritems(d): if v: ret[k] = v return ret
Given an email address, checks the local cache if corresponding email address: channel_id mapping exists email Email escalation policy profile A dict of telemetry config information.
def _retrieve_channel_id(email, profile='telemetry'): ''' Given an email address, checks the local cache if corresponding email address: channel_id mapping exists email Email escalation policy profile A dict of telemetry config information. ''' key = "telemetry.channels"...
Get all alert definitions associated with a given deployment or if metric_name is specified, obtain the specific alert config Returns dictionary or list of dictionaries. CLI Example: salt myminion telemetry.get_alert_config rs-ds033197 currentConnections profile=telemetry salt myminion te...
def get_alert_config(deployment_id, metric_name=None, api_key=None, profile="telemetry"): ''' Get all alert definitions associated with a given deployment or if metric_name is specified, obtain the specific alert config Returns dictionary or list of dictionaries. CLI Example: salt myminio...
Given an email address, creates a notification-channels if one is not found and also returns the corresponding notification channel id. notify_channel Email escalation policy profile A dict of telemetry config information. CLI Example: salt myminion telemetry.get_notificat...
def get_notification_channel_id(notify_channel, profile="telemetry"): ''' Given an email address, creates a notification-channels if one is not found and also returns the corresponding notification channel id. notify_channel Email escalation policy profile A dict of telemetry co...
get all the alarms set up against the current deployment Returns dictionary of alarm information CLI Example: salt myminion telemetry.get_alarms rs-ds033197 profile=telemetry
def get_alarms(deployment_id, profile="telemetry"): ''' get all the alarms set up against the current deployment Returns dictionary of alarm information CLI Example: salt myminion telemetry.get_alarms rs-ds033197 profile=telemetry ''' auth = _auth(profile=profile) try: r...
create an telemetry alarms. data is a dict of alert configuration data. Returns (bool success, str message) tuple. CLI Example: salt myminion telemetry.create_alarm rs-ds033197 {} profile=telemetry
def create_alarm(deployment_id, metric_name, data, api_key=None, profile="telemetry"): ''' create an telemetry alarms. data is a dict of alert configuration data. Returns (bool success, str message) tuple. CLI Example: salt myminion telemetry.create_alarm rs-ds033197 {} profile=telemetry...
update an telemetry alarms. data is a dict of alert configuration data. Returns (bool success, str message) tuple. CLI Example: salt myminion telemetry.update_alarm rs-ds033197 {} profile=telemetry
def update_alarm(deployment_id, metric_name, data, api_key=None, profile="telemetry"): ''' update an telemetry alarms. data is a dict of alert configuration data. Returns (bool success, str message) tuple. CLI Example: salt myminion telemetry.update_alarm rs-ds033197 {} profile=telemetry ...
delete an alert specified by alert_id or if not specified blows away all the alerts in the current deployment. Returns (bool success, str message) tuple. CLI Example: salt myminion telemetry.delete_alarms rs-ds033197 profile=telemetry
def delete_alarms(deployment_id, alert_id=None, metric_name=None, api_key=None, profile='telemetry'): '''delete an alert specified by alert_id or if not specified blows away all the alerts in the current deployment. Returns (bool success, str message) tuple. CLI Example: salt myminion te...
Decompress returned HTTP content depending on the specified encoding. Currently supports identity/none, deflate, and gzip, which should cover 99%+ of the content on the internet.
def __decompressContent(coding, pgctnt): ''' Decompress returned HTTP content depending on the specified encoding. Currently supports identity/none, deflate, and gzip, which should cover 99%+ of the content on the internet. ''' log.trace("Decompressing %s byte content with compression type: %s"...
Query a resource, and decode the return data
def query(url, method='GET', params=None, data=None, data_file=None, header_dict=None, header_list=None, header_file=None, username=None, password=None, auth=None, decode=False, decode_type='auto', ...
Return the location of the ca bundle file. See the following article: http://tinyurl.com/k7rx42a
def get_ca_bundle(opts=None): ''' Return the location of the ca bundle file. See the following article: http://tinyurl.com/k7rx42a ''' if hasattr(get_ca_bundle, '__return_value__'): return get_ca_bundle.__return_value__ if opts is None: opts = {} opts_bundle = opts.get...
Attempt to update the CA bundle file from a URL If not specified, the local location on disk (``target``) will be auto-detected, if possible. If it is not found, then a new location on disk will be created and updated. The default ``source`` is: http://curl.haxx.se/ca/cacert.pem This is ...
def update_ca_bundle( target=None, source=None, opts=None, merge_files=None, ): ''' Attempt to update the CA bundle file from a URL If not specified, the local location on disk (``target``) will be auto-detected, if possible. If it is not found, then a new locati...
Render a template
def _render(template, render, renderer, template_dict, opts): ''' Render a template ''' if render: if template_dict is None: template_dict = {} if not renderer: renderer = opts.get('renderer', 'jinja|yaml') rend = salt.loader.render(opts, {}) black...
Parse the "Set-cookie" header, and return a list of cookies. This function is here because Tornado's HTTPClient doesn't handle cookies.
def parse_cookie_header(header): ''' Parse the "Set-cookie" header, and return a list of cookies. This function is here because Tornado's HTTPClient doesn't handle cookies. ''' attribs = ('expires', 'path', 'domain', 'version', 'httponly', 'secure', 'comment', 'max-age') # Split into cookie(s)...
Make sure no secret fields show up in logs
def sanitize_url(url, hide_fields): ''' Make sure no secret fields show up in logs ''' if isinstance(hide_fields, list): url_comps = splitquery(url) log_url = url_comps[0] if len(url_comps) > 1: log_url += '?' for pair in url_comps[1:]: url_tmp = N...
Recursive function to sanitize each component of the url.
def _sanitize_url_components(comp_list, field): ''' Recursive function to sanitize each component of the url. ''' if not comp_list: return '' elif comp_list[0].startswith('{0}='.format(field)): ret = '{0}=XXXXXXXXXX&'.format(field) comp_list.remove(comp_list[0]) retur...
Retrieves information about a registered nameserver. Returns the following information: - IP Address set for the nameserver - Domain name which was queried - A list of nameservers and their statuses sld SLD of the domain name tld TLD of the domain name nameserver ...
def get_info(sld, tld, nameserver): ''' Retrieves information about a registered nameserver. Returns the following information: - IP Address set for the nameserver - Domain name which was queried - A list of nameservers and their statuses sld SLD of the domain name tld ...
Deletes a nameserver. Returns ``True`` if the nameserver was updated successfully. sld SLD of the domain name tld TLD of the domain name nameserver Nameserver to create old_ip Current ip address new_ip New ip address CLI Example: .. code-blo...
def update(sld, tld, nameserver, old_ip, new_ip): ''' Deletes a nameserver. Returns ``True`` if the nameserver was updated successfully. sld SLD of the domain name tld TLD of the domain name nameserver Nameserver to create old_ip Current ip address ne...
Creates a new nameserver. Returns ``True`` if the nameserver was created successfully. sld SLD of the domain name tld TLD of the domain name nameserver Nameserver to create ip Nameserver IP address CLI Example: .. code-block:: bash salt '*' name...
def create(sld, tld, nameserver, ip): ''' Creates a new nameserver. Returns ``True`` if the nameserver was created successfully. sld SLD of the domain name tld TLD of the domain name nameserver Nameserver to create ip Nameserver IP address CLI Example...
Deletes a nameserver. Returns ``True`` if the nameserver was deleted successfully sld SLD of the domain name tld TLD of the domain name nameserver Nameserver to delete CLI Example: .. code-block:: bash salt '*' namecheap_domains_ns.delete sld tld nameserver
def delete(sld, tld, nameserver): ''' Deletes a nameserver. Returns ``True`` if the nameserver was deleted successfully sld SLD of the domain name tld TLD of the domain name nameserver Nameserver to delete CLI Example: .. code-block:: bash salt '*' n...
Shows installed version of dnsmasq. CLI Example: .. code-block:: bash salt '*' dnsmasq.version
def version(): ''' Shows installed version of dnsmasq. CLI Example: .. code-block:: bash salt '*' dnsmasq.version ''' cmd = 'dnsmasq -v' out = __salt__['cmd.run'](cmd).splitlines() comps = out[0].split() return comps[2]
Shows installed version of dnsmasq and compile options. CLI Example: .. code-block:: bash salt '*' dnsmasq.fullversion
def fullversion(): ''' Shows installed version of dnsmasq and compile options. CLI Example: .. code-block:: bash salt '*' dnsmasq.fullversion ''' cmd = 'dnsmasq -v' out = __salt__['cmd.run'](cmd).splitlines() comps = out[0].split() version_num = comps[2] comps = out[1]...
Sets a value or a set of values in the specified file. By default, if conf-dir is configured in this file, salt will attempt to set the option in any file inside the conf-dir where it has already been enabled. If it does not find it inside any files, it will append it to the main config file. Setting fo...
def set_config(config_file='/etc/dnsmasq.conf', follow=True, **kwargs): ''' Sets a value or a set of values in the specified file. By default, if conf-dir is configured in this file, salt will attempt to set the option in any file inside the conf-dir where it has already been enabled. If it does not...
Dumps all options from the config file. config_file The location of the config file from which to obtain contents. Defaults to ``/etc/dnsmasq.conf``. CLI Examples: .. code-block:: bash salt '*' dnsmasq.get_config salt '*' dnsmasq.get_config config_file=/etc/dnsmasq.conf
def get_config(config_file='/etc/dnsmasq.conf'): ''' Dumps all options from the config file. config_file The location of the config file from which to obtain contents. Defaults to ``/etc/dnsmasq.conf``. CLI Examples: .. code-block:: bash salt '*' dnsmasq.get_config ...
Generic function for parsing dnsmasq files including includes.
def _parse_dnamasq(filename): ''' Generic function for parsing dnsmasq files including includes. ''' fileopts = {} if not os.path.isfile(filename): raise CommandExecutionError( 'Error: No such file \'{0}\''.format(filename) ) with salt.utils.files.fopen(filename, 'r...
Read in the dict structure generated by the salt key API methods and print the structure.
def output(data, **kwargs): # pylint: disable=unused-argument ''' Read in the dict structure generated by the salt key API methods and print the structure. ''' color = salt.utils.color.get_colors( __opts__.get('color'), __opts__.get('color_theme')) strip_colors = __opts_...
Get a boto connection to SQS.
def _get_sqs_conn(profile, region=None, key=None, keyid=None): ''' Get a boto connection to SQS. ''' if profile: if isinstance(profile, six.string_types): _profile = __opts__[profile] elif isinstance(profile, dict): _profile = profile key = _profile.get('k...
Listen to sqs and fire message on event bus
def start(queue, profile=None, tag='salt/engine/sqs', owner_acct_id=None): ''' Listen to sqs and fire message on event bus ''' if __opts__.get('__role') == 'master': fire_master = salt.utils.event.get_master_event( __opts__, __opts__['sock_dir'], listen=False)...
Transfer a directory down
def get_dir(path, dest, saltenv='base'): ''' Transfer a directory down ''' src = __context__['fileclient'].cache_dir( path, saltenv, cachedir=os.path.join('salt-ssh', __salt__.kwargs['id_'])) src = ' '.join(src) single = salt.client.ssh.Single( __opts__, ...
Send a file from the master to the location in specified .. note:: gzip compression is not supported in the salt-ssh version of cp.get_file. The argument is only accepted for interface compatibility.
def get_file(path, dest, saltenv='base', makedirs=False, template=None, gzip=None): ''' Send a file from the master to the location in specified .. note:: gzip compression is not supported in the salt-ssh version of cp.get_fi...
Freeze python types by turning them into immutable structures.
def freeze(obj): ''' Freeze python types by turning them into immutable structures. ''' if isinstance(obj, dict): return ImmutableDict(obj) if isinstance(obj, list): return ImmutableList(obj) if isinstance(obj, set): return ImmutableSet(obj) return obj
Display alternatives settings for defined command name CLI Example: .. code-block:: bash salt '*' alternatives.display editor
def display(name): ''' Display alternatives settings for defined command name CLI Example: .. code-block:: bash salt '*' alternatives.display editor ''' cmd = [_get_cmd(), '--display', name] out = __salt__['cmd.run_all'](cmd, python_shell=False) if out['retcode'] > 0 and out['...
Display master link for the alternative .. versionadded:: 2015.8.13,2016.3.4,2016.11.0 CLI Example: .. code-block:: bash salt '*' alternatives.show_link editor
def show_link(name): ''' Display master link for the alternative .. versionadded:: 2015.8.13,2016.3.4,2016.11.0 CLI Example: .. code-block:: bash salt '*' alternatives.show_link editor ''' if __grains__['os_family'] == 'RedHat': path = '/var/lib/' elif __grains__['os...
Check if the given path is an alternative for a name. .. versionadded:: 2015.8.4 CLI Example: .. code-block:: bash salt '*' alternatives.check_exists name path
def check_exists(name, path): ''' Check if the given path is an alternative for a name. .. versionadded:: 2015.8.4 CLI Example: .. code-block:: bash salt '*' alternatives.check_exists name path ''' cmd = [_get_cmd(), '--display', name] out = __salt__['cmd.run_all'](cmd, pytho...
Install symbolic links determining default commands CLI Example: .. code-block:: bash salt '*' alternatives.install editor /usr/bin/editor /usr/bin/emacs23 50
def install(name, link, path, priority): ''' Install symbolic links determining default commands CLI Example: .. code-block:: bash salt '*' alternatives.install editor /usr/bin/editor /usr/bin/emacs23 50 ''' cmd = [_get_cmd(), '--install', link, name, path, six.text_type(priority)] ...
Remove symbolic links determining the default commands. CLI Example: .. code-block:: bash salt '*' alternatives.remove name path
def remove(name, path): ''' Remove symbolic links determining the default commands. CLI Example: .. code-block:: bash salt '*' alternatives.remove name path ''' cmd = [_get_cmd(), '--remove', name, path] out = __salt__['cmd.run_all'](cmd, python_shell=False) if out['retcode'] ...