You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by bh...@apache.org on 2016/12/07 18:36:48 UTC

[09/13] git commit: updated refs/heads/master to 0e057ad

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4c91c9c5/plugins/network-elements/nuage-vsp/src/com/cloud/network/manager/NuageVspManagerImpl.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nuage-vsp/src/com/cloud/network/manager/NuageVspManagerImpl.java b/plugins/network-elements/nuage-vsp/src/com/cloud/network/manager/NuageVspManagerImpl.java
index 7bc36e2..3a90163 100644
--- a/plugins/network-elements/nuage-vsp/src/com/cloud/network/manager/NuageVspManagerImpl.java
+++ b/plugins/network-elements/nuage-vsp/src/com/cloud/network/manager/NuageVspManagerImpl.java
@@ -19,6 +19,49 @@
 
 package com.cloud.network.manager;
 
+import static com.cloud.agent.api.sync.SyncNuageVspCmsIdCommand.SyncType;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.ExecutionException;
+
+import javax.inject.Inject;
+import javax.naming.ConfigurationException;
+
+import net.nuage.vsp.acs.client.api.NuageVspPluginClientLoader;
+import net.nuage.vsp.acs.client.api.model.VspApiDefaults;
+import net.nuage.vsp.acs.client.api.model.VspDomain;
+import net.nuage.vsp.acs.client.api.model.VspDomainCleanUp;
+import net.nuage.vsp.acs.client.api.model.VspHost;
+import net.nuage.vsp.acs.client.common.NuageVspApiVersion;
+import net.nuage.vsp.acs.client.common.NuageVspConstants;
+
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.log4j.Logger;
+
+import com.google.common.base.MoreObjects;
+import com.google.common.base.Strings;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
+
+import org.apache.cloudstack.api.ResponseGenerator;
+import org.apache.cloudstack.framework.config.ConfigKey;
+import org.apache.cloudstack.framework.config.Configurable;
+import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
+import org.apache.cloudstack.framework.config.impl.ConfigurationVO;
+import org.apache.cloudstack.framework.messagebus.MessageBus;
+import org.apache.cloudstack.framework.messagebus.MessageSubscriber;
+import org.apache.cloudstack.network.ExternalNetworkDeviceManager;
+
 import com.cloud.agent.AgentManager;
 import com.cloud.agent.Listener;
 import com.cloud.agent.api.AgentControlAnswer;
@@ -27,11 +70,12 @@ import com.cloud.agent.api.Answer;
 import com.cloud.agent.api.Command;
 import com.cloud.agent.api.PingNuageVspCommand;
 import com.cloud.agent.api.StartupCommand;
+import com.cloud.agent.api.manager.CleanUpDomainCommand;
 import com.cloud.agent.api.manager.EntityExistsCommand;
 import com.cloud.agent.api.manager.GetApiDefaultsAnswer;
 import com.cloud.agent.api.manager.GetApiDefaultsCommand;
 import com.cloud.agent.api.manager.SupportedApiVersionCommand;
-import com.cloud.agent.api.sync.SyncDomainAnswer;
+import com.cloud.agent.api.manager.UpdateNuageVspDeviceCommand;
 import com.cloud.agent.api.sync.SyncDomainCommand;
 import com.cloud.agent.api.sync.SyncNuageVspCmsIdAnswer;
 import com.cloud.agent.api.sync.SyncNuageVspCmsIdCommand;
@@ -79,6 +123,7 @@ import com.cloud.network.dao.PhysicalNetworkServiceProviderDao;
 import com.cloud.network.dao.PhysicalNetworkServiceProviderVO;
 import com.cloud.network.dao.PhysicalNetworkVO;
 import com.cloud.network.resource.NuageVspResource;
+import com.cloud.network.resource.NuageVspResourceConfiguration;
 import com.cloud.network.vpc.VpcManager;
 import com.cloud.network.vpc.VpcOffering;
 import com.cloud.network.vpc.VpcOfferingServiceMapVO;
@@ -96,6 +141,7 @@ import com.cloud.resource.ResourceManager;
 import com.cloud.resource.ResourceState;
 import com.cloud.user.AccountManager;
 import com.cloud.user.DomainManager;
+import com.cloud.util.NuageVspEntityBuilder;
 import com.cloud.util.NuageVspUtil;
 import com.cloud.utils.component.ManagerBase;
 import com.cloud.utils.db.DB;
@@ -106,41 +152,6 @@ import com.cloud.utils.db.TransactionStatus;
 import com.cloud.utils.exception.CloudRuntimeException;
 import com.cloud.utils.fsm.StateListener;
 import com.cloud.utils.fsm.StateMachine2;
-import com.google.common.base.Joiner;
-import com.google.common.base.MoreObjects;
-import com.google.common.base.Strings;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Sets;
-import com.cloud.util.NuageVspEntityBuilder;
-import net.nuage.vsp.acs.NuageVspPluginClientLoader;
-import net.nuage.vsp.acs.client.api.model.VspApiDefaults;
-import net.nuage.vsp.acs.client.api.model.VspDomain;
-import org.apache.cloudstack.api.ResponseGenerator;
-import org.apache.cloudstack.framework.config.ConfigKey;
-import org.apache.cloudstack.framework.config.Configurable;
-import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
-import org.apache.cloudstack.framework.config.impl.ConfigurationVO;
-import org.apache.cloudstack.framework.messagebus.MessageBus;
-import org.apache.cloudstack.framework.messagebus.MessageSubscriber;
-import org.apache.cloudstack.network.ExternalNetworkDeviceManager;
-import org.apache.commons.collections.CollectionUtils;
-import org.apache.log4j.Logger;
-
-import javax.inject.Inject;
-import javax.naming.ConfigurationException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.UUID;
-import java.util.concurrent.ExecutionException;
-
-import static com.cloud.agent.api.sync.SyncNuageVspCmsIdCommand.SyncType;
 
 public class NuageVspManagerImpl extends ManagerBase implements NuageVspManager, Configurable, StateListener<Status, Status.Event, Host> {
 
@@ -149,6 +160,7 @@ public class NuageVspManagerImpl extends ManagerBase implements NuageVspManager,
     public static final Map<Network.Service, Set<Network.Provider>> NUAGE_VSP_VPC_SERVICE_MAP;
     private static final ConfigKey[] NUAGE_VSP_CONFIG_KEYS = new ConfigKey<?>[] { NuageVspConfigDns, NuageVspDnsExternal, NuageVspConfigGateway,
             NuageVspSharedNetworkDomainTemplateName, NuageVspVpcDomainTemplateName, NuageVspIsolatedNetworkDomainTemplateName };
+    public static final String CMSID_CONFIG_KEY = "nuagevsp.cms.id";
 
     @Inject
     ResourceManager _resourceMgr;
@@ -255,37 +267,65 @@ public class NuageVspManagerImpl extends ManagerBase implements NuageVspManager,
             throw new CloudRuntimeException("A NuageVsp device is already configured on this physical network");
         }
 
