示例#1
0
    def connect_org_vdc_network(self,
                                orgvdc_network_name,
                                retain_ip=None,
                                is_deployed=None,
                                fence_mode=FenceMode.BRIDGED.value):
        """Connect the vApp to an org vdc network.

        :param str orgvdc_network_name: name of the org vdc network to be
            connected to.
        :param bool retain_ip: True, if  the network resources such as IP/MAC
            of router will be retained across deployments.
        :param bool is_deployed: True, if this org vdc network has been
            deployed.
        :param str fence_mode: mode of connectivity to the parent network.
            Acceptable values are 'bridged', 'isolated' or 'natRouted'. Default
            value is 'bridged'.

        :return: an object containing EntityType.TASK XML data which represents
            the asynchronous task  that is connecting the vApp to the network.

        :rtype: lxml.objectify.ObjectifiedElement

        :raises: EntityNotFoundException: if named org vdc network does not
            exist.
        :raises: InvalidStateException: if the vApp is already connected to the
            org vdc network.
        """
        vdc = VDC(self.client,
                  href=find_link(self.resource, RelationType.UP,
                                 EntityType.VDC.value).href)
        orgvdc_network_href = vdc.get_orgvdc_network_admin_href_by_name(
            orgvdc_network_name)

        network_configuration_section = \
            deepcopy(self.resource.NetworkConfigSection)

        matched_orgvdc_network_config = \
            self._search_for_network_config_by_name(
                orgvdc_network_name, network_configuration_section)
        if matched_orgvdc_network_config is not None:
            raise InvalidStateException(
                "Org vdc network \'%s\' is already connected to "
                "vApp." % orgvdc_network_name)

        configuration = E.Configuration(
            E.ParentNetwork(href=orgvdc_network_href), E.FenceMode(fence_mode))
        if retain_ip is not None:
            configuration.append(E.RetainNetInfoAcrossDeployments(retain_ip))
        network_config = E.NetworkConfig(configuration,
                                         networkName=orgvdc_network_name)
        if is_deployed is not None:
            network_config.append(E.IsDeployed(is_deployed))
        network_configuration_section.append(network_config)

        return self.client.put_linked_resource(
            self.resource.NetworkConfigSection, RelationType.EDIT,
            EntityType.NETWORK_CONFIG_SECTION.value,
            network_configuration_section)