Пример #1
0
    def disconnect_org_vdc_network(self, orgvdc_network_name):
        """Disconnect the vApp from an org vdc network.

        :param str orgvdc_network_name: (str): name of the orgvdc network to be
            disconnected.

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

        :rtype: lxml.objectify.ObjectifiedElement

        :raises: InvalidStateException: if the named org vdc network is not
            connected to the vApp.
        """
        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 None:
            raise InvalidStateException(
                "Org vdc network \'%s\' is not attached to the vApp" %
                orgvdc_network_name)
        else:
            network_configuration_section.remove(matched_orgvdc_network_config)

        return self.client.put_linked_resource(
            self.resource.NetworkConfigSection, RelationType.EDIT,
            EntityType.NETWORK_CONFIG_SECTION.value,
            network_configuration_section)
Пример #2
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_record_by_name(
            orgvdc_network_name).get('href')

        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)
Пример #3
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 orgvdc network.

        :param orgvdc_network_name: (str): name of the orgvdc network to be
            connected
        :param retain_ip: (bool): True if  the network resources such as
            IP/MAC of router will be retained across deployments.
        :param is_deployed: (bool): True if this orgvdc network has been
            deployed.
        :param fence_mode: (str): Controls connectivity to the parent
            network. One of bridged, isolated or natRouted. bridged by default.

        :return:  A :class:`lxml.objectify.StringElement` object representing
            the asynchronous task that is connecting the network.

        :raises: Exception: If orgvdc network does not exist in the vdc or if
        it is already connected to the vapp.
        """
        vdc = VDC(self.client,
                  href=find_link(self.resource, RelationType.UP,
                                 EntityType.VDC.value).href)
        orgvdc_networks = \
            vdc.list_orgvdc_network_resources(orgvdc_network_name)
        if len(orgvdc_networks) == 0:
            raise EntityNotFoundException(
                "Orgvdc network \'%s\' does not exist in vdc "
                "\'%s\'" %
                (orgvdc_network_name, vdc.get_resource().get('name')))
        orgvdc_network_href = orgvdc_networks[0].get('href')

        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(
                "Orgvdc 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)
Пример #4
0
    def _clone(self, source_vapp_name, target_vapp_name, target_vm_name,
               source_delete):
        """Clone VM from one vApp to another.

        :param: str source vApp name
        :param: str target vApp name
        :param: str target VM name
        :param: bool source delete option

        :return: an object containing EntityType.TASK XML data which represents
                 the asynchronous task that is copying VM

        :rtype: lxml.objectify.ObjectifiedElement
        """
        from pyvcloud.vcd.vapp import VApp
        vm_resource = self.get_resource()
        resource_type = ResourceType.VAPP.value
        if self.is_powered_off(vm_resource) or source_delete:
            records1 = self.___validate_vapp_records(
                vapp_name=source_vapp_name, resource_type=resource_type)

            source_vapp_href = records1[0].get('href')

            records2 = self.___validate_vapp_records(
                vapp_name=target_vapp_name, resource_type=resource_type)

            target_vapp_href = records2[0].get('href')

            source_vapp = VApp(self.client, href=source_vapp_href)
            target_vapp = VApp(self.client, href=target_vapp_href)
            target_vapp.reload()
            spec = {
                'vapp': source_vapp.get_resource(),
                'source_vm_name': self.get_resource().get('name'),
                'target_vm_name': target_vm_name
            }
            return target_vapp.add_vms([spec],
                                       deploy=False,
                                       power_on=False,
                                       all_eulas_accepted=True,
                                       source_delete=source_delete
                                       )
        else:
            raise InvalidStateException("VM Must be powered off.")
Пример #5
0
    def detach_vcenter(self, vc_name):
        """Detach (unregister) a Virtual Center (VC) server.

        :param str vc_name: name of VC server.

        :return: an object containing XML data of the VC server
            specifically, EntityType.VIRTUAL_CENTER

        :rtype: lxml.objectify.ObjectifiedElement
        """
        vc = self.get_vcenter(vc_name)
        if vc.IsEnabled:
            raise InvalidStateException('VC must be disabled before detach.')

        return self.client.\
            post_linked_resource(resource=vc,
                                 rel=RelationType.UNREGISTER,
                                 media_type=None,
                                 contents=vc)