def network(self, index): xml = "" for key, net in enumerate(self.conf['params']['networks']): net_params = [i for i in self.full_conf['networks'] if net in i][0] box_net = Network.hosts[0][self.box][index] if net_params[net]["dhcp"] or len(self.conf['params']['networks']) == 1: # True or False mac = box_net["mac"] xml += netconf['template']["interface_dhcp"].format( net_name=make_network_name(self.lab_id, net), mac=mac ) self.pool[self.box][index]["mac"] = mac self.pool[self.box][index]["ip"] = box_net["ip"] self.pool[self.box][index]["admin_interface"] = "eth" + str(key) self.pool[self.box][index]["eth" + str(key)] = box_net["ip"] else: xml += netconf['template']["interface"].format(net_name=make_network_name(self.lab_id, net)) self.pool[self.box][index]["hostname"] = box_net["hostname"] if net_params[net]["external"]: self.pool[self.box][index]["external_interface"] = "eth" + str(key) if "external_net" not in self.pool: if "ipv" in net_params[net] and net_params[net]["ipv"] == 6: net_name = make_network_name(self.lab_id, net) self.pool["external_net"] = Network.pool[net_name][1].net_ip else: self.pool["external_net"] = construct_net_ip(env[self.lab_id]["net_start"], key) if not net_params[net]["nat"]: self.pool[self.box][index]["internal_interface"] = "eth" + str(key) return xml
def network(self, index): xml = "" for key, net in enumerate(self.conf['params']['networks']): net_params = [i for i in self.full_conf['networks'] if net in i][0] box_net = Network.hosts[0][self.box][index] if net_params[net]["dhcp"] or len( self.conf['params']['networks']) == 1: # True or False mac = box_net["mac"] xml += netconf['template']["interface_dhcp"].format( net_name=make_network_name(self.lab_id, net), mac=mac) self.pool[self.box][index]["mac"] = mac self.pool[self.box][index]["ip"] = box_net["ip"] self.pool[ self.box][index]["admin_interface"] = "eth" + str(key) self.pool[self.box][index]["eth" + str(key)] = box_net["ip"] else: xml += netconf['template']["interface"].format( net_name=make_network_name(self.lab_id, net)) self.pool[self.box][index]["hostname"] = box_net["hostname"] if net_params[net]["external"]: self.pool[ self.box][index]["external_interface"] = "eth" + str(key) if "external_net" not in self.pool: if "ipv" in net_params[net] and net_params[net]["ipv"] == 6: net_name = make_network_name(self.lab_id, net) self.pool["external_net"] = Network.pool[net_name][ 1].net_ip else: self.pool["external_net"] = construct_net_ip( env[self.lab_id]["net_start"], key) if not net_params[net]["nat"]: self.pool[ self.box][index]["internal_interface"] = "eth" + str(key) return xml
def define_interfaces(self): nets = self.full_conf['networks'] used_nets = self.full_conf["servers"][self.server]['params']['networks'] filtered_nets = [i for i in nets if i.keys()[0] in used_nets] ifupdown = [] for num, net in enumerate(filtered_nets): conf_net_name = net.keys()[0] if "bridge" in conf_net_name: continue net_name = make_network_name(self.lab_id, conf_net_name) network = Network.pool[net_name][1] combine_func = Network6.network_combine if network.ipv6 else Network.network_combine interface = network.interface if not network.dhcp: interface_ip = combine_func( network.net_ip, Network.hosts[0][self.server][self.index]['ip_base'] ) interface_text = interface.format(int_name="eth" + str(num), int_ip=interface_ip) else: interface_text = interface.format(int_name="eth" + str(num)) if opts.distro == "ubuntu": interface_path = "/etc/network/interfaces.d/eth{int_num}.cfg" else: interface_path = "/etc/sysconfig/network-scripts/ifcfg-eth{int_num}" self.ydict["write_files"].append({ "content": interface_text, "path": interface_path.format(int_num=num), }) ifupdown.append("eth{int_num}".format(int_num=num)) for cmd in self.ydict['runcmd']: if "ifdown" in cmd: for i in ifupdown: self.cmd.append("/sbin/ifdown {int} && /sbin/ifup {int}".format(int=i)) self.cmd.append("service networking restart")
def define_interfaces(self): nets = self.full_conf['networks'] used_nets = self.full_conf["servers"][self.server]['params']['networks'] filtered_nets = [i for i in nets if i.keys()[0] in used_nets] ifupdown = [] for num, net in enumerate(filtered_nets): conf_net_name = net.keys()[0] net_name = make_network_name(self.lab_id, conf_net_name) network = Network.pool[net_name][1] combine_func = Network6.network_combine if network.ipv6 else Network.network_combine interface = network.interface if not network.dhcp: interface_ip = combine_func( network.net_ip, Network.hosts[0][self.server][self.index]['ip_base'] ) interface_text = interface.format(int_name="eth" + str(num), int_ip=interface_ip) else: interface_text = interface.format(int_name="eth" + str(num)) if opts.distro == "ubuntu": interface_path = "/etc/network/interfaces.d/eth{int_num}.cfg" else: interface_path = "/etc/sysconfig/network-scripts/ifcfg-eth{int_num}" self.ydict["write_files"].append({ "content": interface_text, "path": interface_path.format(int_num=num), }) ifupdown.append("eth{int_num}".format(int_num=num)) for cmd in self.ydict['runcmd']: if "ifdown" in cmd: for i in ifupdown: self.cmd.append("/sbin/ifdown {int} && /sbin/ifup {int}".format(int=i)) self.cmd.append("service networking restart")
def __init__(self, lab_id, config, name, net_shift, **kwargs): self.xml = netconf["template"] self.lab_id = lab_id self.name = make_network_name(lab_id, name) self.config = config self.net_shift = net_shift self.ipv = None for key in kwargs: setattr(self, key, kwargs.get(key)) self.denition = None lab_ip = env[self.lab_id]["net_start"] self.net_ip = ".".join(lab_ip.split(".")[:2] + [str(int(lab_ip.split(".")[-1]) + self.net_shift)] + ["0"]) self.net_ip_base = ".".join(self.net_ip.split(".")[:-1]) self.interface = None self.ipv6 = False self.dns_host_template = netconf["template"]["dns_host"]
def __init__(self, lab_id, config, name, net_shift, **kwargs): self.xml = netconf["template"] self.lab_id = lab_id self.name = make_network_name(lab_id, name) self.config = config self.net_shift = net_shift self.ipv = None for key in kwargs: setattr(self, key, kwargs.get(key)) self.denition = None lab_ip = env[self.lab_id]["net_start"] self.net_ip = ".".join( lab_ip.split(".")[:2] + [str(int(lab_ip.split(".")[-1]) + self.net_shift)] + ["0"]) self.net_ip_base = ".".join(self.net_ip.split(".")[:-1]) self.interface = None self.ipv6 = False self.dns_host_template = netconf["template"]["dns_host"]