Пример #1
0
    def edit_name_and_description(self, name, description=None):
        """Edit name and description of the vApp.

        :param str name: New name of the vApp. It is mandatory.
        :param str description: New description of the vApp.

        :return: object containing EntityType.TASK XML data
            representing the asynchronous task.

        :rtype: lxml.objectify.ObjectifiedElement
        """
        if name is None or name.isspace():
            raise InvalidParameterException("Name can't be None or empty")
        vapp = self.get_resource()
        vapp.set('name', name.strip())
        if description is not None:
            if hasattr(vapp, 'Description'):
                vapp.replace(vapp.Description, E.Description(description))
            else:
                vapp.LeaseSettingsSection.addprevious(
                    E.Description(description))

        return self.client.put_linked_resource(self.resource,
                                               RelationType.EDIT,
                                               EntityType.VAPP.value, vapp)
Пример #2
0
    def update_vapp_network(self, network_name, new_net_name, new_net_desc):
        """Update a vApp network.

        :param str network_name: name of vApp network to be updated.
        :param str new_net_name: name of vApp network to be updated.
        :param str new_net_desc: description of vApp network to be updated.
        :return: an object containing EntityType.TASK XML data which represents
            the asynchronous task that is updating the vApp network.
        :rtype: lxml.objectify.ObjectifiedElement
        """
        # find the required network
        for network_config in self.resource.NetworkConfigSection.NetworkConfig:
            if network_config.get("networkName") == network_name:
                if new_net_name:
                    network_config.set('networkName', new_net_name)
                if new_net_desc:
                    if hasattr(network_config, 'Description'):
                        network_config.Description = E.Description(
                            new_net_desc)
                    else:
                        network_config.insert(0, E.Description(new_net_desc))
                return self.client.put_linked_resource(
                    self.resource.NetworkConfigSection, RelationType.EDIT,
                    EntityType.NETWORK_CONFIG_SECTION.value,
                    self.resource.NetworkConfigSection)
        raise EntityNotFoundException('Can\'t find network \'%s\'' %
                                      network_name)
Пример #3
0
 def upload_media(self,
                  catalog_name,
                  file_name,
                  item_name=None,
                  description='',
                  chunk_size=DEFAULT_CHUNK_SIZE,
                  callback=None):
     stat_info = os.stat(file_name)
     catalog = self.get_catalog(catalog_name)
     if item_name is None:
         item_name = os.path.basename(file_name)
     image_type = os.path.splitext(item_name)[1][1:]
     media = E.Media(name=item_name,
                     size=str(stat_info.st_size),
                     imageType=image_type)
     media.append(E.Description(description))
     catalog_item = self.client.post_resource(
         catalog.get('href') + '/action/upload', media,
         EntityType.MEDIA.value)
     entity = self.client.get_resource(catalog_item.Entity.get('href'))
     file_href = entity.Files.File.Link.get('href')
     return self.upload_file(file_name,
                             file_href,
                             chunk_size=chunk_size,
                             callback=callback)
Пример #4
0
    def update_disk(self,
                    name=None,
                    disk_id=None,
                    new_name=None,
                    new_size=None,
                    new_description=None,
                    new_storage_profile_name=None,
                    new_iops=None):
        """Update an existing independent disk.

        :param name: (str): The name of the existing disk.
        :param disk_id: (str): The id of the existing disk.
        :param new_name: (str): The new name of the disk.
        :param new_size: (int): The new size of the disk in bytes.
        :param new_description: (str): The new description of the disk.
        :param new_storage_profile_name: (str): The new storage profile that
            the disk will be moved to.
        :param new_iops: (int): The new iops requirement of the disk.

        :return:  A :class:`lxml.objectify.StringElement` object describing
            the asynchronous task updating the disk.

        :raises: Exception: If the named disk cannot be located or some
            other error occurs.
        """
        if self.resource is None:
            self.resource = self.client.get_resource(self.href)

        if disk_id is not None:
            disk = self.get_disk(disk_id=disk_id)
        else:
            disk = self.get_disk(name=name)

        disk_params = E.Disk()
        if new_name is not None:
            disk_params.set('name', new_name)
        else:
            disk_params.set('name', disk.get('name'))

        if new_size is not None:
            disk_params.set('size', str(new_size))
        else:
            disk_params.set('size', disk.get('size'))

        if new_description is not None:
            disk_params.append(E.Description(new_description))

        if new_storage_profile_name is not None:
            new_sp = self.get_storage_profile(new_storage_profile_name)
            disk_params.append(
                E.StorageProfile(name=new_storage_profile_name,
                                 href=new_sp.get('href'),
                                 type=new_sp.get('type')))

        if new_iops is not None:
            disk_params.set('iops', str(new_iops))

        return self.client.put_linked_resource(disk, RelationType.EDIT,
                                               EntityType.DISK.value,
                                               disk_params)
Пример #5
0
    def edit_name_description_and_shared_state(self,
                                               name,
                                               description=None,
                                               is_shared=None):
        """Edit name, description and shared state of the org vdc network.

        :param str name: New name of org vdc network. It is mandatory.
        :param str description: New description of org vdc network
        :param bool is_shared: True if user want to share else False.

        :return: object containing EntityType.TASK XML data
            representing the asynchronous task.

        :rtype: lxml.objectify.ObjectifiedElement
        """
        if name is None:
            raise InvalidParameterException("Name can't be None or empty")
        vdc_network = self.get_resource()
        vdc_network.set('name', name)
        if description is not None:
            vdc_network.Description = E.Description(description)
        if is_shared is not None:
            vdc_network.IsShared = E.IsShared(is_shared)
        return self.client.put_linked_resource(
            self.resource, RelationType.EDIT, EntityType.ORG_VDC_NETWORK.value,
            vdc_network)
Пример #6
0
    def add_service_right(self, right_name, service_name, namespace,
                          description, category, bundle_key):
        """Add a new right using API extension service.

        :param str right_name: the name of the new right to be registered.
        :param str service_name: the name of the extension service whose
            record we want to retrieve.
        :param str namespace: the namespace of the extension service.
        :param str description: brief description about the new right.
        :param str category: add the right in existing categories in
            vCD Roles and Rights or specify a new category name.
        :param str bundle_key: is used to identify the right name and change
            its value to different languages using localization bundle.

        :return: object containing EntityType.RIGHT XML data i.e. the
            sparse representation of the Right element.

        :rtype: lxml.objectify.ObjectifiedElement
        """
        params = E.Right({'name': right_name})
        params.append(E.Description(description))
        params.append(E.Category(category))
        params.append(E.BundleKey(bundle_key))

        record = self._get_extension_record(name=service_name,
                                            namespace=namespace,
                                            format=QueryResultFormat.RECORDS)
        ext_service = self.client.get_resource(record.get('href'))
        ext_rights = self.client.get_linked_resource(ext_service,
                                                     RelationType.RIGHTS,
                                                     EntityType.RIGHTS.value)
        return self.client.post_linked_resource(ext_rights, RelationType.ADD,
                                                EntityType.RIGHT.value, params)
