def do_run(self, context, cmd, node=None): ''' Execute the given command on all nodes/specific node, report outcome ''' try: import parallax _has_parallax = True except ImportError: _has_parallax = False if not _has_parallax: context.fatal_error("python package parallax is needed for this command") hosts = utils.list_cluster_nodes() if node and node in hosts: hosts = [node] opts = parallax.Options() for host, result in parallax.call(hosts, cmd, opts).items(): if isinstance(result, parallax.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], utils.to_ascii(result[1]), utils.to_ascii(result[2]))) else: if not result[1]: err_buf.ok("[%s]" % host) else: err_buf.ok("[%s]\n%s" % (host, utils.to_ascii(result[1])))
def do_run(self, context, cmd): ''' Execute the given command on all nodes, report outcome ''' try: import parallax _has_parallax = True except ImportError: _has_parallax = False if not _has_parallax: context.fatal_error( "python package parallax is needed for this command") hosts = utils.list_cluster_nodes() opts = parallax.Options() for host, result in parallax.call(hosts, cmd, opts).iteritems(): if isinstance(result, parallax.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]))
def run_copy(): try: import parallax except ImportError: crm_script.exit_fail("Command node needs parallax installed") opts = make_opts() has_auth = os.path.isfile(COROSYNC_AUTH) if has_auth: results = parallax.copy(add_nodes, COROSYNC_AUTH, COROSYNC_AUTH, opts) check_results(parallax, results) results = parallax.call( add_nodes, "chown root:root %s;chmod 400 %s" % (COROSYNC_AUTH, COROSYNC_AUTH), opts) check_results(parallax, results) # Add new nodes to corosync.conf before copying for node in add_nodes: rc, _, err = crm_script.call(['crm', 'corosync', 'add-node', node]) if rc != 0: crm_script.exit_fail('Failed to add %s to corosync.conf: %s' % (node, err)) results = parallax.copy(add_nodes, COROSYNC_CONF, COROSYNC_CONF, opts) check_results(parallax, results) # reload corosync config here? rc, _, err = crm_script.call(['crm', 'corosync', 'reload']) if rc != 0: crm_script.exit_fail('Failed to reload corosync configuration: %s' % (err)) crm_script.exit_ok(host)
def testUptime(self): opts = para.Options() opts.default_user = g_user for host, result in para.call(g_hosts, "uptime", opts).items(): if isinstance(result, para.Error): raise result rc, out, err = result self.assertEqual(rc, 0) self.assert_(out.decode("utf8").find("load average") != -1)
def testSimpleCall(self): opts = para.Options() opts.default_user = g_user for host, result in para.call(g_hosts, "ls -l /", opts).items(): if isinstance(result, para.Error): raise result rc, out, err = result self.assertEqual(rc, 0) self.assert_(len(out) > 0)
def run_copy(): try: import parallax except ImportError: crm_script.exit_fail("Command node needs parallax installed") opts = make_opts() results = parallax.copy(others, COROSYNC_AUTH, COROSYNC_AUTH, opts) check_results(parallax, results) results = parallax.call(others, "chown root:root %s;chmod 400 %s" % (COROSYNC_AUTH, COROSYNC_AUTH), opts) check_results(parallax, results)
def run_copy(): try: import parallax as pssh except ImportError: crm_script.exit_fail("Command node needs parallax installed") opts = make_opts() results = pssh.copy(others, COROSYNC_AUTH, COROSYNC_AUTH, opts) check_results(pssh, results) results = pssh.call(others, "chown root:root %s;chmod 400 %s" % (COROSYNC_AUTH, COROSYNC_AUTH), opts) check_results(pssh, results)
def parallax_call(nodes_list, cmd, askpass=False, ssh_options=None): opts = parallax.Options() if ssh_options is None: opts.ssh_options = ['StrictHostKeyChecking=no', 'ConnectTimeout=10'] opts.askpass = askpass if hasattr(opts, 'warn_message'): opts.warn_message = False results = parallax.call(nodes_list, cmd, opts) for host, result in results.items(): if isinstance(result, parallax.Error): raise ValueError("Failed on {}: {}".format(host, result)) return list(results.items())
def do_run(self, context, cmd, *nodes): ''' Execute the given command on all nodes/specific node, report outcome ''' try: import parallax _has_parallax = True except ImportError: _has_parallax = False if not _has_parallax: context.fatal_error( "python package parallax is needed for this command") if nodes: hosts = list(nodes) else: hosts = utils.list_cluster_nodes() if hosts is None: context.fatal_error("failed to get node list from cluster") opts = parallax.Options() opts.ssh_options = ['StrictHostKeyChecking=no'] for host in hosts: res = utils.check_ssh_passwd_need(host) if res: opts.askpass = True break for host, result in parallax.call(hosts, cmd, opts).items(): if isinstance(result, parallax.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], utils.to_ascii( result[1]), utils.to_ascii(result[2]))) else: if not result[1]: err_buf.ok("[%s]" % host) else: err_buf.ok("[%s]\n%s" % (host, utils.to_ascii(result[1])))
def do_run(self, context, cmd): ''' Execute the given command on all nodes, report outcome ''' try: import parallax 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]))
def _pssh_call(hosts, cmd, opts): "pssh.call with debug logging" if config.core.debug or options.regression_tests: err_buf.debug("pssh.call(%s, %s)" % (repr(hosts), cmd)) return pssh.call(hosts, cmd, opts)
def call(self): results = parallax.call(self.nodes, self.cmd, self.opts) return self.handle(list(results.items()))
def testFailingCall(self): opts = para.Options() opts.default_user = g_user for host, result in para.call(g_hosts, "touch /foofoo/barbar/jfikjfdj", opts).items(): self.assert_(isinstance(result, para.Error)) self.assert_(str(result).find('with error code') != -1)