コード例 #1
0
ファイル: mine.py プロジェクト: mamh-mixed/saltstack-salt
def get(tgt, fun, tgt_type="glob", roster="flat"):
    """
    Get data from the mine based on the target, function and tgt_type

    This will actually run the function on all targeted minions (like
    publish.publish), as salt-ssh clients can't update the mine themselves.

    We will look for mine_functions in the roster, pillar, and master config,
    in that order, looking for a match for the defined function

    Targets can be matched based on any standard matching system that can be
    matched on the defined roster (in salt-ssh) via these keywords::

    CLI Example:

    .. code-block:: bash

        salt-ssh '*' mine.get '*' network.interfaces
        salt-ssh '*' mine.get 'myminion' network.interfaces roster=flat
        salt-ssh '*' mine.get '192.168.5.0' network.ipaddrs roster=scan
    """
    # Set up opts for the SSH object
    opts = copy.deepcopy(__context__["master_opts"])
    minopts = copy.deepcopy(__opts__)
    opts.update(minopts)
    if roster:
        opts["roster"] = roster
    opts["argv"] = [fun]
    opts["selected_target_option"] = tgt_type
    opts["tgt"] = tgt
    opts["arg"] = []

    # Create the SSH object to handle the actual call
    ssh = salt.client.ssh.SSH(opts)

    # Run salt-ssh to get the minion returns
    rets = {}
    for ret in ssh.run_iter(mine=True):
        rets.update(ret)

    cret = {}
    for host in rets:
        if "return" in rets[host]:
            cret[host] = rets[host]["return"]
        else:
            cret[host] = rets[host]
    return cret
コード例 #2
0
ファイル: client.py プロジェクト: whytewolf/salt
    def cmd_iter(self,
                 tgt,
                 fun,
                 arg=(),
                 timeout=None,
                 tgt_type="glob",
                 ret="",
                 kwarg=None,
                 **kwargs):
        """
        Execute a single command via the salt-ssh subsystem and return a
        generator

        .. versionadded:: 2015.5.0
        """
        ssh = self._prep_ssh(tgt, fun, arg, timeout, tgt_type, kwarg, **kwargs)
        yield from ssh.run_iter(jid=kwargs.get("jid", None))
コード例 #3
0
ファイル: mine.py プロジェクト: zsjohny/salt
def get(tgt, fun, expr_form='glob', roster='flat'):
    '''
    Get data from the mine based on the target, function and expr_form

    This will actually run the function on all targeted minions (like
    publish.publish), as salt-ssh clients can't update the mine themselves.

    We will look for mine_functions in the roster, pillar, and master config,
    in that order, looking for a match for the defined function

    Targets can be matched based on any standard matching system that can be
    matched on the defined roster (in salt-ssh) via these keywords::

    CLI Example:

    .. code-block:: bash

        salt-ssh '*' mine.get '*' network.interfaces
        salt-ssh '*' mine.get 'myminion' network.interfaces roster=flat
        salt-ssh '*' mine.get '192.168.5.0' network.ipaddrs roster=scan
    '''
    # Set up opts for the SSH object
    opts = copy.deepcopy(__opts__)
    if roster:
        opts['roster'] = roster
    opts['argv'] = [fun]
    opts['selected_target_option'] = expr_form
    opts['tgt'] = tgt
    opts['arg'] = []

    # Create the SSH object to handle the actual call
    ssh = salt.client.ssh.SSH(opts)

    # Run salt-ssh to get the minion returns
    rets = {}
    for ret in ssh.run_iter(mine=True):
        rets.update(ret)

    cret = {}
    for host in rets:
        if 'return' in rets[host]:
            cret[host] = rets[host]['return']
        else:
            cret[host] = rets[host]
    return cret
コード例 #4
0
ファイル: mine.py プロジェクト: DaveQB/salt
def get(tgt, fun, expr_form='glob', roster='flat'):
    '''
    Get data from the mine based on the target, function and expr_form

    This will actually run the function on all targeted minions (like
    publish.publish), as salt-ssh clients can't update the mine themselves.

    We will look for mine_functions in the roster, pillar, and master config,
    in that order, looking for a match for the defined function

    Targets can be matched based on any standard matching system that can be
    matched on the defined roster (in salt-ssh) via these keywords::

    CLI Example:

    .. code-block:: bash

        salt-ssh '*' mine.get '*' network.interfaces
        salt-ssh '*' mine.get 'myminion' network.interfaces roster=flat
        salt-ssh '*' mine.get '192.168.5.0' network.ipaddrs roster=scan
    '''
    # Set up opts for the SSH object
    opts = copy.deepcopy(__opts__)
    if roster:
        opts['roster'] = roster
    opts['argv'] = [fun]
    opts['selected_target_option'] = expr_form
    opts['tgt'] = tgt
    opts['arg'] = []

    # Create the SSH object to handle the actual call
    ssh = salt.client.ssh.SSH(opts)

    # Run salt-ssh to get the minion returns
    rets = {}
    for ret in ssh.run_iter(mine=True):
        rets.update(ret)

    cret = {}
    for host in rets:
        if 'return' in rets[host]:
            cret[host] = rets[host]['return']
        else:
            cret[host] = rets[host]
    return cret