Пример #7
0
    def update(self):
        role_name = self.params.get('role_name')
        role_description = self.params.get('role_description')
        role_rights = self.params.get('role_rights')
        response = dict()
        response['changed'] = False

        role = self.org.get_role_record(role_name)
        role_resource = self.org.get_role_resource(role_name)
        role_resource.Description = E.Description(role_description)
        role_rights = tuple() if role_rights is None else role_rights

        for role_right in tuple(role_rights):
            role_right_record = self.org.get_right_record(role_right)
            role_resource.RightReferences.append(
                E.RightReference(name=role_right_record.get('name'),
                                 href=role_right_record.get('href'),
                                 type=EntityType.RIGHT.value))

        self.client.put_resource(role.get('href'), role_resource,
                                 EntityType.ROLE.value)
        response['msg'] = 'Role {} has been updated.'.format(role_name)
        response['changed'] = True

        return response
Пример #8
0
    def add_extension(self, name, namespace, routing_key, exchange, patterns,
                      description=None):
        """Add an API extension service.

        :param str name: name of the new API extension service.
        :param str namespace: namespace of the new API extension service.
        :param str routing_key: AMQP routing key to use with the extension.
        :param str exchange: AMQP exchange to use with the extension.
        :param list patterns: list of url API filters to register with the
            extension.

        :return: object containing EntityType.ADMIN_SERVICE XML data i.e. the
            sparse representation of the API extension.

        :rtype: lxml.objectify.ObjectifiedElement
        """
        params = E_VMEXT.Service({'name': name})
        if description is not None:
            params.append(E.Description(description))
        params.append(E_VMEXT.Namespace(namespace))
        params.append(E_VMEXT.Enabled('true'))
        params.append(E_VMEXT.RoutingKey(routing_key))
        params.append(E_VMEXT.Exchange(exchange))
        filters = E_VMEXT.ApiFilters()
        for pattern in patterns:
            filters.append(
                E_VMEXT.ApiFilter(E_VMEXT.UrlPattern(pattern.strip())))
        params.append(filters)
        ext = self.client.get_extension()
        ext_services = self.client.get_linked_resource(
            ext, RelationType.DOWN, EntityType.EXTENSION_SERVICES.value)
        return self.client.post_linked_resource(ext_services, RelationType.ADD,
                                                EntityType.ADMIN_SERVICE.value,
                                                params)
Пример #9
0
    def update_external_network(self,
                                name,
                                new_name=None,
                                new_description=None):
        """Update name and description of an external network.

        :param str name: name of the external network to be updated.

        :param str new_name: new name of the external network.

        :param str new_description: new description of the external network.

        :return: an object containing vmext:VMWExternalNetwork XML element that
            represents the updated external network.

        :rtype: lxml.objectify.ObjectifiedElement
        """
        ext_net = self.get_external_network(name)

        if (new_name is None) and (new_description is None):
            return ext_net

        if new_name is not None:
            ext_net.set('name', new_name)
        if new_description is not None:
            description = ext_net['{' + NSMAP['vcloud'] + '}Description']
            ext_net.replace(description, E.Description(new_description))

        return self.client.put_linked_resource(
            ext_net,
            rel=RelationType.EDIT,
            media_type=EntityType.EXTERNAL_NETWORK.value,
            contents=ext_net)
Пример #10
0
    def update_extension(self, name, namespace=None, routing_key=None,
                         exchange=None, description=None):
        """Update properties for an existing API extension.

        :param str name: name of the API extension.
        :param str namespace: namespace of the API extension.
        :param str routing_key: AMQP routing key to use for the extension.
        :param str exchange: AMQP exchange to use for the extension.

        :return: href of the API extension.

        :rtype: str

        :raises MissingRecordException: if an extension with the given name and
            namespace couldn't be found.
        :raise MultipleRecordsException: if more than one service with the
            given name and namespace are found.
        """
        record = self._get_extension_record(name=name,
                                            namespace=namespace,
                                            format=QueryResultFormat.RECORDS)

        params = E_VMEXT.Service({'name': name})
        description = description or record.get('description')
        if description is not None:
            params.append(E.Description(description))
        params.append(E_VMEXT.Namespace(record.get('namespace')))
        params.append(E_VMEXT.Enabled(record.get('enabled')))
        params.append(E_VMEXT.RoutingKey(
            routing_key if routing_key else record.get('routingKey')))
        params.append(E_VMEXT.Exchange(
            exchange if exchange else record.get('exchange')))

        self.client.put_resource(record.get('href'), params, None)
        return record.get('href')
Пример #11
0
    def update_disk(self,
                    name,
                    size,
                    new_name=None,
                    description=None,
                    disk_id=None):
        """
        Update an existing independent disk.
        :param name: (str): The existing name of the Disk.
        :param new_name: (str): The new name for the Disk.
        :param size: (str): The size of the new disk in MB.
        :param description: (str): A description of the new disk.
        :param description: (str): The disk_id of the existing disk.
        :return:  A :class:`lxml.objectify.StringElement` object describing the asynchronous Task creating the disk.
        """  # NOQA
        if self.resource is None:
            self.resource = self.client.get_resource(self.href)

        diskParms = E.Disk(name=name, size=size)

        if description is not None:
            diskParms.append(E.Description(description))

        if disk_id is not None:
            disk = self.get_disk(None, disk_id)
        else:
            disk = self.get_disk(name)

        if disk is None:
            raise Exception('Could not locate Disk %s for update. ' % disk_id)

        return self.client.put_linked_resource(disk, RelationType.EDIT,
                                               EntityType.DISK.value,
                                               diskParms)
