VMware Cloud Community
WJPConway
Contributor
Contributor
Jump to solution

Using vAPI endpoint in vRO to deploy an OVF from Content Library

I have been testing two methods of deploying an ovf from vRO 7.2 in a vCenter 6.5. This would be used in conjunction with a workflow that would deploy many similar vm's from the same ovf for a testing environment.

First method is using the OVF Transfer plugin - I have this working and it looks pretty handy and does everything I need it to.

The Second method would be to use the vAPI Endpoint method to deploy ovf from the content library.

I am finding it hard to understand how to get the vAPI method working or to find any blogs examples or how to's on this

I have added my vAPI endpoint in vRO and imported the vAPI metamodel.

Am looking at below example but having difficulty extraction what I need to get a working workflow.

vSphere 6.0 Documentation Center

content-library-api-samples/LibraryCount.java at master · vmware/content-library-api-samples · GitHu...

Has anyone been able to do this or anything similar. I could always use the OVF plugin but am curious about the possibilities of a new method of doing this and other tasks. Not looking for completed workflows or anything just a point in the right direction of how to. Also general information/opinions/experiences from anyone who has used either method

Reply
0 Kudos
1 Solution

Accepted Solutions
iiliev
VMware Employee
VMware Employee
Jump to solution

Hi,

As for library count sample, the equivalent scripting code in vRO would be something like the following:

var client = endpoint.client();

var clib = new com_vmware_content_library(client);

System.log("The number of libraries in this system is: " + clib.list().length);

The input parameter above is variable endpoint of type VAPI:VAPIEndpoint.

For the second question, I'm not familiar with content library API, but maybe the OVF to deploy is referenced by variable libItemId? At the moment I don't have a suitable environment to verify it, sorry.

View solution in original post

Reply
0 Kudos
12 Replies
WJPConway
Contributor
Contributor
Jump to solution

Just to add my assumption would be that I would be passing various inputs to the scriptable task in a workflow - that the below section is what would pull what is required as inputs for the ovf and somehow binding the two

// Retrieve the library items OVF information and use it for populating the

// deployment spec instance.

LibraryItem libItemStub = stubFactory.createStub(LibraryItem.class, myStubConfiguration);

OvfSummary ovfSummary = libItemStub.filter(libItemId, deploymentTarget);

deploymentSpec.setAnnotation(ovfSummary.getAnnotation());

String clientToken = UUID.randomUUID().toString();

DeploymentResult result = libItemStub.deploy(clientToken,libItemId,

                                                           deploymentTarget,

                                                           deploymentSpec);

taken from (VMware vSphere 6.5 Documentation Library )

But am unsure as to where this is getting the source ovf from the content library - assume I am missing something here.

Reply
0 Kudos
iiliev
VMware Employee
VMware Employee
Jump to solution

Hi,

As for library count sample, the equivalent scripting code in vRO would be something like the following:

var client = endpoint.client();

var clib = new com_vmware_content_library(client);

System.log("The number of libraries in this system is: " + clib.list().length);

The input parameter above is variable endpoint of type VAPI:VAPIEndpoint.

For the second question, I'm not familiar with content library API, but maybe the OVF to deploy is referenced by variable libItemId? At the moment I don't have a suitable environment to verify it, sorry.

Reply
0 Kudos
vbranden
Contributor
Contributor
Jump to solution

I believe this gives you a general idea of how to deploy from the content library

REST API - deploy

Using the metamodel should be the same as using the java api LibraryItem (VMware-vSphere-Automation-SDK-Java-6.5.0)

So something like this (untested)

// fill in your specific values

var folderId = "..."

var hostId = "..."

var poolId = "..."

var templateName = "..."

