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

[40/50] [abbrv] moving out VMWAre and Nexus VSM support code into plugins/hypervisors/vmware

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/8197f1f0/server/src/com/cloud/hypervisor/vmware/VmwareServerDiscoverer.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/hypervisor/vmware/VmwareServerDiscoverer.java b/server/src/com/cloud/hypervisor/vmware/VmwareServerDiscoverer.java
deleted file mode 100755
index 65a1068..0000000
--- a/server/src/com/cloud/hypervisor/vmware/VmwareServerDiscoverer.java
+++ /dev/null
@@ -1,364 +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.hypervisor.vmware;
-
-import java.net.URI;
-import java.net.URLDecoder;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-
-import javax.ejb.Local;
-import javax.naming.ConfigurationException;
-
-import org.apache.log4j.Logger;
-
-import com.cloud.agent.api.StartupCommand;
-import com.cloud.agent.api.StartupRoutingCommand;
-import com.cloud.alert.AlertManager;
-import com.cloud.configuration.dao.ConfigurationDao;
-import com.cloud.dc.ClusterDetailsDao;
-import com.cloud.dc.ClusterVO;
-import com.cloud.dc.DataCenter.NetworkType;
-import com.cloud.dc.DataCenterVO;
-import com.cloud.dc.dao.ClusterDao;
-import com.cloud.dc.dao.DataCenterDao;
-import com.cloud.exception.DiscoveredWithErrorException;
-import com.cloud.exception.DiscoveryException;
-import com.cloud.host.HostVO;
-import com.cloud.host.dao.HostDao;
-import com.cloud.hypervisor.Hypervisor;
-import com.cloud.hypervisor.Hypervisor.HypervisorType;
-import com.cloud.hypervisor.vmware.manager.VmwareManager;
-import com.cloud.hypervisor.vmware.mo.ClusterMO;
-import com.cloud.hypervisor.vmware.mo.HostMO;
-import com.cloud.hypervisor.vmware.resource.VmwareContextFactory;
-import com.cloud.hypervisor.vmware.resource.VmwareResource;
-import com.cloud.hypervisor.vmware.util.VmwareContext;
-import com.cloud.network.NetworkManager;
-import com.cloud.network.dao.CiscoNexusVSMDeviceDao;
-import com.cloud.resource.Discoverer;
-import com.cloud.resource.DiscovererBase;
-import com.cloud.resource.ResourceManager;
-import com.cloud.resource.ResourceStateAdapter;
-import com.cloud.resource.ServerResource;
-import com.cloud.resource.UnableDeleteHostException;
-import com.cloud.storage.Storage.ImageFormat;
-import com.cloud.storage.Storage.TemplateType;
-import com.cloud.storage.VMTemplateVO;
-import com.cloud.storage.dao.VMTemplateDao;
-import com.cloud.user.Account;
-import com.cloud.utils.UriUtils;
-import com.cloud.utils.component.ComponentLocator;
-import com.cloud.utils.component.Inject;
-import com.vmware.vim25.ClusterDasConfigInfo;
-import com.vmware.vim25.ManagedObjectReference;
-
-@Local(value=Discoverer.class)
-public class VmwareServerDiscoverer extends DiscovererBase implements Discoverer, ResourceStateAdapter {
-	private static final Logger s_logger = Logger.getLogger(VmwareServerDiscoverer.class);
-	
-	@Inject ClusterDao _clusterDao;
-	@Inject VmwareManager _vmwareMgr;
-    @Inject AlertManager _alertMgr;
-    @Inject VMTemplateDao _tmpltDao;
-    @Inject ClusterDetailsDao _clusterDetailsDao;
-    @Inject HostDao _hostDao;
-    @Inject
-    DataCenterDao _dcDao;
-    @Inject ResourceManager _resourceMgr;
-    @Inject CiscoNexusVSMDeviceDao _nexusDao;
-    @Inject
-    NetworkManager _netmgr;
-    
-    @Override
-    public Map<? extends ServerResource, Map<String, String>> find(long dcId, Long podId, Long clusterId, URI url, 
-    	String username, String password, List<String> hostTags) throws DiscoveryException {
-    	
-    	if(s_logger.isInfoEnabled())
-    		s_logger.info("Discover host. dc: " + dcId + ", pod: " + podId + ", cluster: " + clusterId + ", uri host: " + url.getHost());
-    	
-    	if(podId == null) {
-        	if(s_logger.isInfoEnabled())
-        		s_logger.info("No pod is assigned, assuming that it is not for vmware and skip it to next discoverer"); 
-    		return null;
-    	}
-    	
-        ClusterVO cluster = _clusterDao.findById(clusterId);
-        if(cluster == null || cluster.getHypervisorType() != HypervisorType.VMware) {
-        	if(s_logger.isInfoEnabled())
-        		s_logger.info("invalid cluster id or cluster is not for VMware hypervisors"); 
-    		return null;
-        }
-        
-        List<HostVO> hosts = _resourceMgr.listAllHostsInCluster(clusterId);
-        if(hosts.size() >= _vmwareMgr.getMaxHostsPerCluster()) {
-        	String msg = "VMware cluster " + cluster.getName() + " is too big to add new host now. (current configured cluster size: " + _vmwareMgr.getMaxHostsPerCluster() + ")";
-        	s_logger.error(msg);
-        	throw new DiscoveredWithErrorException(msg);
-        }
-
-        String privateTrafficLabel = null;
-        String publicTrafficLabel = null;
-        String guestTrafficLabel = null;
-        Map<String, String> vsmCredentials = null;
-        
-        privateTrafficLabel = _netmgr.getDefaultManagementTrafficLabel(dcId, HypervisorType.VMware);
-        if (privateTrafficLabel != null) {
-            s_logger.info("Detected private network label : " + privateTrafficLabel);
-        }
-        
-        if (_vmwareMgr.getNexusVSwitchGlobalParameter()) {
-            DataCenterVO zone = _dcDao.findById(dcId);
-            NetworkType zoneType = zone.getNetworkType();
-            if (zoneType != NetworkType.Basic) {
-                publicTrafficLabel = _netmgr.getDefaultPublicTrafficLabel(dcId, HypervisorType.VMware);
-                if (publicTrafficLabel != null) {
-                    s_logger.info("Detected public network label : " + publicTrafficLabel);
-                }
-            }
-            // Get physical network label
-            guestTrafficLabel = _netmgr.getDefaultGuestTrafficLabel(dcId, HypervisorType.VMware);
-            if (guestTrafficLabel != null) {
-                s_logger.info("Detected guest network label : " + guestTrafficLabel);
-            }
-            vsmCredentials = _vmwareMgr.getNexusVSMCredentialsByClusterId(clusterId);
-        }
-
-		VmwareContext context = null;
-		try {
-			context = VmwareContextFactory.create(url.getHost(), username, password);
-            if (privateTrafficLabel != null)
-                context.registerStockObject("privateTrafficLabel", privateTrafficLabel);
-			
-            if (_vmwareMgr.getNexusVSwitchGlobalParameter()) {
-                if (vsmCredentials != null) {
-                    s_logger.info("Stocking credentials of Nexus VSM");
-                    context.registerStockObject("vsmcredentials", vsmCredentials);
-                }
-            }
-			List<ManagedObjectReference> morHosts = _vmwareMgr.addHostToPodCluster(context, dcId, podId, clusterId,
-				URLDecoder.decode(url.getPath()));
-            if (morHosts == null)
-                s_logger.info("Found 0 hosts.");
-            if (privateTrafficLabel != null)
-                context.uregisterStockObject("privateTrafficLabel");
-
-			if(morHosts == null) {
-				s_logger.error("Unable to find host or cluster based on url: " + URLDecoder.decode(url.getPath()));
-				return null;
-			}
-			
-			ManagedObjectReference morCluster = null;
-			Map<String, String> clusterDetails = _clusterDetailsDao.findDetails(clusterId);
-			if(clusterDetails.get("url") != null) {
-				URI uriFromCluster = new URI(UriUtils.encodeURIComponent(clusterDetails.get("url")));
-				morCluster = context.getHostMorByPath(URLDecoder.decode(uriFromCluster.getPath()));
-				
-				if(morCluster == null || !morCluster.getType().equalsIgnoreCase("ClusterComputeResource")) {
-					s_logger.warn("Cluster url does not point to a valid vSphere cluster, url: " + clusterDetails.get("url"));
-					return null;
-				} else {
-					ClusterMO clusterMo = new ClusterMO(context, morCluster);
-					ClusterDasConfigInfo dasConfig = clusterMo.getDasConfig();
-					if(dasConfig != null && dasConfig.getEnabled() != null && dasConfig.getEnabled().booleanValue()) {
-						clusterDetails.put("NativeHA", "true");
-						_clusterDetailsDao.persist(clusterId, clusterDetails);
-					}
-				}
-			}
-			
-			if(!validateDiscoveredHosts(context, morCluster, morHosts)) {
-				if(morCluster == null)
-					s_logger.warn("The discovered host is not standalone host, can not be added to a standalone cluster");
-				else
-					s_logger.warn("The discovered host does not belong to the cluster");
-				return null;
-			}
-
-            Map<VmwareResource, Map<String, String>> resources = new HashMap<VmwareResource, Map<String, String>>();
-			for(ManagedObjectReference morHost : morHosts) {
-	            Map<String, String> details = new HashMap<String, String>();
-	            Map<String, Object> params = new HashMap<String, Object>();
-	            
-	            HostMO hostMo = new HostMO(context, morHost);
-	            details.put("url", hostMo.getHostName());
-	            details.put("username", username);
-	            details.put("password", password);
-	            String guid = morHost.getType() + ":" + morHost.get_value() + "@"+ url.getHost();
-	            details.put("guid", guid);
-	            
-	            params.put("url", hostMo.getHostName());
-	            params.put("username", username);
-	            params.put("password", password);
-	            params.put("zone", Long.toString(dcId));
-	            params.put("pod", Long.toString(podId));
-	            params.put("cluster", Long.toString(clusterId));
-	            params.put("guid", guid);
-                if (privateTrafficLabel != null) {
-                    params.put("private.network.vswitch.name", privateTrafficLabel);
-                }
-                if (publicTrafficLabel != null) {
-                    params.put("public.network.vswitch.name", publicTrafficLabel);
-                }
-                if (guestTrafficLabel != null) {
-                    params.put("guest.network.vswitch.name", guestTrafficLabel);
-                }
-	            
-	            VmwareResource resource = new VmwareResource(); 
-	            try {
-	                resource.configure("VMware", params);
-	            } catch (ConfigurationException e) {
-	                _alertMgr.sendAlert(AlertManager.ALERT_TYPE_HOST, dcId, podId, "Unable to add " + url.getHost(), "Error is " + e.getMessage());
-	                s_logger.warn("Unable to instantiate " + url.getHost(), e);
-	            }
-	            resource.start();
-	            
-	            resources.put(resource, details);
-			}
-            
-            // place a place holder guid derived from cluster ID
-            cluster.setGuid(UUID.nameUUIDFromBytes(String.valueOf(clusterId).getBytes()).toString());
-            _clusterDao.update(clusterId, cluster);
-            
-            return resources;
-		} catch (DiscoveredWithErrorException e) {
-			throw e;
-		} catch (Exception e) {
-			s_logger.warn("Unable to connect to Vmware vSphere server. service address: " + url.getHost());
-			return null;
-		} finally {
-			if(context != null)
-				context.close();
-		}
-    }
-    
-    private boolean validateDiscoveredHosts(VmwareContext context, ManagedObjectReference morCluster, List<ManagedObjectReference> morHosts) throws Exception {
-    	if(morCluster == null) {
-    		for(ManagedObjectReference morHost : morHosts) {
-    			ManagedObjectReference morParent = (ManagedObjectReference)context.getServiceUtil().getDynamicProperty(morHost, "parent");
-    			if(morParent.getType().equalsIgnoreCase("ClusterComputeResource"))
-    				return false;
-    		}
-    	} else {
-    		for(ManagedObjectReference morHost : morHosts) {
-    			ManagedObjectReference morParent = (ManagedObjectReference)context.getServiceUtil().getDynamicProperty(morHost, "parent");
-    			if(!morParent.getType().equalsIgnoreCase("ClusterComputeResource"))
-    				return false;
-    			
-    			if(!morParent.get_value().equals(morCluster.get_value()))
-    				return false;
-    		}
-    	}
-    	
-    	return true;
-    }
-    
-    @Override
-    public void postDiscovery(List<HostVO> hosts, long msId) {
-        // do nothing
-    }
-    
-    @Override
-	public boolean matchHypervisor(String hypervisor) {
-    	if(hypervisor == null)
-    		return true;
-    	
-    	return Hypervisor.HypervisorType.VMware.toString().equalsIgnoreCase(hypervisor);
-    }
-    
-    @Override
-	public Hypervisor.HypervisorType getHypervisorType() {
-    	return Hypervisor.HypervisorType.VMware;
-    }
-    
-    @Override
-    public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
-        if(s_logger.isInfoEnabled())
-        	s_logger.info("Configure VmwareServerDiscoverer, discover name: " + name);
-        
-        super.configure(name, params);
-        
-        ComponentLocator locator = ComponentLocator.getCurrentLocator();
-        ConfigurationDao configDao = locator.getDao(ConfigurationDao.class);
-        if (configDao == null) {
-            throw new ConfigurationException("Unable to get the configuration dao.");
-        }
-        
-        createVmwareToolsIso();
-
-		if(s_logger.isInfoEnabled()) {
-			s_logger.info("VmwareServerDiscoverer has been successfully configured");
-		}
-		_resourceMgr.registerResourceStateAdapter(this.getClass().getSimpleName(), this);
-        return true;
-    }
-    
-    private void createVmwareToolsIso() {
-        String isoName = "vmware-tools.iso";
-        VMTemplateVO tmplt = _tmpltDao.findByTemplateName(isoName);
-        Long id;
-        if (tmplt == null) {
-            id = _tmpltDao.getNextInSequence(Long.class, "id");
-            VMTemplateVO template = new VMTemplateVO(id, isoName, isoName, ImageFormat.ISO, true, true,
-                    TemplateType.PERHOST, null, null, true, 64,
-                    Account.ACCOUNT_ID_SYSTEM, null, "VMware Tools Installer ISO", false, 1, false, HypervisorType.VMware);
-            _tmpltDao.persist(template);
-        } else {
-            id = tmplt.getId();
-            tmplt.setTemplateType(TemplateType.PERHOST);
-            tmplt.setUrl(null);
-            _tmpltDao.update(id, tmplt);
-        }
-    }
-
-	@Override
-    public HostVO createHostVOForConnectedAgent(HostVO host, StartupCommand[] cmd) {
-	    // TODO Auto-generated method stub
-	    return null;
-    }
-
-	@Override
-    public HostVO createHostVOForDirectConnectAgent(HostVO host, StartupCommand[] startup, ServerResource resource, Map<String, String> details,
-            List<String> hostTags) {
-		StartupCommand firstCmd = startup[0];
-		if (!(firstCmd instanceof StartupRoutingCommand)) {
-			return null;
-		}
-
-		StartupRoutingCommand ssCmd = ((StartupRoutingCommand) firstCmd);
-		if (ssCmd.getHypervisorType() != HypervisorType.VMware) {
-			return null;
-		}
-
-		return _resourceMgr.fillRoutingHostVO(host, ssCmd, HypervisorType.VMware, details, hostTags);
-    }
-
-	@Override
-    public DeleteHostAnswer deleteHost(HostVO host, boolean isForced, boolean isForceDeleteStorage) throws UnableDeleteHostException {
-		if (host.getType() != com.cloud.host.Host.Type.Routing || host.getHypervisorType() != HypervisorType.VMware) {
-			return null;
-		}
-		
-		_resourceMgr.deleteRoutingHost(host, isForced, isForceDeleteStorage);
-		return new DeleteHostAnswer(true);
-    }
-	
-    @Override
-    public boolean stop() {
-    	_resourceMgr.unregisterResourceStateAdapter(this.getClass().getSimpleName());
-        return super.stop();
-    }
-}
-

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/8197f1f0/server/src/com/cloud/network/CiscoNexusVSMDeviceManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/CiscoNexusVSMDeviceManagerImpl.java b/server/src/com/cloud/network/CiscoNexusVSMDeviceManagerImpl.java
deleted file mode 100644
index e00564f..0000000
--- a/server/src/com/cloud/network/CiscoNexusVSMDeviceManagerImpl.java
+++ /dev/null
@@ -1,315 +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.network;
-
-import java.util.HashMap;
-
-import java.util.List;
-import java.util.Map;
-
-import org.apache.log4j.Logger;
-
-import com.cloud.agent.api.StartupCommand;
-import com.cloud.api.ApiConstants;
-import com.cloud.dc.ClusterDetailsDao;
-import com.cloud.dc.ClusterVO;
-import com.cloud.dc.ClusterVSMMapVO;
-import com.cloud.dc.dao.ClusterDao;
-import com.cloud.dc.dao.ClusterVSMMapDao;
-import com.cloud.exception.InvalidParameterValueException;
-import com.cloud.host.DetailVO;
-import com.cloud.host.Host;
-import com.cloud.host.HostVO;
-import com.cloud.host.dao.HostDetailsDao;
-import com.cloud.hypervisor.Hypervisor.HypervisorType;
-import com.cloud.hypervisor.vmware.manager.VmwareManager;
-import com.cloud.resource.ResourceManager;
-import com.cloud.utils.component.AdapterBase;
-import com.cloud.utils.component.Inject;
-import com.cloud.utils.db.DB;
-import com.cloud.utils.db.Transaction;
-import com.cloud.utils.exception.CloudRuntimeException;
-import com.cloud.network.dao.CiscoNexusVSMDeviceDao;
-import com.cloud.network.dao.PortProfileDao;
-import com.cloud.exception.ResourceInUseException;
-import com.cloud.utils.cisco.n1kv.vsm.NetconfHelper;
-
-public abstract class CiscoNexusVSMDeviceManagerImpl extends AdapterBase {
-
-	@Inject
-    CiscoNexusVSMDeviceDao _ciscoNexusVSMDeviceDao;    
-    @Inject
-    ClusterDao _clusterDao;
-    @Inject
-    ClusterVSMMapDao _clusterVSMDao;
-    @Inject
-    ResourceManager _resourceMgr;
-	@Inject
-	VmwareManager _vmwareMgr;
-    @Inject
-    ClusterDetailsDao _clusterDetailsDao;
-    @Inject
-    HostDetailsDao _hostDetailDao;
-    @Inject
-    PortProfileDao _ppDao;
-
-    
-    private static final org.apache.log4j.Logger s_logger = Logger.getLogger(ExternalLoadBalancerDeviceManagerImpl.class);
-    
-    @DB
-    //public CiscoNexusVSMDeviceVO addCiscoNexusVSM(long clusterId, String ipaddress, String username, String password, ServerResource resource, String vsmName) {
-    public CiscoNexusVSMDeviceVO addCiscoNexusVSM(long clusterId, String ipaddress, String username, String password, String vCenterIpaddr, String vCenterDcName) {
-
-    	// In this function, we associate this VSM with each host
-    	// in the clusterId specified.
-
-    	// First check if the cluster is of type vmware. If not,
-    	// throw an exception. VSMs are tightly integrated with vmware clusters.
-    	
-    	ClusterVO cluster = _clusterDao.findById(clusterId);
-    	if (cluster == null) {
-    		throw new InvalidParameterValueException("Cluster with specified ID not found!");
-    	}
-    	if (cluster.getHypervisorType() != HypervisorType.VMware) {
-    		InvalidParameterValueException ex = new InvalidParameterValueException("Cluster with specified id is not a VMWare hypervisor cluster");
-    		throw ex;
-    	}
-
-    	// Next, check if the cluster already has a VSM associated with it.
-    	// If so, throw an exception disallowing this operation. The user must first
-    	// delete the current VSM and then only attempt to add the new one.
-    	
-    	if (_clusterVSMDao.findByClusterId(clusterId) != null) {
-    		// We can't have two VSMs for the same cluster. Throw exception.
-    		throw new InvalidParameterValueException("Cluster with specified id already has a VSM tied to it. Please remove that first and retry the operation.");
-    	}
-
-    	// TODO: Confirm whether we should be checking for VSM reachability here.
-    	
-    	// Next, check if this VSM is reachable. Use the XML-RPC VSM API Java bindings to talk to
-    	// the VSM.
-    	//NetconfHelper (String ip, String username, String password)
-
-    	NetconfHelper netconfClient;
-    	try	{
-    		netconfClient = new NetconfHelper(ipaddress, username, password);	
-    	} catch(CloudRuntimeException e) {
-    		String msg = "Failed to connect to Nexus VSM " + ipaddress + " with credentials of user " + username;
-    		s_logger.error(msg);
-    		throw new CloudRuntimeException(msg);
-    	}
-
-    	// Disconnect from the VSM. A VSM has a default of 8 maximum parallel connections that it allows.
-    	netconfClient.disconnect();
-
-    	// Now, go ahead and associate the cluster with this VSM.
-    	// First, check if VSM already exists in the table "virtual_supervisor_module".
-    	// If it's not there already, create it.
-    	// If it's there already, return success.
-    	
-    	// TODO - Right now, we only check if the ipaddress matches for both requests.
-    	// We must really check whether every field of the VSM matches. Anyway, the
-    	// advantage of our approach for now is that existing infrastructure using
-    	// the existing VSM won't be affected if the new request to add the VSM
-    	// assumed different information on the VSM (mgmt vlan, username, password etc).
-    	CiscoNexusVSMDeviceVO VSMObj;
-    	try {
-    		VSMObj = _ciscoNexusVSMDeviceDao.getVSMbyIpaddress(ipaddress);
-    	} catch (Exception e) {
-    		throw new CloudRuntimeException(e.getMessage());
-    	}
-
-    	if (VSMObj == null) {    		
-    		// Create the VSM record. For now, we aren't using the vsmName field.
-    		VSMObj = new CiscoNexusVSMDeviceVO(ipaddress, username, password);
-    		Transaction txn = Transaction.currentTxn();
-    		try {
-   				txn.start();
-   	            _ciscoNexusVSMDeviceDao.persist(VSMObj);
-   	            txn.commit();
-    		} catch (Exception e) {
-    			txn.rollback();
-    			throw new CloudRuntimeException(e.getMessage());
-    		}
-    	}
-    	
-    	// At this stage, we have a VSM record for sure. Connect the VSM to the cluster Id.
-    	long vsmId = _ciscoNexusVSMDeviceDao.getVSMbyIpaddress(ipaddress).getId();
-    	ClusterVSMMapVO connectorObj = new ClusterVSMMapVO(clusterId, vsmId);
-    	Transaction txn = Transaction.currentTxn();
-    	try {
-    		txn.start();
-    		_clusterVSMDao.persist(connectorObj);
-    		txn.commit();
-    	} catch (Exception e) {
-    		txn.rollback();
-    		throw new CloudRuntimeException(e.getMessage());
-    	}
-    	
-    	// Now, get a list of all the ESXi servers in this cluster.
-    	// This is effectively a select * from host where cluster_id=clusterId;
-    	// All ESXi servers are stored in the host table, and their resource
-    	// type is vmwareresource.
-    	
-        //List<HostVO> hosts = _resourceMgr.listAllHostsInCluster(clusterId);
-        
-        //TODO: Activate the code below if we make the Nexus VSM a separate resource.
-        // Iterate through each of the hosts in this list. Each host has a host id.
-        // Given this host id, we can reconfigure the in-memory resource representing
-        // the host via the agent manager. Thus we inject VSM related information
-        // into each host's resource. Also, we first configure each resource's
-        // entries in the database to contain this VSM information before the injection.
-    	
-        //for (HostVO host : hosts) {        	
-        	// Create a host details VO object and write it out for this hostid.
-        	//Long hostid = new Long(vsmId);
-        	//DetailVO vsmDetail = new DetailVO(host.getId(), "vsmId", hostid.toString());
-        	//Transaction tx = Transaction.currentTxn();
-        	//try {
-        		//tx.start();
-        		//_hostDetailDao.persist(vsmDetail);
-        		//tx.commit();
-        	//} catch (Exception e) {
-        		//tx.rollback();
-        		//throw new CloudRuntimeException(e.getMessage());
-        	//}
-        //}
-        // Reconfigure the resource.
-        //Map hostDetails = new HashMap<String, String>();
-        //hostDetails.put(ApiConstants.ID, vsmId);
-        //hostDetails.put(ApiConstants.IP_ADDRESS, ipaddress);
-        //hostDetails.put(ApiConstants.USERNAME, username);
-        //hostDetails.put(ApiConstants.PASSWORD, password);
-        //_agentMrg.send(host.getId(), )
-        
-        return VSMObj;
-        
-    }
-    
-    @DB
-    public boolean deleteCiscoNexusVSM(long vsmId) throws ResourceInUseException {    	
-        CiscoNexusVSMDeviceVO cisconexusvsm = _ciscoNexusVSMDeviceDao.findById(vsmId);
-        if (cisconexusvsm == null) {
-        	// This entry is already not present. Return success.
-        	return true;
-        }
-        
-        // First, check whether this VSM is part of any non-empty cluster.
-        // Search ClusterVSMMap's table for a list of clusters using this vsmId.
-        
-        List<ClusterVSMMapVO> clusterList = _clusterVSMDao.listByVSMId(vsmId);
-        
-        if (clusterList != null) {        	
-        	for (ClusterVSMMapVO record : clusterList) {
-        		// If this cluster id has any hosts in it, fail this operation.
-        		Long clusterId = record.getClusterId();        		
-        		List<HostVO> hosts = _resourceMgr.listAllHostsInCluster(clusterId);
-        		if (hosts != null && hosts.size() > 0) {
-        			for (Host host: hosts) {
-        				if (host.getType() == Host.Type.Routing) {
-        					s_logger.info("Non-empty cluster with id" + clusterId + "still has a host that uses this VSM. Please empty the cluster first");
-                			throw new ResourceInUseException("Non-empty cluster with id" + clusterId + "still has a host that uses this VSM. Please empty the cluster first");
-        				}
-        			}        			
-        		}
-        	}
-        }
-        
-        // Iterate through the cluster list again, this time, delete the VSM.
-        Transaction txn = Transaction.currentTxn();
-        try {
-            txn.start();
-            // Remove the VSM entry in CiscoNexusVSMDeviceVO's table.            
-            _ciscoNexusVSMDeviceDao.remove(vsmId);
-            // Remove the current record as well from ClusterVSMMapVO's table.            
-            _clusterVSMDao.removeByVsmId(vsmId);
-            // There are no hosts at this stage in the cluster, so we don't need
-            // to notify any resources or remove host details.            
-            txn.commit();            
-        } catch (Exception e) {
-        	s_logger.info("Caught exception when trying to delete VSM record.." + e.getMessage());        	
-        	throw new CloudRuntimeException("Failed to delete VSM");
-        }        
-        return true;
-    }
-
-    @DB
-    public CiscoNexusVSMDeviceVO enableCiscoNexusVSM(long vsmId) {
-        CiscoNexusVSMDeviceVO cisconexusvsm = _ciscoNexusVSMDeviceDao.findById(vsmId);
-        if (cisconexusvsm == null) {
-        	throw new InvalidParameterValueException("Invalid vsm Id specified");        	
-        }
-        // Else, check if this db record shows that this VSM is enabled or not.
-        if (cisconexusvsm.getvsmDeviceState() == CiscoNexusVSMDeviceVO.VSMDeviceState.Disabled) {        
-        	// it's currently disabled. So change it to enabled and write it out to the db.
-        	cisconexusvsm.setVsmDeviceState(CiscoNexusVSMDeviceVO.VSMDeviceState.Enabled);
-        	Transaction txn = Transaction.currentTxn();
-        	try {
-        		txn.start();
-        		_ciscoNexusVSMDeviceDao.persist(cisconexusvsm);
-   	            txn.commit();
-    		} catch (Exception e) {
-    			txn.rollback();
-    			throw new CloudRuntimeException(e.getMessage());
-    		}
-    	}
-        
-        return cisconexusvsm;
-    }
-    
-    @DB    
-    public CiscoNexusVSMDeviceVO disableCiscoNexusVSM(long vsmId) {
-        CiscoNexusVSMDeviceVO cisconexusvsm = _ciscoNexusVSMDeviceDao.findById(vsmId);
-        if (cisconexusvsm == null) {
-        	throw new InvalidParameterValueException("Invalid vsm Id specified");        	
-        }
-        // Else, check if this db record shows that this VSM is enabled or not.
-        if (cisconexusvsm.getvsmDeviceState() == CiscoNexusVSMDeviceVO.VSMDeviceState.Enabled) {        
-        	// it's currently disabled. So change it to enabled and write it out to the db.
-        	cisconexusvsm.setVsmDeviceState(CiscoNexusVSMDeviceVO.VSMDeviceState.Disabled);
-        	Transaction txn = Transaction.currentTxn();
-        	try {
-        		txn.start();
-        		_ciscoNexusVSMDeviceDao.persist(cisconexusvsm);
-   	            txn.commit();
-    		} catch (Exception e) {
-    			txn.rollback();
-    			throw new CloudRuntimeException(e.getMessage());
-    		}
-    	}
-        
-        return cisconexusvsm;
-    }
-    
-    @DB
-    public CiscoNexusVSMDeviceVO getCiscoVSMbyVSMId(long vsmId) {
-    	return _ciscoNexusVSMDeviceDao.findById(vsmId);
-    }
-    
-    @DB
-    public CiscoNexusVSMDeviceVO getCiscoVSMbyClusId(long clusterId) {
-    	ClusterVSMMapVO mapVO = _clusterVSMDao.findByClusterId(clusterId);
-    	if (mapVO == null) {
-    		s_logger.info("Couldn't find a VSM associated with the specified cluster Id");
-    		return null;
-    	}
-    	// Else, pull out the VSM associated with the VSM id in mapVO.
-    	CiscoNexusVSMDeviceVO result = _ciscoNexusVSMDeviceDao.findById(mapVO.getVsmId());
-    	return result;
-    }
-    
-    public HostVO createHostVOForConnectedAgent(HostVO host, StartupCommand[] cmd) {
-        // TODO Auto-generated method stub
-        return null;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/8197f1f0/server/src/com/cloud/network/CiscoNexusVSMDeviceVO.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/CiscoNexusVSMDeviceVO.java b/server/src/com/cloud/network/CiscoNexusVSMDeviceVO.java
deleted file mode 100644
index 6165ec1..0000000
--- a/server/src/com/cloud/network/CiscoNexusVSMDeviceVO.java
+++ /dev/null
@@ -1,222 +0,0 @@
-/**
- *  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.network;
-
-import java.util.UUID;
-
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.GenerationType;
-import javax.persistence.Id;
-import javax.persistence.Table;
-
-import com.cloud.api.Identity;
-
-/**
- * CiscoNexusVSMDeviceVO contains information on external Cisco Nexus 1000v VSM devices added into a deployment.
- * This should be probably made as a more generic class so that we can handle multiple versions of Nexus VSMs
- * in future.
- */
-
-@Entity
-@Table(name="virtual_supervisor_module")
-public class CiscoNexusVSMDeviceVO implements CiscoNexusVSMDevice, Identity{
-	
-	// We need to know what properties a VSM has. Put them here.
-	
-    @Id
-    @GeneratedValue(strategy = GenerationType.IDENTITY)
-    @Column(name = "id")
-    private long id;
-
-    @Column(name="uuid")
-    private String uuid;
-
-    @Column(name = "host_id")
-    private long hostId;
-
-    @Column(name = "vsm_name")
-    private String vsmName;
-    
-    @Column(name = "username")
-    private String vsmUserName;
-    
-    @Column(name = "password")
-    private String vsmPassword;
-
-    @Column(name = "ipaddr")
-    private String ipaddr;
-    
-    @Column(name = "management_vlan")
-    private int managementVlan;
-
-    @Column(name = "control_vlan")
-    private int controlVlan;
-    
-    @Column(name = "packet_vlan")
-    private int packetVlan;
-    
-    @Column(name = "storage_vlan")
-    private int storageVlan;
-    
-    @Column(name = "vsm_domain_id")
-    private long vsmDomainId;
-    
-    @Column(name = "config_mode")
-    private VSMConfigMode vsmConfigMode;
-    
-    @Column(name = "config_state")
-    private VSMConfigState vsmConfigState;
-    
-    @Column(name = "vsm_device_state")
-    private VSMDeviceState vsmDeviceState;
-
-    // Accessor methods
-    public long getId() {
-        return id;
-    }
-
-    public String getvsmName() {
-    	return vsmName;
-    }
-    
-    public long getHostId() {
-        return hostId;
-    }
-    
-    public String getUserName() {
-    	return vsmUserName;
-    }
-    
-    public String getPassword() {
-    	return vsmPassword;
-    }
-
-    public String getipaddr() {
-    	return ipaddr;
-    }
-    
-    public int getManagementVlan() {
-    	return managementVlan;
-    }
-    
-    public int getControlVlan() {
-    	return controlVlan;
-    }
-    
-    public int getPacketVlan() {
-    	return packetVlan;
-    }  
-
-    public int getStorageVlan() {
-    	return storageVlan;
-    }
-    
-    public long getvsmDomainId() {
-    	return vsmDomainId;
-    }
-    
-    public VSMConfigMode getvsmConfigMode() {
-    	return vsmConfigMode;
-    }
-    
-    public VSMConfigState getvsmConfigState() {
-    	return vsmConfigState;
-    }
-    
-    public VSMDeviceState getvsmDeviceState() {
-    	return vsmDeviceState;
-    }
-    
-    public String getUuid() {
-        return uuid;
-    }
-    
-    // Setter methods
-
-    public void setHostId(long hostid) {
-        this.hostId = hostid;
-    }
-    
-    public void setVsmUserName(String username) {
-    	this.vsmUserName = username;
-    }
-    
-    public void setVsmName(String vsmName) {
-    	this.vsmName = vsmName;
-    }
-    
-    public void setVsmPassword(String password) {
-    	this.vsmPassword = password;
-    }
-
-    public void setMgmtIpAddr(String ipaddr) {
-    	this.ipaddr = ipaddr;
-    }
-    
-    public void setManagementVlan(int vlan) {
-    	this.managementVlan = vlan;
-    }
-    
-    public void setControlVlan(int vlan) {
-    	this.controlVlan = vlan;
-    }
-    
-    public void setPacketVlan(int vlan) {
-    	this.packetVlan = vlan;
-    }  
-
-    public void setStorageVlan(int vlan) {
-    	this.storageVlan = vlan;
-    }
-    
-    public void setVsmDomainId(long id) {
-    	this.vsmDomainId = id;
-    }
-    
-    public void setVsmConfigMode(VSMConfigMode mode) {
-    	this.vsmConfigMode = mode;
-    }
-    
-    public void setVsmConfigState(VSMConfigState state) {
-    	this.vsmConfigState = state;
-    }
-    
-    public void setVsmDeviceState(VSMDeviceState devState) {
-    	this.vsmDeviceState = devState;
-    }
- 
-        
-    // Constructors.
-    
-    public CiscoNexusVSMDeviceVO(String vsmIpAddr, String username, String password) {    	
-    	// Set all the VSM's properties here.
-        this.uuid = UUID.randomUUID().toString();
-        this.setMgmtIpAddr(vsmIpAddr);
-        this.setVsmUserName(username);
-        this.setVsmPassword(password);
-        this.setVsmName(vsmName);
-        this.setVsmDeviceState(VSMDeviceState.Enabled);
-    }
-    
-    public CiscoNexusVSMDeviceVO() {
-        this.uuid = UUID.randomUUID().toString();
-    }    
-}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/8197f1f0/server/src/com/cloud/network/dao/CiscoNexusVSMDeviceDao.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/dao/CiscoNexusVSMDeviceDao.java b/server/src/com/cloud/network/dao/CiscoNexusVSMDeviceDao.java
deleted file mode 100644
index 95771a5..0000000
--- a/server/src/com/cloud/network/dao/CiscoNexusVSMDeviceDao.java
+++ /dev/null
@@ -1,107 +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.network.dao;
-
-import java.util.List;
-import com.cloud.network.CiscoNexusVSMDeviceVO;
-import com.cloud.utils.db.GenericDao;
-
-public interface CiscoNexusVSMDeviceDao extends GenericDao<CiscoNexusVSMDeviceVO, Long> {
-
-    /**
-     * Return a Cisco Nexus VSM record given its switch domain Id. 
-     * @param Cisco Nexus VSM Switch Domain Id
-     * @return CiscoNexusVSMDeviceVO for the VSM having the specified switch domain Id.
-     */
-    CiscoNexusVSMDeviceVO getVSMbyDomainId(long domId);
-
-    /**
-     * Return a Cisco Nexus VSM VO (db record) given its name.
-     * @param vsmName
-     */
-    CiscoNexusVSMDeviceVO getVSMbyName(String vsmName);
-    
-    /**
-     * Return a Cisco Nexus VSM VO (db record) given its ipaddress.
-     * @param vsmIpaddr
-     */
-    CiscoNexusVSMDeviceVO getVSMbyIpaddress(String ipaddress);
-    
-    /**
-     * Return a list of VSM devices that use the same VLAN for no matter what interface. Unlikely, but oh well.
-     * @param vlanId
-     * 	- Needs to filter results by the invoker's account Id. So we may end up adding another param
-     *    or may query it in the function. 
-     * @return
-     */
-    List<CiscoNexusVSMDeviceVO> listByVlanId(int vlanId);
-    
-    /**
-     * Return a list of VSM devices that use the same VLAN for their mgmt interface. Again, unlikely, but we'll just keep it around.
-     * @param vlanId
-     * @return
-     */
-    List<CiscoNexusVSMDeviceVO> listByMgmtVlan(int vlanId);
-    
-    /**
-     * Lists all configured VSMs on the management server.
-     * @return
-     */
-    List<CiscoNexusVSMDeviceVO> listAllVSMs();
-    
-    
-    /**
-     * Below is a big list of other functions that we may need, but will declare/define/implement once we implement
-     * the functions above. Pasting those below to not lose track of them.
-     * 
-     *  	ListbyZoneId()
-		- Lists all VSMs in the specified zone.
-
-	ListbyAccountId()
-		- Lists all VSMs owned by the specified Account.
-
-	ListbyStorageVLAN(vlanId)
-		- Lists all VSMs whose storage VLAN matches the specified VLAN.
-			- Filters results by the invoker's account Id.
-
-	ListbyControlVLAN(vlanId)
-		- Lists all VSMs whose control VLAN matches the specified VLAN.
-			- Filters results by the invoker's account Id.
-
-	ListbyPacketVLAN(vlanId)
-		- Lists all VSMs whose Packet VLAN matches the specified VLAN.
-			- Filters results by the invoker's account Id.
-
-	ListbyConfigMode(mode)	
-		- Lists all VSMs which are currently configured in the specified mode (standalone/HA).
-			- Filters results by the invoker's account Id.
-
-	ListbyConfigState(configState)
-		- Lists all VSMs which are currently configured in the specified state (primary/standby).
-			- Filters results by the invoker's account Id.
-
-	ListbyDeviceState(deviceState)
-		- Lists all VSMs which are currently in the specified device state (enabled/disabled).
-			- Filters results by the invoker's account Id.
-
-
-	getBySwitchDomainId(domId)
-		- Retrieves the VSM with the specified switch domain Id. Each VSM has a unique switch domain Id, just like a real physical switch would.
-			- Filters results by invoker's account id.
-
-
-	getbySwitchName(vsmName)
-		- Retrieves the VSM's VO object by the specified vsmName.
-
-     */
-}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/8197f1f0/server/src/com/cloud/network/dao/CiscoNexusVSMDeviceDaoImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/dao/CiscoNexusVSMDeviceDaoImpl.java b/server/src/com/cloud/network/dao/CiscoNexusVSMDeviceDaoImpl.java
deleted file mode 100644
index 02d9e44..0000000
--- a/server/src/com/cloud/network/dao/CiscoNexusVSMDeviceDaoImpl.java
+++ /dev/null
@@ -1,108 +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.network.dao;
-
-import java.util.List;
-import javax.ejb.Local;
-
-import org.apache.log4j.Logger;
-
-import com.cloud.network.CiscoNexusVSMDeviceVO;
-import com.cloud.utils.db.DB;
-import com.cloud.utils.db.GenericDaoBase;
-import com.cloud.utils.db.SearchBuilder;
-import com.cloud.utils.db.SearchCriteria;
-import com.cloud.utils.db.SearchCriteria.Op;
-
-@Local(value=CiscoNexusVSMDeviceDao.class) @DB(txn=false)
-public class CiscoNexusVSMDeviceDaoImpl extends GenericDaoBase<CiscoNexusVSMDeviceVO, Long> implements CiscoNexusVSMDeviceDao {
-	protected static final Logger s_logger     = Logger.getLogger(CiscoNexusVSMDeviceDaoImpl.class);
-    final SearchBuilder<CiscoNexusVSMDeviceVO> mgmtVlanIdSearch;
-    final SearchBuilder<CiscoNexusVSMDeviceVO> domainIdSearch;
-    final SearchBuilder<CiscoNexusVSMDeviceVO> nameSearch;
-    final SearchBuilder<CiscoNexusVSMDeviceVO> ipaddrSearch;
-    final SearchBuilder<CiscoNexusVSMDeviceVO> genericVlanIdSearch;
-    final SearchBuilder<CiscoNexusVSMDeviceVO> fullTableSearch;
-    // We will add more searchbuilder objects.
-    
-    
-    public CiscoNexusVSMDeviceDaoImpl() {    	
-        super();
-        
-        mgmtVlanIdSearch = createSearchBuilder();
-        mgmtVlanIdSearch.and("managementVlan", mgmtVlanIdSearch.entity().getManagementVlan(), Op.EQ);
-        mgmtVlanIdSearch.done();
-        
-        genericVlanIdSearch = createSearchBuilder();
-        genericVlanIdSearch.and("managementVlan", genericVlanIdSearch.entity().getManagementVlan(), Op.EQ);
-        genericVlanIdSearch.or("controlVlan", genericVlanIdSearch.entity().getControlVlan(), Op.EQ);
-        genericVlanIdSearch.or("packetVlan", genericVlanIdSearch.entity().getPacketVlan(), Op.EQ);
-        genericVlanIdSearch.or("storageVlan", genericVlanIdSearch.entity().getStorageVlan(), Op.EQ);
-        genericVlanIdSearch.done();
-
-        domainIdSearch = createSearchBuilder();
-        domainIdSearch.and("vsmSwitchDomainId", domainIdSearch.entity().getvsmDomainId(), Op.EQ);
-        domainIdSearch.done();
-        
-        nameSearch = createSearchBuilder();
-        nameSearch.and("vsmName", nameSearch.entity().getvsmName(), Op.EQ);
-        nameSearch.done();
-        
-        ipaddrSearch = createSearchBuilder();
-        ipaddrSearch.and("ipaddr", ipaddrSearch.entity().getipaddr(), Op.EQ);
-        ipaddrSearch.done();
-        
-        fullTableSearch = createSearchBuilder();
-        fullTableSearch.done();
-        
-        // We may add more and conditions by specifying more fields, like say, accountId.
-    }
-    
-    public CiscoNexusVSMDeviceVO getVSMbyDomainId(long domId) {
-    	SearchCriteria<CiscoNexusVSMDeviceVO> sc = domainIdSearch.create();
-    	sc.setParameters("vsmSwitchDomainId", domId);
-    	return findOneBy(sc);
-    }
-    
-    public CiscoNexusVSMDeviceVO getVSMbyName(String vsmName) {
-    	SearchCriteria<CiscoNexusVSMDeviceVO> sc = nameSearch.create();
-    	sc.setParameters("vsmName", vsmName);
-    	return findOneBy(sc);
-    }
-    
-    public CiscoNexusVSMDeviceVO getVSMbyIpaddress(String ipaddress) {
-    	SearchCriteria<CiscoNexusVSMDeviceVO> sc = ipaddrSearch.create();
-    	sc.setParameters("ipaddr", ipaddress);
-    	return findOneBy(sc);
-    }
-    
-    public List<CiscoNexusVSMDeviceVO> listByMgmtVlan(int vlanId) {
-        SearchCriteria<CiscoNexusVSMDeviceVO> sc = mgmtVlanIdSearch.create();
-        sc.setParameters("managementVlan", vlanId);        
-        return search(sc, null);
-    }
-    
-    public List<CiscoNexusVSMDeviceVO> listAllVSMs() {
-    	SearchCriteria<CiscoNexusVSMDeviceVO> sc = fullTableSearch.create();
-    	return search(sc, null);
-    }
-
-    public List<CiscoNexusVSMDeviceVO> listByVlanId(int vlanId) {
-        SearchCriteria<CiscoNexusVSMDeviceVO> sc = genericVlanIdSearch.create();
-        sc.setParameters("managementVlan", vlanId);
-        sc.setParameters("storageVlan", vlanId);
-        sc.setParameters("packetVlan", vlanId);
-        sc.setParameters("controlVlan", vlanId);
-        return search(sc, null);
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/8197f1f0/server/src/com/cloud/network/element/CiscoNexusVSMElement.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/element/CiscoNexusVSMElement.java b/server/src/com/cloud/network/element/CiscoNexusVSMElement.java
deleted file mode 100644
index c57b664..0000000
--- a/server/src/com/cloud/network/element/CiscoNexusVSMElement.java
+++ /dev/null
@@ -1,238 +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.network.element;
-
-import java.util.List;
-import java.util.Map;
-import java.util.ArrayList;
-
-import javax.ejb.Local;
-
-import org.apache.log4j.Logger;
-
-import com.cloud.api.commands.DeleteCiscoNexusVSMCmd;
-import com.cloud.api.commands.EnableCiscoNexusVSMCmd;
-import com.cloud.api.commands.DisableCiscoNexusVSMCmd;
-import com.cloud.api.commands.ListCiscoNexusVSMsCmd;
-import com.cloud.api.response.CiscoNexusVSMResponse;
-import com.cloud.deploy.DeployDestination;
-import com.cloud.event.ActionEvent;
-import com.cloud.event.EventTypes;
-import com.cloud.exception.ConcurrentOperationException;
-import com.cloud.exception.InsufficientCapacityException;
-import com.cloud.exception.ResourceUnavailableException;
-import com.cloud.network.CiscoNexusVSMDeviceVO;
-import com.cloud.network.CiscoNexusVSMDevice;
-import com.cloud.network.CiscoNexusVSMDeviceManagerImpl;
-import com.cloud.network.Network;
-import com.cloud.network.PhysicalNetworkServiceProvider;
-import com.cloud.network.Network.Capability;
-import com.cloud.network.Network.Provider;
-import com.cloud.network.Network.Service;
-import com.cloud.network.dao.CiscoNexusVSMDeviceDao;
-import com.cloud.utils.component.Inject;
-import com.cloud.vm.NicProfile;
-import com.cloud.vm.ReservationContext;
-import com.cloud.vm.VirtualMachine;
-import com.cloud.vm.VirtualMachineProfile;
-import com.cloud.network.element.NetworkElement;
-import com.cloud.offering.NetworkOffering;
-import com.cloud.org.Cluster;
-import com.cloud.utils.component.Manager;
-import com.cloud.exception.ResourceInUseException;
-import com.cloud.utils.exception.CloudRuntimeException;
-import com.cloud.server.ManagementService;
-
-@Local(value = NetworkElement.class)
-public class CiscoNexusVSMElement extends CiscoNexusVSMDeviceManagerImpl implements CiscoNexusVSMElementService, NetworkElement, Manager {
-
-    private static final Logger s_logger = Logger.getLogger(CiscoNexusVSMElement.class);
-
-    @Inject
-    CiscoNexusVSMDeviceDao _vsmDao;    
-
-    @Override
-    public Map<Service, Map<Capability, String>> getCapabilities() {
-    	return null;
-    }
-    
-    @Override
-    public Provider getProvider() {
-        return null;
-    }
-    
-    @Override
-    public boolean implement(Network network, NetworkOffering offering,
-            DeployDestination dest, ReservationContext context)
-            throws ConcurrentOperationException, ResourceUnavailableException,
-            InsufficientCapacityException {
-        return true;
-    }
-    
-    @Override
-    public boolean prepare(Network network, NicProfile nic,
-            VirtualMachineProfile<? extends VirtualMachine> vm,
-            DeployDestination dest, ReservationContext context)
-            throws ConcurrentOperationException, ResourceUnavailableException,
-            InsufficientCapacityException {
-        return true;
-    }
-    
-    @Override
-    public boolean release(Network network, NicProfile nic,
-            VirtualMachineProfile<? extends VirtualMachine> vm,
-            ReservationContext context) throws ConcurrentOperationException,
-            ResourceUnavailableException {
-        return true;
-    }
-    
-    @Override
-    public boolean shutdown(Network network, ReservationContext context,
-    		boolean cleanup) throws ConcurrentOperationException,
-    		ResourceUnavailableException {
-        return true;
-    }
-
-    @Override
-    public boolean destroy(Network network)
-            throws ConcurrentOperationException, ResourceUnavailableException {
-        return true;
-    }
-    
-    @Override
-    public boolean isReady(PhysicalNetworkServiceProvider provider) {
-        return true;
-    }
-
-    @Override
-    public boolean shutdownProviderInstances(PhysicalNetworkServiceProvider provider,
-    		ReservationContext context) throws ConcurrentOperationException,
-    		ResourceUnavailableException {
-    	return true;
-    }
-    
-    @Override
-    public boolean canEnableIndividualServices() {
-    	return true;
-    }
-    
-    @Override
-    public boolean verifyServicesCombination(List<String> services) {
-    	return true;
-    }
-
-    @Override
-    @ActionEvent(eventType = EventTypes.EVENT_EXTERNAL_SWITCH_MGMT_DEVICE_DELETE, eventDescription = "deleting VSM", async = true)   
-    public boolean deleteCiscoNexusVSM(DeleteCiscoNexusVSMCmd cmd) {
-    	boolean result;
-    	try {
-    		result = deleteCiscoNexusVSM(cmd.getCiscoNexusVSMDeviceId());
-    	} catch (ResourceInUseException e) {
-    		s_logger.info("VSM could not be deleted");
-    		// TODO: Throw a better exception here.
-    		throw new CloudRuntimeException("Failed to delete specified VSM");
-    	}
-    	return result;
-    }    
-
-    @Override
-    @ActionEvent(eventType = EventTypes.EVENT_EXTERNAL_SWITCH_MGMT_DEVICE_ENABLE, eventDescription = "deleting VSM", async = true)  
-    public CiscoNexusVSMDeviceVO enableCiscoNexusVSM(EnableCiscoNexusVSMCmd cmd) {
-    	CiscoNexusVSMDeviceVO result;
-    	result = enableCiscoNexusVSM(cmd.getCiscoNexusVSMDeviceId());
-    	return result;
-    }
-    
-    @Override
-    @ActionEvent(eventType = EventTypes.EVENT_EXTERNAL_SWITCH_MGMT_DEVICE_DISABLE, eventDescription = "deleting VSM", async = true)
-    public CiscoNexusVSMDeviceVO disableCiscoNexusVSM(DisableCiscoNexusVSMCmd cmd) {
-    	CiscoNexusVSMDeviceVO result;
-    	result = disableCiscoNexusVSM(cmd.getCiscoNexusVSMDeviceId());
-    	return result;
-    }
-    
-    @Override
-    public List<CiscoNexusVSMDeviceVO> getCiscoNexusVSMs(ListCiscoNexusVSMsCmd cmd) {
-    	// If clusterId is defined, then it takes precedence, and we will return
-    	// the VSM associated with this cluster.    	
-
-    	Long clusterId = cmd.getClusterId();
-    	Long zoneId = cmd.getZoneId();
-    	List<CiscoNexusVSMDeviceVO> result = new ArrayList<CiscoNexusVSMDeviceVO>();
-    	if (clusterId != null && clusterId.longValue() != 0) {    		
-    		// Find the VSM associated with this clusterId and return a list.
-    		CiscoNexusVSMDeviceVO vsm = getCiscoVSMbyClusId(cmd.getClusterId());
-    		if (vsm == null) {
-        		throw new CloudRuntimeException("No Cisco VSM associated with specified Cluster Id");
-        	}
-    		// Else, add it to a list and return the list.
-    		result.add(vsm);
-    		return result;
-    	}    	
-    	// Else if there is only a zoneId defined, get a list of all vmware clusters
-    	// in the zone, and then for each cluster, pull the VSM and prepare a list.
-    	if (zoneId != null && zoneId.longValue() != 0) {
-    		ManagementService ref = cmd.getMgmtServiceRef();    	
-    		List<? extends Cluster> clusterList = ref.searchForClusters(zoneId, cmd.getStartIndex(), cmd.getPageSizeVal(), "VMware");
-    	
-    		if (clusterList.size() == 0) {
-    			throw new CloudRuntimeException("No VMWare clusters found in the specified zone!");
-    		}
-    		// Else, iterate through each vmware cluster, pull its VSM if it has one, and add to the list.
-    		for (Cluster clus : clusterList) {
-    			CiscoNexusVSMDeviceVO vsm = getCiscoVSMbyClusId(clus.getId());
-    			if (vsm != null)
-    				result.add(vsm);
-    		}
-    		return result;
-    	}
-    	
-    	// If neither is defined, we will simply return the entire list of VSMs
-    	// configured in the management server.
-    	// TODO: Is this a safe thing to do? Only ROOT admin can invoke this call.
-    	result = _vsmDao.listAllVSMs();    	
-    	return result;
-    }
-    
-    @Override
-    public CiscoNexusVSMResponse createCiscoNexusVSMResponse(CiscoNexusVSMDevice vsmDeviceVO) {
-            CiscoNexusVSMResponse response = new CiscoNexusVSMResponse();
-            response.setId(vsmDeviceVO.getId());            
-            response.setMgmtIpAddress(vsmDeviceVO.getipaddr());
-            return response;
-        }
-    
-    public CiscoNexusVSMResponse createCiscoNexusVSMDetailedResponse(CiscoNexusVSMDevice vsmDeviceVO) {
-    	CiscoNexusVSMResponse response = new CiscoNexusVSMResponse();
-    	response.setId(vsmDeviceVO.getId());
-    	response.setDeviceName(vsmDeviceVO.getvsmName());
-    	response.setDeviceState(vsmDeviceVO.getvsmDeviceState().toString());    	
-    	response.setMgmtIpAddress(vsmDeviceVO.getipaddr());
-    	// The following values can be null, so check for that.
-    	if(vsmDeviceVO.getvsmConfigMode() != null)
-    		response.setVSMConfigMode(vsmDeviceVO.getvsmConfigMode().toString());
-    	if(vsmDeviceVO.getvsmConfigState() != null)
-    		response.setVSMConfigState(vsmDeviceVO.getvsmConfigState().toString());
-    	if(vsmDeviceVO.getvsmDeviceState() != null)
-    		response.setVSMDeviceState(vsmDeviceVO.getvsmDeviceState().toString());
-    	response.setVSMCtrlVlanId(vsmDeviceVO.getManagementVlan());
-    	response.setVSMPktVlanId(vsmDeviceVO.getPacketVlan());
-    	response.setVSMStorageVlanId(vsmDeviceVO.getStorageVlan());
-    	return response;
-    }
-
-    @Override
-    public String getPropertiesFile() {
-    	return "cisconexusvsm_commands.properties";
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/8197f1f0/server/src/com/cloud/network/element/CiscoNexusVSMElementService.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/element/CiscoNexusVSMElementService.java b/server/src/com/cloud/network/element/CiscoNexusVSMElementService.java
deleted file mode 100644
index d462e99..0000000
--- a/server/src/com/cloud/network/element/CiscoNexusVSMElementService.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/**
- *  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.network.element;
-
-import java.util.List;
-
-import com.cloud.api.commands.DeleteCiscoNexusVSMCmd;
-import com.cloud.api.commands.EnableCiscoNexusVSMCmd;
-import com.cloud.api.commands.DisableCiscoNexusVSMCmd;
-import com.cloud.api.commands.ListCiscoNexusVSMsCmd;
-import com.cloud.api.response.CiscoNexusVSMResponse;
-import com.cloud.network.CiscoNexusVSMDeviceVO;
-import com.cloud.network.CiscoNexusVSMDevice;
-import com.cloud.utils.component.PluggableService;
-
-public interface CiscoNexusVSMElementService extends PluggableService {
-    /**
-     * removes a Cisco Nexus VSM
-     * @param DeleteCiscoNexusVSMCmd 
-     * @return true if VSM is deleted successfully
-     */
-    public boolean deleteCiscoNexusVSM(DeleteCiscoNexusVSMCmd cmd);
-
-    /**
-     * Enables a Cisco Nexus VSM. 
-     */
-    public CiscoNexusVSMDeviceVO enableCiscoNexusVSM(EnableCiscoNexusVSMCmd cmd);
-    
-    
-    /**
-     * Disables a Cisco Nexus VSM.
-     */
-    public CiscoNexusVSMDeviceVO disableCiscoNexusVSM(DisableCiscoNexusVSMCmd cmd);
-    
-    /**
-     * Returns a list of VSMs.
-     * @param ListCiscoNexusVSMsCmd
-     * @return List<CiscoNexusVSMDeviceVO>
-     */
-    public List<CiscoNexusVSMDeviceVO> getCiscoNexusVSMs(ListCiscoNexusVSMsCmd cmd);
-    
-    /**
-     * creates API response object for Cisco Nexus VSMs
-     * @param vsmDeviceVO VSM VO object
-     * @return CiscoNexusVSMResponse
-     */
-    
-    public CiscoNexusVSMResponse createCiscoNexusVSMResponse(CiscoNexusVSMDevice vsmDeviceVO);
-    
-    /**
-     * Creates a detailed API response object for Cisco Nexus VSMs
-     * @param CiscoNexusVSMDeviceVO
-     * @return CiscoNexusVSMResponse
-     */
-    public CiscoNexusVSMResponse createCiscoNexusVSMDetailedResponse(CiscoNexusVSMDevice vsmDeviceVO);
-}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/8197f1f0/server/src/com/cloud/resource/ResourceManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/resource/ResourceManagerImpl.java b/server/src/com/cloud/resource/ResourceManagerImpl.java
index 423e6df..73935f1 100755
--- a/server/src/com/cloud/resource/ResourceManagerImpl.java
+++ b/server/src/com/cloud/resource/ResourceManagerImpl.java
@@ -95,9 +95,7 @@ import com.cloud.host.dao.HostTagsDao;
 import com.cloud.hypervisor.Hypervisor;
 import com.cloud.hypervisor.Hypervisor.HypervisorType;
 import com.cloud.hypervisor.kvm.resource.KvmDummyResourceBase;
-import com.cloud.network.CiscoNexusVSMDeviceVO;
 import com.cloud.network.IPAddressVO;
-import com.cloud.network.dao.CiscoNexusVSMDeviceDao;
 import com.cloud.network.dao.IPAddressDao;
 import com.cloud.org.Cluster;
 import com.cloud.org.Grouping;
@@ -173,10 +171,6 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma
     @Inject
     protected ClusterDao                     _clusterDao;
     @Inject
-    protected ClusterVSMMapDao _clusterVSMDao;
-    @Inject
-    protected CiscoNexusVSMDeviceDao _vsmDao;
-    @Inject
     protected CapacityDao 					 _capacityDao;
     @Inject
     protected HostDao                        _hostDao;
@@ -434,95 +428,6 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma
         clusterId = cluster.getId();
         result.add(cluster);
 
-        // Check if we're associating a Cisco Nexus VSM with a vmware cluster.
-        if (hypervisorType == HypervisorType.VMware &&
-                Boolean.parseBoolean(_configDao.getValue(Config.VmwareUseNexusVSwitch.toString()))) {
-            String vsmIp = cmd.getVSMIpaddress();
-            String vsmUser = cmd.getVSMUsername();
-            String vsmPassword = cmd.getVSMPassword();
-
-            if(vsmIp != null && vsmUser != null && vsmPassword != null) {
-                NetconfHelper netconfClient;
-                try {
-                    netconfClient = new NetconfHelper(vsmIp, vsmUser, vsmPassword);
-                    netconfClient.disconnect();
-                } catch (CloudRuntimeException e) {
-                    String msg = "Invalid credentials supplied for user " + vsmUser + " for Cisco Nexus 1000v VSM at " + vsmIp;
-                    s_logger.error(msg);
-                    _clusterDao.remove(clusterId);
-                    throw new CloudRuntimeException(msg);
-                }
-
-                Transaction txn;
-
-                // If VSM already exists and is mapped to a cluster, fail this operation.
-                CiscoNexusVSMDeviceVO vsm = _vsmDao.getVSMbyIpaddress(vsmIp);
-                if(vsm != null) {
-                    List<ClusterVSMMapVO> clusterList = _clusterVSMDao.listByVSMId(vsm.getId());
-                    if (clusterList != null && !clusterList.isEmpty()) {
-                        s_logger.error("Failed to add cluster: specified Nexus VSM is already associated with another cluster");
-                        _clusterDao.remove(clusterId);
-                        ResourceInUseException ex = new ResourceInUseException("Failed to add cluster: specified Nexus VSM is already associated with another cluster with specified Id");
-                        ex.addProxyObject("cluster", clusterList.get(0).getClusterId(), "clusterId");
-                        throw ex;
-                    }
-                }
-                // persist credentials to database if the VSM entry is not already in the db.
-                if (_vsmDao.getVSMbyIpaddress(vsmIp) == null) {
-                    vsm = new CiscoNexusVSMDeviceVO(vsmIp, vsmUser, vsmPassword);
-                    txn = Transaction.currentTxn();
-                    try {
-                        txn.start();
-                        vsm = _vsmDao.persist(vsm);
-                        txn.commit();
-                    } catch (Exception e) {
-                        txn.rollback();
-                        s_logger.error("Failed to persist Cisco Nexus 1000v VSM details to database. Exception: " + e.getMessage());
-                        // Removing the cluster record which was added already because the persistence of Nexus VSM credentials has failed.
-                        _clusterDao.remove(clusterId);
-                        throw new CloudRuntimeException(e.getMessage());
-                    }
-                }
-                // Create a mapping between the cluster and the vsm.
-                vsm = _vsmDao.getVSMbyIpaddress(vsmIp);
-                if (vsm != null) {
-                    ClusterVSMMapVO connectorObj = new ClusterVSMMapVO(clusterId, vsm.getId());
-                    txn = Transaction.currentTxn();
-                    try {
-                        txn.start();
-                        _clusterVSMDao.persist(connectorObj);
-                        txn.commit();
-                    } catch (Exception e) {
-                        txn.rollback();
-                        s_logger.error("Failed to associate Cisco Nexus 1000v VSM with cluster: " + clusterName + ". Exception: " + e.getMessage());
-                        _clusterDao.remove(clusterId);
-                        throw new CloudRuntimeException(e.getMessage());
-                    }
-                }
-            } else {
-                String msg;
-                msg = "The global parameter " + Config.VmwareUseNexusVSwitch.toString() +
-                        " is set to \"true\". Following mandatory parameters are not specified. ";
-                if(vsmIp == null) {
-                    msg += "vsmipaddress: Management IP address of Cisco Nexus 1000v dvSwitch. ";
-                }
-                if(vsmUser == null) {
-                    msg += "vsmusername: Name of a user account with admin privileges over Cisco Nexus 1000v dvSwitch. ";
-                }
-                if(vsmPassword == null) {
-                    if(vsmUser != null) {
-                        msg += "vsmpassword: Password of user account " + vsmUser + ". ";
-                    } else {
-                        msg += "vsmpassword: Password of user account with admin privileges over Cisco Nexus 1000v dvSwitch. ";
-                    }
-                }
-                s_logger.error(msg);
-                // Cleaning up the cluster record as addCluster operation failed because Nexus dvSwitch credentials are supplied.
-                _clusterDao.remove(clusterId);
-                throw new CloudRuntimeException(msg);
-            }
-        }
-
         if (clusterType == Cluster.ClusterType.CloudManaged) {
             return result;
         }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/8197f1f0/utils/src/com/cloud/utils/ssh/SshHelper.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/ssh/SshHelper.java b/utils/src/com/cloud/utils/ssh/SshHelper.java
new file mode 100755
index 0000000..f29b368
--- /dev/null
+++ b/utils/src/com/cloud/utils/ssh/SshHelper.java
@@ -0,0 +1,201 @@
+// 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.utils.ssh;
+
+import java.io.File;
+import java.io.InputStream;
+
+import org.apache.log4j.Logger;
+
+import com.cloud.utils.Pair;
+import com.trilead.ssh2.ChannelCondition;
+
+public class SshHelper {
+	private static int DEFAULT_CONNECT_TIMEOUT = 60000;
+	private static int DEFAULT_KEX_TIMEOUT = 60000;
+	
+	private static final Logger s_logger = Logger.getLogger(SshHelper.class);
+	
+	public static Pair<Boolean, String> sshExecute(String host, int port, String user, File pemKeyFile, String password, String command) 
+		throws Exception {
+	
+		return sshExecute(host, port, user, pemKeyFile, password, command, 60000, 60000, 120000);
+	}
+	
+	public static void scpTo(String host, int port, String user, File pemKeyFile, String password, String remoteTargetDirectory, 
+		String localFile, String fileMode) throws Exception {
+		
+		scpTo(host, port, user, pemKeyFile, password, remoteTargetDirectory, localFile, fileMode, 
+			DEFAULT_CONNECT_TIMEOUT, DEFAULT_KEX_TIMEOUT);
+	}
+	
+	public static void scpTo(String host, int port, String user, File pemKeyFile, String password, String remoteTargetDirectory, 
+		byte[] data, String remoteFileName, String fileMode) throws Exception {
+		
+		scpTo(host, port, user, pemKeyFile, password, remoteTargetDirectory, data, remoteFileName, fileMode, 
+			DEFAULT_CONNECT_TIMEOUT, DEFAULT_KEX_TIMEOUT);
+	}
+	
+	public static void scpTo(String host, int port, String user, File pemKeyFile, String password, String remoteTargetDirectory, 
+		String localFile, String fileMode, int connectTimeoutInMs, int kexTimeoutInMs) throws Exception {
+		
+		com.trilead.ssh2.Connection conn = null;
+		com.trilead.ssh2.SCPClient scpClient = null;
+		
+		try {
+			conn = new com.trilead.ssh2.Connection(host, port);
+			conn.connect(null, connectTimeoutInMs, kexTimeoutInMs);
+			
+			if(pemKeyFile == null) {
+				if(!conn.authenticateWithPassword(user, password)) {
+					String msg = "Failed to authentication SSH user " + user + " on host " + host;
+					s_logger.error(msg);
+					throw new Exception(msg);
+				}
+			} else {
+				if(!conn.authenticateWithPublicKey(user, pemKeyFile, password)) {
+					String msg = "Failed to authentication SSH user " + user + " on host " + host;
+					s_logger.error(msg);
+					throw new Exception(msg);
+				}
+			}
+			
+			scpClient = conn.createSCPClient();
+			
+			if(fileMode != null)
+				scpClient.put(localFile, remoteTargetDirectory, fileMode);
+			else
+				scpClient.put(localFile, remoteTargetDirectory);
+		} finally {
+			if(conn != null)
+				conn.close();
+		}
+	}
+	
+	public static void scpTo(String host, int port, String user, File pemKeyFile, String password, String remoteTargetDirectory, 
+		byte[] data, String remoteFileName, String fileMode, int connectTimeoutInMs, int kexTimeoutInMs) throws Exception {
+		
+		com.trilead.ssh2.Connection conn = null;
+		com.trilead.ssh2.SCPClient scpClient = null;
+		
+		try {
+			conn = new com.trilead.ssh2.Connection(host, port);
+			conn.connect(null, connectTimeoutInMs, kexTimeoutInMs);
+			
+			if(pemKeyFile == null) {
+				if(!conn.authenticateWithPassword(user, password)) {
+					String msg = "Failed to authentication SSH user " + user + " on host " + host;
+					s_logger.error(msg);
+					throw new Exception(msg);
+				}
+			} else {
+				if(!conn.authenticateWithPublicKey(user, pemKeyFile, password)) {
+					String msg = "Failed to authentication SSH user " + user + " on host " + host;
+					s_logger.error(msg);
+					throw new Exception(msg);
+				}
+			}
+			
+			scpClient = conn.createSCPClient();
+			if(fileMode != null)
+				scpClient.put(data, remoteFileName, remoteTargetDirectory, fileMode);
+			else
+				scpClient.put(data, remoteFileName, remoteTargetDirectory);
+		} finally {
+			if(conn != null)
+				conn.close();
+		}
+	}
+	
+	public static Pair<Boolean, String> sshExecute(String host, int port, String user, File pemKeyFile, String password, String command, 
+		int connectTimeoutInMs, int kexTimeoutInMs, int waitResultTimeoutInMs) throws Exception {
+		
+		com.trilead.ssh2.Connection conn = null;
+		com.trilead.ssh2.Session sess = null; 
+		try {
+			conn = new com.trilead.ssh2.Connection(host, port);
+			conn.connect(null, connectTimeoutInMs, kexTimeoutInMs);
+
+			if(pemKeyFile == null) {
+				if(!conn.authenticateWithPassword(user, password)) {
+					String msg = "Failed to authentication SSH user " + user + " on host " + host;
+					s_logger.error(msg);
+					throw new Exception(msg);
+				}
+			} else {
+				if(!conn.authenticateWithPublicKey(user, pemKeyFile, password)) {
+					String msg = "Failed to authentication SSH user " + user + " on host " + host;
+					s_logger.error(msg);
+					throw new Exception(msg);
+				}
+			}
+			sess = conn.openSession();
+			
+			// There is a bug in Trilead library, wait a second before
+			// starting a shell and executing commands, from http://spci.st.ewi.tudelft.nl/chiron/xref/nl/tudelft/swerl/util/SSHConnection.html
+			Thread.sleep(1000);
+			
+			sess.execCommand(command);
+			
+			InputStream stdout = sess.getStdout();
+			InputStream stderr = sess.getStderr();
+	
+            byte[] buffer = new byte[8192];
+            StringBuffer sbResult = new StringBuffer();
+            
+            int currentReadBytes = 0;
+            while (true) {
+                if ((stdout.available() == 0) && (stderr.available() == 0)) {
+                    int conditions = sess.waitForCondition(ChannelCondition.STDOUT_DATA | ChannelCondition.STDERR_DATA | ChannelCondition.EOF, 
+                        waitResultTimeoutInMs);
+                    
+                    if ((conditions & ChannelCondition.TIMEOUT) != 0) {
+                        String msg = "Timed out in waiting SSH execution result";
+                        s_logger.error(msg);
+                        throw new Exception(msg);
+                    }
+
+                    if ((conditions & ChannelCondition.EOF) != 0) {
+                        if ((conditions & (ChannelCondition.STDOUT_DATA | ChannelCondition.STDERR_DATA)) == 0) {                            
+                            break;
+                        }
+                    }
+                }
+                            
+                while (stdout.available() > 0) {
+                    currentReadBytes = stdout.read(buffer);
+                    sbResult.append(new String(buffer, 0, currentReadBytes));
+                }
+            
+                while (stderr.available() > 0) {
+                    currentReadBytes = stderr.read(buffer);
+                    sbResult.append(new String(buffer, 0, currentReadBytes));
+                }
+            }
+            
+            String result = sbResult.toString();
+            if (sess.getExitStatus() != null && sess.getExitStatus().intValue() != 0) {
+                s_logger.error("SSH execution of command " + command + " has an error status code in return. result output: " + result);
+                return new Pair<Boolean, String>(false, result);
+            }
+            
+            return new Pair<Boolean, String>(true, result);
+		} finally {
+			if(sess != null)
+				sess.close();
+			
+			if(conn != null)
+				conn.close();
+		}
+	}
+}