Пример #12
0
    def update_catalog(self, old_catalog_name, new_catalog_name, description):
        """Update the name and/or description of a catalog.

        :param old_catalog_name: (str): The current name of the catalog.
        :param new_catalog_name: (str): The new name of the catalog.
        :param description: (str): The new description of the catalog.
        :return:  A :class:`lxml.objectify.StringElement` object describing
            the updated catalog.
        """
        if self.resource is None:
            self.resource = self.client.get_resource(self.href)
        org = self.resource
        links = get_links(org,
                          rel=RelationType.DOWN,
                          media_type=EntityType.CATALOG.value)
        for link in links:
            if old_catalog_name == link.name:
                catalog = self.client.get_resource(link.href)
                href = catalog.get('href')
                admin_href = href.replace('/api/catalog/',
                                          '/api/admin/catalog/')
                admin_view_of_catalog = self.client.get_resource(admin_href)
                if new_catalog_name is not None:
                    admin_view_of_catalog.set('name', new_catalog_name)
                if description is not None:
                    admin_view_of_catalog['Description'] = E.Description(
                        description)
                return self.client.put_resource(
                    admin_href,
                    admin_view_of_catalog,
                    media_type=EntityType.ADMIN_CATALOG.value)
        raise Exception('Catalog not found.')
Пример #13
0
 def create_catalog(self, name, description):
     if self.resource is None:
         self.resource = self.client.get_resource(self.href)
     catalog = E.AdminCatalog(E.Description(description), name=name)
     return self.client.post_linked_resource(
         self.resource, RelationType.ADD, EntityType.ADMIN_CATALOG.value,
         catalog)
Пример #14
0
    def add_firewall_rule(self,
                          name,
                          is_enabled=False,
                          policy='drop',
                          protocols=['Any'],
                          source_port_range='Any',
                          source_ip='Any',
                          destination_port_range='Any',
                          destination_ip='Any',
                          enable_logging=False):
        """Add firewall rule on firewall services to vApp network.

        :param str name: name of firewall rule.
        :param str policy: policy on firewall rule.
        :param list protocols: list of protocols on firewall rule.
        :param str source_port_range: source port range for firewall rule.
        :param str source_ip: source IP.
        :param str destination_port_range:destination port range for firewall
            rule.
        :param str destination_ip: destination IP.
        :param str enable_logging: enable logging on firewall rule.
        :return: an object containing EntityType.TASK XML data which represents
            the asynchronous task that is updating the vApp network.
        :rtype: lxml.objectify.ObjectifiedElement
        :raises: InvalidParameterException: Enable firewall service failed as
            given network's connection is not routed
        """
        self._get_resource()
        fence_mode = self.resource.Configuration.FenceMode
        if fence_mode != 'natRouted':
            raise InvalidParameterException(
                "Enable firewall service failed as given network's connection "
                "is not routed")
        firewall_service = self.resource.Configuration.Features.FirewallService
        firewall_rule = E.FirewallRule()
        firewall_rule.append(E.IsEnabled(is_enabled))
        firewall_rule.append(E.Description(name))
        firewall_rule.append(E.Policy(policy))
        protocol = E.Protocols()
        for proto in protocols:
            if proto == 'Any':
                protocol.append(E.Any(True))
            elif proto == 'Icmp':
                protocol.append(E.Icmp(True))
            elif proto == 'Tcp':
                protocol.append(E.Tcp(True))
            elif proto == 'Udp':
                protocol.append(E.Udp(True))
        firewall_rule.append(protocol)
        firewall_rule.append(E.DestinationPortRange(destination_port_range))
        firewall_rule.append(E.DestinationIp(destination_ip))
        firewall_rule.append(E.SourcePortRange(source_port_range))
        firewall_rule.append(E.SourceIp(source_ip))
        firewall_rule.append(E.EnableLogging(enable_logging))
        firewall_service.append(firewall_rule)
        return self.client.put_linked_resource(self.resource,
                                               RelationType.EDIT,
                                               EntityType.vApp_Network.value,
                                               self.resource)
Пример #15
0
    def create_vapp(self,
                    name,
                    description=None,
                    network=None,
                    fence_mode=FenceMode.BRIDGED.value,
                    accept_all_eulas=None):
        """Create a new vApp in this vdc.

        :param name: (str) Name of the new vApp.
        :param description: (str) Description of the new vApp.
        :param network: (str) Name of the OrgVDC network the vApp will
            connect to.
        :param fence_mode: (str): Network fence mode.
            Possible values are `bridged` and `natRouted`
        :param accept_all_eulas: (bool): True confirms acceptance of all EULAs
            in a vApp template.
        :return:  A :class:`lxml.objectify.StringElement` object representing a
            sparsely populated vApp element in the target vdc.
        """
        if self.resource is None:
            self.resource = self.client.get_resource(self.href)

        network_href = network_name = None
        if network is not None:
            if hasattr(self.resource, 'AvailableNetworks') and \
               hasattr(self.resource.AvailableNetworks, 'Network'):
                for n in self.resource.AvailableNetworks.Network:
                    if network == n.get('name'):
                        network_href = n.get('href')
                        network_name = n.get('name')
                        break
            if network_href is None:
                raise Exception(
                    'Network \'%s\' not found in the Virtual Datacenter.' %
                    network)

        vapp_instantiation_param = None
        if network_name is not None:
            network_configuration = E.Configuration(
                E.ParentNetwork(href=network_href), E.FenceMode(fence_mode))

            vapp_instantiation_param = E.InstantiationParams(
                E.NetworkConfigSection(
                    E_OVF.Info('Configuration for logical networks'),
                    E.NetworkConfig(network_configuration,
                                    networkName=network_name)))

        params = E.ComposeVAppParams(name=name)
        if description is not None:
            params.append(E.Description(description))
        if vapp_instantiation_param is not None:
            params.append(vapp_instantiation_param)
        if accept_all_eulas is not None:
            params.append(E.AllEULAsAccepted(accept_all_eulas))

        return self.client.post_linked_resource(
            self.resource, RelationType.ADD,
            EntityType.COMPOSE_VAPP_PARAMS.value, params)
