Browse Source

Change the interface for method creating a security group to allow specification of a network under which to create the group. Add corresponding implementation for AWS.

Enis Afgan 10 years ago
parent
commit
815efcd3a0

+ 6 - 1
cloudbridge/cloud/interfaces/services.py

@@ -880,7 +880,7 @@ class SecurityGroupService(PageableObjectMixin, CloudService):
         pass
         pass
 
 
     @abstractmethod
     @abstractmethod
-    def create(self, name, description):
+    def create(self, name, description, network_id=None):
         """
         """
         Create a new SecurityGroup.
         Create a new SecurityGroup.
 
 
@@ -890,6 +890,11 @@ class SecurityGroupService(PageableObjectMixin, CloudService):
         :type description: str
         :type description: str
         :param description: The description of the new security group.
         :param description: The description of the new security group.
 
 
+        :type  network_id: ``str``
+        :param network_id: An optional network ID under which to create the
+                           security group that may be supported by some
+                           providers.
+
         :rtype: ``object`` of :class:`.SecurityGroup`
         :rtype: ``object`` of :class:`.SecurityGroup`
         :return:  A SecurityGroup instance or ``None`` if one was not created.
         :return:  A SecurityGroup instance or ``None`` if one was not created.
         """
         """

+ 7 - 2
cloudbridge/cloud/providers/aws/services.py

@@ -165,7 +165,7 @@ class AWSSecurityGroupService(BaseSecurityGroupService):
         return ClientPagedResultList(self.provider, sgs,
         return ClientPagedResultList(self.provider, sgs,
                                      limit=limit, marker=marker)
                                      limit=limit, marker=marker)
 
 
-    def create(self, name, description):
+    def create(self, name, description, network_id=None):
         """
         """
         Create a new SecurityGroup.
         Create a new SecurityGroup.
 
 
@@ -175,10 +175,15 @@ class AWSSecurityGroupService(BaseSecurityGroupService):
         :type description: str
         :type description: str
         :param description: The description of the new security group.
         :param description: The description of the new security group.
 
 
+        :type  network_id: ``str``
+        :param network_id: The ID of the VPC to create the security group in,
+                           if any.
+
         :rtype: ``object`` of :class:`.SecurityGroup`
         :rtype: ``object`` of :class:`.SecurityGroup`
         :return:  A SecurityGroup instance or ``None`` if one was not created.
         :return:  A SecurityGroup instance or ``None`` if one was not created.
         """
         """
-        sg = self.provider.ec2_conn.create_security_group(name, description)
+        sg = self.provider.ec2_conn.create_security_group(name, description,
+                                                          network_id)
         if sg:
         if sg:
             return AWSSecurityGroup(self.provider, sg)
             return AWSSecurityGroup(self.provider, sg)
         return None
         return None

+ 5 - 1
cloudbridge/cloud/providers/openstack/services.py

@@ -193,7 +193,7 @@ class OpenStackSecurityGroupService(BaseSecurityGroupService):
         return ClientPagedResultList(self.provider, sgs,
         return ClientPagedResultList(self.provider, sgs,
                                      limit=limit, marker=marker)
                                      limit=limit, marker=marker)
 
 
-    def create(self, name, description):
+    def create(self, name, description, network_id=None):
         """
         """
         Create a new security group under the current account.
         Create a new security group under the current account.
 
 
@@ -203,6 +203,10 @@ class OpenStackSecurityGroupService(BaseSecurityGroupService):
         :type description: str
         :type description: str
         :param description: The description of the new security group.
         :param description: The description of the new security group.
 
 
+        :type  network_id: ``None``
+        :param network_id: Not applicable for OpenStack (yet) so any value is
+                           ignored.
+
         :rtype: ``object`` of :class:`.SecurityGroup`
         :rtype: ``object`` of :class:`.SecurityGroup`
         :return: a SecurityGroup object
         :return: a SecurityGroup object
         """
         """