-        try {
-            NuageVspPluginClientLoader clientLoader = NuageVspPluginClientLoader.getClientLoader(null, null, null, null, 1, 1, null);
+        // While the default VSD port is 8443, clustering via HAProxy will go over port 443 (CLOUD-58)
+        int port = cmd.getPort() > 0 ? cmd.getPort() : 443;
 
-            VspApiDefaults apiDefaults = clientLoader.getNuageVspManagerClient().getApiDefaults();
-            String apiVersion = MoreObjects.firstNonNull(cmd.getApiVersion(), apiDefaults.getVersion());
-            if (!clientLoader.getNuageVspManagerClient().isSupportedApiVersion(apiVersion)) {
-                throw new CloudRuntimeException("Unsupported API version : " + apiVersion);
-            }
+        try {
+            String apiVersion = null;
 
-            int port = cmd.getPort();
-            if (0 == port) {
-                port = 443;
-            }
             String cmsUserPasswordBase64 = NuageVspUtil.encodePassword(cmd.getPassword());
-            String retryCount = String.valueOf(MoreObjects.firstNonNull(cmd.getApiRetryCount(), apiDefaults.getRetryCount()));
-            String retryInterval = String.valueOf(MoreObjects.firstNonNull(cmd.getApiRetryInterval(), apiDefaults.getRetryInterval()));
-            NuageVspResource.Configuration resourceConfiguration = new NuageVspResource.Configuration()
-                    .name("Nuage VSD - " + cmd.getHostName())
+
+            NuageVspResourceConfiguration resourceConfiguration = new NuageVspResourceConfiguration()
                     .guid(UUID.randomUUID().toString())
                     .zoneId(String.valueOf(physicalNetwork.getDataCenterId()))
                     .hostName(cmd.getHostName())
                     .cmsUser(cmd.getUserName())
                     .cmsUserPassword(cmsUserPasswordBase64)
                     .port(String.valueOf(port))
+                    .apiVersion(NuageVspApiVersion.CURRENT.toString())
+                    .retryCount(NuageVspConstants.DEFAULT_API_RETRY_COUNT.toString())
+                    .retryInterval(NuageVspConstants.DEFAULT_API_RETRY_INTERVAL.toString())
+                    .apiRelativePath("/nuage");
+
+            VspHost vspHost = resourceConfiguration.buildVspHost();
+            NuageVspPluginClientLoader clientLoader = NuageVspPluginClientLoader.getClientLoader(vspHost);
+            VspApiDefaults apiDefaults = clientLoader.getNuageVspManagerClient().getApiDefaults();
+
+
+            if (StringUtils.isNotBlank(cmd.getApiVersion())){
+                if (!clientLoader.getNuageVspManagerClient().isSupportedApiVersion(cmd.getApiVersion())){
+                    throw new CloudRuntimeException("Unsupported API version : " + cmd.getApiVersion());
+                }
+                apiVersion = cmd.getApiVersion();
+            } else {
+                boolean apiVersionFound = false;
+                Map<NuageVspApiVersion, NuageVspApiVersion.Status> supportedVersions = clientLoader.getNuageVspManagerClient().getSupportedVersions();
+                for (NuageVspApiVersion selectedVersion : supportedVersions.keySet()) {
+                    if (supportedVersions.get(selectedVersion) == NuageVspApiVersion.Status.CURRENT){
+                        apiVersion = selectedVersion.toString();
+                        apiVersionFound = true;
+                        break;
+                    }
+                }
+
+                if(!apiVersionFound) {
+                    throw new CloudRuntimeException("No supported API version found!");
+                }
+            }
+
+
+            String retryCount = String.valueOf(MoreObjects.firstNonNull(cmd.getApiRetryCount(), apiDefaults.getRetryCount()));
+            String retryInterval = String.valueOf(MoreObjects.firstNonNull(cmd.getApiRetryInterval(), apiDefaults.getRetryInterval()));
+
+            resourceConfiguration
                     .apiVersion(apiVersion)
                     .apiRelativePath("/nuage/api/" + apiVersion)
                     .retryCount(retryCount)
                     .retryInterval(retryInterval);
-
             Map<String, String> hostDetails = resourceConfiguration.build();
-            resource.configure(cmd.getHostName(), Maps.<String, Object>newHashMap(hostDetails));
+            resource.configure("Nuage VSD - " + cmd.getHostName(), Maps.<String, Object>newHashMap(hostDetails));
+
+
             Host host = _resourceMgr.addHost(zoneId, resource, Host.Type.L2Networking, hostDetails);
             if (host == null) {
                 throw new CloudRuntimeException("Failed to add Nuage Vsp Device due to internal error.");
@@ -297,11 +337,10 @@ public class NuageVspManagerImpl extends ManagerBase implements NuageVspManager,
             DetailVO detail = new DetailVO(host.getId(), "nuagevspdeviceid", String.valueOf(nuageVspDevice.getId()));
             _hostDetailsDao.persist(detail);
 
-            ConfigurationVO cmsIdConfig = _configDao.findByName("nuagevsp.cms.id");
             NuageVspDeviceVO matchingNuageVspDevice = findMatchingNuageVspDevice(nuageVspDevice);
             String cmsId;
             if (matchingNuageVspDevice != null) {
-                cmsId = findNuageVspCmsIdForDevice(matchingNuageVspDevice.getId(), cmsIdConfig);
+                cmsId = findNuageVspCmsIdForDeviceOrHost(matchingNuageVspDevice.getId(), matchingNuageVspDevice.getHostId());
             } else {
                 SyncNuageVspCmsIdCommand syncCmd = new SyncNuageVspCmsIdCommand(SyncType.REGISTER, null);
                 SyncNuageVspCmsIdAnswer answer = (SyncNuageVspCmsIdAnswer) _agentMgr.easySend(nuageVspDevice.getHostId(), syncCmd);
@@ -313,10 +352,7 @@ public class NuageVspManagerImpl extends ManagerBase implements NuageVspManager,
             }
 
             host = findNuageVspHost(nuageVspDevice.getHostId());
-            registerNewNuageVspDevice(cmsIdConfig, nuageVspDevice.getId() + ":" + cmsId);
-
-            detail = new DetailVO(host.getId(), "nuagevspcmsid", cmsId);
-            _hostDetailsDao.persist(detail);
+            registerNewNuageVspDevice(host.getId(), cmsId);
 
             resourceConfiguration.nuageVspCmsId(cmsId);
             resource.configure(cmd.getHostName(), Maps.<String, Object>newHashMap(resourceConfiguration.build()));
@@ -368,56 +404,73 @@ public class NuageVspManagerImpl extends ManagerBase implements NuageVspManager,
             _hostDao.loadDetails(nuageVspHost);
         }
 
-        boolean updateRequired = false;
-        NuageVspResource.Configuration resourceConfiguration = NuageVspResource.Configuration.fromConfiguration(nuageVspHost.getDetails());
+        boolean resourceConfigurationChanged = false;
+        NuageVspResourceConfiguration resourceConfiguration = NuageVspResourceConfiguration.fromConfiguration(nuageVspHost.getDetails());
         if (!Strings.isNullOrEmpty(command.getHostName()) &&
                 !command.getHostName().equals(resourceConfiguration.hostName())) {
-            resourceConfiguration.name("Nuage VSD - " + command.getHostName());
             resourceConfiguration.hostName(command.getHostName());
-            updateRequired = true;
+            resourceConfigurationChanged = true;
         }
 
         if (!Strings.isNullOrEmpty(command.getUserName()) &&
                 !command.getUserName().equals(resourceConfiguration.cmsUser())) {
             resourceConfiguration.cmsUser(command.getUserName());
-            updateRequired = true;
+            resourceConfigurationChanged = true;
         }
 
         if (!Strings.isNullOrEmpty(command.getPassword())) {
             String encodedNewPassword = NuageVspUtil.encodePassword(command.getPassword());
             if (!encodedNewPassword.equals(resourceConfiguration.cmsUserPassword())) {
                 resourceConfiguration.cmsUserPassword(encodedNewPassword);
-                updateRequired = true;
+                resourceConfigurationChanged = true;
             }
         }
 
         if (command.getPort() != null &&
                 command.getPort() != Integer.parseInt(resourceConfiguration.port())) {
             resourceConfiguration.port(String.valueOf(command.getPort()));
-            updateRequired = true;
+            resourceConfigurationChanged = true;
         }
 
-        GetApiDefaultsCommand apiDefaultsCmd = new GetApiDefaultsCommand();
-        GetApiDefaultsAnswer apiDefaultsAnswer = (GetApiDefaultsAnswer) _agentMgr.easySend(nuageVspHost.getId(), apiDefaultsCmd);
         String apiVersion = MoreObjects.firstNonNull(command.getApiVersion(), resourceConfiguration.apiVersion());
-        SupportedApiVersionCommand supportedApiVersionCmd = new SupportedApiVersionCommand(apiVersion);
-        Answer supportedApiVersionAnswer = _agentMgr.easySend(nuageVspHost.getId(), supportedApiVersionCmd);
-        if (!supportedApiVersionAnswer.getResult()) {
-            throw new CloudRuntimeException("Incorrect API version: Nuage plugin only supports " + apiDefaultsAnswer.getApiDefaults().getVersion());
+        NuageVspApiVersion apiVersionObj = NuageVspApiVersion.fromString(apiVersion);
+        NuageVspApiVersion apiVersionCurrent = null;
+        try {
+            apiVersionCurrent = resourceConfiguration.getApiVersion();
+        } catch (ConfigurationException e){
+            throw new CloudRuntimeException("Current version is not configured correctly");
         }
 
-        String apiRelativePath = "/nuage/api/" + apiVersion;
-        if (!apiRelativePath.equals(resourceConfiguration.apiRelativePath())) {
-            resourceConfiguration.apiVersion(apiVersion);
-            resourceConfiguration.apiRelativePath(apiRelativePath);
-            updateRequired = true;
+
+        if(command.getApiVersion() != null){
+            if(apiVersionObj.compareTo(apiVersionCurrent) < 0) {
+                throw new CloudRuntimeException("Downgrading is not supported");
+            }
+
+            GetApiDefaultsCommand apiDefaultsCmd = new GetApiDefaultsCommand();
+            GetApiDefaultsAnswer apiDefaultsAnswer = (GetApiDefaultsAnswer) _agentMgr.easySend(nuageVspHost.getId(), apiDefaultsCmd);
+
+            SupportedApiVersionCommand supportedApiVersionCmd = new SupportedApiVersionCommand(apiVersion);
+            Answer supportedApiVersionAnswer = _agentMgr.easySend(nuageVspHost.getId(), supportedApiVersionCmd);
+
+            if (!supportedApiVersionAnswer.getResult()) {
+                throw new CloudRuntimeException("Incorrect API version: Nuage plugin only supports " + apiDefaultsAnswer.getApiDefaults().getVersion());
+            }
+
+            String apiRelativePath = "/nuage/api/" + apiVersion;
+            if (!apiRelativePath.equals(resourceConfiguration.apiRelativePath())) {
+                resourceConfiguration.apiVersion(apiVersion);
+                resourceConfiguration.apiRelativePath(apiRelativePath);
+                resourceConfigurationChanged = true;
+            }
+
         }
 
         if (command.getApiRetryCount() != null && resourceConfiguration.retryCount() != null) {
             final int retryCount = Integer.parseInt(resourceConfiguration.retryCount());
             if (command.getApiRetryCount() != retryCount) {
                 resourceConfiguration.retryCount(String.valueOf(command.getApiRetryCount()));
-                updateRequired = true;
+                resourceConfigurationChanged = true;
             }
         }
 
@@ -425,11 +478,11 @@ public class NuageVspManagerImpl extends ManagerBase implements NuageVspManager,
             final int apiRetryInterval = Integer.parseInt(resourceConfiguration.retryInterval());
             if (command.getApiRetryInterval() != apiRetryInterval) {
                 resourceConfiguration.retryInterval(String.valueOf(command.getApiRetryInterval()));
-                updateRequired = true;
+                resourceConfigurationChanged = true;
             }
         }
 
-        if (!updateRequired) {
+        if (!resourceConfigurationChanged) {
             if (s_logger.isDebugEnabled()) {
                 s_logger.debug("No change in the NuageVsp device parameters. None of the NuageVsp device parameters are modified");
             }
@@ -437,13 +490,21 @@ public class NuageVspManagerImpl extends ManagerBase implements NuageVspManager,
         }
 
         Map<String, String> config = resourceConfiguration.build();
-        String updateParameters = "{" + Joiner.on(", ").withKeyValueSeparator(": ").join(config) + "}";
-        Map<String, Object> hostDetails = Maps.<String, Object>newHashMap(config);
         try {
-            resource.configure(resourceConfiguration.hostName(), hostDetails);
+            resource.validate(config);
+
+            UpdateNuageVspDeviceCommand cmd = new UpdateNuageVspDeviceCommand(resourceConfiguration);
+            Answer answer = _agentMgr.easySend(nuageVspHost.getId(), cmd);
+            if (answer == null || !answer.getResult()) {
+                s_logger.error("UpdateNuageVspDeviceCommand failed");
+                if ((null != answer) && (null != answer.getDetails())) {
+                    throw new CloudRuntimeException(answer.getDetails());
+                }
+            }
+
             _hostDetailsDao.persist(nuageVspDevice.getHostId(), config);
         } catch (ConfigurationException e) {
-            throw new CloudRuntimeException("Failed to update Nuage VSP device " + nuageVspDevice.getId() + " with parameters " + updateParameters, e);
+            throw new CloudRuntimeException("Failed to update Nuage VSP device " + nuageVspDevice.getId() + " with parameters " + resourceConfiguration, e);
         }
         return nuageVspDevice;
     }
@@ -453,7 +514,7 @@ public class NuageVspManagerImpl extends ManagerBase implements NuageVspManager,
         HostVO nuageVspHost = _hostDao.findById(nuageVspDeviceVO.getHostId());
         _hostDao.loadDetails(nuageVspHost);
 
-        NuageVspResource.Configuration resourceConfiguration = NuageVspResource.Configuration.fromConfiguration(nuageVspHost.getDetails());
+        NuageVspResourceConfiguration resourceConfiguration = NuageVspResourceConfiguration.fromConfiguration(nuageVspHost.getDetails());
         NuageVspDeviceResponse response = new NuageVspDeviceResponse();
         response.setDeviceName(nuageVspDeviceVO.getDeviceName());
         PhysicalNetwork pnw = ApiDBUtils.findPhysicalNetworkById(nuageVspDeviceVO.getPhysicalNetworkId());
@@ -500,10 +561,10 @@ public class NuageVspManagerImpl extends ManagerBase implements NuageVspManager,
         }
 
         NuageVspDeviceVO matchingNuageVspDevice = findMatchingNuageVspDevice(nuageVspDevice);
-        ConfigurationVO cmsIdConfig = _configDao.findByName("nuagevsp.cms.id");
-        HostVO host = findNuageVspHost(nuageVspDevice.getHostId());
-        String nuageVspCmsId = findNuageVspCmsIdForDevice(nuageVspDevice.getId(), cmsIdConfig);
+
+        String nuageVspCmsId = findNuageVspCmsIdForDeviceOrHost(nuageVspDevice.getId(), nuageVspDevice.getHostId());
         if (matchingNuageVspDevice == null) {
+            HostVO host = findNuageVspHost(nuageVspDevice.getHostId());
             if (!auditDomainsOnVsp(host, false)) {
                 return false;
             }
@@ -515,15 +576,7 @@ public class NuageVspManagerImpl extends ManagerBase implements NuageVspManager,
             }
         }
 
-        String newValue = cmsIdConfig.getValue().replace(nuageVspDevice.getId() + ":" + nuageVspCmsId, "");
-        if (newValue.startsWith(";")) {
-            newValue = newValue.substring(1);
-        }
-        if (newValue.endsWith(";")) {
-            newValue = newValue.substring(0, newValue.length() - 1);
-        }
-        newValue = newValue.replaceAll(";+", ";");
-        _configDao.update("nuagevsp.cms.id", newValue);
+        removeLegacyNuageVspDeviceCmsId(nuageVspDevice.getId());
 
         HostVO nuageHost = _hostDao.findById(nuageVspDevice.getHostId());
         Long hostId = nuageHost.getId();
@@ -537,15 +590,15 @@ public class NuageVspManagerImpl extends ManagerBase implements NuageVspManager,
     }
 
     private NuageVspDeviceVO findMatchingNuageVspDevice(NuageVspDeviceVO nuageVspDevice) {
+        DetailVO nuageVspDeviceHost =  _hostDetailsDao.findDetail(nuageVspDevice.getHostId(), "hostname");
+        String nuageVspDeviceHostName = (nuageVspDeviceHost != null) ? nuageVspDeviceHost.getValue(): null;
+
         List<NuageVspDeviceVO> otherNuageVspDevices = _nuageVspDao.listAll();
         for (NuageVspDeviceVO otherNuageVspDevice : otherNuageVspDevices) {
             if (otherNuageVspDevice.getId() == nuageVspDevice.getId()) continue;
 
-            HostVO nuageVspDeviceHost = findNuageVspHost(nuageVspDevice.getHostId());
-            HostVO otherNuageVspDeviceHost = findNuageVspHost(otherNuageVspDevice.getHostId());
-            String nuageVspDeviceHostName = nuageVspDeviceHost.getDetail("hostname");
-            String otherNuageVspDeviceHostName = otherNuageVspDeviceHost.getDetail("hostname");
-            if (otherNuageVspDeviceHostName != null && otherNuageVspDeviceHostName.equals(nuageVspDeviceHostName)) {
+            DetailVO otherNuageVspDeviceHostName = _hostDetailsDao.findDetail(otherNuageVspDevice.getHostId(), "hostname");
+            if (otherNuageVspDeviceHostName != null && nuageVspDeviceHostName.equals(otherNuageVspDeviceHostName.getValue())) {
                 return otherNuageVspDevice;
             }
         }
@@ -579,24 +632,51 @@ public class NuageVspManagerImpl extends ManagerBase implements NuageVspManager,
         return responseList;
     }
 
-    private void registerNewNuageVspDevice(ConfigurationVO currentConfig, String registeredNuageVspDevice) {
-        if (currentConfig == null) {
-            ConfigKey<String> configKey = new ConfigKey<String>("Advanced", String.class, "nuagevsp.cms.id", registeredNuageVspDevice,
-                    "<ACS Nuage VSP Device ID>:<Allocated VSD CMS ID> - Do not edit", false);
-            ConfigurationVO configuration = new ConfigurationVO("management-server", configKey);
-            _configDao.persist(configuration);
-        } else {
-            String newValue;
-            String currentValue = currentConfig.getValue();
-            if (!Strings.isNullOrEmpty(currentValue)) {
-                newValue = currentValue + ";" + registeredNuageVspDevice;
+    private void registerNewNuageVspDevice(long hostId, String cmsId) {
+        DetailVO detail = new DetailVO(hostId, "nuagevspcmsid", cmsId);
+        _hostDetailsDao.persist(detail);
+    }
+
+    @Deprecated
+    private void removeLegacyNuageVspDeviceCmsId(long deviceId) {
+        ConfigurationVO cmsIdConfig = _configDao.findByName(CMSID_CONFIG_KEY);
+        if (cmsIdConfig != null) {
+            if (!cmsIdConfig.getValue().contains(";") && cmsIdConfig.getValue().startsWith(deviceId + ":")) {
+                _configDao.update(CMSID_CONFIG_KEY, "Advanced", "");
             } else {
-                newValue = registeredNuageVspDevice;
+                String newValue = cmsIdConfig.getValue().replace(String.format("(^|;)%d:[0-9a-f\\-]+;?", deviceId), ";");
+                _configDao.update(CMSID_CONFIG_KEY, "Advanced", newValue);
             }
-            _configDao.update("nuagevsp.cms.id", newValue);
         }
     }
 
+    public boolean executeSyncCmsId(NuageVspDeviceVO nuageVspDevice, SyncType syncType) {
+        NuageVspDeviceVO matchingNuageVspDevice = findMatchingNuageVspDevice(nuageVspDevice);
+        if (syncType == SyncType.REGISTER && matchingNuageVspDevice != null) {
+            String cmsId = findNuageVspCmsIdForDeviceOrHost(matchingNuageVspDevice.getId(), matchingNuageVspDevice.getHostId());
+            registerNewNuageVspDevice(nuageVspDevice.getHostId(), cmsId);
+            return true;
+        }
+
+        String cmsId = findNuageVspCmsIdForDeviceOrHost(nuageVspDevice.getId(), nuageVspDevice.getHostId());
+
+        SyncNuageVspCmsIdCommand syncCmd = new SyncNuageVspCmsIdCommand(syncType, cmsId);
+        SyncNuageVspCmsIdAnswer answer = (SyncNuageVspCmsIdAnswer) _agentMgr.easySend(nuageVspDevice.getHostId(), syncCmd);
+        if (answer != null) {
+            if (answer.getSuccess()) {
+                if (syncType == SyncType.REGISTER || answer.getSyncType() == SyncType.REGISTER) {
+                    registerNewNuageVspDevice(nuageVspDevice.getHostId(), answer.getNuageVspCmsId());
+                } else if (syncType == SyncType.UNREGISTER) {
+                    removeLegacyNuageVspDeviceCmsId(nuageVspDevice.getId());
+                }
+            } else if (syncType == SyncType.AUDIT || syncType == SyncType.AUDIT_ONLY) {
+                s_logger.fatal("Nuage VSP Device with ID " + nuageVspDevice.getId() + " is configured with an unknown CMS ID!");
+            }
+        }
+
+        return answer != null && answer.getSuccess();
+    }
+
     private void auditHost(HostVO host) {
         if (host == null) return;
 
@@ -606,8 +686,7 @@ public class NuageVspManagerImpl extends ManagerBase implements NuageVspManager,
         List<NuageVspDeviceVO> nuageVspDevices = _nuageVspDao.listByHost(host.getId());
         if (!CollectionUtils.isEmpty(nuageVspDevices)) {
             for (NuageVspDeviceVO nuageVspDevice : nuageVspDevices) {
-                ConfigurationVO cmsIdConfig = _configDao.findByName("nuagevsp.cms.id");
-                String nuageVspCmsId = findNuageVspCmsIdForDevice(nuageVspDevice.getId(), cmsIdConfig);
+                String nuageVspCmsId = findNuageVspCmsIdForDeviceOrHost(nuageVspDevice.getId(), nuageVspDevice.getHostId());
                 SyncNuageVspCmsIdCommand syncCmd = new SyncNuageVspCmsIdCommand(SyncType.AUDIT, nuageVspCmsId);
                 SyncNuageVspCmsIdAnswer answer = (SyncNuageVspCmsIdAnswer) _agentMgr.easySend(nuageVspDevice.getHostId(), syncCmd);
 
@@ -615,7 +694,7 @@ public class NuageVspManagerImpl extends ManagerBase implements NuageVspManager,
                     s_logger.error("Nuage VSP Device with ID " + nuageVspDevice.getId() + " is configured with an unknown CMS ID!");
                     validateDomains = false;
                 } else if (answer != null && answer.getSyncType() == SyncType.REGISTER) {
-                    registerNewNuageVspDevice(cmsIdConfig, nuageVspDevice.getId() + ":" + answer.getNuageVspCmsId());
+                    registerNewNuageVspDevice(nuageVspDevice.getHostId(), answer.getNuageVspCmsId());
                 }
             }
         }
@@ -631,42 +710,82 @@ public class NuageVspManagerImpl extends ManagerBase implements NuageVspManager,
             return true;
         }
 
+        final SyncDomainCommand.Type action = add ? SyncDomainCommand.Type.ADD : SyncDomainCommand.Type.REMOVE;
+
         _hostDao.loadDetails(host);
         List<DomainVO> allDomains = _domainDao.listAll();
         for (DomainVO domain : allDomains) {
+            if (action == SyncDomainCommand.Type.REMOVE) {
+                VspDomainCleanUp vspDomainCleanUp = _nuageVspEntityBuilder.buildVspDomainCleanUp(domain);
+                CleanUpDomainCommand cmd = new CleanUpDomainCommand(vspDomainCleanUp);
+                Answer answer = _agentMgr.easySend(host.getId(), cmd);
+                if (!answer.getResult()) {
+                    return false;
+                }
+            }
+
             VspDomain vspDomain = _nuageVspEntityBuilder.buildVspDomain(domain);
-            SyncDomainCommand cmd = new SyncDomainCommand(vspDomain, add ? SyncDomainCommand.Type.ADD :  SyncDomainCommand.Type.REMOVE);
-            SyncDomainAnswer answer = (SyncDomainAnswer) _agentMgr.easySend(host.getId(), cmd);
-            return answer.getSuccess();
+            SyncDomainCommand cmd = new SyncDomainCommand(vspDomain, action);
+            Answer answer = _agentMgr.easySend(host.getId(), cmd);
+            if (!answer.getResult()) {
+                return false;
+            }
         }
         return true;
     }
 
-    private String findNuageVspCmsIdForDevice(long deviceId, ConfigurationVO cmsIdConfig) {
-        String configValue = cmsIdConfig.getValue();
-        if (!Strings.isNullOrEmpty(configValue)) {
-            String[] configuredNuageVspDevices = configValue.split(";");
-            for (String configuredNuageVspDevice : configuredNuageVspDevices) {
-                if (configuredNuageVspDevice.startsWith(deviceId + ":")) {
-                    String[] split = configuredNuageVspDevice.split(":");
-                    if (split.length != 2 || (split.length > 1 && Strings.isNullOrEmpty(split[1]))) {
-                        throw new IllegalArgumentException("The configured CMS ID for Nuage VSP device " + deviceId + " is in an incorrect format");
+    private String findNuageVspCmsIdForDeviceOrHost(long deviceId, long hostId) {
+        String cmsId = findNuageVspCmsIdForHostDevice(hostId);
+        if(cmsId == null) {
+            cmsId = findNuageVspCmsIdForDevice(deviceId);
+
+            if (cmsId != null) {
+                // Upgrade
+                registerNewNuageVspDevice(hostId, cmsId);
+                removeLegacyNuageVspDeviceCmsId(deviceId);
+            }
+        }
+
+        return cmsId;
+    }
+
+    private String findNuageVspCmsIdForHostDevice(long hostId) {
+        final DetailVO cmsIdDetailVO = _hostDetailsDao.findDetail(hostId, "nuagevspcmsid");
+        if (cmsIdDetailVO != null) {
+            return cmsIdDetailVO.getValue();
+        }
+        return null;
+    }
+
+    @Deprecated
+    private String findNuageVspCmsIdForDevice(long deviceId) {
+        ConfigurationVO cmsIdConfig = _configDao.findByName(CMSID_CONFIG_KEY);
+        if(cmsIdConfig != null) {
+            String configValue = cmsIdConfig.getValue();
+            if (!Strings.isNullOrEmpty(configValue)) {
+                String[] configuredNuageVspDevices = configValue.split(";");
+                for (String configuredNuageVspDevice : configuredNuageVspDevices) {
+                    if (configuredNuageVspDevice.startsWith(deviceId + ":")) {
+                        String[] split = configuredNuageVspDevice.split(":");
+                        if (split.length != 2 || (split.length > 1 && Strings.isNullOrEmpty(split[1]))) {
+                            throw new IllegalArgumentException("The configured CMS ID for Nuage VSP device " + deviceId + " is in an incorrect format");
+                        }
+                        return split[1];
                     }
-                    return split[1];
                 }
             }
         }
         return null;
     }
 
-    public List<String> getDnsDetails(Network network) {
+    public List<String> getDnsDetails(long dataCenterId) {
         Boolean configureDns = Boolean.valueOf(_configDao.getValue(NuageVspManager.NuageVspConfigDns.key()));
         if (!configureDns) {
             return Lists.newArrayList();
         }
 
         Boolean configureExternalDns = Boolean.valueOf(_configDao.getValue(NuageVspManager.NuageVspDnsExternal.key()));
-        DataCenterVO dc = _dataCenterDao.findById(network.getDataCenterId());
+        DataCenterVO dc = _dataCenterDao.findById(dataCenterId);
         List<String> dnsServers = new ArrayList<String>();
         if (configureExternalDns) {
             if (!Strings.isNullOrEmpty(dc.getDns1())) {
@@ -799,6 +918,20 @@ public class NuageVspManagerImpl extends ManagerBase implements NuageVspManager,
             }
         });
 
+        // Clean up corresponding resources in VSP when deleting a CS Domain
+        _messageBus.subscribe(DomainManager.MESSAGE_PRE_REMOVE_DOMAIN_EVENT, new MessageSubscriber() {
+            @Override
+            public void onPublishMessage(String senderAddress, String subject, Object args) {
+                DomainVO domain = (DomainVO) args;
+                List<NuageVspDeviceVO> nuageVspDevices = _nuageVspDao.listAll();
+                for (NuageVspDeviceVO nuageVspDevice : nuageVspDevices) {
+                    VspDomainCleanUp vspDomainCleanUp = _nuageVspEntityBuilder.buildVspDomainCleanUp(domain);
+                    CleanUpDomainCommand cmd = new CleanUpDomainCommand(vspDomainCleanUp);
+                    _agentMgr.easySend(nuageVspDevice.getHostId(), cmd);
+                }
+            }
+        });
+
         // Delete corresponding enterprise and profile in VSP when deleting a CS Domain
         _messageBus.subscribe(DomainManager.MESSAGE_REMOVE_DOMAIN_EVENT, new MessageSubscriber() {
             @Override
@@ -807,8 +940,8 @@ public class NuageVspManagerImpl extends ManagerBase implements NuageVspManager,
                 List<NuageVspDeviceVO> nuageVspDevices = _nuageVspDao.listAll();
                 for (NuageVspDeviceVO nuageVspDevice : nuageVspDevices) {
                     VspDomain vspDomain = _nuageVspEntityBuilder.buildVspDomain(domain);
-                    SyncDomainCommand cmd = new SyncDomainCommand(vspDomain, SyncDomainCommand.Type.REMOVE);
-                    _agentMgr.easySend(nuageVspDevice.getHostId(), cmd);
+                    SyncDomainCommand syncCmd = new SyncDomainCommand(vspDomain, SyncDomainCommand.Type.REMOVE);
+                    _agentMgr.easySend(nuageVspDevice.getHostId(), syncCmd);
                 }
             }
         });

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4c91c9c5/plugins/network-elements/nuage-vsp/src/com/cloud/network/resource/NuageVspRequestWrapper.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nuage-vsp/src/com/cloud/network/resource/NuageVspRequestWrapper.java b/plugins/network-elements/nuage-vsp/src/com/cloud/network/resource/NuageVspRequestWrapper.java
new file mode 100644
index 0000000..2a0e0bf
--- /dev/null
+++ b/plugins/network-elements/nuage-vsp/src/com/cloud/network/resource/NuageVspRequestWrapper.java
@@ -0,0 +1,78 @@
+//
+// 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.network.resource;
+
+import java.util.Hashtable;
+import java.util.Set;
+
+import org.reflections.Reflections;
+
+import com.cloud.agent.api.Answer;
+import com.cloud.agent.api.Command;
+import com.cloud.resource.CommandWrapper;
+import com.cloud.resource.RequestWrapper;
+import com.cloud.resource.ServerResource;
+
+public class NuageVspRequestWrapper extends RequestWrapper {
+
+    private static NuageVspRequestWrapper instance;
+
+    @SuppressWarnings("rawtypes")
+    private final static Set<Class<? extends CommandWrapper>> baseSet;
+
+    static {
+        Reflections baseWrappers = new Reflections("com.cloud.network.vsp.resource.wrapper");
+        baseSet = baseWrappers.getSubTypesOf(CommandWrapper.class);
+        instance = new NuageVspRequestWrapper();
+    }
+
+    private NuageVspRequestWrapper() {
+        init();
+    }
+
+    @SuppressWarnings("rawtypes")
+    private void init() {
+        // NuageVspResource commands
+        final Hashtable<Class<? extends Command>, CommandWrapper> vspCommands = processAnnotations(baseSet);
+
+        resources.put(NuageVspResource.class, vspCommands);
+    }
+
+    public static NuageVspRequestWrapper getInstance() {
+        return instance;
+    }
+
+    @SuppressWarnings("rawtypes")
+    @Override
+    public Answer execute(final Command command, final ServerResource serverResource) {
+        final Class<? extends ServerResource> resourceClass = serverResource.getClass();
+
+        final Hashtable<Class<? extends Command>, CommandWrapper> resourceCommands = retrieveResource(command, resourceClass);
+
+        CommandWrapper<Command, Answer, ServerResource> commandWrapper = retrieveCommands(command.getClass(), resourceCommands);
+
+        while (commandWrapper == null) {
+            //Could not find the command in the given resource, will traverse the family tree.
+            commandWrapper = retryWhenAllFails(command, resourceClass, resourceCommands);
+        }
+
+        return commandWrapper.execute(command, serverResource);
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4c91c9c5/plugins/network-elements/nuage-vsp/src/com/cloud/network/resource/NuageVspResource.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nuage-vsp/src/com/cloud/network/resource/NuageVspResource.java b/plugins/network-elements/nuage-vsp/src/com/cloud/network/resource/NuageVspResource.java
index 9d04ab0..5ffe683 100644
--- a/plugins/network-elements/nuage-vsp/src/com/cloud/network/resource/NuageVspResource.java
+++ b/plugins/network-elements/nuage-vsp/src/com/cloud/network/resource/NuageVspResource.java
@@ -19,19 +19,19 @@
 
 package com.cloud.network.resource;
 
-import java.util.HashMap;
 import java.util.Map;
 import java.util.concurrent.ExecutionException;
-import java.util.regex.Pattern;
 
 import javax.naming.ConfigurationException;
 
-import net.nuage.vsp.acs.NuageVspPluginClientLoader;
+import net.nuage.vsp.acs.client.api.NuageVspAclClient;
 import net.nuage.vsp.acs.client.api.NuageVspApiClient;
 import net.nuage.vsp.acs.client.api.NuageVspElementClient;
 import net.nuage.vsp.acs.client.api.NuageVspGuruClient;
 import net.nuage.vsp.acs.client.api.NuageVspManagerClient;
-import net.nuage.vsp.acs.client.common.model.Pair;
+import net.nuage.vsp.acs.client.api.NuageVspPluginClientLoader;
+import net.nuage.vsp.acs.client.api.model.VspHost;
+import net.nuage.vsp.acs.client.exception.NuageVspException;
 
 import org.apache.log4j.Logger;
 
@@ -40,191 +40,75 @@ import com.google.common.base.Strings;
 import com.cloud.agent.IAgentControl;
 import com.cloud.agent.api.Answer;
 import com.cloud.agent.api.Command;
-import com.cloud.agent.api.MaintainAnswer;
-import com.cloud.agent.api.MaintainCommand;
 import com.cloud.agent.api.PingCommand;
 import com.cloud.agent.api.PingNuageVspCommand;
-import com.cloud.agent.api.ReadyAnswer;
-import com.cloud.agent.api.ReadyCommand;
 import com.cloud.agent.api.StartupCommand;
 import com.cloud.agent.api.StartupVspCommand;
-import com.cloud.agent.api.element.ApplyAclRuleVspCommand;
-import com.cloud.agent.api.element.ApplyStaticNatVspCommand;
-import com.cloud.agent.api.element.ImplementVspCommand;
-import com.cloud.agent.api.element.ShutDownVpcVspCommand;
-import com.cloud.agent.api.element.ShutDownVspCommand;
-import com.cloud.agent.api.guru.DeallocateVmVspCommand;
-import com.cloud.agent.api.guru.ImplementNetworkVspCommand;
-import com.cloud.agent.api.guru.ReserveVmInterfaceVspCommand;
-import com.cloud.agent.api.guru.TrashNetworkVspCommand;
-import com.cloud.agent.api.guru.UpdateDhcpOptionVspCommand;
-import com.cloud.agent.api.manager.EntityExistsCommand;
-import com.cloud.agent.api.manager.GetApiDefaultsAnswer;
-import com.cloud.agent.api.manager.GetApiDefaultsCommand;
-import com.cloud.agent.api.manager.SupportedApiVersionCommand;
-import com.cloud.agent.api.sync.SyncDomainAnswer;
-import com.cloud.agent.api.sync.SyncDomainCommand;
-import com.cloud.agent.api.sync.SyncNuageVspCmsIdAnswer;
-import com.cloud.agent.api.sync.SyncNuageVspCmsIdCommand;
-import com.cloud.dc.Vlan;
 import com.cloud.host.Host;
 import com.cloud.resource.ServerResource;
-import com.cloud.util.NuageVspUtil;
-import com.cloud.utils.StringUtils;
 import com.cloud.utils.component.ManagerBase;
 import com.cloud.utils.exception.CloudRuntimeException;
-import net.nuage.vsp.acs.client.common.model.NuageVspEntity;
-
-import static com.cloud.agent.api.sync.SyncNuageVspCmsIdCommand.SyncType;
 
 public class NuageVspResource extends ManagerBase implements ServerResource {
     private static final Logger s_logger = Logger.getLogger(NuageVspResource.class);
 
-    private static final String NAME = "name";
-    private static final String GUID = "guid";
-    private static final String ZONE_ID = "zoneid";
-    private static final String HOST_NAME = "hostname";
-    private static final String CMS_USER = "cmsuser";
-    private static final String CMS_USER_PASSWORD = "cmsuserpass";
-    private static final String PORT = "port";
-    private static final String API_VERSION = "apiversion";
-    private static final String API_RELATIVE_PATH = "apirelativepath";
-    private static final String RETRY_COUNT = "retrycount";
-    private static final String RETRY_INTERVAL = "retryinterval";
-    private static final String NUAGE_VSP_CMS_ID = "nuagevspcmsid";
-
-    private String _name;
     private String _guid;
     private String _zoneId;
-    private String _cmsUserLogin;
-    private String _cmsUserPassword;
     private String _hostName;
-    private String _relativePath;
-    private int _numRetries;
-    private int _retryInterval;
-    private String _nuageVspCmsId;
     private boolean _shouldAudit = true;
 
-    protected NuageVspApiClient _nuageVspApiClient;
-    protected NuageVspGuruClient _nuageVspGuruClient;
-    protected NuageVspElementClient _nuageVspElementClient;
-    protected NuageVspManagerClient _nuageVspManagerClient;
-    protected boolean _isNuageVspClientLoaded;
+    private VspHost _vspHost;
 
-    private static final String CMS_USER_ENTEPRISE_NAME = "CSP";
     private static final String NUAGE_VSP_PLUGIN_ERROR_MESSAGE = "Nuage Vsp plugin client is not installed";
+    protected NuageVspPluginClientLoader _clientLoader;
 
-    @Override
-    public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
-
-        _name = (String)params.get(NAME);
-        if (_name == null) {
-            throw new ConfigurationException("Unable to find name");
-        }
-
-        _guid = (String)params.get(GUID);
-        if (_guid == null) {
-            throw new ConfigurationException("Unable to find the guid");
-        }
-
-        _zoneId = (String)params.get(ZONE_ID);
-        if (_zoneId == null) {
-            throw new ConfigurationException("Unable to find zone");
-        }
-
-        _hostName = (String)params.get(HOST_NAME);
-        if (Strings.isNullOrEmpty(_hostName)) {
-            throw new ConfigurationException("Unable to find hostname");
-        }
-
-        String cmsUser = (String)params.get(CMS_USER);
-        if (Strings.isNullOrEmpty(cmsUser)) {
-            throw new ConfigurationException("Unable to find CMS username");
-        }
-
-        String cmsUserPassBase64 = (String)params.get(CMS_USER_PASSWORD);
-        if (Strings.isNullOrEmpty(cmsUserPassBase64)) {
-            throw new ConfigurationException("Unable to find CMS password");
-        }
+    public VspHost validate(Map<String, ?> params) throws ConfigurationException {
+        return validate(NuageVspResourceConfiguration.fromConfiguration(params));
+    }
 
-        String port = (String)params.get(PORT);
-        if (Strings.isNullOrEmpty(port)) {
-            throw new ConfigurationException("Unable to find port");
-        }
+    public VspHost validate(NuageVspResourceConfiguration configuration) throws ConfigurationException {
+        configuration.validate();
 
-        String apiVersion = (String)params.get(API_VERSION);
-        if (Strings.isNullOrEmpty(apiVersion)) {
-            throw new ConfigurationException("Unable to find API version");
-        } else if (!Pattern.matches("v\\d+_\\d+", apiVersion)) {
-            throw new ConfigurationException("Incorrect API version");
-        }
+        VspHost newVspHost = configuration.buildVspHost();
 
-        String apiRelativePath = (String)params.get(API_RELATIVE_PATH);
-        if (Strings.isNullOrEmpty(apiRelativePath) || !apiRelativePath.contains(apiVersion)) {
-            throw new ConfigurationException("Unable to find API version in relative path");
-        }
-
-        String retryCount = (String)params.get(RETRY_COUNT);
-        if (!Strings.isNullOrEmpty(retryCount)) {
-            try {
-                _numRetries = Integer.parseInt(retryCount);
-            } catch (NumberFormatException ex) {
-                throw new ConfigurationException("Number of retries has to be between 1 and 10");
-            }
-            if ((_numRetries < 1) || (_numRetries > 10)) {
-                throw new ConfigurationException("Number of retries has to be between 1 and 10");
-            }
-        } else {
-            throw new ConfigurationException("Unable to find number of retries");
-        }
 
-        String retryInterval = (String)params.get(RETRY_INTERVAL);
-        if (!Strings.isNullOrEmpty(retryInterval)) {
-            try {
-                _retryInterval = Integer.parseInt(retryInterval);
-            } catch (NumberFormatException ex) {
-                throw new ConfigurationException("Retry interval has to be between 0 and 10000 ms");
-            }
-            if ((_retryInterval < 0) || (_retryInterval > 10000)) {
-                throw new ConfigurationException("Retry interval has to be between 0 and 10000 ms");
-            }
-        } else {
-            throw new ConfigurationException("Unable to find retry interval");
+        if (!newVspHost.getApiVersion().isSupported()) {
+            s_logger.warn(String.format("[UPGRADE] API version %s of Nuage Vsp Device %s should be updated.", _vspHost.getApiVersion(), configuration.hostName()));
         }
 
-        _relativePath = new StringBuffer().append("https://").append(_hostName).append(":").append(port).append(apiRelativePath).toString();
-
-        String cmsUserPass = NuageVspUtil.decodePassword(cmsUserPassBase64);
-        _cmsUserLogin = cmsUser;
-        _cmsUserPassword = cmsUserPass;
-
-        _nuageVspCmsId = (String)params.get(NUAGE_VSP_CMS_ID);
-
-        loadNuageClient();
+        _guid = configuration.guid();
+        _zoneId = configuration.zoneId();
+        _hostName = configuration.hostName();
+        _name = configuration.name();
 
         try {
-            login();
-        } catch (ExecutionException | ConfigurationException e) {
+            final NuageVspPluginClientLoader clientLoader = getClientLoader(newVspHost);
+            clientLoader.getNuageVspApiClient().login();
+
+            _vspHost = newVspHost;
+            _clientLoader = clientLoader;
+        } catch (ExecutionException e) {
             s_logger.error(e.getMessage(), e);
             throw new CloudRuntimeException(e.getMessage(), e);
         }
 
+        return _vspHost;
+    }
+
+    @Override
+    public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
+        if(super.configure(name, params)) {
+            validate(params);
+        }
         return true;
     }
 
-    protected void login() throws ConfigurationException, ExecutionException {
-        isNuageVspApiLoaded();
-        _nuageVspApiClient.login();
+    protected void login() throws ConfigurationException, NuageVspException {
+        getNuageVspApiClient().login();
     }
 
-    protected <A extends NuageVspApiClient, B extends NuageVspElementClient, C extends NuageVspGuruClient> void loadNuageClient() {
-        NuageVspPluginClientLoader clientLoader = NuageVspPluginClientLoader.getClientLoader(_relativePath, CMS_USER_ENTEPRISE_NAME,
-                _cmsUserLogin, _cmsUserPassword, _numRetries, _retryInterval, _nuageVspCmsId);
-        _nuageVspApiClient = clientLoader.getNuageVspApiClient();
-        _nuageVspGuruClient = clientLoader.getNuageVspGuruClient();
-        _nuageVspElementClient = clientLoader.getNuageVspElementClient();
-        _nuageVspManagerClient = clientLoader.getNuageVspManagerClient();
-        _isNuageVspClientLoaded = true;
+    protected NuageVspPluginClientLoader getClientLoader(VspHost vspHost) {
+        return NuageVspPluginClientLoader.getClientLoader(vspHost);
     }
 
     @Override
@@ -238,11 +122,6 @@ public class NuageVspResource extends ManagerBase implements ServerResource {
     }
 
     @Override
-    public String getName() {
-        return _name;
-    }
-
-    @Override
     public Host.Type getType() {
         return Host.Type.L2Networking;
     }
@@ -262,20 +141,22 @@ public class NuageVspResource extends ManagerBase implements ServerResource {
 
     @Override
     public PingCommand getCurrentStatus(long id) {
-        if (Strings.isNullOrEmpty(_relativePath)) {
+        if (Strings.isNullOrEmpty(_vspHost.getRestRelativePath())) {
             s_logger.error("Refusing to ping Nuage VSD because the resource configuration is missing the relative path information");
             _shouldAudit = true;
             return null;
         }
-        if (Strings.isNullOrEmpty(_cmsUserLogin) || Strings.isNullOrEmpty(_cmsUserPassword)) {
+
+        if (Strings.isNullOrEmpty(_vspHost.getCmsUserLogin()) || Strings.isNullOrEmpty(_vspHost.getCmsUserPassword())) {
             s_logger.error("Refusing to ping Nuage VSD because the resource configuration is missing the CMS user information");
             _shouldAudit = true;
             return null;
         }
+
         try {
             login();
         } catch (ExecutionException | ConfigurationException e) {
-            s_logger.error("Failed to ping to Nuage VSD on " + _name + " as user " + _cmsUserLogin, e);
+            s_logger.error("Failed to ping to Nuage VSD on " + _name + " as user " +_vspHost.getCmsUserLogin(), e);
             _shouldAudit = true;
             return null;
         }
@@ -285,54 +166,16 @@ public class NuageVspResource extends ManagerBase implements ServerResource {
     }
 
     @Override
-    public Answer executeRequest(Command cmd) {
-        if (cmd instanceof ReadyCommand) {
-            return executeRequest((ReadyCommand)cmd);
-        } else if (cmd instanceof MaintainCommand) {
-            return executeRequest((MaintainCommand)cmd);
-        }
-        //Guru commands
-        else if (cmd instanceof ImplementNetworkVspCommand) {
-            return executeRequest((ImplementNetworkVspCommand)cmd);
-        } else if (cmd instanceof ReserveVmInterfaceVspCommand) {
-            return executeRequest((ReserveVmInterfaceVspCommand)cmd);
-        } else if (cmd instanceof DeallocateVmVspCommand) {
-            return executeRequest((DeallocateVmVspCommand)cmd);
-        } else if (cmd instanceof TrashNetworkVspCommand) {
-            return executeRequest((TrashNetworkVspCommand)cmd);
-        } else if (cmd instanceof UpdateDhcpOptionVspCommand) {
-            return executeRequest((UpdateDhcpOptionVspCommand)cmd);
-        }
-        //Element commands
-        else if (cmd instanceof ImplementVspCommand) {
-            return executeRequest((ImplementVspCommand)cmd);
-        } else if (cmd instanceof ApplyAclRuleVspCommand) {
-            return executeRequest((ApplyAclRuleVspCommand)cmd);
-        } else if (cmd instanceof ApplyStaticNatVspCommand) {
-            return executeRequest((ApplyStaticNatVspCommand)cmd);
-        } else if (cmd instanceof ShutDownVpcVspCommand) {
-            return executeRequest((ShutDownVpcVspCommand)cmd);
-        } else if (cmd instanceof ShutDownVspCommand) {
-            return executeRequest((ShutDownVspCommand)cmd);
-        }
-        //Sync Commands
-        else if (cmd instanceof SyncNuageVspCmsIdCommand) {
-            return executeRequest((SyncNuageVspCmsIdCommand)cmd);
-        } else if (cmd instanceof SyncDomainCommand) {
-            return executeRequest((SyncDomainCommand)cmd);
-        }
-        //Other commands
-        else if (cmd instanceof GetApiDefaultsCommand) {
-            return executeRequest((GetApiDefaultsCommand)cmd);
-        } else if (cmd instanceof SupportedApiVersionCommand) {
-            return executeRequest((SupportedApiVersionCommand)cmd);
-        } else if (cmd instanceof EntityExistsCommand) {
-            return executeRequest((EntityExistsCommand)cmd);
-        }
-        if (s_logger.isDebugEnabled()) {
-            s_logger.debug("Received unsupported command " + cmd.toString());
+    public Answer executeRequest(final Command cmd) {
+        final NuageVspRequestWrapper wrapper = NuageVspRequestWrapper.getInstance();
+        try {
+            return wrapper.execute(cmd, this);
+        } catch (final Exception e) {
+            if (s_logger.isDebugEnabled()) {
+                s_logger.debug("Received unsupported command " + cmd.toString());
+            }
+            return Answer.createUnsupportedCommandAnswer(cmd);
         }
-        return Answer.createUnsupportedCommandAnswer(cmd);
     }
 
     @Override
@@ -348,369 +191,36 @@ public class NuageVspResource extends ManagerBase implements ServerResource {
     public void setAgentControl(IAgentControl agentControl) {
     }
 
-    private Answer executeRequest(ReadyCommand cmd) {
-        return new ReadyAnswer(cmd);
-    }
-
-    private Answer executeRequest(MaintainCommand cmd) {
-        return new MaintainAnswer(cmd);
-    }
-
-    private Answer executeRequest(ImplementNetworkVspCommand cmd) {
-        try {
-            isNuageVspGuruLoaded();
-            _nuageVspGuruClient.implement(cmd.getNetwork(), cmd.getDhcpOption());
-            return new Answer(cmd, true, "Created network mapping to " + cmd.getNetwork().getName() + " on Nuage VSD " + _hostName);
-        } catch (ExecutionException | ConfigurationException e) {
-            s_logger.error("Failure during " + cmd.toDetailString() + " on Nuage VSD " + _hostName, e);
-            return new Answer(cmd, e);
-        }
-    }
-
-    private Answer executeRequest(ReserveVmInterfaceVspCommand cmd) {
-        try {
-            isNuageVspGuruLoaded();
-            _nuageVspGuruClient.reserve(cmd.getNetwork(), cmd.getVm(), cmd.getNic(), cmd.getStaticNat(), cmd.getDhcpOption());
-            return new Answer(cmd, true, "Created NIC that maps to nicUuid" + cmd.getNic().getUuid() + " on Nuage VSD " + _hostName);
-        } catch (ExecutionException | ConfigurationException e) {
-            s_logger.error("Failure during " + cmd + " on Nuage VSD " + _hostName, e);
-            return new Answer(cmd, e);
-        }
-    }
-
-    private Answer executeRequest(DeallocateVmVspCommand cmd) {
-        try {
-            isNuageVspGuruLoaded();
-
-            _nuageVspGuruClient.deallocate(cmd.getNetwork(), cmd.getVm(), cmd.getNic());
-            return new Answer(cmd, true, "Deallocated VM " + cmd.getVm().getName() + " on Nuage VSD " + _hostName);
-        } catch (ExecutionException | ConfigurationException e) {
-            s_logger.error("Failure during " + cmd + " on Nuage VSD " + _hostName, e);
-            return new Answer(cmd, e);
-        }
-    }
-
-    private Answer executeRequest(TrashNetworkVspCommand cmd) {
-        try {
-            isNuageVspGuruLoaded();
-            _nuageVspGuruClient.trash(cmd.getNetwork());
-            return new Answer(cmd, true, "Deleted network mapping to " + cmd.getNetwork().getUuid() + " on Nuage VSD " + _hostName);
-        } catch (ExecutionException | ConfigurationException e) {
-            s_logger.error("Failure during " + cmd + " on Nuage VSD " + _hostName, e);
-            return new Answer(cmd, e);
-        }
-    }
-
-    private Answer executeRequest(UpdateDhcpOptionVspCommand cmd) {
-        try {
-            isNuageVspManagerLoaded();
-            _nuageVspGuruClient.applyDhcpOptions(cmd.getDhcpOptions(), cmd.getNetwork());
-            return new Answer(cmd, true, "Update DhcpOptions on VM's in network: " + cmd.getNetwork().getName() + " on Nuage VSD " + _hostName);
-        } catch (ExecutionException | ConfigurationException e) {
-            s_logger.error("Failure during " + cmd.toDetailString() + " on Nuage VSD " + _hostName, e);
-            return new Answer(cmd, e);
-        }
-    }
-
-    private Answer executeRequest(ApplyStaticNatVspCommand cmd) {
-        try {
-            isNuageVspElementLoaded();
-            _nuageVspElementClient.applyStaticNats(cmd.getNetwork(), cmd.getStaticNatDetails());
-            return new Answer(cmd, true, "Applied Static NAT to network mapping " + cmd.getNetwork().getUuid() + " on Nuage VSD " + _hostName);
-        } catch (ExecutionException | ConfigurationException e) {
-            s_logger.error("Failure during " + cmd + " on Nuage VSD " + _hostName, e);
-            return new Answer(cmd, e);
-        }
-    }
-
-    private Answer executeRequest(ImplementVspCommand cmd) {
-        try {
-            isNuageVspElementLoaded();
-            boolean success = _nuageVspElementClient.implement(cmd.getNetwork(), cmd.getDhcpOption(), cmd.getIngressFirewallRules(),
-                    cmd.getEgressFirewallRules(), cmd.getFloatingIpUuids());
-            return new Answer(cmd, success, "Implemented network " + cmd.getNetwork().getUuid() + " on Nuage VSD " + _hostName);
-        } catch (ExecutionException | ConfigurationException e) {
-            s_logger.error("Failure during " + cmd + " on Nuage VSD " + _hostName, e);
-            return new Answer(cmd, e);
-        }
-    }
-
-    private Answer executeRequest(ApplyAclRuleVspCommand cmd) {
-        try {
-            isNuageVspElementLoaded();
-            _nuageVspElementClient.applyAclRules(cmd.getAclType(), cmd.getNetwork(), cmd.getAclRules(), cmd.isNetworkReset());
-            return new Answer(cmd, true, "Applied ACL Rule to network mapping " + cmd.getNetwork().getUuid() + " on Nuage VSD " + _hostName);
-        } catch (ExecutionException | ConfigurationException e) {
-            s_logger.error("Failure during " + cmd + " on Nuage VSD " + _hostName, e);
-            return new Answer(cmd, e);
-        }
-    }
-
-    private Answer executeRequest(ShutDownVpcVspCommand cmd) {
-        try {
-            isNuageVspElementLoaded();
-            _nuageVspElementClient.shutdownVpc(cmd.getDomainUuid(), cmd.getVpcUuid(), cmd.getDomainTemplateName(), cmd.getDomainRouterUuids());
-            return new Answer(cmd, true, "Shutdown VPC " + cmd.getVpcUuid() + " on Nuage VSD " + _hostName);
-        } catch (ExecutionException | ConfigurationException e) {
-            s_logger.error("Failure during " + cmd + " on Nuage VSD " + _hostName, e);
-            return new Answer(cmd, e);
-        }
-    }
-
-    private Answer executeRequest(ShutDownVspCommand cmd) {
-        try {
-            isNuageVspElementLoaded();
-            _nuageVspElementClient.shutdownNetwork(cmd.getNetwork(), cmd.getDhcpOptions());
-            return new Answer(cmd, true, "Shutdown VPC " + cmd.getNetwork().getUuid()+ " on Nuage VSD " + _hostName);
-        } catch (ConfigurationException e) {
-            s_logger.error("Failure during " + cmd.toDetailString() + " on Nuage VSD " + _hostName, e);
-            return new Answer(cmd, e);
-        }
-    }
-
-    private Answer executeRequest(SyncNuageVspCmsIdCommand cmd) {
-        try {
-            isNuageVspManagerLoaded();
-            if (cmd.getSyncType() == SyncType.AUDIT || cmd.getSyncType() == SyncType.AUDIT_ONLY) {
-                Pair<Boolean, String> answer = _nuageVspManagerClient.auditNuageVspCmsId(cmd.getNuageVspCmsId(), cmd.getSyncType() == SyncType.AUDIT_ONLY);
-                return new SyncNuageVspCmsIdAnswer(answer.getLeft(), answer.getRight(), cmd.getSyncType());
-            } else if (cmd.getSyncType() == SyncType.REGISTER) {
-                String registeredNuageVspCmsId = _nuageVspManagerClient.registerNuageVspCmsId();
-                return new SyncNuageVspCmsIdAnswer(StringUtils.isNotBlank(registeredNuageVspCmsId), registeredNuageVspCmsId, cmd.getSyncType());
-            } else {
-                boolean success = _nuageVspManagerClient.unregisterNuageVspCmsId(cmd.getNuageVspCmsId());
-                return new SyncNuageVspCmsIdAnswer(success, cmd.getNuageVspCmsId(), cmd.getSyncType());
-            }
-        } catch (ExecutionException | ConfigurationException e) {
-            s_logger.error("Failure during " + cmd + " on Nuage VSD " + _hostName, e);
-            return new SyncNuageVspCmsIdAnswer(false, null, cmd.getSyncType());
-        }
-    }
-
-    private Answer executeRequest(SyncDomainCommand cmd) {
-        try {
-            isNuageVspManagerLoaded();
-            boolean success = _nuageVspManagerClient.syncDomainWithNuageVsp(cmd.getDomain(), cmd.isToAdd(), cmd.isToRemove());
-            return new SyncDomainAnswer(success);
-        } catch (ExecutionException | ConfigurationException e) {
-            s_logger.error("Failure during " + cmd + " on Nuage VSD " + _hostName, e);
-            return new SyncDomainAnswer(false);
-        }
-    }
-
-    private Answer executeRequest(GetApiDefaultsCommand cmd) {
-        try {
-            isNuageVspManagerLoaded();
-            return new GetApiDefaultsAnswer(cmd, _nuageVspManagerClient.getApiDefaults());
-        } catch (ExecutionException | ConfigurationException e) {
-            s_logger.error("Failure during " + cmd + " on Nuage VSD " + _hostName, e);
-            return new GetApiDefaultsAnswer(cmd, e);
+    protected void assertNuageVspClientsLoaded() throws ConfigurationException {
+        if (_clientLoader == null) {
+            throw new ConfigurationException(NUAGE_VSP_PLUGIN_ERROR_MESSAGE);
         }
     }
 
-    private Answer executeRequest(SupportedApiVersionCommand cmd) {
-        try {
-            isNuageVspManagerLoaded();
-            boolean supported = _nuageVspManagerClient.isSupportedApiVersion(cmd.getApiVersion());
-            return new Answer(cmd, supported, "Check if API version " + cmd.getApiVersion() + " is supported");
-        } catch (ConfigurationException e) {
-            s_logger.error("Failure during " + cmd + " on Nuage VSD " + _hostName, e);
-            return new Answer(cmd, e);
-        }
-    }
+    public NuageVspApiClient getNuageVspApiClient() throws ConfigurationException {
+        assertNuageVspClientsLoaded();
+        return _clientLoader.getNuageVspApiClient();
 
-    private Answer executeRequest(EntityExistsCommand cmd) {
-        try {
-            isNuageVspApiLoaded();
-            NuageVspEntity entityType = null;
-            if (Vlan.class.isAssignableFrom(cmd.getType())) {
-                entityType = NuageVspEntity.SHARED_NETWORK;
-            }
-            boolean exists = _nuageVspApiClient.entityExists(entityType, cmd.getUuid());
-            return new Answer(cmd, exists, "Check if entity with UUID " + cmd.getUuid() + " of type " + entityType + " exists");
-        } catch (ExecutionException | ConfigurationException e) {
-            s_logger.error("Failure during " + cmd + " on Nuage VSD " + _hostName, e);
-            return new Answer(cmd, e);
-        }
     }
 
-    protected void isNuageVspApiLoaded() throws ConfigurationException {
-        if (!_isNuageVspClientLoaded || _nuageVspApiClient == null) {
-            throw new ConfigurationException(NUAGE_VSP_PLUGIN_ERROR_MESSAGE);
-        }
+    public NuageVspGuruClient getNuageVspGuruClient() throws ConfigurationException {
+        assertNuageVspClientsLoaded();
+        return _clientLoader.getNuageVspGuruClient();
     }
 
-    protected void isNuageVspGuruLoaded() throws ConfigurationException {
-        if (!_isNuageVspClientLoaded || _nuageVspGuruClient == null) {
-            throw new ConfigurationException(NUAGE_VSP_PLUGIN_ERROR_MESSAGE);
-        }
+    public NuageVspAclClient getNuageVspAclClient() throws ConfigurationException {
+        assertNuageVspClientsLoaded();
+        return _clientLoader.getNuageVspAclClient();
     }
 
-    protected void isNuageVspElementLoaded() throws ConfigurationException {
-        if (!_isNuageVspClientLoaded || _nuageVspElementClient == null) {
-            throw new ConfigurationException(NUAGE_VSP_PLUGIN_ERROR_MESSAGE);
-        }
+    public NuageVspElementClient getNuageVspElementClient() throws ConfigurationException {
+        assertNuageVspClientsLoaded();
+        return _clientLoader.getNuageVspElementClient();
     }
 
-    protected void isNuageVspManagerLoaded() throws ConfigurationException {
-        if (!_isNuageVspClientLoaded || _nuageVspManagerClient == null) {
-            throw new ConfigurationException(NUAGE_VSP_PLUGIN_ERROR_MESSAGE);
-        }
+    public NuageVspManagerClient getNuageVspManagerClient() throws ConfigurationException {
+        assertNuageVspClientsLoaded();
+        return _clientLoader.getNuageVspManagerClient();
     }
 
-    public static class Configuration {
-        private String _name;
-        private String _guid;
-        private String _zoneId;
-        private String _hostName;
-        private String _cmsUser;
-        private String _cmsUserPassword;
-        private String _port;
-        private String _apiVersion;
-        private String _apiRelativePath;
-        private String _retryCount;
-        private String _retryInterval;
-        private String _nuageVspCmsId;
-
-        public String name() {
-            return this._name;
-        }
-
-        public Configuration name(String name) {
-            this._name = name;
-            return this;
-        }
-
-        public String guid() {
-            return this._guid;
-        }
-
-        public Configuration guid(String guid) {
-            this._guid = guid;
-            return this;
-        }
-
-        public String zoneId() {
-            return this._zoneId;
-        }
-
-        public Configuration zoneId(String zoneId) {
-            this._zoneId = zoneId;
-            return this;
-        }
-
-        public String hostName() {
-            return this._hostName;
-        }
-
-        public Configuration hostName(String hostName) {
-            this._hostName = hostName;
-            return this;
-        }
-
-        public String cmsUser() {
-            return this._cmsUser;
-        }
-
-        public Configuration cmsUser(String cmsUser) {
-            this._cmsUser = cmsUser;
-            return this;
-        }
-
-        public String cmsUserPassword() {
-            return this._cmsUserPassword;
-        }
-
-        public Configuration cmsUserPassword(String cmsUserPassword) {
-            this._cmsUserPassword = cmsUserPassword;
-            return this;
-        }
-
-        public String port() {
-            return this._port;
-        }
-
-        public Configuration port(String port) {
-            this._port = port;
-            return this;
-        }
-
-        public String apiVersion() {
-            return this._apiVersion;
-        }
-
-        public Configuration apiVersion(String apiVersion) {
-            this._apiVersion = apiVersion;
-            return this;
-        }
-
-        public String apiRelativePath() {
-            return this._apiRelativePath;
-        }
-
-        public Configuration apiRelativePath(String apiRelativePath) {
-            this._apiRelativePath = apiRelativePath;
-            return this;
-        }
-
-        public String retryCount() {
-            return this._retryCount;
-        }
-
-        public Configuration retryCount(String retryCount) {
-            this._retryCount = retryCount;
-            return this;
-        }
-
-        public String retryInterval() {
-            return this._retryInterval;
-        }
-
-        public Configuration retryInterval(String retryInterval) {
-            this._retryInterval = retryInterval;
-            return this;
-        }
-
-        public String nuageVspCmsId() {
-            return this._nuageVspCmsId;
-        }
-
-        public Configuration nuageVspCmsId(String nuageVspCmsId) {
-            this._nuageVspCmsId = nuageVspCmsId;
-            return this;
-        }
-
-        public Map<String, String> build() {
-            return new HashMap<String, String>() {{
-                if (_name != null) put(NAME, _name);
-                if (_guid != null) put(GUID, _guid);
-                if (_zoneId != null) put(ZONE_ID, _zoneId);
-                if (_hostName != null) put(HOST_NAME, _hostName);
-                if (_cmsUser != null) put(CMS_USER, _cmsUser);
-                if (_cmsUserPassword != null) put(CMS_USER_PASSWORD, _cmsUserPassword);
-                if (_port != null) put(PORT, _port);
-                if (_apiVersion != null) put(API_VERSION, _apiVersion);
-                if (_apiRelativePath != null) put(API_RELATIVE_PATH, _apiRelativePath);
-                if (_retryCount != null) put(RETRY_COUNT, _retryCount);
-                if (_retryInterval != null) put(RETRY_INTERVAL, _retryInterval);
-                if (_nuageVspCmsId != null) put(NUAGE_VSP_CMS_ID, _nuageVspCmsId);
-            }};
-        }
-
-        public static Configuration fromConfiguration(Map<String, String> configuration) {
-            return new Configuration()
-                    .name(configuration.get(NAME))
-                    .guid(configuration.get(GUID))
-                    .zoneId(configuration.get(ZONE_ID))
-                    .hostName(configuration.get(HOST_NAME))
-                    .cmsUser(configuration.get(CMS_USER))
-                    .cmsUserPassword(configuration.get(CMS_USER_PASSWORD))
-                    .port(configuration.get(PORT))
-                    .apiVersion(configuration.get(API_VERSION))
-                    .apiRelativePath(configuration.get(API_RELATIVE_PATH))
-                    .retryCount(configuration.get(RETRY_COUNT))
-                    .retryInterval(configuration.get(RETRY_INTERVAL))
-                    .nuageVspCmsId(configuration.get(NUAGE_VSP_CMS_ID));
-        }
-    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4c91c9c5/plugins/network-elements/nuage-vsp/src/com/cloud/network/resource/NuageVspResourceConfiguration.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nuage-vsp/src/com/cloud/network/resource/NuageVspResourceConfiguration.java b/plugins/network-elements/nuage-vsp/src/com/cloud/network/resource/NuageVspResourceConfiguration.java
new file mode 100644
index 0000000..1861941
--- /dev/null
+++ b/plugins/network-elements/nuage-vsp/src/com/cloud/network/resource/NuageVspResourceConfiguration.java
@@ -0,0 +1,359 @@
+//
+// 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.network.resource;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+
+import javax.naming.ConfigurationException;
+
+import com.google.common.base.Preconditions;
+import net.nuage.vsp.acs.client.api.model.NuageVspUser;
+import net.nuage.vsp.acs.client.api.model.VspHost;
+import net.nuage.vsp.acs.client.common.NuageVspApiVersion;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang.builder.HashCodeBuilder;
+import org.apache.commons.lang.builder.ToStringBuilder;
+
+import com.cloud.util.NuageVspUtil;
+
+public class NuageVspResourceConfiguration {
+    private static final String NAME = "name";
+    private static final String GUID = "guid";
+    private static final String ZONE_ID = "zoneid";
+    private static final String HOST_NAME = "hostname";
+    private static final String CMS_USER = "cmsuser";
+    private static final String CMS_USER_PASSWORD = "cmsuserpass";
+    private static final String PORT = "port";
+    private static final String API_VERSION = "apiversion";
+    private static final String API_RELATIVE_PATH = "apirelativepath";
+    private static final String RETRY_COUNT = "retrycount";
+    private static final String RETRY_INTERVAL = "retryinterval";
+    private static final String NUAGE_VSP_CMS_ID = "nuagevspcmsid";
+
+    private static final String CMS_USER_ENTEPRISE_NAME = "CSP";
+
+    private String _name;
+    private String _guid;
+    private String _zoneId;
+    private String _hostName;
+    private String _cmsUser;
+    private String _cmsUserPassword;
+    private String _port;
+    private String _apiVersion;
+    private String _apiRelativePath;
+    private String _retryCount;
+    private String _retryInterval;
+    private String _nuageVspCmsId;
+
+    public String name() {
+        return _name;
+    }
+
+    public String guid() {
+        return this._guid;
+    }
+
+    public NuageVspResourceConfiguration guid(String guid) {
+        this._guid = guid;
+        return this;
+    }
+
+    public String zoneId() {
+        return this._zoneId;
+    }
+
+    public NuageVspResourceConfiguration zoneId(String zoneId) {
+        this._zoneId = zoneId;
+        return this;
+    }
+
+    public String hostName() {
+        return this._hostName;
+    }
+
+    public NuageVspResourceConfiguration hostName(String hostName) {
+        this._hostName = hostName;
+        this._name = "Nuage VSD - " + _hostName;
+        return this;
+    }
+
+    public String cmsUser() {
+        return this._cmsUser;
+    }
+
+    public NuageVspResourceConfiguration cmsUser(String cmsUser) {
+        this._cmsUser = cmsUser;
+        return this;
+    }
+
+    public String cmsUserPassword() {
+        return this._cmsUserPassword;
+    }
+
+    public NuageVspResourceConfiguration cmsUserPassword(String cmsUserPassword) {
+        this._cmsUserPassword = cmsUserPassword;
+        return this;
+    }
+
+    public String port() {
+        return this._port;
+    }
+
+    public NuageVspResourceConfiguration port(String port) {
+        this._port = port;
+        return this;
+    }
+
+    public String apiVersion() {
+        return this._apiVersion;
+    }
+
+    public NuageVspResourceConfiguration apiVersion(String apiVersion) {
+        this._apiVersion = apiVersion;
+        return this;
+    }
+
+    public String apiRelativePath() {
+        return this._apiRelativePath;
+    }
+
+    public NuageVspResourceConfiguration apiRelativePath(String apiRelativePath) {
+        this._apiRelativePath = apiRelativePath;
+        return this;
+    }
+
+    public String retryCount() {
+        return this._retryCount;
+    }
+
+    public NuageVspResourceConfiguration retryCount(String retryCount) {
+        this._retryCount = retryCount;
+        return this;
+    }
+
+    public String retryInterval() {
+        return this._retryInterval;
+    }
+
+    public NuageVspResourceConfiguration retryInterval(String retryInterval) {
+        this._retryInterval = retryInterval;
+        return this;
+    }
+
+    public String nuageVspCmsId() {
+        return this._nuageVspCmsId;
+    }
+
+    public NuageVspResourceConfiguration nuageVspCmsId(String nuageVspCmsId) {
+        this._nuageVspCmsId = nuageVspCmsId;
+        return this;
+    }
+
+    public String getRootPath(){
+        return "https://" + _hostName + ":" + _port + "/nuage";
+    }
+
+    public String getApiPath() {
+            return "https://" + _hostName + ":" + _port + "/nuage/api/" + _apiVersion;
+    }
+
+    public NuageVspApiVersion getApiVersion() throws ConfigurationException {
+        try {
+            if(_apiVersion != null) {
+                return NuageVspApiVersion.fromString(_apiVersion);
+            }
+            return null;
+        } catch (IllegalArgumentException e) {
+            throw new ConfigurationException("Incorrect API version");
+        }
+    }
+
+    public Map<String, String> build() {
+        Map<String, String> map = new HashMap<>();
+        putIfPresent(map, GUID, _guid);
+        putIfPresent(map, ZONE_ID, _zoneId);
+        putIfPresent(map, HOST_NAME, _hostName);
+        putIfPresent(map, CMS_USER, _cmsUser);
+        putIfPresent(map, CMS_USER_PASSWORD, _cmsUserPassword);
+        putIfPresent(map, PORT, _port);
+        putIfPresent(map, API_VERSION, _apiVersion);
+        putIfPresent(map, API_RELATIVE_PATH, _apiRelativePath);
+        putIfPresent(map, RETRY_COUNT, _retryCount);
+        putIfPresent(map, RETRY_INTERVAL, _retryInterval);
+        putIfPresent(map, NUAGE_VSP_CMS_ID, _nuageVspCmsId);
+        return  map;
+    }
+
+    private void putIfPresent(Map<String, String> map, String key, String value) {
+        Preconditions.checkNotNull(map);
+        Preconditions.checkNotNull(key);
+
+        if (value != null) {
+            map.put(key, value);
+        }
+    }
+
+    public static NuageVspResourceConfiguration fromConfiguration(Map<String, ?> configuration) {
+        return new NuageVspResourceConfiguration()
+                .guid((String)configuration.get(GUID))
+                .zoneId((String)configuration.get(ZONE_ID))
+                .hostName((String)configuration.get(HOST_NAME))
+                .cmsUser((String)configuration.get(CMS_USER))
+                .cmsUserPassword((String)configuration.get(CMS_USER_PASSWORD))
+                .port((String)configuration.get(PORT))
+                .apiVersion((String)configuration.get(API_VERSION))
+                .apiRelativePath((String)configuration.get(API_RELATIVE_PATH))
+                .retryCount((String)configuration.get(RETRY_COUNT))
+                .retryInterval((String)configuration.get(RETRY_INTERVAL))
+                .nuageVspCmsId((String)configuration.get(NUAGE_VSP_CMS_ID));
+    }
+
+    private void verifyNotNull(String name, String value) throws ConfigurationException {
+        if (value == null) {
+            throw new ConfigurationException("Unable to find " + name);
+        }
+    }
+
+    private void verifyNotEmpty(String name, String value) throws ConfigurationException {
+        if (StringUtils.isEmpty(value)) {
+            throw new ConfigurationException("Unable to find " + name);
+        }
+    }
+
+    private int verifyInRange(String name, String value, int min, int max) throws ConfigurationException {
+        verifyNotEmpty(name, value);
+
+        int parsedValue;
+        try {
+            parsedValue = Integer.parseInt(value);
+        } catch (NumberFormatException ex) {
+            throw new ConfigurationException(name + " has to be between " + min + " and " + max);
+        }
+        if ((parsedValue < min) || (parsedValue > max)) {
+            throw new ConfigurationException(name + " has to be between " + min + " and " + max);
+        }
+        return parsedValue;
+    }
+
+    public void validate() throws ConfigurationException {
+        verifyNotNull("name", _name);
+        verifyNotNull("guid", _guid);
+        verifyNotNull("zone", _zoneId);
+        verifyNotNull("hostname", _hostName);
+        verifyNotNull("CMS username", _cmsUser);
+        verifyNotNull("CMS password", _cmsUserPassword);
+        verifyNotEmpty("API version", _apiVersion);
+
+        try {
+                new NuageVspApiVersion(_apiVersion);
+        } catch(IllegalArgumentException e) {
+            throw new ConfigurationException("Incorrect API version");
+        }
+
+        verifyNotEmpty("number of retries", _retryCount);
+        verifyNotEmpty("retry interval", _retryInterval);
+    }
+
+    public int parseRetryCount() throws ConfigurationException {
+        return verifyInRange("Number of retries", _retryCount, 1, 10);
+    }
+
+    public int parseRetryInterval() throws ConfigurationException {
+        return verifyInRange("Retry interval", _retryInterval, 1, 10000);
+    }
+
+    public VspHost buildVspHost() throws ConfigurationException {
+        return new VspHost.Builder()
+                .cmsUser(new NuageVspUser(CMS_USER_ENTEPRISE_NAME, _cmsUser,  NuageVspUtil.decodePassword(_cmsUserPassword)))
+                .apiVersion(getApiVersion())
+                .restRelativePath(getApiPath())
+                .rootPath(getRootPath())
+                .nuageVspCmsId(_nuageVspCmsId)
+                .noofRetry(parseRetryCount())
+                .retryInterval(parseRetryInterval())
+                .build();
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) {
+            return true;
+        }
+
+        if (!(o instanceof NuageVspResourceConfiguration)) {
+            return false;
+        }
+
+        NuageVspResourceConfiguration that = (NuageVspResourceConfiguration) o;
+
+        return super.equals(that)
+                && Objects.equals(_name, that._name)
+                && Objects.equals(_guid, that._guid)
+                && Objects.equals(_zoneId, that._zoneId)
+                && Objects.equals(_hostName, that._hostName)
+                && Objects.equals(_cmsUser, that._cmsUser)
+                && Objects.equals(_cmsUserPassword, that._cmsUserPassword)
+                && Objects.equals(_port, that._port)
+                && Objects.equals(_apiVersion, that._apiVersion)
+                && Objects.equals(_apiRelativePath, that._apiRelativePath)
+                && Objects.equals(_retryCount, that._retryCount)
+                && Objects.equals(_retryInterval, that._retryInterval)
+                && Objects.equals(_nuageVspCmsId, that._nuageVspCmsId);
+    }
+
+    @Override
+    public int hashCode() {
+        return new HashCodeBuilder()
+                .appendSuper(super.hashCode())
+                .append(_name)
+                .append(_guid)
+                .append(_zoneId)
+                .append(_hostName)
+                .append(_cmsUser)
+                .append(_cmsUserPassword)
+                .append(_port)
+                .append(_apiVersion)
+                .append(_apiRelativePath)
+                .append(_retryCount)
+                .append(_retryInterval)
+                .append(_nuageVspCmsId)
+                .toHashCode();
+    }
+
+    @Override public String toString() {
+        return new ToStringBuilder(this)
+                .append("_name", _name)
+                .append("_guid", _guid)
+                .append("_zoneId", _zoneId)
+                .append("_hostName", _hostName)
+                .append("_cmsUser", _cmsUser)
+                .append("_cmsUserPassword", _cmsUserPassword)
+                .append("_port", _port)
+                .append("_apiVersion", _apiVersion)
+                .append("_apiRelativePath", _apiRelativePath)
+                .append("_retryCount", _retryCount)
+                .append("_retryInterval", _retryInterval)
+                .append("_nuageVspCmsId", _nuageVspCmsId)
+                .toString();
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4c91c9c5/plugins/network-elements/nuage-vsp/src/com/cloud/network/vsp/resource/wrapper/NuageVspApiSupportCommandWrapper.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nuage-vsp/src/com/cloud/network/vsp/resource/wrapper/NuageVspApiSupportCommandWrapper.java b/plugins/network-elements/nuage-vsp/src/com/cloud/network/vsp/resource/wrapper/NuageVspApiSupportCommandWrapper.java
new file mode 100644
index 0000000..1e84e20
--- /dev/null
+++ b/plugins/network-elements/nuage-vsp/src/com/cloud/network/vsp/resource/wrapper/NuageVspApiSupportCommandWrapper.java
@@ -0,0 +1,41 @@
+//
+// 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.network.vsp.resource.wrapper;
+
+import javax.naming.ConfigurationException;
+
+import net.nuage.vsp.acs.client.exception.NuageVspException;
+
+import com.cloud.agent.api.manager.SupportedApiVersionCommand;
+import com.cloud.network.resource.NuageVspResource;
+import com.cloud.resource.ResourceWrapper;
+
+@ResourceWrapper(handles =  SupportedApiVersionCommand.class)
+public final class NuageVspApiSupportCommandWrapper extends NuageVspCommandWrapper<SupportedApiVersionCommand> {
+
+    @Override public boolean executeNuageVspCommand(SupportedApiVersionCommand cmd, NuageVspResource nuageVspResource) throws ConfigurationException, NuageVspException {
+        return nuageVspResource.getNuageVspManagerClient().isSupportedApiVersion(cmd.getApiVersion());
+    }
+
+    @Override public StringBuilder fillDetail(StringBuilder stringBuilder, SupportedApiVersionCommand cmd) {
+        return stringBuilder.append("Check if API version ").append(cmd.getApiVersion()).append(" is supported");
+    }
+
+}
\ No newline at end of file