def create_node()

in libcloud/compute/drivers/vcloud.py [0:0]


    def create_node(self, **kwargs):
        """
        Creates and returns node. If the source image is:
          - vApp template - a new vApp is instantiated from template
          - existing vApp - a new vApp is cloned from the source vApp. Can
                            not clone more vApps is parallel otherwise
                            resource busy error is raised.


        @inherits: :class:`NodeDriver.create_node`

        :keyword    image:  OS Image to boot on node. (required). Can be a
                            NodeImage or existing Node that will be cloned.
        :type       image:  :class:`NodeImage` or :class:`Node`

        :keyword    ex_network: Organisation's network name for attaching vApp
                                VMs to.
        :type       ex_network: ``str``

        :keyword    ex_vdc: Name of organisation's virtual data center where
                            vApp VMs will be deployed.
        :type       ex_vdc: ``str``

        :keyword    ex_vm_names: list of names to be used as a VM and computer
                                 name. The name must be max. 15 characters
                                 long and follow the host name requirements.
        :type       ex_vm_names: ``list`` of ``str``

        :keyword    ex_vm_cpu: number of virtual CPUs/cores to allocate for
                               each vApp VM.
        :type       ex_vm_cpu: ``int``

        :keyword    ex_vm_memory: amount of memory in MB to allocate for each
                                  vApp VM.
        :type       ex_vm_memory: ``int``

        :keyword    ex_vm_script: full path to file containing guest
                                  customisation script for each vApp VM.
                                  Useful for creating users & pushing out
                                  public SSH keys etc.
        :type       ex_vm_script: ``str``

        :keyword    ex_vm_script_text: content of guest customisation script
                                       for each vApp VM. Overrides ex_vm_script
                                       parameter.
        :type       ex_vm_script_text: ``str``

        :keyword    ex_vm_network: Override default vApp VM network name.
                                   Useful for when you've imported an OVF
                                   originating from outside of the vCloud.
        :type       ex_vm_network: ``str``

        :keyword    ex_vm_fence: Fence mode for connecting the vApp VM network
                                 (ex_vm_network) to the parent
                                 organisation network (ex_network).
        :type       ex_vm_fence: ``str``

        :keyword    ex_vm_ipmode: IP address allocation mode for all vApp VM
                                  network connections.
        :type       ex_vm_ipmode: ``str``

        :keyword    ex_deploy: set to False if the node shouldn't be deployed
                               (started) after creation
        :type       ex_deploy: ``bool``

        :keyword    ex_force_customization: Used to specify whether to force
                                            customization on deployment,
                                            if not set default value is False.
        :type       ex_force_customization: ``bool``

        :keyword    ex_clone_timeout: timeout in seconds for clone/instantiate
                                      VM operation.
                                      Cloning might be a time consuming
                                      operation especially when linked clones
                                      are disabled or VMs are created on
                                      different datastores.
                                      Overrides the default task completion
                                      value.
        :type       ex_clone_timeout: ``int``

        :keyword    ex_admin_password: set the node admin password explicitly.
        :type       ex_admin_password: ``str``

        :keyword    ex_description: Set a description for the vApp.
        :type       ex_description: ``str``
        """
        name = kwargs["name"]
        image = kwargs["image"]
        ex_vm_names = kwargs.get("ex_vm_names")
        ex_vm_cpu = kwargs.get("ex_vm_cpu")
        ex_vm_memory = kwargs.get("ex_vm_memory")
        ex_vm_script = kwargs.get("ex_vm_script")
        ex_vm_script_text = kwargs.get("ex_vm_script_text", None)
        ex_vm_fence = kwargs.get("ex_vm_fence", None)
        ex_network = kwargs.get("ex_network", None)
        ex_vm_network = kwargs.get("ex_vm_network", None)
        ex_vm_ipmode = kwargs.get("ex_vm_ipmode", None)
        ex_deploy = kwargs.get("ex_deploy", True)
        ex_force_customization = kwargs.get("ex_force_customization", False)
        ex_vdc = kwargs.get("ex_vdc", None)
        ex_clone_timeout = kwargs.get("ex_clone_timeout", DEFAULT_TASK_COMPLETION_TIMEOUT)
        ex_admin_password = kwargs.get("ex_admin_password", None)
        ex_description = kwargs.get("ex_description", None)

        self._validate_vm_names(ex_vm_names)
        self._validate_vm_cpu(ex_vm_cpu)
        self._validate_vm_memory(ex_vm_memory)
        self._validate_vm_fence(ex_vm_fence)
        self._validate_vm_ipmode(ex_vm_ipmode)
        ex_vm_script = self._validate_vm_script(ex_vm_script)

        # Some providers don't require a network link

        if ex_network:
            network_href = self._get_network_href(ex_network)
            network_elem = self.connection.request(get_url_path(network_href)).object
        else:
            network_elem = None

        vdc = self._get_vdc(ex_vdc)

        if self._is_node(image):
            vapp_name, vapp_href = self._clone_node(name, image, vdc, ex_clone_timeout)
        else:
            vapp_name, vapp_href = self._instantiate_node(
                name,
                image,
                network_elem,
                vdc,
                ex_vm_network,
                ex_vm_fence,
                ex_clone_timeout,
                description=ex_description,
            )

        self._change_vm_names(vapp_href, ex_vm_names)
        self._change_vm_cpu(vapp_href, ex_vm_cpu)
        self._change_vm_memory(vapp_href, ex_vm_memory)
        self._change_vm_script(vapp_href, ex_vm_script, ex_vm_script_text)
        self._change_vm_ipmode(vapp_href, ex_vm_ipmode)

        if ex_admin_password is not None:
            self.ex_change_vm_admin_password(vapp_href, ex_admin_password)

        # Power on the VM.

        if ex_deploy:
            res = self.connection.request(get_url_path(vapp_href))
            node = self._to_node(res.object)
            # Retry 3 times: when instantiating large number of VMs at the same
            # time some may fail on resource allocation
            retry = 3

            while True:
                try:
                    self.ex_deploy_node(node, ex_force_customization)

                    break
                except Exception:
                    if retry <= 0:
                        raise
                    retry -= 1
                    time.sleep(10)

        res = self.connection.request(get_url_path(vapp_href))
        node = self._to_node(res.object)

        return node