Pārlūkot izejas kodu

Unify network interface config for AWS and OpenStack providers at the network ID level.

When launching instances with private networking, AWS requires a subnet ID while OpenStack requires a network ID. Until now, this distinction had to be made at the application level vs. within automatically CloudBridge. With this change, the network ID needs to be supplied for either provider. For AWS, CloudBridge will extract a subnet within the given network and use it. This clearly leads to less control for the application/user but it provides a uniform interface. We can revisit this implementation  after we see how it works in practice. Most likely, we will want to check for multiple subnets within a network and perhaps choose one with the largest available address range.
Enis Afgan 9 gadi atpakaļ
vecāks
revīzija
9d47b7fdce

+ 22 - 1
cloudbridge/cloud/providers/aws/resources.py

@@ -7,6 +7,7 @@ from cloudbridge.cloud.base.resources import BaseBucketObject
 from cloudbridge.cloud.base.resources import BaseInstance
 from cloudbridge.cloud.base.resources import BaseInstanceType
 from cloudbridge.cloud.base.resources import BaseKeyPair
+from cloudbridge.cloud.base.resources import BaseLaunchConfig
 from cloudbridge.cloud.base.resources import BaseMachineImage
 from cloudbridge.cloud.base.resources import BaseNetwork
 from cloudbridge.cloud.base.resources import BasePlacementZone
@@ -636,7 +637,7 @@ class AWSSecurityGroup(BaseSecurityGroup):
         try:
             if not isinstance(src_group, SecurityGroup):
                 src_group = self._provider.security.security_groups.get(
-                                src_group)
+                    src_group)
 
             if self._security_group.authorize(
                     ip_protocol=ip_protocol,
@@ -1011,3 +1012,23 @@ class AWSFloatingIP(BaseFloatingIP):
 
     def delete(self):
         return self._ip.delete()
+
+
+class AWSLaunchConfig(BaseLaunchConfig):
+
+    def __init__(self, provider):
+        super(AWSLaunchConfig, self).__init__(provider)
+
+    def add_network_interface(self, net_id):
+        """
+        Extract a subnet within the network identified by ``net_id``.
+
+        AWS requires a subnet ID to be supplied vs. a network (i.e., VPC) ID
+        so just pull out one subnet within the network (currently, the first
+        one).
+        """
+        net = self.provider.network.get(net_id)
+        sns = net.subnets()
+        if sns:
+            sn = sns[0]
+        self.network_interfaces.append(sn.id)

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

@@ -7,7 +7,6 @@ from boto.ec2.blockdevicemapping import BlockDeviceMapping
 from boto.ec2.blockdevicemapping import BlockDeviceType
 from boto.exception import EC2ResponseError
 
-from cloudbridge.cloud.base.resources import BaseLaunchConfig
 from cloudbridge.cloud.base.resources import ClientPagedResultList
 from cloudbridge.cloud.base.resources import ServerPagedResultList
 from cloudbridge.cloud.base.services import BaseBlockStoreService
@@ -42,6 +41,7 @@ from .resources import AWSFloatingIP
 from .resources import AWSInstance
 from .resources import AWSInstanceType
 from .resources import AWSKeyPair
+from .resources import AWSLaunchConfig
 from .resources import AWSMachineImage
 from .resources import AWSNetwork
 from .resources import AWSRegion
@@ -665,7 +665,7 @@ class AWSInstanceService(BaseInstanceService):
                 else None)
 
     def create_launch_config(self):
-        return BaseLaunchConfig(self.provider)
+        return AWSLaunchConfig(self.provider)
 
     def get(self, instance_id):
         """