if (endpoint == null) {

throw "'endpoint' parameter should not be null";

}

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) {

    throw new Error("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 = folderId

  deploymentTarget.host_id = hostId

  deploymentTarget.resource_pool_id = poolId

  // create a ResourcePoolDeploymentSpec

  var resourcePoolDeploymentSpec = new com_vmware_vcenter_ovf_library__item_resource__pool__deployment__spec()

  resourcePoolDeploymentSpec.accept_all_EULA = true

  // deploy the ovf

  var ovfSvc = new com_vmware_vcenter_ovf_library__item(client)

  var result = ovfSvc.deploy(null, ovfLibraryItemId, deploymentTarget, resourcePoolDeploymentSpec)

} finally {

  client.close();

}

Reply
0 Kudos
avseelam
Contributor
Contributor
Jump to solution

How do we specify network & storage mappings. I am having hard time deploying to a desired datastore & network using the vAPI
Reply
0 Kudos
anton749
Contributor
Contributor
Jump to solution

Hi Iliev,

I am trying to run the code to get the library items, i added vCenter as VAPI endpoint and then copied your code but i am getting this error

ReferenceError: "com_vmware_content_library" is not defined.

i am running vCenter 6.7 U1f, vRO 7.4. am i perhaps missing something like defining metamodel for the VAPI endpoint or something?

pastedImage_0.png

Reply
0 Kudos
anton749
Contributor
Contributor
Jump to solution

i found the issue, i was not importing the metamodel and missed the /api in the URL

Reply
0 Kudos
anton749
Contributor
Contributor
Jump to solution

hi, I added these lines to the code to try to set network for deployment

resourcePoolDeploymentSpec.network_mappings.key = att_networkInfo.key;

resourcePoolDeploymentSpec.network_mappings.value = att_networkInfo.value;

I get the portgroup key using VcDistributedVirtualPortgroup, but when trying to run I get this error

TypeError: Cannot set property “key” of null to “dvportgroup-624”

Reply
0 Kudos
iiliev
VMware Employee
VMware Employee
Jump to solution

Not familiar with this particular API, but probably you need to initialize resourcePoolDeploymentSpec.network_mappings object before trying to set its key/value properties.

Reply
0 Kudos
anton749
Contributor
Contributor
Jump to solution

i did set the var for resourcePoolDeploymentSpec

var resourcePoolDeploymentSpec = new com_vmware_vcenter_ovf_library__item_resource__pool__deployment__spec();

resourcePoolDeploymentSpec.accept_all_EULA = true;

resourcePoolDeploymentSpec.name = att_vmName;

resourcePoolDeploymentSpec.default_datastore_id = att_datastore.id;

resourcePoolDeploymentSpec.network_mappings.key[0] = att_networkInfo.key;

resourcePoolDeploymentSpec.network_mappings.value[0] = att_networkInfo.value;

Reply
0 Kudos
iiliev
VMware Employee
VMware Employee
Jump to solution

The error is not about resourcePoolDeploymentSpec but about its network_mappings field.

So you probably have to add a line similar to the following before trying to set key/value fields:

resourcePoolDeploymentSpec.network_mappings = new <some-type>();

Also, from the last couple of lines, it looks like key/value fields are arrays, so you may need to do some initialization for them too, or directly assign the whole value arrays instead of individual elements.

Reply
0 Kudos
anton749
Contributor
Contributor
Jump to solution

that seems a bit tricky as I don't find which type those are, I looked in here but not sure REST API - resource_pool_deployment_spec

thanks

Reply
0 Kudos
robrtb12
Enthusiast
Enthusiast
Jump to solution

I started testing this yesterday and was able to assign a network by using a Properties object with the "key" being the Network name that's in the OVF descriptor file ( <Network ovf:name="VM Network"> ) and the "value" being the new Network Object id.

[2020-05-27 15:55:41.785] [D] DynamicWrapper (Instance) : [com_vmware_vcenter_ovf_library__item_resource__pool__deployment__spec]-[class com.vmware.o11n.plugin.vapi.model.VapiObjectWrapper] -- VALUE : com.vmware.o11n.plugin.vapi.model.VapiObjectWrapper@7d7f9c33[{default_datastore_id=datastore-1341, accept_all_EULA=true, network_mappings={VM Network=network-1233}, name=MyNewServer}]

...

// create a ResourcePoolDeploymentSpec 

var resourcePoolDeploymentSpec = new com_vmware_vcenter_ovf_library__item_resource__pool__deployment__spec();

resourcePoolDeploymentSpec.accept_all_EULA = true;

resourcePoolDeploymentSpec.name = att_vmName;

resourcePoolDeploymentSpec.default_datastore_id = att_datastore.id;

var networkMappings = new Properties();

networkMappings.put("VM Network", att_networkObject.id);

resourcePoolDeploymentSpec.network_mappings = networkMappings;

System.debug(resourcePoolDeploymentSpec);

...

OVF descriptor file excerpt:

<NetworkSection>

    <Info>The list of logical networks</Info>

    <Network ovf:name="VM Network">

        <Description>The VM Network network</Description>

    </Network>

</NetworkSection>

Reply
0 Kudos