Please use below script to get depoy the VM from content library after adding the vapi end point in vmware orachestrator.
input & out put parameters:
Name | Type | Description |
datastore | VC:Datastore | The datastore to deploy to |
endpoint | VAPI:VAPIEndpoint | The VAPI endpoint to use |
folder | VC:VmFolder | The folder to deploy to |
host | VC:HostSystem | The target host for deployment |
hostname | string | Name of the new VM |
ovfLibraryItemId | string | id of the content library item |
respool | VC:ResourcePool | Resource pool to deploy to |
vmObject VC:VirtualMachine VM created details
Script :
// Set the VAPI endpoint to the first endpoint returned
if (endpoint == null) {
throw"Unable to locate a VAPI endpoint";
}
var client = endpoint.client();
try {
var itemSvc = new com_vmware_content_library_item(client)
var findItemSpec = new com_vmware_content_library_item_find__spec()
findItemSpec.name = TemplateName
var results = itemSvc.find(findItemSpec)
if (!Array.isArray(results) || !results.length) {
thrownewError("Content Library template " + TemplateName + " was not found")
}
var ovfLibraryItemId = results.shift()
// create a DeploymentTarget
var deploymentTarget = new com_vmware_vcenter_ovf_library__item_deployment__target();
deploymentTarget.folder_id = folder.id;
deploymentTarget.host_id = host.id;
deploymentTarget.resource_pool_id = respool.id;
// create a ResourcePoolDeploymentSpec
var resourcePoolDeploymentSpec = new com_vmware_vcenter_ovf_library__item_resource__pool__deployment__spec();
resourcePoolDeploymentSpec.accept_all_EULA = true;
resourcePoolDeploymentSpec.name = hostname;
resourcePoolDeploymentSpec.default_datastore_id = datastore.id;
// deploy the ovf
var ovfSvc = new com_vmware_vcenter_ovf_library__item(client);
var result = ovfSvc.deploy(null, ovfLibraryItemId, deploymentTarget, resourcePoolDeploymentSpec);
// return the vmObject
vmObject = VcPlugin.getAllVirtualMachines(null, "xpath:matches(id, '" + result.resource_id.id + "')")[0];
}
finally {
client.close();
}