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: 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 service_info(service): "Returns information about a given service" active, enabled = 'unknown', 'unknown' rc, out, err = crm_script.call(["/usr/bin/systemctl", "is-enabled", "%s.service" % (service)]) if rc in (0, 1, 3) and out: enabled = out.strip() else: return {'name': service, 'error': err.strip()} rc, out, err = crm_script.call(["/usr/bin/systemctl", "is-active", "%s.service" % (service)]) if rc in (0, 1, 3) and out: active = out.strip() else: return {'name': service, 'error': err.strip()} return {'name': service, 'active': active, 'enabled': enabled}
def run_apply(): for node in remove_nodes: rc, out, err = crm_script.call(['ssh', '-o', 'PasswordAuthentication=no', 'root@%s' % (node), 'systemctl stop corosync.service']) if rc != 0: crm_script.exit_fail("Failed to stop corosync on %s: %s" % (node, err)) rc, out, err = crm_script.call(['crm', 'node', 'delete', node]) if rc != 0: crm_script.exit_fail("Failed to remove %s from CIB: %s" % (node, err)) crm_script.exit_ok({"removed": remove_nodes})
def start_new_node(): if host not in add_nodes: crm_script.exit_ok(host) rc, _, err = crm_script.call(['crm', 'cluster', 'start']) if rc == 0: crm_script.exit_ok(host) crm_script.exit_fail(err)
def run_apply(): for node in remove_nodes: rc, out, err = crm_script.call([ 'ssh', '-o', 'PasswordAuthentication=no', 'root@%s' % (node), 'systemctl stop corosync.service' ]) if rc != 0: crm_script.exit_fail("Failed to stop corosync on %s: %s" % (node, err)) rc, out, err = crm_script.call(['crm', 'node', 'delete', node]) if rc != 0: crm_script.exit_fail("Failed to remove %s from CIB: %s" % (node, err)) crm_script.exit_ok({"removed": remove_nodes})
def disk_info(): rc, out, err = crm_script.call(['df'], shell=False) if rc == 0: disk_use = [] for line in out.split('\n')[1:]: line = line.strip() if line: data = line.split() if len(data) >= 6: disk_use.append((data[5], data[4])) return disk_use return []
def disk_info(): rc, out, err = crm_script.call(['df'], shell=False) if rc == 0: disk_use = [] for line in out.split('\n')[1:]: line = line.strip() if line: data = line.split() if len(data) >= 6: disk_use.append((data[5], int(data[4][:-1]))) return disk_use return []
def disk_info(): rc, out, err = crm_script.call(["df"], shell=False) if rc == 0: disk_use = [] for line in out.split("\n")[1:]: line = line.strip() if line: data = line.split() if len(data) >= 6: disk_use.append((data[5], data[4])) return disk_use return []
def configure_firewall(): _SUSE_FW_TEMPLATE = """## Name: HAE cluster ports ## Description: opens ports for HAE cluster services TCP="%(tcp)s" UDP="%(udp)s" """ corosync_mcastport = crm_script.param('mcastport') if not corosync_mcastport: rc, out, err = crm_script.call(['crm', 'corosync', 'get', 'totem.interface.mcastport']) if rc == 0: corosync_mcastport = out.strip() FW = '/etc/sysconfig/SuSEfirewall2' FW_CLUSTER = '/etc/sysconfig/SuSEfirewall2.d/services/cluster' tcp_ports = '30865 5560 7630 21064' udp_ports = '%s %s' % (corosync_mcastport, int(corosync_mcastport) - 1) if is_service_enabled('SuSEfirewall2'): if os.path.isfile(FW_CLUSTER): tmpl = open(FW_CLUSTER).read() tmpl = re.sub(r'^TCP="(.*)"', 'TCP="%s"' % (tcp_ports), tmpl, flags=re.M) tmpl = re.sub(r'^UDP="(.*)"', 'UDP="%s"' % (udp_ports), tmpl, flags=re.M) with open(FW_CLUSTER, 'w') as f: f.write(tmpl) elif os.path.isdir(os.path.dirname(FW_CLUSTER)): with open(FW_CLUSTER, 'w') as fwc: fwc.write(_SUSE_FW_TEMPLATE % {'tcp': tcp_ports, 'udp': udp_ports}) else: # neither the cluster file nor the services # directory exists crm_script.exit_fail("SUSE firewall is configured but %s does not exist" % os.path.dirname(FW_CLUSTER)) # add cluster to FW_CONFIGURATIONS_EXT if os.path.isfile(FW): txt = open(FW).read() m = re.search(r'^FW_CONFIGURATIONS_EXT="(.*)"', txt, re.M) if m: services = m.group(1).split() if 'cluster' not in services: services.append('cluster') txt = re.sub(r'^FW_CONFIGURATIONS_EXT="(.*)"', r'FW_CONFIGURATIONS_EXT="%s"' % (' '.join(services)), txt, flags=re.M) else: txt += '\nFW_CONFIGURATIONS_EXT="cluster"' with open(FW, 'w') as fw: fw.write(txt) if is_service_active('SuSEfirewall2'): crm_script.service('SuSEfirewall2', 'restart')
def net_info(): ret = {} interfaces = [] rc, out, err = crm_script.call(['netstat', '-nr']) if rc == 0: data = [l.split() for l in out.split('\n')] if len(data) < 3: return {'error': "Failed to parse netstat output"} keys = data[1] for line in data[2:]: if len(line) == len(keys): interfaces.append(dict(zip(keys, line))) else: interfaces.append({'error': err.strip()}) ret['interfaces'] = interfaces hostname = platform.node().split('.')[0] try: ip = socket.gethostbyname(hostname) ret['hostname'] = {'name': hostname, 'ip': ip} except Exception, e: ret['hostname'] = {'error': str(e)}
#!/usr/bin/env python import crm_script rc, _, err = crm_script.call(['crm', 'cluster', 'wait_for_startup', '30']) if rc != 0: crm_script.exit_fail("Cluster not responding") def check_for_primitives(): rc, out, err = crm_script.call( "crm configure show type:primitive | grep primitive", shell=True) if rc == 0 and out: return True return False if check_for_primitives(): crm_script.debug("Joined existing cluster - will not reconfigure") crm_script.exit_ok(True) try: nodelist = crm_script.param('nodes') crm_script.save_template('./basic.cib.template', './basic.cib') except IOError, e: crm_script.exit_fail("IO error: %s" % (str(e))) except ValueError, e: crm_script.exit_fail("Value error: %s" % (str(e))) rc, _, err = crm_script.call( ['crm', 'configure', 'load', 'replace', './basic.cib']) if rc != 0:
""" % ((len(nodelist) / 2) + 1) try: crm_script.save_template('./corosync.conf.template', '/etc/corosync/corosync.conf', bindnetaddr=make_bindnetaddr(), mcastaddr=crm_script.param('mcastaddr'), mcastport=crm_script.param('mcastport'), transport=crm_script.param('transport'), nodelist=nodelist_txt, quorum=quorum_txt) except Exception, e: crm_script.exit_fail(str(e)) # start cluster rc, out, err = crm_script.call(['crm', 'cluster', 'start']) if rc != 0: crm_script.exit_fail("Failed to start cluster: %s" % (err)) crm_script.exit_ok(True) if __name__ == "__main__": if len(sys.argv) < 2: crm_script.exit_fail("Missing argument to configure.py") elif sys.argv[1] == 'install': run_install() elif sys.argv[1] == 'corosync': run_corosync() else: crm_script.exit_fail("Bad argument to configure.py: %s" %
def extract_report(): rc, out, err = crm.call(['tar', 'xjf', 'health-report.tar.bz2'], shell=False) return rc == 0
def create_report(): cmd = ['crm', 'report', '-f', get_from_date(), '-D', '-Z', 'health-report'] rc, out, err = crm.call(cmd, shell=False) return rc == 0
def logrotate_info(): rc, _, _ = crm_script.call( 'grep -r corosync.conf /etc/logrotate.d', shell=True) return {'corosync.conf': rc == 0}
#!/usr/bin/env python import crm_script rc, _, err = crm_script.call(['crm', 'cluster', 'wait_for_startup', '30']) if rc != 0: crm_script.exit_fail("Cluster not responding") def check_for_primitives(): rc, out, err = crm_script.call("crm configure show type:primitive | grep primitive", shell=True) if rc == 0 and out: return True return False if check_for_primitives(): crm_script.debug("Joined existing cluster - will not reconfigure") crm_script.exit_ok(True) try: nodelist = crm_script.param('nodes') crm_script.save_template('./basic.cib.template', './basic.cib') except IOError, e: crm_script.exit_fail("IO error: %s" % (str(e))) except ValueError, e: crm_script.exit_fail("Value error: %s" % (str(e))) rc, _, err = crm_script.call(['crm', 'configure', 'load', 'replace', './basic.cib']) if rc != 0: crm_script.exit_fail("Failed to load CIB configuration: %s" % (err)) crm_script.exit_ok(True)
def check_for_primitives(): rc, out, err = crm_script.call("crm configure show type:primitive | grep primitive", shell=True) if rc == 0 and out: return True return False
""" % ((len(nodelist) / 2) + 1) try: crm_script.save_template('./corosync.conf.template', '/etc/corosync/corosync.conf', bindnetaddr=make_bindnetaddr(), mcastaddr=crm_script.param('mcastaddr'), mcastport=crm_script.param('mcastport'), transport=crm_script.param('transport'), nodelist=nodelist_txt, quorum=quorum_txt) except Exception, e: crm_script.exit_fail(str(e)) # start cluster rc, out, err = crm_script.call(['crm', 'cluster', 'start']) if rc != 0: crm_script.exit_fail("Failed to start cluster: %s" % (err)) crm_script.exit_ok(True) if __name__ == "__main__": if len(sys.argv) < 2: crm_script.exit_fail("Missing argument to configure.py") elif sys.argv[1] == 'ssh': run_ssh() elif sys.argv[1] == 'install': run_install() elif sys.argv[1] == 'corosync': run_corosync() else:
def get_from_date(): rc, out, err = crm.call("date '+%F %H:%M' --date='1 day ago'", shell=True) return out.strip()
def check_for_primitives(): rc, out, err = crm_script.call( "crm configure show type:primitive | grep primitive", shell=True) if rc == 0 and out: return True return False
def logrotate_info(): rc, _, _ = crm_script.call("grep -r corosync.conf /etc/logrotate.d", shell=True) return {"corosync.conf": rc == 0}