Просмотр исходного кода

Make subnet parameter mandatory and document relevant constraints

Nuwan Goonasekera 9 лет назад
Родитель
Сommit
6aff193dc2

+ 22 - 16
cloudbridge/cloud/interfaces/services.py

@@ -205,7 +205,7 @@ class InstanceService(PageableObjectMixin, CloudService):
         pass
 
     @abstractmethod
-    def create(self, name, image, instance_type, subnet=None, zone=None,
+    def create(self, name, image, instance_type, subnet, zone=None,
                key_pair=None, security_groups=None, user_data=None,
                launch_config=None,
                **kwargs):
@@ -224,33 +224,39 @@ class InstanceService(PageableObjectMixin, CloudService):
                               the instance to boot into
 
         :type  subnet:  ``Subnet`` or ``str``
-        :param subnet: The Subnet object or a subnet string ID with which the
-                       instance should be associated. If no subnet was
-                       specified, this method will attempt to find a 'default'
-                       network and launch the instance using that network (or
-                       subnet, as appropriate by the provider). A 'default'
-                       network is one tagged as such by the native API. If such
-                       tag or functionality does not exist, an attempt to
-                       create a new network (by default called
-                       'CloudBridgeNet') will be made. If that falls through,
-                       an attempt will be made to launch the instance without
-                       specifying the network parameter (this is under the
-                       assumption the private networking functionality is not
-                       available on the provider).
+        :param subnet: The subnet object or a subnet string ID with which the
+                       instance should be associated. The subnet is a mandatory
+                       parameter, and must be provided when launching an
+                       instance.
+
+                       Note: Older clouds (with classic networking), may not
+                       have proper subnet support and are not guaranteed to
+                       work. Some providers (e.g. OpenStack) support a null
+                       value but the behaviour is implementation specific.
 
         :type  zone: ``Zone`` or ``str``
         :param zone: The Zone or its name, where the instance should be placed.
+                     This parameter is provided for legacy compatibility (with
+                     classic networks).
+
+                     The subnet's placement zone will take precedence over this
+                     parameter, but in its absence, this value will be used.
 
         :type  key_pair: ``KeyPair`` or ``str``
         :param key_pair: The KeyPair object or its name, to set for the
                          instance.
 
         :type  security_groups: A ``list`` of ``SecurityGroup`` objects or a
-                                list of ``str`` names
+                                list of ``str`` object IDs
         :param security_groups: A list of ``SecurityGroup`` objects or a list
-                                of ``SecurityGroup`` names, which should be
+                                of ``SecurityGroup`` IDs, which should be
                                 assigned to this instance.
 
+                                The security groups must be associated with the
+                                same network as the supplied subnet. Use
+                                ``network.security_groups`` to retrieve a list
+                                of security groups belonging to a network.
+
         :type  user_data: ``str``
         :param user_data: An extra userdata object which is compatible with
                           the provider.

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

@@ -466,7 +466,7 @@ class AWSInstanceService(BaseInstanceService):
     def __init__(self, provider):
         super(AWSInstanceService, self).__init__(provider)
 
-    def create(self, name, image, instance_type, subnet=None, zone=None,
+    def create(self, name, image, instance_type, subnet, zone=None,
                key_pair=None, security_groups=None, user_data=None,
                launch_config=None, **kwargs):
         image_id = image.id if isinstance(image, MachineImage) else image

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

@@ -562,7 +562,7 @@ class OpenStackInstanceService(BaseInstanceService):
     def __init__(self, provider):
         super(OpenStackInstanceService, self).__init__(provider)
 
-    def create(self, name, image, instance_type, subnet=None, zone=None,
+    def create(self, name, image, instance_type, subnet, zone=None,
                key_pair=None, security_groups=None, user_data=None,
                launch_config=None,
                **kwargs):
@@ -593,7 +593,6 @@ class OpenStackInstanceService(BaseInstanceService):
         net = self._get_network(network_id)
 
         log.debug("Launching with net %s" % net)
-        print("(PR) Launching with net %s" % net)
         os_instance = self.provider.nova.servers.create(
             name,
             None if self._has_root_device(launch_config) else image_id,