Pārlūkot izejas kodu

When querying security groups for an instance, return cloudbridge SecurityGroup objects vs. native IDs

Enis Afgan 10 gadi atpakaļ
vecāks
revīzija
114ae70892

+ 4 - 3
cloudbridge/providers/aws/resources.py

@@ -233,11 +233,12 @@ class AWSInstance(BaseInstance):
             'mac_address not implemented by this provider')
 
     @property
-    def security_group_ids(self):
+    def security_groups(self):
         """
-        Get the security group IDs associated with this instance.
+        Get the security groups associated with this instance.
         """
-        return self._ec2_instance.groups
+        return [AWSSecurityGroup(self.provider, group)
+                for group in self._ec2_instance.groups]
 
     @property
     def key_pair_name(self):

+ 5 - 5
cloudbridge/providers/interfaces/resources.py

@@ -228,15 +228,15 @@ class Instance(ObjectLifeCycleMixin):
             'Instance.mac_address not implemented by this provider')
 
     @property
-    def security_group_ids(self):
+    def security_groups(self):
         """
-        Get the security group IDs associated with this instance.
+        Get the security groups associated with this instance.
 
-        :rtype: list
-        :return: A list of security group IDs associated with this instance.
+        :rtype: list or :class:``SecurityGroup`` objects
+        :return: A list of SecurityGroup objects associated with this instance.
         """
         raise NotImplementedError(
-            'Instance.security_group_ids not implemented by this provider')
+            'Instance.security_groups not implemented by this provider')
 
     @property
     def key_pair_name(self):

+ 9 - 5
cloudbridge/providers/openstack/resources.py

@@ -253,12 +253,16 @@ class OpenStackInstance(BaseInstance):
             'mac_address not implemented by this provider')
 
     @property
-    def security_group_ids(self):
+    def security_groups(self):
         """
-        Get the security group IDs associated with this instance.
+        Get the security groups associated with this instance.
         """
-        return [BaseSecurityGroup(group.id, group.name, group.description)
-                for group in self._os_instance.security_groups]
+        security_groups = []
+        for group in self._os_instance.security_groups:
+            security_groups.append(self.provider.nova.security_groups.find(
+                name=group.get('name')))
+        return [OpenStackSecurityGroup(self.provider, group)
+                for group in security_groups]
 
     @property
     def key_pair_name(self):
@@ -295,7 +299,7 @@ class OpenStackInstance(BaseInstance):
             self._os_instance.status = 'unknown'
 
     def __repr__(self):
-        return "<CB-OSInstance: {0}({1})>".format(self.name, self.instance_id)
+        return "<CB-OSInstance: {0} ({1})>".format(self.name, self.instance_id)
 
 
 class OpenStackRegion(Region):