def get_network(self, net_type):
"""
Returns a network (as a string) that includes the private/public IPs of all nodes in the config.
Raises an EXAConfError if an invalid IP is found or the IP of at least one node is not part
of the network defined by the first node section.
This function assumes that all nodes have an entry for the requested network type. The calling
function has to check if the network type is actually present (private / public).
"""
network = ""
for section in self.config.sections:
if self.is_node(section):
node_sec = self.config[section]
node_network = node_sec.get(net_type)
if not node_network or node_network == "":
raise EXAConfError("Network type '%s' is missing in section '%s'!" % (net_type, section))
node_ip = node_network.split("/")[0].strip()
# check if the extracted IP is valid
if not self.ip_is_valid(node_ip):
raise EXAConfError("IP %s in section '%s' is invalid!" % (node_ip, section))
# first node : choose the private net as the cluster network (and make it a 'real' network)
if network == "":
subnet = ipaddr.IPNetwork(node_network)
network = "%s/%s" % (str(subnet.network), str(subnet.prefixlen))
# other nodes : check if their IP is part of the chosen net
elif ipaddr.IPAddress(node_ip) not in ipaddr.IPNetwork(network):
raise EXAConfError("IP %s is not part of network %s!" % (node_ip, network))
return network
#}}}
#{{{ Get private network
评论列表
文章目录