コード例 #5
0
ファイル: client.py プロジェクト: whytewolf/salt
    def cmd(self,
            tgt,
            fun,
            arg=(),
            timeout=None,
            tgt_type="glob",
            kwarg=None,
            **kwargs):
        """
        Execute a single command via the salt-ssh subsystem and return all
        routines at once

        .. versionadded:: 2015.5.0
        """
        ssh = self._prep_ssh(tgt, fun, arg, timeout, tgt_type, kwarg, **kwargs)
        final = {}
        for ret in ssh.run_iter(jid=kwargs.get("jid", None)):
            final.update(ret)
        return final
コード例 #6
0
ファイル: publish.py プロジェクト: thepauleh/salt
def _publish(tgt,
             fun,
             arg=None,
             expr_form='glob',
             returner='',
             timeout=None,
             form='clean',
             roster=None):
    '''
    Publish a command "from the minion out to other minions". In reality, the
    minion does not execute this function, it is executed by the master. Thus,
    no access control is enabled, as minions cannot initiate publishes
    themselves.

    Salt-ssh publishes will default to whichever roster was used for the
    initiating salt-ssh call, and can be overridden using the ``roster``
    argument

    Returners are not currently supported

    The arguments sent to the minion publish function are separated with
    commas. This means that for a minion executing a command with multiple
    args it will look like this::

        salt-ssh system.example.com publish.publish '*' user.add 'foo,1020,1020'

    CLI Example:

    .. code-block:: bash

        salt-ssh system.example.com publish.publish '*' cmd.run 'ls -la /tmp'
    '''
    if fun.startswith('publish.'):
        log.info('Cannot publish publish calls. Returning {}')
        return {}

    # TODO: implement returners? Do they make sense for salt-ssh calls?
    if returner:
        log.warning('Returners currently not supported in salt-ssh publish')

    # Make sure args have been processed
    if arg is None:
        arg = []
    elif not isinstance(arg, list):
        arg = [salt.utils.args.yamlify_arg(arg)]
    else:
        arg = [salt.utils.args.yamlify_arg(x) for x in arg]
    if len(arg) == 1 and arg[0] is None:
        arg = []

    # Set up opts for the SSH object
    opts = copy.deepcopy(__opts__)
    if roster:
        opts['roster'] = roster
    if timeout:
        opts['timeout'] = timeout
    opts['argv'] = [fun] + arg
    opts['selected_target_option'] = expr_form
    opts['tgt'] = tgt
    opts['arg'] = arg

    # Create the SSH object to handle the actual call
    ssh = salt.client.ssh.SSH(opts)

    # Run salt-ssh to get the minion returns
    rets = {}
    for ret in ssh.run_iter():
        rets.update(ret)

    if form == 'clean':
        cret = {}
        for host in rets:
            if 'return' in rets[host]:
                cret[host] = rets[host]['return']
            else:
                cret[host] = rets[host]
        return cret
    else:
        return rets
コード例 #7
0
ファイル: publish.py プロジェクト: qzchenwl/saltstack-verify
def _publish(tgt,
             fun,
             arg=None,
             expr_form='glob',
             returner='',
             timeout=None,
             form='clean',
             roster=None):
    '''
    Publish a command "from the minion out to other minions". In reality, the
    minion does not execute this function, it is executed by the master. Thus,
    no access control is enabled, as minions cannot initiate publishes
    themselves.

    Salt-ssh publishes will default to whichever roster was used for the
    initiating salt-ssh call, and can be overridden using the ``roster``
    argument

    Returners are not currently supported

    The arguments sent to the minion publish function are separated with
    commas. This means that for a minion executing a command with multiple
    args it will look like this::

        salt-ssh system.example.com publish.publish '*' user.add 'foo,1020,1020'

    CLI Example:

    .. code-block:: bash

        salt-ssh system.example.com publish.publish '*' cmd.run 'ls -la /tmp'
    '''
    if fun.startswith('publish.'):
        log.info('Cannot publish publish calls. Returning {}')
        return {}

    # TODO: implement returners? Do they make sense for salt-ssh calls?
    if returner:
        log.warning('Returners currently not supported in salt-ssh publish')

    # Make sure args have been processed
    if arg is None:
        arg = []
    elif not isinstance(arg, list):
        arg = [salt.utils.args.yamlify_arg(arg)]
    else:
        arg = [salt.utils.args.yamlify_arg(x) for x in arg]
    if len(arg) == 1 and arg[0] is None:
        arg = []

    # Set up opts for the SSH object
    opts = copy.deepcopy(__opts__)
    if roster:
        opts['roster'] = roster
    if timeout:
        opts['timeout'] = timeout
    opts['argv'] = [fun] + arg
    opts['selected_target_option'] = expr_form
    opts['tgt'] = tgt
    opts['arg'] = arg

    # Create the SSH object to handle the actual call
    ssh = salt.client.ssh.SSH(opts)

    # Run salt-ssh to get the minion returns
    rets = {}
    for ret in ssh.run_iter():
        rets.update(ret)

    if form == 'clean':
        cret = {}
        for host in rets:
            if 'return' in rets[host]:
                cret[host] = rets[host]['return']
            else:
                cret[host] = rets[host]
        return cret
    else:
        return rets