def setUp(self): hv_input = {'image': '/home/test/GNS3/Images/c3725.image', 'idlepc': '0x61616161', 'ram': '256', 'npe': 'npe-400', 'chassis': '3640',} self.app = Node(hv_input, 1)
def generate_nodes(self, topology): """ Generate a list of nodes for the new topology :param dict topology: processed topology from :py:meth:`process_topology` :return: a list of dicts on nodes :rtype: list """ nodes = [] devices = topology['devices'] hypervisors = topology['conf'] for device in sorted(devices): hv_id = devices[device]['hv_id'] try: tmp_node = Node(hypervisors[hv_id], self.port_id) except IndexError: tmp_node = Node({}, self.port_id) # Start building the structure tmp_node.node['properties']['name'] = device tmp_node.node['id'] = devices[device]['node_id'] tmp_node.node['x'] = devices[device]['x'] tmp_node.node['y'] = devices[device]['y'] tmp_node.device_info['from'] = devices[device]['from'] tmp_node.device_info['type'] = devices[device]['type'] tmp_node.device_info['desc'] = devices[device]['desc'] if 'ext_conf' in devices[device]: tmp_node.device_info['ext_conf'] = devices[device]['ext_conf'] # Node Label tmp_node.node['label']['text'] = device if 'hx' in devices[device] and 'hy' in devices[device]: tmp_node.node['label']['x'] = devices[device]['hx'] tmp_node.node['label']['y'] = devices[device]['hy'] if 'model' in devices[device]: tmp_node.device_info['model'] = devices[device]['model'] else: tmp_node.device_info['model'] = '' tmp_node.set_description() tmp_node.set_type() # Now lets process the rest for item in sorted(devices[device]): tmp_node.add_device_items(item, devices[device]) if tmp_node.device_info['type'] == 'Router': tmp_node.add_info_from_hv() tmp_node.node['router_id'] = devices[device]['node_id'] tmp_node.calc_mb_ports() for item in sorted(tmp_node.node['properties']): if item.startswith('slot'): tmp_node.add_slot_ports(item) elif item.startswith('wic'): tmp_node.add_wic_ports(item) # Add default ports to 7200 and 3660 if tmp_node.device_info['model'] == 'c7200': # tmp_node.add_slot_ports('slot0') # C7200 doesnt have any ports by default pass elif tmp_node.device_info['model'] == 'c3600' \ and tmp_node.device_info['chassis'] == '3660': tmp_node.node['properties']['slot0'] = 'Leopard-2FE' for name in [ 'rom', 'nvram', 'bootflash', 'disk0', 'disk1', 'slot0', 'slot1' ]: self.datas.append({ 'old': os.path.join( 'working', tmp_node.device_info['model'] + '_' + device + '_' + name), 'new': tmp_node.device_info['model'] + '_i' + str(tmp_node.node['router_id']) + '_' + name }) # Calculate the router links tmp_node.calc_device_links() elif tmp_node.device_info['type'] == 'Cloud': try: tmp_node.calc_cloud_connection() except RuntimeError as err: print(err) elif tmp_node.device_info['type'] == 'FrameRelaySwitch': tmp_node.process_mappings() elif tmp_node.device_info['type'] == 'VirtualBoxVM': tmp_node.add_to_virtualbox() tmp_node.add_vm_ethernet_ports() tmp_node.calc_device_links() elif tmp_node.device_info['type'] == 'QemuVM': tmp_node.add_to_qemu() tmp_node.set_qemu_symbol() tmp_node.add_vm_ethernet_ports() tmp_node.calc_device_links() # Get the data we need back from the node instance self.links.extend(tmp_node.links) self.configs.extend(tmp_node.config) self.port_id += tmp_node.get_nb_added_ports(self.port_id) nodes.append(tmp_node.node) return nodes