소스 검색

Add network_id property to SecurityGroup resource

Enis Afgan 9 년 전
부모
커밋
1e2e85cd5d
3개의 변경된 파일23개의 추가작업 그리고 0개의 파일을 삭제
  1. 10 0
      cloudbridge/cloud/interfaces/resources.py
  2. 4 0
      cloudbridge/cloud/providers/aws/resources.py
  3. 9 0
      cloudbridge/cloud/providers/openstack/resources.py

+ 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