VMware Cloud Community
ctech930
Contributor
Contributor

Deploying a VM from a Content Library through the API with Powershell Help

    I am trying to deploy a VM from a Content Library using the com.vmware.vcenter.ovf.library_item  Deploy method.  I believe I must be missing something or am not doing something correctly because I keep getting the following error:

A server error occurred: 'com.vmware.vapi.std.errors.internal_server_error': Could not retrieve permission information for ID

urn:vapi:com.vmware.content.library.Item:@{Help=; resource_pool_id=ResourcePool-resgroup-12; host_id=HostSystem-host-208; folder_id=}

for operation com.vmware.vcenter.ovf.library_item.deploy. (Server error id: 'com.vmware.vapi.authorization.permission.error'). Check

$Error[0].Exception.ServerError for more details.

At line:1 char:1

+ $ovfLibItem.deploy($ovf_lib_item_id,$deployment_target,$deploymentSpec)

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : OperationStopped: (:) [], CisServerException

    + FullyQualifiedErrorId : VMware.VimAutomation.Cis.Core.Types.V1.CisServerException

Below is a sample of code I am trying to use.  Any help figuring out how to make this work would be really appreciated. 

*[Sample Code]*

$DeployTemplateName = 'TestOVAVMTemplate'
$DeployTemplateID = '6ca1a465-0d59-41f2-a060-bfef93935570'
$DeployTargetClusterName = 'Cluster01'
$DeployTargetDataStoreName = 'Datastore1'
$DeployTargetResourcePoolName = 'Resources'
$ContentLibID = '1f41dafd-67e5-4ac4-81ee-2b3532c006da'

$cisserverconnected = Connect-CisServer -User $user -Password $pass -Server $ciserver
$viserverconnected = Connect-VIServer -User $user -Password $pass -Server $vc

#Get OVF Template ID for specific template from specified Content Library

$svcContentLibrary = Get-CisService com.vmware.content.library -Server $cisserverconnected
$ContentLibrary = $svcContentLibrary.get($ContentLibID) 
$svcLibraryItems   = Get-CisService com.vmware.content.library.item 
$LibraryItems = $svcLibraryItems.list($ContentLibID) 
$libraryitem = foreach ($libitem in $LibraryItems) {
  $svcLibraryItems.get($libitem) | where {$_.name -like $DeployTemplateName}
}

$DeployTargetCluster = get-cluster $DeployTargetClusterName
$DeployTargetvmHost = $DeployTargetCluster | get-vmhost | where{$_.connectionstate -like "Connected"} | select -first 1
$DeployTargetDatastore = $DeployTargetvmHost | get-datastore -name $DeployTargetDataStoreName
$DeployTargetResourcePool = $DeployTargetCluster | get-resourcepool -name $DeployTargetResourcePoolName

$ovfLibItem = Get-CisService -Name com.vmware.vcenter.ovf.library_item 
$deployment_target = $ovfLibItem.Help.deploy.target.CreateExample() 
$deployment_target.resource_pool_id = $DeployTargetResourcePool.Id 
$deployment_target.host_id = $DeployTargetvmHost.Id

$deploymentSpec = $ovfLibItem.help.deploy.deployment_spec.CreateExample() 
$deploymentSpec.accept_all_EULA = $true 
$deploymentSpec.default_datastore_id = $DeployTargetDatastore.Id 
$deploymentSpec.name="$($templatetodeployinfo.name)-template"

$UniqueID = [guid]::NewGuid().tostring()

$ovf_lib_item_id = $ovfLibItem.help.deploy.ovf_library_item_id.CreateExample()
$ovf_lib_item_id=$libraryitem.id

$client_token = $ovfLibItem.help.deploy.client_token.CreateExample()
$client_token = $UniqueID

$ovfLibItem.deploy($ovf_lib_item_id,$deployment_target,$deploymentSpec)

Tags (1)
3 Replies
LucD
Leadership
Leadership

Can you check if the bypass in vcsa 6.5 trying to automate the backup - authentication failure  works here as well?

Restart the appliance and then manually start the service


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
ctech930
Contributor
Contributor

Thanks for the reply.  I guess I should have provided a bit more details.  This is not against a vcenter appliance its against a vcenter server running on windows.

vcenter sever version 6.0.0 build: 5318200

Powercli version:

                         VMware Cis Core PowerCLI Component 6.5 build 6230110

                          VMware VimAutomation Core PowerCLI Component 6.5 build 6234650

Not sure this changes things but without the appliance not sure the bypass applies?

0 Kudos
LucD
Leadership
Leadership

Is that a master or a subscribed content library from which you are pulling the template?

Seems there were issues with vSphere 6.0 master Content libraries.

Unfortunately can't test your code (no more vSphere 6)


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference