@@ -0,0 +1,2294 @@
+package com.vmware.vim25.mo.samples.vm;%0A%0Aimport java.rmi.RemoteException;%0A%0Aimport com.vmware.vim25.mo.HostSystem;%0Aimport com.vmware.vim25.mo.InventoryNavigator;%0Aimport com.vmware.vim25.mo.ResourcePool;%0Aimport com.vmware.vim25.mo.ServiceInstance;%0Aimport com.vmware.vim25.mo.VirtualMachine;%0Aimport com.vmware.vim25.mo.samples.SampleUtil;%0A%0Apublic class VmConvert %7B%0A%0A    public static void main(String%5B%5D args) throws Exception %7B%0A%09ServiceInstance si = SampleUtil.createServiceInstance();%0A%0A%09VmConvert vmConvert = new VmConvert();%0A%09vmConvert.convertToTemplate(si, %22vm1%22);%0A%09vmConvert.convertToVm(si, %22vm1%22, %22rp1%22, null);%0A%0A%09si.getServerConnection().logout();%0A    %7D%0A%0A    public void convertToTemplate(ServiceInstance si, String vmName) throws Exception %7B%0A%09VirtualMachine vm = (VirtualMachine) new InventoryNavigator(si.getRootFolder()).searchManagedEntity(%22VirtualMachine%22, vmName);%0A%09if (vm == null) %7B%0A%09    System.out.println(%22Not found vm %22 + vmName);%0A%09    return;%0A%09%7D%0A%09if (vm.getConfig().isTemplate()) %7B%0A%09    System.out.println(%22The vm %22 + vmName + %22 is already a template!%22);%0A%09    return;%0A%09%7D%0A%09vm.markAsTemplate();%0A%09System.out.println(%22Convert vm %22 + vmName + %22 to template successfully!%22);%0A    %7D%0A%0A    /**%0A     * @param hostName The target host on which the virtual machine is intended to run. If it is set to null, the default host will be used.%0A     */%0A    public void convertToVm(ServiceInstance si, String vmName, String poolName, String hostName) throws RemoteException %7B%0A%09VirtualMachine vm = (VirtualMachine) new InventoryNavigator(si.getRootFolder()).searchManagedEntity(%22VirtualMachine%22, vmName);%0A%09if (vm == null) %7B%0A%09    System.out.println(%22Not found vm %22 + vmName);%0A%09    return;%0A%09%7D%0A%09ResourcePool pool = (ResourcePool) new InventoryNavigator(si.getRootFolder()).searchManagedEntity(%22ResourcePool%22, poolName);%0A%09if (pool == null) %7B%0A%09    System.out.println(%22Not found resource pool %22 + poolName);%0A%09    return;%0A%09%7D%0A%09HostSystem host = null;%0A%09if (hostName != null) %7B%0A%09    host = (HostSystem) new InventoryNavigator(si.getRootFolder()).searchManagedEntity(%22HostSystem%22, hostName);%0A%09    if (host == null) %7B%0A%09%09System.out.println(%22Not found host %22 + hostName);%0A%09%09return;%0A%09    %7D%0A%09%7D%0A%09vm.markAsVirtualMachine(pool, host);%0A%09System.out.println(%22Convert vm %22 + vmName + %22 from template successfully!%22);%0A    %7D%0A%0A%7D%0A

Add sample code for vm/template convertion.