Просмотр исходного кода

Merge branch 'master' of https://github.com/gvlproject/cloudbridge

nuwan_ag 10 лет назад
Родитель
Сommit
d984a362c0

+ 14 - 5
cloudbridge/providers/aws/resources.py

@@ -233,11 +233,20 @@ class AWSInstance(BaseInstance):
             'mac_address not implemented by this provider')
 
     @property
-    def security_group_ids(self):
-        """
-        Get the security group IDs associated with this instance.
-        """
-        return self._ec2_instance.groups
+    def security_groups(self):
+        """
+        Get the security groups associated with this instance.
+        """
+        # boto instance.groups field returns a ``Group`` object so need to
+        # convert that into a ``SecurityGroup`` object before creating a
+        # cloudbridge SecurityGroup object
+        security_groups = []
+        names = []
+        for group in self._ec2_instance.groups:
+            names.append(group.name)
+        security_groups = self.provider.security.security_groups.get(names)
+        return [AWSSecurityGroup(self.provider, group)
+                for group in security_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):