cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sw...@apache.org
Subject [21/39] git commit: updated refs/heads/master to 3c800b4
Date Thu, 26 May 2016 03:06:00 GMT
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b0c27e48/plugins/network-elements/nuage-vsp/src/com/cloud/network/guru/NuageVspGuestNetworkGuru.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nuage-vsp/src/com/cloud/network/guru/NuageVspGuestNetworkGuru.java b/plugins/network-elements/nuage-vsp/src/com/cloud/network/guru/NuageVspGuestNetworkGuru.java
index 2037d92..a6c17e3 100644
--- a/plugins/network-elements/nuage-vsp/src/com/cloud/network/guru/NuageVspGuestNetworkGuru.java
+++ b/plugins/network-elements/nuage-vsp/src/com/cloud/network/guru/NuageVspGuestNetworkGuru.java
@@ -31,18 +31,14 @@ import com.cloud.dc.DataCenter.NetworkType;
 import com.cloud.dc.VlanVO;
 import com.cloud.deploy.DeployDestination;
 import com.cloud.deploy.DeploymentPlan;
-import com.cloud.domain.Domain;
-import com.cloud.domain.DomainVO;
 import com.cloud.domain.dao.DomainDao;
 import com.cloud.exception.ConcurrentOperationException;
 import com.cloud.exception.InsufficientAddressCapacityException;
 import com.cloud.exception.InsufficientVirtualNetworkCapacityException;
 import com.cloud.host.HostVO;
 import com.cloud.host.dao.HostDao;
-import com.cloud.network.IpAddress;
 import com.cloud.network.Network;
 import com.cloud.network.Network.GuestType;
-import com.cloud.network.Network.Service;
 import com.cloud.network.Network.State;
 import com.cloud.network.NetworkProfile;
 import com.cloud.network.Networks;
@@ -50,11 +46,12 @@ import com.cloud.network.NuageVspDeviceVO;
 import com.cloud.network.PhysicalNetwork;
 import com.cloud.network.PhysicalNetwork.IsolationMethod;
 import com.cloud.network.dao.IPAddressVO;
+import com.cloud.network.dao.NetworkDetailVO;
+import com.cloud.network.dao.NetworkDetailsDao;
 import com.cloud.network.dao.NetworkVO;
 import com.cloud.network.dao.NuageVspDao;
 import com.cloud.network.dao.PhysicalNetworkVO;
 import com.cloud.network.manager.NuageVspManager;
-import com.cloud.network.vpc.Vpc;
 import com.cloud.network.vpc.dao.VpcDao;
 import com.cloud.offering.NetworkOffering;
 import com.cloud.offerings.dao.NetworkOfferingDao;
@@ -62,28 +59,25 @@ import com.cloud.offerings.dao.NetworkOfferingServiceMapDao;
 import com.cloud.user.Account;
 import com.cloud.user.AccountVO;
 import com.cloud.user.dao.AccountDao;
-import com.cloud.util.NuageVspUtil;
+import com.cloud.utils.StringUtils;
 import com.cloud.utils.db.DB;
 import com.cloud.utils.exception.CloudRuntimeException;
-import com.cloud.utils.net.NetUtils;
 import com.cloud.vm.NicProfile;
 import com.cloud.vm.NicVO;
 import com.cloud.vm.ReservationContext;
-import com.cloud.vm.VirtualMachine;
 import com.cloud.vm.VirtualMachineProfile;
 import com.google.common.base.Strings;
-import org.apache.commons.lang.StringUtils;
+import com.cloud.util.NuageVspEntityBuilder;
+import net.nuage.vsp.acs.client.api.model.VspNetwork;
+import net.nuage.vsp.acs.client.api.model.VspNic;
+import net.nuage.vsp.acs.client.api.model.VspStaticNat;
+import net.nuage.vsp.acs.client.api.model.VspVm;
+import org.apache.cloudstack.resourcedetail.VpcDetailVO;
+import org.apache.cloudstack.resourcedetail.dao.VpcDetailsDao;
 import org.apache.log4j.Logger;
 
 import javax.inject.Inject;
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Iterator;
 import java.util.List;
-import java.util.Set;
-import java.util.TreeSet;
 
 public class NuageVspGuestNetworkGuru extends GuestNetworkGuru {
     public static final Logger s_logger = Logger.getLogger(NuageVspGuestNetworkGuru.class);
@@ -108,6 +102,12 @@ public class NuageVspGuestNetworkGuru extends GuestNetworkGuru {
     NuageVspManager _nuageVspManager;
     @Inject
     ConfigurationManager _configMgr;
+    @Inject
+    NuageVspEntityBuilder _nuageVspEntityBuilder;
+    @Inject
+    NetworkDetailsDao _networkDetailsDao;
+    @Inject
+    VpcDetailsDao _vpcDetailsDao;
 
     public NuageVspGuestNetworkGuru() {
         super();
@@ -148,6 +148,15 @@ public class NuageVspGuestNetworkGuru extends GuestNetworkGuru {
                 throw new IllegalStateException("Network " + networkId + " is not in expected state Implementing, but is in state " + network.getState());
             }
 
+            //Get the Account details and find the type
+            AccountVO networksAccount = _accountDao.findById(network.getAccountId());
+            if (networksAccount.getType() == Account.ACCOUNT_TYPE_PROJECT) {
+                String errorMessage = "Networks created by account " + networksAccount.getAccountName() + " of type Project (" + Account.ACCOUNT_TYPE_PROJECT + ") " +
+                        "are not yet supported by NuageVsp provider";
+                s_logger.error(errorMessage);
+                throw new InsufficientVirtualNetworkCapacityException(errorMessage, Account.class, network.getAccountId());
+            }
+
             long dcId = dest.getDataCenter().getId();
             //Get physical network id
             Long physicalNetworkId = network.getPhysicalNetworkId();
@@ -155,80 +164,29 @@ public class NuageVspGuestNetworkGuru extends GuestNetworkGuru {
             if (physicalNetworkId == null) {
                 physicalNetworkId = _networkModel.findPhysicalNetworkId(dcId, offering.getTags(), offering.getTrafficType());
             }
-            implemented = new NetworkVO(network.getTrafficType(), network.getMode(), network.getBroadcastDomainType(), network.getNetworkOfferingId(), State.Allocated,
-                    network.getDataCenterId(), physicalNetworkId, offering.getRedundantRouter());
+
+            implemented = new NetworkVO(network.getId(), network, network.getNetworkOfferingId(), network.getGuruName(), network.getDomainId(), network.getAccountId(),
+                    network.getRelated(), network.getName(), network.getDisplayText(), network.getNetworkDomain(), network.getGuestType(), network.getDataCenterId(),
+                    physicalNetworkId, network.getAclType(), network.getSpecifyIpRanges(), network.getVpcId(), offering.getRedundantRouter());
+            implemented.setUuid(network.getUuid());
+            implemented.setState(State.Allocated);
             if (network.getGateway() != null) {
                 implemented.setGateway(network.getGateway());
             }
             if (network.getCidr() != null) {
                 implemented.setCidr(network.getCidr());
             }
-            List<String[]> ipAddressRanges = new ArrayList<String[]>();
-            String virtualRouterIp = getVirtualRouterIP(network, ipAddressRanges);
-            String networkUuid = implemented.getUuid();
+
+            VspNetwork vspNetwork = _nuageVspEntityBuilder.buildVspNetwork(implemented, true);
             String tenantId = context.getDomain().getName() + "-" + context.getAccount().getAccountId();
-            String broadcastUriStr = networkUuid + "/" + virtualRouterIp;
+            String broadcastUriStr = implemented.getUuid() + "/" + vspNetwork.getVirtualRouterIp();
             implemented.setBroadcastUri(Networks.BroadcastDomainType.Vsp.toUri(broadcastUriStr));
             implemented.setBroadcastDomainType(Networks.BroadcastDomainType.Vsp);
-            //Check if the network is associated to a VPC
-            Long vpcId = network.getVpcId();
-            boolean isVpc = (vpcId != null);
-            //Check owner of the Network
-            Domain networksDomain = _domainDao.findById(network.getDomainId());
-            //Get the Account details and find the type
-            AccountVO networksAccount = _accountDao.findById(network.getAccountId());
-            if (networksAccount.getType() == Account.ACCOUNT_TYPE_PROJECT) {
-                String errorMessage = "Networks created by account " + networksAccount.getAccountName() + " of type Project (" + Account.ACCOUNT_TYPE_PROJECT + ") " +
-                        "are not yet supported by NuageVsp provider";
-                s_logger.error(errorMessage);
-                throw new InsufficientVirtualNetworkCapacityException(errorMessage, Account.class, network.getAccountId());
-            }
-            String vpcName = null;
-            String vpcUuid = null;
-            String preConfiguredDomainTemplateName = NuageVspUtil.getPreConfiguredDomainTemplateName(_configDao, network, offering);
-            boolean isSharedNetwork = offering.getGuestType() == GuestType.Shared;
-            boolean isL3Network = !isVpc && (isSharedNetwork || isL3Network(network));
-
-            if (isVpc) {
-                Vpc vpcObj = _vpcDao.findById(vpcId);
-                vpcName = vpcObj.getName();
-                vpcUuid = vpcObj.getUuid();
-            }
-
-            if (isSharedNetwork) {
-                List<VlanVO> vlans = _vlanDao.listVlansByNetworkId(network.getId());
-                for (VlanVO vlan : vlans) {
-                    boolean isIpv4 = StringUtils.isNotBlank(vlan.getIpRange());
-                    String[] range = isIpv4 ? vlan.getIpRange().split("-") : vlan.getIp6Range().split("-");
-                    ipAddressRanges.add(range);
-                }
-            }
 
             HostVO nuageVspHost = getNuageVspHost(physicalNetworkId);
             List<String> dnsServers = _nuageVspManager.getDnsDetails(network);
-            List<String> gatewaySystemIds = _nuageVspManager.getGatewaySystemIds();
-            ImplementNetworkVspCommand.Builder cmdBuilder = new ImplementNetworkVspCommand.Builder()
-                    .networkDomainName(networksDomain.getName())
-                    .networkDomainPath(networksDomain.getPath())
-                    .networkDomainUuid(networksDomain.getUuid())
-                    .networkAccountName(networksAccount.getAccountName())
-                    .networkAccountUuid(networksAccount.getUuid())
-                    .networkName(network.getName())
-                    .networkCidr(network.getCidr())
-                    .networkGateway(network.getGateway())
-                    .networkAclId(network.getNetworkACLId())
-                    .dnsServers(dnsServers)
-                    .gatewaySystemIds(gatewaySystemIds)
-                    .networkUuid(network.getUuid())
-                    .isL3Network(isL3Network)
-                    .isVpc(isVpc)
-                    .isSharedNetwork(isSharedNetwork)
-                    .vpcName(vpcName)
-                    .vpcUuid(vpcUuid)
-                    .defaultEgressPolicy(offering.getEgressDefaultPolicy())
-                    .ipAddressRange(ipAddressRanges)
-                    .domainTemplateName(preConfiguredDomainTemplateName);
-            Answer answer = _agentMgr.easySend(nuageVspHost.getId(), cmdBuilder.build());
+            ImplementNetworkVspCommand cmd = new ImplementNetworkVspCommand(vspNetwork, dnsServers);
+            Answer answer = _agentMgr.easySend(nuageVspHost.getId(), cmd);
 
             if (answer == null || !answer.getResult()) {
                 s_logger.error("ImplementNetworkVspCommand for network " + network.getUuid() + " failed on Nuage VSD " + nuageVspHost.getDetail("hostname"));
@@ -237,7 +195,18 @@ public class NuageVspGuestNetworkGuru extends GuestNetworkGuru {
                 }
                 return null;
             }
-            s_logger.info("Implemented OK, network " + networkUuid + " in tenant " + tenantId + " linked to " + implemented.getBroadcastUri());
+
+            if (StringUtils.isNotBlank(vspNetwork.getDomainTemplateName())) {
+                if (network.getVpcId() != null) {
+                    VpcDetailVO vpcDetail = new VpcDetailVO(network.getVpcId(), NuageVspManager.nuageDomainTemplateDetailName, vspNetwork.getDomainTemplateName(), false);
+                    _vpcDetailsDao.persist(vpcDetail);
+                } else {
+                    NetworkDetailVO networkDetail = new NetworkDetailVO(implemented.getId(), NuageVspManager.nuageDomainTemplateDetailName, vspNetwork.getDomainTemplateName(), false);
+                    _networkDetailsDao.persist(networkDetail);
+                }
+            }
+
+            s_logger.info("Implemented OK, network " + implemented.getUuid() + " in tenant " + tenantId + " linked to " + implemented.getBroadcastUri());
         } finally {
             _networkDao.releaseFromLockTable(network.getId());
         }
@@ -262,68 +231,38 @@ public class NuageVspGuestNetworkGuru extends GuestNetworkGuru {
             if (s_logger.isDebugEnabled()) {
                 s_logger.debug("Handling reserve() call back to with Create a new VM or add an interface to existing VM in network " + network.getName());
             }
-            nic.setBroadcastUri(network.getBroadcastUri());
-            nic.setIsolationUri(network.getBroadcastUri());
+
             DataCenter dc = _dcDao.findById(network.getDataCenterId());
-            Account networksAccount = _accountDao.findById(network.getAccountId());
-            DomainVO networksDomain = _domainDao.findById(network.getDomainId());
-            //Get the Account details and find the type
-            long networkOwnedBy = network.getAccountId();
-            AccountVO neworkAccountDetails = _accountDao.findById(networkOwnedBy);
+            AccountVO neworkAccountDetails = _accountDao.findById(network.getAccountId());
             if (neworkAccountDetails.getType() == Account.ACCOUNT_TYPE_PROJECT) {
                 throw new InsufficientVirtualNetworkCapacityException("CS project support is not yet implemented in NuageVsp", DataCenter.class, dc.getId());
             }
 
-            //NicProfile does not contain the NIC UUID. We need this information to set it in the VMInterface and VPort
-            //that we create in VSP
-            NicVO nicFrmDB = _nicDao.findById(nic.getId());
-            NetworkOffering networkOffering = _ntwkOfferingDao.findById(network.getNetworkOfferingId());
-            boolean isDomainRouter = vm.getType().equals(VirtualMachine.Type.DomainRouter);
-            URI broadcastUri = network.getBroadcastUri();
-            if (Strings.isNullOrEmpty(broadcastUri.getPath()) || !broadcastUri.getPath().startsWith("/")) {
+            if (Strings.isNullOrEmpty(network.getBroadcastUri().getPath()) || !network.getBroadcastUri().getPath().startsWith("/")) {
                 throw new IllegalStateException("The broadcast URI path " + network.getBroadcastUri() + " is empty or in an incorrect format.");
             }
-            String domainRouterIp = network.getBroadcastUri().getPath().substring(1);
-            boolean isL3Network = isL3Network(network);
-            boolean isSharedNetwork = networkOffering.getGuestType() == GuestType.Shared;
-            Long vpcId = network.getVpcId();
-            String vpcUuid = null;
-            if (vpcId != null) {
-                Vpc vpcObj = _vpcDao.findById(vpcId);
-                vpcUuid = vpcObj.getUuid();
-            }
-            HostVO nuageVspHost = getNuageVspHost(network.getPhysicalNetworkId());
+
+            nic.setBroadcastUri(network.getBroadcastUri());
+            nic.setIsolationUri(network.getBroadcastUri());
+
+            //NicProfile does not contain the NIC UUID. We need this information to set it in the VMInterface and VPort
+            //that we create in VSP
+            NicVO nicFromDb = _nicDao.findById(nic.getId());
             IPAddressVO staticNatIp = _ipAddressDao.findByVmIdAndNetworkId(network.getId(), vm.getId());
 
-            ReserveVmInterfaceVspCommand.Builder cmdBuilder = new ReserveVmInterfaceVspCommand.Builder()
-                    .nicUuid(nicFrmDB.getUuid())
-                    .nicMacAddress(nic.getMacAddress())
-                    .networkUuid(network.getUuid())
-                    .isL3Network(isL3Network)
-                    .isSharedNetwork(isSharedNetwork)
-                    .vpcUuid(vpcUuid)
-                    .networkDomainUuid(networksDomain.getUuid())
-                    .networksAccountUuid(networksAccount.getUuid())
-                    .isDomainRouter(isDomainRouter)
-                    .domainRouterIp(domainRouterIp)
-                    .vmInstanceName(vm.getInstanceName())
-                    .vmUuid(vm.getUuid())
-                    .vmUserName(networksDomain.getUuid())
-                    .vmUserDomainName(networksAccount.getUuid())
-                    .useStaticIp(true)
-                    .staticIp(nic.getIPv4Address());
+            VspNetwork vspNetwork = _nuageVspEntityBuilder.buildVspNetwork(network, false);
+            VspVm vspVm = _nuageVspEntityBuilder.buildVspVm(vm.getVirtualMachine(), network);
+            VspNic vspNic = _nuageVspEntityBuilder.buildVspNic(nicFromDb.getUuid(), nic);
+            VspStaticNat vspStaticNat = null;
             if (staticNatIp != null) {
                 VlanVO staticNatVlan = _vlanDao.findById(staticNatIp.getVlanId());
-                cmdBuilder = cmdBuilder.staticNatIpUuid(staticNatIp.getUuid())
-                        .staticNatIpAddress(staticNatIp.getAddress().addr())
-                        .isStaticNatIpAllocated(staticNatIp.getState().equals(IpAddress.State.Allocated))
-                        .isOneToOneNat(staticNatIp.isOneToOneNat())
-                        .staticNatVlanUuid(staticNatVlan.getUuid())
-                        .staticNatVlanGateway(staticNatVlan.getVlanGateway())
-                        .staticNatVlanNetmask(staticNatVlan.getVlanNetmask());
+                vspStaticNat = _nuageVspEntityBuilder.buildVspStaticNat(null, staticNatIp, staticNatVlan, null);
             }
 
-            Answer answer = _agentMgr.easySend(nuageVspHost.getId(), cmdBuilder.build());
+            HostVO nuageVspHost = getNuageVspHost(network.getPhysicalNetworkId());
+            ReserveVmInterfaceVspCommand cmd = new ReserveVmInterfaceVspCommand(vspNetwork, vspVm, vspNic, vspStaticNat);
+            Answer answer = _agentMgr.easySend(nuageVspHost.getId(), cmd);
+
             if (answer == null || !answer.getResult()) {
                 s_logger.error("ReserveVmInterfaceNuageVspCommand failed for NIC " + nic.getId() + " attached to VM " + vm.getId() + " in network " + network.getId());
                 if ((null != answer) && (null != answer.getDetails())) {
@@ -332,8 +271,8 @@ public class NuageVspGuestNetworkGuru extends GuestNetworkGuru {
                 throw new InsufficientVirtualNetworkCapacityException("Failed to reserve VM in Nuage VSP.", Network.class, network.getId());
             }
 
-            if (isDomainRouter) {
-                nic.setIPv4Address(domainRouterIp);
+            if (vspVm.getDomainRouter() == Boolean.TRUE) {
+                nic.setIPv4Address(vspVm.getDomainRouterIp());
             }
 
         } finally {
@@ -378,32 +317,16 @@ public class NuageVspGuestNetworkGuru extends GuestNetworkGuru {
                 s_logger.debug("Handling deallocate() call back, which is called when a VM is destroyed or interface is removed, " + "to delete VM Interface with IP "
                         + nic.getIPv4Address() + " from a VM " + vm.getInstanceName() + " with state " + vm.getVirtualMachine().getState());
             }
-            DomainVO networksDomain = _domainDao.findById(network.getDomainId());
-            NicVO nicFrmDd = _nicDao.findById(nic.getId());
-            NetworkOffering networkOffering = _ntwkOfferingDao.findById(network.getNetworkOfferingId());
-            boolean isL3Network = isL3Network(network);
-            boolean isSharedNetwork = networkOffering.getGuestType() == GuestType.Shared;
-            boolean isExpunging = vm.getVirtualMachine().getState() == VirtualMachine.State.Expunging;
-            Long vpcId = network.getVpcId();
-            String vpcUuid = null;
-            if (vpcId != null) {
-                Vpc vpcObj = _vpcDao.findById(vpcId);
-                vpcUuid = vpcObj.getUuid();
-            }
+
+            NicVO nicFromDb = _nicDao.findById(nic.getId());
+
+            VspNetwork vspNetwork = _nuageVspEntityBuilder.buildVspNetwork(network, false);
+            VspVm vspVm = _nuageVspEntityBuilder.buildVspVm(vm.getVirtualMachine(), network);
+            VspNic vspNic = _nuageVspEntityBuilder.buildVspNic(nicFromDb.getUuid(), nic);
             HostVO nuageVspHost = getNuageVspHost(network.getPhysicalNetworkId());
-            DeallocateVmVspCommand.Builder cmdBuilder = new DeallocateVmVspCommand.Builder()
-                    .networkUuid(network.getUuid())
-                    .nicFromDbUuid(nicFrmDd.getUuid())
-                    .nicMacAddress(nic.getMacAddress())
-                    .nicIp4Address(nic.getIPv4Address())
-                    .isL3Network(isL3Network)
-                    .isSharedNetwork(isSharedNetwork)
-                    .vpcUuid(vpcUuid)
-                    .networksDomainUuid(networksDomain.getUuid())
-                    .vmInstanceName(vm.getInstanceName())
-                    .vmUuid(vm.getUuid())
-                    .isExpungingState(isExpunging);
-            Answer answer = _agentMgr.easySend(nuageVspHost.getId(), cmdBuilder.build());
+
+            DeallocateVmVspCommand cmd = new DeallocateVmVspCommand(vspNetwork, vspVm, vspNic);
+            Answer answer = _agentMgr.easySend(nuageVspHost.getId(), cmd);
             if (answer == null || !answer.getResult()) {
                 s_logger.error("DeallocateVmNuageVspCommand for VM " + vm.getUuid() + " failed on Nuage VSD " + nuageVspHost.getDetail("hostname"));
                 if ((null != answer) && (null != answer.getDetails())) {
@@ -451,27 +374,10 @@ public class NuageVspGuestNetworkGuru extends GuestNetworkGuru {
             if (s_logger.isDebugEnabled()) {
                 s_logger.debug("Handling trash() call back to delete the network " + network.getName() + " with uuid " + network.getUuid() + " from VSP");
             }
-            long domainId = network.getDomainId();
-            Domain domain = _domainDao.findById(domainId);
-            boolean isL3Network = isL3Network(network);
-            boolean isSharedNetwork = offering.getGuestType() == GuestType.Shared;
-            Long vpcId = network.getVpcId();
-            String vpcUuid = null;
-            if (vpcId != null) {
-                Vpc vpcObj = _vpcDao.findById(vpcId);
-                vpcUuid = vpcObj.getUuid();
-            }
-
-            String preConfiguredDomainTemplateName = NuageVspUtil.getPreConfiguredDomainTemplateName(_configDao, network, offering);
+            VspNetwork vspNetwork = _nuageVspEntityBuilder.buildVspNetwork(network, false);
             HostVO nuageVspHost = getNuageVspHost(network.getPhysicalNetworkId());
-            TrashNetworkVspCommand.Builder cmdBuilder = new TrashNetworkVspCommand.Builder()
-                    .domainUuid(domain.getUuid())
-                    .networkUuid(network.getUuid())
-                    .isL3Network(isL3Network)
-                    .isSharedNetwork(isSharedNetwork)
-                    .vpcUuid(vpcUuid)
-                    .domainTemplateName(preConfiguredDomainTemplateName);
-            Answer answer = _agentMgr.easySend(nuageVspHost.getId(), cmdBuilder.build());
+            TrashNetworkVspCommand cmd = new TrashNetworkVspCommand(vspNetwork);
+            Answer answer = _agentMgr.easySend(nuageVspHost.getId(), cmd);
             if (answer == null || !answer.getResult()) {
                 s_logger.error("TrashNetworkNuageVspCommand for network " + network.getUuid() + " failed");
                 if ((null != answer) && (null != answer.getDetails())) {
@@ -485,51 +391,6 @@ public class NuageVspGuestNetworkGuru extends GuestNetworkGuru {
         return super.trash(network, offering);
     }
 
-    private String getVirtualRouterIP(Network network, Collection<String[]> ipAddressRanges) throws InsufficientVirtualNetworkCapacityException {
-        String virtualRouterIp;
-        //Check if the subnet has minimum 5 host in it.
-        String subnet = NetUtils.getCidrSubNet(network.getCidr());
-        String netmask = NetUtils.getCidrNetmask(network.getCidr());
-        long cidrSize = NetUtils.getCidrSize(netmask);
-
-        Set<Long> allIPsInCidr = NetUtils.getAllIpsFromCidr(subnet, cidrSize, new HashSet<Long>());
-        if (allIPsInCidr == null || !(allIPsInCidr instanceof TreeSet)) {
-            throw new IllegalStateException("The IPs in CIDR for subnet " + subnet + " where null or returned in a non-ordered set.");
-        }
-
-        if (allIPsInCidr.size() > 3) {
-            //get the second IP and see if it the networks GatewayIP
-            Iterator<Long> ipIterator = allIPsInCidr.iterator();
-            long vip = ipIterator.next();
-            if (NetUtils.ip2Long(network.getGateway()) == vip) {
-                vip = ipIterator.next();
-                virtualRouterIp = NetUtils.long2Ip(vip);
-                if (s_logger.isDebugEnabled()) {
-                    s_logger.debug("1st IP is used as gateway IP. Reserving " + virtualRouterIp + " for the Virtual Router IP for Network(" + network.getName() + ")");
-                }
-            } else {
-                virtualRouterIp = NetUtils.long2Ip(vip);
-                if (s_logger.isDebugEnabled()) {
-                    s_logger.debug("1st IP is not used as the gateway IP. Reserving" + virtualRouterIp + " for the Virtual Router IP for Network(" + network.getName() + ")");
-                }
-            }
-            ipAddressRanges.add(new String[] {
-                NetUtils.long2Ip(ipIterator.next()),
-                NetUtils.getIpRangeEndIpFromCidr(subnet, cidrSize)
-            });
-            return virtualRouterIp;
-        }
-
-        throw new InsufficientVirtualNetworkCapacityException("VSP allocates an IP for VirtualRouter." + " So, subnet should have atleast minimum 4 hosts ", Network.class,
-                network.getId());
-    }
-
-    private boolean isL3Network(Network network) {
-        return _ntwkOfferingSrvcDao.areServicesSupportedByNetworkOffering(network.getNetworkOfferingId(), Service.SourceNat)
-                || _ntwkOfferingSrvcDao.areServicesSupportedByNetworkOffering(network.getNetworkOfferingId(), Service.StaticNat)
-                || network.getGuestType() == GuestType.Shared;
-    }
-
     private HostVO getNuageVspHost(long physicalNetworkId) {
         HostVO nuageVspHost;
         List<NuageVspDeviceVO> nuageVspDevices = _nuageVspDao.listByPhysicalNetwork(physicalNetworkId);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b0c27e48/plugins/network-elements/nuage-vsp/src/com/cloud/network/manager/NuageVspManager.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nuage-vsp/src/com/cloud/network/manager/NuageVspManager.java b/plugins/network-elements/nuage-vsp/src/com/cloud/network/manager/NuageVspManager.java
index 0aae22c..4861fb2 100644
--- a/plugins/network-elements/nuage-vsp/src/com/cloud/network/manager/NuageVspManager.java
+++ b/plugins/network-elements/nuage-vsp/src/com/cloud/network/manager/NuageVspManager.java
@@ -40,6 +40,8 @@ public interface NuageVspManager extends PluggableService {
 
     static final String nuageVPCOfferingDisplayText = "Nuage VSP VPC Offering";
 
+    static final String nuageDomainTemplateDetailName = "domainTemplateName";
+
     static final ConfigKey<Boolean> NuageVspConfigDns = new ConfigKey<Boolean>(Boolean.class, "nuagevsp.configure.dns", "Advanced", "true",
             "Defines if NuageVsp plugin needs to configure DNS setting for a VM or not. True will configure the DNS and false will not configure the DNS settings", true,
             Scope.Global, null);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b0c27e48/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 f38a9c7..04b1ccc 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
@@ -27,8 +27,8 @@ 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.GetClientDefaultsAnswer;
-import com.cloud.agent.api.manager.GetClientDefaultsCommand;
+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;
@@ -37,7 +37,6 @@ import com.cloud.agent.api.sync.SyncNuageVspCmsIdCommand;
 import com.cloud.api.ApiDBUtils;
 import com.cloud.api.commands.AddNuageVspDeviceCmd;
 import com.cloud.api.commands.DeleteNuageVspDeviceCmd;
-import com.cloud.api.commands.IssueNuageVspResourceRequestCmd;
 import com.cloud.api.commands.ListNuageVspDevicesCmd;
 import com.cloud.api.commands.UpdateNuageVspDeviceCmd;
 import com.cloud.api.response.NuageVspDeviceResponse;
@@ -70,7 +69,6 @@ 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.sync.NuageVspSync;
 import com.cloud.network.vpc.VpcManager;
 import com.cloud.network.vpc.VpcOffering;
 import com.cloud.network.vpc.VpcOfferingServiceMapVO;
@@ -106,7 +104,10 @@ 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.framework.config.ConfigKey;
 import org.apache.cloudstack.framework.config.Configurable;
 import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
@@ -127,7 +128,6 @@ import java.util.Map;
 import java.util.Set;
 import java.util.UUID;
 import java.util.concurrent.ExecutionException;
-import java.util.concurrent.ScheduledExecutorService;
 
 import static com.cloud.agent.api.sync.SyncNuageVspCmsIdCommand.SyncType;
 
@@ -135,8 +135,6 @@ public class NuageVspManagerImpl extends ManagerBase implements NuageVspManager,
 
     private static final Logger s_logger = Logger.getLogger(NuageVspManagerImpl.class);
 
-    private static final int ONE_MINUTE_MULTIPLIER = 60 * 1000;
-
     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 };
@@ -164,8 +162,6 @@ public class NuageVspManagerImpl extends ManagerBase implements NuageVspManager,
     @Inject
     NuageVspDao _nuageVspDao;
     @Inject
-    NuageVspSync _nuageVspSync;
-    @Inject
     DataCenterDao _dataCenterDao;
     @Inject
     ConfigurationDao _configDao;
@@ -187,8 +183,8 @@ public class NuageVspManagerImpl extends ManagerBase implements NuageVspManager,
     NetworkOfferingDao _networkOfferingDao;
     @Inject
     NetworkOfferingServiceMapDao _networkOfferingServiceMapDao;
-
-    private ScheduledExecutorService scheduler;
+    @Inject
+    NuageVspEntityBuilder _nuageVspEntityBuilder;
 
     @Inject
     MessageBus _messageBus;
@@ -212,7 +208,7 @@ public class NuageVspManagerImpl extends ManagerBase implements NuageVspManager,
     @Override
     public List<Class<?>> getCommands() {
         return Lists.<Class<?>>newArrayList(AddNuageVspDeviceCmd.class, DeleteNuageVspDeviceCmd.class, ListNuageVspDevicesCmd.class,
-                IssueNuageVspResourceRequestCmd.class, UpdateNuageVspDeviceCmd.class);
+                UpdateNuageVspDeviceCmd.class);
     }
 
     @Override
@@ -242,21 +238,21 @@ public class NuageVspManagerImpl extends ManagerBase implements NuageVspManager,
         }
 
         try {
-            NuageVspPluginClientLoader clientLoader = NuageVspPluginClientLoader.getClientLoader(null, null, 1, 1, null);
+            NuageVspPluginClientLoader clientLoader = NuageVspPluginClientLoader.getClientLoader(null, null, null, null, 1, 1, null);
 
-            Map<String, Object> clientDefaults = clientLoader.getNuageVspManagerClient().getClientDefaults();
-            String apiVersion = MoreObjects.firstNonNull(cmd.getApiVersion(), (String) clientDefaults.get("CURRENT_API_VERSION"));
+            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);
             }
 
             int port = cmd.getPort();
             if (0 == port) {
-                port = 8443;
+                port = 443;
             }
             String cmsUserPasswordBase64 = NuageVspUtil.encodePassword(cmd.getPassword());
-            String retryCount = String.valueOf(MoreObjects.firstNonNull(cmd.getApiRetryCount(), clientDefaults.get("DEFAULT_API_RETRY_COUNT")));
-            String retryInterval = String.valueOf(MoreObjects.firstNonNull(cmd.getApiRetryInterval(), clientDefaults.get("DEFAULT_API_RETRY_INTERVAL")));
+            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())
                     .guid(UUID.randomUUID().toString())
@@ -284,22 +280,33 @@ public class NuageVspManagerImpl extends ManagerBase implements NuageVspManager,
             _hostDetailsDao.persist(detail);
 
             ConfigurationVO cmsIdConfig = _configDao.findByName("nuagevsp.cms.id");
+            NuageVspDeviceVO matchingNuageVspDevice = findMatchingNuageVspDevice(nuageVspDevice);
+            String cmsId;
+            if (matchingNuageVspDevice != null) {
+                cmsId = findNuageVspCmsIdForDevice(matchingNuageVspDevice.getId(), cmsIdConfig);
+            } else {
+                SyncNuageVspCmsIdCommand syncCmd = new SyncNuageVspCmsIdCommand(SyncType.REGISTER, null);
+                SyncNuageVspCmsIdAnswer answer = (SyncNuageVspCmsIdAnswer) _agentMgr.easySend(nuageVspDevice.getHostId(), syncCmd);
+                if (answer != null && answer.getSuccess()) {
+                    cmsId = answer.getNuageVspCmsId();
+                } else {
+                    throw new CloudRuntimeException("Failed to register CMS ID");
+                }
+            }
+
             host = findNuageVspHost(nuageVspDevice.getHostId());
-            SyncNuageVspCmsIdCommand syncCmd = new SyncNuageVspCmsIdCommand(SyncType.REGISTER, null);
-            SyncNuageVspCmsIdAnswer answer = (SyncNuageVspCmsIdAnswer) _agentMgr.easySend(nuageVspDevice.getHostId(), syncCmd);
-            if (answer != null && answer.getSuccess()) {
-                registerNewNuageVspDevice(cmsIdConfig, nuageVspDevice.getId() + ":" + answer.getNuageVspCmsId());
+            registerNewNuageVspDevice(cmsIdConfig, nuageVspDevice.getId() + ":" + cmsId);
 
-                detail = new DetailVO(host.getId(), "nuagevspcmsid", answer.getNuageVspCmsId());
-                _hostDetailsDao.persist(detail);
+            detail = new DetailVO(host.getId(), "nuagevspcmsid", cmsId);
+            _hostDetailsDao.persist(detail);
 
-                resourceConfiguration.nuageVspCmsId(answer.getNuageVspCmsId());
-                resource.configure(cmd.getHostName(), Maps.<String, Object>newHashMap(resourceConfiguration.build()));
+            resourceConfiguration.nuageVspCmsId(cmsId);
+            resource.configure(cmd.getHostName(), Maps.<String, Object>newHashMap(resourceConfiguration.build()));
 
+            if (matchingNuageVspDevice == null) {
                 auditDomainsOnVsp((HostVO) host, true, false);
-            } else {
-                throw new CloudRuntimeException("Failed to register CMS ID");
             }
+
             return nuageVspDevice;
         } catch (ConfigurationException e) {
             s_logger.error("Failed to configure Nuage VSD resource " + cmd.getHostName(), e);
@@ -372,13 +379,13 @@ public class NuageVspManagerImpl extends ManagerBase implements NuageVspManager,
             updateRequired = true;
         }
 
-        GetClientDefaultsCommand getClientDefaultsCmd = new GetClientDefaultsCommand();
-        GetClientDefaultsAnswer getClientDefaultsAnswer = (GetClientDefaultsAnswer) _agentMgr.easySend(nuageVspHost.getId(), getClientDefaultsCmd);
+        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 " + getClientDefaultsAnswer.getCurrentApiVersion());
+            throw new CloudRuntimeException("Incorrect API version: Nuage plugin only supports " + apiDefaultsAnswer.getApiDefaults().getVersion());
         }
 
         String apiRelativePath = "/nuage/api/" + apiVersion;
@@ -474,25 +481,31 @@ public class NuageVspManagerImpl extends ManagerBase implements NuageVspManager,
             }
         }
 
+        NuageVspDeviceVO matchingNuageVspDevice = findMatchingNuageVspDevice(nuageVspDevice);
         ConfigurationVO cmsIdConfig = _configDao.findByName("nuagevsp.cms.id");
         HostVO host = findNuageVspHost(nuageVspDevice.getHostId());
-        if (!auditDomainsOnVsp(host, false, true)) {
-            return false;
-        }
-
         String nuageVspCmsId = findNuageVspCmsIdForDevice(nuageVspDevice.getId(), cmsIdConfig);
-        SyncNuageVspCmsIdCommand syncCmd = new SyncNuageVspCmsIdCommand(SyncType.UNREGISTER, nuageVspCmsId);
-        SyncNuageVspCmsIdAnswer answer = (SyncNuageVspCmsIdAnswer) _agentMgr.easySend(nuageVspDevice.getHostId(), syncCmd);
-        if (answer != null && answer.getSuccess()) {
-            String currentValue = cmsIdConfig.getValue();
-            String newValue = currentValue.replace(nuageVspDevice.getId() + ":" + answer.getNuageVspCmsId(), "");
-            if (!Strings.isNullOrEmpty(newValue) && newValue.startsWith(";")) {
-                newValue = newValue.substring(1);
+        if (matchingNuageVspDevice == null) {
+            if (!auditDomainsOnVsp(host, false, true)) {
+                return false;
             }
-            _configDao.update("nuagevsp.cms.id", newValue);
-        } else {
-            return false;
+
+            SyncNuageVspCmsIdCommand syncCmd = new SyncNuageVspCmsIdCommand(SyncType.UNREGISTER, nuageVspCmsId);
+            SyncNuageVspCmsIdAnswer answer = (SyncNuageVspCmsIdAnswer) _agentMgr.easySend(nuageVspDevice.getHostId(), syncCmd);
+            if (answer == null || !answer.getSuccess()) {
+                return false;
+            }
+        }
+
+        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);
 
         HostVO nuageHost = _hostDao.findById(nuageVspDevice.getHostId());
         Long hostId = nuageHost.getId();
@@ -505,6 +518,22 @@ public class NuageVspManagerImpl extends ManagerBase implements NuageVspManager,
         return true;
     }
 
+    private NuageVspDeviceVO findMatchingNuageVspDevice(NuageVspDeviceVO nuageVspDevice) {
+        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)) {
+                return otherNuageVspDevice;
+            }
+        }
+        return null;
+    }
+
     @Override
     public List<NuageVspDeviceVO> listNuageVspDevices(ListNuageVspDevicesCmd cmd) {
         Long physicalNetworkId = cmd.getPhysicalNetworkId();
@@ -551,6 +580,8 @@ public class NuageVspManagerImpl extends ManagerBase implements NuageVspManager,
     }
 
     private void auditHost(HostVO host) {
+        if (host == null) return;
+
         _hostDao.loadDetails(host);
 
         boolean validateDomains = true;
@@ -585,7 +616,8 @@ public class NuageVspManagerImpl extends ManagerBase implements NuageVspManager,
         _hostDao.loadDetails(host);
         List<DomainVO> allDomains = _domainDao.listAll();
         for (DomainVO domain : allDomains) {
-            SyncDomainCommand cmd = new SyncDomainCommand(domain.getUuid(), domain.getName(), domain.getPath(), add, remove);
+            VspDomain vspDomain = _nuageVspEntityBuilder.buildVspDomain(domain);
+            SyncDomainCommand cmd = new SyncDomainCommand(vspDomain, add, remove);
             SyncDomainAnswer answer = (SyncDomainAnswer) _agentMgr.easySend(host.getId(), cmd);
             return answer.getSuccess();
         }
@@ -683,7 +715,8 @@ public class NuageVspManagerImpl extends ManagerBase implements NuageVspManager,
                     List<NuageVspDeviceVO> nuageVspDevices = _nuageVspDao.listAll();
                     for (NuageVspDeviceVO nuageVspDevice : nuageVspDevices) {
                         HostVO host = findNuageVspHost(nuageVspDevice.getHostId());
-                        SyncDomainCommand cmd = new SyncDomainCommand(domain.getUuid(), domain.getName(), domain.getPath(), true, false);
+                        VspDomain vspDomain = _nuageVspEntityBuilder.buildVspDomain(domain);
+                        SyncDomainCommand cmd = new SyncDomainCommand(vspDomain, true, false);
                         _agentMgr.easySend(host.getId(), cmd);
                     }
                 } finally {
@@ -700,7 +733,8 @@ public class NuageVspManagerImpl extends ManagerBase implements NuageVspManager,
                 List<NuageVspDeviceVO> nuageVspDevices = _nuageVspDao.listAll();
                 for (NuageVspDeviceVO nuageVspDevice : nuageVspDevices) {
                     HostVO host = findNuageVspHost(nuageVspDevice.getHostId());
-                    SyncDomainCommand cmd = new SyncDomainCommand(domain.getUuid(), domain.getName(), domain.getPath(), false, true);
+                    VspDomain vspDomain = _nuageVspEntityBuilder.buildVspDomain(domain);
+                    SyncDomainCommand cmd = new SyncDomainCommand(vspDomain, false, true);
                     _agentMgr.easySend(host.getId(), cmd);
                 }
             }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b0c27e48/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 8e14237..677fa9f 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
@@ -30,8 +30,6 @@ 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.VspResourceAnswer;
-import com.cloud.agent.api.VspResourceCommand;
 import com.cloud.agent.api.element.ApplyAclRuleVspCommand;
 import com.cloud.agent.api.element.ApplyStaticNatVspCommand;
 import com.cloud.agent.api.element.ImplementVspCommand;
@@ -40,14 +38,13 @@ 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.manager.GetClientDefaultsAnswer;
-import com.cloud.agent.api.manager.GetClientDefaultsCommand;
+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.agent.api.sync.SyncVspCommand;
 import com.cloud.host.Host;
 import com.cloud.resource.ServerResource;
 import com.cloud.util.NuageVspUtil;
@@ -56,12 +53,11 @@ import com.cloud.utils.component.ManagerBase;
 import com.cloud.utils.exception.CloudRuntimeException;
 import com.google.common.base.Strings;
 import net.nuage.vsp.acs.NuageVspPluginClientLoader;
-import net.nuage.vsp.acs.client.NuageVspApiClient;
-import net.nuage.vsp.acs.client.NuageVspElementClient;
-import net.nuage.vsp.acs.client.NuageVspGuruClient;
-import net.nuage.vsp.acs.client.NuageVspManagerClient;
-import net.nuage.vsp.acs.client.NuageVspSyncClient;
-import org.apache.commons.lang3.tuple.Pair;
+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 org.apache.log4j.Logger;
 
 import javax.naming.ConfigurationException;
@@ -91,7 +87,8 @@ public class NuageVspResource extends ManagerBase implements ServerResource {
     private String _name;
     private String _guid;
     private String _zoneId;
-    private String[] _cmsUserInfo;
+    private String _cmsUserLogin;
+    private String _cmsUserPassword;
     private String _hostName;
     private String _relativePath;
     private int _numRetries;
@@ -102,7 +99,6 @@ public class NuageVspResource extends ManagerBase implements ServerResource {
     protected NuageVspApiClient _nuageVspApiClient;
     protected NuageVspGuruClient _nuageVspGuruClient;
     protected NuageVspElementClient _nuageVspElementClient;
-    protected NuageVspSyncClient _nuageVspSyncClient;
     protected NuageVspManagerClient _nuageVspManagerClient;
     protected boolean _isNuageVspClientLoaded;
 
@@ -190,7 +186,8 @@ public class NuageVspResource extends ManagerBase implements ServerResource {
         _relativePath = new StringBuffer().append("https://").append(_hostName).append(":").append(port).append(apiRelativePath).toString();
 
         String cmsUserPass = NuageVspUtil.decodePassword(cmsUserPassBase64);
-        _cmsUserInfo = new String[] {CMS_USER_ENTEPRISE_NAME, cmsUser, cmsUserPass};
+        _cmsUserLogin = cmsUser;
+        _cmsUserPassword = cmsUserPass;
 
         _nuageVspCmsId = (String)params.get(NUAGE_VSP_CMS_ID);
 
@@ -199,8 +196,8 @@ public class NuageVspResource extends ManagerBase implements ServerResource {
         try {
             login();
         } catch (ExecutionException | ConfigurationException e) {
-            s_logger.error("Failed to login to Nuage VSD on " + name + " as user " + cmsUser, e);
-            throw new CloudRuntimeException("Failed to login to Nuage VSD on " + name + " as user " + cmsUser, e);
+            s_logger.error(e.getMessage(), e);
+            throw new CloudRuntimeException(e.getMessage(), e);
         }
 
         return true;
@@ -211,23 +208,14 @@ public class NuageVspResource extends ManagerBase implements ServerResource {
         _nuageVspApiClient.login();
     }
 
-    protected <A extends NuageVspApiClient, B extends NuageVspElementClient, C extends NuageVspSyncClient, D extends NuageVspGuruClient> void loadNuageClient() {
-
-        try {
-            NuageVspPluginClientLoader clientLoader = NuageVspPluginClientLoader.getClientLoader(_relativePath, _cmsUserInfo, _numRetries, _retryInterval, _nuageVspCmsId);
-            _nuageVspApiClient = clientLoader.getNuageVspApiClient();
-            _nuageVspSyncClient = clientLoader.getNuageVspSyncClient();
-            _nuageVspGuruClient = clientLoader.getNuageVspGuruClient();
-            _nuageVspElementClient = clientLoader.getNuageVspElementClient();
-            _nuageVspManagerClient = clientLoader.getNuageVspManagerClient();
-            _isNuageVspClientLoaded = true;
-        } catch (ConfigurationException e) {
-            _isNuageVspClientLoaded = false;
-            String errorMessage = "Nuage Vsp Plugin client is not yet installed. Please install NuageVsp plugin client to use NuageVsp plugin in Cloudstack. ";
-            s_logger.error(errorMessage, e);
-            throw new CloudRuntimeException(errorMessage, e);
-        }
-
+    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;
     }
 
     @Override
@@ -265,12 +253,12 @@ public class NuageVspResource extends ManagerBase implements ServerResource {
 
     @Override
     public PingCommand getCurrentStatus(long id) {
-        if (_relativePath == null || _relativePath.isEmpty()) {
+        if (Strings.isNullOrEmpty(_relativePath)) {
             s_logger.error("Refusing to ping Nuage VSD because the resource configuration is missing the relative path information");
             _shouldAudit = true;
             return null;
         }
-        if (_cmsUserInfo == null || _cmsUserInfo.length < 2) {
+        if (Strings.isNullOrEmpty(_cmsUserLogin) || Strings.isNullOrEmpty(_cmsUserPassword)) {
             s_logger.error("Refusing to ping Nuage VSD because the resource configuration is missing the CMS user information");
             _shouldAudit = true;
             return null;
@@ -278,7 +266,7 @@ public class NuageVspResource extends ManagerBase implements ServerResource {
         try {
             login();
         } catch (ExecutionException | ConfigurationException e) {
-            s_logger.error("Failed to ping to Nuage VSD on " + _name + " as user " + _cmsUserInfo[1], e);
+            s_logger.error("Failed to ping to Nuage VSD on " + _name + " as user " + _cmsUserLogin, e);
             _shouldAudit = true;
             return null;
         }
@@ -293,8 +281,6 @@ public class NuageVspResource extends ManagerBase implements ServerResource {
             return executeRequest((ReadyCommand)cmd);
         } else if (cmd instanceof MaintainCommand) {
             return executeRequest((MaintainCommand)cmd);
-        } else if (cmd instanceof VspResourceCommand) {
-            return executeRequest((VspResourceCommand)cmd);
         }
         //Guru commands
         else if (cmd instanceof ImplementNetworkVspCommand) {
@@ -317,16 +303,14 @@ public class NuageVspResource extends ManagerBase implements ServerResource {
             return executeRequest((ShutDownVpcVspCommand)cmd);
         }
         //Sync Commands
-        else if (cmd instanceof SyncVspCommand) {
-            return executeRequest((SyncVspCommand)cmd);
-        } else if (cmd instanceof SyncNuageVspCmsIdCommand) {
+        else if (cmd instanceof SyncNuageVspCmsIdCommand) {
             return executeRequest((SyncNuageVspCmsIdCommand)cmd);
         } else if (cmd instanceof SyncDomainCommand) {
             return executeRequest((SyncDomainCommand)cmd);
         }
         //Other commands
-        else if (cmd instanceof GetClientDefaultsCommand) {
-            return executeRequest((GetClientDefaultsCommand)cmd);
+        else if (cmd instanceof GetApiDefaultsCommand) {
+            return executeRequest((GetApiDefaultsCommand)cmd);
         } else if (cmd instanceof SupportedApiVersionCommand) {
             return executeRequest((SupportedApiVersionCommand)cmd);
         }
@@ -357,29 +341,11 @@ public class NuageVspResource extends ManagerBase implements ServerResource {
         return new MaintainAnswer(cmd);
     }
 
-    private Answer executeRequest(VspResourceCommand cmd) {
-        try {
-            isNuageVspApiLoaded();
-            if (cmd.getRequestType().equalsIgnoreCase("GETALL") || cmd.getRequestType().equalsIgnoreCase("GET") || cmd.getRequestType().equalsIgnoreCase("GETRELATED")) {
-                String resourceInfo = _nuageVspApiClient.executeRestApi(cmd.getRequestType(), cmd.getResource(), cmd.getResourceId(), cmd.getChildResource(),
-                        cmd.getEntityDetails(), cmd.getResourceFilter(), cmd.getProxyUserUuid(), cmd.getProxyUserDomainuuid());
-                return new VspResourceAnswer(cmd, resourceInfo, "Executed Issue Resource command");
-            }
-            return new VspResourceAnswer(cmd, false, cmd.getRequestType() + " is not yet supported");
-        } catch (ExecutionException | ConfigurationException e) {
-            s_logger.error("Failure during " + cmd + " on Nuage VSD " + _hostName, e);
-            return new VspResourceAnswer(cmd, e);
-        }
-    }
-
     private Answer executeRequest(ImplementNetworkVspCommand cmd) {
         try {
             isNuageVspGuruLoaded();
-            _nuageVspGuruClient.implement(cmd.getNetworkDomainName(), cmd.getNetworkDomainPath(), cmd.getNetworkDomainUuid(), cmd.getNetworkAccountName(),
-                    cmd.getNetworkAccountUuid(), cmd.getNetworkName(), cmd.getNetworkCidr(), cmd.getNetworkGateway(), cmd.getNetworkAclId(), cmd.getDnsServers(),
-                    cmd.getGatewaySystemIds(), cmd.isL3Network(), cmd.isVpc(), cmd.isSharedNetwork(), cmd.getNetworkUuid(), cmd.getVpcName(), cmd.getVpcUuid(),
-                    cmd.isDefaultEgressPolicy(), cmd.getIpAddressRange(), cmd.getDomainTemplateName());
-            return new Answer(cmd, true, "Created network mapping to " + cmd.getNetworkName() + " on Nuage VSD " + _hostName);
+            _nuageVspGuruClient.implement(cmd.getNetwork(), cmd.getDnsServers());
+            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 + " on Nuage VSD " + _hostName, e);
             return new Answer(cmd, e);
@@ -389,11 +355,8 @@ public class NuageVspResource extends ManagerBase implements ServerResource {
     private Answer executeRequest(ReserveVmInterfaceVspCommand cmd) {
         try {
             isNuageVspGuruLoaded();
-            _nuageVspGuruClient.reserve(cmd.getNicUuid(), cmd.getNicMacAddress(), cmd.getNetworkUuid(), cmd.isL3Network(),
-                    cmd.isSharedNetwork(), cmd.getVpcUuid(), cmd.getNetworkDomainUuid(), cmd.getNetworksAccountUuid(), cmd.isDomainRouter(), cmd.getDomainRouterIp(),
-                    cmd.getVmInstanceName(), cmd.getVmUuid(), cmd.useStaticIp(), cmd.getStaticIp(), cmd.getStaticNatIpUuid(), cmd.getStaticNatIpAddress(), cmd.isStaticNatIpAllocated(),
-                    cmd.isOneToOneNat(), cmd.getStaticNatVlanUuid(), cmd.getStaticNatVlanGateway(), cmd.getStaticNatVlanNetmask());
-            return new Answer(cmd, true, "Created NIC that maps to nicUuid" + cmd.getNicUuid() + " on Nuage VSD " + _hostName);
+            _nuageVspGuruClient.reserve(cmd.getNetwork(), cmd.getVm(), cmd.getNic(), cmd.getStaticNat());
+            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);
@@ -403,9 +366,9 @@ public class NuageVspResource extends ManagerBase implements ServerResource {
     private Answer executeRequest(DeallocateVmVspCommand cmd) {
         try {
             isNuageVspGuruLoaded();
-            _nuageVspGuruClient.deallocate(cmd.getNetworkUuid(), cmd.getNicFromDdUuid(), cmd.getNicMacAddress(), cmd.getNicIp4Address(), cmd.isL3Network(), cmd.isSharedNetwork(),
-                    cmd.getVpcUuid(), cmd.getNetworksDomainUuid(), cmd.getVmInstanceName(), cmd.getVmUuid(), cmd.isExpungingState());
-            return new Answer(cmd, true, "Deallocated VM " + cmd.getVmInstanceName() + " on Nuage VSD " + _hostName);
+
+            _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);
@@ -415,8 +378,8 @@ public class NuageVspResource extends ManagerBase implements ServerResource {
     private Answer executeRequest(TrashNetworkVspCommand cmd) {
         try {
             isNuageVspGuruLoaded();
-            _nuageVspGuruClient.trash(cmd.getDomainUuid(), cmd.getNetworkUuid(), cmd.isL3Network(), cmd.isSharedNetwork(), cmd.getVpcUuid(), cmd.getDomainTemplateName());
-            return new Answer(cmd, true, "Deleted network mapping to " + cmd.getNetworkUuid() + " on Nuage VSD " + _hostName);
+            _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);
@@ -426,9 +389,8 @@ public class NuageVspResource extends ManagerBase implements ServerResource {
     private Answer executeRequest(ApplyStaticNatVspCommand cmd) {
         try {
             isNuageVspElementLoaded();
-            _nuageVspElementClient.applyStaticNats(cmd.getNetworkDomainUuid(), cmd.getNetworkUuid(), cmd.getVpcOrSubnetUuid(), cmd.isL3Network(),
-                    cmd.isVpc(), cmd.getStaticNatDetails());
-            return new Answer(cmd, true, "Applied Static NAT to network mapping " + cmd.getVpcOrSubnetUuid() + " on Nuage VSD " + _hostName);
+            _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);
@@ -438,10 +400,9 @@ public class NuageVspResource extends ManagerBase implements ServerResource {
     private Answer executeRequest(ImplementVspCommand cmd) {
         try {
             isNuageVspElementLoaded();
-            boolean success = _nuageVspElementClient.implement(cmd.getNetworkId(), cmd.getNetworkDomainUuid(), cmd.getNetworkUuid(), cmd.getNetworkName(), cmd.getVpcOrSubnetUuid(), cmd.isL2Network(),
-                    cmd.isL3Network(), cmd.isVpc(), cmd.isShared(), cmd.getDomainTemplateName(), cmd.isFirewallServiceSupported(), cmd.getDnsServers(), cmd.getIngressFirewallRules(),
-                    cmd.getEgressFirewallRules(), cmd.getAcsFipUuid(), cmd.isEgressDefaultPolicy());
-            return new Answer(cmd, success, "Implemented network " + cmd.getNetworkUuid() + " on Nuage VSD " + _hostName);
+            boolean success = _nuageVspElementClient.implement(cmd.getNetwork(), cmd.getDnsServers(), 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);
@@ -451,9 +412,8 @@ public class NuageVspResource extends ManagerBase implements ServerResource {
     private Answer executeRequest(ApplyAclRuleVspCommand cmd) {
         try {
             isNuageVspElementLoaded();
-            _nuageVspElementClient.applyAclRules(cmd.isNetworkAcl(), cmd.getNetworkUuid(), cmd.getNetworkDomainUuid(), cmd.getVpcOrSubnetUuid(), cmd.getNetworkName(),
-                    cmd.isL2Network(), cmd.getAclRules(), cmd.getNetworkId(), cmd.isEgressDefaultPolicy(), cmd.getAcsIngressAcl(), cmd.isNetworkReset(), cmd.getDomainTemplateName());
-            return new Answer(cmd, true, "Applied ACL Rule to network mapping " + cmd.getVpcOrSubnetUuid() + " on Nuage VSD " + _hostName);
+            _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);
@@ -471,17 +431,6 @@ public class NuageVspResource extends ManagerBase implements ServerResource {
         }
     }
 
-    private Answer executeRequest(SyncVspCommand cmd) {
-        try {
-            isNuageVspSyncLoaded();
-            _nuageVspSyncClient.syncWithNuageVsp(cmd.getNuageVspEntity());
-            return new Answer(cmd, true, "Synced " + cmd.getNuageVspEntity() + " 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(SyncNuageVspCmsIdCommand cmd) {
         try {
             isNuageVspManagerLoaded();
@@ -504,7 +453,7 @@ public class NuageVspResource extends ManagerBase implements ServerResource {
     private Answer executeRequest(SyncDomainCommand cmd) {
         try {
             isNuageVspManagerLoaded();
-            boolean success = _nuageVspManagerClient.syncDomainWithNuageVsp(cmd.getDomainUuid(), cmd.getDomainName(), cmd.getDomainPath(), cmd.isToAdd(), cmd.isToRemove());
+            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);
@@ -512,14 +461,13 @@ public class NuageVspResource extends ManagerBase implements ServerResource {
         }
     }
 
-    private Answer executeRequest(GetClientDefaultsCommand cmd) {
+    private Answer executeRequest(GetApiDefaultsCommand cmd) {
         try {
             isNuageVspManagerLoaded();
-            Map<String, Object> clientDefaults = _nuageVspManagerClient.getClientDefaults();
-            return new GetClientDefaultsAnswer(cmd, clientDefaults);
+            return new GetApiDefaultsAnswer(cmd, _nuageVspManagerClient.getApiDefaults());
         } catch (ExecutionException | ConfigurationException e) {
             s_logger.error("Failure during " + cmd + " on Nuage VSD " + _hostName, e);
-            return new GetClientDefaultsAnswer(cmd, e);
+            return new GetApiDefaultsAnswer(cmd, e);
         }
     }
 
@@ -552,12 +500,6 @@ public class NuageVspResource extends ManagerBase implements ServerResource {
         }
     }
 
-    protected void isNuageVspSyncLoaded() throws ConfigurationException {
-        if (!_isNuageVspClientLoaded || _nuageVspSyncClient == null) {
-            throw new ConfigurationException(NUAGE_VSP_PLUGIN_ERROR_MESSAGE);
-        }
-    }
-
     protected void isNuageVspManagerLoaded() throws ConfigurationException {
         if (!_isNuageVspClientLoaded || _nuageVspManagerClient == null) {
             throw new ConfigurationException(NUAGE_VSP_PLUGIN_ERROR_MESSAGE);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b0c27e48/plugins/network-elements/nuage-vsp/src/com/cloud/network/sync/NuageVspSync.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nuage-vsp/src/com/cloud/network/sync/NuageVspSync.java b/plugins/network-elements/nuage-vsp/src/com/cloud/network/sync/NuageVspSync.java
deleted file mode 100644
index 4e1cc43..0000000
--- a/plugins/network-elements/nuage-vsp/src/com/cloud/network/sync/NuageVspSync.java
+++ /dev/null
@@ -1,26 +0,0 @@
-//
-// 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.sync;
-
-
-public interface NuageVspSync {
-
-    public void syncWithNuageVsp(String nuageVspEntity);
-}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b0c27e48/plugins/network-elements/nuage-vsp/src/com/cloud/network/sync/NuageVspSyncImpl.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nuage-vsp/src/com/cloud/network/sync/NuageVspSyncImpl.java b/plugins/network-elements/nuage-vsp/src/com/cloud/network/sync/NuageVspSyncImpl.java
deleted file mode 100644
index 9180c17..0000000
--- a/plugins/network-elements/nuage-vsp/src/com/cloud/network/sync/NuageVspSyncImpl.java
+++ /dev/null
@@ -1,65 +0,0 @@
-//
-// 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.sync;
-
-import com.cloud.agent.AgentManager;
-import com.cloud.agent.api.Answer;
-import com.cloud.agent.api.sync.SyncVspCommand;
-import com.cloud.host.HostVO;
-import com.cloud.host.dao.HostDao;
-import com.cloud.network.NuageVspDeviceVO;
-import com.cloud.network.dao.NuageVspDao;
-import org.apache.log4j.Logger;
-import org.springframework.stereotype.Component;
-
-import javax.inject.Inject;
-import java.util.List;
-
-@Component
-public class NuageVspSyncImpl implements NuageVspSync {
-
-    private static final Logger s_logger = Logger.getLogger(NuageVspSyncImpl.class);
-
-    @Inject
-    NuageVspDao _nuageVspDao;
-    @Inject
-    HostDao _hostDao;
-    @Inject
-    AgentManager _agentMgr;
-
-    public void syncWithNuageVsp(String nuageVspEntity) {
-        //Get the NuageVspDevice and get the host information.
-        //This information is used to query VSP and synch the corresponding
-        //entities
-        List<NuageVspDeviceVO> nuageVspDevices = _nuageVspDao.listAll();
-        for (NuageVspDeviceVO nuageVspDevice : nuageVspDevices) {
-            HostVO nuageVspHost = _hostDao.findById(nuageVspDevice.getHostId());
-            _hostDao.loadDetails(nuageVspHost);
-            SyncVspCommand cmd = new SyncVspCommand(nuageVspEntity);
-            Answer answer = _agentMgr.easySend(nuageVspHost.getId(), cmd);
-            if (answer == null || !answer.getResult()) {
-                s_logger.error("SyncNuageVspCommand for Nuage VSP Host " + nuageVspHost.getUuid() + " failed");
-                if ((null != answer) && (null != answer.getDetails())) {
-                    s_logger.error(answer.getDetails());
-                }
-            }
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b0c27e48/plugins/network-elements/nuage-vsp/src/com/cloud/util/NuageVspEntityBuilder.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nuage-vsp/src/com/cloud/util/NuageVspEntityBuilder.java b/plugins/network-elements/nuage-vsp/src/com/cloud/util/NuageVspEntityBuilder.java
new file mode 100644
index 0000000..135a552
--- /dev/null
+++ b/plugins/network-elements/nuage-vsp/src/com/cloud/util/NuageVspEntityBuilder.java
@@ -0,0 +1,368 @@
+//
+// 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.util;
+
+import com.cloud.dc.VlanVO;
+import com.cloud.dc.dao.VlanDao;
+import com.cloud.domain.Domain;
+import com.cloud.domain.DomainVO;
+import com.cloud.domain.dao.DomainDao;
+import com.cloud.exception.InsufficientVirtualNetworkCapacityException;
+import com.cloud.network.Network;
+import com.cloud.network.NetworkModel;
+import com.cloud.network.dao.IPAddressDao;
+import com.cloud.network.dao.IPAddressVO;
+import com.cloud.network.dao.NetworkDetailsDao;
+import com.cloud.network.rules.FirewallRule;
+import com.cloud.network.vpc.NetworkACLItem;
+import com.cloud.network.vpc.VpcVO;
+import com.cloud.network.vpc.dao.VpcDao;
+import com.cloud.offerings.NetworkOfferingVO;
+import com.cloud.offerings.dao.NetworkOfferingDao;
+import com.cloud.offerings.dao.NetworkOfferingServiceMapDao;
+import com.cloud.user.AccountVO;
+import com.cloud.user.dao.AccountDao;
+import com.cloud.utils.exception.CloudRuntimeException;
+import com.cloud.utils.net.NetUtils;
+import com.cloud.vm.NicProfile;
+import com.cloud.vm.NicVO;
+import com.cloud.vm.VirtualMachine;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
+import net.nuage.vsp.acs.client.api.model.VspAclRule;
+import net.nuage.vsp.acs.client.api.model.VspDomain;
+import net.nuage.vsp.acs.client.api.model.VspNetwork;
+import net.nuage.vsp.acs.client.api.model.VspNic;
+import net.nuage.vsp.acs.client.api.model.VspStaticNat;
+import net.nuage.vsp.acs.client.api.model.VspVm;
+import net.nuage.vsp.acs.client.common.model.Pair;
+import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
+import org.apache.commons.lang.StringUtils;
+import org.apache.log4j.Logger;
+
+import javax.inject.Inject;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.TreeSet;
+
+public class NuageVspEntityBuilder {
+    private static final Logger s_logger = Logger.getLogger(NuageVspEntityBuilder.class);
+
+    @Inject
+    VpcDao _vpcDao;
+    @Inject
+    DomainDao _domainDao;
+    @Inject
+    AccountDao _accountDao;
+    @Inject
+    NetworkOfferingDao _networkOfferingDao;
+    @Inject
+    NetworkOfferingServiceMapDao _networkOfferingServiceMapDao;
+    @Inject
+    NetworkModel _networkModel;
+    @Inject
+    VlanDao _vlanDao;
+    @Inject
+    ConfigurationDao _configurationDao;
+    @Inject
+    IPAddressDao _ipAddressDao;
+    @Inject
+    NetworkDetailsDao _networkDetailsDao;
+
+    public VspDomain buildVspDomain(Domain domain) {
+        return new VspDomain.Builder()
+                .uuid(domain.getUuid())
+                .name(domain.getName())
+                .path(domain.getPath())
+                .build();
+    }
+
+    public VspNetwork buildVspNetwork(Network network, boolean fillAddressRange) {
+        VspNetwork.Builder vspNetworkBuilder = new VspNetwork.Builder()
+                .id(network.getId())
+                .uuid(network.getUuid())
+                .name(network.getName())
+                .cidr(network.getCidr())
+                .gateway(network.getGateway());
+
+        DomainVO domain = _domainDao.findById(network.getDomainId());
+        VspDomain vspDomain = buildVspDomain(domain);
+        vspNetworkBuilder.domain(vspDomain);
+
+        AccountVO account = _accountDao.findById(network.getAccountId());
+        vspNetworkBuilder.accountUuid(account.getUuid()).accountName(account.getAccountName());
+
+        NetworkOfferingVO networkOffering = _networkOfferingDao.findById(network.getNetworkOfferingId());
+        vspNetworkBuilder.egressDefaultPolicy(networkOffering.getEgressDefaultPolicy());
+
+        if (network.getVpcId() != null) {
+            VpcVO vpc = _vpcDao.findById(network.getVpcId());
+            vspNetworkBuilder.vpcUuid(vpc.getUuid())
+                    .vpcName(vpc.getName())
+                    .networkType(VspNetwork.NetworkType.Vpc);
+        } else {
+            if (networkOffering.getGuestType() == Network.GuestType.Shared) {
+                vspNetworkBuilder.networkType(VspNetwork.NetworkType.Shared);
+            } else if (_networkOfferingServiceMapDao.areServicesSupportedByNetworkOffering(network.getNetworkOfferingId(), Network.Service.SourceNat)
+                    || _networkOfferingServiceMapDao.areServicesSupportedByNetworkOffering(network.getNetworkOfferingId(), Network.Service.StaticNat)) {
+                vspNetworkBuilder.networkType(VspNetwork.NetworkType.L3);
+            } else {
+                vspNetworkBuilder.networkType(VspNetwork.NetworkType.L2);
+            }
+        }
+
+        boolean firewallServiceSupported = _networkModel.areServicesSupportedByNetworkOffering(network.getNetworkOfferingId(), Network.Service.Firewall);
+        vspNetworkBuilder.firewallServiceSupported(firewallServiceSupported);
+
+        String preConfiguredDomainTemplateName = NuageVspUtil.getPreConfiguredDomainTemplateName(_configurationDao, _networkDetailsDao, network, networkOffering);
+        vspNetworkBuilder.domainTemplateName(preConfiguredDomainTemplateName);
+
+        if (fillAddressRange) {
+            try {
+                List<Pair<String, String>> ipAddressRanges = getIpAddressRanges(networkOffering, network);
+                vspNetworkBuilder.ipAddressRanges(ipAddressRanges);
+
+                String virtualRouterIp = getVirtualRouterIP(network, ipAddressRanges);
+                vspNetworkBuilder.virtualRouterIp(virtualRouterIp);
+            } catch (InsufficientVirtualNetworkCapacityException ex) {
+                s_logger.error("There is an insufficient network capacity in network " + network.getId(), ex);
+                throw new CloudRuntimeException("There is an insufficient network capacity in network " + network.getId(), ex);
+            }
+        }
+
+        return vspNetworkBuilder.build();
+    }
+
+    private List<Pair<String, String>> getIpAddressRanges(NetworkOfferingVO networkOffering, Network network) {
+        List<Pair<String, String>> ipAddressRanges = Lists.newArrayList();
+        if (networkOffering.getGuestType() == Network.GuestType.Shared) {
+            List<VlanVO> vlans = _vlanDao.listVlansByNetworkId(network.getId());
+            ipAddressRanges = Lists.newArrayList();
+            for (VlanVO vlan : vlans) {
+                boolean isIpv4 = StringUtils.isNotBlank(vlan.getIpRange());
+                String[] range = isIpv4 ? vlan.getIpRange().split("-") : vlan.getIp6Range().split("-");
+                if (range.length == 2) {
+                    ipAddressRanges.add(Pair.of(range[0], range[1]));
+                }
+            }
+            return ipAddressRanges;
+        }
+
+        String subnet = NetUtils.getCidrSubNet(network.getCidr());
+        String netmask = NetUtils.getCidrNetmask(network.getCidr());
+        long cidrSize = NetUtils.getCidrSize(netmask);
+        Set<Long> allIPsInCidr = NetUtils.getAllIpsFromCidr(subnet, cidrSize, new HashSet<Long>());
+        if (allIPsInCidr == null || !(allIPsInCidr instanceof TreeSet)) {
+            throw new IllegalStateException("The IPs in CIDR for subnet " + subnet + " where null or returned in a non-ordered set.");
+        }
+
+        Iterator<Long> ipIterator = allIPsInCidr.iterator();
+        long ip =  ipIterator.next();
+        if (NetUtils.ip2Long(network.getGateway()) == ip) {
+            ip = ipIterator.next();
+        }
+        ipAddressRanges.add(Pair.of(NetUtils.long2Ip(ip), NetUtils.getIpRangeEndIpFromCidr(subnet, cidrSize)));
+        return ipAddressRanges;
+    }
+
+    private String getVirtualRouterIP(Network network, List<Pair<String, String>> ipAddressRanges) throws InsufficientVirtualNetworkCapacityException {
+        Pair<String, String> lowestIpAddressRange = null;
+        if (ipAddressRanges.size() == 1) {
+            lowestIpAddressRange = Iterables.getOnlyElement(ipAddressRanges);
+        } else {
+            for (Pair<String, String> ipAddressRange : ipAddressRanges) {
+                if (lowestIpAddressRange == null || NetUtils.ip2Long(ipAddressRange.getLeft()) < NetUtils.ip2Long(lowestIpAddressRange.getLeft())) {
+                    lowestIpAddressRange = ipAddressRange;
+                }
+            }
+        }
+
+        if (lowestIpAddressRange == null) {
+            throw new InsufficientVirtualNetworkCapacityException("VSP allocates an IP for VirtualRouter." + " But no ip address ranges are specified", Network.class,
+                    network.getId());
+        } else if (NetUtils.ip2Long(lowestIpAddressRange.getRight()) - NetUtils.ip2Long(lowestIpAddressRange.getLeft()) < 2) {
+            throw new InsufficientVirtualNetworkCapacityException("VSP allocates an IP for VirtualRouter." + " So, subnet should have atleast minimum 3 hosts", Network.class,
+                    network.getId());
+        }
+
+        String virtualRouterIp = lowestIpAddressRange.getLeft();
+        long lowestIp = NetUtils.ip2Long(lowestIpAddressRange.getLeft());
+        lowestIp = lowestIp + 1;
+        lowestIpAddressRange.setLeft(NetUtils.long2Ip(lowestIp));
+        return virtualRouterIp;
+    }
+
+    public VspVm buildVspVm(VirtualMachine vm, Network network) {
+        VspVm.Builder vspVmBuilder = new VspVm.Builder()
+                .uuid(vm.getUuid())
+                .name(vm.getInstanceName());
+
+        switch (vm.getState()) {
+            case Starting:
+                vspVmBuilder.state(VspVm.State.Starting); break;
+            case Running:
+                vspVmBuilder.state(VspVm.State.Running); break;
+            case Stopping:
+                vspVmBuilder.state(VspVm.State.Stopping); break;
+            case Stopped:
+                vspVmBuilder.state(VspVm.State.Stopped); break;
+            case Destroyed:
+                vspVmBuilder.state(VspVm.State.Destroyed); break;
+            case Expunging:
+                vspVmBuilder.state(VspVm.State.Expunging); break;
+            case Migrating:
+                vspVmBuilder.state(VspVm.State.Migrating); break;
+            case Error:
+                vspVmBuilder.state(VspVm.State.Error); break;
+            case Shutdowned:
+                vspVmBuilder.state(VspVm.State.Shutdowned); break;
+            default:
+                vspVmBuilder.state(VspVm.State.Unknown);
+        }
+
+        boolean isDomainRouter = vm.getType().equals(VirtualMachine.Type.DomainRouter);
+        vspVmBuilder.domainRouter(isDomainRouter);
+
+        if (network.getBroadcastUri() != null) {
+            String domainRouterIp = network.getBroadcastUri().getPath().substring(1);
+            vspVmBuilder.domainRouterIp(domainRouterIp);
+        }
+
+        return vspVmBuilder.build();
+    }
+
+    public VspNic buildVspNic(String nicUuid, NicProfile nicProfile) {
+        VspNic.Builder vspNicBuilder = new VspNic.Builder()
+                .uuid(nicUuid)
+                .macAddress(nicProfile.getMacAddress())
+                .useStaticIp(true)
+                .ip(nicProfile.getIPv4Address());
+        return vspNicBuilder.build();
+    }
+
+    public VspNic buildVspNic(NicVO nic) {
+        VspNic.Builder vspNicBuilder = new VspNic.Builder()
+                .uuid(nic.getUuid())
+                .macAddress(nic.getMacAddress())
+                .useStaticIp(true)
+                .ip(nic.getIPv4Address());
+        return vspNicBuilder.build();
+    }
+
+    public VspStaticNat buildVspStaticNat(Boolean forRevoke, IPAddressVO staticNatIp, VlanVO staticNatVlan, NicVO nic) {
+        VspStaticNat.Builder vspStaticNatBuilder = new VspStaticNat.Builder()
+                .ipUuid(staticNatIp.getUuid())
+                .ipAddress(staticNatIp.getAddress().addr())
+                .revoke(forRevoke)
+                .oneToOneNat(staticNatIp.isOneToOneNat())
+                .vlanUuid(staticNatVlan.getUuid())
+                .vlanGateway(staticNatVlan.getVlanGateway())
+                .vlanNetmask(staticNatVlan.getVlanNetmask());
+
+        if (nic != null) {
+            VspNic vspNic = buildVspNic(nic);
+            vspStaticNatBuilder.nic(vspNic);
+        }
+
+        return vspStaticNatBuilder.build();
+    }
+
+    public VspAclRule buildVspAclRule(FirewallRule firewallRule, Network network) {
+        VspAclRule.Builder vspAclRuleBuilder = new VspAclRule.Builder()
+                .uuid(firewallRule.getUuid())
+                .protocol(firewallRule.getProtocol())
+                .startPort(firewallRule.getSourcePortStart())
+                .endPort(firewallRule.getSourcePortEnd())
+                .sourceCidrList(firewallRule.getSourceCidrList())
+                .priority(-1)
+                .type(VspAclRule.ACLType.Firewall);
+
+        switch (firewallRule.getState()) {
+            case Active:
+                vspAclRuleBuilder.state(VspAclRule.ACLState.Active); break;
+            case Add:
+                vspAclRuleBuilder.state(VspAclRule.ACLState.Add); break;
+            case Revoke:
+                vspAclRuleBuilder.state(VspAclRule.ACLState.Revoke);
+        }
+
+        switch (firewallRule.getTrafficType()) {
+            case Ingress:
+                vspAclRuleBuilder.trafficType(VspAclRule.ACLTrafficType.Ingress); break;
+            case Egress:
+                vspAclRuleBuilder.trafficType(VspAclRule.ACLTrafficType.Egress);
+        }
+
+        NetworkOfferingVO networkOffering = _networkOfferingDao.findById(network.getNetworkOfferingId());
+        if (firewallRule.getTrafficType() == FirewallRule.TrafficType.Egress && networkOffering.getEgressDefaultPolicy()) {
+            vspAclRuleBuilder.action(VspAclRule.ACLAction.Deny);
+        } else {
+            vspAclRuleBuilder.action(VspAclRule.ACLAction.Allow);
+        }
+
+        if (firewallRule.getSourceIpAddressId() != null) {
+            IPAddressVO ipAddress = _ipAddressDao.findById(firewallRule.getSourceIpAddressId());
+            if (ipAddress != null) {
+                vspAclRuleBuilder.sourceIpAddress(ipAddress.getVmIp() + "/32");
+            }
+        }
+
+        return vspAclRuleBuilder.build();
+    }
+
+    public VspAclRule buildVspAclRule(NetworkACLItem networkAcl) {
+        VspAclRule.Builder vspAclRuleBuilder = new VspAclRule.Builder()
+                .uuid(networkAcl.getUuid())
+                .protocol(networkAcl.getProtocol())
+                .startPort(networkAcl.getSourcePortStart())
+                .endPort(networkAcl.getSourcePortEnd())
+                .sourceIpAddress(null)
+                .sourceCidrList(networkAcl.getSourceCidrList())
+                .priority(networkAcl.getNumber())
+                .type(VspAclRule.ACLType.NetworkACL);
+
+        switch (networkAcl.getState()) {
+            case Active:
+                vspAclRuleBuilder.state(VspAclRule.ACLState.Active); break;
+            case Add:
+                vspAclRuleBuilder.state(VspAclRule.ACLState.Add); break;
+            case Revoke:
+                vspAclRuleBuilder.state(VspAclRule.ACLState.Revoke);
+        }
+
+        switch (networkAcl.getTrafficType()) {
+            case Ingress:
+                vspAclRuleBuilder.trafficType(VspAclRule.ACLTrafficType.Ingress); break;
+            case Egress:
+                vspAclRuleBuilder.trafficType(VspAclRule.ACLTrafficType.Egress);
+        }
+
+        switch (networkAcl.getAction()) {
+            case Allow:
+                vspAclRuleBuilder.action(VspAclRule.ACLAction.Allow); break;
+            case Deny:
+                vspAclRuleBuilder.action(VspAclRule.ACLAction.Deny);
+        }
+
+        return vspAclRuleBuilder.build();
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/b0c27e48/plugins/network-elements/nuage-vsp/src/com/cloud/util/NuageVspUtil.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nuage-vsp/src/com/cloud/util/NuageVspUtil.java b/plugins/network-elements/nuage-vsp/src/com/cloud/util/NuageVspUtil.java
index 2300289..fedf048 100644
--- a/plugins/network-elements/nuage-vsp/src/com/cloud/util/NuageVspUtil.java
+++ b/plugins/network-elements/nuage-vsp/src/com/cloud/util/NuageVspUtil.java
@@ -20,6 +20,8 @@
 package com.cloud.util;
 
 import com.cloud.network.Network;
+import com.cloud.network.dao.NetworkDetailVO;
+import com.cloud.network.dao.NetworkDetailsDao;
 import com.cloud.network.manager.NuageVspManager;
 import com.cloud.offering.NetworkOffering;
 import com.cloud.utils.StringUtils;
@@ -28,7 +30,12 @@ import org.apache.commons.codec.binary.Base64;
 
 public class NuageVspUtil {
 
-    public static String getPreConfiguredDomainTemplateName(ConfigurationDao configDao, Network network, NetworkOffering networkOffering) {
+    public static String getPreConfiguredDomainTemplateName(ConfigurationDao configDao, NetworkDetailsDao networkDetailsDao, Network network, NetworkOffering networkOffering) {
+        NetworkDetailVO domainTemplateNetworkDetail = networkDetailsDao.findDetail(network.getId(), NuageVspManager.nuageDomainTemplateDetailName);
+        if (domainTemplateNetworkDetail != null) {
+            return domainTemplateNetworkDetail.getValue();
+        }
+
         String configKey;
         if (network.getVpcId() != null) {
             configKey = NuageVspManager.NuageVspVpcDomainTemplateName.key();


Mime
View raw message