def generate_links(self, nodes): """ Generate a list of links :param list nodes: A list of nodes from :py:meth:`generate_nodes` :return: list of links :rtype: list """ new_links = [] for link in self.links: # Expand port name if required if INTERFACE_RE.search(link['dest_port'])\ or VBQ_INT_RE.search(link['dest_port']): int_type = link['dest_port'][0] dest_port = link['dest_port'].replace( int_type, PORT_TYPES[int_type.upper()]) else: dest_port = link['dest_port'] # Convert dest_dev and port to id's dest_details = self.convert_destination_to_id( link['dest_dev'], dest_port, nodes) desc = 'Link from %s port %s to %s port %s' % \ (link['source_dev'], link['source_port_name'], dest_details['name'], dest_port) new_links.append({ 'description': desc, 'destination_node_id': dest_details['id'], 'destination_port_id': dest_details['pid'], 'source_port_id': link['source_port_id'], 'source_node_id': link['source_node_id'] }) # Remove duplicate links and add link_id link_id = 1 for link in new_links: t_link = str(link['source_node_id']) + ':' + \ str(link['source_port_id']) for link2 in new_links: d_link = str(link2['destination_node_id']) + ':' + \ str(link2['destination_port_id']) if t_link == d_link: new_links.remove(link2) break link['id'] = link_id link_id += 1 self.add_node_connection(link, nodes) return new_links
def generate_links(self, nodes): """ Generate a list of links :param list nodes: A list of nodes from :py:meth:`generate_nodes` :return: list of links :rtype: list """ new_links = [] for link in self.links: # Expand port name if required if INTERFACE_RE.search(link['dest_port'])\ or VBQ_INT_RE.search(link['dest_port']): int_type = link['dest_port'][0] dest_port = link['dest_port'].replace( int_type, PORT_TYPES[int_type.upper()]) else: dest_port = link['dest_port'] # Convert dest_dev and port to id's dest_details = self.convert_destination_to_id( link['dest_dev'], dest_port, nodes) desc = 'Link from %s port %s to %s port %s' % \ (link['source_dev'], link['source_port_name'], dest_details['name'], dest_port) new_links.append({'description': desc, 'destination_node_id': dest_details['id'], 'destination_port_id': dest_details['pid'], 'source_port_id': link['source_port_id'], 'source_node_id': link['source_node_id']}) # Remove duplicate links and add link_id link_id = 1 for link in new_links: t_link = str(link['source_node_id']) + ':' + \ str(link['source_port_id']) for link2 in new_links: d_link = str(link2['destination_node_id']) + ':' + \ str(link2['destination_port_id']) if t_link == d_link: new_links.remove(link2) break link['id'] = link_id link_id += 1 self.add_node_connection(link, nodes) return new_links
def add_device_items(self, item, device): """ Add the various items from the device to the node :param str item: item key :param dict device: dictionary containing items """ if item in ('aux', 'console'): self.node['properties'][item] = device[item] elif item.startswith('slot'): if self.device_info['model'] == 'c7200': if item != 'slot0': self.node['properties'][item] = device[item] else: self.node['properties'][item] = device[item] elif item == 'connections': self.connections = device[item] elif INTERFACE_RE.search(item) or VBQ_INT_RE.search(item): self.interfaces.append({'from': item, 'to': device[item]}) elif NUMBER_RE.search(item): if self.device_info['type'] == 'EthernetSwitch': self.calc_ethsw_port(item, device[item]) elif self.device_info['type'] == 'FrameRelaySwitch': self.calc_frsw_port(item, device[item]) elif MAPINT_RE.search(item): self.add_mapping((item, device[item])) elif item == 'cnfg': new_config = os.path.join( 'configs', 'i%s_startup-config.cfg' % self.node['id']) self.node['properties']['startup_config'] = new_config self.config.append({ 'old': fix_path(device[item]), 'new': new_config }) elif item.startswith('wic'): self.add_wic(item, device[item]) elif item == 'symbol': self.set_symbol(device[item]) elif item == 'nics': self.node['properties']['adapters'] = device[item] elif item == 'image': self.node['properties']['vmname'] = device[item] elif item == 'vbox_id': self.node['vbox_id'] = device[item]
def add_device_items(self, item, device): """ Add the various items from the device to the node :param str item: item key :param dict device: dictionary containing items """ if item in ('aux', 'console'): self.node['properties'][item] = device[item] elif item.startswith('slot'): if self.device_info['model'] == 'c7200': if item != 'slot0': self.node['properties'][item] = device[item] else: self.node['properties'][item] = device[item] elif item == 'connections': self.connections = device[item] elif INTERFACE_RE.search(item) or VBQ_INT_RE.search(item): self.interfaces.append({'from': item, 'to': device[item]}) elif NUMBER_RE.search(item): if self.device_info['type'] == 'EthernetSwitch': self.calc_ethsw_port(item, device[item]) elif self.device_info['type'] == 'FrameRelaySwitch': self.calc_frsw_port(item, device[item]) elif MAPINT_RE.search(item): self.add_mapping((item, device[item])) elif item == 'cnfg': new_config = os.path.join('configs', 'i%s_startup-config.cfg' % self.node['id']) self.node['properties']['startup_config'] = new_config self.config.append({'old': fix_path(device[item]), 'new': new_config}) elif item.startswith('wic'): self.add_wic(item, device[item]) elif item == 'symbol': self.set_symbol(device[item]) elif item == 'nics': self.node['properties']['adapters'] = device[item] elif item == 'image': self.node['properties']['vmname'] = device[item] elif item == 'vbox_id': self.node['vbox_id'] = device[item]
def add_device_items(self, item, device): """ Add the various items from the device to the node :param str item: item key :param dict device: dictionary containing items """ if item in ("aux", "console"): self.node["properties"][item] = device[item] elif item.startswith("slot"): if self.device_info["model"] == "c7200": if item != "slot0": self.node["properties"][item] = device[item] else: self.node["properties"][item] = device[item] elif item == "connections": self.connections = device[item] elif INTERFACE_RE.search(item) or VBQ_INT_RE.search(item): self.interfaces.append({"from": item, "to": device[item]}) elif NUMBER_RE.search(item): if self.device_info["type"] == "EthernetSwitch": self.calc_ethsw_port(item, device[item]) elif self.device_info["type"] == "FrameRelaySwitch": self.calc_frsw_port(item, device[item]) elif MAPINT_RE.search(item): self.add_mapping((item, device[item])) elif item == "cnfg": new_config = os.path.join("configs", "i%s_startup-config.cfg" % self.node["id"]) self.node["properties"]["startup_config"] = new_config self.config.append({"old": fix_path(device[item]), "new": new_config}) elif item.startswith("wic"): self.add_wic(item, device[item]) elif item == "symbol": self.set_symbol(device[item]) elif item == "nics": self.node["properties"]["adapters"] = device[item] elif item == "image": self.node["properties"]["vmname"] = device[item] elif item == "vbox_id" or item == "qemu_id": self.node[item] = device[item]