Ver Fonte

Add network_id property to SecurityGroup resource

Enis Afgan há 9 anos atrás
pai
commit
1e2e85cd5d

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

@@ -1844,6 +1844,16 @@ class SecurityGroup(CloudResource):
         """
         pass
 
+    @abstractproperty
+    def network_id(self):
+        """
+        Network ID with which this security group is associated.
+
+        :rtype: ``str``
+        :return: Provider-supplied network ID or ``None`` is not available.
+        """
+        pass
+
     @abstractproperty
     def rules(self):
         """

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

@@ -608,6 +608,10 @@ class AWSSecurityGroup(BaseSecurityGroup):
     def __init__(self, provider, security_group):
         super(AWSSecurityGroup, self).__init__(provider, security_group)
 
+    @property
+    def network_id(self):
+        return self._security_group.vpc_id
+
     @property
     def rules(self):
         return [AWSSecurityGroupRule(self._provider, r, self)

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

@@ -853,6 +853,15 @@ class OpenStackSecurityGroup(BaseSecurityGroup):
     def __init__(self, provider, security_group):
         super(OpenStackSecurityGroup, self).__init__(provider, security_group)
 
+    @property
+    def network_id(self):
+        """
+        OpenStack does not associate a SG with a network so default to None.
+
+        :return: Always return ``None``.
+        """
+        return None
+
     @property
     def rules(self):
         # Update SG object; otherwise, recently added rules do now show