def get_bdm_metadata(self, context, instance, block_device_info): """Builds a metadata object for instance devices, that maps the user provided tag to the hypervisor assigned device address. """ # block_device_info does not contain tags information. bdm_obj_list = objects.BlockDeviceMappingList.get_by_instance_uuid( context, instance.uuid) # create a map between BDM object and its device name. bdm_obj_map = {bdm.device_name: bdm for bdm in bdm_obj_list} bdm_metadata = [] for bdm in itertools.chain(block_device_info['block_device_mapping'], block_device_info['ephemerals'], [block_device_info['root_disk']]): # NOTE(claudiub): ephemerals have device_name instead of # mount_device. device_name = bdm.get('mount_device') or bdm.get('device_name') bdm_obj = bdm_obj_map.get(device_name) if bdm_obj and 'tag' in bdm_obj and bdm_obj.tag: bus = self._get_device_bus(bdm) device = objects.DiskMetadata(bus=bus, tags=[bdm_obj.tag]) bdm_metadata.append(device) return bdm_metadata
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import mock from oslo_serialization import jsonutils from nova import objects from nova.tests.unit.objects import test_objects fake_net_interface_meta = objects.NetworkInterfaceMetadata( mac='52:54:00:f6:35:8f', tags=['mytag1'], bus=objects.PCIDeviceBus(address='0000:00:03.0'), vlan=1000) fake_pci_disk_meta = objects.DiskMetadata( bus=objects.PCIDeviceBus(address='0000:00:09.0'), tags=['nfvfunc3']) fake_obj_devices_metadata = objects.InstanceDeviceMetadata( devices=[fake_net_interface_meta, fake_pci_disk_meta]) fake_devices_metadata = fake_obj_devices_metadata._to_json() fake_db_metadata = { 'created_at': None, 'updated_at': None, 'deleted_at': None, 'deleted': 0, 'id': 1, 'device_metadata': fake_obj_devices_metadata._to_json() } fake_old_db_metadata = dict(fake_db_metadata) # copy