def corosync_setup(argv,returnConfig=False): fedora_config = not utils.is_rhel6() if len(argv) < 2: usage.cluster() exit(1) if not returnConfig and "--start" in utils.pcs_options and not "--local" in utils.pcs_options and fedora_config: sync_start(argv) return elif not returnConfig and not "--local" in utils.pcs_options and fedora_config: sync(argv) return else: nodes = argv[1:] cluster_name = argv[0] # Verify that all nodes are resolvable otherwise problems may occur for node in nodes: try: socket.gethostbyname(node) except socket.error: print "Warning: Unable to resolve hostname: %s" % node if fedora_config == True: f = open(COROSYNC_CONFIG_FEDORA_TEMPLATE, 'r') corosync_config = f.read() f.close() i = 1 new_nodes_section = "" for node in nodes: new_nodes_section += " node {\n" new_nodes_section += " ring0_addr: %s\n" % (node) new_nodes_section += " nodeid: %d\n" % (i) new_nodes_section += " }\n" i = i+1 corosync_config = corosync_config.replace("@@nodes", new_nodes_section) corosync_config = corosync_config.replace("@@cluster_name",cluster_name) if returnConfig: return corosync_config utils.setCorosyncConf(corosync_config) else: output, retval = utils.run(["/usr/sbin/ccs", "-i", "-f", "/etc/cluster/cluster.conf", "--createcluster", cluster_name]) if retval != 0: print output print "Error creating cluster:", cluster_name sys.exit(1) for node in nodes: output, retval = utils.run(["/usr/sbin/ccs", "-f", "/etc/cluster/cluster.conf", "--addnode", node]) if retval != 0: print output print "Error adding node:", node sys.exit(1) if "--start" in utils.pcs_options: start_cluster([])
def corosync_configure(argv,returnConfig=False): fedora_config = True if len(argv) == 0: usage.cluster() exit(1) elif argv[0] == "sync" and len(argv) > 2: sync(argv[1:]) return elif argv[0] == "sync_start" and len(argv) > 2: sync_start(argv[1:]) return elif len(argv) > 1: nodes = argv[1:] cluster_name = argv[0] else: usage.cluster() exit(1) if fedora_config == True: f = open(COROSYNC_CONFIG_FEDORA_TEMPLATE, 'r') else: f = open(COROSYNC_CONFIG_TEMPLATE, 'r') corosync_config = f.read() f.close() if fedora_config == True: i = 1 new_nodes_section = "" for node in nodes: new_nodes_section += " node {\n" new_nodes_section += " ring0_addr: %s\n" % (node) new_nodes_section += " nodeid: %d\n" % (i) new_nodes_section += " }\n" i = i+1 corosync_config = corosync_config.replace("@@nodes", new_nodes_section) corosync_config = corosync_config.replace("@@cluster_name",cluster_name) if returnConfig: return corosync_config utils.setCorosyncConf(corosync_config)
def corosync_setup(argv, returnConfig=False): fedora_config = True if len(argv) < 2: usage.cluster() exit(1) if not returnConfig and "--start" in utils.pcs_options and not "--local" in utils.pcs_options: sync_start(argv) return elif not returnConfig and not "--local" in utils.pcs_options: sync(argv) return else: nodes = argv[1:] cluster_name = argv[0] if fedora_config == True: f = open(COROSYNC_CONFIG_FEDORA_TEMPLATE, 'r') else: f = open(COROSYNC_CONFIG_TEMPLATE, 'r') corosync_config = f.read() f.close() if fedora_config == True: i = 1 new_nodes_section = "" for node in nodes: new_nodes_section += " node {\n" new_nodes_section += " ring0_addr: %s\n" % (node) new_nodes_section += " nodeid: %d\n" % (i) new_nodes_section += " }\n" i = i + 1 corosync_config = corosync_config.replace("@@nodes", new_nodes_section) corosync_config = corosync_config.replace("@@cluster_name", cluster_name) if returnConfig: return corosync_config utils.setCorosyncConf(corosync_config) if "--start" in utils.pcs_options: start_cluster([])
def corosync_setup(argv,returnConfig=False): fedora_config = True if len(argv) < 2: usage.cluster() exit(1) if not returnConfig and "--start" in utils.pcs_options and not "--local" in utils.pcs_options: sync_start(argv) return elif not returnConfig and not "--local" in utils.pcs_options: sync(argv) return else: nodes = argv[1:] cluster_name = argv[0] if fedora_config == True: f = open(COROSYNC_CONFIG_FEDORA_TEMPLATE, 'r') else: f = open(COROSYNC_CONFIG_TEMPLATE, 'r') corosync_config = f.read() f.close() if fedora_config == True: i = 1 new_nodes_section = "" for node in nodes: new_nodes_section += " node {\n" new_nodes_section += " ring0_addr: %s\n" % (node) new_nodes_section += " nodeid: %d\n" % (i) new_nodes_section += " }\n" i = i+1 corosync_config = corosync_config.replace("@@nodes", new_nodes_section) corosync_config = corosync_config.replace("@@cluster_name",cluster_name) if returnConfig: return corosync_config utils.setCorosyncConf(corosync_config) if "--start" in utils.pcs_options: start_cluster([])
def corosync_setup(argv,returnConfig=False): fedora_config = not utils.is_rhel6() failure = False primary_nodes = [] # If node contains a ',' we only care about the first address for node in argv[1:]: if "," in node: primary_nodes.append(node.split(',')[0]) else: primary_nodes.append(node) if len(argv) < 2: usage.cluster() exit(1) if not returnConfig and "--start" in utils.pcs_options and not "--local" in utils.pcs_options:# and fedora_config: sync_start(argv, primary_nodes) if "--enable" in utils.pcs_options: enable_cluster(primary_nodes) return elif not returnConfig and not "--local" in utils.pcs_options:# and fedora_config: sync(argv, primary_nodes) if "--enable" in utils.pcs_options: enable_cluster(primary_nodes) return else: nodes = argv[1:] cluster_name = argv[0] # Verify that all nodes are resolvable otherwise problems may occur udpu_rrp = False for node in nodes: try: if "," in node: socket.getaddrinfo(node.split(",")[0],None) socket.getaddrinfo(node.split(",")[1],None) udpu_rrp = True else: socket.getaddrinfo(node,None) except socket.error: print "Warning: Unable to resolve hostname: %s" % node failure = True if udpu_rrp: for node in nodes: if "," not in node: utils.err("if one node is configured for RRP, all nodes must configured for RRP") if failure and "--force" not in utils.pcs_options: utils.err("Unable to resolve all hostnames (use --force to override).") if fedora_config == True: if os.path.exists(settings.corosync_conf_file) and not "--force" in utils.pcs_options: utils.err("%s already exists, use --force to overwrite" % settings.corosync_conf_file) if not ("--corosync_conf" in utils.pcs_options and "--local" in utils.pcs_options): cib_path = os.path.join(settings.cib_dir, "cib.xml") if os.path.exists(cib_path) and not "--force" in utils.pcs_options: utils.err("%s already exists, use --force to overwrite" % cib_path) if "--corosync_conf" not in utils.pcs_options: cluster_destroy([]) f = open(COROSYNC_CONFIG_FEDORA_TEMPLATE, 'r') corosync_config = f.read() f.close() i = 1 new_nodes_section = "" for node in nodes: new_nodes_section += " node {\n" if udpu_rrp: new_nodes_section += " ring0_addr: %s\n" % (node.split(",")[0]) new_nodes_section += " ring1_addr: %s\n" % (node.split(",")[1]) else: new_nodes_section += " ring0_addr: %s\n" % (node) new_nodes_section += " nodeid: %d\n" % (i) new_nodes_section += " }\n" i = i+1 two_node_section = "" if len(nodes) == 2: two_node_section = "two_node: 1" quorum_options = "" if "--wait_for_all" in utils.pcs_options: quorum_options += "wait_for_all: " + utils.pcs_options["--wait_for_all"] + "\n" if "--auto_tie_breaker" in utils.pcs_options: quorum_options += "auto_tie_breaker: " + utils.pcs_options["--auto_tie_breaker"] + "\n" if "--last_man_standing" in utils.pcs_options: quorum_options += "last_man_standing: " + utils.pcs_options["--last_man_standing"] + "\n" if "--last_man_standing_window" in utils.pcs_options: quorum_options += "last_man_standing_window: " + utils.pcs_options["--last_man_standing_window"] + "\n" transport = "udpu" if "--transport" in utils.pcs_options: transport = utils.pcs_options["--transport"] ir = "" if transport == "udpu" and ("--addr0" in utils.pcs_options or "--addr1" in utils.pcs_options): utils.err("--addr0 and --addr1 can only be used with --transport=udp") if "--rrpmode" in utils.pcs_options or udpu_rrp or "--addr0" in utils.pcs_options: rrpmode = "passive" if "--rrpmode" in utils.pcs_options: rrpmode = utils.pcs_options["--rrpmode"] if rrpmode == "active" and "--force" not in utils.pcs_options: utils.err("using a RRP mode of 'active' is not supported or tested, use --force to override") elif rrpmode != "passive" and "--force" not in utils.pcs_options: utils.err("%s is an unknown RRP mode, use --force to override" % rrpmode) ir += "rrp_mode: " + rrpmode + "\n" if transport == "udp": if "--addr0" in utils.pcs_options: ir += utils.generate_rrp_corosync_config(0) if "--addr1" in utils.pcs_options: ir += utils.generate_rrp_corosync_config(1) if "--ipv6" in utils.pcs_options: ip_version = "ip_version: ipv6\n" else: ip_version = "" totem_options = "" if "--token" in utils.pcs_options: totem_options += "token: " + utils.pcs_options["--token"] + "\n" if "--token_coefficient" in utils.pcs_options: totem_options += "token_coefficient: " + utils.pcs_options["--token_coefficient"] + "\n" if "--join" in utils.pcs_options: totem_options += "join: " + utils.pcs_options["--join"] + "\n" if "--consensus" in utils.pcs_options: totem_options += "consensus: " + utils.pcs_options["--consensus"] + "\n" if "--miss_count_const" in utils.pcs_options: totem_options += "miss_count_const: " + utils.pcs_options["--miss_count_const"] + "\n" if "--fail_recv_const" in utils.pcs_options: totem_options += "fail_recv_const: " + utils.pcs_options["--fail_recv_const"] + "\n" corosync_config = corosync_config.replace("@@nodes", new_nodes_section) corosync_config = corosync_config.replace("@@cluster_name",cluster_name) corosync_config = corosync_config.replace("@@quorum_options\n",quorum_options) corosync_config = corosync_config.replace("@@two_node",two_node_section) corosync_config = corosync_config.replace("@@transport",transport) corosync_config = corosync_config.replace("@@interfaceandrrpmode\n",ir) corosync_config = corosync_config.replace("@@ip_version\n",ip_version) corosync_config = corosync_config.replace("@@totem_options\n",totem_options) if returnConfig: return corosync_config utils.setCorosyncConf(corosync_config) else: cluster_conf_location = "/etc/cluster/cluster.conf" if returnConfig: cc_temp = tempfile.NamedTemporaryFile('w+b', -1, ".pcs") cluster_conf_location = cc_temp.name if os.path.exists("/etc/cluster/cluster.conf") and not "--force" in utils.pcs_options and not returnConfig: print "Error: /etc/cluster/cluster.conf already exists, use --force to overwrite" sys.exit(1) output, retval = utils.run(["/usr/sbin/ccs", "-i", "-f", cluster_conf_location, "--createcluster", cluster_name]) if retval != 0: print output utils.err("error creating cluster: %s" % cluster_name) output, retval = utils.run(["/usr/sbin/ccs", "-i", "-f", cluster_conf_location, "--addfencedev", "pcmk-redirect", "agent=fence_pcmk"]) if retval != 0: print output utils.err("error creating fence dev: %s" % cluster_name) if len(nodes) == 2: output, retval = utils.run(["/usr/sbin/ccs", "-f", cluster_conf_location, "--setcman", "two_node=1", "expected_votes=1"]) if retval != 0: print output utils.err("error adding node: %s" % node) for node in nodes: output, retval = utils.run(["/usr/sbin/ccs", "-f", cluster_conf_location, "--addnode", node]) if retval != 0: print output utils.err("error adding node: %s" % node) output, retval = utils.run(["/usr/sbin/ccs", "-i", "-f", cluster_conf_location, "--addmethod", "pcmk-method", node]) if retval != 0: print output utils.err("error adding fence method: %s" % node) output, retval = utils.run(["/usr/sbin/ccs", "-i", "-f", cluster_conf_location, "--addfenceinst", "pcmk-redirect", node, "pcmk-method", "port="+node]) if retval != 0: print output utils.err("error adding fence instance: %s" % node) if returnConfig: cc_temp.seek(0) cluster_conf_data = cc_temp.read() cc_temp.close() return cluster_conf_data if "--start" in utils.pcs_options: start_cluster([]) if "--enable" in utils.pcs_options: enable_cluster([])
def corosync_setup(argv, returnConfig=False): fedora_config = not utils.is_rhel6() failure = False if len(argv) < 2: usage.cluster() exit(1) if not returnConfig and "--start" in utils.pcs_options and not "--local" in utils.pcs_options and fedora_config: sync_start(argv) return elif not returnConfig and not "--local" in utils.pcs_options and fedora_config: sync(argv) return else: nodes = argv[1:] cluster_name = argv[0] # Verify that all nodes are resolvable otherwise problems may occur for node in nodes: try: socket.gethostbyname(node) except socket.error: print "Warning: Unable to resolve hostname: %s" % node failure = True if failure: utils.err("Unable to resolve all hostnames.") if fedora_config == True: f = open(COROSYNC_CONFIG_FEDORA_TEMPLATE, 'r') corosync_config = f.read() f.close() i = 1 new_nodes_section = "" for node in nodes: new_nodes_section += " node {\n" new_nodes_section += " ring0_addr: %s\n" % (node) new_nodes_section += " nodeid: %d\n" % (i) new_nodes_section += " }\n" i = i + 1 two_node_section = "" if len(nodes) == 2: two_node_section = "two_node: 1" corosync_config = corosync_config.replace("@@nodes", new_nodes_section) corosync_config = corosync_config.replace("@@cluster_name", cluster_name) corosync_config = corosync_config.replace("@@two_node", two_node_section) if returnConfig: return corosync_config utils.setCorosyncConf(corosync_config) else: if os.path.exists("/etc/cluster/cluster.conf" ) and not "--force" in utils.pcs_options: print "Error: /etc/cluster/cluster.conf already exists, use --force to overwrite" sys.exit(1) output, retval = utils.run([ "/usr/sbin/ccs", "-i", "-f", "/etc/cluster/cluster.conf", "--createcluster", cluster_name ]) if retval != 0: print output utils.err("error creating cluster: %s" % cluster_name) output, retval = utils.run([ "/usr/sbin/ccs", "-i", "-f", "/etc/cluster/cluster.conf", "--addfencedev", "pcmk-redirect", "agent=fence_pcmk" ]) if retval != 0: print output utils.err("error creating fence dev: %s" % cluster_name) for node in nodes: output, retval = utils.run([ "/usr/sbin/ccs", "-f", "/etc/cluster/cluster.conf", "--addnode", node ]) if retval != 0: print output utils.err("error adding node: %s" % node) output, retval = utils.run([ "/usr/sbin/ccs", "-i", "-f", "/etc/cluster/cluster.conf", "--addmethod", "pcmk-method", node ]) if retval != 0: print output utils.err("error adding fence method: %s" % node) output, retval = utils.run([ "/usr/sbin/ccs", "-i", "-f", "/etc/cluster/cluster.conf", "--addfenceinst", "pcmk-redirect", node, "pcmk-method", "port=" + node ]) if retval != 0: print output utils.err("error adding fence instance: %s" % node) if "--start" in utils.pcs_options: start_cluster([])
def corosync_setup(argv,returnConfig=False): fedora_config = not utils.is_rhel6() failure = False if len(argv) < 2: usage.cluster() exit(1) if not returnConfig and "--start" in utils.pcs_options and not "--local" in utils.pcs_options and fedora_config: sync_start(argv) if "--enable" in utils.pcs_options: enable_cluster(argv[1:]) return elif not returnConfig and not "--local" in utils.pcs_options and fedora_config: sync(argv) if "--enable" in utils.pcs_options: enable_cluster(argv[1:]) return else: nodes = argv[1:] cluster_name = argv[0] # Verify that all nodes are resolvable otherwise problems may occur for node in nodes: try: socket.gethostbyname(node) except socket.error: print "Warning: Unable to resolve hostname: %s" % node failure = True if failure: utils.err("Unable to resolve all hostnames.") if fedora_config == True: f = open(COROSYNC_CONFIG_FEDORA_TEMPLATE, 'r') corosync_config = f.read() f.close() i = 1 new_nodes_section = "" for node in nodes: new_nodes_section += " node {\n" new_nodes_section += " ring0_addr: %s\n" % (node) new_nodes_section += " nodeid: %d\n" % (i) new_nodes_section += " }\n" i = i+1 two_node_section = "" if len(nodes) == 2: two_node_section = "two_node: 1" corosync_config = corosync_config.replace("@@nodes", new_nodes_section) corosync_config = corosync_config.replace("@@cluster_name",cluster_name) corosync_config = corosync_config.replace("@@two_node",two_node_section) if returnConfig: return corosync_config utils.setCorosyncConf(corosync_config) else: if os.path.exists("/etc/cluster/cluster.conf") and not "--force" in utils.pcs_options: print "Error: /etc/cluster/cluster.conf already exists, use --force to overwrite" sys.exit(1) output, retval = utils.run(["/usr/sbin/ccs", "-i", "-f", "/etc/cluster/cluster.conf", "--createcluster", cluster_name]) if retval != 0: print output utils.err("error creating cluster: %s" % cluster_name) output, retval = utils.run(["/usr/sbin/ccs", "-i", "-f", "/etc/cluster/cluster.conf", "--addfencedev", "pcmk-redirect", "agent=fence_pcmk"]) if retval != 0: print output utils.err("error creating fence dev: %s" % cluster_name) if len(nodes) == 2: output, retval = utils.run(["/usr/sbin/ccs", "-f", "/etc/cluster/cluster.conf", "--setcman", "two_node=1", "expected_votes=1"]) if retval != 0: print output utils.err("error adding node: %s" % node) for node in nodes: output, retval = utils.run(["/usr/sbin/ccs", "-f", "/etc/cluster/cluster.conf", "--addnode", node]) if retval != 0: print output utils.err("error adding node: %s" % node) output, retval = utils.run(["/usr/sbin/ccs", "-i", "-f", "/etc/cluster/cluster.conf", "--addmethod", "pcmk-method", node]) if retval != 0: print output utils.err("error adding fence method: %s" % node) output, retval = utils.run(["/usr/sbin/ccs", "-i", "-f", "/etc/cluster/cluster.conf", "--addfenceinst", "pcmk-redirect", node, "pcmk-method", "port="+node]) if retval != 0: print output utils.err("error adding fence instance: %s" % node) if "--start" in utils.pcs_options: start_cluster([]) if "--enable" in utils.pcs_options: enable_cluster([])
def corosync_setup(argv,returnConfig=False): fedora_config = not utils.is_rhel6() failure = False primary_nodes = [] # If node contains a ',' we only care about the first address for node in argv[1:]: if "," in node: primary_nodes.append(node.split(',')[0]) else: primary_nodes.append(node) if len(argv) < 2: usage.cluster() exit(1) if not returnConfig and "--start" in utils.pcs_options and not "--local" in utils.pcs_options and fedora_config: sync_start(argv, primary_nodes) if "--enable" in utils.pcs_options: enable_cluster(primary_nodes) return elif not returnConfig and not "--local" in utils.pcs_options and fedora_config: sync(argv, primary_nodes) if "--enable" in utils.pcs_options: enable_cluster(primary_nodes) return else: nodes = argv[1:] cluster_name = argv[0] # Verify that all nodes are resolvable otherwise problems may occur udpu_rrp = False for node in nodes: try: if "," in node: socket.getaddrinfo(node.split(",")[0],None) socket.getaddrinfo(node.split(",")[1],None) udpu_rrp = True else: socket.getaddrinfo(node,None) except socket.error: print "Warning: Unable to resolve hostname: %s" % node failure = True if udpu_rrp: for node in nodes: if "," not in node: utils.err("if one node is configured for RRP, all nodes must configured for RRP") if failure and "--force" not in utils.pcs_options: utils.err("Unable to resolve all hostnames (use --force to override).") if fedora_config == True: f = open(COROSYNC_CONFIG_FEDORA_TEMPLATE, 'r') corosync_config = f.read() f.close() i = 1 new_nodes_section = "" for node in nodes: new_nodes_section += " node {\n" if udpu_rrp: new_nodes_section += " ring0_addr: %s\n" % (node.split(",")[0]) new_nodes_section += " ring1_addr: %s\n" % (node.split(",")[1]) else: new_nodes_section += " ring0_addr: %s\n" % (node) new_nodes_section += " nodeid: %d\n" % (i) new_nodes_section += " }\n" i = i+1 two_node_section = "" if len(nodes) == 2: two_node_section = "two_node: 1" quorum_options = "" if "--wait_for_all" in utils.pcs_options: quorum_options += "wait_for_all: " + utils.pcs_options["--wait_for_all"] + "\n" if "--auto_tie_breaker" in utils.pcs_options: quorum_options += "auto_tie_breaker: " + utils.pcs_options["--auto_tie_breaker"] + "\n" if "--last_node_standing" in utils.pcs_options: quorum_options += "last_node_standing: " + utils.pcs_options["--last_node_standing"] + "\n" if "--last_node_standing_window" in utils.pcs_options: quorum_options += "last_node_standing_window: " + utils.pcs_options["--last_node_standing_window"] + "\n" transport = "udpu" if "--transport" in utils.pcs_options: transport = utils.pcs_options["--transport"] ir = "" if transport == "udpu" and ("--addr0" in utils.pcs_options or "--addr1" in utils.pcs_options): utils.err("--addr0 and --addr1 can only be used with --transport=udp") if "--rrpmode" in utils.pcs_options or udpu_rrp or "--addr0" in utils.pcs_options: rrpmode = "passive" if "--rrpmode" in utils.pcs_options: rrpmode = utils.pcs_options["--rrpmode"] ir += "rrp_mode: " + rrpmode + "\n" if transport == "udp": if "--addr0" in utils.pcs_options: ir += utils.generate_rrp_corosync_config(0) if "--addr1" in utils.pcs_options: ir += utils.generate_rrp_corosync_config(1) corosync_config = corosync_config.replace("@@nodes", new_nodes_section) corosync_config = corosync_config.replace("@@cluster_name",cluster_name) corosync_config = corosync_config.replace("@@quorum_options\n",quorum_options) corosync_config = corosync_config.replace("@@two_node",two_node_section) corosync_config = corosync_config.replace("@@transport",transport) corosync_config = corosync_config.replace("@@interfaceandrrpmode\n",ir) if returnConfig: return corosync_config utils.setCorosyncConf(corosync_config) else: if os.path.exists("/etc/cluster/cluster.conf") and not "--force" in utils.pcs_options: print "Error: /etc/cluster/cluster.conf already exists, use --force to overwrite" sys.exit(1) output, retval = utils.run(["/usr/sbin/ccs", "-i", "-f", "/etc/cluster/cluster.conf", "--createcluster", cluster_name]) if retval != 0: print output utils.err("error creating cluster: %s" % cluster_name) output, retval = utils.run(["/usr/sbin/ccs", "-i", "-f", "/etc/cluster/cluster.conf", "--addfencedev", "pcmk-redirect", "agent=fence_pcmk"]) if retval != 0: print output utils.err("error creating fence dev: %s" % cluster_name) if len(nodes) == 2: output, retval = utils.run(["/usr/sbin/ccs", "-f", "/etc/cluster/cluster.conf", "--setcman", "two_node=1", "expected_votes=1"]) if retval != 0: print output utils.err("error adding node: %s" % node) for node in nodes: output, retval = utils.run(["/usr/sbin/ccs", "-f", "/etc/cluster/cluster.conf", "--addnode", node]) if retval != 0: print output utils.err("error adding node: %s" % node) output, retval = utils.run(["/usr/sbin/ccs", "-i", "-f", "/etc/cluster/cluster.conf", "--addmethod", "pcmk-method", node]) if retval != 0: print output utils.err("error adding fence method: %s" % node) output, retval = utils.run(["/usr/sbin/ccs", "-i", "-f", "/etc/cluster/cluster.conf", "--addfenceinst", "pcmk-redirect", node, "pcmk-method", "port="+node]) if retval != 0: print output utils.err("error adding fence instance: %s" % node) if "--start" in utils.pcs_options: start_cluster([]) if "--enable" in utils.pcs_options: enable_cluster([])