示例#1
0
文件: corosync.py 项目: icclab/crmsh
def push_configuration(nodes):
    '''
    Push the local configuration to the list of remote nodes
    '''
    try:
        from psshlib import api as pssh
        _has_pssh = True
    except ImportError:
        _has_pssh = False

    if not _has_pssh:
        raise ValueError("PSSH is required to push")

    local_path = conf()

    opts = pssh.Options()
    opts.timeout = 60
    opts.ssh_options += ['ControlPersist=no']
    ok = True
    for host, result in pssh.copy(nodes,
                                  local_path,
                                  local_path, opts).iteritems():
        if isinstance(result, pssh.Error):
            err_buf.error("Failed to push configuration to %s: %s" % (host, result))
            ok = False
        else:
            err_buf.ok(host)
    return ok
示例#2
0
def push_configuration(nodes):
    '''
    Push the local configuration to the list of remote nodes
    '''
    try:
        from psshlib import api as pssh
        _has_pssh = True
    except ImportError:
        _has_pssh = False

    if not _has_pssh:
        raise ValueError("PSSH is required to push")

    local_path = conf()

    opts = pssh.Options()
    opts.timeout = 60
    opts.ssh_options += ['ControlPersist=no']
    ok = True
    for host, result in pssh.copy(nodes, local_path, local_path,
                                  opts).iteritems():
        if isinstance(result, pssh.Error):
            err_buf.error("Failed to push configuration to %s: %s" %
                          (host, result))
            ok = False
        else:
            err_buf.ok(host)
    return ok
示例#3
0
文件: scripts.py 项目: icclab/crmsh
def _print_debug(local_node, hosts, workdir, opts):
    "Print debug output (if any)"
    dbglog = os.path.join(workdir, 'crm_script.debug')
    for host, result in _pssh_call(hosts,
                                   "[ -f '%s' ] && cat '%s'" % (dbglog, dbglog),
                                   opts).iteritems():
        if isinstance(result, pssh.Error):
            err_buf.error("[%s]: %s" % (host, result))
        else:
            _print_output(host, *result)
    if os.path.isfile(dbglog):
        f = open(dbglog).read()
        err_buf.ok("[%s]: %s" % (local_node, f))
示例#4
0
def _print_debug(local_node, hosts, workdir, opts):
    "Print debug output (if any)"
    dbglog = os.path.join(workdir, 'crm_script.debug')
    for host, result in _pssh_call(
            hosts, "[ -f '%s' ] && cat '%s'" % (dbglog, dbglog),
            opts).iteritems():
        if isinstance(result, pssh.Error):
            err_buf.error("[%s]: %s" % (host, result))
        else:
            _print_output(host, *result)
    if os.path.isfile(dbglog):
        f = open(dbglog).read()
        err_buf.ok("[%s]: %s" % (local_node, f))
示例#5
0
文件: ui_cluster.py 项目: lge/crmsh
    def do_run(self, context, cmd):
        '''
        Execute the given command on all nodes, report outcome
        '''
        try:
            from psshlib import api as pssh
            _has_pssh = True
        except ImportError:
            _has_pssh = False

        if not _has_pssh:
            context.fatal_error("PSSH not found")

        hosts = utils.list_cluster_nodes()
        opts = pssh.Options()
        for host, result in pssh.call(hosts, cmd, opts).iteritems():
            if isinstance(result, pssh.Error):
                err_buf.error("[%s]: %s" % (host, result))
            else:
                if result[0] != 0:
                    err_buf.error("[%s]: rc=%s\n%s\n%s" % (host, result[0], result[1], result[2]))
                else:
                    err_buf.ok("[%s]\n%s" % (host, result[1]))
示例#6
0
文件: corosync.py 项目: lge/crmsh
def push_configuration(nodes):
    '''
    Push the local configuration to the list of remote nodes
    '''
    try:
        import parallax
    except ImportError:
        raise ValueError("parallax is required to push")

    local_path = conf()

    opts = parallax.Options()
    opts.timeout = 60
    opts.ssh_options += ['ControlPersist=no']
    ok = True
    for host, result in parallax.copy(nodes,
                                      local_path,
                                      local_path, opts).iteritems():
        if isinstance(result, parallax.Error):
            err_buf.error("Failed to push configuration to %s: %s" % (host, result))
            ok = False
        else:
            err_buf.ok(host)
    return ok
示例#7
0
    def do_run(self, context, cmd):
        '''
        Execute the given command on all nodes, report outcome
        '''
        try:
            from psshlib import api as pssh
            _has_pssh = True
        except ImportError:
            _has_pssh = False

        if not _has_pssh:
            context.fatal_error("PSSH not found")

        hosts = utils.list_cluster_nodes()
        opts = pssh.Options()
        for host, result in pssh.call(hosts, cmd, opts).iteritems():
            if isinstance(result, pssh.Error):
                err_buf.error("[%s]: %s" % (host, result))
            else:
                if result[0] != 0:
                    err_buf.error("[%s]: rc=%s\n%s\n%s" %
                                  (host, result[0], result[1], result[2]))
                else:
                    err_buf.ok("[%s]\n%s" % (host, result[1]))
示例#8
0
文件: scripts.py 项目: icclab/crmsh
def _print_output(host, rc, out, err):
    "Print the output from a process that ran on host"
    if out:
        err_buf.ok("[%s]: %s" % (host, out))
    if err:
        err_buf.error("[%s]: %s" % (host, err))
示例#9
0
文件: scripts.py 项目: icclab/crmsh
 def ok(self, fmt, *args):
     self.flush()
     err_buf.ok(fmt % args)
示例#10
0
def _print_output(host, rc, out, err):
    "Print the output from a process that ran on host"
    if out:
        err_buf.ok("[%s]: %s" % (host, out))
    if err:
        err_buf.error("[%s]: %s" % (host, err))
示例#11
0
 def ok(self, fmt, *args):
     self.flush()
     err_buf.ok(fmt % args)
示例#12
0
 def do_verify(self, context, name):
     '''
     Verify the given script.
     '''
     if scripts.verify(name):
         err_buf.ok(name)