You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by mu...@apache.org on 2012/06/27 04:45:55 UTC

[3/9] moving out VMWAre and Nexus VSM support code into plugins/hypervisors/vmware

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/8197f1f0/core/src/com/cloud/storage/resource/PremiumSecondaryStorageResource.java
----------------------------------------------------------------------
diff --git a/core/src/com/cloud/storage/resource/PremiumSecondaryStorageResource.java b/core/src/com/cloud/storage/resource/PremiumSecondaryStorageResource.java
deleted file mode 100644
index 2ea6768..0000000
--- a/core/src/com/cloud/storage/resource/PremiumSecondaryStorageResource.java
+++ /dev/null
@@ -1,101 +0,0 @@
-// Copyright 2012 Citrix Systems, Inc. Licensed under the
-// Apache License, Version 2.0 (the "License"); you may not use this
-// file except in compliance with the License.  Citrix Systems, Inc.
-// reserves all rights not expressly granted by the License.
-// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-// 
-// Automatically generated by addcopyright.py at 04/03/2012
-package com.cloud.storage.resource;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.naming.ConfigurationException;
-
-import org.apache.log4j.Logger;
-
-import com.cloud.agent.api.Answer;
-import com.cloud.agent.api.Command;
-import com.cloud.hypervisor.Hypervisor;
-
-public class PremiumSecondaryStorageResource extends NfsSecondaryStorageResource {
-
-    private static final Logger s_logger = Logger.getLogger(PremiumSecondaryStorageResource.class);
-
-    private Map<Hypervisor.HypervisorType, SecondaryStorageResourceHandler> _handlers = new HashMap<Hypervisor.HypervisorType, SecondaryStorageResourceHandler>();
-    
-    private Map<String, String> _activeOutgoingAddresses = new HashMap<String, String>();
-	
-    @Override
-    public Answer executeRequest(Command cmd) {
-    	String hypervisor = cmd.getContextParam("hypervisor");
-    	if(hypervisor != null) {
-    		Hypervisor.HypervisorType hypervisorType = Hypervisor.HypervisorType.getType(hypervisor);
-    		if(hypervisorType == null) {
-    			s_logger.error("Unsupported hypervisor type in command context, hypervisor: " + hypervisor);
-    			return defaultAction(cmd);
-    		}
-    		
-    		SecondaryStorageResourceHandler handler = getHandler(hypervisorType);
-    		if(handler == null) {
-    			s_logger.error("No handler can be found for hypervisor type in command context, hypervisor: " + hypervisor);
-    			return defaultAction(cmd);
-    		}
-    		
-    		return handler.executeRequest(cmd);
-    	}
-
-        return defaultAction(cmd);
-    }
-    
-    public Answer defaultAction(Command cmd) {
-    	return super.executeRequest(cmd);
-    }
-    
-    public void ensureOutgoingRuleForAddress(String address) {
-    	if(address == null || address.isEmpty() || address.startsWith("0.0.0.0")) {
-    		if(s_logger.isInfoEnabled())
-    			s_logger.info("Drop invalid dynamic route/firewall entry " + address);
-    		return;
-    	}
-    	
-    	boolean needToSetRule = false;
-    	synchronized(_activeOutgoingAddresses) {
-    		if(!_activeOutgoingAddresses.containsKey(address)) {
-    			_activeOutgoingAddresses.put(address, address);
-    			needToSetRule = true;
-    		}
-    	}
-    	
-    	if(needToSetRule) {
-    		if(s_logger.isInfoEnabled())
-    			s_logger.info("Add dynamic route/firewall entry for " + address);
-    		allowOutgoingOnPrivate(address);
-    	}
-    }
-    
-    private void registerHandler(Hypervisor.HypervisorType hypervisorType, SecondaryStorageResourceHandler handler) {
-    	_handlers.put(hypervisorType, handler);
-    }
-    
-    private SecondaryStorageResourceHandler getHandler(Hypervisor.HypervisorType hypervisorType) {
-    	return _handlers.get(hypervisorType);
-    }
-    
-    @Override
-    public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
-    	super.configure(name, params);
-
-    	if(_inSystemVM) {
-    		VmwareSecondaryStorageContextFactory.initFactoryEnvironment();
-    	}
-    	
-    	registerHandler(Hypervisor.HypervisorType.VMware, new VmwareSecondaryStorageResourceHandler(this));
-    	return true;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/8197f1f0/core/src/com/cloud/storage/resource/VmwareSecondaryStorageContextFactory.java
----------------------------------------------------------------------
diff --git a/core/src/com/cloud/storage/resource/VmwareSecondaryStorageContextFactory.java b/core/src/com/cloud/storage/resource/VmwareSecondaryStorageContextFactory.java
deleted file mode 100644
index edbe8e6..0000000
--- a/core/src/com/cloud/storage/resource/VmwareSecondaryStorageContextFactory.java
+++ /dev/null
@@ -1,68 +0,0 @@
-// Copyright 2012 Citrix Systems, Inc. Licensed under the
-// Apache License, Version 2.0 (the "License"); you may not use this
-// file except in compliance with the License.  Citrix Systems, Inc.
-// reserves all rights not expressly granted by the License.
-// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-// 
-// Automatically generated by addcopyright.py at 04/03/2012
-package com.cloud.storage.resource;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import com.cloud.hypervisor.vmware.util.VmwareContext;
-import com.vmware.apputils.version.ExtendedAppUtil;
-
-public class VmwareSecondaryStorageContextFactory {
-	private static volatile int s_seq = 1;
-	
-	private static Map<String, VmwareContext> s_contextMap = new HashMap<String, VmwareContext>();
-	
-	public static void initFactoryEnvironment() {
-		System.setProperty("axis.socketSecureFactory", "org.apache.axis.components.net.SunFakeTrustSocketFactory");
-	}
-	
-	public static VmwareContext create(String vCenterAddress, String vCenterUserName, String vCenterPassword) throws Exception {
-		assert(vCenterAddress != null);
-		assert(vCenterUserName != null);
-		assert(vCenterPassword != null);
-		
-		VmwareContext context = null;
-		
-		synchronized(s_contextMap) {
-			context = s_contextMap.get(vCenterAddress);
-			if(context == null) {
-				String serviceUrl = "https://" + vCenterAddress + "/sdk/vimService";
-				String[] params = new String[] {"--url", serviceUrl, "--username", vCenterUserName, "--password", vCenterPassword };
-				ExtendedAppUtil appUtil = ExtendedAppUtil.initialize(vCenterAddress + "-" + s_seq++, params);
-				
-				appUtil.connect();
-				context = new VmwareContext(appUtil, vCenterAddress);
-				context.registerStockObject("username", vCenterUserName);
-				context.registerStockObject("password", vCenterPassword);
-				
-				s_contextMap.put(vCenterAddress, context);
-			}
-		}
-		
-		assert(context != null);
-		return context;
-	}
-	
-	public static void invalidate(VmwareContext context) {
-		synchronized(s_contextMap) {
-			for(Map.Entry<String, VmwareContext> entry : s_contextMap.entrySet()) {
-				if(entry.getValue() == context) {
-					s_contextMap.remove(entry.getKey());
-				}
-			}
-		}
-		
-		context.close();
-	}
-}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/8197f1f0/core/src/com/cloud/storage/resource/VmwareSecondaryStorageResourceHandler.java
----------------------------------------------------------------------
diff --git a/core/src/com/cloud/storage/resource/VmwareSecondaryStorageResourceHandler.java b/core/src/com/cloud/storage/resource/VmwareSecondaryStorageResourceHandler.java
deleted file mode 100644
index bd98400..0000000
--- a/core/src/com/cloud/storage/resource/VmwareSecondaryStorageResourceHandler.java
+++ /dev/null
@@ -1,301 +0,0 @@
-// Copyright 2012 Citrix Systems, Inc. Licensed under the
-// Apache License, Version 2.0 (the "License"); you may not use this
-// file except in compliance with the License.  Citrix Systems, Inc.
-// reserves all rights not expressly granted by the License.
-// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-// 
-// Automatically generated by addcopyright.py at 04/03/2012
-package com.cloud.storage.resource;
-
-import java.util.List;
-
-import org.apache.log4j.Logger;
-
-import com.cloud.agent.api.Answer;
-import com.cloud.agent.api.BackupSnapshotCommand;
-import com.cloud.agent.api.Command;
-import com.cloud.agent.api.CreatePrivateTemplateFromSnapshotCommand;
-import com.cloud.agent.api.CreatePrivateTemplateFromVolumeCommand;
-import com.cloud.agent.api.CreateVolumeFromSnapshotCommand;
-import com.cloud.agent.api.storage.CopyVolumeCommand;
-import com.cloud.agent.api.storage.PrimaryStorageDownloadCommand;
-import com.cloud.hypervisor.vmware.manager.VmwareHostService;
-import com.cloud.hypervisor.vmware.manager.VmwareStorageManager;
-import com.cloud.hypervisor.vmware.manager.VmwareStorageManagerImpl;
-import com.cloud.hypervisor.vmware.manager.VmwareStorageMount;
-import com.cloud.hypervisor.vmware.mo.ClusterMO;
-import com.cloud.hypervisor.vmware.mo.HostMO;
-import com.cloud.hypervisor.vmware.mo.VmwareHostType;
-import com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost;
-import com.cloud.hypervisor.vmware.mo.VmwareHypervisorHostNetworkSummary;
-import com.cloud.hypervisor.vmware.util.VmwareContext;
-import com.cloud.hypervisor.vmware.util.VmwareHelper;
-import com.cloud.serializer.GsonHelper;
-import com.cloud.utils.Pair;
-import com.google.gson.Gson;
-import com.vmware.vim25.ManagedObjectReference;
-
-public class VmwareSecondaryStorageResourceHandler implements SecondaryStorageResourceHandler, VmwareHostService, VmwareStorageMount {
-    private static final Logger s_logger = Logger.getLogger(VmwareSecondaryStorageResourceHandler.class);
-
-    private final PremiumSecondaryStorageResource _resource;
-    private final VmwareStorageManager _storageMgr;
-
-    private final Gson _gson;
-
-    /*
-	private Map<String, HostMO> _activeHosts = new HashMap<String, HostMO>();
-     */
-
-    public VmwareSecondaryStorageResourceHandler(PremiumSecondaryStorageResource resource) {
-        _resource = resource;
-        _storageMgr = new VmwareStorageManagerImpl(this);
-        _gson = GsonHelper.getGsonLogger();
-    }
-
-    @Override
-    public Answer executeRequest(Command cmd) {
-        Answer answer;
-        if (cmd instanceof PrimaryStorageDownloadCommand) {
-            answer = execute((PrimaryStorageDownloadCommand)cmd);
-        } else if(cmd instanceof BackupSnapshotCommand) {
-            answer = execute((BackupSnapshotCommand)cmd);
-        } else if(cmd instanceof CreatePrivateTemplateFromVolumeCommand) {
-            answer = execute((CreatePrivateTemplateFromVolumeCommand)cmd);
-        } else if(cmd instanceof CreatePrivateTemplateFromSnapshotCommand) {
-            answer = execute((CreatePrivateTemplateFromSnapshotCommand)cmd);
-        } else if(cmd instanceof CopyVolumeCommand) {
-            answer = execute((CopyVolumeCommand)cmd);
-        } else if(cmd instanceof CreateVolumeFromSnapshotCommand) {
-            answer = execute((CreateVolumeFromSnapshotCommand)cmd);
-        } else {
-            answer =  _resource.defaultAction(cmd);
-        }
-
-        // special handling to pass-back context info for cleanups
-        if(cmd.getContextParam("execid") != null) {
-            answer.setContextParam("execid", cmd.getContextParam("execid"));
-        }
-        
-        if(cmd.getContextParam("checkpoint") != null) {
-            answer.setContextParam("checkpoint", cmd.getContextParam("checkpoint"));
-        }
-        
-        if(cmd.getContextParam("checkpoint2") != null) {
-            answer.setContextParam("checkpoint2", cmd.getContextParam("checkpoint2"));
-        }
-
-        return answer;
-    }
-
-    private Answer execute(PrimaryStorageDownloadCommand cmd) {
-        if (s_logger.isDebugEnabled()) {
-            s_logger.debug("Executing resource PrimaryStorageDownloadCommand: " + _gson.toJson(cmd));
-        }
-
-        return _storageMgr.execute(this, cmd);
-    }
-
-    private Answer execute(BackupSnapshotCommand cmd) {
-        if (s_logger.isDebugEnabled()) {
-            s_logger.debug("Executing resource BackupSnapshotCommand: " + _gson.toJson(cmd));
-        }
-
-        return _storageMgr.execute(this, cmd);
-    }
-
-    private Answer execute(CreatePrivateTemplateFromVolumeCommand cmd) {
-        if (s_logger.isDebugEnabled()) {
-            s_logger.debug("Executing resource CreatePrivateTemplateFromVolumeCommand: " + _gson.toJson(cmd));
-        }
-
-        return _storageMgr.execute(this, cmd);
-    }
-
-    private Answer execute(CreatePrivateTemplateFromSnapshotCommand cmd) {
-        if (s_logger.isDebugEnabled()) {
-            s_logger.debug("Executing resource CreatePrivateTemplateFromVolumeCommand: " + _gson.toJson(cmd));
-        }
-
-        return _storageMgr.execute(this, cmd);
-    }
-
-    private Answer execute(CopyVolumeCommand cmd) {
-        if (s_logger.isDebugEnabled()) {
-            s_logger.debug("Executing resource CopyVolumeCommand: " + _gson.toJson(cmd));
-        }
-
-        return _storageMgr.execute(this, cmd);
-    }
-
-    private Answer execute(CreateVolumeFromSnapshotCommand cmd) {
-        if (s_logger.isDebugEnabled()) {
-            s_logger.debug("Executing resource CreateVolumeFromSnapshotCommand: " + _gson.toJson(cmd));
-        }
-
-        return _storageMgr.execute(this, cmd);
-    }
-
-    @Override
-    public VmwareContext getServiceContext(Command cmd) {
-        String guid = cmd.getContextParam("guid");
-        if(guid == null || guid.isEmpty()) {
-            s_logger.error("Invalid command context parameter guid");
-            return null;
-        }
-
-        String username = cmd.getContextParam("username");
-        if(username == null || username.isEmpty()) {
-            s_logger.error("Invalid command context parameter username");
-            return null;
-        }
-
-        String password = cmd.getContextParam("password");
-
-        // validate command guid parameter
-        String[] tokens = guid.split("@");
-        if(tokens == null || tokens.length != 2) {
-            s_logger.error("Invalid content in command context parameter guid");
-            return null;
-        }
-
-        String vCenterAddress = tokens[1];
-        String[] hostTokens = tokens[0].split(":");
-        if(hostTokens == null || hostTokens.length != 2) {
-            s_logger.error("Invalid content in command context parameter guid");
-            return null;
-        }
-
-        try {
-            _resource.ensureOutgoingRuleForAddress(vCenterAddress);
-            VmwareContext context = null;
-
-            // cached VmwareContext may be timed out in vCenter, give it a chance to reclaim a new context from factory
-            for(int i = 0; i < 2; i++) {
-                context = VmwareSecondaryStorageContextFactory.create(vCenterAddress, username, password);
-                if(!validateContext(context, cmd)) {
-                    invalidateServiceContext(context);
-                }
-            }
-
-            if(context != null) {
-                context.registerStockObject("serviceconsole", cmd.getContextParam("serviceconsole"));
-                context.registerStockObject("manageportgroup", cmd.getContextParam("manageportgroup"));
-            }
-            return context;
-        } catch(Exception e) {
-            s_logger.error("Unexpected exception " + e.toString(), e);
-            return null;
-        }
-    }
-
-    @Override
-    public void invalidateServiceContext(VmwareContext context) {
-        VmwareSecondaryStorageContextFactory.invalidate(context);
-    }
-
-    @Override
-    public VmwareHypervisorHost getHyperHost(VmwareContext context, Command cmd) {
-        String guid = cmd.getContextParam("guid");
-        assert(guid != null);
-
-        String[] tokens = guid.split("@");
-        assert(tokens != null && tokens.length == 2);
-
-        ManagedObjectReference morHyperHost = new ManagedObjectReference();
-        String[] hostTokens = tokens[0].split(":");
-        if(hostTokens == null || hostTokens.length != 2) {
-            s_logger.error("Invalid content in command context parameter guid");
-            return null;
-        }
-
-        morHyperHost.setType(hostTokens[0]);
-        morHyperHost.set_value(hostTokens[1]);
-
-        if(morHyperHost.getType().equalsIgnoreCase("HostSystem")) {
-            HostMO hostMo =  new HostMO(context, morHyperHost);
-
-            try {
-                
-                ManagedObjectReference mor = hostMo.getHyperHostCluster();
-                ClusterMO clusterMo = new ClusterMO(hostMo.getContext(), mor);
-                List<Pair<ManagedObjectReference, String>> hostsInCluster = clusterMo.getClusterHosts();
-                for(Pair<ManagedObjectReference, String> hostPair : hostsInCluster) {
-                    HostMO hostIteratorMo = new HostMO(hostMo.getContext(), hostPair.first());
-                    
-                    VmwareHypervisorHostNetworkSummary netSummary = hostIteratorMo.getHyperHostNetworkSummary(
-                            hostIteratorMo.getHostType() == VmwareHostType.ESXi ? cmd.getContextParam("manageportgroup") : cmd.getContextParam("serviceconsole"));
-                    _resource.ensureOutgoingRuleForAddress(netSummary.getHostIp());
-                    
-                    s_logger.info("Setup firewall rule for host: " + netSummary.getHostIp());
-                }
-            } catch(Throwable e) {
-                s_logger.warn("Unable to retrive host network information due to exception " + e.toString() + ", host: " + hostTokens[0] + "-" + hostTokens[1]);
-            }
-
-            return hostMo;
-        }
-
-        assert(false);
-        return new ClusterMO(context, morHyperHost);
-    }
-
-    @Override
-    public String getWorkerName(VmwareContext context, Command cmd, int workerSequence) {
-        assert(cmd.getContextParam("worker") != null);
-        assert(workerSequence < 2);
-        
-        if(workerSequence == 0)
-            return cmd.getContextParam("worker");
-        return cmd.getContextParam("worker2");
-    }
-
-    @Override
-    public String getMountPoint(String storageUrl) {
-        return _resource.getRootDir(storageUrl);
-    }
-
-    private boolean validateContext(VmwareContext context, Command cmd) {
-        String guid = cmd.getContextParam("guid");
-        assert(guid != null);
-
-        String[] tokens = guid.split("@");
-        assert(tokens != null && tokens.length == 2);
-
-        ManagedObjectReference morHyperHost = new ManagedObjectReference();
-        String[] hostTokens = tokens[0].split(":");
-        assert(hostTokens.length == 2);
-
-        morHyperHost.setType(hostTokens[0]);
-        morHyperHost.set_value(hostTokens[1]);
-
-        if(morHyperHost.getType().equalsIgnoreCase("HostSystem")) {
-            HostMO hostMo =  new HostMO(context, morHyperHost);
-            try {
-                VmwareHypervisorHostNetworkSummary netSummary = hostMo.getHyperHostNetworkSummary(
-                	hostMo.getHostType() == VmwareHostType.ESXi ? cmd.getContextParam("manageportgroup") : cmd.getContextParam("serviceconsole"));
-                assert(netSummary != null);
-                if(netSummary.getHostIp() != null && !netSummary.getHostIp().isEmpty()) {
-                    if(s_logger.isDebugEnabled()) {
-                        s_logger.debug("Context validation succeeded. Validated via host: " + netSummary.getHostIp() + ", guid: " + guid);
-                    }
-                    return true;
-                }
-
-                s_logger.warn("Context validation failed due to invalid host network summary");
-                return false;
-            } catch(Throwable e) {
-                s_logger.warn("Context validation failed due to " + VmwareHelper.getExceptionMessage(e));
-                return false;
-            }
-        }
-
-        assert(false);
-        return true;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/8197f1f0/plugins/hypervisors/vmware/.classpath
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/.classpath b/plugins/hypervisors/vmware/.classpath
new file mode 100755
index 0000000..74eb425
--- /dev/null
+++ b/plugins/hypervisors/vmware/.classpath
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+	<classpathentry combineaccessrules="false" kind="src" path="/core"/>
+	<classpathentry combineaccessrules="false" kind="src" path="/utils"/>
+	<classpathentry combineaccessrules="false" kind="src" path="/server"/>
+	<classpathentry combineaccessrules="false" kind="src" path="/api"/>
+	<classpathentry combineaccessrules="false" kind="src" path="/deps"/>
+	<classpathentry combineaccessrules="false" kind="src" path="/vmware-base"/>
+	<classpathentry kind="output" path="bin"/>
+</classpath>

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/8197f1f0/plugins/hypervisors/vmware/.project
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/.project b/plugins/hypervisors/vmware/.project
new file mode 100755
index 0000000..f53a2a2
--- /dev/null
+++ b/plugins/hypervisors/vmware/.project
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>vmware</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.python.pydev.PyDevBuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+		<nature>org.python.pydev.pythonNature</nature>
+	</natures>
+</projectDescription>

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/8197f1f0/plugins/hypervisors/vmware/build.xml
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/build.xml b/plugins/hypervisors/vmware/build.xml
new file mode 100755
index 0000000..f6bcd43
--- /dev/null
+++ b/plugins/hypervisors/vmware/build.xml
@@ -0,0 +1,135 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+
+
+<project name="Cloud Stack Vmware" default="help" basedir=".">
+  <description>
+		Cloud Stack ant build file
+    </description>
+
+  <dirname property="vmware.base.dir" file="${ant.file.Cloud Stack Vmware}/"/>
+  <!-- This directory must be set -->
+  <property name="top.dir" location="${vmware.base.dir}/../../.."/>
+  <property name="build.dir" location="${top.dir}/build"/>
+	
+	<echo message="build.dir=${build.dir}; top.dir=${top.dir}; vmware.base.dir=${vmware.base.dir}"/>
+
+  <!-- Import anything that the user wants to set-->
+  <!-- Import properties files and environment variables here -->
+
+  <property environment="env" />
+
+  <condition property="build-cloud.properties.file" value="${build.dir}/override/build-cloud.properties" else="${build.dir}/build-cloud.properties">
+    <available file="${build.dir}/override/build-cloud.properties" />
+  </condition>
+
+  <condition property="cloud.properties.file" value="${build.dir}/override/cloud.properties" else="${build.dir}/cloud.properties">
+    <available file="${build.dir}/override/cloud.properties" />
+  </condition>
+
+  <condition property="override.file" value="${build.dir}/override/replace.properties" else="${build.dir}/replace.properties">
+    <available file="${build.dir}/override/replace.properties" />
+  </condition>
+
+  <echo message="Using build parameters from ${build-cloud.properties.file}" />
+  <property file="${build-cloud.properties.file}" />
+
+  <echo message="Using company info from ${cloud.properties.file}" />
+  <property file="${cloud.properties.file}" />
+
+  <echo message="Using override file from ${override.file}" />
+  <property file="${override.file}" />
+
+  <property file="${build.dir}/build.number" />
+
+  <!-- In case these didn't get defined in the build-cloud.properties -->
+  <property name="branding.name" value="default" />
+  <property name="deprecation" value="off" />
+  <property name="target.compat.version" value="1.6" />
+  <property name="source.compat.version" value="1.6" />
+  <property name="debug" value="true" />
+  <property name="debuglevel" value="lines,source"/>
+
+  <echo message="target.dir=${target.dir}; top.dir=${top.dir}"/>
+  <!-- directories for build and distribution -->
+  <property name="target.dir" location="${top.dir}/target" />
+  <property name="classes.dir" location="${target.dir}/classes" />
+  <property name="jar.dir" location="${target.dir}/jar" />
+  <property name="dep.cache.dir" location="${target.dir}/dep-cache" />
+  <property name="build.log" location="${target.dir}/ant_verbose.txt" />
+
+  <property name="deps.dir" location="${top.dir}/deps" />
+  
+  <property name="vmware.jar" value="cloud-vmware.jar" />
+  <property name="vmware-scripts.dir" location="${base.dir}/plugins/hypervisors/vmware/scripts" />
+	
+  <import file="${build.dir}/build-common.xml"/>
+
+  <echo message="target.dir=${target.dir}; top.dir=${top.dir}"/>
+	
+  <!-- This section needs to be replaced by some kind of dependency library-->
+  <path id="deps.classpath">
+    <!--filelist files="${deps.classpath}" /-->
+    <fileset dir="${deps.dir}" erroronmissingdir="false">
+      <include name="*.jar" />
+    </fileset>
+  </path>
+	
+  <path id="cloudstack.classpath">
+  	<fileset dir="${jar.dir}">
+  	  <include name="*.jar"/>
+    </fileset>
+  </path>
+	
+  <path id="vmware.classpath">
+	<path refid="deps.classpath"/>
+  	<path refid="cloudstack.classpath"/>
+  </path>
+	
+  <!-- This section needs to be replaced by some kind of dependency library-->
+
+  <target name="deploy-vmware" >
+      <copy todir="${server.deploy.to.dir}/webapps/client/WEB-INF/lib/scripts">
+          <fileset dir="${vmware-scripts.dir}">
+              <include name="**/*"/>
+          </fileset>
+      </copy>
+  </target>
+
+  <target name="init" description="Initialize binaries directory">
+  	<mkdir dir="${classes.dir}/${vmware.jar}"/>
+  	<mkdir dir="${jar.dir}"/>
+  </target>
+	
+  <target name="compile-vmware" depends="init" description="Compiles Vmware">
+    <compile-java jar.name="${vmware.jar}" top.dir="${vmware.base.dir}" classpath="vmware.classpath" />
+  </target>
+	
+  <target name="help" description="help">
+    <echo level="info" message="This is the build file for vmware"/>
+    <echo level="info" message="You can do a build by doing ant build or clean by ant clean" />
+  </target>
+
+  <target name="clean-vmware">
+    <delete dir="${classes.dir}/${vmware.jar}"/>
+  </target>
+	
+  <target name="build" depends="compile-vmware"/>
+  <target name="clean" depends="clean-vmware"/>
+	
+</project>

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/8197f1f0/plugins/hypervisors/vmware/src/com/cloud/api/commands/DeleteCiscoNexusVSMCmd.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/api/commands/DeleteCiscoNexusVSMCmd.java b/plugins/hypervisors/vmware/src/com/cloud/api/commands/DeleteCiscoNexusVSMCmd.java
new file mode 100644
index 0000000..e684703
--- /dev/null
+++ b/plugins/hypervisors/vmware/src/com/cloud/api/commands/DeleteCiscoNexusVSMCmd.java
@@ -0,0 +1,98 @@
+/**
+ *  Copyright (C) 2011 Citrix Systems, Inc.  All rights reserved.
+ * 
+ * This software is licensed under the GNU General Public License v3 or later.
+ * 
+ * It is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ * 
+ */
+
+package com.cloud.api.commands;
+
+import org.apache.log4j.Logger;
+
+import com.cloud.api.ApiConstants;
+import com.cloud.api.BaseAsyncCmd;
+import com.cloud.api.IdentityMapper;
+import com.cloud.api.Implementation;
+import com.cloud.api.Parameter;
+import com.cloud.api.PlugService;
+import com.cloud.api.ServerApiException;
+import com.cloud.api.response.SuccessResponse;
+import com.cloud.event.EventTypes;
+import com.cloud.exception.ConcurrentOperationException;
+import com.cloud.exception.InsufficientCapacityException;
+import com.cloud.exception.ResourceAllocationException;
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.network.element.CiscoNexusVSMElementService;
+import com.cloud.user.Account;
+import com.cloud.user.UserContext;
+
+@Implementation(responseObject=SuccessResponse.class, description=" delete a Cisco Nexus VSM device")
+public class DeleteCiscoNexusVSMCmd extends BaseAsyncCmd {
+
+    public static final Logger s_logger = Logger.getLogger(DeleteCiscoNexusVSMCmd.class.getName());
+    private static final String s_name = "deletecisconexusvsmresponse";
+    @PlugService CiscoNexusVSMElementService _ciscoNexusVSMService;
+
+    /////////////////////////////////////////////////////
+    //////////////// API parameters /////////////////////
+    /////////////////////////////////////////////////////
+
+    @IdentityMapper(entityTableName="virtual_supervisor_module")
+    @Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="Id of the Cisco Nexus 1000v VSM device to be deleted")
+    private Long id;
+
+    /////////////////////////////////////////////////////
+    /////////////////// Accessors ///////////////////////
+    /////////////////////////////////////////////////////
+
+    public Long getCiscoNexusVSMDeviceId() {
+        return id;
+    }
+
+    /////////////////////////////////////////////////////
+    /////////////// API Implementation///////////////////
+    /////////////////////////////////////////////////////
+
+    @Override
+    public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
+    	boolean result = _ciscoNexusVSMService.deleteCiscoNexusVSM(this);
+        if (result) {
+        	SuccessResponse response = new SuccessResponse(getCommandName());
+        	response.setResponseName(getCommandName());
+        	this.setResponseObject(response);
+        } else {
+        	throw new ServerApiException(BaseAsyncCmd.INTERNAL_ERROR, "Failed to delete Cisco Nexus VSM device");
+        }
+    }
+
+    @Override
+    public String getCommandName() {
+        return s_name;
+    }
+
+    @Override
+    public long getEntityOwnerId() {
+        return Account.ACCOUNT_ID_SYSTEM;
+    }
+    
+    @Override
+    public String getEventType() {
+    	return EventTypes.EVENT_EXTERNAL_SWITCH_MGMT_DEVICE_DELETE;
+    }
+
+    @Override
+    public String getEventDescription() {
+    	return "Deleting a Cisco Nexus VSM device";
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/8197f1f0/plugins/hypervisors/vmware/src/com/cloud/api/commands/DisableCiscoNexusVSMCmd.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/api/commands/DisableCiscoNexusVSMCmd.java b/plugins/hypervisors/vmware/src/com/cloud/api/commands/DisableCiscoNexusVSMCmd.java
new file mode 100644
index 0000000..17f4eb1
--- /dev/null
+++ b/plugins/hypervisors/vmware/src/com/cloud/api/commands/DisableCiscoNexusVSMCmd.java
@@ -0,0 +1,98 @@
+/**
+ *  Copyright (C) 2011 Citrix Systems, Inc.  All rights reserved.
+ * 
+ * This software is licensed under the GNU General Public License v3 or later.
+ * 
+ * It is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ * 
+ */
+
+package com.cloud.api.commands;
+
+import org.apache.log4j.Logger;
+
+import com.cloud.api.ApiConstants;
+import com.cloud.api.BaseAsyncCmd;
+import com.cloud.api.IdentityMapper;
+import com.cloud.api.Implementation;
+import com.cloud.api.Parameter;
+import com.cloud.api.PlugService;
+import com.cloud.api.ServerApiException;
+import com.cloud.exception.ConcurrentOperationException;
+import com.cloud.exception.InsufficientCapacityException;
+import com.cloud.exception.ResourceAllocationException;
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.network.element.CiscoNexusVSMElementService;
+import com.cloud.user.Account;
+import com.cloud.event.EventTypes;
+import com.cloud.api.response.CiscoNexusVSMResponse;
+import com.cloud.network.CiscoNexusVSMDevice;
+
+@Implementation(responseObject=CiscoNexusVSMResponse.class, description="disable a Cisco Nexus VSM device")
+public class DisableCiscoNexusVSMCmd extends BaseAsyncCmd {
+
+    public static final Logger s_logger = Logger.getLogger(DisableCiscoNexusVSMCmd.class.getName());
+    private static final String s_name = "disablecisconexusvsmresponse";
+    @PlugService CiscoNexusVSMElementService _ciscoNexusVSMService;
+
+    /////////////////////////////////////////////////////
+    //////////////// API parameters /////////////////////
+    /////////////////////////////////////////////////////
+
+    @IdentityMapper(entityTableName="virtual_supervisor_module")
+    @Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="Id of the Cisco Nexus 1000v VSM device to be deleted")
+    private Long id;
+
+    /////////////////////////////////////////////////////
+    /////////////////// Accessors ///////////////////////
+    /////////////////////////////////////////////////////
+
+    public Long getCiscoNexusVSMDeviceId() {
+        return id;
+    }
+
+    /////////////////////////////////////////////////////
+    /////////////// API Implementation///////////////////
+    /////////////////////////////////////////////////////
+
+    @Override
+    public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
+    	CiscoNexusVSMDevice result = _ciscoNexusVSMService.disableCiscoNexusVSM(this);
+        if (result != null) {
+        	CiscoNexusVSMResponse response = _ciscoNexusVSMService.createCiscoNexusVSMDetailedResponse(result);
+        	response.setResponseName(getCommandName());
+        	this.setResponseObject(response);
+        } else {
+        	throw new ServerApiException(BaseAsyncCmd.INTERNAL_ERROR, "Failed to disable Cisco Nexus VSM device");
+        }
+    }
+
+    @Override
+    public String getCommandName() {
+        return s_name;
+    }
+
+    @Override
+    public long getEntityOwnerId() {
+        return Account.ACCOUNT_ID_SYSTEM;
+    }
+
+    @Override
+    public String getEventDescription() {
+    	return "Disabling a Cisco Nexus VSM device";
+    }
+
+    @Override
+    public String getEventType() {
+    	return EventTypes.EVENT_EXTERNAL_SWITCH_MGMT_DEVICE_DISABLE;
+    }    
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/8197f1f0/plugins/hypervisors/vmware/src/com/cloud/api/commands/EnableCiscoNexusVSMCmd.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/api/commands/EnableCiscoNexusVSMCmd.java b/plugins/hypervisors/vmware/src/com/cloud/api/commands/EnableCiscoNexusVSMCmd.java
new file mode 100644
index 0000000..b532269
--- /dev/null
+++ b/plugins/hypervisors/vmware/src/com/cloud/api/commands/EnableCiscoNexusVSMCmd.java
@@ -0,0 +1,98 @@
+/**
+ *  Copyright (C) 2011 Citrix Systems, Inc.  All rights reserved.
+ * 
+ * This software is licensed under the GNU General Public License v3 or later.
+ * 
+ * It is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ * 
+ */
+
+package com.cloud.api.commands;
+
+import org.apache.log4j.Logger;
+
+import com.cloud.api.ApiConstants;
+import com.cloud.api.BaseAsyncCmd;
+import com.cloud.api.IdentityMapper;
+import com.cloud.api.Implementation;
+import com.cloud.api.Parameter;
+import com.cloud.api.PlugService;
+import com.cloud.api.ServerApiException;
+import com.cloud.event.EventTypes;
+import com.cloud.exception.ConcurrentOperationException;
+import com.cloud.exception.InsufficientCapacityException;
+import com.cloud.exception.ResourceAllocationException;
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.network.element.CiscoNexusVSMElementService;
+import com.cloud.user.Account;
+import com.cloud.api.response.CiscoNexusVSMResponse;
+import com.cloud.network.CiscoNexusVSMDevice;
+
+@Implementation(responseObject=CiscoNexusVSMResponse.class, description="Enable a Cisco Nexus VSM device")
+public class EnableCiscoNexusVSMCmd extends BaseAsyncCmd {
+
+    public static final Logger s_logger = Logger.getLogger(EnableCiscoNexusVSMCmd.class.getName());
+    private static final String s_name = "enablecisconexusvsmresponse";
+    @PlugService CiscoNexusVSMElementService _ciscoNexusVSMService;
+
+    /////////////////////////////////////////////////////
+    //////////////// API parameters /////////////////////
+    /////////////////////////////////////////////////////
+
+    @IdentityMapper(entityTableName="virtual_supervisor_module")
+    @Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="Id of the Cisco Nexus 1000v VSM device to be enabled")
+    private Long id;
+
+    /////////////////////////////////////////////////////
+    /////////////////// Accessors ///////////////////////
+    /////////////////////////////////////////////////////
+
+    public Long getCiscoNexusVSMDeviceId() {
+        return id;
+    }
+
+    /////////////////////////////////////////////////////
+    /////////////// API Implementation///////////////////
+    /////////////////////////////////////////////////////
+
+    @Override
+    public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
+    	CiscoNexusVSMDevice result = _ciscoNexusVSMService.enableCiscoNexusVSM(this);
+        if (result != null) {
+        	CiscoNexusVSMResponse response = _ciscoNexusVSMService.createCiscoNexusVSMDetailedResponse(result);
+        	response.setResponseName(getCommandName());
+        	this.setResponseObject(response);
+        } else {
+        	throw new ServerApiException(BaseAsyncCmd.INTERNAL_ERROR, "Failed to enable Cisco Nexus VSM device");
+        }
+    }
+
+    @Override
+    public String getCommandName() {
+        return s_name;
+    }
+
+    @Override
+    public long getEntityOwnerId() {
+        return Account.ACCOUNT_ID_SYSTEM;
+    }
+
+    @Override
+    public String getEventDescription() {
+    	return "Enabling a Cisco Nexus VSM device";
+    }
+
+    @Override
+    public String getEventType() {
+    	return EventTypes.EVENT_EXTERNAL_SWITCH_MGMT_DEVICE_ENABLE;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/8197f1f0/plugins/hypervisors/vmware/src/com/cloud/api/commands/ListCiscoNexusVSMsCmd.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/api/commands/ListCiscoNexusVSMsCmd.java b/plugins/hypervisors/vmware/src/com/cloud/api/commands/ListCiscoNexusVSMsCmd.java
new file mode 100755
index 0000000..40bd36e
--- /dev/null
+++ b/plugins/hypervisors/vmware/src/com/cloud/api/commands/ListCiscoNexusVSMsCmd.java
@@ -0,0 +1,117 @@
+/**
+ *  Copyright (C) 2011 Citrix Systems, Inc.  All rights reserved.
+ * 
+ * This software is licensed under the GNU General Public License v3 or later.
+ * 
+ * It is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ * 
+ */
+
+package com.cloud.api.commands;
+
+import org.apache.log4j.Logger;
+import com.cloud.api.ApiConstants;
+import com.cloud.api.BaseListCmd;
+import com.cloud.api.IdentityMapper;
+import com.cloud.api.Implementation;
+import com.cloud.api.Parameter;
+import com.cloud.api.PlugService;
+import com.cloud.api.ServerApiException;
+import com.cloud.api.response.CiscoNexusVSMResponse;
+import com.cloud.api.response.ListResponse;
+import com.cloud.exception.ConcurrentOperationException;
+import com.cloud.exception.InsufficientCapacityException;
+import com.cloud.exception.ResourceAllocationException;
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.network.CiscoNexusVSMDevice;
+import com.cloud.network.element.CiscoNexusVSMElementService;
+import com.cloud.user.Account;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@Implementation(responseObject=CiscoNexusVSMResponse.class, description="Retrieves a Cisco Nexus 1000v Virtual Switch Manager device associated with a Cluster")
+public class ListCiscoNexusVSMsCmd extends BaseListCmd {
+
+	/**
+	 * This command returns a list of all the VSMs configured in the management server.
+	 * If a clusterId is specified, it will return a list containing only that VSM 
+	 * that is associated with that cluster. If a zone is specified, it will pull
+	 * up all the clusters of type vmware in that zone, and prepare a list of VSMs
+	 * associated with those clusters.
+	 */
+    public static final Logger s_logger = Logger.getLogger(ListCiscoNexusVSMsCmd.class.getName());
+    private static final String s_name = "listcisconexusvsmscmdresponse";
+    @PlugService CiscoNexusVSMElementService _ciscoNexusVSMService;
+
+    /////////////////////////////////////////////////////
+    //////////////// API parameters /////////////////////
+    /////////////////////////////////////////////////////
+
+    @IdentityMapper(entityTableName="cluster")
+    @Parameter(name=ApiConstants.CLUSTER_ID, type=CommandType.LONG, required = false, description="Id of the CloudStack cluster in which the Cisco Nexus 1000v VSM appliance.")
+    private long clusterId;
+    
+    @IdentityMapper(entityTableName="data_center")
+    @Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, required = false, description="Id of the CloudStack cluster in which the Cisco Nexus 1000v VSM appliance.")
+    private long zoneId;
+
+    /////////////////////////////////////////////////////
+    /////////////////// Accessors ///////////////////////
+    /////////////////////////////////////////////////////
+    
+    public long getClusterId() {
+    	return clusterId;
+    }
+    
+    public long getZoneId() {
+    	return zoneId;
+    }
+
+    /////////////////////////////////////////////////////
+    /////////////// API Implementation///////////////////
+    /////////////////////////////////////////////////////
+
+    // NOTE- The uuid that is sent in during the invocation of the API AddCiscoNexusVSM()
+    // automagically gets translated to the corresponding db id before this execute() method
+    // is invoked. That's the reason why we don't have any uuid-dbid translation code here.
+    @Override
+    public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
+    	List<? extends CiscoNexusVSMDevice> vsmDeviceList = _ciscoNexusVSMService.getCiscoNexusVSMs(this);
+    	
+    	if (vsmDeviceList.size() > 0) {
+    		ListResponse<CiscoNexusVSMResponse> response = new ListResponse<CiscoNexusVSMResponse>();
+    		List<CiscoNexusVSMResponse> vsmResponses = new ArrayList<CiscoNexusVSMResponse>();
+    		for (CiscoNexusVSMDevice vsmDevice : vsmDeviceList) {
+    			CiscoNexusVSMResponse vsmresponse = _ciscoNexusVSMService.createCiscoNexusVSMDetailedResponse(vsmDevice);
+    			vsmresponse.setObjectName("cisconexusvsm");
+    			response.setResponseName(getCommandName());
+    			vsmResponses.add(vsmresponse);
+    		}
+    		response.setResponses(vsmResponses);
+    		response.setResponseName(getCommandName());
+    		this.setResponseObject(response);
+    	} else {
+        	throw new ServerApiException(BaseListCmd.INTERNAL_ERROR, "No VSM found.");
+        }
+    }
+ 
+    @Override
+    public String getCommandName() {
+        return s_name;
+    }
+
+    @Override
+    public long getEntityOwnerId() {
+        return Account.ACCOUNT_ID_SYSTEM;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/8197f1f0/plugins/hypervisors/vmware/src/com/cloud/api/response/CiscoNexusVSMResponse.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/api/response/CiscoNexusVSMResponse.java b/plugins/hypervisors/vmware/src/com/cloud/api/response/CiscoNexusVSMResponse.java
new file mode 100644
index 0000000..e0169d3
--- /dev/null
+++ b/plugins/hypervisors/vmware/src/com/cloud/api/response/CiscoNexusVSMResponse.java
@@ -0,0 +1,112 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.api.response;
+
+import javax.persistence.Column;
+
+import com.cloud.api.ApiConstants;
+import com.cloud.utils.IdentityProxy;
+import com.cloud.serializer.Param;
+import com.google.gson.annotations.SerializedName;
+
+public class CiscoNexusVSMResponse extends BaseResponse {
+
+    @SerializedName(ApiConstants.EXTERNAL_SWITCH_MGMT_DEVICE_ID) @Param(description="device id of the Cisco N1KV VSM device")
+    private IdentityProxy id = new IdentityProxy("virtual_supervisor_module");
+    
+    @SerializedName(ApiConstants.EXTERNAL_SWITCH_MGMT_DEVICE_NAME) @Param(description="device name")
+    private String deviceName;
+    
+    @SerializedName(ApiConstants.IP_ADDRESS) @Param(description="the management IP address of the external Cisco Nexus 1000v Virtual Supervisor Module")
+    private String vsmmgmtIpAddress;
+    
+    @SerializedName(ApiConstants.EXTERNAL_SWITCH_MGMT_DEVICE_STATE) @Param(description="device state")
+    private String deviceState;
+    
+    @SerializedName(ApiConstants.VSM_MGMT_VLAN_ID) @Param(description="management vlan id of the VSM")
+    private String vsmmgmtvlanid;
+
+    @SerializedName(ApiConstants.VSM_CTRL_VLAN_ID) @Param(description="control vlan id of the VSM")
+    private int vsmctrlvlanid;
+
+    @SerializedName(ApiConstants.VSM_PKT_VLAN_ID) @Param(description="packet vlan id of the VSM")
+    private int vsmpktvlanid;
+
+    @SerializedName(ApiConstants.VSM_STORAGE_VLAN_ID) @Param(description="storage vlan id of the VSM")
+    private int vsmstoragevlanid;
+    
+    @SerializedName(ApiConstants.VSM_DOMAIN_ID) @Param(description="The VSM is a switch supervisor. This is the VSM's switch domain id")
+    private String vsmdomainid;
+    
+    @SerializedName(ApiConstants.VSM_CONFIG_MODE) @Param(description="The mode of the VSM (standalone/HA)")
+    private String vsmconfigmode;
+    
+    @SerializedName(ApiConstants.VSM_CONFIG_STATE) @Param(description="The Config State (Primary/Standby) of the VSM")
+    private String vsmconfigstate;
+    
+    @SerializedName(ApiConstants.VSM_DEVICE_STATE) @Param(description="The Device State (Enabled/Disabled) of the VSM")
+    private String vsmdevicestate;
+
+    // Setter methods.
+    public void setId(long vsmDeviceId) {
+        this.id.setValue(vsmDeviceId);
+    }
+
+    public void setDeviceName(String deviceName) {
+        this.deviceName = deviceName;
+    }
+
+    public void setMgmtIpAddress(String ipAddress) {
+        this.vsmmgmtIpAddress = ipAddress;
+    }
+    
+    public void setDeviceState(String deviceState) {
+    	this.deviceState = deviceState;
+    }
+    
+    public void setVSMMgmtVlanId(String vlanId) {
+    	this.vsmmgmtvlanid = vlanId;
+    }
+    
+    public void setVSMCtrlVlanId(int vlanId) {
+    	this.vsmctrlvlanid = vlanId;
+    }
+    
+    public void setVSMPktVlanId(int vlanId) {
+    	this.vsmpktvlanid = vlanId;
+    }
+    
+    public void setVSMStorageVlanId(int vlanId) {
+    	this.vsmstoragevlanid = vlanId;
+    }
+    
+    public void setVSMDomainId(String domId) {
+    	this.vsmdomainid = domId;
+    }
+    
+    public void setVSMConfigMode(String configMode) {
+    	this.vsmconfigmode = configMode;
+    }
+    
+    public void setVSMConfigState(String configState) {
+    	this.vsmconfigstate = configState;
+    }
+    
+    public void setVSMDeviceState(String devState) {
+    	this.vsmdevicestate = devState;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/8197f1f0/plugins/hypervisors/vmware/src/com/cloud/ha/VmwareFencer.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/ha/VmwareFencer.java b/plugins/hypervisors/vmware/src/com/cloud/ha/VmwareFencer.java
new file mode 100644
index 0000000..f33f1e1
--- /dev/null
+++ b/plugins/hypervisors/vmware/src/com/cloud/ha/VmwareFencer.java
@@ -0,0 +1,56 @@
+// Copyright 2012 Citrix Systems, Inc. Licensed under the
+// Apache License, Version 2.0 (the "License"); you may not use this
+// file except in compliance with the License.  Citrix Systems, Inc.
+// reserves all rights not expressly granted by the License.
+// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+// 
+// Automatically generated by addcopyright.py at 04/03/2012
+package com.cloud.ha;
+
+import java.util.Map;
+
+import javax.ejb.Local;
+import javax.naming.ConfigurationException;
+
+import com.cloud.host.HostVO;
+import com.cloud.vm.VMInstanceVO;
+
+@Local(value=FenceBuilder.class)
+public class VmwareFencer implements FenceBuilder {
+    String _name;
+
+    @Override
+    public Boolean fenceOff(VMInstanceVO vm, HostVO host) {
+    	return null;
+    }
+	
+    public VmwareFencer() {
+        super();
+    }
+
+    @Override
+    public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
+        _name = name;
+        return true;
+    }
+
+    @Override
+    public String getName() {
+        return _name;
+    }
+
+    @Override
+    public boolean start() {
+        return true;
+    }
+
+    @Override
+    public boolean stop() {
+        return true;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/8197f1f0/plugins/hypervisors/vmware/src/com/cloud/ha/VmwareInvestigator.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/ha/VmwareInvestigator.java b/plugins/hypervisors/vmware/src/com/cloud/ha/VmwareInvestigator.java
new file mode 100644
index 0000000..b85f307
--- /dev/null
+++ b/plugins/hypervisors/vmware/src/com/cloud/ha/VmwareInvestigator.java
@@ -0,0 +1,44 @@
+// Copyright 2012 Citrix Systems, Inc. Licensed under the
+// Apache License, Version 2.0 (the "License"); you may not use this
+// file except in compliance with the License.  Citrix Systems, Inc.
+// reserves all rights not expressly granted by the License.
+// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+// 
+// Automatically generated by addcopyright.py at 04/03/2012
+package com.cloud.ha;
+
+import javax.ejb.Local;
+
+import com.cloud.host.HostVO;
+import com.cloud.host.Status;
+import com.cloud.hypervisor.Hypervisor.HypervisorType;
+import com.cloud.utils.component.AdapterBase;
+import com.cloud.vm.VMInstanceVO;
+
+@Local(value=Investigator.class)
+public class VmwareInvestigator extends AdapterBase implements Investigator {
+    protected VmwareInvestigator() {
+    }
+    
+    @Override
+    public Status isAgentAlive(HostVO agent) {
+    	if(agent.getHypervisorType() == HypervisorType.VMware)
+    		return Status.Disconnected;
+    	
+    	return null;
+    }
+    
+    @Override
+    public Boolean isVmAlive(VMInstanceVO vm, HostVO host) {
+    	if(vm.getHypervisorType() == HypervisorType.VMware)
+    		return true;
+    	
+    	return null;
+    }
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/8197f1f0/plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java
new file mode 100644
index 0000000..4f936be
--- /dev/null
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/guru/VMwareGuru.java
@@ -0,0 +1,311 @@
+// Copyright 2012 Citrix Systems, Inc. Licensed under the
+// Apache License, Version 2.0 (the "License"); you may not use this
+// file except in compliance with the License.  Citrix Systems, Inc.
+// reserves all rights not expressly granted by the License.
+// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+// 
+// Automatically generated by addcopyright.py at 04/03/2012
+package com.cloud.hypervisor.guru;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.ejb.Local;
+
+import org.apache.log4j.Logger;
+
+import com.cloud.agent.api.BackupSnapshotCommand;
+import com.cloud.agent.api.Command;
+import com.cloud.agent.api.CreatePrivateTemplateFromSnapshotCommand;
+import com.cloud.agent.api.CreatePrivateTemplateFromVolumeCommand;
+import com.cloud.agent.api.CreateVolumeFromSnapshotCommand;
+import com.cloud.agent.api.storage.CopyVolumeCommand;
+import com.cloud.agent.api.storage.PrimaryStorageDownloadCommand;
+import com.cloud.agent.api.to.NicTO;
+import com.cloud.agent.api.to.VirtualMachineTO;
+import com.cloud.cluster.CheckPointManager;
+import com.cloud.cluster.ClusterManager;
+import com.cloud.exception.InsufficientAddressCapacityException;
+import com.cloud.host.HostVO;
+import com.cloud.host.dao.HostDao;
+import com.cloud.host.dao.HostDetailsDao;
+import com.cloud.hypervisor.Hypervisor.HypervisorType;
+import com.cloud.hypervisor.HypervisorGuru;
+import com.cloud.hypervisor.HypervisorGuruBase;
+import com.cloud.hypervisor.vmware.VmwareCleanupMaid;
+import com.cloud.hypervisor.vmware.manager.VmwareManager;
+import com.cloud.hypervisor.vmware.mo.VirtualEthernetCardType;
+import com.cloud.network.NetworkManager;
+import com.cloud.network.NetworkVO;
+import com.cloud.network.Networks.TrafficType;
+import com.cloud.network.dao.NetworkDao;
+import com.cloud.secstorage.CommandExecLogDao;
+import com.cloud.secstorage.CommandExecLogVO;
+import com.cloud.storage.GuestOSVO;
+import com.cloud.storage.dao.GuestOSDao;
+import com.cloud.storage.secondary.SecondaryStorageVmManager;
+import com.cloud.template.VirtualMachineTemplate.BootloaderType;
+import com.cloud.utils.Pair;
+import com.cloud.utils.component.Inject;
+import com.cloud.utils.db.DB;
+import com.cloud.utils.exception.CloudRuntimeException;
+import com.cloud.utils.net.NetUtils;
+import com.cloud.vm.ConsoleProxyVO;
+import com.cloud.vm.DomainRouterVO;
+import com.cloud.vm.NicProfile;
+import com.cloud.vm.SecondaryStorageVmVO;
+import com.cloud.vm.VirtualMachine;
+import com.cloud.vm.VirtualMachineProfile;
+import com.cloud.vm.VmDetailConstants;
+
+@Local(value=HypervisorGuru.class)
+public class VMwareGuru extends HypervisorGuruBase implements HypervisorGuru {
+	private static final Logger s_logger = Logger.getLogger(VMwareGuru.class);
+
+	@Inject NetworkDao _networkDao;
+	@Inject GuestOSDao _guestOsDao;
+    @Inject HostDao _hostDao;
+    @Inject HostDetailsDao _hostDetailsDao;
+    @Inject CommandExecLogDao _cmdExecLogDao;
+    @Inject ClusterManager _clusterMgr;
+    @Inject VmwareManager _vmwareMgr;
+    @Inject SecondaryStorageVmManager _secStorageMgr;
+    @Inject CheckPointManager _checkPointMgr;
+    @Inject NetworkManager _networkMgr;
+
+    protected VMwareGuru() {
+    	super();
+    }
+    
+    @Override
+    public HypervisorType getHypervisorType() {
+        return HypervisorType.VMware;
+    }
+
+    @Override
+    public <T extends VirtualMachine> VirtualMachineTO implement(VirtualMachineProfile<T> vm) {
+        VirtualMachineTO to = toVirtualMachineTO(vm);
+        to.setBootloader(BootloaderType.HVM);
+
+    	Map<String, String> details = to.getDetails();
+    	if(details == null)
+    		details = new HashMap<String, String>();
+        
+    	String nicDeviceType = details.get(VmDetailConstants.NIC_ADAPTER);
+        if(vm.getVirtualMachine() instanceof DomainRouterVO || vm.getVirtualMachine() instanceof ConsoleProxyVO 
+        	|| vm.getVirtualMachine() instanceof SecondaryStorageVmVO) {
+        	
+        	if(nicDeviceType == null) {
+        		details.put(VmDetailConstants.NIC_ADAPTER, _vmwareMgr.getSystemVMDefaultNicAdapterType());
+        	} else {
+        		try {
+        			VirtualEthernetCardType.valueOf(nicDeviceType);
+        		} catch (Exception e) {
+        			s_logger.warn("Invalid NIC device type " + nicDeviceType + " is specified in VM details, switch to default E1000");
+            		details.put(VmDetailConstants.NIC_ADAPTER, VirtualEthernetCardType.E1000.toString());
+        		}
+        	}
+        } else {
+        	// for user-VM, use E1000 as default
+        	if(nicDeviceType == null) {
+        		details.put(VmDetailConstants.NIC_ADAPTER, VirtualEthernetCardType.E1000.toString());
+        	} else {
+        		try {
+        			VirtualEthernetCardType.valueOf(nicDeviceType);
+        		} catch (Exception e) {
+        			s_logger.warn("Invalid NIC device type " + nicDeviceType + " is specified in VM details, switch to default E1000");
+            		details.put(VmDetailConstants.NIC_ADAPTER, VirtualEthernetCardType.E1000.toString());
+        		}
+        	}
+        }
+    	to.setDetails(details);
+
+    	if(vm.getVirtualMachine() instanceof DomainRouterVO) {
+    		List<NicProfile> nicProfiles = vm.getNics();
+    		NicProfile publicNicProfile = null;
+    		
+    		for(NicProfile nicProfile : nicProfiles) {
+    			if(nicProfile.getTrafficType() == TrafficType.Public) {
+    				publicNicProfile = nicProfile;
+    				break;
+    			}
+    		}
+    		
+    		if(publicNicProfile != null) {
+	    		NicTO[] nics = to.getNics();
+
+	    		// reserve extra NICs
+	    		NicTO[] expandedNics = new NicTO[nics.length + _vmwareMgr.getRouterExtraPublicNics()];
+	    		int i = 0;
+	    		int deviceId = -1;
+	    		for(i = 0; i < nics.length; i++) {
+	    			expandedNics[i] = nics[i];
+	    			if(nics[i].getDeviceId() > deviceId)
+	    				deviceId = nics[i].getDeviceId();
+	    		}
+	    		deviceId++;
+	    		
+	    		long networkId = publicNicProfile.getNetworkId();
+	    		NetworkVO network = _networkDao.findById(networkId);
+	    		
+	    		for(; i < nics.length + _vmwareMgr.getRouterExtraPublicNics(); i++) {
+	    			NicTO nicTo = new NicTO();
+	    			
+	    			nicTo.setDeviceId(deviceId++);
+	    			nicTo.setBroadcastType(publicNicProfile.getBroadcastType());
+	    			nicTo.setType(publicNicProfile.getTrafficType());
+	    			nicTo.setIp("0.0.0.0");
+	    			nicTo.setNetmask("255.255.255.255");
+	    			
+	    			try {
+	    				String mac = _networkMgr.getNextAvailableMacAddressInNetwork(networkId);
+						nicTo.setMac(mac);
+					} catch (InsufficientAddressCapacityException e) {
+						throw new CloudRuntimeException("unable to allocate mac address on network: " + networkId);
+					}
+	    			nicTo.setDns1(publicNicProfile.getDns1());
+	    			nicTo.setDns2(publicNicProfile.getDns2());
+	    	        if (publicNicProfile.getGateway() != null) {
+	    	        	nicTo.setGateway(publicNicProfile.getGateway());
+	    	        } else {
+	    	        	nicTo.setGateway(network.getGateway());
+	    	        }
+	    	        nicTo.setDefaultNic(false);
+	    	        nicTo.setBroadcastUri(publicNicProfile.getBroadCastUri());
+	    	        nicTo.setIsolationuri(publicNicProfile.getIsolationUri());
+
+	    	        Integer networkRate = _networkMgr.getNetworkRate(network.getId(), null);
+	    	        nicTo.setNetworkRateMbps(networkRate);
+	    	        
+	    	        expandedNics[i] = nicTo;
+	    		}
+	    		
+	    		to.setNics(expandedNics);
+    		}
+    		
+    		StringBuffer sbMacSequence = new StringBuffer();
+        	for(NicTO nicTo : sortNicsByDeviceId(to.getNics())) {
+    			sbMacSequence.append(nicTo.getMac()).append("|");
+        	}
+    		sbMacSequence.deleteCharAt(sbMacSequence.length() - 1);
+    		String bootArgs = to.getBootArgs();
+    		to.setBootArgs(bootArgs + " nic_macs=" + sbMacSequence.toString());
+    	}
+
+        // Determine the VM's OS description
+        GuestOSVO guestOS = _guestOsDao.findById(vm.getVirtualMachine().getGuestOSId());
+        to.setOs(guestOS.getDisplayName());
+        return to;
+    }
+    
+    private NicTO[] sortNicsByDeviceId(NicTO[] nics) {
+
+        List<NicTO> listForSort = new ArrayList<NicTO>();
+        for (NicTO nic : nics) {
+            listForSort.add(nic);
+        }
+        Collections.sort(listForSort, new Comparator<NicTO>() {
+
+            @Override
+            public int compare(NicTO arg0, NicTO arg1) {
+                if (arg0.getDeviceId() < arg1.getDeviceId()) {
+                    return -1;
+                } else if (arg0.getDeviceId() == arg1.getDeviceId()) {
+                    return 0;
+                }
+
+                return 1;
+            }
+        });
+
+        return listForSort.toArray(new NicTO[0]);
+    }
+    
+    @Override @DB
+    public long getCommandHostDelegation(long hostId, Command cmd) {
+    	boolean needDelegation = false;
+    	
+    	if(cmd instanceof PrimaryStorageDownloadCommand || 
+    		cmd instanceof BackupSnapshotCommand ||
+    		cmd instanceof CreatePrivateTemplateFromVolumeCommand ||
+    		cmd instanceof CreatePrivateTemplateFromSnapshotCommand ||
+    		cmd instanceof CopyVolumeCommand ||
+    		cmd instanceof CreateVolumeFromSnapshotCommand) {
+    		needDelegation = true;
+    	}
+
+    	if(needDelegation) {
+    		HostVO host = _hostDao.findById(hostId);
+    		assert(host != null);
+    		assert(host.getHypervisorType() == HypervisorType.VMware);
+    		long dcId = host.getDataCenterId();
+    		
+    		Pair<HostVO, SecondaryStorageVmVO> cmdTarget = _secStorageMgr.assignSecStorageVm(dcId, cmd);
+    		if(cmdTarget != null) {
+    			// TODO, we need to make sure agent is actually connected too
+    			cmd.setContextParam("hypervisor", HypervisorType.VMware.toString());
+    		    Map<String, String> hostDetails = _hostDetailsDao.findDetails(hostId);
+    		    cmd.setContextParam("guid", resolveNameInGuid(hostDetails.get("guid")));
+    		    cmd.setContextParam("username", hostDetails.get("username"));
+    		    cmd.setContextParam("password", hostDetails.get("password"));
+    			cmd.setContextParam("serviceconsole", _vmwareMgr.getServiceConsolePortGroupName());
+    			cmd.setContextParam("manageportgroup", _vmwareMgr.getManagementPortGroupName());
+    			
+    			CommandExecLogVO execLog = new CommandExecLogVO(cmdTarget.first().getId(), cmdTarget.second().getId(), cmd.getClass().getSimpleName(), 1);
+    			_cmdExecLogDao.persist(execLog);
+    			cmd.setContextParam("execid", String.valueOf(execLog.getId()));
+    			
+    			if(cmd instanceof BackupSnapshotCommand || 
+    				cmd instanceof CreatePrivateTemplateFromVolumeCommand || 
+    				cmd instanceof CreatePrivateTemplateFromSnapshotCommand ||
+    				cmd instanceof CopyVolumeCommand ||
+    				cmd instanceof CreateVolumeFromSnapshotCommand) {
+    				
+    				String workerName = _vmwareMgr.composeWorkerName();
+    				long checkPointId = _checkPointMgr.pushCheckPoint(new VmwareCleanupMaid(hostDetails.get("guid"), workerName));
+    				cmd.setContextParam("worker", workerName);
+    				cmd.setContextParam("checkpoint", String.valueOf(checkPointId));
+
+    				// some commands use 2 workers
+                    String workerName2 = _vmwareMgr.composeWorkerName();
+                    long checkPointId2 = _checkPointMgr.pushCheckPoint(new VmwareCleanupMaid(hostDetails.get("guid"), workerName2));
+                    cmd.setContextParam("worker2", workerName2);
+                    cmd.setContextParam("checkpoint2", String.valueOf(checkPointId2));
+    			}
+    			
+    			return cmdTarget.first().getId();
+    		}
+    	}
+  
+    	return hostId;
+    }
+    
+    public boolean trackVmHostChange() {
+    	return true;
+    }
+    
+    private static String resolveNameInGuid(String guid) {
+    	String tokens[] = guid.split("@");
+    	assert(tokens.length == 2);
+
+    	String vCenterIp = NetUtils.resolveToIp(tokens[1]);
+    	if(vCenterIp == null) {
+    		s_logger.error("Fatal : unable to resolve vCenter address " + tokens[1] + ", please check your DNS configuration");
+    		return guid;
+    	}
+    	
+    	if(vCenterIp.equals(tokens[1]))
+    		return guid;
+    	
+    	return tokens[0] + "@" + vCenterIp;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/8197f1f0/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareCleanupMaid.java
----------------------------------------------------------------------
diff --git a/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareCleanupMaid.java b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareCleanupMaid.java
new file mode 100644
index 0000000..ee2f56f
--- /dev/null
+++ b/plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/VmwareCleanupMaid.java
@@ -0,0 +1,143 @@
+// Copyright 2012 Citrix Systems, Inc. Licensed under the
+// Apache License, Version 2.0 (the "License"); you may not use this
+// file except in compliance with the License.  Citrix Systems, Inc.
+// reserves all rights not expressly granted by the License.
+// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+// 
+// Automatically generated by addcopyright.py at 04/03/2012
+package com.cloud.hypervisor.vmware;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+
+import com.cloud.cluster.CheckPointManager;
+import com.cloud.cluster.CleanupMaid;
+import com.cloud.hypervisor.vmware.manager.VmwareManager;
+import com.cloud.hypervisor.vmware.mo.ClusterMO;
+import com.cloud.hypervisor.vmware.mo.DatacenterMO;
+import com.cloud.hypervisor.vmware.mo.HostMO;
+import com.cloud.hypervisor.vmware.mo.VirtualMachineMO;
+import com.cloud.hypervisor.vmware.util.VmwareContext;
+
+public class VmwareCleanupMaid implements CleanupMaid {
+    private static final Logger s_logger = Logger.getLogger(VmwareCleanupMaid.class);
+    
+    private static Map<String, List<VmwareCleanupMaid>> s_leftoverDummyVMs = new HashMap<String, List<VmwareCleanupMaid>>();
+    
+    private String _vCenterAddress;
+    private String _dcMorValue;
+    private String _hostMorValue;
+    private String _vmName;
+    private long _checkPoint;
+    
+	public VmwareCleanupMaid() {
+	}
+	
+	public VmwareCleanupMaid(String hostGuid, String vmName) {
+		String[] tokens = hostGuid.split("@");
+		assert(tokens != null);
+		assert(tokens.length == 2);
+		_vCenterAddress = tokens[1];
+		
+		String[] hostTokens = tokens[0].split(":");
+		assert(hostTokens != null);
+		assert(hostTokens.length == 2);
+		
+		_hostMorValue = hostTokens[1];
+		
+		_vmName = vmName;
+	}
+	
+	public VmwareCleanupMaid(String vCenterAddress, String dcMorValue, String vmName) {
+		_vCenterAddress = vCenterAddress;
+		_dcMorValue = dcMorValue;
+		_vmName = vmName;
+	}
+	
+	@Override
+	public int cleanup(CheckPointManager checkPointMgr) {
+		
+		// save a check-point in case we crash at current run so that we won't lose it
+		_checkPoint = checkPointMgr.pushCheckPoint(new VmwareCleanupMaid(_vCenterAddress, _dcMorValue, _vmName));
+		addLeftOverVM(this);
+		return 0;
+	}
+
+	@Override
+	public String getCleanupProcedure() {
+		return null;
+	}
+	
+	public String getVCenterServer() {
+		return _vCenterAddress;
+	}
+	
+	public String getDatacenterMorValue() {
+		return _dcMorValue;
+	}
+	
+	public String getHostMorValue() {
+		return _hostMorValue;
+	}
+	
+	public String getVmName() {
+		return _vmName;
+	}
+	
+	public long getCheckPoint() {
+		return _checkPoint;
+	}
+	
+    private synchronized static void addLeftOverVM(VmwareCleanupMaid cleanupMaid) {
+        List<VmwareCleanupMaid> l = s_leftoverDummyVMs.get(cleanupMaid.getVCenterServer());
+        if(l == null) {
+            l = new ArrayList<VmwareCleanupMaid>();
+            s_leftoverDummyVMs.put(cleanupMaid.getVCenterServer(), l);
+        }
+        
+        l.add(cleanupMaid);
+    }
+    
+    public synchronized static void gcLeftOverVMs(VmwareContext context) {
+        List<VmwareCleanupMaid> l = s_leftoverDummyVMs.get(context.getServerAddress());
+        VmwareManager mgr = context.getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
+        assert(mgr != null);
+        
+        if(l != null && l.size() > 0) {
+            for(VmwareCleanupMaid cleanupMaid : l) {
+                try {
+                    VirtualMachineMO vmMo = null;
+                    if(cleanupMaid.getDatacenterMorValue() != null) {
+                    	DatacenterMO dcMo = new DatacenterMO(context, "Datacenter", cleanupMaid.getDatacenterMorValue());
+                    	vmMo = dcMo.findVm(cleanupMaid.getVmName());
+                    } else {
+                    	assert(cleanupMaid.getHostMorValue() != null);
+                    	HostMO hostMo = new HostMO(context, "HostSystem", cleanupMaid.getHostMorValue());
+                    	ClusterMO clusterMo = new ClusterMO(context, hostMo.getHyperHostCluster());
+                    	vmMo = clusterMo.findVmOnHyperHost(cleanupMaid.getVmName());
+                    }
+                    
+                    if(vmMo != null) {
+                        s_logger.info("Found left over dummy VM " + cleanupMaid.getVmName() + ", destroy it");
+                        vmMo.destroy();
+                    }
+                } catch(Throwable e) {
+                    s_logger.warn("Unable to destroy left over dummy VM " + cleanupMaid.getVmName());
+                } finally {
+                	mgr.popCleanupCheckpoint(cleanupMaid.getCheckPoint());
+                }
+            }
+            
+            l.clear();
+        }
+    }
+}