Add uuid field to sliver
Sapan Bhatia [Tue, 20 Jan 2015 20:59:24 +0000 (20:59 +0000)]
planetstack/core/models/sliver.py
planetstack/openstack_observer/steps/sync_slivers.py

index 4d89d9f..d2f794f 100644 (file)
@@ -81,6 +81,7 @@ class Sliver(PlCoreBase):
     objects = SliverManager()
     deleted_objects = SliverDeletionManager()
     instance_id = models.CharField(null=True, blank=True, max_length=200, help_text="Nova instance id")
+    instance_uuid = models.CharField(null=True, blank=True, max_length=200, help_text="Nova instance uuid")
     name = models.CharField(max_length=200, help_text="Sliver name")
     instance_name = models.CharField(blank=True, null=True, max_length=200, help_text="OpenStack generated name")
     ip = models.GenericIPAddressField(help_text="Sliver ip address", blank=True, null=True)
index a2d0e81..8155c10 100644 (file)
@@ -124,9 +124,18 @@ class SyncSlivers(OpenStackSyncStep):
         if (len(res)!=2):
             raise Exception('Could not sync sliver %s'%sliver.slice.name)
         else:
-            sliver_id = res[1]['id'] # 0 is for the key
+            sliver_id = res[1]['info']['OS-EXT-SRV-ATTR:instance_name'] # 0 is for the key
+            sliver_uuid = res[1]['id'] # 0 is for the key
+
+            try:
+                hostname = res[1]['info']['OS-EXT-SRV-ATTR:hypervisor_hostname']
+                ip = socket.gethostbyname(hostname)
+                sliver.ip = ip
+            except:
+                pass
 
             sliver.instance_id = sliver_id
+            sliver.instance_uuid = sliver_uuid
             sliver.instance_name = sliver_name
             sliver.save()