def handle_create(self): config_obj = self.vnc_lib().global_system_config_read( fq_name=["default-global-system-config"]) pr_obj = vnc_api.PhysicalRouter(name=self.properties[self.NAME], parent_obj=config_obj) pr_uuid = self.vnc_lib().physical_router_create(pr_obj) self.resource_id_set(pr_uuid)
def test_update_pis_empty_refs(vpg_service, vnc_api_client, fabric): pr = vnc_api.PhysicalRouter("qfx-1") pi = vnc_api.PhysicalInterface(name="pi-1", parent_obj=pr) pi.set_uuid("pi-1-uuid") previous_vpg = vnc_api.VirtualPortGroup(parent_obj=fabric) current_pis = [pi] vpg_service.update_pis_for_vpg(previous_vpg, current_pis) vnc_api_client.detach_pis_from_vpg.assert_called_once_with( previous_vpg, []) vnc_api_client.attach_pis_to_vpg.assert_called_once_with( previous_vpg, [pi])
def _make_fake_fabric(cls): fabric = vnc_api.Fabric('fabric01') cls._fabric_uuid = cls._vnc_api.fabric_create(fabric) cls._vnc_api.fabric_read(id=cls._fabric_uuid) cls._cleanup_fabric_queue.append(('fabric', cls._fabric_uuid)) for pr_name in cls.FABRIC: pr = vnc_api.PhysicalRouter(pr_name) pr.set_fabric(fabric) pr_uuid = cls._vnc_api.physical_router_create(pr) cls._cleanup_fabric_queue.append(('physical_router', pr_uuid)) for pi_name in cls.FABRIC[pr_name]: pi = vnc_api.PhysicalInterface(name=pi_name, parent_obj=pr) pi_uuid = cls._vnc_api.physical_interface_create(pi) cls._cleanup_fabric_queue.append( ('physical_interface', pi_uuid))
def test_create_vpg_in_vnc(vpg_model, vpg_service, vnc_api_client, database, fabric): pr = vnc_api.PhysicalRouter("qfx-1") pi = vnc_api.PhysicalInterface(name="pi-1", parent_obj=pr) pi.set_uuid("pi-1-uuid") vnc_api_client.read_pi.return_value = pi vnc_api_client.read_vpg.return_value = None vnc_api_client.read_fabric.return_value = fabric pi_model = models.PhysicalInterfaceModel("pi-1-uuid", "fabric-uuid", "esxi-1", "dvs-1") database.add_pi_model(pi_model) pi_models = [pi_model] vpg_service.create_vpg_in_vnc(vpg_model, pi_models) vnc_api_client.create_vpg.assert_called_once() vnc_api_client.read_fabric.assert_called_once_with(pi_model.fabric_uuid) vnc_api_client.read_pi.assert_called_once_with("pi-1-uuid")
def test_update_pis(vpg_service, vnc_api_client, fabric): pr = vnc_api.PhysicalRouter("qfx-1") pi_1 = vnc_api.PhysicalInterface(name="pi-1", parent_obj=pr) pi_2 = vnc_api.PhysicalInterface(name="pi-2", parent_obj=pr) pi_3 = vnc_api.PhysicalInterface(name="pi-3", parent_obj=pr) pi_1.set_uuid("pi-1-uuid") pi_2.set_uuid("pi-2-uuid") pi_3.set_uuid("pi-3-uuid") previous_vpg = vnc_api.VirtualPortGroup(parent_obj=fabric) previous_vpg.add_physical_interface(pi_1) previous_vpg.add_physical_interface(pi_2) current_pis = [pi_2, pi_3] vpg_service.update_pis_for_vpg(previous_vpg, current_pis) vnc_api_client.detach_pis_from_vpg.assert_called_once_with( previous_vpg, ["pi-1-uuid"]) vnc_api_client.attach_pis_to_vpg.assert_called_once_with( previous_vpg, [pi_3])
def physical_router_3(fabric_2): pr = vnc_api.PhysicalRouter(name="pr-2-1") pr.set_uuid("pr-uuid-2-1") pr.add_fabric(fabric_2) return pr
def physical_router_2(fabric_1): pr = vnc_api.PhysicalRouter(name="pr-1-2") pr.set_uuid("pr-uuid-1-2") pr.add_fabric(fabric_1) return pr
def physical_router(fabric): pr = vnc_api.PhysicalRouter("qfx-1") pr.set_uuid("pr-1-uuid") pr.add_fabric(fabric) return pr
def physical_router_4(): pr = vnc_api.PhysicalRouter(name="pr-2-2") pr.set_uuid("pr-uuid-2-2") return pr
password = admin_password, tenant_name = admin_tenant, auth_host = api_server, api_server_host=api_server, api_server_port=api_port) vrName = socket.gethostname() def get_ip_address(ifname): s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) return socket.inet_ntoa(fcntl.ioctl( s.fileno(), 0x8915, # SIOCGIFADDR struct.pack('256s', ifname[:15]) )[20:24]) vrIp = get_ip_address('vhost0') project = vnc_client.project_read(fq_name_str = 'default-domain:' + admin_tenant) virtualRouter = vnc_api.VirtualRouter(fq_name = [ 'default-global-system-config',vrName], name = vrName, virtual_router_type = [ 'embedded'], virtual_router_ip_address = vrIp) virtualRouterObject = vnc_client.virtual_router_create(virtualRouter) physicalRouter = vnc_api.PhysicalRouter(fq_name_str = 'default-global-system-config:'+vrName, name = vrName, physical_router_management_ip = vrIp) physicalRouter.add_virtual_router(ref_obj = virtualRouter) physicalRouterObj = vnc_client.physical_router_create(physicalRouter) phIntObj = vnc_api.PhysicalInterface(name = serviceInt, parent_obj = physicalRouter) phIntResult = vnc_client.physical_interface_create(phIntObj)
def handle_create(self): parent_obj = None if parent_obj is None and self.properties.get( self.GLOBAL_SYSTEM_CONFIG): try: parent_obj = self.vnc_lib().global_system_config_read( id=self.properties.get(self.GLOBAL_SYSTEM_CONFIG)) except vnc_api.NoIdError: parent_obj = self.vnc_lib().global_system_config_read( fq_name_str=self.properties.get(self.GLOBAL_SYSTEM_CONFIG)) except: parent_obj = None if parent_obj is None: raise Exception('Error: parent is not specified in template!') obj_0 = vnc_api.PhysicalRouter(name=self.properties[self.NAME], parent_obj=parent_obj) if self.properties.get(self.PHYSICAL_ROUTER_MANAGEMENT_IP) is not None: obj_0.set_physical_router_management_ip( self.properties.get(self.PHYSICAL_ROUTER_MANAGEMENT_IP)) if self.properties.get( self.PHYSICAL_ROUTER_SNMP_CREDENTIALS) is not None: obj_1 = vnc_api.SNMPCredentials() if self.properties.get( self.PHYSICAL_ROUTER_SNMP_CREDENTIALS, {}).get( self.PHYSICAL_ROUTER_SNMP_CREDENTIALS_VERSION) is not None: obj_1.set_version( self.properties.get( self.PHYSICAL_ROUTER_SNMP_CREDENTIALS, {}).get(self.PHYSICAL_ROUTER_SNMP_CREDENTIALS_VERSION)) if self.properties.get( self.PHYSICAL_ROUTER_SNMP_CREDENTIALS, {}).get(self.PHYSICAL_ROUTER_SNMP_CREDENTIALS_LOCAL_PORT ) is not None: obj_1.set_local_port( self.properties.get( self.PHYSICAL_ROUTER_SNMP_CREDENTIALS, {}).get( self.PHYSICAL_ROUTER_SNMP_CREDENTIALS_LOCAL_PORT)) if self.properties.get( self.PHYSICAL_ROUTER_SNMP_CREDENTIALS, {}).get( self.PHYSICAL_ROUTER_SNMP_CREDENTIALS_RETRIES) is not None: obj_1.set_retries( self.properties.get( self.PHYSICAL_ROUTER_SNMP_CREDENTIALS, {}).get(self.PHYSICAL_ROUTER_SNMP_CREDENTIALS_RETRIES)) if self.properties.get( self.PHYSICAL_ROUTER_SNMP_CREDENTIALS, {}).get( self.PHYSICAL_ROUTER_SNMP_CREDENTIALS_TIMEOUT) is not None: obj_1.set_timeout( self.properties.get( self.PHYSICAL_ROUTER_SNMP_CREDENTIALS, {}).get(self.PHYSICAL_ROUTER_SNMP_CREDENTIALS_TIMEOUT)) if self.properties.get( self.PHYSICAL_ROUTER_SNMP_CREDENTIALS, {}).get(self.PHYSICAL_ROUTER_SNMP_CREDENTIALS_V2_COMMUNITY ) is not None: obj_1.set_v2_community( self.properties.get(self.PHYSICAL_ROUTER_SNMP_CREDENTIALS, {}). get(self.PHYSICAL_ROUTER_SNMP_CREDENTIALS_V2_COMMUNITY)) if self.properties.get( self.PHYSICAL_ROUTER_SNMP_CREDENTIALS, {}).get(self.PHYSICAL_ROUTER_SNMP_CREDENTIALS_V3_SECURITY_NAME ) is not None: obj_1.set_v3_security_name( self.properties.get( self.PHYSICAL_ROUTER_SNMP_CREDENTIALS, {}).get( self. PHYSICAL_ROUTER_SNMP_CREDENTIALS_V3_SECURITY_NAME)) if self.properties.get( self.PHYSICAL_ROUTER_SNMP_CREDENTIALS, {}).get(self.PHYSICAL_ROUTER_SNMP_CREDENTIALS_V3_SECURITY_LEVEL ) is not None: obj_1.set_v3_security_level( self.properties.get(self.PHYSICAL_ROUTER_SNMP_CREDENTIALS, {}). get(self.PHYSICAL_ROUTER_SNMP_CREDENTIALS_V3_SECURITY_LEVEL )) if self.properties.get( self.PHYSICAL_ROUTER_SNMP_CREDENTIALS, {}).get( self.PHYSICAL_ROUTER_SNMP_CREDENTIALS_V3_SECURITY_ENGINE_ID ) is not None: obj_1.set_v3_security_engine_id( self.properties.get(self.PHYSICAL_ROUTER_SNMP_CREDENTIALS, {}). get(self. PHYSICAL_ROUTER_SNMP_CREDENTIALS_V3_SECURITY_ENGINE_ID) ) if self.properties.get( self.PHYSICAL_ROUTER_SNMP_CREDENTIALS, {}).get(self.PHYSICAL_ROUTER_SNMP_CREDENTIALS_V3_CONTEXT ) is not None: obj_1.set_v3_context( self.properties.get( self.PHYSICAL_ROUTER_SNMP_CREDENTIALS, {}).get( self.PHYSICAL_ROUTER_SNMP_CREDENTIALS_V3_CONTEXT)) if self.properties.get( self.PHYSICAL_ROUTER_SNMP_CREDENTIALS, {}).get( self.PHYSICAL_ROUTER_SNMP_CREDENTIALS_V3_CONTEXT_ENGINE_ID ) is not None: obj_1.set_v3_context_engine_id( self.properties.get(self.PHYSICAL_ROUTER_SNMP_CREDENTIALS, {}). get(self. PHYSICAL_ROUTER_SNMP_CREDENTIALS_V3_CONTEXT_ENGINE_ID)) if self.properties.get( self.PHYSICAL_ROUTER_SNMP_CREDENTIALS, {}).get( self. PHYSICAL_ROUTER_SNMP_CREDENTIALS_V3_AUTHENTICATION_PROTOCOL ) is not None: obj_1.set_v3_authentication_protocol( self.properties.get(self.PHYSICAL_ROUTER_SNMP_CREDENTIALS, {}). get(self. PHYSICAL_ROUTER_SNMP_CREDENTIALS_V3_AUTHENTICATION_PROTOCOL )) if self.properties.get( self.PHYSICAL_ROUTER_SNMP_CREDENTIALS, {}).get( self. PHYSICAL_ROUTER_SNMP_CREDENTIALS_V3_AUTHENTICATION_PASSWORD ) is not None: obj_1.set_v3_authentication_password( self.properties.get(self.PHYSICAL_ROUTER_SNMP_CREDENTIALS, {}). get(self. PHYSICAL_ROUTER_SNMP_CREDENTIALS_V3_AUTHENTICATION_PASSWORD )) if self.properties.get( self.PHYSICAL_ROUTER_SNMP_CREDENTIALS, {}).get( self.PHYSICAL_ROUTER_SNMP_CREDENTIALS_V3_PRIVACY_PROTOCOL ) is not None: obj_1.set_v3_privacy_protocol( self.properties.get(self.PHYSICAL_ROUTER_SNMP_CREDENTIALS, {}). get(self. PHYSICAL_ROUTER_SNMP_CREDENTIALS_V3_PRIVACY_PROTOCOL)) if self.properties.get( self.PHYSICAL_ROUTER_SNMP_CREDENTIALS, {}).get( self.PHYSICAL_ROUTER_SNMP_CREDENTIALS_V3_PRIVACY_PASSWORD ) is not None: obj_1.set_v3_privacy_password( self.properties.get(self.PHYSICAL_ROUTER_SNMP_CREDENTIALS, {}). get(self. PHYSICAL_ROUTER_SNMP_CREDENTIALS_V3_PRIVACY_PASSWORD)) if self.properties.get( self.PHYSICAL_ROUTER_SNMP_CREDENTIALS, {}).get(self.PHYSICAL_ROUTER_SNMP_CREDENTIALS_V3_ENGINE_ID ) is not None: obj_1.set_v3_engine_id( self.properties.get(self.PHYSICAL_ROUTER_SNMP_CREDENTIALS, {}). get(self.PHYSICAL_ROUTER_SNMP_CREDENTIALS_V3_ENGINE_ID)) if self.properties.get( self.PHYSICAL_ROUTER_SNMP_CREDENTIALS, {}).get(self.PHYSICAL_ROUTER_SNMP_CREDENTIALS_V3_ENGINE_BOOTS ) is not None: obj_1.set_v3_engine_boots( self.properties.get(self.PHYSICAL_ROUTER_SNMP_CREDENTIALS, {}). get(self.PHYSICAL_ROUTER_SNMP_CREDENTIALS_V3_ENGINE_BOOTS)) if self.properties.get( self.PHYSICAL_ROUTER_SNMP_CREDENTIALS, {}).get(self.PHYSICAL_ROUTER_SNMP_CREDENTIALS_V3_ENGINE_TIME ) is not None: obj_1.set_v3_engine_time( self.properties.get(self.PHYSICAL_ROUTER_SNMP_CREDENTIALS, {}). get(self.PHYSICAL_ROUTER_SNMP_CREDENTIALS_V3_ENGINE_TIME)) obj_0.set_physical_router_snmp_credentials(obj_1) if self.properties.get(self.DISPLAY_NAME) is not None: obj_0.set_display_name(self.properties.get(self.DISPLAY_NAME)) if self.properties.get(self.PHYSICAL_ROUTER_VENDOR_NAME) is not None: obj_0.set_physical_router_vendor_name( self.properties.get(self.PHYSICAL_ROUTER_VENDOR_NAME)) if self.properties.get(self.PHYSICAL_ROUTER_PRODUCT_NAME) is not None: obj_0.set_physical_router_product_name( self.properties.get(self.PHYSICAL_ROUTER_PRODUCT_NAME)) if self.properties.get( self.PHYSICAL_ROUTER_USER_CREDENTIALS) is not None: obj_1 = vnc_api.UserCredentials() if self.properties.get( self.PHYSICAL_ROUTER_USER_CREDENTIALS, {} ).get(self.PHYSICAL_ROUTER_USER_CREDENTIALS_USERNAME) is not None: obj_1.set_username( self.properties.get( self.PHYSICAL_ROUTER_USER_CREDENTIALS, {}).get( self.PHYSICAL_ROUTER_USER_CREDENTIALS_USERNAME)) if self.properties.get( self.PHYSICAL_ROUTER_USER_CREDENTIALS, {} ).get(self.PHYSICAL_ROUTER_USER_CREDENTIALS_PASSWORD) is not None: obj_1.set_password( self.properties.get( self.PHYSICAL_ROUTER_USER_CREDENTIALS, {}).get( self.PHYSICAL_ROUTER_USER_CREDENTIALS_PASSWORD)) obj_0.set_physical_router_user_credentials(obj_1) if self.properties.get(self.PHYSICAL_ROUTER_VNC_MANAGED) is not None: obj_0.set_physical_router_vnc_managed( self.properties.get(self.PHYSICAL_ROUTER_VNC_MANAGED)) if self.properties.get(self.PHYSICAL_ROUTER_DATAPLANE_IP) is not None: obj_0.set_physical_router_dataplane_ip( self.properties.get(self.PHYSICAL_ROUTER_DATAPLANE_IP)) if self.properties.get( self.PHYSICAL_ROUTER_JUNOS_SERVICE_PORTS) is not None: obj_1 = vnc_api.JunosServicePorts() if self.properties.get( self.PHYSICAL_ROUTER_JUNOS_SERVICE_PORTS, {}).get(self.PHYSICAL_ROUTER_JUNOS_SERVICE_PORTS_SERVICE_PORT ) is not None: for index_1 in range( len( self.properties.get( self.PHYSICAL_ROUTER_JUNOS_SERVICE_PORTS, {}). get(self. PHYSICAL_ROUTER_JUNOS_SERVICE_PORTS_SERVICE_PORT ))): obj_1.add_service_port( self.properties.get( self.PHYSICAL_ROUTER_JUNOS_SERVICE_PORTS, {} ).get(self. PHYSICAL_ROUTER_JUNOS_SERVICE_PORTS_SERVICE_PORT) [index_1]) obj_0.set_physical_router_junos_service_ports(obj_1) # reference to virtual_router_refs if self.properties.get(self.VIRTUAL_ROUTER_REFS): for index_0 in range( len(self.properties.get(self.VIRTUAL_ROUTER_REFS))): try: ref_obj = self.vnc_lib().virtual_router_read( id=self.properties.get( self.VIRTUAL_ROUTER_REFS)[index_0]) except vnc_api.NoIdError: ref_obj = self.vnc_lib().virtual_router_read( fq_name_str=self.properties.get( self.VIRTUAL_ROUTER_REFS)[index_0]) obj_0.add_virtual_router(ref_obj) # reference to bgp_router_refs if self.properties.get(self.BGP_ROUTER_REFS): for index_0 in range(len(self.properties.get( self.BGP_ROUTER_REFS))): try: ref_obj = self.vnc_lib().bgp_router_read( id=self.properties.get(self.BGP_ROUTER_REFS)[index_0]) except vnc_api.NoIdError: ref_obj = self.vnc_lib().bgp_router_read( fq_name_str=self.properties.get( self.BGP_ROUTER_REFS)[index_0]) obj_0.add_bgp_router(ref_obj) # reference to virtual_network_refs if self.properties.get(self.VIRTUAL_NETWORK_REFS): for index_0 in range( len(self.properties.get(self.VIRTUAL_NETWORK_REFS))): try: ref_obj = self.vnc_lib().virtual_network_read( id=self.properties.get( self.VIRTUAL_NETWORK_REFS)[index_0]) except vnc_api.NoIdError: ref_obj = self.vnc_lib().virtual_network_read( fq_name_str=self.properties.get( self.VIRTUAL_NETWORK_REFS)[index_0]) obj_0.add_virtual_network(ref_obj) try: obj_uuid = super(ContrailPhysicalRouter, self).resource_create(obj_0) except: raise Exception( _('physical-router %s could not be updated.') % self.name) self.resource_id_set(obj_uuid)
def create_physical_router(self, pr_name, fabric): physical_router = vnc_api.PhysicalRouter(pr_name) physical_router.add_fabric(fabric) uuid = self.vnc_lib.physical_router_create(physical_router) return self.read_physical_router(uuid)