def get_placement_spec_for_resource_pool(stub_config,
                                         datacenter_name,
                                         vm_folder_name,
                                         datastore_name):
    """
    Returns a VM placement spec for a resourcepool. Ensures that the
    vm folder and datastore are all in the same datacenter which is specified.
    """
    resource_pool = resource_pool_helper.get_resource_pool(stub_config,
                                                           datacenter_name)

    folder = folder_helper.get_folder(stub_config,
                                      datacenter_name,
                                      vm_folder_name)

    datastore = datastore_helper.get_datastore(stub_config,
                                               datacenter_name,
                                               datastore_name)

    # Create the vm placement spec with the datastore, resource pool and vm
    # folder
    placement_spec = VM.PlacementSpec(folder=folder,
                                      resource_pool=resource_pool,
                                      datastore=datastore)

    print("get_placement_spec_for_resource_pool: Result is '{}'".
          format(placement_spec))
    return placement_spec
Beispiel #2
0
    def _execute(self):
        # Get the identifiers of the resources used for deployment
        item_id = self.helper.get_item_id_by_name(self.item_name)
        assert item_id
        folder_id = get_folder(self.vsphere_client,
                               self.datacenter_name,
                               self.folder_name)
        assert folder_id
        resource_pool_id = get_resource_pool(self.vsphere_client,
                                             self.datacenter_name,
                                             self.resource_pool_name)
        assert resource_pool_id
        datastore_id = get_datastore_id(self.servicemanager,
                                        self.datastore_name)
        assert datastore_id

        # Build the deployment specification
        placement_spec = VmtxLibraryItem.DeployPlacementSpec(
            folder=folder_id,
            resource_pool=resource_pool_id)
        vm_home_storage_spec = VmtxLibraryItem.DeploySpecVmHomeStorage(
            datastore=datastore_id)
        disk_storage_spec = VmtxLibraryItem.DeploySpecDiskStorage(
            datastore=datastore_id)
        deploy_spec = VmtxLibraryItem.DeploySpec(
            name=self.vm_name,
            placement=placement_spec,
            vm_home_storage=vm_home_storage_spec,
            disk_storage=disk_storage_spec)

        # Deploy a virtual machine from the VM template item
        self.vm_id = self.client.vmtx_service.deploy(item_id, deploy_spec)
        self.vm = get_obj_by_moId(self.servicemanager.content,
                                  [vim.VirtualMachine], self.vm_id)
        print("Deployed VM '{0}' with ID: {1}".format(self.vm.name,
                                                      self.vm_id))

        # Print a summary of the deployed VM
        vm_summary = self.vm.summary.config
        print('Guest OS: {0}'.format(vm_summary.guestId))
        print('{0} CPU(s)'.format(vm_summary.numCpu))
        print('{0} MB memory'.format(vm_summary.memorySizeMB))
        print('{0} disk(s)'.format(vm_summary.numVirtualDisks))
        print('{0} network adapter(s)'.format(vm_summary.numEthernetCards))
    def _setup(self):
        self.datastore_name = self.args.datastorename
        self.cluster_name = self.args.clustername
        self.folder_name = self.args.foldername
        self.datacenter_name = self.args.datacentername
        self.servicemanager = self.get_service_manager()

        self.datastore_id = get_datastore_id(
            service_manager=self.servicemanager,
            datastore_name=self.datastore_name)
        self.client = ClsApiClient(self.servicemanager)
        self.helper = ClsApiHelper(self.client, self.skip_verification)
        session = get_unverified_session() if self.skip_verification else None
        self.vsphere_client = create_vsphere_client(server=self.server,
                                                    username=self.username,
                                                    password=self.password,
                                                    session=session)
        self.folder_id = get_folder(self.vsphere_client, self.datacenter_name,
                                    self.folder_name)
        self.storage_backings = self.helper.create_storage_backings(
            self.servicemanager, self.datastore_name)
        cluster_obj = get_obj(self.servicemanager.content,
                              [vim.ClusterComputeResource], self.cluster_name)
        self.resource_pool_id = cluster_obj.resourcePool._GetMoId()