VMware Cloud Community
frefal
Enthusiast
Enthusiast

Convert VC:VM to vCloud:VM

Hi,

To get the vCloud object from the vCenter one my idea was to use the VC:virtualmachine.name output and then get the vCloud ID within the () and use this with queryservices to find the vCloud object.

Problem is that VC:virtualmachine.name strips away the () so only the plain VM name is returned.

Anyone know if it is possible to change the behavior of this, or another way to get the VC object full name?

Thanks!

9 Replies
Burke-
VMware Employee
VMware Employee

Hello, I'm at VMworld right now and don't have a test vCD instance available to play around with.. but looking through some of my workflow library, I only see flows for going the other direction - Getting vCenter VM for a given vCloud VM. In this case, we have commonly used the MoRef (Managed Object Reference). From the vCD side, this looks like vm.getVMVimRef().moRef -- where "vm" is a vCloud:VM object. And on the vCenter side, this is simply vm.id -- where "vm" is a VC:VirtualMachine. I'm not sure if this helps, but I hope it gives you an idea of one possible avenue of test Smiley Happy

Good luck!

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you! Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator for vRealize Orchestrator tips and tutorials - @TechnicalValues on Twitter
frefal
Enthusiast
Enthusiast

Thanks for you answer and enjoy VMworld!

As you say the other way is a more common practice and not a problem.

I have a workflow that runs both VC:VM and Vcloud:VM workflows and my idea was to start it from the web client context menu.

If I somehow is able to extract the ID within () from the VC:VM then it would be fine!! Anyone with any idea? For example, can I get the folder name in the datastore of this VC:VM from the object?

Thanks

Reply
0 Kudos
ashutoshyadav
Contributor
Contributor

Did you find a way to

Convert VC:VM to vCloud:VM ?

Reply
0 Kudos
qc4vmware
Virtuoso
Virtuoso

This is a snippet of code that will get you the VC:VM from a vCloud:VM.  Note I have an action that determines which vCenter in my inventory the vm lives in.  You can just set it statically or prompt for it but you need it for the lookup.

// determine the vCenter to perform the lookup on

var vcServer = System.getModule("com.qualcomm.basic").QCgetvCenterFromVclVm(vm);

// create reference object for lookup

var managedObject = new VcManagedObjectReference();

var vcVmMoRef = vm.getVMVimRef().moRef;


managedObject.type = "VirtualMachine";

managedObject.value = vcVmMoRef;

// Lookup the vm based on the managed object reference

var vcVm = VcPlugin.convertToVimManagedObject(vcServer , managedObject);

Reply
0 Kudos
legioon
Enthusiast
Enthusiast

hi qc4vmware

I have similar issue, I don't have this action object ;

System.getModule("com.qualcomm.basic").QCgetvCenterFromVclVm(vm);

if you have could you please send it to me ?

Thanks.

qc4vmware
Virtuoso
Virtuoso

This is how I did it.  I'm pretty sure I found this code in the orchestrator forum somewhere.

var vApp = vm.parent; 

var vdc = vApp.parent; 

var org = vdc.parent; 

var host = org.parent; 

var providerVdcReference = vdc.toAdminObject().providerVdcReference; 

var providerVdc = host.getEntityByReference(VclFinderType.PROVIDER_VDC ,providerVdcReference); 

var adminExtProviderVdc = providerVdc.toAdminExtensionObject(); 

var vimServerUrl = adminExtProviderVdc.getVimServers()[0].url; 

 

//Check we have the right vCenter server for that 

var allVimServers = VcPlugin.allSdkConnections; 

var gotRightVimServer = false; 

for each (var vimServer in allVimServers) { 

//   System.log(vimServer.name); 

    if (isHostIpMatch(getHostname(vimServer.name),getHostname(vimServerUrl))) { 

        gotRightVimServer = true; 

  return vimServer;

    }     

function getHostname(url){ 

    // expected input is in form of https://myhost:443 or https://myhost.domain.com:443 

    return url.substring(url.indexOf("://") + 3,url.lastIndexOf(":")); 

function isHostIpMatch(host1,host2) {

  var host1Ip = System.resolveHostName(host1); 

  var host2Ip = System.resolveHostName(host2); 

// System.log("host1Ip = " + host1Ip) 

// System.log("host2Ip = " +host2Ip) 

  return (host1Ip == host2Ip);

}

Reply
0 Kudos
qc4vmware
Virtuoso
Virtuoso

If this worked for you can you mark my answer as the answer?  Thanks!

Reply
0 Kudos
legioon
Enthusiast
Enthusiast

Hi,

this, did not worked me but i found own solution ;

I wrote this workflow, its very basic ;

var vcloudvmvm=vm.getVMVimRef().moRef;

for each( vcentervm in vcentersdk.getAllVirtualMachines()) {

if (vcloudvmvm==vcentervm.id) {

vCenterVmOut=vcentervm;

break;

}

}

vm variable is vcloud:vm attribute ( select vm )

vcentersdk variable is VC:sdkConnection attribute.( select vcenter )

vCenterVmOut variable is vc:VirtualMachine Attiribute.

You can convert vCloud:vm to vc:VirtualMachine or vc:VirtualMachine  to vCloud:vm wtih this method..

Reply
0 Kudos
qc4vmware
Virtuoso
Virtuoso

So I'll throw this out there in the spirit of letting others learn from my pain.  Avoid vcentersdk.getAllVirtualMachines() when at all possible.  Especially if you are dealing with large vCenter inventories.  It is indeed quick and easy but can come at a cost in both speed and stability.

Sorry my samples aren't working for you.  I'm not sure why they are not as we have had them in production for years but it could be some variance in our environments that are the culprit.  Glad you have something working now.

Reply
0 Kudos