def build_topo(self, topology): real_topo = topology.real intf_conv = file_io.read_yaml(INTF_CONV_FILE) for ((a_name, a_intf), (b_name, b_intf)) in real_topo: a_device = Switch(a_name, L2_IMAGE) if 'sw' in a_name.lower() else Router( a_name, L3_IMAGE) b_device = Switch(b_name, L2_IMAGE) if 'sw' in b_name.lower() else Router( b_name, L3_IMAGE) if a_name not in self.nodes: self.nodes[a_name] = self.lab.create_node(a_device) # print("*** NODE {} CREATED".format(a_name)) if b_name not in self.nodes: self.nodes[b_name] = self.lab.create_node(b_device) # print("*** NODE {} CREATED".format(b_name)) node_a = self.nodes[a_name] node_b = self.nodes[b_name] if intf_conv.get(a_name, {}).get(a_intf, None): a_intf_lab = intf_conv[a_name][a_intf] else: a_intf_lab = node_a.get_next_intf() if intf_conv.get(b_name, {}).get(b_intf, None): b_intf_lab = intf_conv[b_name][b_intf] else: b_intf_lab = node_b.get_next_intf() intf_conv.setdefault(a_name, {})[a_intf] = a_intf_lab intf_conv.setdefault(b_name, {})[b_intf] = b_intf_lab node_a.connect_node(a_intf_lab, node_b, b_intf_lab) # print("*** NODES {} and {} ARE CONNECTED".format(a_name, b_name)) file_io.write_yaml(INTF_CONV_FILE, intf_conv) return None
def build_topo(self, topology): real_topo = topology.real intf_conv = file_io.read_yaml(INTF_CONV_FILE) for ((a_name, a_intf), (b_name, b_intf)) in real_topo: a_device = Switch(a_name, L2_IMAGE) if "sw" in a_name.lower() else Router(a_name, L3_IMAGE) b_device = Switch(b_name, L2_IMAGE) if "sw" in b_name.lower() else Router(b_name, L3_IMAGE) if a_name not in self.nodes: self.nodes[a_name] = self.lab.create_node(a_device) # print("*** NODE {} CREATED".format(a_name)) if b_name not in self.nodes: self.nodes[b_name] = self.lab.create_node(b_device) # print("*** NODE {} CREATED".format(b_name)) node_a = self.nodes[a_name] node_b = self.nodes[b_name] if intf_conv.get(a_name, {}).get(a_intf, None): a_intf_lab = intf_conv[a_name][a_intf] else: a_intf_lab = node_a.get_next_intf() if intf_conv.get(b_name, {}).get(b_intf, None): b_intf_lab = intf_conv[b_name][b_intf] else: b_intf_lab = node_b.get_next_intf() intf_conv.setdefault(a_name, {})[a_intf] = a_intf_lab intf_conv.setdefault(b_name, {})[b_intf] = b_intf_lab node_a.connect_node(a_intf_lab, node_b, b_intf_lab) # print("*** NODES {} and {} ARE CONNECTED".format(a_name, b_name)) file_io.write_yaml(INTF_CONV_FILE, intf_conv) return None
def extract_ip(self): result = {} # cwd = os.path.join(TMP_DIR, CONF_DIR) for f in os.listdir(TMP_DIR): if f.endswith('.txt'): dev_name = os.path.splitext(f)[0] file_text = file_io.read_txt(TMP_DIR + '/' + f) ips = self.get_ips(file_text) result[dev_name] = ips file_io.write_yaml(TMP_DIR + '/' + 'ip.yml', result) return result
def ext_connect(self, topo): ext_topo = topo.ext_net intf_conv = file_io.read_yaml(INTF_CONV_FILE) for (node_name, node_intf), pnet in ext_topo.iteritems(): ext_net = self.lab.create_net('cloud', net_type=pnet) the_node = self.nodes[node_name] node_intf_lab = the_node.get_next_intf() the_node.connect_interface(node_intf_lab, ext_net) intf_conv.setdefault(node_name, {})[node_intf] = node_intf_lab file_io.write_yaml(INTF_CONV_FILE, intf_conv) return None
def ext_connect(self, topo): ext_topo = topo.ext_net intf_conv = file_io.read_yaml(INTF_CONV_FILE) for (node_name, node_intf), pnet in ext_topo.iteritems(): ext_net = self.lab.create_net("cloud", net_type=pnet) the_node = self.nodes[node_name] node_intf_lab = the_node.get_next_intf() the_node.connect_interface(node_intf_lab, ext_net) intf_conv.setdefault(node_name, {})[node_intf] = node_intf_lab file_io.write_yaml(INTF_CONV_FILE, intf_conv) return None
def extract_ip(self): result = {} cwd = os.path.join(TMP_DIR, CONF_DIR) for f in os.listdir(cwd): if f.endswith('.txt'): dev_name = os.path.splitext(f)[0] file_text = file_io.read_txt(cwd + '/' + f) ips = self.get_ips(file_text) result[dev_name] = ips file_io.write_yaml(TMP_DIR + '/' + 'ip.yml', result) return result