Пример #16
0
    def update_general_setting(self,
                               name=None,
                               description=None,
                               computer_name=None,
                               boot_delay=None,
                               enter_bios_setup=None,
                               storage_policy_href=None):
        """Update general settings of VM .

        :param str name: name of VM.
        :param str description: description of VM.
        :param str computer_name: computer name of VM.
        :param int boot_delay: boot delay of VM.
        :param bool enter_bios_setup: enter bios setup of VM.
        :param str storage_policy_href: storage policy href.
        :return: an object containing EntityType.TASK XML data which represents
            the asynchronous task that is updating general setting of VM.
        :rtype: lxml.objectify.ObjectifiedElement
        """
        self.get_resource()
        if name is not None:
            self.resource.set('name', name)
        guest_customization = self.resource.GuestCustomizationSection
        if computer_name is not None:
            guest_customization.remove(guest_customization.ComputerName)
            cn = E.ComputerName(computer_name)
            guest_customization.ResetPasswordRequired.addnext(cn)
        if description is not None:
            if hasattr(self.resource, 'Description'):
                self.resource.remove(self.resource.Description)
            desc = E.Description(description)
            self.resource.VmSpecSection.addprevious(desc)
        if boot_delay is not None:
            if hasattr(self.resource.BootOptions, 'BootDelay'):
                self.resource.BootOptions.remove(
                    self.resource.BootOptions.BootDelay)
            bd = E.BootDelay(boot_delay)
            self.resource.BootOptions.EnterBIOSSetup.addprevious(bd)
        if enter_bios_setup is not None:
            if hasattr(self.resource.BootOptions, 'EnterBIOSSetup'):
                self.resource.BootOptions.remove(
                    self.resource.BootOptions.EnterBIOSSetup)
            ebs = E.EnterBIOSSetup(enter_bios_setup)
            self.resource.BootOptions.BootDelay.addnext(ebs)
        if storage_policy_href is not None:
            storage_policy_res = self.client.get_resource(storage_policy_href)
            print(storage_policy_href)
            self.resource.StorageProfile.set('href', storage_policy_href)
            self.resource.StorageProfile.set('id',
                                             storage_policy_res.get('id'))
            self.resource.StorageProfile.set('name',
                                             storage_policy_res.get('name'))
        return self.client.post_linked_resource(
            self.resource, RelationType.RECONFIGURE_VM, EntityType.VM.value,
            self.resource)
Пример #17
0
    def create_directly_connected_vdc_network(self,
                                              network_name,
                                              description,
                                              parent_network_name,
                                              is_shared=None):
        """Create a new directly connected OrgVdc network in this VDC.

        :param network_name: (str): Name of the new network
        :param description: (str): Description of the new network
        :param parent_network_name: (str): Name of the external network
            that the new network will be directly connected to
        :param is_shared: (bool): True, is the network is shared with \
            other VDC(s) in the organization else False
        :return: A :class:`lxml.objectify.StringElement` object representing
            a sparsely populated OrgVdcNetwork element.
        """

        resource_admin = self.client.get_resource(self.href_admin)
        parent_network_href = None
        if hasattr(resource_admin, 'ProviderVdcReference'):
            pvdc_admin_href = resource_admin.ProviderVdcReference.get('href')
            pvdc_admin_ext_href = get_admin_extension_href(pvdc_admin_href)
            pvdc_resource = self.client.get_resource(pvdc_admin_ext_href)

            available_network_tag = '{' + NSMAP['vcloud'] + \
                                    '}AvailableNetworks'
            if hasattr(pvdc_resource, available_network_tag) and \
               hasattr(pvdc_resource[available_network_tag], 'Network'):
                for ext_net in pvdc_resource[available_network_tag].Network:
                    if parent_network_name == ext_net.get('name'):
                        parent_network_href = ext_net.get('href')
                        break
        else:
            raise Exception('User doesn\'t have enough permission to view '
                            'Provider Virtual Datacenter backing Virtual '
                            'Datacenter %s' % self.name)
        if parent_network_href is None:
            raise Exception('Network \'%s\' not found in the Provider '
                            'Virtual Datacenter.' % parent_network_name)

        request_payload = E.OrgVdcNetwork(name=network_name)
        request_payload.append(E.Description(description))
        vdc_network_configuration = E.Configuration()
        vdc_network_configuration.append(
            E.ParentNetwork(href=parent_network_href))
        vdc_network_configuration.append(E.FenceMode('bridged'))
        request_payload.append(vdc_network_configuration)
        if is_shared is not None:
            request_payload.append(E.IsShared(is_shared))

        return self.client.post_linked_resource(
            resource_admin, RelationType.ADD, EntityType.ORG_VDC_NETWORK.value,
            request_payload)
Пример #18
0
    def add_disk(self,
                 name,
                 size,
                 bus_type=None,
                 bus_sub_type=None,
                 description=None,
                 storage_profile_name=None):
        """
        Request the creation of an indendent disk.
        :param name: (str): The name of the new Disk.
        :param size: (str): The size of the new disk in MB.
        :param bus_type: (str): The bus type of the new disk.
        :param bus_subtype: (str): The bus subtype  of the new disk.
        :param description: (str): A description of the new disk.
        :param storage_profile_name: (str): The name of an existing storage profile to be used by the new disk.
        :return:  A :class:`lxml.objectify.StringElement` object describing the asynchronous Task creating the disk.
        """  # NOQA
        if self.resource is None:
            self.resource = self.client.get_resource(self.href)

        diskParms = E.DiskCreateParams(E.Disk(name=name, size=size))

        if description is not None:
            diskParms.Disk.append(E.Description(description))

        if bus_type is not None and bus_sub_type is not None:
            diskParms.Disk.attrib['busType'] = bus_type
            diskParms.Disk.attrib['busSubType'] = bus_sub_type

        if storage_profile_name is not None:
            storage_profile = self.get_storage_profile(storage_profile_name)
            print((etree.tostring(storage_profile, pretty_print=True)))
            diskParms.Disk.append(storage_profile)
            # etree.SubElement(diskParms.Disk, 'StorageProfile')
            # diskParms.Disk.append(
            # E.StorageProfile(name=storage_profile_name))
            # diskParms.Disk.StorageProfile.attrib['href'] =
            # storage_profile.get('href')
            # diskParms.Disk.StorageProfile.attrib['name'] =
            # storage_profile.get('name')
            # diskParms.Disk.StorageProfile.attrib['type'] =
            # storage_profile.get('type')

            print((etree.tostring(diskParms, pretty_print=True)))

        return self.client.post_linked_resource(
            self.resource,
            RelationType.ADD,
            EntityType.DISK_CREATE_PARMS.value,
            diskParms)
Пример #19
0
    def create_disk(self,
                    name,
                    size,
                    bus_type=None,
                    bus_sub_type=None,
                    description=None,
                    storage_profile_name=None,
                    iops=None):
        """Request the creation of an indendent disk.

        :param name: (str): The name of the new disk.
        :param size: (int): The size of the new disk in bytes.
        :param bus_type: (str): The bus type of the new disk.
        :param bus_subtype: (str): The bus subtype  of the new disk.
        :param description: (str): A description of the new disk.
        :param storage_profile_name: (str): The name of an existing
            storage profile to be used by the new disk.
        :param iops: (int): Iops requirement of the new disk.

        :return:  A :class:`lxml.objectify.StringElement` object containing
            the sparse representation of the new disk and the asynchronus task
            that is creating the disk.
        """
        if self.resource is None:
            self.resource = self.client.get_resource(self.href)

        disk_params = E.DiskCreateParams(E.Disk(name=name, size=str(size)))
        if iops is not None:
            disk_params.Disk.set('iops', iops)

        if description is not None:
            disk_params.Disk.append(E.Description(description))

        if bus_type is not None and bus_sub_type is not None:
            disk_params.Disk.set('busType', bus_type)
            disk_params.Disk.set('busSubType', bus_sub_type)

        if storage_profile_name is not None:
            storage_profile = self.get_storage_profile(storage_profile_name)
            disk_params.Disk.append(
                E.StorageProfile(
                    name=storage_profile_name,
                    href=storage_profile.get('href'),
                    type=storage_profile.get('type')))

        return self.client.post_linked_resource(
            self.resource, RelationType.ADD,
            EntityType.DISK_CREATE_PARMS.value, disk_params)
Пример #20
0
    def update_disk(self,
                    name,
                    size,
                    new_name=None,
                    description=None,
                    storage_profile_name=None,
                    iops=None,
                    disk_id=None):
        """
        Update an existing independent disk.
        :param name: (str): The existing name of the Disk.
        :param size: (str): The size of the new disk in MB.
        :param new_name: (str): The new name for the Disk.
        :param iops: (str): The new iops for the disk. 
        :param storage_profile_name: (str): The storage profile that the disk belongs to.
        :param description: (str): A description of the new disk.
        :param disk_id: (str): The disk_id of the existing disk.
        :return:  A :class:`lxml.objectify.StringElement` object describing the asynchronous Task creating the disk.
        """  # NOQA
        if self.resource is None:
            self.resource = self.client.get_resource(self.href)

        if iops is None:
            diskParms = E.Disk(name=name, size=size)
        else:
            diskParms = E.Disk(name=name, size=size, iops=iops)

        if description is not None:
            diskParms.append(E.Description(description))

        if disk_id is not None:
            disk = self.get_disk(None, disk_id)
        else:
            disk = self.get_disk(name)

        if storage_profile_name is not None:
            storage_profile = self.get_storage_profile(storage_profile_name)
            sp = etree.XML(etree.tostring(storage_profile, pretty_print=True))
            sp_href = sp.attrib['href']
            diskParms.append(E.StorageProfile(href=sp_href,
                                              name=storage_profile_name))
        if disk is None:
            raise Exception('Could not locate Disk %s for update. ' % disk_id)

        return self.client.put_linked_resource(disk,
                                               RelationType.EDIT,
                                               EntityType.DISK.value,
                                               diskParms)
Пример #21
0
    def capture_vapp(self,
                     catalog_resource,
                     vapp_href,
                     catalog_item_name,
                     description,
                     customize_on_instantiate=False,
                     overwrite=False):
        """Capture vApp as a catalog item template.

        :param catalog_resource: (`lxml.objectify.StringElement`): The
            catalog.
        :param vapp_href: (str): The href of the vApp to capture.
        :param catalog_item_name: (str): The name of the target catalog item.
        :param description: (str): The description of the catalog item.
        :param customize_on_instantiate: (bool): A flag indicating if the
            vApp to be instantiated from this vApp template can be customized.
        :param overwrite: (bool): A flag indicating if the item in the catalog
            has to be overwritten if it already exists. If it doesn't exists,
            this flag is not used.
        :return:  A :class:`lxml.objectify.StringElement` object describing
            the updated catalog item.
        """
        contents = E.CaptureVAppParams(
            E.Description(description),
            E.Source(href=vapp_href),
            name=catalog_item_name)
        if customize_on_instantiate:
            contents.append(
                E.CustomizationSection(
                    E_OVF.Info('VApp template customization section'),
                    E.CustomizeOnInstantiate('true')))
        if overwrite:
            try:
                item = self.get_catalog_item(
                    catalog_resource.get('name'), catalog_item_name)
                contents.append(
                    E.TargetCatalogItem(
                        href=item.get('href'),
                        id=item.get('id'),
                        type=item.get('type'),
                        name=item.get('name')))
            except Exception:
                pass
        return self.client.post_linked_resource(
            catalog_resource,
            rel=RelationType.ADD,
            media_type=EntityType.CAPTURE_VAPP_PARAMS.value,
            contents=contents)
Пример #22
0
 def capture_vapp(self,
                  catalog_resource,
                  vapp_href,
                  catalog_item_name,
                  description,
                  customize_on_instantiate=False):
     contents = E.CaptureVAppParams(E.Description(description),
                                    E.Source(href=vapp_href),
                                    name=catalog_item_name)
     if customize_on_instantiate:
         contents.append(
             E.CustomizationSection(
                 E_OVF.Info('VApp template customization section'),
                 E.CustomizeOnInstantiate('true')))
     return self.client.post_linked_resource(
         catalog_resource,
         rel=RelationType.ADD,
         media_type=EntityType.CAPTURE_VAPP_PARAMS.value,
         contents=contents)
Пример #23
0
 def create_role(self, role_name, description, rights):
     """
     Creates a role in the organization
     :param role_name: (str): name of the role to be created
     :param description: (str): description of the role
     :param rights: (tuple of (str)) names of zero or more rights to be associated with the role
     :return: RoleType just created
     """  # NOQA
     org_admin_resource = self.client.get_resource(self.href_admin)
     role = E.Role(
         E.Description(description), E.RightReferences(), name=role_name)
     if rights is None:
         rights = ()
     for right in tuple(rights):
         right_record = self.get_right(right)
         role.RightReferences.append(
             E.RightReference(
                 name=right_record.get('name'),
                 href=right_record.get('href'),
                 type=EntityType.RIGHT.value))
     return self.client.post_linked_resource(
         org_admin_resource, RelationType.ADD, EntityType.ROLE.value, role)
Пример #24
0
    def create_directly_connected_vdc_network(self,
                                              network_name,
                                              parent_network_name,
                                              description=None,
                                              is_shared=None):
        """Create a new directly connected OrgVdc network in this vdc.

        :param network_name: (str): Name of the new network.
        :param parent_network_name: (str): Name of the external network
            that the new network will be directly connected to.
        :param description: (str): Description of the new network.
        :param is_shared: (bool): True, if the network is shared with
            other vdc(s) in the organization, else False.

        :return: A :class:`lxml.objectify.StringElement` object representing
            a sparsely populated OrgVdcNetwork element.
        """
        if self.resource is None:
            self.resource = self.client.get_resource(self.href)

        platform = Platform(self.client)
        parent_network = platform.get_external_network(parent_network_name)
        parent_network_href = parent_network.get('href')

        request_payload = E.OrgVdcNetwork(name=network_name)
        if description is not None:
            request_payload.append(E.Description(description))
        vdc_network_configuration = E.Configuration()
        vdc_network_configuration.append(
            E.ParentNetwork(href=parent_network_href))
        vdc_network_configuration.append(E.FenceMode(FenceMode.BRIDGED.value))
        request_payload.append(vdc_network_configuration)
        if is_shared is not None:
            request_payload.append(E.IsShared(is_shared))

        return self.client.post_linked_resource(
            self.resource, RelationType.ADD, EntityType.ORG_VDC_NETWORK.value,
            request_payload)
Пример #25
0
    def register_nsxt_manager(self,
                              nsxt_manager_name,
                              nsxt_manager_url,
                              nsxt_manager_username,
                              nsxt_manager_password,
                              nsxt_manager_description=None):
        """Register a NSX-T manager.

        :param str nsxt_manager_name: name of NSX-T manager.
        :param str nsxt_manager_url: URL of NSX-T manager server.
        :param str nsxt_manager_username: username of NSX-T manager admin.
        :param str nsxt_manager_password: password of NSX-T manager admin.
        :param str nsxt_manager_description: description of NSX-T manager.

        :return: an object containing XML data the newly registered NSX-T
            manager.

        :rtype: lxml.objectify.ObjectifiedElement
        """
        payload = E_VMEXT.NsxTManager(name=nsxt_manager_name)
        if (nsxt_manager_description is not None):
            payload.append(E.Description(nsxt_manager_description))
        payload.append(E_VMEXT.Username(nsxt_manager_username))
        payload.append(E_VMEXT.Password(nsxt_manager_password))
        payload.append(E_VMEXT.Url(nsxt_manager_url))

        nsxt_manager_resource = self.client.get_linked_resource(
            resource=self.extension.get_resource(),
            rel=RelationType.DOWN,
            media_type=EntityType.NETWORK_MANAGERS.value)

        return self.client.\
            post_linked_resource(resource=nsxt_manager_resource,
                                 rel=RelationType.ADD,
                                 media_type=EntityType.NSXT_MANAGER.value,
                                 contents=payload)
Пример #26
0
    def create_provider_vdc(self,
                            vim_server_name,
                            resource_pool_names,
                            storage_profiles,
                            pvdc_name,
                            is_enabled=None,
                            description=None,
                            highest_hw_vers=None,
                            vxlan_network_pool=None,
                            nsxt_manager_name=None):
        """Create a Provider Virtual Datacenter.

        :param str vim_server_name: vim_server_name (VC name).
        :param list resource_pool_names: list of resource_pool_names.
        :param list storage_profiles: (list): list of storageProfile names.
        :param str pvdc_name: name of PVDC to be created.
        :param bool is_enabled: flag, True to enable and False to disable.
        :param str description: description of pvdc.
        :param str highest_hw_vers: highest supported hw version number.
        :param str vxlan_network_pool: name of vxlan_network_pool.
        :param str nsxt_manager_name: name of nsx-t manager.

        :return: an object containing vmext:VMWProviderVdc XML element that
            represents the new provider VDC.

        :rtype: lxml.objectify.ObjectifiedElement
        """
        vc_record = self.get_vcenter(vim_server_name)
        vc_href = vc_record.get('href')
        rp_morefs = self.get_resource_pool_morefs(vc_href, resource_pool_names)
        vmw_prov_vdc_params = E_VMEXT.VMWProviderVdcParams(name=pvdc_name)
        if description is not None:
            vmw_prov_vdc_params.append(E.Description(description))
        resource_pool_refs = E_VMEXT.ResourcePoolRefs()
        for rp_moref in rp_morefs:
            vim_object_ref = E_VMEXT.VimObjectRef()
            vim_object_ref.append(E_VMEXT.VimServerRef(href=vc_href))
            vim_object_ref.append(E_VMEXT.MoRef(rp_moref))
            vim_object_ref.append(E_VMEXT.VimObjectType('RESOURCE_POOL'))
            resource_pool_refs.append(vim_object_ref)
        vmw_prov_vdc_params.append(resource_pool_refs)
        vmw_prov_vdc_params.append(E_VMEXT.VimServer(href=vc_href))
        if vxlan_network_pool is not None:
            network_pool_rec = self.get_ref_by_name(ResourceType.NETWORK_POOL,
                                                    vxlan_network_pool)
            vx_href = network_pool_rec.get('href')
            vmw_prov_vdc_params.append(E_VMEXT.VxlanNetworkPool(href=vx_href))
        if nsxt_manager_name is not None:
            nsxt_manager_rec = self.get_ref_by_name(ResourceType.NSXT_MANAGER,
                                                    nsxt_manager_name)
            nsxt_href = nsxt_manager_rec.get('href')
            vmw_prov_vdc_params.append(
                E_VMEXT.NsxTManagerReference(href=nsxt_href))
        if highest_hw_vers is not None:
            vmw_prov_vdc_params.append(
                E_VMEXT.HighestSupportedHardwareVersion(highest_hw_vers))
        if is_enabled is not None:
            vmw_prov_vdc_params.append(E_VMEXT.IsEnabled(is_enabled))
        for storage_profile in storage_profiles:
            vmw_prov_vdc_params.append(E_VMEXT.StorageProfile(storage_profile))
        random_username_suffix = uuid.uuid4().hex
        default_user = '******' + random_username_suffix[:8]
        default_pwd = 'PWD' + random_username_suffix[:8]
        vmw_prov_vdc_params.append(E_VMEXT.DefaultPassword(default_pwd))
        vmw_prov_vdc_params.append(E_VMEXT.DefaultUsername(default_user))

        return self.client.post_linked_resource(
            self.extension.get_resource(),
            rel=RelationType.ADD,
            media_type=EntityType.PROVIDER_VDC_PARAMS.value,
            contents=vmw_prov_vdc_params)
