ソースを参照

Added method for obtaining the list of security_group_ids associated
with an instance.

Nuwan Goonasekera 10 年 前
コミット
d63a689a31

+ 10 - 0
cloudbridge/cloud/interfaces/resources.py

@@ -561,6 +561,16 @@ class Instance(ObjectLifeCycleMixin, CloudResource):
         """
         pass
 
+    @abstractproperty
+    def security_group_ids(self):
+        """
+        Get the IDs of the security groups associated with this instance.
+
+        :rtype: list or :class:``str`
+        :return: A list of the SecurityGroup IDs associated with this instance.
+        """
+        pass
+
     @abstractproperty
     def key_pair_name(self):
         """

+ 7 - 0
cloudbridge/cloud/providers/aws/resources.py

@@ -305,6 +305,13 @@ class AWSInstance(BaseInstance):
         return [self._provider.security.security_groups.get(group.id)
                 for group in self._ec2_instance.groups]
 
+    @property
+    def security_group_ids(self):
+        """
+        Get the security groups IDs associated with this instance.
+        """
+        return [group.id for group in self._ec2_instance.groups]
+
     @property
     def key_pair_name(self):
         """

+ 7 - 0
cloudbridge/cloud/providers/openstack/resources.py

@@ -322,6 +322,13 @@ class OpenStackInstance(BaseInstance):
         return [self._provider.security.security_groups.find(group['name'])[0]
                 for group in self._os_instance.security_groups]
 
+    @property
+    def security_group_ids(self):
+        """
+        Get the security groups IDs associated with this instance.
+        """
+        return [group['name'] for group in self._os_instance.security_groups]
+
     @property
     def key_pair_name(self):
         """

+ 4 - 0
test/test_compute_service.py

@@ -147,6 +147,10 @@ class CloudComputeServiceTestCase(ProviderTestBase):
             self.assertEqual(
                 test_instance.security_groups[0],
                 sg)
+            self.assertIsInstance(test_instance.security_group_ids, list)
+            self.assertEqual(
+                test_instance.security_group_ids[0],
+                sg.id)
             # Must have either a public or a private ip
             ip_private = test_instance.private_ips[0] \
                 if test_instance.private_ips else None