Misc CAL fixes
[osm/SO.git] / rwcal / plugins / vala / rwcal_openstack / rift / rwcal / openstack / utils / compute.py
index 6a800de..fa0bfaf 100644 (file)
@@ -185,14 +185,15 @@ class ComputeUtils(object):
         
         for vol in self.driver._cinder_volume_list:
             voldict = vol.to_dict()
-            if voldict['display_name'] == volume_ref:
-                if 'status' in voldict and voldict['status'] == 'available':
-                    return voldict['id']
-                else:
-                    self.log.error("Volume %s not in available state. Current state: %s",
+            if 'display_name' in voldict and voldict['display_name'] == volume_ref:
+                if 'status' in voldict:
+                    if voldict['status'] == 'available':
+                        return voldict['id']
+                    else:
+                        self.log.error("Volume %s not in available state. Current state: %s",
                                volume_ref, voldict['status'])
-                    raise VolumeValidateError("Volume with name %s found in incorrect (%s) state"
-                                         %(volume_ref, vol['status']))
+                        raise VolumeValidateError("Volume with name %s found in incorrect (%s) state"
+                                         %(volume_ref, voldict['status']))
 
         self.log.info("No volume found with matching name: %s ", volume_ref)
         raise VolumeValidateError("No volume found with matching name: %s " %(volume_ref))
@@ -210,7 +211,9 @@ class ComputeUtils(object):
         """
         kwargs = dict()
 
-        kwargs['boot_index'] = volume.boot_priority
+        if 'boot_priority' in volume:
+            # Rift-only field
+            kwargs['boot_index'] = volume.boot_priority
         if volume.has_field("image"):
             # Support image->volume
             kwargs['source_type'] = "image"
@@ -218,6 +221,7 @@ class ComputeUtils(object):
             kwargs['delete_on_termination'] = True
         elif "volume_ref" in volume:
             # Support volume-ref->volume (only ref)
+            # Rift-only field
             kwargs['source_type'] = "volume"
             kwargs['uuid'] = self.resolve_volume_n_validate(volume.volume_ref)
             kwargs['delete_on_termination'] = False
@@ -236,26 +240,16 @@ class ComputeUtils(object):
                 self.log.error("Unsupported device_type <%s> found for volume: %s",
                                volume.device_type, volume.name)
                 raise VolumeValidateError("Unsupported device_type <%s> found for volume: %s"
-                                          %(volume.device_type, volume.name))        
-        else:
-            self.log.error("Mandatory field <device_type> not specified for volume: %s",
-                           volume.name)
-            raise VolumeValidateError("Mandatory field <device_type> not specified for volume: %s"
-                                      %(volume.name))
+                                          %(volume.device_type, volume.name))
 
         if volume.has_field('device_bus'):
             if volume.device_bus in ['ide', 'virtio', 'scsi']:
                 kwargs['disk_bus'] = volume.device_bus
             else:
-                self.log.error("Unsupported device_bus <%s> found for volume: %s",
-                               volume.device_bus, volume.name)
-                raise VolumeValidateError("Unsupported device_bus <%s> found for volume: %s"
-                                          %(volume.device_bus, volume.name))        
-        else:
-            self.log.error("Mandatory field <device_bus> not specified for volume: %s",
-                           volume.name)
-            raise VolumeValidateError("Mandatory field <device_bus> not specified for volume: %s"
-                                      %(volume.name))
+                self.log.error("Unsupported device_type <%s> found for volume: %s",
+                               volume.device_type, volume.name)
+                raise VolumeValidateError("Unsupported device_type <%s> found for volume: %s"
+                                          %(volume.device_type, volume.name))
 
         return kwargs
             
@@ -580,10 +574,14 @@ class ComputeUtils(object):
                 volume.name = (v['device']).split('/')[2]
                 volume.volume_id = v['volumeId']
                 details = self.driver.cinder_volume_get(volume.volume_id)
-                for k, v in details.metadata.items():
-                    vd = volume.custom_meta_data.add()
-                    vd.name = k
-                    vd.value = v
+                try:
+                    # Rift only
+                    for k, v in details.metadata.items():
+                        vd = volume.custom_meta_data.add()
+                        vd.name = k
+                        vd.value = v
+                except Exception as e:
+                    pass
             except Exception as e:
                 self.log.exception("Exception %s occured during volume list parsing", str(e))
                 continue
@@ -629,9 +627,6 @@ class ComputeUtils(object):
         vdu.vdu_id = vm_info['id']
         vdu.cloud_type  = 'openstack'
 
-        if 'config_drive' in vm_info:
-            vdu.supplemental_boot_data.boot_data_drive = vm_info['config_drive']
-
         if 'image' in vm_info and 'id' in vm_info['image']:
             vdu.image_id = vm_info['image']['id']
 
@@ -662,7 +657,11 @@ class ComputeUtils(object):
                 ha = vdu.host_aggregate.add()
                 ha.from_dict(aggr.as_dict())
 
-        vdu.node_id, vdu.supplemental_boot_data = self._parse_vdu_boot_config_data(vm_info)
+        node_id, boot_data = self._parse_vdu_boot_config_data(vm_info)
+        if node_id:
+            vdu.node_id = node_id
+        if boot_data:
+            vdu.supplemental_boot_data = boot_data
 
         cp_list = self._parse_vdu_cp_info(vdu.vdu_id)
         for cp in cp_list: