def run_copy(): try: from psshlib import api as pssh except ImportError: crm_script.exit_fail("Command node needs pssh installed") opts = make_opts() has_auth = os.path.isfile(COROSYNC_AUTH) if has_auth: results = pssh.copy(add_nodes, COROSYNC_AUTH, COROSYNC_AUTH, opts) check_results(pssh, results) results = pssh.call( add_nodes, "chown root:root %s;chmod 400 %s" % (COROSYNC_AUTH, COROSYNC_AUTH), opts) check_results(pssh, 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 = pssh.copy(add_nodes, COROSYNC_CONF, COROSYNC_CONF, opts) check_results(pssh, 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 run_copy(): try: from psshlib import api as pssh except ImportError: crm_script.exit_fail("Command node needs pssh installed") opts = make_opts() has_auth = os.path.isfile(COROSYNC_AUTH) if has_auth: results = pssh.copy(add_nodes, COROSYNC_AUTH, COROSYNC_AUTH, opts) check_results(pssh, results) results = pssh.call(add_nodes, "chown root:root %s;chmod 400 %s" % (COROSYNC_AUTH, COROSYNC_AUTH), opts) check_results(pssh, 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 = pssh.copy(add_nodes, COROSYNC_CONF, COROSYNC_CONF, opts) check_results(pssh, 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 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
def run_copy(): try: from psshlib import api as pssh except ImportError: crm_script.exit_fail("Command node needs pssh 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 run_copy(): try: from psshlib import api as pssh except ImportError: crm_script.exit_fail("Command node needs pssh 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 testCopyFile(self): opts = pssh.Options() opts.default_user = g_user opts.localdir = self.tmpDir by_host = pssh.copy(g_hosts, "/etc/hosts", "/tmp/pssh.test", opts) for host, result in by_host.iteritems(): rc, _, _ = result self.assertEqual(rc, 0) by_host = pssh.slurp(g_hosts, "/tmp/pssh.test", "pssh.test", opts) for host, result in by_host.iteritems(): rc, _, _, path = result self.assertEqual(rc, 0) self.assert_(path.endswith('%s/pssh.test' % (host)))
def _pssh_copy(hosts, src, dst, opts): "pssh.copy with debug logging" if config.core.debug or options.regression_tests: err_buf.debug("pssh.copy(%s, %s, %s)" % (repr(hosts), src, dst)) return pssh.copy(hosts, src, dst, opts)