Last active
August 23, 2016 21:51
-
-
Save jeffgreenca/389a8da3c74bb76383c0d865ca09b5b2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var transform = null; | |
if (thinProvisioned == true) { | |
transform = VcVirtualMachineRelocateTransformation.sparse; | |
} else if (thinProvisioned == false) { | |
transform = VcVirtualMachineRelocateTransformation.flat; | |
} | |
if (datastore == null) { | |
datastore = vm.datastore[0]; | |
} | |
relocateSpec = System.getModule("com.vmware.library.vc.vm.spec").getRelocateSpec(datastore,null,host,pool,transform); | |
///////////////// Build ServiceLocator for cross-vCenter vMotion -- Begin modifications JG | |
var vCreds = new VcServiceLocatorNamePassword(); //Future: Use SAML token isntead of user/pass | |
vCreds.username = vcusername; | |
vCreds.password = vcpassword; | |
var vcSL = new VcServiceLocator(); | |
var destVcSdk = VcPlugin.allSdkConnections[1]; //TODO: Fix this hack | |
vcSL.instanceUuid = destVcSdk.about.instanceUuid; | |
vcSL.url = destVcSdk.name.toString(); | |
vcSL.sslThumbprint = destvCenterThumbprint; //Ugly, but vCO doesn't provide a mechanism to query vCenter SSL thumbprint that I can find. | |
vcSL.credential = vCreds; | |
relocateSpec.service = vcSL; //Add ServiceLocator to relocate spec | |
//////////////////// End substantative modifications | |
cloneSpec = System.getModule("com.vmware.library.vc.vm.spec").getCloneSpec(null,null,relocateSpec,powerOn,template); | |
var task = vm.cloneVM_Task(vmFolder, name, cloneSpec); | |
var actionResult = System.getModule("com.vmware.library.vc.basic").vim3WaitTaskEnd(task,true,2); | |
// If success, actionResult == VC:VirtualMachine object representing the cloned VM, partially. | |
// The VM ID is correct, but the sdk connection will be against the source vCenter not the destination. | |
// I use a function to map this vm id and destination sdk connection to a VC:VirtualMachine object to do further operations |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment