def get_port_uuid(self, port): phy_device_fixture = PhysicalDeviceFixture(self.name, self.mgmt_ip) phy_device_fixture.setUp() phy_device_uuid = phy_device_fixture.phy_device.uuid pif_fixture = PhysicalInterfaceFixture(port, device_id=phy_device_uuid) pif_fixture.setUp() return pif_fixture.uuid
def get_port_uuid(self,port,inputs=None): phy_device_fixture=PhysicalDeviceFixture(self.name,self.mgmt_ip,inputs=inputs) phy_device_fixture.setUp() phy_device_uuid = phy_device_fixture.phy_device.uuid pif_fixture=PhysicalInterfaceFixture(name=port,device_id=phy_device_uuid,inputs=inputs) pif_fixture.setUp() return pif_fixture.uuid
def onboard_existing_fabric(self, fabric_dict, wait_for_finish=True, name=None, cleanup=False): interfaces = {'physical': [], 'logical': []} devices = list() name = get_random_name(name) if name else get_random_name('fabric') fq_name = [ 'default-global-system-config', 'existing_fabric_onboard_template' ] payload = {'fabric_fq_name': ["default-global-system-config", name], 'node_profiles': [{"node_profile_name": profile} for profile in fabric_dict.get('node_profiles')\ or NODE_PROFILES], 'device_auth': [{"username": cred['username'], "password": cred['password']} for cred in fabric_dict['credentials']], 'overlay_ibgp_asn': fabric_dict['namespaces']['asn'][0]['min'], 'management_subnets': [{"cidr": mgmt["cidr"]} for mgmt in fabric_dict['namespaces']['management']] } self.logger.info('Onboarding existing fabric %s %s' % (name, payload)) execution_id = self.vnc_h.execute_job(fq_name, payload) status, fabric = self._get_fabric_fixture(name) assert fabric, 'Create fabric seems to have failed' if cleanup: self.addCleanup(self.cleanup_fabric, fabric, devices, interfaces) if wait_for_finish: try: status = self.wait_for_job_to_finish(':'.join(fq_name), execution_id) except AssertionError: self.cleanup_fabric(fabric, verify=False) raise assert status, 'job %s to create fabric failed' % execution_id for device in fabric.fetch_associated_devices() or []: device_fixture = PhysicalDeviceFixture( connections=self.connections, name=device) device_fixture.read() device_fixture.add_csn() devices.append(device_fixture) for device in devices: for port in device.get_physical_ports(): pif = PhysicalInterfaceFixture( uuid=port, connections=self.connections) pif.read() interfaces['physical'].append(pif) for pif in interfaces['physical']: for port in pif.get_logical_ports(): lif = LogicalInterfaceFixture(uuid=port, connections=self.connections) lif.read() interfaces['logical'].append(lif) return (fabric, devices, interfaces)
def configure_l2_vlan(self, **kwargs): self.logger.info('Creating l2 vlan configuration for down link') l2_dict = kwargs.get('l2_dict') kwargs['fabric_fixture'] = self.fabric_fixture kwargs['host'] = l2_dict['mgmt_ip'] kwargs['username'] = l2_dict['ssh_username'] kwargs['password'] = l2_dict['ssh_password'] kwargs['name'] = l2_dict['name'] down_link = kwargs.get('down_link', False) device_fixture = PhysicalDeviceFixture(connections=self.connections, **kwargs) conn = device_fixture.get_connection_obj('juniper', **kwargs) kwargs['conn'] = conn if down_link: stmt = '''set interfaces {0} unit 0 family ethernet-switching interface-mode trunk set interfaces {0} unit 0 family ethernet-switching vlan members {1} set vlans {1} vlan-id {2}'''.format(kwargs.get('pi_name', ''), kwargs.get('vlan', ''), self.vlan_id or 0) else: links = kwargs.get('links', []) if len(links) > 1: kwargs['ae'] = True stmt_list = list() stmt_list.append( 'set chassis aggregated-devices ethernet device-count 28') for link in links: stmt1 = 'set interfaces {0} ether-options 802.3ad ae0'.format( link['local_port']) stmt_list.append(stmt1) stmt1 = '''set interfaces ae0 aggregated-ether-options lacp active set interfaces ae0 unit 0 family ethernet-switching interface-mode trunk set interfaces ae0 unit 0 family ethernet-switching vlan members {0} set vlans {0} vlan-id {1}'''.format( kwargs.get('vlan', ''), self.vlan_id or 0) stmt_list.extend(stmt1.split('\n')) stmt = '\n'.join(stmt_list) elif len(links) == 1: pi_name = links[0]['local_port'] kwargs['pi_name'] = pi_name stmt = '''set interfaces {0} unit 0 family ethernet-switching interface-mode trunk set interfaces {0} unit 0 family ethernet-switching vlan members {1} set vlans {1} vlan-id {2}'''.format( pi_name, kwargs.get('vlan', ''), self.vlan_id or 0) conn.config(stmt.split('\n')) self.addCleanup(self.delete_l2_vlan, **kwargs)
def createPhysicalRouter(self, pr_list, pr_params): self.pr_fixture = {} self.pr_list = pr_list self.pr_params = pr_params for self.pr_name in self.pr_list: self.pr_fixture[self.pr_name] = self.useFixture( PhysicalDeviceFixture( self.pr_name, self.pr_params[self.pr_name]['mgmt_ip'], vendor=self.pr_params[self.pr_name]['vendor'], model=self.pr_params[self.pr_name]['model'], ssh_username=self.pr_params[self.pr_name]['ssh_username'], ssh_password=self.pr_params[self.pr_name]['ssh_password'], tunnel_ip=self.pr_params[self.pr_name]['tunnel_ip'], set_netconf=self.pr_params[self.pr_name]['set_netconf'], connections=self.project_connections)) return self
def discover(self, fabric, wait_for_finish=True): devices = list() fq_name = ['default-global-system-config', 'discover_device_template'] payload = {'fabric_uuid': fabric.uuid} execution_id = self.vnc_h.execute_job(fq_name, payload) self.logger.info('Started device discovery for fabric %s'%( fabric.name)) self.addCleanup(self.cleanup_discover, fabric, devices) if wait_for_finish: status = self.wait_for_job_to_finish(':'.join(fq_name), execution_id) assert status, 'job %s to discover devices failed'%execution_id for device in fabric.fetch_associated_devices() or []: device_fixture = PhysicalDeviceFixture(connections=self.connections, name=device) device_fixture.read() device_fixture.add_csn() devices.append(device_fixture) self.logger.info('discovered devices %s for fabric %s'%( devices, fabric.name)) return execution_id, devices
def onboard_fabric(self, fabric_dict, wait_for_finish=True, name=None, cleanup=False, enterprise_style=True, dc_asn=None, serList=None): interfaces = {'physical': [], 'logical': []} devices = list() name = name if name else get_random_name('fabric') fq_name = ['default-global-system-config', 'fabric_onboard_template'] if 'image_upgrade_os_version' in list( fabric_dict['namespaces'].keys()): self.logger.info("ZTP with image upgrade") os_version = fabric_dict['namespaces']['image_upgrade_os_version'] else: self.logger.info("ZTP without image upgrade") os_version = '' payload = {'fabric_fq_name': ["default-global-system-config", name], 'fabric_display_name': name, "supplemental_day_0_cfg":[{"name": dct["supplemental_day_0_cfg"]["name"],\ "cfg": dct["supplemental_day_0_cfg"]["cfg"]} for dct in list(self.inputs.physical_routers_data.values()) \ if dct.get('supplemental_day_0_cfg') \ if serList is None or dct["serial_number"] in serList], 'device_to_ztp': [{"serial_number": dct['serial_number'], \ "hostname": dct['name'], \ "supplemental_day_0_cfg": dct.get("supplemental_day_0_cfg",{}).get('name','')} \ for dct in list(self.inputs.physical_routers_data.values()) \ if dct.get('serial_number') \ if serList is None or dct["serial_number"] in serList], 'node_profiles': [{"node_profile_name": profile} for profile in fabric_dict.get('node_profiles')\ or NODE_PROFILES], 'device_auth': {"root_password": fabric_dict['credentials'][0]['password']}, 'loopback_subnets': fabric_dict['namespaces']['loopback_subnets'], 'management_subnets': fabric_dict['namespaces']['management_subnets'], 'fabric_subnets': fabric_dict['namespaces']['fabric_subnets'], 'overlay_ibgp_asn': dc_asn or fabric_dict['namespaces']['overlay_ibgp_asn'], 'fabric_asn_pool': [{"asn_max": fabric_dict['namespaces']['asn'][0]['max'], "asn_min": fabric_dict['namespaces']['asn'][0]['min']}] } if os_version: payload['os_version'] = os_version self.logger.info('Onboarding new fabric %s %s' % (name, payload)) execution_id = self.vnc_h.execute_job(fq_name, payload) status, fabric = self._get_fabric_fixture(name) assert fabric, 'Create fabric seems to have failed' if cleanup: self.addCleanup(self.cleanup_fabric, fabric, devices, interfaces) if wait_for_finish: try: status = self.wait_for_job_to_finish(':'.join(fq_name), execution_id)[0] except AssertionError: self.cleanup_fabric(fabric, verify=False) raise assert status, 'job %s to create fabric failed' % execution_id for device in fabric.fetch_associated_devices() or []: device_dict = self.get_prouter_dict(device) device_fixture = PhysicalDeviceFixture( connections=self.connections, name=device) device_fixture.read() device_fixture.add_csn() devices.append(device_fixture) for device in devices: for port in device.get_physical_ports(): pif = PhysicalInterfaceFixture( uuid=port, connections=self.connections) pif.read() interfaces['physical'].append(pif) for pif in interfaces['physical']: for port in pif.get_logical_ports(): lif = LogicalInterfaceFixture(uuid=port, connections=self.connections) lif.read() interfaces['logical'].append(lif) return (fabric, devices, interfaces)
def create_physical_router(self, connections=None, **kwargs): ''' Refer PhysicalDeviceFixture for params info ''' connections = connections or self.connections return self.useFixture( PhysicalDeviceFixture(connections=connections, **kwargs))