Пример #27
0
    def create_external_network(self,
                                name,
                                vim_server_name,
                                port_group_names,
                                gateway_ip,
                                netmask,
                                ip_ranges,
                                description=None,
                                primary_dns_ip=None,
                                secondary_dns_ip=None,
                                dns_suffix=None):
        """Create an external network.

        :param str name: name of external network to be created.
        :param str vim_server_name: VIM server_name (VC name).
        :param list port_group_names: list of port group names.
        :param str gateway_ip: IP address of the gateway of the new network.
        :param str netmask: Netmask of the gateway.
        :param list ip_ranges: list of IP ranges used for static pool
            allocation in the network. For example, [192.168.1.2-192.168.1.49,
            192.168.1.100-192.168.1.149].
        :param str description: description of external network.
        :param str primary_dns_ip: IP address of primary DNS server.
        :param str secondary_dns_ip: IP address of secondary DNS Server.
        :param str dns_suffix: DNS suffix.

        :return: an object containing vmext:VMWExternalNetwork XML element that
            represents the new external network.

        :rtype: lxml.objectify.ObjectifiedElement
        """
        vc_record = self.get_vcenter(vim_server_name)
        vc_href = vc_record.get('href')
        pg_morefs = self.get_port_group_morefs(port_group_names)
        vmw_external_network = E_VMEXT.VMWExternalNetwork(name=name)
        if description is not None:
            vmw_external_network.append(E.Description(description))
        config = E.Configuration()
        ip_scopes = E.IpScopes()
        ip_scope = E.IpScope()
        ip_scope.append(E.IsInherited(False))
        ip_scope.append(E.Gateway(gateway_ip))
        ip_scope.append(E.Netmask(netmask))
        if primary_dns_ip is not None:
            ip_scope.append(E.Dns1(primary_dns_ip))
        if secondary_dns_ip is not None:
            ip_scope.append(E.Dns2(secondary_dns_ip))
        if dns_suffix is not None:
            ip_scope.append(E.DnsSuffix(dns_suffix))
        e_ip_ranges = E.IpRanges()
        for ip_range in ip_ranges:
            e_ip_range = E.IpRange()
            ip_range_token = ip_range.split('-')
            e_ip_range.append(E.StartAddress(ip_range_token[0]))
            e_ip_range.append(E.EndAddress(ip_range_token[1]))
            e_ip_ranges.append(e_ip_range)
        ip_scope.append(e_ip_ranges)
        ip_scopes.append(ip_scope)
        config.append(ip_scopes)
        config.append(E.FenceMode(FenceMode.ISOLATED.value))
        vmw_external_network.append(config)
        vim_port_group_refs = E_VMEXT.VimPortGroupRefs()
        for pg_moref in pg_morefs:
            vim_object_ref = E_VMEXT.VimObjectRef()
            vim_object_ref.append(E_VMEXT.VimServerRef(href=vc_href))
            vim_object_ref.append(E_VMEXT.MoRef(pg_moref[0]))
            vim_object_ref.append(E_VMEXT.VimObjectType(pg_moref[1]))
            vim_port_group_refs.append(vim_object_ref)
        vmw_external_network.append(vim_port_group_refs)

        return self.client.post_linked_resource(
            self.extension.get_resource(),
            rel=RelationType.ADD,
            media_type=EntityType.EXTERNAL_NETWORK.value,
            contents=vmw_external_network)
Пример #28
0
 def upload_ovf(self,
                catalog_name,
                file_name,
                item_name=None,
                description='',
                chunk_size=DEFAULT_CHUNK_SIZE,
                callback=None):
     catalog = self.get_catalog(catalog_name)
     if item_name is None:
         item_name = os.path.basename(file_name)
     tempdir = tempfile.mkdtemp(dir='.')
     total_bytes = 0
     try:
         ova = tarfile.open(file_name)
         ova.extractall(path=tempdir)
         ova.close()
         ovf_file = None
         files = os.listdir(tempdir)
         for f in files:
             fn, ex = os.path.splitext(f)
             if ex == '.ovf':
                 ovf_file = os.path.join(tempdir, f)
                 break
         if ovf_file is not None:
             stat_info = os.stat(ovf_file)
             total_bytes += stat_info.st_size
             ovf = objectify.parse(ovf_file)
             files = []
             ns = '{' + NSMAP['ovf'] + '}'
             for f in ovf.getroot().References.File:
                 source_file = {
                     'href': f.get(ns + 'href'),
                     'name': f.get(ns + 'id'),
                     'size': f.get(ns + 'size')
                 }
                 files.append(source_file)
             if item_name is None:
                 item_name = os.path.basename(file_name)
             params = E.UploadVAppTemplateParams(name=item_name)
             params.append(E.Description(description))
             catalog_item = self.client.post_resource(
                 catalog.get('href') + '/action/upload', params,
                 EntityType.UPLOAD_VAPP_TEMPLATE_PARAMS.value)
             entity = self.client.get_resource(
                 catalog_item.Entity.get('href'))
             file_href = entity.Files.File.Link.get('href')
             self.client.put_resource(file_href, ovf, 'text/xml')
             while True:
                 time.sleep(5)
                 entity = self.client.get_resource(
                     catalog_item.Entity.get('href'))
                 if len(entity.Files.File) > 1:
                     break
             for source_file in files:
                 for target_file in entity.Files.File:
                     if source_file.get('href') == target_file.get('name'):
                         file_path = os.path.join(tempdir,
                                                  source_file.get('href'))
                         total_bytes += self.upload_file(
                             file_path,
                             target_file.Link.get('href'),
                             chunk_size=chunk_size,
                             callback=callback)
         shutil.rmtree(tempdir)
     except Exception as e:
         print(traceback.format_exc())
         shutil.rmtree(tempdir)
         raise e
     return total_bytes
