Exemple #1
0
def add_config(lines, **kwargs):
    """
    Add one or more config lines to the NX-OS device running config.

    lines
        Configuration lines to add

    save_config
        If False, don't save configuration commands to startup configuration.
        If True, save configuration to startup configuration.
        Default: True

    .. code-block:: bash

        salt '*' nxos.add_config 'snmp-server community TESTSTRINGHERE group network-operator'

    .. note::
        For more than one config added per command, lines should be a list.
    """
    warn_until(
        "Argon",
        "'nxos.add_config lines' is deprecated in favor of 'nxos.config commands'",
    )

    kwargs = clean_kwargs(**kwargs)
    return config(lines, **kwargs)
Exemple #2
0
def salt_master():
    """
    Start the salt master.
    """
    import salt.cli.daemons

    # Fix for setuptools generated scripts, so that it will
    # work with multiprocessing fork emulation.
    # (see multiprocessing.forking.get_preparation_data())
    if __name__ != "__main__":
        sys.modules["__main__"] = sys.modules[__name__]

    # REMOVEME after Python 2.7 support is dropped (also the six import)
    if six.PY2:
        from salt.utils.versions import warn_until

        # Message borrowed from pip's deprecation warning
        warn_until(
            "3001",
            "Python 2.7 will reach the end of its life on January 1st,"
            " 2020. Please upgrade your Python as Python 2.7 won't be"
            " maintained after that date.  Salt will drop support for"
            " Python 2.7 in the 3001 release or later.",
        )
    # END REMOVEME
    master = salt.cli.daemons.Master()
    master.start()
Exemple #3
0
    def factory(cls, opts, **kwargs):
        import salt.channel.client

        warn_until(
            "Argon",
            "This module is deprecated. Please use salt.channel.client instead.",
        )
        return salt.channel.client.AsyncPubChannel.factory(opts, **kwargs)
Exemple #4
0
def system_info(**kwargs):
    """
    Return system information for grains of the minion.

    .. code-block:: bash

        salt '*' nxos.system_info
    """
    warn_until("Argon", "'nxos.system_info' is deprecated in favor of 'nxos.grains'")
    return salt.utils.nxos.system_info(show_ver(**kwargs))["nxos"]
Exemple #5
0
    def factory(opts, **kwargs):
        """
        If we have additional IPC transports other than UXD and TCP, add them here
        """
        import salt.channel.client

        warn_until(
            "Argon",
            "This module is deprecated. Please use salt.channel.client instead.",
        )
        return salt.channel.client.AsyncPullChannel.factory(opts, **kwargs)
Exemple #6
0
def show(commands, raw_text=True, **kwargs):
    """
    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.
        NOTE: raw_text option is ignored for SSH proxy minion.  Data is
        returned unstructured.

    CLI Example:

    .. code-block:: bash

        salt-call --local nxos.show 'show version'
        salt '*' nxos.show 'show bgp sessions ; show processes' raw_text=False
        salt 'regular-minion' nxos.show 'show interfaces' host=sw01.example.com username=test password=test
    """
    warn_until(
        "Argon",
        "'nxos.show commands' is deprecated in favor of 'nxos.sendline commands'",
    )

    if not isinstance(raw_text, bool):
        msg = """
        INPUT ERROR: Second argument 'raw_text' must be either True or False
        Value passed: {}
        Hint: White space separated show commands should be wrapped by double quotes
        """.format(
            raw_text
        )
        return msg

    if raw_text:
        method = "cli_show_ascii"
    else:
        method = "cli_show"

    response_list = sendline(commands, method, **kwargs)
    if isinstance(response_list, list):
        ret = [response for response in response_list if response]
        if not ret:
            ret = [""]
        return ret
    else:
        return response_list
Exemple #7
0
def salt_master():
    '''
    Start the salt master.
    '''
    import salt.cli.daemons
    # REMOVEME after Python 2.7 support is dropped (also the six import)
    if six.PY2:
        from salt.utils.versions import warn_until
        # Message borrowed from pip's deprecation warning
        warn_until(
            'Sodium',
            'Python 2.7 will reach the end of its life on January 1st,'
            ' 2020. Please upgrade your Python as Python 2.7 won\'t be'
            ' maintained after that date.  Salt will drop support for'
            ' Python 2.7 in the Sodium release or later.')


