def test_update_vmi_host(self): vmi = VirtualMachineInterface( name='test-virtual-machine-interface', parent_obj=self.project) vmi.set_virtual_machine(self.virtual_machine) vmi.set_virtual_network(self.virtual_network_red) vmi.set_virtual_machine_interface_bindings( KeyValuePairs( key_value_pair=[KeyValuePair(key='vnic_type', value='direct'), KeyValuePair( key='host_id', value=self.node_red_hostname)])) vmi_uuid = self.api.virtual_machine_interface_create(vmi) self.check_vpg_exists( self.vlan_id_red, self.physical_interface_red.get_uuid() ) # update host vmi = self.api.virtual_machine_interface_read(id=vmi_uuid) vmi.set_virtual_machine_interface_bindings( KeyValuePairs( key_value_pair=[KeyValuePair(key='vnic_type', value='direct'), KeyValuePair( key='host_id', value=self.node_green_hostname)])) self.api.virtual_machine_interface_update(vmi) self.check_vpg_not_exist( self.vlan_id_red, self.physical_interface_red.get_uuid() ) self.check_vpg_exists( self.vlan_id_red, self.physical_interface_green.get_uuid() ) self.api.virtual_machine_interface_delete(id=vmi_uuid)
def test_single_vn_multiple_pi(self): vmi_red = VirtualMachineInterface( name='test-virtual-machine-interface-red', parent_obj=self.project) vmi_red.set_virtual_machine(self.virtual_machine) vmi_red.set_virtual_network(self.virtual_network_red) vmi_red.set_virtual_machine_interface_bindings( KeyValuePairs( key_value_pair=[KeyValuePair(key='vnic_type', value='direct'), KeyValuePair( key='host_id', value=self.node_red_hostname)])) vmi_red_uuid = self.api.virtual_machine_interface_create(vmi_red) vmi_green = VirtualMachineInterface( name='test-virtual-machine-interface-green', parent_obj=self.project) vmi_green.set_virtual_machine(self.virtual_machine) vmi_green.set_virtual_network(self.virtual_network_red) vmi_green.set_virtual_machine_interface_bindings( KeyValuePairs( key_value_pair=[KeyValuePair(key='vnic_type', value='direct'), KeyValuePair( key='host_id', value=self.node_green_hostname)])) vmi_green_uuid = self.api.virtual_machine_interface_create(vmi_green) self.check_vpg_exists( self.vlan_id_red, self.physical_interface_red.get_uuid() ) self.check_vpg_exists( self.vlan_id_red, self.physical_interface_green.get_uuid() ) self.api.virtual_machine_interface_delete(id=vmi_red_uuid) self.api.virtual_machine_interface_delete(id=vmi_green_uuid)
def _pre_create_virtual_router(self): # create virtual_router_red virtual_router_red = VirtualRouter(name='test-virtual-router-red') virtual_router_red.set_display_name(self.node_red_hostname) self.physnet = "test-physnet-red" virtual_router_red.set_virtual_router_sriov_physical_networks( KeyValuePairs( key_value_pair=[ KeyValuePair( key=self.physnet, value=self.port_red_display_name)])) virtual_router_red_uuid = \ self.api.virtual_router_create(virtual_router_red) self.virtual_router_red = \ self.api.virtual_router_read(id=virtual_router_red_uuid) # create virtual_router_green virtual_router_green = VirtualRouter(name='test-virtual-router-green') virtual_router_green.set_display_name(self.node_green_hostname) virtual_router_green.set_virtual_router_sriov_physical_networks( KeyValuePairs( key_value_pair=[ KeyValuePair( key=self.physnet, value=self.port_green_display_name)])) virtual_router_green_uuid = \ self.api.virtual_router_create(virtual_router_green) self.virtual_router_green = \ self.api.virtual_router_read(id=virtual_router_green_uuid)
def mockFabricObj(self): fabric_obj = Fabric(name='fab01') fabric_obj.uuid = FAB_UUID1 fabric_obj.fq_name = [DGSC, 'fab01'] cred = UserCredentials(username='******', password='******') credentials = DeviceCredential(credential=cred) fabric_credentials = DeviceCredentialList( device_credential=[credentials]) fabric_obj.set_fabric_credentials(fabric_credentials) fabric_obj.set_annotations(KeyValuePairs([ KeyValuePair(key='cli_sync_input', value=mock_job_template_input_schema)])) return fabric_obj
def create(self, context, pool): """ Create a loadbalancer_pool object. """ p = pool['pool'] tenant_id = self._get_tenant_id_for_create(context, p) project = self._project_read(project_id=tenant_id) if p['listener_id']: try: ll = self._api.loadbalancer_listener_read(id=p['listener_id']) except NoIdError: raise loadbalancerv2.EntityNotFound(name='Listener', id=p['listener_id']) project_id = ll.parent_uuid if str(uuid.UUID(tenant_id)) != project_id: raise NotAuthorized() else: ll = None pool_uuid = uuidutils.generate_uuid() name = self._get_resource_name('loadbalancer-pool', project, p['name'], pool_uuid) props = self.make_properties(p) id_perms = IdPermsType(enable=True, description=p['description']) pool = LoadbalancerPool(name, project, uuid=pool_uuid, loadbalancer_pool_properties=props, id_perms=id_perms, display_name=p['name']) if ll: pool_exists = ll.get_loadbalancer_pool_back_refs() if pool_exists is not None: raise loadbalancerv2.OnePoolPerListener( listener_id=p['listener_id'], pool_id=pool_exists[0]['uuid']) pool.set_loadbalancer_listener(ll) # Custom attributes if p['custom_attributes'] != ATTR_NOT_SPECIFIED: custom_attributes = KeyValuePairs() self.create_update_custom_attributes(p['custom_attributes'], custom_attributes) pool.set_loadbalancer_pool_custom_attributes(custom_attributes) self._api.loadbalancer_pool_create(pool) return self.make_dict(pool)
def _check_lb_members(self, *members): lb_pool = self._vnc_lib.loadbalancer_pool_read( id=self.pool_uid, fields=('loadbalancer-pool-loadbalancer-member',)) lb_members = lb_pool.get_loadbalancer_members() or () self.assertEqual(len(lb_members), len(members)) lb_members = [ self._vnc_lib.loadbalancer_member_read(id=member['uuid']) for member in lb_members] member_annotations = [member.annotations for member in lb_members] for vm_uid, vmi_uid in members: self.assertIn( KeyValuePairs([ KeyValuePair('vm', vm_uid), KeyValuePair('vmi', vmi_uid)]), member_annotations)
def update_properties(self, pool_db, id, p): props = pool_db.get_loadbalancer_pool_properties() change = False if self._update_pool_properties(props, p): pool_db.set_loadbalancer_pool_properties(props) change = True if 'custom_attributes' in p: custom_attributes = pool_db.get_loadbalancer_pool_custom_attributes() # Make sure to initialize custom_attributes if not custom_attributes: custom_attributes = KeyValuePairs() if self.create_update_custom_attributes(p['custom_attributes'], custom_attributes): pool_db.set_loadbalancer_pool_custom_attributes(custom_attributes) change = True return change
def mockFabric(self): try: fabric_obj = Fabric(name='fab01') fabric_obj.uuid = FAB_UUID1 fabric_obj.fq_name = [DGSC, 'fab01'] cred = UserCredentials(username='******', password='******') credentials = DeviceCredential(credential=cred) fabric_credentials = DeviceCredentialList( device_credential=[credentials]) fabric_obj.set_fabric_credentials(fabric_credentials) fabric_obj.set_annotations(KeyValuePairs([ KeyValuePair(key='cli_sync_input', value=mock_job_template_input_schema)])) self._vnc_lib.fabric_create(fabric_obj) except RefsExistError: logger.info("Fabric {} already exists".format('fab01')) except Exception as ex: logger.error("ERROR creating fabric {}: {}".format('fab01', ex))
def create_virtual_machine(self, name, vn, ipaddress): vm = VirtualMachine(name) self._vnc_lib.virtual_machine_create(vm) VirtualMachineKM.locate(vm.uuid) vmi = VirtualMachineInterface(parent_type='virtual-machine', fq_name=[name, '0']) vmi.set_virtual_machine(vm) vmi.set_virtual_network(vn) if DBBaseKM.is_nested(): vmi.set_virtual_machine_interface_bindings( KeyValuePairs([KeyValuePair('host_id', 'WHATEVER')])) self._vnc_lib.virtual_machine_interface_create(vmi) VirtualMachineInterfaceKM.locate(vmi.uuid) ip = InstanceIp(vm.name + '.0') ip.set_virtual_machine_interface(vmi) ip.set_virtual_network(vn) ip.set_instance_ip_address(ipaddress) self._vnc_lib.instance_ip_create(ip) InstanceIpKM.locate(ip.uuid) return vm, vmi, ip
def test_create_service_instance(self): sas_name = 'sas-1' + self.id() sas_fq_name = ['default-global-system-config', sas_name] sas = ServiceApplianceSet( fq_name=sas_fq_name, parent_type='global-system-config', service_appliance_set_virtualization_type='physical-device') self._vnc_lib.service_appliance_set_create(sas) sa_name = 'sa-1' + self.id() sa_fq_name = ['default-global-system-config', sas_name, sa_name] sa = ServiceAppliance( fq_name=sa_fq_name, parent_type='service-appliance-set', service_appliance_virtualization_type='physical-device') sa.set_service_appliance_properties( KeyValuePairs([ KeyValuePair(key='left-attachment-point', value=self.pi1_0_fq), KeyValuePair(key='right-attachment-point', value=self.pi1_1_fq) ])) attr = ServiceApplianceInterfaceType(interface_type='left') sa.add_physical_interface(self.pi2_0, attr) attr = ServiceApplianceInterfaceType(interface_type='right') sa.add_physical_interface(self.pi2_1, attr) self._vnc_lib.service_appliance_create(sa) tid, td = self.check_trans_info('Service Appliance', 'Create', sa_name, pr_name=self.pr1.name) st_name = 'st-1' + self.id() st_fq_name = ['default-domain', st_name] st = ServiceTemplate(fq_name=st_fq_name) st.set_service_appliance_set(sas) st.set_service_config_managed(False) svc_properties = ServiceTemplateType() svc_properties.set_service_virtualization_type('physical-device') if_type = ServiceTemplateInterfaceType(interface_type='left') svc_properties.add_interface_type(if_type) if_type = ServiceTemplateInterfaceType(interface_type='right') svc_properties.add_interface_type(if_type) st.set_service_template_properties(svc_properties) self._vnc_lib.service_template_create(st) self.check_trans_info(trans_id=tid, trans_descr=td, pr_name=self.pr1.name) si_name = 'si-' + self.id() si_fqn = ['default-domain', 'default-project', si_name] si = ServiceInstance(fq_name=si_fqn) si.fq_name = si_fqn si.add_service_template(st) kvp_array = [] kvp = KeyValuePair("left-svc-vlan", "100") kvp_array.append(kvp) kvp = KeyValuePair("right-svc-vlan", "101") kvp_array.append(kvp) kvp = KeyValuePair("left-svc-asns", "66000,66001") kvp_array.append(kvp) kvp = KeyValuePair("right-svc-asns", "66000,66002") kvp_array.append(kvp) kvps = KeyValuePairs() kvps.set_key_value_pair(kvp_array) si.set_annotations(kvps) props = ServiceInstanceType() props.set_service_virtualization_type('physical-device') props.set_ha_mode("active-standby") si.set_service_instance_properties(props) self._vnc_lib.service_instance_create(si) self.check_trans_info(trans_id=tid, trans_descr=td, pr_name=self.pr1.name) pt_name = 'pt-' + self.id() pt = PortTuple(pt_name, parent_obj=si) pt.add_logical_router(self.lr1) pt.add_logical_router(self.lr2) kvp_array = [] kvp = KeyValuePair("left-lr", self.lr1.uuid) kvp_array.append(kvp) kvp = KeyValuePair("right-lr", self.lr2.uuid) kvp_array.append(kvp) kvps = KeyValuePairs() kvps.set_key_value_pair(kvp_array) pt.set_annotations(kvps) self._vnc_lib.port_tuple_create(pt) self.check_trans_info('Service Instance', 'Create', si_name, pr_name=self.pr1.name) self._vnc_lib.port_tuple_delete(id=pt.uuid) self.check_trans_info('Service Instance', 'Delete', si_name, pr_name=self.pr1.name) self._vnc_lib.service_appliance_delete(fq_name=sa.fq_name) self.check_trans_info('Service Appliance', 'Delete', sa_name, pr_name=self.pr1.name)