def crt_secure_rmc_vif(adapter, instance, host_uuid): """Creates the Secure RMC Network Adapter on the VM. :param adapter: The pypowervm adapter API interface. :param instance: The nova instance to create the VIF against. :param host_uuid: The host system UUID. """ lpar_uuid = get_pvm_uuid(instance) cna.crt_cna(adapter, host_uuid, lpar_uuid, SECURE_RMC_VLAN, vswitch=SECURE_RMC_VSWITCH, crt_vswitch=True)
def crt_vif(adapter, instance, host_uuid, vif): """Will create a Client Network Adapter on the system. :param adapter: The pypowervm adapter API interface. :param instance: The nova instance to create the VIF against. :param host_uuid: The host system UUID. :param vif: The nova VIF that describes the ethernet interface. """ lpar_uuid = get_pvm_uuid(instance) # CNA's require a VLAN. If the network doesn't provide, default to 1 vlan = vif['network']['meta'].get('vlan', 1) cna.crt_cna(adapter, host_uuid, lpar_uuid, vlan, mac_addr=vif['address'])
def plug(self, vif, new_vif=True): """Plugs a virtual interface (network) into a VM. This method simply creates the client network adapter into the VM. :param vif: The virtual interface to plug into the instance. :param new_vif: (Optional, Default: True) If set, indicates that it is a brand new VIF. If False, it indicates that the VIF is already on the client but should be treated on the bridge. :return: The new vif that was created. Only returned if new_vif is set to True. Otherwise None is expected. """ # Do nothing if not a new VIF if not new_vif: return None lpar_uuid = vm.get_pvm_uuid(self.instance) # CNA's require a VLAN. The networking-powervm neutron agent puts this # in the vif details. vlan = int(vif['details']['vlan']) LOG.debug("Creating SEA-based VIF with VLAN %s", str(vlan), instance=self.instance) cna_w = pvm_cna.crt_cna(self.adapter, None, lpar_uuid, vlan, mac_addr=vif['address']) return cna_w
def test_crt_cna_new_vswitch(self, mock_vnet_find): """Validates the create will also create the vSwitch.""" # First need to load in the various test responses. vs = tju.load_file(VSWITCH_FILE) self.adpt.read.return_value = vs # Create a side effect that can validate the input into the create # call. def validate_of_create(*kargs, **kwargs): self.assertIsNotNone(kargs[0]) if 'LogicalPartition' == kargs[1]: self.assertEqual('LogicalPartition', kargs[1]) self.assertEqual('fake_lpar', kwargs.get('root_id')) self.assertEqual('ClientNetworkAdapter', kwargs.get('child_type')) return pvm_net.CNA.bld(self.adpt, 1, 'href').entry else: # Is the vSwitch create self.assertEqual('ManagedSystem', kargs[1]) self.assertEqual('VirtualSwitch', kwargs.get('child_type')) # Return a previously created vSwitch... return pvm_net.VSwitch.wrap(vs)[0].entry self.adpt.create.side_effect = validate_of_create n_cna = cna.crt_cna(self.adpt, 'fake_host', 'fake_lpar', 5, vswitch='Temp', crt_vswitch=True) self.assertIsNotNone(n_cna)
def test_crt_cna_no_vnet_crt(self, mock_vnet_find): """Tests the creation of Client Network Adapters. The virtual network creation shouldn't be done in this flow. """ # First need to load in the various test responses. vs = tju.load_file(VSWITCH_FILE) self.adpt.read.return_value = vs # PVMish Traits self.adptfx.set_traits(fx.LocalPVMTraits) # Create a side effect that can validate the input into the create # call. def validate_of_create(*kargs, **kwargs): self.assertIsNotNone(kargs[0]) self.assertEqual('LogicalPartition', kargs[1]) self.assertEqual('fake_lpar', kwargs.get('root_id')) self.assertEqual('ClientNetworkAdapter', kwargs.get('child_type')) return pvm_net.CNA.bld(self.adpt, 1, 'href').entry self.adpt.create.side_effect = validate_of_create n_cna = cna.crt_cna(self.adpt, 'fake_host', 'fake_lpar', 5) self.assertIsNotNone(n_cna) self.assertIsInstance(n_cna, pvm_net.CNA) self.assertEqual(0, mock_vnet_find.call_count)
def execute(self, vm_cnas): LOG.info('Plugging the Management Network Interface to instance.', instance=self.instance) # Determine if we need to create the secure RMC VIF. This should only # be needed if there is not a VIF on the secure RMC vSwitch vswitch = None vswitches = pvm_net.VSwitch.search( self.adapter, parent_type=pvm_ms.System.schema_type, parent_uuid=self.adapter.sys_uuid, name=SECURE_RMC_VSWITCH) if len(vswitches) == 1: vswitch = vswitches[0] if vswitch is None: LOG.warning('No management VIF created for instance due to lack ' 'of Management Virtual Switch', instance=self.instance) return None # This next check verifies that there are no existing NICs on the # vSwitch, so that the VM does not end up with multiple RMC VIFs. if vm_cnas is None: has_mgmt_vif = vm.get_cnas(self.adapter, self.instance, vswitch_uri=vswitch.href) else: has_mgmt_vif = vswitch.href in [cna.vswitch_uri for cna in vm_cnas] if has_mgmt_vif: LOG.debug('Management VIF already created for instance', instance=self.instance) return None lpar_uuid = vm.get_pvm_uuid(self.instance) return pvm_cna.crt_cna(self.adapter, None, lpar_uuid, SECURE_RMC_VLAN, vswitch=SECURE_RMC_VSWITCH, crt_vswitch=True)
def plug_secure_rmc_vif(adapter, instance, host_uuid, slot_mgr): """Creates the Secure RMC Network Adapter on the VM. :param adapter: The pypowervm adapter API interface. :param instance: The nova instance to create the VIF against. :param host_uuid: The host system UUID. :param slot_mgr: A NovaSlotManager. Used to store/retrieve the client slots used when a VIF is attached to the VM :return: The created network adapter wrapper. """ # Gather the mac and slot number for the mgmt vif mac, slot_num = slot_mgr.build_map.get_mgmt_vea_slot() # Create the adapter. lpar_uuid = vm.get_pvm_uuid(instance) cna_w = pvm_cna.crt_cna(adapter, host_uuid, lpar_uuid, SECURE_RMC_VLAN, vswitch=SECURE_RMC_VSWITCH, crt_vswitch=True, slot_num=slot_num, mac_addr=mac) # Save the mgmt vif to the slot map. if not mac: slot_mgr.register_cna(cna_w) return cna_w
def test_crt_cna_no_vnet_crt(self, mock_vnet_find): """Tests the creation of Client Network Adapters. The virtual network creation shouldn't be done in this flow. """ # PVMish Traits self.adptfx.set_traits(fx.LocalPVMTraits) self.adpt.read.return_value = self.resp # Create a side effect that can validate the input into the create # call. def validate_of_create(*kargs, **kwargs): self.assertIsNotNone(kargs[0]) self.assertEqual('LogicalPartition', kargs[1]) self.assertEqual('fake_lpar', kwargs.get('root_id')) self.assertEqual('ClientNetworkAdapter', kwargs.get('child_type')) return pvm_net.CNA.bld(self.adpt, 1, 'href').entry self.adpt.create.side_effect = validate_of_create n_cna = cna.crt_cna(self.adpt, None, 'fake_lpar', 5, slot_num=1) self.assertIsNotNone(n_cna) self.assertIsInstance(n_cna, pvm_net.CNA) self.assertEqual(0, mock_vnet_find.call_count)
def crt_secure_rmc_vif(adapter, instance, host_uuid): """Creates the Secure RMC Network Adapter on the VM. :param adapter: The pypowervm adapter API interface. :param instance: The nova instance to create the VIF against. :param host_uuid: The host system UUID. :return: The created network adapter wrapper. """ lpar_uuid = get_pvm_uuid(instance) return cna.crt_cna(adapter, host_uuid, lpar_uuid, SECURE_RMC_VLAN, vswitch=SECURE_RMC_VSWITCH, crt_vswitch=True)
def crt_vif(adapter, instance, host_uuid, vif): """Will create a Client Network Adapter on the system. :param adapter: The pypowervm adapter API interface. :param instance: The nova instance to create the VIF against. :param host_uuid: The host system UUID. :param vif: The nova VIF that describes the ethernet interface. :return: The created network adapter wrapper. """ lpar_uuid = get_pvm_uuid(instance) # CNA's require a VLAN. If the network doesn't provide, default to 1 vlan = vif["network"]["meta"].get("vlan", 1) return cna.crt_cna(adapter, host_uuid, lpar_uuid, vlan, mac_addr=vif["address"])
def crt_vif(adapter, instance, host_uuid, vif): """Will create a Client Network Adapter on the system. :param adapter: The pypowervm adapter API interface. :param instance: The nova instance to create the VIF against. :param host_uuid: The host system UUID. :param vif: The nova VIF that describes the ethernet interface. :return: The created network adapter wrapper. """ lpar_uuid = get_pvm_uuid(instance) # CNA's require a VLAN. If the network doesn't provide, default to 1 vlan = vif['network']['meta'].get('vlan', 1) return cna.crt_cna(adapter, host_uuid, lpar_uuid, vlan, mac_addr=vif['address'])
def plug(self, vif, slot_num): """Plugs a virtual interface (network) into a VM. This method simply creates the client network adapter into the VM. :param vif: The virtual interface to plug into the instance. :param slot_num: Which slot number to plug the VIF into. May be None. """ lpar_uuid = vm.get_pvm_uuid(self.instance) # CNA's require a VLAN. If the network doesn't provide, default to 1 vlan = vif['network']['meta'].get('vlan', 1) cna_w = pvm_cna.crt_cna(self.adapter, self.host_uuid, lpar_uuid, vlan, mac_addr=vif['address'], slot_num=slot_num) return cna_w
def test_crt_cna(self, mock_vnet_find): """Tests the creation of Client Network Adapters.""" # Create a side effect that can validate the input into the create # call. def validate_of_create(*kargs, **kwargs): self.assertIsNotNone(kargs[0]) self.assertEqual('LogicalPartition', kargs[1]) self.assertEqual('fake_lpar', kwargs.get('root_id')) self.assertEqual('ClientNetworkAdapter', kwargs.get('child_type')) return pvm_net.CNA.bld(self.adpt, 1, 'href').entry self.adpt.create.side_effect = validate_of_create self.adpt.read.return_value = self.resp n_cna = cna.crt_cna(self.adpt, None, 'fake_lpar', 5) self.assertIsNotNone(n_cna) self.assertIsInstance(n_cna, pvm_net.CNA) self.assertEqual(1, mock_vnet_find.call_count)
def plug_secure_rmc_vif(adapter, instance, host_uuid, slot_mgr): """Creates the Secure RMC Network Adapter on the VM. :param adapter: The pypowervm adapter API interface. :param instance: The nova instance to create the VIF against. :param host_uuid: The host system UUID. :param slot_mgr: A NovaSlotManager. Used to store/retrieve the client slots used when a VIF is attached to the VM :return: The created network adapter wrapper. """ # Gather the mac and slot number for the mgmt vif mac, slot_num = slot_mgr.build_map.get_mgmt_vea_slot() if not mac: # This is either a deploy case or rebuild case. For remote restart, # mac will not be none, as it will be available from slot data. # Deploy case - mac is None at both slot and instance_system_metadata # and crt_cna will auto-generate it. # Rebuild case - mac is none from slot data but is available # at instance system_metadata. mac = instance.system_metadata.get('mgmt_interface_mac') # Create the adapter. lpar_uuid = vm.get_pvm_uuid(instance) cna_w = pvm_cna.crt_cna(adapter, host_uuid, lpar_uuid, SECURE_RMC_VLAN, vswitch=SECURE_RMC_VSWITCH, crt_vswitch=True, slot_num=slot_num, mac_addr=mac) # Save the mgmt vif to the slot map. # For the rebuild case, mac will be present but not slot_num. # For deploy case, both will be none. We want to register cna in both cases if not slot_num: slot_mgr.register_cna(cna_w) if cna_w.mac != mac: # Update instance system metadata to store instance management # interface mac address. instance.system_metadata.update({'mgmt_interface_mac': cna_w.mac}) return cna_w
def execute(self, vm_cnas): LOG.info('Plugging the Management Network Interface to instance.', instance=self.instance) # Determine if we need to create the secure RMC VIF. This should only # be needed if there is not a VIF on the secure RMC vSwitch vswitch = None vswitches = pvm_net.VSwitch.search( self.adapter, parent_type=pvm_ms.System.schema_type, parent_uuid=self.adapter.sys_uuid, name=SECURE_RMC_VSWITCH) if len(vswitches) == 1: vswitch = vswitches[0] if vswitch is None: LOG.warning( 'No management VIF created for instance due to lack ' 'of Management Virtual Switch', instance=self.instance) return None # This next check verifies that there are no existing NICs on the # vSwitch, so that the VM does not end up with multiple RMC VIFs. if vm_cnas is None: has_mgmt_vif = vm.get_cnas(self.adapter, self.instance, vswitch_uri=vswitch.href) else: has_mgmt_vif = vswitch.href in [cna.vswitch_uri for cna in vm_cnas] if has_mgmt_vif: LOG.debug('Management VIF already created for instance', instance=self.instance) return None lpar_uuid = vm.get_pvm_uuid(self.instance) return pvm_cna.crt_cna(self.adapter, None, lpar_uuid, SECURE_RMC_VLAN, vswitch=SECURE_RMC_VSWITCH, crt_vswitch=True)
def plug(self, vif, slot_num, new_vif=True): """Plugs a virtual interface (network) into a VM. This method simply creates the client network adapter into the VM. :param vif: The virtual interface to plug into the instance. :param slot_num: Which slot number to plug the VIF into. May be None. :param new_vif: (Optional, Default: True) If set, indicates that it is a brand new VIF. If False, it indicates that the VIF is already on the client but should be treated on the bridge. :return: The new vif that was created. Only returned if new_vif is set to True. Otherwise None is expected. """ # Do nothing if not a new VIF if not new_vif: return None lpar_uuid = vm.get_pvm_uuid(self.instance) # CNA's require a VLAN. Nova network puts it in network-meta. # The networking-powervm neutron agent will also send it, if so via # the vif details. vlan = vif['network']['meta'].get('vlan', None) if not vlan: vlan = int(vif['details']['vlan']) LOG.debug("Creating SEA based VIF with VLAN %s", str(vlan)) cna_w = pvm_cna.crt_cna(self.adapter, self.host_uuid, lpar_uuid, vlan, mac_addr=vif['address'], slot_num=slot_num) return cna_w