def push_configuration(nodes): ''' Push the local configuration to the list of remote nodes ''' try: import parallax 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
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 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 make_opts(): import parallax as pssh opts = pssh.Options() opts.timeout = 60 opts.recursive = True opts.user = '******' opts.ssh_options += ['PasswordAuthentication=no', 'StrictHostKeyChecking=no', 'ControlPersist=no'] return opts
def prepare(self): opts = parallax.Options() if self.ssh_options is None: self.ssh_options = ['StrictHostKeyChecking=no', 'ConnectTimeout=10'] opts.ssh_options = self.ssh_options opts.askpass = self.askpass # warn_message will available from parallax-1.0.5 if hasattr(opts, 'warn_message'): opts.warn_message = False opts.localdir = self.localdir return opts
def remote_diff_slurp(nodes, filename): try: import parallax except ImportError: raise ValueError("Parallax is required to diff") from . import tmpfiles tmpdir = tmpfiles.create_dir() opts = parallax.Options() opts.localdir = tmpdir dst = os.path.basename(filename) return parallax.slurp(nodes, filename, dst, opts).items()
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 _make_options(params): "Setup pssh options." opts = pssh.Options() opts.timeout = int(params['timeout']) opts.recursive = True opts.ssh_options += [ 'KbdInteractiveAuthentication=no', 'PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey', 'PasswordAuthentication=no', 'StrictHostKeyChecking=no', 'ControlPersist=no' ] if options.regression_tests: opts.ssh_extra += ['-vvv'] return opts
def testCopyFile(self): opts = para.Options() opts.default_user = g_user opts.localdir = self.tmpDir by_host = para.copy(g_hosts, "/etc/hosts", "/tmp/para.test", opts) for host, result in by_host.items(): if isinstance(result, para.Error): raise result rc, _, _ = result self.assertEqual(rc, 0) by_host = para.slurp(g_hosts, "/tmp/para.test", "para.test", opts) for host, result in by_host.items(): if isinstance(result, para.Error): raise result rc, _, _, path = result self.assertEqual(rc, 0) self.assert_(path.endswith('%s/para.test' % (host)))
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 cluster_copy_file(local_path, nodes=None): """ Copies given file to all other cluster nodes. """ try: import parallax except ImportError: raise ValueError("parallax is required to copy cluster files") if not nodes: nodes = list_cluster_nodes() nodes.remove(this_node()) 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 %s to %s: %s" % (local_path, host, result)) ok = False else: err_buf.ok(host) return ok
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)
def _diff_slurp(pssh, nodes, filename): tmpdir = tmpfiles.create_dir() opts = pssh.Options() opts.localdir = tmpdir dst = os.path.basename(filename) return pssh.slurp(nodes, filename, dst, opts).items()