Пример #29
0
    def create_org_vdc(self,
                       vdc_name,
                       provider_vdc_name,
                       description='',
                       allocation_model='AllocationVApp',
                       cpu_units='MHz',
                       cpu_allocated=0,
                       cpu_limit=0,
                       mem_units='MB',
                       mem_allocated=0,
                       mem_limit=0,
                       nic_quota=0,
                       network_quota=0,
                       vm_quota=0,
                       storage_profiles=[],
                       resource_guaranteed_memory=None,
                       resource_guaranteed_cpu=None,
                       vcpu_in_mhz=None,
                       is_thin_provision=None,
                       network_pool_name=None,
                       uses_fast_provisioning=None,
                       over_commit_allowed=None,
                       vm_discovery_enabled=None,
                       is_enabled=True):
        """Create Organization VDC in the current Org.

        :param vdc_name (str): The name of the new org vdc.
        :param provider_vdc_name (str): The name of an existing provider vdc.
        :param description (str): The description of the new org vdc.
        :param allocation_model (str): The allocation model used by this vDC.
            One of AllocationVApp, AllocationPool or ReservationPool.
        :param cpu_units (str): The cpu units compute capacity allocated to
            this vDC. One of MHz or GHz
        :param cpu_allocated (int): Capacity that is committed to be available.
        :param cpu_limit (int): Capacity limit relative to the value specified
            for Allocation.
        :param mem_units (str): The memory units compute capacity allocated to
            this vDC. One of MB or GB.
        :param mem_allocated (int): Memory capacity that is committed to be
            available.
        :param mem_limit (int): Memory capacity limit relative to the value
            specified for Allocation.
        :param nic_quota (int): Maximum number of virtual NICs allowed in this
            vDC. Defaults to 0, which specifies an unlimited number.
        :param network_quota (int): Maximum number of network objects that can
            be deployed in this vDC. Defaults to 0, which means no networks can
            be deployed.
        :param vm_quota (int): The maximum number of VMs that can be created in
            this vDC. Defaults to 0, which specifies an unlimited number.
        :param storage_profiles: List of provider vDC storage profiles to add
            to this vDC.
            Each item is a dictionary that should include the following
                elements:
                name: (string) name of the PVDC storage profile.
                enabled: (bool) True if the storage profile is enabled for this
                    vDC.
                units: (string) Units used to define limit. One of MB or GB.
                limit: (int) Max number of units allocated for this storage
                    profile.
                default: (bool) True if this is default storage profile for
                    this vDC.
        :param resource_guaranteed_memory (float): Percentage of allocated CPU
            resources guaranteed to vApps deployed in this vDC.
            Value defaults to 1.0 if the element is empty.
        :param resource_guaranteed_cpu (float): Percentage of allocated memory
            resources guaranteed to vApps deployed in this vDC.
            Value defaults to 1.0 if the element is empty.
        :param vcpu_in_mhz (int): Specifies the clock frequency, in Megahertz,
            for any virtual CPU that is allocated to a VM.
        :param is_thin_provision (bool): Boolean to request thin provisioning.
        :param network_pool_name (str): Reference to a network pool in the
            Provider vDC.
        :param uses_fast_provisioning (bool): Boolean to request fast
            provisioning.
        :param over_commit_allowed (bool): Set to false to disallow creation of
            the VDC if the AllocationModel is AllocationPool or ReservationPool
            and the ComputeCapacity you specified is greater than what the
            backing Provider VDC can supply. Defaults to true if empty or
            missing.
        :param vm_discovery_enabled (bool): True if discovery of vCenter VMs
            is enabled for resource pools backing this vDC.
        :param is_enabled (bool): True if this vDC is enabled for use by the
            organization users.
        :return:  A :class:`lxml.objectify.StringElement` object describing
            the new VDC.
        """
        if self.resource is None:
            self.resource = self.client.get_resource(self.href)
        sys_admin_resource = self.client.get_admin()
        system = System(self.client, admin_resource=sys_admin_resource)
        pvdc = system.get_provider_vdc(provider_vdc_name)
        resource_admin = self.client.get_resource(self.href_admin)
        params = E.CreateVdcParams(E.Description(description),
                                   E.AllocationModel(allocation_model),
                                   E.ComputeCapacity(
                                       E.Cpu(E.Units(cpu_units),
                                             E.Allocated(cpu_allocated),
                                             E.Limit(cpu_limit)),
                                       E.Memory(E.Units(mem_units),
                                                E.Allocated(mem_allocated),
                                                E.Limit(mem_limit))),
                                   E.NicQuota(nic_quota),
                                   E.NetworkQuota(network_quota),
                                   E.VmQuota(vm_quota),
                                   E.IsEnabled(is_enabled),
                                   name=vdc_name)
        for sp in storage_profiles:
            pvdc_sp = system.get_provider_vdc_storage_profile(sp['name'])
            params.append(
                E.VdcStorageProfile(
                    E.Enabled(sp['enabled']), E.Units(sp['units']),
                    E.Limit(sp['limit']), E.Default(sp['default']),
                    E.ProviderVdcStorageProfile(href=pvdc_sp.get('href'))))
        if resource_guaranteed_memory is not None:
            params.append(
                E.ResourceGuaranteedMemory(resource_guaranteed_memory))
        if resource_guaranteed_cpu is not None:
            params.append(E.ResourceGuaranteedCpu(resource_guaranteed_cpu))
        if vcpu_in_mhz is not None:
            params.append(E.VCpuInMhz(vcpu_in_mhz))
        if is_thin_provision is not None:
            params.append(E.IsThinProvision(is_thin_provision))
        if network_pool_name is not None:
            npr = system.get_network_pool_reference(network_pool_name)
            href = npr.get('href')
            params.append(
                E.NetworkPoolReference(href=href,
                                       id=href.split('/')[-1],
                                       type=npr.get('type'),
                                       name=npr.get('name')))
        params.append(pvdc)
        if uses_fast_provisioning is not None:
            params.append(E.UsesFastProvisioning(uses_fast_provisioning))
        if over_commit_allowed is not None:
            params.append(E.OverCommitAllowed(over_commit_allowed))
        if vm_discovery_enabled is not None:
            params.append(E.VmDiscoveryEnabled(vm_discovery_enabled))
        return self.client.post_linked_resource(resource_admin,
                                                RelationType.ADD,
                                                EntityType.VDCS_PARAMS.value,
                                                params)
Пример #30
0
    def create_user(self,
                    user_name,
                    password,
                    role_href,
                    full_name='',
                    description='',
                    email='',
                    telephone='',
                    im='',
                    alert_email='',
                    alert_email_prefix='',
                    stored_vm_quota=0,
                    deployed_vm_quota=0,
                    is_group_role=False,
                    is_default_cached=False,
                    is_external=False,
                    is_alert_enabled=False,
                    is_enabled=False):
        """Create User in the current Org.

        :param user_name: The username of the user
        :param password: The password of the user
        :param role_href: The href of the user role
        :param full_name: The full name of the user
        :param description: The description for the User
        :param email: The email of the user
        :param telephone: The telephone of the user
        :param im: The im address of the user
        :param alert_email: The alert email address
        :param alert_email_prefix: The string to prepend to the alert message
                subject line
        :param stored_vm_quota: The quota of vApps that this user can store
        :param deployed_vm_quota: The quota of vApps that this user can deploy
                concurrently
        :param is_group_role: Indicates if the user has a group role
        :param is_default_cached: Indicates if user should be cached
        :param is_external: Indicates if user is imported from an external
                source
        :param is_alert_enabled: The alert email address
        :param is_enabled: Enable user
        :return: (UserType) Created user object
        """
        resource_admin = self.client.get_resource(self.href_admin)
        user = E.User(E.Description(description),
                      E.FullName(full_name),
                      E.EmailAddress(email),
                      E.Telephone(telephone),
                      E.IsEnabled(is_enabled),
                      E.IM(im),
                      E.IsAlertEnabled(is_alert_enabled),
                      E.AlertEmailPrefix(alert_email_prefix),
                      E.AlertEmail(alert_email),
                      E.IsExternal(is_external),
                      E.IsDefaultCached(is_default_cached),
                      E.IsGroupRole(is_group_role),
                      E.StoredVmQuota(stored_vm_quota),
                      E.DeployedVmQuota(deployed_vm_quota),
                      E.Role(href=role_href),
                      E.Password(password),
                      name=user_name)
        return self.client.post_linked_resource(resource_admin,
                                                RelationType.ADD,
                                                EntityType.USER.value, user)