# END REMOVEME
    master = salt.cli.daemons.Master()
    master.start()
Exemple #8
0
def cmd(command, *args, **kwargs):
    """
    NOTE: This function is preserved for backwards compatibility.  This allows
    commands to be executed using either of the following syntactic forms.

    salt '*' nxos.cmd <function>

    or

    salt '*' nxos.<function>

    command
        function from `salt.modules.nxos` to run

    args
        positional args to pass to `command` function

    kwargs
        key word arguments to pass to `command` function

    .. code-block:: bash

        salt '*' nxos.cmd sendline 'show ver'
        salt '*' nxos.cmd show_run
        salt '*' nxos.cmd check_password username=admin password='******' encrypted=True
    """
    warn_until(
        "Phosphorus", "'nxos.cmd COMMAND' is deprecated in favor of 'nxos.COMMAND'"
    )

    for k in list(kwargs):
        if k.startswith("__pub_"):
            kwargs.pop(k)
    local_command = ".".join(["nxos", command])
    log.info("local command: %s", local_command)
    if local_command not in __salt__:
        return False
    return __salt__[local_command](*args, **kwargs)
Exemple #9
0
def salt_minion():
    """
    Start the salt minion in a subprocess.
    Auto restart minion on error.
    """
    import signal

    import salt.utils.platform
    import salt.utils.process

    salt.utils.process.notify_systemd()

    import salt.cli.daemons
    import multiprocessing

    # Fix for setuptools generated scripts, so that it will
    # work with multiprocessing fork emulation.
    # (see multiprocessing.forking.get_preparation_data())
    if __name__ != "__main__":
        sys.modules["__main__"] = sys.modules[__name__]

    if "" in sys.path:
        sys.path.remove("")

    if salt.utils.platform.is_windows():
        minion = salt.cli.daemons.Minion()
        minion.start()
        return
    # REMOVEME after Python 2.7 support is dropped (also the six import)
    elif six.PY2:
        from salt.utils.versions import warn_until

        # Message borrowed from pip's deprecation warning
        warn_until(
            "3001",
            "Python 2.7 will reach the end of its life on January 1st,"
            " 2020. Please upgrade your Python as Python 2.7 won't be"
            " maintained after that date.  Salt will drop support for"
            " Python 2.7 in the 3001 release or later.",
        )
    # END REMOVEME

    if "--disable-keepalive" in sys.argv:
        sys.argv.remove("--disable-keepalive")
        minion = salt.cli.daemons.Minion()
        minion.start()
        return

    def escalate_signal_to_process(pid, signum, sigframe):  # pylint: disable=unused-argument
        """
        Escalate the signal received to the multiprocessing process that
        is actually running the minion
        """
        # escalate signal
        os.kill(pid, signum)

    # keep one minion subprocess running
    prev_sigint_handler = signal.getsignal(signal.SIGINT)
    prev_sigterm_handler = signal.getsignal(signal.SIGTERM)
    while True:
        try:
            process = multiprocessing.Process(target=minion_process)
            process.start()
            signal.signal(
                signal.SIGTERM,
                functools.partial(escalate_signal_to_process, process.pid),
            )
            signal.signal(
                signal.SIGINT,
                functools.partial(escalate_signal_to_process, process.pid),
            )
            signal.signal(
                signal.SIGHUP,
                functools.partial(escalate_signal_to_process, process.pid),
            )
        except Exception:  # pylint: disable=broad-except
            # if multiprocessing does not work
            minion = salt.cli.daemons.Minion()
            minion.start()
            break

        process.join()

        # Process exited or was terminated. Since we're going to try to restart
        # it, we MUST, reset signal handling to the previous handlers
        signal.signal(signal.SIGINT, prev_sigint_handler)
        signal.signal(signal.SIGTERM, prev_sigterm_handler)

        if not process.exitcode == salt.defaults.exitcodes.SALT_KEEPALIVE:
            sys.exit(process.exitcode)
        # ontop of the random_reauth_delay already preformed
        # delay extra to reduce flooding and free resources
        # NOTE: values are static but should be fine.
        time.sleep(2 + randint(1, 10))
        # need to reset logging because new minion objects
        # cause extra log handlers to accumulate
        rlogger = logging.getLogger()
        for handler in rlogger.handlers:
            rlogger.removeHandler(handler)
        logging.basicConfig()