You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by hu...@apache.org on 2013/09/24 05:54:43 UTC

[2/4] Move away from the services model and fix all resulting errors

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/67fc53ab/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java
----------------------------------------------------------------------
diff --git a/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java b/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java
index 3cd4463..0fa8cad 100644
--- a/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java
+++ b/vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java
@@ -91,6 +91,14 @@ import com.vmware.vim25.VirtualMachineSnapshotTree;
 import com.vmware.vim25.VirtualPCIController;
 import com.vmware.vim25.VirtualSCSIController;
 import com.vmware.vim25.VirtualSCSISharing;
+import com.vmware.vim25.mo.Folder;
+import com.vmware.vim25.mo.HostSystem;
+import com.vmware.vim25.mo.OvfManager;
+import com.vmware.vim25.mo.PropertyCollector;
+import com.vmware.vim25.mo.ResourcePool;
+import com.vmware.vim25.mo.Task;
+import com.vmware.vim25.mo.VirtualMachine;
+import com.vmware.vim25.mo.VirtualMachineSnapshot;
 
 import com.cloud.hypervisor.vmware.mo.SnapshotDescriptor.SnapshotInfo;
 import com.cloud.hypervisor.vmware.util.VmwareContext;
@@ -105,13 +113,16 @@ import java.util.Arrays;
 public class VirtualMachineMO extends BaseMO {
     private static final Logger s_logger = Logger.getLogger(VirtualMachineMO.class);
     private ManagedObjectReference _vmEnvironmentBrowser = null;
+    private VirtualMachine _virtualMachine;
 
 	public VirtualMachineMO(VmwareContext context, ManagedObjectReference morVm) {
 		super(context, morVm);
+		_virtualMachine = new VirtualMachine(context.getServerConnection(), morVm);
 	}
 
 	public VirtualMachineMO(VmwareContext context, String morType, String morValue) {
 		super(context, morType, morValue);
+		_virtualMachine = new VirtualMachine(context.getServerConnection(), _mor);
 	}
 
 	public Pair<DatacenterMO, String> getOwnerDatacenter() throws Exception {
@@ -123,7 +134,7 @@ public class VirtualMachineMO extends BaseMO {
 
 		PropertySpec pSpec = new PropertySpec();
 		pSpec.setType("Datastore");
-		pSpec.getPathSet().add("name");
+		pSpec.setPathSet(new String[] { "name" });
 
 	    TraversalSpec vmDatastoreTraversal = new TraversalSpec();
 	    vmDatastoreTraversal.setType("VirtualMachine");
@@ -133,21 +144,20 @@ public class VirtualMachineMO extends BaseMO {
 	    ObjectSpec oSpec = new ObjectSpec();
 	    oSpec.setObj(_mor);
 	    oSpec.setSkip(Boolean.TRUE);
-	    oSpec.getSelectSet().add(vmDatastoreTraversal);
+	    oSpec.setSelectSet(new TraversalSpec[] { vmDatastoreTraversal });
 
 	    PropertyFilterSpec pfSpec = new PropertyFilterSpec();
-	    pfSpec.getPropSet().add(pSpec);
-	    pfSpec.getObjectSet().add(oSpec);
+	    pfSpec.setPropSet( new PropertySpec[] { pSpec });
+	    pfSpec.setObjectSet( new ObjectSpec[] { oSpec });
         List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>();
         pfSpecArr.add(pfSpec);
 
-	    List<ObjectContent> ocs = _context.getService().retrieveProperties(
-	    	_context.getPropertyCollector(), pfSpecArr);
-
+        PropertyCollector pc = _context.getPropertyCollector();
+        ObjectContent[] ocs = pc.retrieveProperties(pfSpecArr.toArray(new PropertyFilterSpec[0]));
 
 	    if(ocs != null) {
 	    	for(ObjectContent oc : ocs) {
-	    		DynamicProperty prop = oc.getPropSet().get(0);
+	    		DynamicProperty prop = oc.getPropSet()[0];
 	    		if(prop.getVal().toString().equals(dsName)) {
 	    			return new Pair<DatastoreMO, String>(new DatastoreMO(_context, oc.getObj()), dsName);
 	    		}
@@ -180,11 +190,13 @@ public class VirtualMachineMO extends BaseMO {
 	}
 
 	public boolean powerOn() throws Exception {
-		if(getPowerState() == VirtualMachinePowerState.POWERED_ON)
+		if(getPowerState() == VirtualMachinePowerState.poweredOn)
 			return true;
 
-		ManagedObjectReference morTask = _context.getService().powerOnVMTask(_mor, null);
-
+		VirtualMachine vm = new VirtualMachine(_context.getServerConnection(), _mor);
+		Task task = vm.powerOnVM_Task(null);
+		ManagedObjectReference morTask = task.getMOR();
+		
 		boolean result = _context.getVimClient().waitForTask(morTask);
 		if(result) {
 			_context.waitForTaskProgressDone(morTask);
@@ -197,7 +209,7 @@ public class VirtualMachineMO extends BaseMO {
 	}
 
 	public boolean powerOff() throws Exception {
-		if(getPowerState() == VirtualMachinePowerState.POWERED_OFF)
+		if(getPowerState() == VirtualMachinePowerState.poweredOff)
 			return true;
 
 		return powerOffNoCheck();
@@ -205,7 +217,7 @@ public class VirtualMachineMO extends BaseMO {
 
 	public boolean safePowerOff(int shutdownWaitMs) throws Exception {
 
-		if(getPowerState() == VirtualMachinePowerState.POWERED_OFF)
+		if(getPowerState() == VirtualMachinePowerState.poweredOff)
 			return true;
 
 		if(isVMwareToolsRunning()) {
@@ -216,14 +228,14 @@ public class VirtualMachineMO extends BaseMO {
 				shutdown();
 
 				long startTick = System.currentTimeMillis();
-				while(getPowerState() != VirtualMachinePowerState.POWERED_OFF && System.currentTimeMillis() - startTick < shutdownWaitMs) {
+				while(getPowerState() != VirtualMachinePowerState.poweredOff && System.currentTimeMillis() - startTick < shutdownWaitMs) {
 					try {
 						Thread.sleep(1000);
 					} catch(InterruptedException e) {
 					}
 				}
 
-				if(getPowerState() != VirtualMachinePowerState.POWERED_OFF) {
+				if(getPowerState() != VirtualMachinePowerState.poweredOff) {
 					s_logger.info("can not gracefully shutdown VM within " + (shutdownWaitMs/1000) + " seconds, we will perform force power off on VM " + vmName);
 					return powerOffNoCheck();
 				}
@@ -238,7 +250,8 @@ public class VirtualMachineMO extends BaseMO {
 	}
 
 	private boolean powerOffNoCheck() throws Exception {
-		ManagedObjectReference morTask = _context.getService().powerOffVMTask(_mor);
+		Task task = getVirtualMachine().powerOffVM_Task();
+		ManagedObjectReference morTask = task.getMOR();
 
 		boolean result = _context.getVimClient().waitForTask(morTask);
 		if(result) {
@@ -248,7 +261,7 @@ public class VirtualMachineMO extends BaseMO {
 			// wait up to 5 seconds to make sure to avoid race conditioning for immediate following on operations
 			// that relies on a powered-off VM
 			long startTick = System.currentTimeMillis();
-			while(getPowerState() != VirtualMachinePowerState.POWERED_OFF && System.currentTimeMillis() - startTick < 5000) {
+			while(getPowerState() != VirtualMachinePowerState.poweredOff && System.currentTimeMillis() - startTick < 5000) {
 				try {
 					Thread.sleep(1000);
 				} catch(InterruptedException e) {
@@ -256,7 +269,7 @@ public class VirtualMachineMO extends BaseMO {
 			}
 			return true;
 		} else {
-			 if(getPowerState() == VirtualMachinePowerState.POWERED_OFF) {
+			 if(getPowerState() == VirtualMachinePowerState.poweredOff) {
 				 // to help deal with possible race-condition
 				 s_logger.info("Current power-off task failed. However, VM has been switched to the state we are expecting for");
 				 return true;
@@ -270,7 +283,7 @@ public class VirtualMachineMO extends BaseMO {
 
 	public VirtualMachinePowerState getPowerState() throws Exception {
 
-	    VirtualMachinePowerState powerState = VirtualMachinePowerState.POWERED_OFF;
+	    VirtualMachinePowerState powerState = VirtualMachinePowerState.poweredOff;
 
 	    // This is really ugly, there is a case that when windows guest VM is doing sysprep, the temporary
 	    // rebooting process may let us pick up a "poweredOff" state during VMsync process, this can trigger
@@ -281,7 +294,7 @@ public class VirtualMachineMO extends BaseMO {
 	    // state report, until then we can remove this hacking fix
 	    for(int i = 0; i < 3; i++) {
 	        powerState = (VirtualMachinePowerState)getContext().getVimClient().getDynamicProperty(_mor, "runtime.powerState");
-	        if(powerState == VirtualMachinePowerState.POWERED_OFF) {
+	        if(powerState == VirtualMachinePowerState.poweredOff) {
 	            try {
 	                Thread.sleep(1000);
 	            } catch(InterruptedException e) {
@@ -295,7 +308,8 @@ public class VirtualMachineMO extends BaseMO {
 	}
 
 	public boolean reset() throws Exception {
-		ManagedObjectReference morTask = _context.getService().resetVMTask(_mor);
+	    Task task = getVirtualMachine().resetVM_Task();
+		ManagedObjectReference morTask = task.getMOR();
 
 		boolean result = _context.getVimClient().waitForTask(morTask);
 		if(result) {
@@ -308,15 +322,15 @@ public class VirtualMachineMO extends BaseMO {
 	}
 
 	public void shutdown() throws Exception {
-		_context.getService().shutdownGuest(_mor);
+	    getVirtualMachine().shutdownGuest();
 	}
 
 	public void rebootGuest() throws Exception {
-		_context.getService().rebootGuest(_mor);
+		getVirtualMachine().rebootGuest();
 	}
 
 	public void markAsTemplate() throws Exception {
-		_context.getService().markAsTemplate(_mor);
+		getVirtualMachine().markAsTemplate();
 	}
 
 	public boolean isTemplate() throws Exception {
@@ -325,9 +339,11 @@ public class VirtualMachineMO extends BaseMO {
 	}
 
 	public boolean migrate(ManagedObjectReference morRp, ManagedObjectReference morTargetHost) throws Exception {
-		ManagedObjectReference morTask = _context.getService().migrateVMTask(_mor,
-			morRp, morTargetHost, VirtualMachineMovePriority.DEFAULT_PRIORITY, null);
-
+	    ResourcePool rp = new ResourcePool(_context.getServerConnection(), morRp);
+	    HostSystem host = new HostSystem(_context.getServerConnection(), morTargetHost);
+	    Task task = getVirtualMachine().migrateVM_Task(rp, host, VirtualMachineMovePriority.defaultPriority, null);
+	    ManagedObjectReference morTask = task.getMOR();
+	    
 		boolean result = _context.getVimClient().waitForTask(morTask);
 		if(result) {
 			_context.waitForTaskProgressDone(morTask);
@@ -340,19 +356,21 @@ public class VirtualMachineMO extends BaseMO {
 	}
 
     public boolean changeDatastore(VirtualMachineRelocateSpec relocateSpec) throws Exception {
-        ManagedObjectReference morTask = _context.getVimClient().getService().relocateVMTask(_mor, relocateSpec, VirtualMachineMovePriority.DEFAULT_PRIORITY);
-        boolean result = _context.getVimClient().waitForTask(morTask);
+        VirtualMachine vm = new VirtualMachine(_context.getServerConnection(), _mor);
+        Task task = vm.relocateVM_Task(relocateSpec, VirtualMachineMovePriority.defaultPriority);
+        boolean result = _context.getVimClient().waitForTask(task.getMOR());
         if(result) {
-            _context.waitForTaskProgressDone(morTask);
+            _context.waitForTaskProgressDone(task.getMOR());
             return true;
         } else {
-            s_logger.error("VMware RelocateVM_Task to change datastore failed due to " + TaskMO.getTaskFailureInfo(_context, morTask));
+            s_logger.error("VMware RelocateVM_Task to change datastore failed due to " + TaskMO.getTaskFailureInfo(_context, task.getMOR()));
         }
         return false;
     }
 
     public boolean changeHost(VirtualMachineRelocateSpec relocateSpec) throws Exception {
-        ManagedObjectReference morTask = _context.getService().relocateVMTask(_mor, relocateSpec, VirtualMachineMovePriority.DEFAULT_PRIORITY);
+        Task task = getVirtualMachine().relocateVM_Task(relocateSpec, VirtualMachineMovePriority.defaultPriority);
+        ManagedObjectReference morTask = task.getMOR();
         boolean result = _context.getVimClient().waitForTask(morTask);
         if (result) {
             _context.waitForTaskProgressDone(morTask);
@@ -366,9 +384,9 @@ public class VirtualMachineMO extends BaseMO {
 	public boolean relocate(ManagedObjectReference morTargetHost) throws Exception {
 	    VirtualMachineRelocateSpec relocateSpec = new VirtualMachineRelocateSpec();
 	    relocateSpec.setHost(morTargetHost);
-
-        ManagedObjectReference morTask = _context.getService().relocateVMTask(_mor,
-            relocateSpec, null);
+	    
+	    Task task = getVirtualMachine().relocateVM_Task(relocateSpec);
+        ManagedObjectReference morTask = task.getMOR();
 
         boolean result = _context.getVimClient().waitForTask(morTask);
         if(result) {
@@ -387,9 +405,8 @@ public class VirtualMachineMO extends BaseMO {
 
 	public boolean createSnapshot(String snapshotName, String snapshotDescription,
 		boolean dumpMemory, boolean quiesce) throws Exception {
-
-		ManagedObjectReference morTask = _context.getService().createSnapshotTask(_mor, snapshotName,
-			snapshotDescription, dumpMemory, quiesce);
+	    Task task = getVirtualMachine().createSnapshot_Task(snapshotName, snapshotDescription, dumpMemory, quiesce);
+		ManagedObjectReference morTask = task.getMOR();
 
 		boolean result = _context.getVimClient().waitForTask(morTask);
 		if(result) {
@@ -424,8 +441,11 @@ public class VirtualMachineMO extends BaseMO {
 			s_logger.warn("Unable to find snapshot: " + snapshotName);
 			return false;
 		}
-
-		ManagedObjectReference morTask = _context.getService().removeSnapshotTask(morSnapshot, removeChildren, true);
+		
+		VirtualMachineSnapshot snapshot = new VirtualMachineSnapshot(_context.getServerConnection(), morSnapshot);
+		Task task = snapshot.removeSnapshot_Task(removeChildren, true);
+		ManagedObjectReference morTask = task.getMOR();
+		
 		boolean result = _context.getVimClient().waitForTask(morTask);
 		if(result) {
 			_context.waitForTaskProgressDone(morTask);
@@ -443,8 +463,9 @@ public class VirtualMachineMO extends BaseMO {
             s_logger.warn("Unable to find snapshot: " + snapshotName);
             return false;
         }
-        ManagedObjectReference morTask = _context.getService()
-                .revertToSnapshotTask(morSnapshot, _mor, null);
+        VirtualMachineSnapshot snapshot = new VirtualMachineSnapshot(_context.getServerConnection(), morSnapshot);
+        Task task = snapshot.revertToSnapshot_Task(null);
+        ManagedObjectReference morTask = task.getMOR();
         boolean result = _context.getVimClient().waitForTask(morTask);
         if (result) {
             _context.waitForTaskProgressDone(morTask);
@@ -458,20 +479,15 @@ public class VirtualMachineMO extends BaseMO {
     }
 
 	public boolean removeAllSnapshots() throws Exception {
-		VirtualMachineSnapshotInfo snapshotInfo = getSnapshotInfo();
-
-		if(snapshotInfo != null && snapshotInfo.getRootSnapshotList() != null) {
-			List<VirtualMachineSnapshotTree> tree = snapshotInfo.getRootSnapshotList();
-			for(VirtualMachineSnapshotTree treeNode : tree) {
-				ManagedObjectReference morTask = _context.getService().removeSnapshotTask(treeNode.getSnapshot(), true, true);
-				boolean result = _context.getVimClient().waitForTask(morTask);
-				if(result) {
-					_context.waitForTaskProgressDone(morTask);
-				} else {
-		        	s_logger.error("VMware removeSnapshot_Task failed due to " + TaskMO.getTaskFailureInfo(_context, morTask));
-		        	return false;
-				}
-			}
+	    Task task = _virtualMachine.removeAllSnapshots_Task(true);
+	    ManagedObjectReference morTask = task.getMOR();
+
+	    boolean result = _context.getVimClient().waitForTask(morTask);
+		if(result) {
+			_context.waitForTaskProgressDone(morTask);
+		} else {
+        	s_logger.error("VMware removeAllSnapshots_Task failed due to " + TaskMO.getTaskFailureInfo(_context, morTask));
+        	return false;
 		}
 
 		return true;
@@ -526,31 +542,30 @@ public class VirtualMachineMO extends BaseMO {
 	public String getSnapshotDescriptorDatastorePath() throws Exception {
 		PropertySpec pSpec = new PropertySpec();
 		pSpec.setType("VirtualMachine");
-		pSpec.getPathSet().add("name");
-		pSpec.getPathSet().add("config.files");
+		pSpec.setPathSet(new String[] { "name", "config.files" });
 
 	    ObjectSpec oSpec = new ObjectSpec();
 	    oSpec.setObj(_mor);
 	    oSpec.setSkip(Boolean.FALSE);
 
 	    PropertyFilterSpec pfSpec = new PropertyFilterSpec();
-	    pfSpec.getPropSet().add(pSpec);
-	    pfSpec.getObjectSet().add(oSpec);
+	    pfSpec.setPropSet( new PropertySpec[] { pSpec });
+	    pfSpec.setObjectSet( new ObjectSpec[] { oSpec });
         List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>();
         pfSpecArr.add(pfSpec);
 
-	    List<ObjectContent> ocs = _context.getService().retrieveProperties(
-	    	_context.getPropertyCollector(), pfSpecArr);
+        PropertyCollector pc = _context.getPropertyCollector();
+	    ObjectContent[] ocs = pc.retrieveProperties(pfSpecArr.toArray(new PropertyFilterSpec[0]));
 	    assert(ocs != null);
 
     	String vmName = null;
     	VirtualMachineFileInfo fileInfo = null;
 
-    	assert(ocs.size() == 1);
+    	assert(ocs.length == 1);
     	for(ObjectContent oc : ocs) {
-    		List<DynamicProperty> props = oc.getPropSet();
+    		DynamicProperty[] props = oc.getPropSet();
     		if(props != null) {
-    			assert(props.size() == 2);
+    			assert(props.length == 2);
 
     			for(DynamicProperty prop : props) {
     				if(prop.getName().equals("name")) {
@@ -572,7 +587,7 @@ public class VirtualMachineMO extends BaseMO {
 	public ManagedObjectReference getSnapshotMor(String snapshotName) throws Exception {
 		VirtualMachineSnapshotInfo info = getSnapshotInfo();
 		if(info != null) {
-	         List<VirtualMachineSnapshotTree> snapTree = info.getRootSnapshotList();
+	         VirtualMachineSnapshotTree[] snapTree = info.getRootSnapshotList();
 	         return VmwareHelper.findSnapshotInTree(snapTree, snapshotName);
 		}
 		return null;
@@ -589,7 +604,9 @@ public class VirtualMachineMO extends BaseMO {
 
      	relocSpec.setDatastore(morDs);
      	relocSpec.setPool(morResourcePool);
-        ManagedObjectReference morTask = _context.getService().cloneVMTask(_mor, morFolder, cloneName, cloneSpec);
+     	Folder folder = new Folder(_context.getServerConnection(), morFolder);
+     	Task task = _virtualMachine.cloneVM_Task(folder, cloneName, cloneSpec);
+        ManagedObjectReference morTask = task.getMOR();
 
 		boolean result = _context.getVimClient().waitForTask(morTask);
 		if(result) {
@@ -619,14 +636,14 @@ public class VirtualMachineMO extends BaseMO {
                 VirtualMachineRelocateSpecDiskLocator loc = new VirtualMachineRelocateSpecDiskLocator();
             	loc.setDatastore(morDs);
             	loc.setDiskId(independentDisks[i].getKey());
-            	loc.setDiskMoveType(VirtualMachineRelocateDiskMoveOptions.MOVE_ALL_DISK_BACKINGS_AND_DISALLOW_SHARING.value());
+            	loc.setDiskMoveType(VirtualMachineRelocateDiskMoveOptions.moveAllDiskBackingsAndDisallowSharing.toString());
             	diskLocator.add(loc);
             }
 
-            rSpec.setDiskMoveType(VirtualMachineRelocateDiskMoveOptions.CREATE_NEW_CHILD_DISK_BACKING.value());
-            rSpec.getDisk().addAll(diskLocator);
+            rSpec.setDiskMoveType(VirtualMachineRelocateDiskMoveOptions.createNewChildDiskBacking.toString());
+            rSpec.setDisk(diskLocator.toArray(new VirtualMachineRelocateSpecDiskLocator[0]));
         } else {
-        	rSpec.setDiskMoveType(VirtualMachineRelocateDiskMoveOptions.CREATE_NEW_CHILD_DISK_BACKING.value());
+        	rSpec.setDiskMoveType(VirtualMachineRelocateDiskMoveOptions.createNewChildDiskBacking.toString());
         }
         rSpec.setPool(morResourcePool);
 
@@ -636,7 +653,9 @@ public class VirtualMachineMO extends BaseMO {
         cloneSpec.setLocation(rSpec);
         cloneSpec.setSnapshot(morBaseSnapshot);
 
-        ManagedObjectReference morTask = _context.getService().cloneVMTask(_mor, morFolder, cloneName, cloneSpec);
+        Folder folder = new Folder(_context.getServerConnection(), morFolder);
+        Task task = _virtualMachine.cloneVM_Task(folder, cloneName, cloneSpec);
+        ManagedObjectReference morTask = task.getMOR();
 
 		boolean result = _context.getVimClient().waitForTask(morTask);
 		if(result) {
@@ -678,7 +697,7 @@ public class VirtualMachineMO extends BaseMO {
 	public String[] getNetworks() throws Exception {
 		PropertySpec pSpec = new PropertySpec();
 		pSpec.setType("Network");
-		pSpec.getPathSet().add("name");
+		pSpec.setPathSet(new String[] { "name" });
 
 	    TraversalSpec vm2NetworkTraversal = new TraversalSpec();
 	    vm2NetworkTraversal.setType("VirtualMachine");
@@ -688,21 +707,21 @@ public class VirtualMachineMO extends BaseMO {
 	    ObjectSpec oSpec = new ObjectSpec();
 	    oSpec.setObj(_mor);
 	    oSpec.setSkip(Boolean.TRUE);
-	    oSpec.getSelectSet().add(vm2NetworkTraversal);
+	    oSpec.setSelectSet(new TraversalSpec[] { vm2NetworkTraversal });
 
 	    PropertyFilterSpec pfSpec = new PropertyFilterSpec();
-	    pfSpec.getPropSet().add(pSpec);
-	    pfSpec.getObjectSet().add(oSpec);
+	    pfSpec.setPropSet(new PropertySpec[] { pSpec });
+	    pfSpec.setObjectSet(new ObjectSpec[] { oSpec });
         List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>();
         pfSpecArr.add(pfSpec);
 
-	    List<ObjectContent> ocs = _context.getService().retrieveProperties(
-	    	_context.getPropertyCollector(), pfSpecArr);
+        PropertyCollector pc = _context.getPropertyCollector();
+	    ObjectContent[] ocs = pc.retrieveProperties(pfSpecArr.toArray(new PropertyFilterSpec[0]));
 
 	    List<String> networks = new ArrayList<String>();
-	    if(ocs != null && ocs.size() > 0) {
+	    if(ocs != null && ocs.length > 0) {
 	    	for(ObjectContent oc : ocs) {
-	    		networks.add(oc.getPropSet().get(0).getVal().toString());
+	    		networks.add(oc.getPropSet()[0].getVal().toString());
 	    	}
 	    }
 	    return networks.toArray(new String[0]);
@@ -720,9 +739,7 @@ public class VirtualMachineMO extends BaseMO {
 
 		PropertySpec pSpec = new PropertySpec();
 		pSpec.setType("Network");
-		pSpec.getPathSet().add("name");
-		pSpec.getPathSet().add("vm");
-		pSpec.getPathSet().add(String.format("value[%d]", gcTagKey));
+		pSpec.setPathSet( new String[] { "name", "vm", String.format("value[%d]", gcTagKey) } );
 
 	    TraversalSpec vm2NetworkTraversal = new TraversalSpec();
 	    vm2NetworkTraversal.setType("VirtualMachine");
@@ -732,19 +749,19 @@ public class VirtualMachineMO extends BaseMO {
 	    ObjectSpec oSpec = new ObjectSpec();
 	    oSpec.setObj(_mor);
 	    oSpec.setSkip(Boolean.TRUE);
-	    oSpec.getSelectSet().add(vm2NetworkTraversal);
+	    oSpec.setSelectSet(new TraversalSpec[] { vm2NetworkTraversal });
 
 	    PropertyFilterSpec pfSpec = new PropertyFilterSpec();
-	    pfSpec.getPropSet().add(pSpec);
-	    pfSpec.getObjectSet().add(oSpec);
+	    pfSpec.setPropSet( new PropertySpec[] { pSpec });
+	    pfSpec.setObjectSet( new ObjectSpec[] { oSpec });
         List<PropertyFilterSpec> pfSpecArr = new ArrayList<PropertyFilterSpec>();
         pfSpecArr.add(pfSpec);
 
-	    List<ObjectContent> ocs = _context.getService().retrieveProperties(
-	    	_context.getPropertyCollector(), pfSpecArr);
+        PropertyCollector pc = _context.getPropertyCollector();
+        ObjectContent[] ocs = pc.retrieveProperties(pfSpecArr.toArray(new PropertyFilterSpec[0]));
 
 
-	    if(ocs != null && ocs.size() > 0) {
+	    if(ocs != null && ocs.length > 0) {
 	    	for(ObjectContent oc : ocs) {
 	    		ArrayOfManagedObjectReference morVms = null;
 	    		String gcTagValue = null;
@@ -763,7 +780,7 @@ public class VirtualMachineMO extends BaseMO {
 	    		}
 
 	    		NetworkDetails details = new NetworkDetails(name, oc.getObj(),
-	    			(morVms != null ? morVms.getManagedObjectReference().toArray(new ManagedObjectReference[morVms.getManagedObjectReference().size()]) : null),
+	    			(morVms != null ? morVms.getManagedObjectReference() : null),
 	    			gcTagValue);
 
 	    		networks.add(details);
@@ -816,8 +833,9 @@ public class VirtualMachineMO extends BaseMO {
 	public boolean setVncConfigInfo(boolean enableVnc, String vncPassword, int vncPort, String keyboard) throws Exception {
 		VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();
 		OptionValue[] vncOptions = VmwareHelper.composeVncOptions(null, enableVnc, vncPassword, vncPort, keyboard);
-		vmConfigSpec.getExtraConfig().addAll(Arrays.asList(vncOptions));
-    	ManagedObjectReference morTask = _context.getService().reconfigVMTask(_mor, vmConfigSpec);
+		vmConfigSpec.setExtraConfig(vncOptions);
+		Task task = _virtualMachine.reconfigVM_Task(vmConfigSpec);
+    	ManagedObjectReference morTask = task.getMOR();
 
   		boolean result = _context.getVimClient().waitForTask(morTask);
 		if(result) {
@@ -830,7 +848,8 @@ public class VirtualMachineMO extends BaseMO {
 	}
 
 	public boolean configureVm(VirtualMachineConfigSpec vmConfigSpec) throws Exception {
-    	ManagedObjectReference morTask = _context.getService().reconfigVMTask(_mor, vmConfigSpec);
+	    Task task = _virtualMachine.reconfigVM_Task(vmConfigSpec);
+    	ManagedObjectReference morTask = task.getMOR();
 
   		boolean result = _context.getVimClient().waitForTask(morTask);
 		if(result) {
@@ -857,9 +876,9 @@ public class VirtualMachineMO extends BaseMO {
 	    	deviceConfigSpec.setFileOperation(deviceTernary.third());
 	    	deviceConfigSpecArray[i++] = deviceConfigSpec;
 	    }
-	    configSpec.getDeviceChange().addAll(Arrays.asList(deviceConfigSpecArray));
+	    configSpec.setDeviceChange(deviceConfigSpecArray);
 
-    	ManagedObjectReference morTask = _context.getService().reconfigVMTask(_mor, configSpec);
+    	ManagedObjectReference morTask = _virtualMachine.reconfigVM_Task(configSpec).getMOR();
 
   		boolean result = _context.getVimClient().waitForTask(morTask);
 		if(result) {
@@ -876,7 +895,7 @@ public class VirtualMachineMO extends BaseMO {
 		VmwareHypervisorHostNetworkSummary summary = hostMo.getHyperHostNetworkSummary(hostNetworkName);
 
 		VirtualMachineConfigInfo configInfo = getConfigInfo();
-		List<OptionValue> values = configInfo.getExtraConfig();
+		OptionValue[] values = configInfo.getExtraConfig();
 
 		if(values != null) {
 			for(OptionValue option : values) {
@@ -893,7 +912,7 @@ public class VirtualMachineMO extends BaseMO {
 
 	// vmdkDatastorePath: [datastore name] vmdkFilePath
 	public void createDisk(String vmdkDatastorePath, int sizeInMb, ManagedObjectReference morDs, int controllerKey) throws Exception {
-		createDisk(vmdkDatastorePath, VirtualDiskType.THIN, VirtualDiskMode.PERSISTENT, null, sizeInMb, morDs, controllerKey);
+		createDisk(vmdkDatastorePath, VirtualDiskType.thin, VirtualDiskMode.persistent, null, sizeInMb, morDs, controllerKey);
 	}
 
 	// vmdkDatastorePath: [datastore name] vmdkFilePath
@@ -901,9 +920,9 @@ public class VirtualMachineMO extends BaseMO {
 		String rdmDeviceName, int sizeInMb, ManagedObjectReference morDs, int controllerKey) throws Exception {
 
 		if(s_logger.isTraceEnabled())
-			s_logger.trace("vCenter API trace - createDisk(). target MOR: " + _mor.getValue() + ", vmdkDatastorePath: " + vmdkDatastorePath
+			s_logger.trace("vCenter API trace - createDisk(). target MOR: " + _mor.getVal() + ", vmdkDatastorePath: " + vmdkDatastorePath
 				+ ", sizeInMb: " + sizeInMb + ", diskType: " + diskType + ", diskMode: " + diskMode + ", rdmDeviceName: " + rdmDeviceName
-				+ ", datastore: " + morDs.getValue() + ", controllerKey: " + controllerKey);
+				+ ", datastore: " + morDs.getVal() + ", controllerKey: " + controllerKey);
 
 		assert(vmdkDatastorePath != null);
 		assert(morDs != null);
@@ -913,18 +932,18 @@ public class VirtualMachineMO extends BaseMO {
         }
 
 		VirtualDisk newDisk = new VirtualDisk();
-		if(diskType == VirtualDiskType.THIN || diskType == VirtualDiskType.PREALLOCATED
-			|| diskType == VirtualDiskType.EAGER_ZEROED_THICK) {
+		if(diskType == VirtualDiskType.thin || diskType == VirtualDiskType.preallocated
+			|| diskType == VirtualDiskType.eagerZeroedThick) {
 
 			VirtualDiskFlatVer2BackingInfo backingInfo = new VirtualDiskFlatVer2BackingInfo();
-	        backingInfo.setDiskMode(diskMode.PERSISTENT.value());
-	        if(diskType == VirtualDiskType.THIN) {
+	        backingInfo.setDiskMode(diskMode.persistent.toString());
+	        if(diskType == VirtualDiskType.thin) {
                 backingInfo.setThinProvisioned(true);
             } else {
                 backingInfo.setThinProvisioned(false);
             }
 
-	        if(diskType == VirtualDiskType.EAGER_ZEROED_THICK) {
+	        if(diskType == VirtualDiskType.eagerZeroedThick) {
                 backingInfo.setEagerlyScrub(true);
             } else {
                 backingInfo.setEagerlyScrub(false);
@@ -933,17 +952,17 @@ public class VirtualMachineMO extends BaseMO {
 	        backingInfo.setDatastore(morDs);
 	        backingInfo.setFileName(vmdkDatastorePath);
 	        newDisk.setBacking(backingInfo);
-		} else if(diskType == VirtualDiskType.RDM || diskType == VirtualDiskType.RDMP) {
+		} else if(diskType == VirtualDiskType.rdm || diskType == VirtualDiskType.rdmp) {
 			VirtualDiskRawDiskMappingVer1BackingInfo backingInfo =
 				new VirtualDiskRawDiskMappingVer1BackingInfo();
-			if(diskType == VirtualDiskType.RDM) {
+			if(diskType == VirtualDiskType.rdm) {
 				backingInfo.setCompatibilityMode("virtualMode");
 	        } else {
 	        	backingInfo.setCompatibilityMode("physicalMode");
 	        }
 	        backingInfo.setDeviceName(rdmDeviceName);
-	        if(diskType == VirtualDiskType.RDM) {
-	        	backingInfo.setDiskMode(diskMode.PERSISTENT.value());
+	        if(diskType == VirtualDiskType.rdm) {
+	        	backingInfo.setDiskMode(diskMode.persistent.toString());
 	        }
 
 	        backingInfo.setDatastore(morDs);
@@ -962,12 +981,12 @@ public class VirtualMachineMO extends BaseMO {
 	    VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec();
 
 	    deviceConfigSpec.setDevice(newDisk);
-	    deviceConfigSpec.setFileOperation(VirtualDeviceConfigSpecFileOperation.CREATE);
-	    deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.ADD);
+	    deviceConfigSpec.setFileOperation(VirtualDeviceConfigSpecFileOperation.create);
+	    deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.add);
 
-	    reConfigSpec.getDeviceChange().add(deviceConfigSpec);
+	    reConfigSpec.setDeviceChange( new VirtualDeviceConfigSpec[] { deviceConfigSpec });
 
-	    ManagedObjectReference morTask = _context.getService().reconfigVMTask(_mor, reConfigSpec);
+	    ManagedObjectReference morTask = _virtualMachine.reconfigVM_Task(reConfigSpec).getMOR();
 		boolean result = _context.getVimClient().waitForTask(morTask);
 
 		if(!result) {
@@ -985,8 +1004,8 @@ public class VirtualMachineMO extends BaseMO {
 	public void attachDisk(String[] vmdkDatastorePathChain, ManagedObjectReference morDs) throws Exception {
 
 		if(s_logger.isTraceEnabled())
-			s_logger.trace("vCenter API trace - attachDisk(). target MOR: " + _mor.getValue() + ", vmdkDatastorePath: "
-				+ new Gson().toJson(vmdkDatastorePathChain) + ", datastore: " + morDs.getValue());
+			s_logger.trace("vCenter API trace - attachDisk(). target MOR: " + _mor.getVal() + ", vmdkDatastorePath: "
+				+ new Gson().toJson(vmdkDatastorePathChain) + ", datastore: " + morDs.getVal());
 
 		VirtualDevice newDisk = VmwareHelper.prepareDiskDevice(this, null, getScsiDeviceControllerKey(),
 			vmdkDatastorePathChain, morDs, -1, 1);
@@ -994,11 +1013,11 @@ public class VirtualMachineMO extends BaseMO {
 	    VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec();
 
 	    deviceConfigSpec.setDevice(newDisk);
-	    deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.ADD);
+	    deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.add);
 
-	    reConfigSpec.getDeviceChange().add(deviceConfigSpec);
+	    reConfigSpec.setDeviceChange(new VirtualDeviceConfigSpec[] { deviceConfigSpec });
 
-	    ManagedObjectReference morTask = _context.getService().reconfigVMTask(_mor, reConfigSpec);
+	    ManagedObjectReference morTask = _virtualMachine.reconfigVM_Task(reConfigSpec).getMOR();
 		boolean result = _context.getVimClient().waitForTask(morTask);
 
 		if(!result) {
@@ -1016,7 +1035,7 @@ public class VirtualMachineMO extends BaseMO {
 	public void attachDisk(Pair<String, ManagedObjectReference>[] vmdkDatastorePathChain, int controllerKey) throws Exception {
 
 		if(s_logger.isTraceEnabled())
-			s_logger.trace("vCenter API trace - attachDisk(). target MOR: " + _mor.getValue() + ", vmdkDatastorePath: "
+			s_logger.trace("vCenter API trace - attachDisk(). target MOR: " + _mor.getVal() + ", vmdkDatastorePath: "
 				+ new Gson().toJson(vmdkDatastorePathChain));
 
 		VirtualDevice newDisk = VmwareHelper.prepareDiskDevice(this, controllerKey,
@@ -1025,11 +1044,11 @@ public class VirtualMachineMO extends BaseMO {
 	    VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec();
 
 	    deviceConfigSpec.setDevice(newDisk);
-	    deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.ADD);
+	    deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.add);
 
-	    reConfigSpec.getDeviceChange().add(deviceConfigSpec);
+	    reConfigSpec.setDeviceChange(new VirtualDeviceConfigSpec[] {deviceConfigSpec});
 
-	    ManagedObjectReference morTask = _context.getService().reconfigVMTask(_mor, reConfigSpec);
+	    ManagedObjectReference morTask = _virtualMachine.reconfigVM_Task(reConfigSpec).getMOR();
 		boolean result = _context.getVimClient().waitForTask(morTask);
 
 		if(!result) {
@@ -1048,7 +1067,7 @@ public class VirtualMachineMO extends BaseMO {
 	public List<Pair<String, ManagedObjectReference>> detachDisk(String vmdkDatastorePath, boolean deleteBackingFile) throws Exception {
 
 		if(s_logger.isTraceEnabled())
-			s_logger.trace("vCenter API trace - detachDisk(). target MOR: " + _mor.getValue() + ", vmdkDatastorePath: "
+			s_logger.trace("vCenter API trace - detachDisk(). target MOR: " + _mor.getVal() + ", vmdkDatastorePath: "
 				+ vmdkDatastorePath + ", deleteBacking: " + deleteBackingFile);
 
 		// Note: if VM has been taken snapshot, original backing file will be renamed, therefore, when we try to find the matching
@@ -1066,13 +1085,13 @@ public class VirtualMachineMO extends BaseMO {
 
 	    deviceConfigSpec.setDevice(deviceInfo.first());
 	    if(deleteBackingFile) {
-            deviceConfigSpec.setFileOperation(VirtualDeviceConfigSpecFileOperation.DESTROY);
+            deviceConfigSpec.setFileOperation(VirtualDeviceConfigSpecFileOperation.destroy);
         }
-	    deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.REMOVE);
+	    deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.remove);
 
-	    reConfigSpec.getDeviceChange().add(deviceConfigSpec);
+	    reConfigSpec.setDeviceChange(new VirtualDeviceConfigSpec[] { deviceConfigSpec });
 
-	    ManagedObjectReference morTask = _context.getService().reconfigVMTask(_mor, reConfigSpec);
+	    ManagedObjectReference morTask = _virtualMachine.reconfigVM_Task(reConfigSpec).getMOR();
 		boolean result = _context.getVimClient().waitForTask(morTask);
 
 		if(!result) {
@@ -1111,7 +1130,7 @@ public class VirtualMachineMO extends BaseMO {
 
 	public void detachAllDisks() throws Exception {
 		if(s_logger.isTraceEnabled())
-			s_logger.trace("vCenter API trace - detachAllDisk(). target MOR: " + _mor.getValue());
+			s_logger.trace("vCenter API trace - detachAllDisk(). target MOR: " + _mor.getVal());
 
 		VirtualDisk[] disks = getAllDiskDevice();
 		if(disks.length > 0) {
@@ -1121,11 +1140,11 @@ public class VirtualMachineMO extends BaseMO {
 			for(int i = 0; i < disks.length; i++) {
 				deviceConfigSpecArray[i] = new VirtualDeviceConfigSpec();
 				deviceConfigSpecArray[i].setDevice(disks[i]);
-				deviceConfigSpecArray[i].setOperation(VirtualDeviceConfigSpecOperation.REMOVE);
+				deviceConfigSpecArray[i].setOperation(VirtualDeviceConfigSpecOperation.remove);
 			}
-		    reConfigSpec.getDeviceChange().addAll(Arrays.asList(deviceConfigSpecArray));
+		    reConfigSpec.setDeviceChange(deviceConfigSpecArray);
 
-		    ManagedObjectReference morTask = _context.getService().reconfigVMTask(_mor, reConfigSpec);
+		    ManagedObjectReference morTask = _virtualMachine.reconfigVM_Task(reConfigSpec).getMOR();
 			boolean result = _context.getVimClient().waitForTask(morTask);
 
 			if(!result) {
@@ -1146,8 +1165,8 @@ public class VirtualMachineMO extends BaseMO {
 		boolean connect, boolean connectAtBoot) throws Exception {
 
 		if(s_logger.isTraceEnabled())
-			s_logger.trace("vCenter API trace - detachIso(). target MOR: " + _mor.getValue() + ", isoDatastorePath: "
-				+ isoDatastorePath + ", datastore: " + morDs.getValue() + ", connect: " + connect + ", connectAtBoot: " + connectAtBoot);
+			s_logger.trace("vCenter API trace - detachIso(). target MOR: " + _mor.getVal() + ", isoDatastorePath: "
+				+ isoDatastorePath + ", datastore: " + morDs.getVal() + ", connect: " + connect + ", connectAtBoot: " + connectAtBoot);
 
 		assert(isoDatastorePath != null);
 		assert(morDs != null);
@@ -1180,15 +1199,15 @@ public class VirtualMachineMO extends BaseMO {
 
         deviceConfigSpec.setDevice(cdRom);
         if(newCdRom) {
-            deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.ADD);
+            deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.add);
         } else {
-            deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.EDIT);
+            deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.edit);
         }
 
 	    //deviceConfigSpecArray[0] = deviceConfigSpec;
-	    reConfigSpec.getDeviceChange().add(deviceConfigSpec);
+	    reConfigSpec.setDeviceChange(new VirtualDeviceConfigSpec[] {deviceConfigSpec});
 
-	    ManagedObjectReference morTask = _context.getService().reconfigVMTask(_mor, reConfigSpec);
+	    ManagedObjectReference morTask = _virtualMachine.reconfigVM_Task(reConfigSpec).getMOR();
 		boolean result = _context.getVimClient().waitForTask(morTask);
 
 		if(!result) {
@@ -1205,7 +1224,7 @@ public class VirtualMachineMO extends BaseMO {
 
 	public void detachIso(String isoDatastorePath) throws Exception {
 		if(s_logger.isTraceEnabled())
-			s_logger.trace("vCenter API trace - detachIso(). target MOR: " + _mor.getValue() + ", isoDatastorePath: "
+			s_logger.trace("vCenter API trace - detachIso(). target MOR: " + _mor.getVal() + ", isoDatastorePath: "
 				+ isoDatastorePath);
 
 		VirtualDevice device = getIsoDevice();
@@ -1224,12 +1243,12 @@ public class VirtualMachineMO extends BaseMO {
 	    VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec();
 
 	    deviceConfigSpec.setDevice(device);
-	    deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.EDIT);
+	    deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.edit);
 
 	    //deviceConfigSpecArray[0] = deviceConfigSpec;
-	    reConfigSpec.getDeviceChange().add(deviceConfigSpec);
+	    reConfigSpec.setDeviceChange(new VirtualDeviceConfigSpec[] {deviceConfigSpec});
 
-	    ManagedObjectReference morTask = _context.getService().reconfigVMTask(_mor, reConfigSpec);
+	    ManagedObjectReference morTask = _virtualMachine.reconfigVM_Task(reConfigSpec).getMOR();
 		boolean result = _context.getVimClient().waitForTask(morTask);
 
 		if(!result) {
@@ -1246,7 +1265,7 @@ public class VirtualMachineMO extends BaseMO {
 	public Pair<VmdkFileDescriptor, byte[]> getVmdkFileInfo(String vmdkDatastorePath) throws Exception {
 
 		if(s_logger.isTraceEnabled())
-			s_logger.trace("vCenter API trace - getVmdkFileInfo(). target MOR: " + _mor.getValue() + ", vmdkDatastorePath: "
+			s_logger.trace("vCenter API trace - getVmdkFileInfo(). target MOR: " + _mor.getVal() + ", vmdkDatastorePath: "
 				+ vmdkDatastorePath);
 
 		Pair<DatacenterMO, String> dcPair = getOwnerDatacenter();
@@ -1274,23 +1293,23 @@ public class VirtualMachineMO extends BaseMO {
 
 		DatacenterMO dcMo = new DatacenterMO(_context, hostMo.getHyperHostDatacenter());
 
-		if(runtimeInfo.getPowerState() != VirtualMachinePowerState.POWERED_OFF) {
+		if(runtimeInfo.getPowerState() != VirtualMachinePowerState.poweredOff) {
 			String msg = "Unable to export VM because it is not at powerdOff state. vmName: " + vmName + ", host: " + hostName;
 			s_logger.error(msg);
 			throw new Exception(msg);
 		}
 
-		ManagedObjectReference morLease = _context.getService().exportVm(getMor());
+		ManagedObjectReference morLease = _virtualMachine.exportVm().getMOR();
 		if(morLease == null) {
 			s_logger.error("exportVm() failed");
 			throw new Exception("exportVm() failed");
 		}
 
 		HttpNfcLeaseMO leaseMo = new HttpNfcLeaseMO(_context, morLease);
-		HttpNfcLeaseState state = leaseMo.waitState(new HttpNfcLeaseState[] { HttpNfcLeaseState.READY, HttpNfcLeaseState.ERROR });
+		HttpNfcLeaseState state = leaseMo.waitState(new HttpNfcLeaseState[] { HttpNfcLeaseState.ready, HttpNfcLeaseState.error });
 
 		try {
-			if(state == HttpNfcLeaseState.READY) {
+			if(state == HttpNfcLeaseState.ready) {
 				final HttpNfcLeaseMO.ProgressReporter progressReporter = leaseMo.createProgressReporter();
 
                 boolean success = false;
@@ -1300,13 +1319,13 @@ public class VirtualMachineMO extends BaseMO {
 					final long totalBytes = leaseInfo.getTotalDiskCapacityInKB() * 1024;
 					long totalBytesDownloaded = 0;
 
-					List<HttpNfcLeaseDeviceUrl> deviceUrls = leaseInfo.getDeviceUrl();
+					HttpNfcLeaseDeviceUrl[] deviceUrls = leaseInfo.getDeviceUrl();
 					s_logger.info("volss: copy vmdk and ovf file starts " + System.currentTimeMillis());
 					if(deviceUrls != null) {
-						OvfFile[] ovfFiles = new OvfFile[deviceUrls.size()];
-						for (int i = 0; i < deviceUrls.size(); i++) {
-							String deviceId = deviceUrls.get(i).getKey();
-						 	String deviceUrlStr = deviceUrls.get(i).getUrl();
+						OvfFile[] ovfFiles = new OvfFile[deviceUrls.length];
+						for (int i = 0; i < deviceUrls.length; i++) {
+							String deviceId = deviceUrls[i].getKey();
+						 	String deviceUrlStr = deviceUrls[i].getUrl();
 						 	String orgDiskFileName = deviceUrlStr.substring(deviceUrlStr.lastIndexOf("/") + 1);
 						 	String diskFileName = String.format("%s-disk%d%s", exportName, i, VmwareHelper.getFileExtension(orgDiskFileName, ".vmdk"));
 						 	String diskUrlStr = deviceUrlStr.replace("*", hostName);
@@ -1338,8 +1357,9 @@ public class VirtualMachineMO extends BaseMO {
 
 						// write OVF descriptor file
 						OvfCreateDescriptorParams ovfDescParams = new OvfCreateDescriptorParams();
-						ovfDescParams.getOvfFiles().addAll(Arrays.asList(ovfFiles));
-						OvfCreateDescriptorResult ovfCreateDescriptorResult = _context.getService().createDescriptor(morOvf, getMor(), ovfDescParams);
+						ovfDescParams.setOvfFiles(ovfFiles);
+						OvfManager ovfManager = _context.getOvfManager();
+						OvfCreateDescriptorResult ovfCreateDescriptorResult = ovfManager.createDescriptor(_virtualMachine, ovfDescParams);
 						String ovfPath = exportDir + File.separator + exportName + ".ovf";
 						fileNames.add(ovfPath);
 
@@ -1572,8 +1592,8 @@ public class VirtualMachineMO extends BaseMO {
     	    VirtualDevice device = VmwareHelper.prepareDiskDevice(clonedVmMo, null, -1, disks, morDs, -1, 1);
 
     	    deviceConfigSpec.setDevice(device);
-    	    deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.ADD);
-    	    vmConfigSpec.getDeviceChange().add(deviceConfigSpec);
+    	    deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.add);
+    	    vmConfigSpec.setDeviceChange(new VirtualDeviceConfigSpec[] {deviceConfigSpec});
     	    clonedVmMo.configureVm(vmConfigSpec);
     	    bSuccess = true;
     	    return clonedVmMo;
@@ -1589,8 +1609,8 @@ public class VirtualMachineMO extends BaseMO {
         GuestOsDescriptor guestOsDescriptor = null;
         ManagedObjectReference vmEnvironmentBrowser =
                 _context.getVimClient().getMoRefProp(_mor, "environmentBrowser");
-        VirtualMachineConfigOption  vmConfigOption = _context.getService().queryConfigOption(vmEnvironmentBrowser, null, null);
-        List<GuestOsDescriptor> guestDescriptors = vmConfigOption.getGuestOSDescriptor();
+        VirtualMachineConfigOption  vmConfigOption = _virtualMachine.getEnvironmentBrowser().queryConfigOption(null, null);
+        GuestOsDescriptor[] guestDescriptors = vmConfigOption.getGuestOSDescriptor();
         for (GuestOsDescriptor descriptor : guestDescriptors) {
             if (guestOsId != null && guestOsId.equalsIgnoreCase(descriptor.getId())) {
                 guestOsDescriptor = descriptor;
@@ -1604,9 +1624,9 @@ public class VirtualMachineMO extends BaseMO {
         VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();
         VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec();
         deviceConfigSpec.setDevice(device);
-        deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.ADD);
+        deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.add);
 
-        vmConfigSpec.getDeviceChange().add(deviceConfigSpec);
+        vmConfigSpec.setDeviceChange(new VirtualDeviceConfigSpec[] {deviceConfigSpec});
         if(!configureVm(vmConfigSpec)) {
             throw new Exception("Failed to add devices");
         }
@@ -1616,9 +1636,9 @@ public class VirtualMachineMO extends BaseMO {
         VirtualMachineConfigSpec vmConfigSpec = new VirtualMachineConfigSpec();
         VirtualDeviceConfigSpec deviceConfigSpec = new VirtualDeviceConfigSpec();
         deviceConfigSpec.setDevice(device);
-        deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.REMOVE);
+        deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.remove);
 
-        vmConfigSpec.getDeviceChange().add(deviceConfigSpec);
+        vmConfigSpec.setDeviceChange(new VirtualDeviceConfigSpec[] {deviceConfigSpec});
         if(!configureVm(vmConfigSpec)) {
             throw new Exception("Failed to detach devices");
         }
@@ -1633,10 +1653,10 @@ public class VirtualMachineMO extends BaseMO {
     	    for(int i = 0; i < devices.length; i++) {
     	    	deviceConfigSpecArray[i] = new VirtualDeviceConfigSpec();
     	    	deviceConfigSpecArray[i].setDevice(devices[i]);
-    	    	deviceConfigSpecArray[i].setOperation(VirtualDeviceConfigSpecOperation.REMOVE);
+    	    	deviceConfigSpecArray[i].setOperation(VirtualDeviceConfigSpecOperation.remove);
     	    }
 
-    	    vmConfigSpec.getDeviceChange().addAll(Arrays.asList(deviceConfigSpecArray));
+    	    vmConfigSpec.setDeviceChange(deviceConfigSpecArray);
     		if(!configureVm(vmConfigSpec)) {
                 throw new Exception("Failed to detach devices");
             }
@@ -1755,14 +1775,14 @@ public class VirtualMachineMO extends BaseMO {
 
 			// Scsi controller
 			VirtualLsiLogicController scsiController = new VirtualLsiLogicController();
-			scsiController.setSharedBus(VirtualSCSISharing.NO_SHARING);
+			scsiController.setSharedBus(VirtualSCSISharing.noSharing);
 			scsiController.setBusNumber(0);
 			scsiController.setKey(1);
 			VirtualDeviceConfigSpec scsiControllerSpec = new VirtualDeviceConfigSpec();
 			scsiControllerSpec.setDevice(scsiController);
-			scsiControllerSpec.setOperation(VirtualDeviceConfigSpecOperation.ADD);
+			scsiControllerSpec.setOperation(VirtualDeviceConfigSpecOperation.add);
 
-			vmConfig.getDeviceChange().add(scsiControllerSpec);
+			vmConfig.setDeviceChange(new VirtualDeviceConfigSpec[] {scsiControllerSpec});
 			if(configureVm(vmConfig)) {
 				throw new Exception("Unable to add Scsi controller");
 			}
@@ -1993,15 +2013,15 @@ public class VirtualMachineMO extends BaseMO {
 					detachedDiskFiles.add(diskBackingInfo.getFileName());
 					
 				    deviceConfigSpec.setDevice(device);
-				    deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.REMOVE);
+				    deviceConfigSpec.setOperation(VirtualDeviceConfigSpecOperation.remove);
 			
-				    reConfigSpec.getDeviceChange().add(deviceConfigSpec);
+				    reConfigSpec.setDeviceChange(new VirtualDeviceConfigSpec[] {deviceConfigSpec});
 				}
 	    	}
 	    }
 	    
 	    if(detachedDiskFiles.size() > 0) {
-		    ManagedObjectReference morTask = _context.getService().reconfigVMTask(_mor, reConfigSpec);
+		    ManagedObjectReference morTask = _virtualMachine.reconfigVM_Task(reConfigSpec).getMOR();
 			boolean result = _context.getVimClient().waitForTask(morTask);
 			if(result) {
 				_context.waitForTaskProgressDone(morTask);
@@ -2215,7 +2235,7 @@ public class VirtualMachineMO extends BaseMO {
         DistributedVirtualSwitchPortConnection dvsPort = dvpBackingInfo.getPort();
         String dvPortGroupKey = dvsPort.getPortgroupKey();
         ManagedObjectReference dvPortGroupMor = new ManagedObjectReference();
-        dvPortGroupMor.setValue(dvPortGroupKey);
+        dvPortGroupMor.setVal(dvPortGroupKey);
         dvPortGroupMor.setType("DistributedVirtualPortgroup");
         return (String) _context.getVimClient().getDynamicProperty(dvPortGroupMor, "name");
     }
@@ -2243,11 +2263,11 @@ public class VirtualMachineMO extends BaseMO {
 	}
 
 	public void mountToolsInstaller() throws Exception {
-		_context.getService().mountToolsInstaller(_mor);
+		_virtualMachine.mountToolsInstaller();
 	}
 
 	public void unmountToolsInstaller() throws Exception {
-		_context.getService().unmountToolsInstaller(_mor);
+		_virtualMachine.unmountToolsInstaller();
 	}
 
 	public void redoRegistration(ManagedObjectReference morHost) throws Exception {
@@ -2264,13 +2284,13 @@ public class VirtualMachineMO extends BaseMO {
 		ManagedObjectReference morFolder = getParentMor();
 		ManagedObjectReference morPool = hostMo.getHyperHostOwnerResourcePool();
 
-		_context.getService().unregisterVM(_mor);
+		_virtualMachine.unregisterVM();
 
-		ManagedObjectReference morTask = _context.getService().registerVMTask(
-    		 morFolder,
-    		 vmFileInfo.getVmPathName(),
-    		 vmName, false,
-    		 morPool, hostMo.getMor());
+		Folder folder = new Folder(_context.getServerConnection(), morFolder);
+		ResourcePool pool = new ResourcePool(_context.getServerConnection(), morPool);
+
+		Task task = folder.registerVM_Task(vmFileInfo.getVmPathName(), vmName, false, pool, hostMo._hostSystem);
+		ManagedObjectReference morTask = task.getMOR();
 
 		boolean result = _context.getVimClient().waitForTask(morTask);
 		if (!result) {
@@ -2309,7 +2329,7 @@ public class VirtualMachineMO extends BaseMO {
     }
 
     public VirtualHardwareOption getVirtualHardwareOption() throws Exception {
-        VirtualMachineConfigOption vmConfigOption = _context.getService().queryConfigOption(getEnvironmentBrowser(), null, null);
+        VirtualMachineConfigOption vmConfigOption = _virtualMachine.getEnvironmentBrowser().queryConfigOption(null, null);
         return vmConfigOption.getHardwareOptions();
     }
 
@@ -2331,7 +2351,7 @@ public class VirtualMachineMO extends BaseMO {
         virtualHardwareVersion = getVirtualHardwareVersion();
 
         // Check if guest operating system supports cpu hotadd
-        if (guestOsDescriptor.isSupportsCpuHotAdd()) {
+        if (guestOsDescriptor.getSupportsCpuHotAdd()) {
             guestOsSupportsCpuHotAdd = true;
         }
 
@@ -2359,7 +2379,7 @@ public class VirtualMachineMO extends BaseMO {
         virtualHardwareVersion = getVirtualHardwareVersion();
 
         // Check if guest operating system supports memory hotadd
-        if (guestOsDescriptor.isSupportsMemoryHotAdd()) {
+        if (guestOsDescriptor.getSupportsMemoryHotAdd()) {
             guestOsSupportsMemoryHotAdd = true;
         }
         // Check if virtual machine is using hardware version 7 or later.
@@ -2368,4 +2388,8 @@ public class VirtualMachineMO extends BaseMO {
         }
         return guestOsSupportsMemoryHotAdd && virtualHardwareSupportsMemoryHotAdd;
     }
+    
+    protected VirtualMachine getVirtualMachine() {
+        return new VirtualMachine(_context.getServerConnection(), _mor);
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/67fc53ab/vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareContext.java
----------------------------------------------------------------------
diff --git a/vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareContext.java b/vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareContext.java
index 688ecbf..ed7eb77 100755
--- a/vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareContext.java
+++ b/vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareContext.java
@@ -44,6 +44,7 @@ import com.cloud.hypervisor.vmware.mo.DatacenterMO;
 import com.cloud.hypervisor.vmware.mo.DatastoreFile;
 import com.cloud.utils.ActionDelegate;
 
+import com.vmware.vim25.DvsMergedEvent;
 import com.vmware.vim25.ManagedObjectReference;
 import com.vmware.vim25.ObjectContent;
 import com.vmware.vim25.ObjectSpec;
@@ -53,7 +54,12 @@ import com.vmware.vim25.ServiceContent;
 import com.vmware.vim25.TaskInfo;
 import com.vmware.vim25.TraversalSpec;
 import com.vmware.vim25.VimPortType;
+import com.vmware.vim25.mo.DistributedVirtualSwitchManager;
+import com.vmware.vim25.mo.FileManager;
+import com.vmware.vim25.mo.OvfManager;
+import com.vmware.vim25.mo.PerformanceManager;
 import com.vmware.vim25.mo.PropertyCollector;
+import com.vmware.vim25.mo.ServerConnection;
 
 public class VmwareContext {
     private static final Logger s_logger = Logger.getLogger(VmwareContext.class);
@@ -137,10 +143,34 @@ public class VmwareContext {
 	public ServiceContent getServiceContent() {
 		return _vimClient.getServiceContent();
 	}
-
-	public ManagedObjectReference getPropertyCollector(){
+	
+	public PropertyCollector getPropertyCollector() {
+	    return _vimClient.getServiceInstance().getPropertyCollector();
+	}
+	
+	public FileManager getFileManager() {
+	    return _vimClient.getServiceInstance().getFileManager();
+	}
+	
+	public OvfManager getOvfManager() {
+	    return _vimClient.getServiceInstance().getOvfManager();
+	}
+	
+	public DistributedVirtualSwitchManager getDistributedVirtualSwitchManager() {
+	    return _vimClient.getServiceInstance().getDistributedVirtualSwitchManager();
+	}
+	
+	public PerformanceManager getPerformanceManager() {
+	    return _vimClient.getServiceInstance().getPerformanceManager();
+	}
+	
+	public ManagedObjectReference getPropertyCollectorMor(){
 	    return _vimClient.getPropCol();
 	}
+	
+	public ServerConnection getServerConnection() {
+	    return _vimClient.getServiceInstance().getServerConnection();
+	}
 
 	public ManagedObjectReference getRootFolder() {
 		return _vimClient.getRootFolder();