You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by hu...@apache.org on 2014/07/21 10:50:19 UTC

[3/4] CLOUDSTACK-6845 : NuageVsp Network plugin

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/03de9cc3/plugins/network-elements/nuage-vsp/src/com/cloud/api/commands/DeleteNuageVspDeviceCmd.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nuage-vsp/src/com/cloud/api/commands/DeleteNuageVspDeviceCmd.java b/plugins/network-elements/nuage-vsp/src/com/cloud/api/commands/DeleteNuageVspDeviceCmd.java
new file mode 100644
index 0000000..ae81c84
--- /dev/null
+++ b/plugins/network-elements/nuage-vsp/src/com/cloud/api/commands/DeleteNuageVspDeviceCmd.java
@@ -0,0 +1,105 @@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+
+package com.cloud.api.commands;
+
+import javax.inject.Inject;
+
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiErrorCode;
+import org.apache.cloudstack.api.BaseAsyncCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.response.SuccessResponse;
+import org.apache.cloudstack.context.CallContext;
+
+import com.cloud.api.response.NuageVspDeviceResponse;
+import com.cloud.event.EventTypes;
+import com.cloud.exception.ConcurrentOperationException;
+import com.cloud.exception.InsufficientCapacityException;
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.exception.ResourceAllocationException;
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.network.manager.NuageVspManager;
+import com.cloud.utils.exception.CloudRuntimeException;
+
+@APICommand(name = "deleteNuageVspDevice", responseObject = SuccessResponse.class, description = "delete a nuage vsp device")
+public class DeleteNuageVspDeviceCmd extends BaseAsyncCmd {
+    private static final String s_name = "deletenuagevspdeviceresponse";
+    @Inject
+    NuageVspManager _nuageVspManager;
+
+    /////////////////////////////////////////////////////
+    //////////////// API parameters /////////////////////
+    /////////////////////////////////////////////////////
+
+    @Parameter(name = VspConstants.NUAGE_VSP_DEVICE_ID, type = CommandType.UUID, entityType = NuageVspDeviceResponse.class, required = true, description = "Nuage device ID")
+    private Long nuageVspDeviceId;
+
+    /////////////////////////////////////////////////////
+    /////////////////// Accessors ///////////////////////
+    /////////////////////////////////////////////////////
+
+    public Long getNuageVspDeviceId() {
+        return nuageVspDeviceId;
+    }
+
+    /////////////////////////////////////////////////////
+    /////////////// API Implementation///////////////////
+    /////////////////////////////////////////////////////
+
+    @Override
+    public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
+        try {
+            boolean result = _nuageVspManager.deleteNuageVspDevice(this);
+            if (result) {
+                SuccessResponse response = new SuccessResponse(getCommandName());
+                response.setResponseName(getCommandName());
+                this.setResponseObject(response);
+            } else {
+                throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete Nuage device.");
+            }
+        } catch (InvalidParameterValueException invalidParamExcp) {
+            throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage());
+        } catch (CloudRuntimeException runtimeExcp) {
+            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage());
+        }
+    }
+
+    @Override
+    public String getCommandName() {
+        return s_name;
+    }
+
+    @Override
+    public long getEntityOwnerId() {
+        return CallContext.current().getCallingAccount().getId();
+    }
+
+    @Override
+    public String getEventType() {
+        return EventTypes.EVENT_EXTERNAL_VSP_VSD_DELETE;
+    }
+
+    @Override
+    public String getEventDescription() {
+        return "Deleting Nuage VSD";
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/03de9cc3/plugins/network-elements/nuage-vsp/src/com/cloud/api/commands/IssueNuageVspResourceRequestCmd.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nuage-vsp/src/com/cloud/api/commands/IssueNuageVspResourceRequestCmd.java b/plugins/network-elements/nuage-vsp/src/com/cloud/api/commands/IssueNuageVspResourceRequestCmd.java
new file mode 100644
index 0000000..f0e3ff8
--- /dev/null
+++ b/plugins/network-elements/nuage-vsp/src/com/cloud/api/commands/IssueNuageVspResourceRequestCmd.java
@@ -0,0 +1,215 @@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+
+package com.cloud.api.commands;
+
+import java.util.List;
+
+import javax.inject.Inject;
+
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.ApiErrorCode;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.response.NetworkOfferingResponse;
+import org.apache.cloudstack.api.response.PhysicalNetworkResponse;
+import org.apache.cloudstack.api.response.ZoneResponse;
+import org.apache.cloudstack.context.CallContext;
+import org.apache.commons.lang.StringUtils;
+import org.apache.log4j.Logger;
+
+import com.cloud.agent.AgentManager;
+import com.cloud.agent.api.VspResourceAnswer;
+import com.cloud.agent.api.VspResourceCommand;
+import com.cloud.api.response.NuageVspResourceResponse;
+import com.cloud.domain.dao.DomainDao;
+import com.cloud.exception.ConcurrentOperationException;
+import com.cloud.exception.InsufficientCapacityException;
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.exception.ResourceAllocationException;
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.host.HostVO;
+import com.cloud.host.dao.HostDao;
+import com.cloud.network.NuageVspDeviceVO;
+import com.cloud.network.dao.NuageVspDao;
+import com.cloud.offering.NetworkOffering;
+import com.cloud.user.Account;
+import com.cloud.user.AccountManager;
+
+@APICommand(name = "issueNuageVspResourceRequest", responseObject = NuageVspResourceResponse.class, description = "Issues a Nuage VSP REST API resource request")
+public class IssueNuageVspResourceRequestCmd extends BaseCmd {
+    private static final Logger s_logger = Logger.getLogger(IssueNuageVspResourceRequestCmd.class.getName());
+    private static final String s_name = "nuagevspresourceresponse";
+
+    @Inject
+    protected AccountManager _accountMgr;
+    @Inject
+    protected DomainDao _domainDao;
+    @Inject
+    protected NuageVspDao _nuageConfigDao;
+    @Inject
+    HostDao _hostDao;
+    @Inject
+    AgentManager _agentMgr;
+
+    /////////////////////////////////////////////////////
+    //////////////// API parameters /////////////////////
+    /////////////////////////////////////////////////////
+
+    @Parameter(name = ApiConstants.NETWORK_OFFERING_ID, type = CommandType.UUID, entityType = NetworkOfferingResponse.class, required = true, description = "the network offering id")
+    private Long networkOfferingId;
+
+    @Parameter(name = ApiConstants.ZONE_ID, type = CommandType.UUID, entityType = ZoneResponse.class, required = true, description = "the Zone ID for the network")
+    private Long zoneId;
+
+    @Parameter(name = ApiConstants.PHYSICAL_NETWORK_ID, type = CommandType.UUID, entityType = PhysicalNetworkResponse.class, description = "the ID of the physical network in to which Nuage VSP Controller is added")
+    private Long physicalNetworkId;
+
+    @Parameter(name = VspConstants.NUAGE_VSP_API_METHOD, type = CommandType.STRING, required = true, description = "the Nuage VSP REST API method type")
+    private String method;
+
+    @Parameter(name = VspConstants.NUAGE_VSP_API_RESOURCE, type = CommandType.STRING, required = true, description = "the resource in Nuage VSP")
+    private String resource;
+
+    @Parameter(name = VspConstants.NUAGE_VSP_API_RESOURCE_ID, type = CommandType.STRING, description = "the ID of the resource in Nuage VSP")
+    private String resourceId;
+
+    @Parameter(name = VspConstants.NUAGE_VSP_API_CHILD_RESOURCE, type = CommandType.STRING, description = "the child resource in Nuage VSP")
+    private String childResource;
+
+    @Parameter(name = VspConstants.NUAGE_VSP_API_RESOURCE_FILTER, type = CommandType.STRING, description = "the resource filter in Nuage VSP")
+    private String resourceFilter;
+
+    /////////////////////////////////////////////////////
+    /////////////// API Implementation///////////////////
+    /////////////////////////////////////////////////////
+
+    public Long getNetworkOfferingId() {
+        return networkOfferingId;
+    }
+
+    public Long getZoneId() {
+        Long physicalNetworkId = getPhysicalNetworkId();
+
+        if (physicalNetworkId == null && zoneId == null) {
+            throw new InvalidParameterValueException("Zone id is required");
+        }
+
+        return zoneId;
+    }
+
+    public Long getPhysicalNetworkId() {
+        if (physicalNetworkId != null) {
+            return physicalNetworkId;
+        }
+
+        NetworkOffering offering = _entityMgr.findById(NetworkOffering.class, networkOfferingId);
+        if (offering == null) {
+            throw new InvalidParameterValueException("Unable to find network offering by id " + networkOfferingId);
+        }
+
+        if (zoneId == null) {
+            throw new InvalidParameterValueException("ZoneId is required as physicalNetworkId is null");
+        }
+        return _networkService.findPhysicalNetworkId(zoneId, offering.getTags(), offering.getTrafficType());
+    }
+
+    public String getMethod() {
+        return method;
+    }
+
+    public void setMethod(String method) {
+        this.method = method;
+    }
+
+    public String getResource() {
+        return resource;
+    }
+
+    public void setResource(String resource) {
+        this.resource = resource;
+    }
+
+    public String getResourceId() {
+        return resourceId;
+    }
+
+    public void setResourceId(String resourceId) {
+        this.resourceId = resourceId;
+    }
+
+    public String getChildResource() {
+        return childResource;
+    }
+
+    public void setChildResource(String childResource) {
+        this.childResource = childResource;
+    }
+
+    public String getResourceFilter() {
+        return resourceFilter;
+    }
+
+    public void setResourceFilter(String resourceFilter) {
+        this.resourceFilter = resourceFilter;
+    }
+
+    @Override
+    public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
+        long accountId = CallContext.current().getCallingAccount().getAccountId();
+        Account account = _accountMgr.getAccount(accountId);
+
+        List<NuageVspDeviceVO> nuageVspDevices = _nuageConfigDao.listByPhysicalNetwork(getPhysicalNetworkId());
+        if (nuageVspDevices != null && (!nuageVspDevices.isEmpty())) {
+            NuageVspDeviceVO config = nuageVspDevices.iterator().next();
+            HostVO nuageVspHost = _hostDao.findById(config.getHostId());
+            VspResourceCommand cmd = new VspResourceCommand(method, resource, resourceId, childResource, null, resourceFilter, null, null);
+            VspResourceAnswer answer = (VspResourceAnswer)_agentMgr.easySend(nuageVspHost.getId(), cmd);
+            if (answer == null || !answer.getResult()) {
+                s_logger.error("VspResourceCommand failed");
+                if ((null != answer) && (null != answer.getDetails())) {
+                    throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, answer.getDetails());
+                }
+            } else {
+                NuageVspResourceResponse response = new NuageVspResourceResponse();
+                response.setResourceInfo(StringUtils.isBlank(answer.getResourceInfo()) ? "" : answer.getResourceInfo());
+                response.setObjectName("nuagevspresource");
+                response.setResponseName(getCommandName());
+                this.setResponseObject(response);
+            }
+        } else {
+            String errorMessage = "No Nuage VSP Controller configured on physical network " + getPhysicalNetworkId();
+            s_logger.error(errorMessage);
+            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, errorMessage);
+        }
+    }
+
+    @Override
+    public String getCommandName() {
+        return s_name;
+    }
+
+    @Override
+    public long getEntityOwnerId() {
+        return CallContext.current().getCallingAccount().getId();
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/03de9cc3/plugins/network-elements/nuage-vsp/src/com/cloud/api/commands/ListNuageVspDevicesCmd.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nuage-vsp/src/com/cloud/api/commands/ListNuageVspDevicesCmd.java b/plugins/network-elements/nuage-vsp/src/com/cloud/api/commands/ListNuageVspDevicesCmd.java
new file mode 100644
index 0000000..46797e0
--- /dev/null
+++ b/plugins/network-elements/nuage-vsp/src/com/cloud/api/commands/ListNuageVspDevicesCmd.java
@@ -0,0 +1,107 @@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+
+package com.cloud.api.commands;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.inject.Inject;
+
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.ApiErrorCode;
+import org.apache.cloudstack.api.BaseListCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.response.ListResponse;
+import org.apache.cloudstack.api.response.PhysicalNetworkResponse;
+
+import com.cloud.api.response.NuageVspDeviceResponse;
+import com.cloud.exception.ConcurrentOperationException;
+import com.cloud.exception.InsufficientCapacityException;
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.exception.ResourceAllocationException;
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.network.NuageVspDeviceVO;
+import com.cloud.network.manager.NuageVspManager;
+import com.cloud.utils.exception.CloudRuntimeException;
+
+@APICommand(name = "listNuageVspDevices", responseObject = NuageVspDeviceResponse.class, description = "Lists Nuage VSP devices")
+public class ListNuageVspDevicesCmd extends BaseListCmd {
+    private static final String s_name = "listnuagevspdeviceresponse";
+    @Inject
+    NuageVspManager _nuageVspManager;
+
+    /////////////////////////////////////////////////////
+    //////////////// API parameters /////////////////////
+    /////////////////////////////////////////////////////
+
+    @Parameter(name = ApiConstants.PHYSICAL_NETWORK_ID, type = CommandType.UUID, entityType = PhysicalNetworkResponse.class, description = "the Physical Network ID")
+    private Long physicalNetworkId;
+
+    @Parameter(name = VspConstants.NUAGE_VSP_DEVICE_ID, type = CommandType.UUID, entityType = NuageVspDeviceResponse.class, description = "the Nuage VSP device ID")
+    private Long nuageVspDeviceId;
+
+    /////////////////////////////////////////////////////
+    /////////////////// Accessors ///////////////////////
+    /////////////////////////////////////////////////////
+
+    public Long getNuageVspDeviceId() {
+        return nuageVspDeviceId;
+    }
+
+    public Long getPhysicalNetworkId() {
+        return physicalNetworkId;
+    }
+
+    /////////////////////////////////////////////////////
+    /////////////// API Implementation///////////////////
+    /////////////////////////////////////////////////////
+
+    @Override
+    public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
+        try {
+            List<NuageVspDeviceVO> nuageDevices = _nuageVspManager.listNuageVspDevices(this);
+            ListResponse<NuageVspDeviceResponse> response = new ListResponse<NuageVspDeviceResponse>();
+            List<NuageVspDeviceResponse> nuageDevicesResponse = new ArrayList<NuageVspDeviceResponse>();
+
+            if (nuageDevices != null && !nuageDevices.isEmpty()) {
+                for (NuageVspDeviceVO nuageDeviceVO : nuageDevices) {
+                    NuageVspDeviceResponse nuageDeviceResponse = _nuageVspManager.createNuageVspDeviceResponse(nuageDeviceVO);
+                    nuageDevicesResponse.add(nuageDeviceResponse);
+                }
+            }
+
+            response.setResponses(nuageDevicesResponse);
+            response.setResponseName(getCommandName());
+            this.setResponseObject(response);
+        } catch (InvalidParameterValueException invalidParamExcp) {
+            throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage());
+        } catch (CloudRuntimeException runtimeExcp) {
+            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage());
+        }
+    }
+
+    @Override
+    public String getCommandName() {
+        return s_name;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/03de9cc3/plugins/network-elements/nuage-vsp/src/com/cloud/api/commands/VspConstants.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nuage-vsp/src/com/cloud/api/commands/VspConstants.java b/plugins/network-elements/nuage-vsp/src/com/cloud/api/commands/VspConstants.java
new file mode 100644
index 0000000..2372890
--- /dev/null
+++ b/plugins/network-elements/nuage-vsp/src/com/cloud/api/commands/VspConstants.java
@@ -0,0 +1,35 @@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+
+package com.cloud.api.commands;
+
+public class VspConstants {
+    public static final String NUAGE_VSP_DEVICE_ID = "vspdeviceid";
+    public static final String NUAGE_VSP_DEVICE_NAME = "nuagedevicename";
+    public static final String NUAGE_VSP_API_PORT = "port";
+    public static final String NUAGE_VSP_API_VERSION = "apiversion";
+    public static final String NUAGE_VSP_API_RETRY_COUNT = "retrycount";
+    public static final String NUAGE_VSP_API_RETRY_INTERVAL = "retryinterval";
+    public static final String NUAGE_VSP_API_METHOD = "method";
+    public static final String NUAGE_VSP_API_RESOURCE = "resource";
+    public static final String NUAGE_VSP_API_RESOURCE_ID = "resourceid";
+    public static final String NUAGE_VSP_API_CHILD_RESOURCE = "childresource";
+    public static final String NUAGE_VSP_API_RESOURCE_FILTER = "resourcefilter";
+    public static final String NUAGE_VSP_API_RESOURCE_INFO = "resourceinfo";
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/03de9cc3/plugins/network-elements/nuage-vsp/src/com/cloud/api/response/NuageVspDeviceResponse.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nuage-vsp/src/com/cloud/api/response/NuageVspDeviceResponse.java b/plugins/network-elements/nuage-vsp/src/com/cloud/api/response/NuageVspDeviceResponse.java
new file mode 100644
index 0000000..b0bbcc8
--- /dev/null
+++ b/plugins/network-elements/nuage-vsp/src/com/cloud/api/response/NuageVspDeviceResponse.java
@@ -0,0 +1,105 @@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+
+package com.cloud.api.response;
+
+import com.cloud.api.commands.VspConstants;
+import com.cloud.network.NuageVspDeviceVO;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseResponse;
+import org.apache.cloudstack.api.EntityReference;
+
+import com.cloud.serializer.Param;
+import com.google.gson.annotations.SerializedName;
+
+@EntityReference(value = NuageVspDeviceVO.class)
+public class NuageVspDeviceResponse extends BaseResponse {
+    @SerializedName(VspConstants.NUAGE_VSP_DEVICE_ID)
+    @Param(description = "the device id of the Nuage VSD")
+    private String id;
+
+    @SerializedName(ApiConstants.PHYSICAL_NETWORK_ID)
+    @Param(description = "the ID of the physical network to which this Nuage VSP belongs to")
+    private String physicalNetworkId;
+
+    @SerializedName(ApiConstants.PROVIDER)
+    @Param(description = "the service provider name corresponding to this Nuage VSP device")
+    private String providerName;
+
+    @SerializedName(VspConstants.NUAGE_VSP_DEVICE_NAME)
+    @Param(description = "the name of the Nuage VSP device")
+    private String deviceName;
+
+    @SerializedName(VspConstants.NUAGE_VSP_API_PORT)
+    @Param(description = "the port to communicate to Nuage VSD")
+    private int port;
+
+    @SerializedName(ApiConstants.HOST_NAME)
+    @Param(description = "the hostname of the Nuage VSD")
+    private String hostName;
+
+    @SerializedName(VspConstants.NUAGE_VSP_API_VERSION)
+    @Param(description = "the version of the API to use to communicate to Nuage VSD")
+    private String apiVersion;
+
+    @SerializedName(VspConstants.NUAGE_VSP_API_RETRY_COUNT)
+    @Param(description = "the number of retries on failure to communicate to Nuage VSD")
+    private int apiRetryCount;
+
+    @SerializedName(VspConstants.NUAGE_VSP_API_RETRY_INTERVAL)
+    @Param(description = "the time to wait after failure before retrying to communicate to Nuage VSD")
+    private long apiRetryInterval;
+
+    public void setId(String vspDetailsId) {
+        this.id = vspDetailsId;
+    }
+
+    public void setPhysicalNetworkId(String physicalNetworkId) {
+        this.physicalNetworkId = physicalNetworkId;
+    }
+
+    public void setProviderName(String providerName) {
+        this.providerName = providerName;
+    }
+
+    public void setDeviceName(String deviceName) {
+        this.deviceName = deviceName;
+    }
+
+    public void setPort(int port) {
+        this.port = port;
+    }
+
+    public void setHostName(String hostName) {
+        this.hostName = hostName;
+    }
+
+    public void setApiVersion(String apiVersion) {
+        this.apiVersion = apiVersion;
+    }
+
+    public void setApiRetryCount(int apiRetryCount) {
+        this.apiRetryCount = apiRetryCount;
+    }
+
+    public void setApiRetryInterval(long apiRetryInterval) {
+        this.apiRetryInterval = apiRetryInterval;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/03de9cc3/plugins/network-elements/nuage-vsp/src/com/cloud/api/response/NuageVspResourceResponse.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nuage-vsp/src/com/cloud/api/response/NuageVspResourceResponse.java b/plugins/network-elements/nuage-vsp/src/com/cloud/api/response/NuageVspResourceResponse.java
new file mode 100644
index 0000000..8e620ed
--- /dev/null
+++ b/plugins/network-elements/nuage-vsp/src/com/cloud/api/response/NuageVspResourceResponse.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.api.response;
+
+import com.cloud.api.commands.VspConstants;
+import org.apache.cloudstack.api.BaseResponse;
+
+import com.cloud.serializer.Param;
+import com.google.gson.annotations.SerializedName;
+
+public class NuageVspResourceResponse extends BaseResponse {
+    @SerializedName(VspConstants.NUAGE_VSP_API_RESOURCE_INFO)
+    @Param(description = "the details of the Nuage VSP resource")
+    private String resourceInfo;
+
+    public String getResourceInfo() {
+        return resourceInfo;
+    }
+
+    public void setResourceInfo(String resourceInfo) {
+        this.resourceInfo = resourceInfo;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/03de9cc3/plugins/network-elements/nuage-vsp/src/com/cloud/network/NuageVspDeviceVO.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nuage-vsp/src/com/cloud/network/NuageVspDeviceVO.java b/plugins/network-elements/nuage-vsp/src/com/cloud/network/NuageVspDeviceVO.java
new file mode 100644
index 0000000..00cb1e4
--- /dev/null
+++ b/plugins/network-elements/nuage-vsp/src/com/cloud/network/NuageVspDeviceVO.java
@@ -0,0 +1,98 @@
+//
+// 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;
+
+import java.util.UUID;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+import org.apache.cloudstack.api.InternalIdentity;
+
+@Entity
+@Table(name = "external_nuage_vsp_devices")
+public class NuageVspDeviceVO implements InternalIdentity {
+
+    private static final long serialVersionUID = 1L;
+
+    @Id
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    @Column(name = "id")
+    private long id;
+
+    @Column(name = "uuid")
+    private String uuid;
+
+    @Column(name = "host_id")
+    private long hostId;
+
+    @Column(name = "physical_network_id")
+    private long physicalNetworkId;
+
+    @Column(name = "provider_name")
+    private String providerName;
+
+    @Column(name = "device_name")
+    private String deviceName;
+
+    public NuageVspDeviceVO() {
+        this.uuid = UUID.randomUUID().toString();
+    }
+
+    public NuageVspDeviceVO(long hostId, long physicalNetworkId,
+           String providerName, String deviceName){
+        super();
+        this.hostId = hostId;
+        this.physicalNetworkId = physicalNetworkId;
+        this.providerName = providerName;
+        this.deviceName = deviceName;
+        this.uuid = UUID.randomUUID().toString();
+    }
+
+    @Override
+    public long getId() {
+        return id;
+    }
+
+    public String getUuid() {
+        return uuid;
+    }
+
+    public long getHostId() {
+        return hostId;
+    }
+
+    public long getPhysicalNetworkId() {
+        return physicalNetworkId;
+    }
+
+    public String getProviderName() {
+        return providerName;
+    }
+
+    public String getDeviceName() {
+        return deviceName;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/03de9cc3/plugins/network-elements/nuage-vsp/src/com/cloud/network/dao/NuageVspDao.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nuage-vsp/src/com/cloud/network/dao/NuageVspDao.java b/plugins/network-elements/nuage-vsp/src/com/cloud/network/dao/NuageVspDao.java
new file mode 100644
index 0000000..6cf7e1a
--- /dev/null
+++ b/plugins/network-elements/nuage-vsp/src/com/cloud/network/dao/NuageVspDao.java
@@ -0,0 +1,36 @@
+//
+// 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.dao;
+
+import com.cloud.network.NuageVspDeviceVO;
+import com.cloud.utils.db.GenericDao;
+
+import java.util.List;
+
+public interface NuageVspDao extends GenericDao<NuageVspDeviceVO, Long> {
+    /**
+     * List all the Nuage Vsp devices added in to this physical network
+     *
+     * @param physicalNetworkId physical Network Id
+     * @return list of NuageVspDeviceVO for this physical network.
+     */
+    List<NuageVspDeviceVO> listByPhysicalNetwork(long physicalNetworkId);
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/03de9cc3/plugins/network-elements/nuage-vsp/src/com/cloud/network/dao/NuageVspDaoImpl.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nuage-vsp/src/com/cloud/network/dao/NuageVspDaoImpl.java b/plugins/network-elements/nuage-vsp/src/com/cloud/network/dao/NuageVspDaoImpl.java
new file mode 100644
index 0000000..bc55f43
--- /dev/null
+++ b/plugins/network-elements/nuage-vsp/src/com/cloud/network/dao/NuageVspDaoImpl.java
@@ -0,0 +1,52 @@
+//
+// 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.dao;
+
+import javax.ejb.Local;
+
+import com.cloud.network.NuageVspDeviceVO;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import org.springframework.stereotype.Component;
+
+import com.cloud.utils.db.GenericDaoBase;
+
+import java.util.List;
+
+@Component
+@Local(value = NuageVspDao.class)
+public class NuageVspDaoImpl extends GenericDaoBase<NuageVspDeviceVO, Long>
+        implements NuageVspDao {
+
+    protected final SearchBuilder<NuageVspDeviceVO> physicalNetworkIdSearch;
+
+    public NuageVspDaoImpl() {
+        physicalNetworkIdSearch = createSearchBuilder();
+        physicalNetworkIdSearch.and("physicalNetworkId", physicalNetworkIdSearch.entity().getPhysicalNetworkId(), SearchCriteria.Op.EQ);
+        physicalNetworkIdSearch.done();
+    }
+
+    @Override
+    public List<NuageVspDeviceVO> listByPhysicalNetwork(long physicalNetworkId) {
+        SearchCriteria<NuageVspDeviceVO> sc = physicalNetworkIdSearch.create();
+        sc.setParameters("physicalNetworkId", physicalNetworkId);
+        return search(sc, null);
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/03de9cc3/plugins/network-elements/nuage-vsp/src/com/cloud/network/element/NuageVspElement.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nuage-vsp/src/com/cloud/network/element/NuageVspElement.java b/plugins/network-elements/nuage-vsp/src/com/cloud/network/element/NuageVspElement.java
new file mode 100644
index 0000000..06f9733
--- /dev/null
+++ b/plugins/network-elements/nuage-vsp/src/com/cloud/network/element/NuageVspElement.java
@@ -0,0 +1,534 @@
+//
+// 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.element;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.ejb.Local;
+import javax.inject.Inject;
+import javax.naming.ConfigurationException;
+
+import org.apache.cloudstack.api.InternalIdentity;
+import org.apache.cloudstack.network.ExternalNetworkDeviceManager;
+import org.apache.log4j.Logger;
+
+import com.cloud.agent.AgentManager;
+import com.cloud.agent.api.StartupCommand;
+import com.cloud.agent.api.StartupVspCommand;
+import com.cloud.agent.api.element.ApplyAclRuleVspAnswer;
+import com.cloud.agent.api.element.ApplyAclRuleVspCommand;
+import com.cloud.agent.api.element.ApplyStaticNatVspAnswer;
+import com.cloud.agent.api.element.ApplyStaticNatVspCommand;
+import com.cloud.dc.VlanVO;
+import com.cloud.dc.dao.DataCenterDao;
+import com.cloud.dc.dao.VlanDao;
+import com.cloud.deploy.DeployDestination;
+import com.cloud.domain.Domain;
+import com.cloud.domain.dao.DomainDao;
+import com.cloud.exception.CloudException;
+import com.cloud.exception.ConcurrentOperationException;
+import com.cloud.exception.InsufficientCapacityException;
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.host.Host;
+import com.cloud.host.HostVO;
+import com.cloud.host.dao.HostDao;
+import com.cloud.network.Network;
+import com.cloud.network.Network.Capability;
+import com.cloud.network.Network.Provider;
+import com.cloud.network.Network.Service;
+import com.cloud.network.NetworkModel;
+import com.cloud.network.Networks;
+import com.cloud.network.NuageVspDeviceVO;
+import com.cloud.network.PhysicalNetworkServiceProvider;
+import com.cloud.network.PublicIpAddress;
+import com.cloud.network.dao.IPAddressDao;
+import com.cloud.network.dao.IPAddressVO;
+import com.cloud.network.dao.NetworkDao;
+import com.cloud.network.dao.NetworkServiceMapDao;
+import com.cloud.network.dao.NuageVspDao;
+import com.cloud.network.rules.FirewallRule;
+import com.cloud.network.rules.FirewallRule.FirewallRuleType;
+import com.cloud.network.rules.StaticNat;
+import com.cloud.network.vpc.NetworkACLItem;
+import com.cloud.network.vpc.Vpc;
+import com.cloud.network.vpc.dao.VpcDao;
+import com.cloud.offering.NetworkOffering;
+import com.cloud.offerings.NetworkOfferingVO;
+import com.cloud.offerings.dao.NetworkOfferingDao;
+import com.cloud.offerings.dao.NetworkOfferingServiceMapDao;
+import com.cloud.resource.ResourceManager;
+import com.cloud.resource.ResourceStateAdapter;
+import com.cloud.resource.ServerResource;
+import com.cloud.resource.UnableDeleteHostException;
+import com.cloud.utils.component.AdapterBase;
+import com.cloud.vm.NicProfile;
+import com.cloud.vm.NicVO;
+import com.cloud.vm.ReservationContext;
+import com.cloud.vm.VirtualMachineProfile;
+import com.cloud.vm.dao.NicDao;
+
+@Local(value = {NetworkElement.class, ConnectivityProvider.class, IpDeployer.class, SourceNatServiceProvider.class, StaticNatServiceProvider.class, FirewallServiceProvider.class,
+        DhcpServiceProvider.class, NetworkACLServiceProvider.class})
+public class NuageVspElement extends AdapterBase implements ConnectivityProvider, IpDeployer, SourceNatServiceProvider, StaticNatServiceProvider, FirewallServiceProvider,
+        DhcpServiceProvider, NetworkACLServiceProvider, ResourceStateAdapter {
+
+    private static final Logger s_logger = Logger.getLogger(NuageVspElement.class);
+
+    private static final Map<Service, Map<Capability, String>> capabilities = setCapabilities();
+
+    public static final ExternalNetworkDeviceManager.NetworkDevice NuageVspDevice = new ExternalNetworkDeviceManager.NetworkDevice("NuageVsp", Provider.NuageVsp.getName());
+
+    @Inject
+    ResourceManager _resourceMgr;
+    @Inject
+    HostDao _hostDao;
+    @Inject
+    NetworkModel _networkModel;
+    @Inject
+    NetworkServiceMapDao _ntwkSrvcDao;
+    @Inject
+    NuageVspDao _nuageVspDao;
+    @Inject
+    NetworkDao _networkDao;
+    @Inject
+    protected DomainDao _domainDao;
+    @Inject
+    protected DataCenterDao _dcDao;
+    @Inject
+    IPAddressDao _ipAddressDao;
+    @Inject
+    VlanDao _vlanDao;
+    @Inject
+    NicDao _nicDao;
+    @Inject
+    VpcDao _vpcDao;
+    @Inject
+    NetworkOfferingServiceMapDao _ntwkOfferingSrvcDao;
+    @Inject
+    AgentManager _agentMgr;
+    @Inject
+    NetworkOfferingDao _ntwkOfferingDao;
+
+    @Override
+    public boolean applyIps(Network network, List<? extends PublicIpAddress> ipAddress, Set<Service> service) throws ResourceUnavailableException {
+        return false;
+    }
+
+    @Override
+    public Map<Service, Map<Capability, String>> getCapabilities() {
+        return capabilities;
+    }
+
+    private static Map<Service, Map<Capability, String>> setCapabilities() {
+        Map<Service, Map<Capability, String>> capabilities = new HashMap<Service, Map<Capability, String>>();
+
+        // L2 Support : SDN provisioning
+        capabilities.put(Service.Connectivity, null);
+
+        // L3 Support : Generic
+        capabilities.put(Service.Gateway, null);
+
+        // L3 Support : SourceNat
+        Map<Capability, String> sourceNatCapabilities = new HashMap<Capability, String>();
+        sourceNatCapabilities.put(Capability.SupportedSourceNatTypes, "peraccount");
+        sourceNatCapabilities.put(Capability.RedundantRouter, "false");
+        capabilities.put(Service.SourceNat, sourceNatCapabilities);
+
+        // L3 support : StaticNat
+        capabilities.put(Service.StaticNat, null);
+
+        // Set capabilities for Firewall service
+        Map<Capability, String> firewallCapabilities = new HashMap<Capability, String>();
+        firewallCapabilities.put(Capability.TrafficStatistics, "per public ip");
+        firewallCapabilities.put(Capability.SupportedProtocols, "tcp,udp,icmp");
+        firewallCapabilities.put(Capability.SupportedEgressProtocols, "tcp,udp,icmp, all");
+        firewallCapabilities.put(Capability.SupportedTrafficDirection, "ingress, egress");
+        firewallCapabilities.put(Capability.MultipleIps, "true");
+        capabilities.put(Service.Firewall, firewallCapabilities);
+
+        // L3 Support : DHCP
+        Map<Capability, String> dhcpCapabilities = new HashMap<Capability, String>();
+        capabilities.put(Service.Dhcp, dhcpCapabilities);
+
+        //add network ACL capability
+        Map<Network.Capability, String> networkACLCapabilities = new HashMap<Network.Capability, String>();
+        networkACLCapabilities.put(Network.Capability.SupportedProtocols, "tcp,udp,icmp");
+        capabilities.put(Network.Service.NetworkACL, networkACLCapabilities);
+
+        return capabilities;
+    }
+
+    @Override
+    public Provider getProvider() {
+        return Provider.NuageVsp;
+    }
+
+    @Override
+    public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
+        super.configure(name, params);
+        _resourceMgr.registerResourceStateAdapter(name, this);
+        return true;
+    }
+
+    @Override
+    public boolean implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException,
+            ResourceUnavailableException, InsufficientCapacityException {
+        s_logger.debug("Entering NuageElement implement function for network " + network.getDisplayText() + " (state " + network.getState() + ")");
+
+        if (!canHandle(network, Service.Connectivity)) {
+            return false;
+        }
+
+        if (network.getBroadcastUri() == null) {
+            s_logger.error("Nic has no broadcast Uri with the virtual router IP");
+            return false;
+        }
+
+        return true;
+    }
+
+    @Override
+    public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException,
+            ResourceUnavailableException, InsufficientCapacityException {
+        if (!canHandle(network, Service.Connectivity)) {
+            return false;
+        }
+
+        if (network.getBroadcastUri() == null) {
+            s_logger.error("Nic has no broadcast Uri with the virtual router IP");
+            return false;
+        }
+
+        return true;
+    }
+
+    @Override
+    public boolean release(Network network, NicProfile nic, VirtualMachineProfile vm, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException {
+        if (!canHandle(network, Service.Connectivity)) {
+            return false;
+        }
+
+        if (network.getBroadcastUri() == null) {
+            s_logger.error("Nic has no broadcast Uri with the virtual router IP");
+            return false;
+        }
+
+        return true;
+    }
+
+    @Override
+    public boolean shutdown(Network network, ReservationContext context, boolean cleanup) throws ConcurrentOperationException, ResourceUnavailableException {
+        if (!canHandle(network, Service.Connectivity)) {
+            return false;
+        }
+
+        return true;
+    }
+
+    @Override
+    public boolean isReady(PhysicalNetworkServiceProvider provider) {
+        return true;
+    }
+
+    @Override
+    public boolean shutdownProviderInstances(PhysicalNetworkServiceProvider provider, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException {
+        return true;
+    }
+
+    @Override
+    public boolean canEnableIndividualServices() {
+        return false;
+    }
+
+    @Override
+    public boolean destroy(Network network, ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException {
+        if (!canHandle(network, Service.Connectivity)) {
+            return false;
+        }
+
+        return true;
+    }
+
+    @Override
+    public boolean verifyServicesCombination(Set<Service> services) {
+        // This element can only function in a NuageVsp based
+        // SDN network, so Connectivity needs to be present here
+        if (!services.contains(Service.Connectivity)) {
+            s_logger.warn("Unable to support services combination without Connectivity service provided by Nuage VSP.");
+            return false;
+        }
+
+        if ((services.contains(Service.StaticNat)) && (!services.contains(Service.SourceNat))) {
+            s_logger.warn("Unable to provide StaticNat without the SourceNat service.");
+            return false;
+        }
+
+        if (services.contains(Service.Vpn) || services.contains(Service.Dns) || services.contains(Service.Lb) || services.contains(Service.PortForwarding)
+                || services.contains(Service.SecurityGroup)) {
+            // NuageVsp doesn't implement any of these services, and we don't
+            // want anyone else to do it for us. So if these services
+            // exist, we can't handle it.
+            s_logger.warn("Unable to support services combination. The services list contains service(s) not supported by Nuage VSP.");
+            return false;
+        }
+
+        return true;
+    }
+
+    protected boolean canHandle(Network network, Service service) {
+
+        if (network.getBroadcastDomainType() != Networks.BroadcastDomainType.Vsp) {
+            return false;
+        }
+
+        if (!_networkModel.isProviderForNetwork(getProvider(), network.getId())) {
+            s_logger.debug("NuageElement is not a provider for network " + network.getDisplayText());
+            return false;
+        }
+
+        if (service != null) {
+            if (!_ntwkSrvcDao.canProviderSupportServiceInNetwork(network.getId(), service, getProvider())) {
+                s_logger.debug("NuageElement can't provide the " + service.getName() + " service on network " + network.getDisplayText());
+                return false;
+            }
+        }
+
+        return true;
+    }
+
+    @Override
+    public boolean addDhcpEntry(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context) throws ConcurrentOperationException,
+            InsufficientCapacityException, ResourceUnavailableException {
+        return true;
+    }
+
+    @Override
+    public boolean configDhcpSupportForSubnet(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context)
+            throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException {
+        return true;
+    }
+
+    @Override
+    public boolean removeDhcpSupportForSubnet(Network network) throws ResourceUnavailableException {
+        return true;
+    }
+
+    @Override
+    public boolean applyStaticNats(Network config, List<? extends StaticNat> rules) throws ResourceUnavailableException {
+        //Check if the network is associated to a VPC
+        Long vpcId = config.getVpcId();
+        String vpcOrSubnetUuid = null;
+        if (vpcId != null) {
+            Vpc vpcObj = _vpcDao.findById(vpcId);
+            vpcOrSubnetUuid = vpcObj.getUuid();
+        } else {
+            vpcOrSubnetUuid = config.getUuid();
+        }
+        Domain networkDomain = _domainDao.findById(config.getDomainId());
+
+        long networkOfferingId = _ntwkOfferingDao.findById(config.getNetworkOfferingId()).getId();
+        boolean isL3Network = isL3Network(networkOfferingId);
+
+        List<Map<String, Object>> sourceNatDetails = new ArrayList<Map<String, Object>>();
+        for (StaticNat staticNat : rules) {
+            Map<String, Object> sourceNatDetail = new HashMap<String, Object>();
+            IPAddressVO sourceNatIp = _ipAddressDao.findById(staticNat.getSourceIpAddressId());
+            VlanVO sourceNatVan = _vlanDao.findById(sourceNatIp.getVlanId());
+            NicVO nicVO = _nicDao.findByIp4AddressAndNetworkId(staticNat.getDestIpAddress(), staticNat.getNetworkId());
+            //Just get all the information about the sourceNat which will be used by NuageVsp
+            //client to process the request
+            sourceNatDetail.put("sourceNatIpUuid", sourceNatIp.getUuid());
+            sourceNatDetail.put("sourceNatIpAddress", sourceNatIp.getAddress().addr());
+            sourceNatDetail.put("nicMacAddress", nicVO == null ? null : nicVO.getMacAddress());
+            sourceNatDetail.put("isRevoke", staticNat.isForRevoke());
+            sourceNatDetail.put("sourceNatVlanUuid", sourceNatVan.getUuid());
+            sourceNatDetail.put("sourceNatVlanGateway", sourceNatVan.getVlanGateway());
+            sourceNatDetail.put("sourceNatVlanNetmask", sourceNatVan.getVlanNetmask());
+            sourceNatDetails.add(sourceNatDetail);
+        }
+        try {
+            try {
+                HostVO nuageVspHost = getNuageVspHost(config.getPhysicalNetworkId());
+                ApplyStaticNatVspCommand cmd = new ApplyStaticNatVspCommand(networkDomain.getUuid(), vpcOrSubnetUuid, isL3Network, sourceNatDetails);
+                ApplyStaticNatVspAnswer answer = (ApplyStaticNatVspAnswer)_agentMgr.easySend(nuageVspHost.getId(), cmd);
+                if (answer == null || !answer.getResult()) {
+                    s_logger.error("ApplyStaticNatNuageVspCommand for network " + config.getUuid() + " failed");
+                    if ((null != answer) && (null != answer.getDetails())) {
+                        throw new ResourceUnavailableException(answer.getDetails(), Network.class, config.getId());
+                    }
+                }
+            } catch (Exception e) {
+                s_logger.warn("Failed to apply static Nat in Vsp " + e.getMessage());
+            }
+        } catch (Exception e) {
+            throw new ResourceUnavailableException("Failed to apply Static NAT in VSP", Network.class, config.getId(), e);
+        }
+
+        return true;
+    }
+
+    @Override
+    public IpDeployer getIpDeployer(Network network) {
+        return this;
+    }
+
+    @Override
+    public boolean applyFWRules(Network network, List<? extends FirewallRule> rules) throws ResourceUnavailableException {
+        s_logger.debug("Handling applyFWRules for network " + network.getName() + " with " + rules.size() + " FWRules");
+        if (rules != null && rules.size() == 1 && rules.iterator().next().getType().equals(FirewallRuleType.System)) {
+            s_logger.debug("Default ACL added by CS as system is ignored for network " + network.getName() + " with rule " + rules);
+            return true;
+        }
+        return applyACLRules(network, rules, false);
+    }
+
+    @Override
+    public boolean applyNetworkACLs(Network network, List<? extends NetworkACLItem> rules) throws ResourceUnavailableException {
+        s_logger.debug("Handling applyNetworkACLs for network " + network.getName() + " with " + rules.size() + " Network ACLs");
+        if (rules == null || rules.isEmpty()) {
+            s_logger.debug("No rules to apply. So, delete all the existing ACL in VSP from Subnet with uuid " + network.getUuid());
+        } else {
+            s_logger.debug("New rules has to applied. So, delete all the existing ACL in VSP from Subnet with uuid " + network.getUuid());
+        }
+        applyACLRules(network, rules, true);
+        return true;
+    }
+
+    protected boolean applyACLRules(Network network, List<? extends InternalIdentity> rules, boolean isVpc) throws ResourceUnavailableException {
+        Domain networksDomain = _domainDao.findById(network.getDomainId());
+        NetworkOfferingVO networkOferringVO = _ntwkOfferingDao.findById(network.getNetworkOfferingId());
+        try {
+            Long vpcId = network.getVpcId();
+            String vpcOrSubnetUuid = null;
+            if (vpcId != null) {
+                Vpc vpcObj = _vpcDao.findById(vpcId);
+                vpcOrSubnetUuid = vpcObj.getUuid();
+            } else {
+                vpcOrSubnetUuid = network.getUuid();
+            }
+            boolean egressDefaultPolicy = networkOferringVO.getEgressDefaultPolicy();
+            List<Map<String, Object>> aclRules = new ArrayList<Map<String, Object>>();
+            for (InternalIdentity acl : rules) {
+                aclRules.add(getACLRuleDetails(acl, egressDefaultPolicy));
+            }
+
+            HostVO nuageVspHost = getNuageVspHost(network.getPhysicalNetworkId());
+            ApplyAclRuleVspCommand cmd = new ApplyAclRuleVspCommand(network.getUuid(), networksDomain.getUuid(), vpcOrSubnetUuid, isL3Network(networkOferringVO.getId()), aclRules,
+                    isVpc, network.getId());
+            ApplyAclRuleVspAnswer answer = (ApplyAclRuleVspAnswer)_agentMgr.easySend(nuageVspHost.getId(), cmd);
+            if (answer == null || !answer.getResult()) {
+                s_logger.error("ApplyAclRuleNuageVspCommand for network " + network.getUuid() + " failed");
+                if ((null != answer) && (null != answer.getDetails())) {
+                    throw new ResourceUnavailableException(answer.getDetails(), Network.class, network.getId());
+                }
+            }
+
+        } catch (Exception e1) {
+            throw new ResourceUnavailableException(e1.getMessage(), Network.class, network.getId());
+        }
+
+        return true;
+    }
+
+    @Override
+    public HostVO createHostVOForConnectedAgent(HostVO host, StartupCommand[] cmd) {
+        return null;
+    }
+
+    @Override
+    public HostVO createHostVOForDirectConnectAgent(HostVO host, StartupCommand[] startup, ServerResource resource, Map<String, String> details, List<String> hostTags) {
+        if (!(startup[0] instanceof StartupVspCommand)) {
+            return null;
+        }
+        host.setType(Host.Type.L2Networking);
+        return host;
+    }
+
+    @Override
+    public DeleteHostAnswer deleteHost(HostVO host, boolean isForced, boolean isForceDeleteStorage) throws UnableDeleteHostException {
+        if (!(host.getType() == Host.Type.L2Networking)) {
+            return null;
+        }
+        return new DeleteHostAnswer(true);
+    }
+
+    protected HostVO getNuageVspHost(Long physicalNetworkId) throws CloudException {
+        HostVO nuageVspHost;
+        List<NuageVspDeviceVO> nuageVspDevices = _nuageVspDao.listByPhysicalNetwork(physicalNetworkId);
+        if (nuageVspDevices != null && (!nuageVspDevices.isEmpty())) {
+            NuageVspDeviceVO config = nuageVspDevices.iterator().next();
+            nuageVspHost = _hostDao.findById(config.getHostId());
+            _hostDao.loadDetails(nuageVspHost);
+        } else {
+            throw new CloudException("Nuage VSD is not configured on physical network " + physicalNetworkId);
+        }
+        return nuageVspHost;
+    }
+
+    protected boolean isL3Network(Long offeringId) {
+        return _ntwkOfferingSrvcDao.areServicesSupportedByNetworkOffering(offeringId, Service.SourceNat)
+                || _ntwkOfferingSrvcDao.areServicesSupportedByNetworkOffering(offeringId, Service.StaticNat);
+    }
+
+    private Map<String, Object> getACLRuleDetails(Object aclRule, boolean egressDefaultPolicy) {
+        Map<String, Object> aclDetails = new HashMap<String, Object>();
+        if (aclRule instanceof FirewallRule) {
+            FirewallRule firewallRule = (FirewallRule)aclRule;
+            aclDetails.put("sourceCidrList", firewallRule.getSourceCidrList());
+            aclDetails.put("uuid", firewallRule.getUuid());
+            aclDetails.put("protocol", firewallRule.getProtocol());
+            aclDetails.put("startPort", firewallRule.getSourcePortStart());
+            aclDetails.put("endPort", firewallRule.getSourcePortEnd());
+            aclDetails.put("state", firewallRule.getState().name());
+            aclDetails.put("trafficType", firewallRule.getTrafficType().name());
+            if (firewallRule.getSourceIpAddressId() != null) {
+                //add the source IP
+                IPAddressVO ipaddress = _ipAddressDao.findById(((FirewallRule)aclRule).getSourceIpAddressId());
+                aclDetails.put("sourceIpAddress", ipaddress != null ? ipaddress.getVmIp() + "/32" : null);
+            }
+            if (firewallRule.getTrafficType().equals(FirewallRule.TrafficType.Egress) && egressDefaultPolicy) {
+                aclDetails.put("action", "Deny");
+            } else {
+                aclDetails.put("action", "Allow");
+            }
+            aclDetails.put("priority", -1);
+            aclDetails.put("type", "Firewall");
+        } else {
+            NetworkACLItem networkAcl = (NetworkACLItem)aclRule;
+            aclDetails.put("sourceCidrList", networkAcl.getSourceCidrList());
+            aclDetails.put("uuid", networkAcl.getUuid());
+            aclDetails.put("protocol", networkAcl.getProtocol());
+            aclDetails.put("startPort", networkAcl.getSourcePortStart());
+            aclDetails.put("endPort", networkAcl.getSourcePortEnd());
+            aclDetails.put("state", networkAcl.getState().name());
+            aclDetails.put("trafficType", networkAcl.getTrafficType().name());
+            //Set sourceIP to null as it is not applicable
+            aclDetails.put("sourceIpAddress", null);
+            aclDetails.put("action", networkAcl.getAction().name());
+            aclDetails.put("priority", networkAcl.getNumber());
+            aclDetails.put("type", "NetworkACL");
+        }
+        return aclDetails;
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/03de9cc3/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
new file mode 100644
index 0000000..d9882ea
--- /dev/null
+++ b/plugins/network-elements/nuage-vsp/src/com/cloud/network/guru/NuageVspGuestNetworkGuru.java
@@ -0,0 +1,416 @@
+//
+// 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.guru;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.ejb.Local;
+import javax.inject.Inject;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.log4j.Logger;
+
+import com.cloud.agent.AgentManager;
+import com.cloud.agent.api.guru.DeallocateVmVspAnswer;
+import com.cloud.agent.api.guru.DeallocateVmVspCommand;
+import com.cloud.agent.api.guru.ImplementNetworkVspAnswer;
+import com.cloud.agent.api.guru.ImplementNetworkVspCommand;
+import com.cloud.agent.api.guru.ReleaseVmVspAnswer;
+import com.cloud.agent.api.guru.ReleaseVmVspCommand;
+import com.cloud.agent.api.guru.ReserveVmInterfaceVspAnswer;
+import com.cloud.agent.api.guru.ReserveVmInterfaceVspCommand;
+import com.cloud.agent.api.guru.TrashNetworkVspAnswer;
+import com.cloud.agent.api.guru.TrashNetworkVspCommand;
+import com.cloud.dc.DataCenter;
+import com.cloud.dc.DataCenter.NetworkType;
+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.InsufficientAddressCapacityException;
+import com.cloud.exception.InsufficientVirtualNetworkCapacityException;
+import com.cloud.host.HostVO;
+import com.cloud.host.dao.HostDao;
+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;
+import com.cloud.network.NuageVspDeviceVO;
+import com.cloud.network.PhysicalNetwork;
+import com.cloud.network.PhysicalNetwork.IsolationMethod;
+import com.cloud.network.dao.NetworkVO;
+import com.cloud.network.dao.NuageVspDao;
+import com.cloud.network.dao.PhysicalNetworkVO;
+import com.cloud.network.vpc.Vpc;
+import com.cloud.network.vpc.dao.VpcDao;
+import com.cloud.offering.NetworkOffering;
+import com.cloud.offerings.dao.NetworkOfferingDao;
+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.utils.db.DB;
+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;
+
+@Local(value = NetworkGuru.class)
+public class NuageVspGuestNetworkGuru extends GuestNetworkGuru {
+    public static final Logger s_logger = Logger.getLogger(NuageVspGuestNetworkGuru.class);
+
+    @Inject
+    NetworkOfferingServiceMapDao _ntwkOfferingSrvcDao;
+    @Inject
+    NetworkOfferingDao _ntwkOfferingDao;
+    @Inject
+    DomainDao _domainDao;
+    @Inject
+    AccountDao _accountDao;
+    @Inject
+    NuageVspDao _nuageVspDao;
+    @Inject
+    HostDao _hostDao;
+    @Inject
+    VpcDao _vpcDao;
+    @Inject
+    AgentManager _agentMgr;
+
+    public NuageVspGuestNetworkGuru() {
+        super();
+        _isolationMethods = new IsolationMethod[] {IsolationMethod.VSP};
+    }
+
+    @Override
+    public Network design(NetworkOffering offering, DeploymentPlan plan, Network userSpecified, Account owner) {
+        PhysicalNetworkVO physnet = _physicalNetworkDao.findById(plan.getPhysicalNetworkId());
+        DataCenter dc = _dcDao.findById(plan.getDataCenterId());
+        if (!canHandle(offering, dc.getNetworkType(), physnet)) {
+            s_logger.debug("Refusing to design this network");
+            return null;
+        }
+
+        NetworkVO networkObject = (NetworkVO)super.design(offering, plan, userSpecified, owner);
+        if (networkObject == null) {
+            return null;
+        }
+
+        networkObject.setBroadcastDomainType(Networks.BroadcastDomainType.Vsp);
+        return networkObject;
+    }
+
+    @Override
+    public Network implement(Network network, NetworkOffering offering, DeployDestination dest, ReservationContext context) throws InsufficientVirtualNetworkCapacityException {
+
+        assert (network.getState() == State.Implementing) : "Why are we implementing " + network;
+
+        long dcId = dest.getDataCenter().getId();
+        //Get physical network id
+        Long physicalNetworkId = network.getPhysicalNetworkId();
+        //Physical network id can be null in Guest Network in Basic zone, so locate the physical network
+        if (physicalNetworkId == null) {
+            physicalNetworkId = _networkModel.findPhysicalNetworkId(dcId, offering.getTags(), offering.getTrafficType());
+        }
+        NetworkVO implemented = new NetworkVO(network.getTrafficType(), network.getMode(), network.getBroadcastDomainType(), network.getNetworkOfferingId(), State.Allocated,
+                network.getDataCenterId(), physicalNetworkId);
+        if (network.getGateway() != null) {
+            implemented.setGateway(network.getGateway());
+        }
+        if (network.getCidr() != null) {
+            implemented.setCidr(network.getCidr());
+        }
+        Collection<String> ipAddressRange = new ArrayList<String>();
+        String virtualRouterIp = getVirtualRouterIP(network, ipAddressRange);
+        String networkUuid = implemented.getUuid();
+        String tenantId = context.getDomain().getName() + "-" + context.getAccount().getAccountId();
+        String broadcastUriStr = networkUuid + "/" + virtualRouterIp;
+        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 = "CS project support is not yet implemented in NuageVsp";
+            s_logger.debug(errorMessage);
+            throw new InsufficientVirtualNetworkCapacityException(errorMessage, Account.class, network.getAccountId());
+        }
+        boolean isL3Network = isL3Network(offering.getId());
+        String vpcName = null;
+        String vpcUuid = null;
+        if (isVpc) {
+            Vpc vpcObj = _vpcDao.findById(vpcId);
+            vpcName = vpcObj.getName();
+            vpcUuid = vpcObj.getUuid();
+        }
+
+        HostVO nuageVspHost = getNuageVspHost(physicalNetworkId);
+        ImplementNetworkVspCommand cmd = new ImplementNetworkVspCommand(networksDomain.getName(), networksDomain.getPath(), networksDomain.getUuid(),
+                networksAccount.getAccountName(), networksAccount.getUuid(), network.getName(), network.getCidr(), network.getGateway(), network.getUuid(), isL3Network, vpcName,
+                vpcUuid, offering.getEgressDefaultPolicy(), ipAddressRange);
+        ImplementNetworkVspAnswer answer = (ImplementNetworkVspAnswer)_agentMgr.easySend(nuageVspHost.getId(), cmd);
+
+        if (answer == null || !answer.getResult()) {
+            s_logger.error("ImplementNetworkNuageVspCommand failed");
+            if ((null != answer) && (null != answer.getDetails())) {
+                s_logger.error(answer.getDetails());
+            }
+            return null;
+        }
+        s_logger.info("Implemented OK, network " + networkUuid + " in tenant " + tenantId + " linked to " + implemented.getBroadcastUri().toString());
+        return implemented;
+    }
+
+    @Override
+    public NicProfile allocate(Network network, NicProfile nic, VirtualMachineProfile vm) throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException {
+
+        return super.allocate(network, nic, vm);
+    }
+
+    @Override
+    public void reserve(NicProfile nic, Network network, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context)
+            throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException {
+        nic.setBroadcastUri(network.getBroadcastUri());
+        nic.setIsolationUri(network.getBroadcastUri());
+
+        s_logger.debug("Handling reserve() call back to with Create a new VM or add an interface to existing VM in network " + network.getName());
+        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);
+        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());
+        long networkOfferingId = _ntwkOfferingDao.findById(network.getNetworkOfferingId()).getId();
+        boolean isL3Network = isL3Network(networkOfferingId);
+        Long vpcId = network.getVpcId();
+        String vpcUuid = null;
+        if (vpcId != null) {
+            Vpc vpcObj = _vpcDao.findById(vpcId);
+            vpcUuid = vpcObj.getUuid();
+        }
+        HostVO nuageVspHost = getNuageVspHost(network.getPhysicalNetworkId());
+        ReserveVmInterfaceVspCommand cmd = new ReserveVmInterfaceVspCommand(nicFrmDB.getUuid(), nic.getMacAddress(), network.getUuid(), isL3Network, vpcUuid,
+                networksDomain.getUuid(), networksAccount.getUuid(), vm.getType().equals(VirtualMachine.Type.DomainRouter), network.getBroadcastUri().getPath().substring(1),
+                vm.getInstanceName(), vm.getUuid(), networksDomain.getUuid(), networksAccount.getUuid());
+        ReserveVmInterfaceVspAnswer answer = (ReserveVmInterfaceVspAnswer)_agentMgr.easySend(nuageVspHost.getId(), cmd);
+
+        if (answer == null || !answer.getResult()) {
+            s_logger.error("ReserveVmInterfaceNuageVspCommand failed");
+            if ((null != answer) && (null != answer.getDetails())) {
+                s_logger.error(answer.getDetails());
+            }
+            throw new InsufficientVirtualNetworkCapacityException("Failed to reserve VM in Nuage VSP.", Network.class, network.getId());
+        }
+        List<Map<String, String>> vmInterfacesDetails = answer.getInterfaceDetails();
+        setIPGatewayMaskInfo(network, nic, vmInterfacesDetails);
+    }
+
+    @Override
+    protected boolean canHandle(NetworkOffering offering, final NetworkType networkType, final PhysicalNetwork physicalNetwork) {
+        if (networkType == NetworkType.Advanced && isMyTrafficType(offering.getTrafficType()) && offering.getGuestType() == Network.GuestType.Isolated
+                && isMyIsolationMethod(physicalNetwork)) {
+            return true;
+        } else {
+            s_logger.trace("We only take care of Guest networks of type   " + GuestType.Isolated + " in zone of type " + NetworkType.Advanced);
+            return false;
+        }
+    }
+
+    @Override
+    public boolean release(NicProfile nic, VirtualMachineProfile vm, String reservationId) {
+        long networkId = nic.getNetworkId();
+        Network network = _networkDao.findById(networkId);
+        s_logger.debug("Handling release() call back, which is called when a VM is stopped or destroyed, to delete the VM with state " + vm.getVirtualMachine().getState()
+                + " from netork " + network.getName());
+        if (vm.getVirtualMachine().getState().equals(VirtualMachine.State.Stopping)) {
+            try {
+                HostVO nuageVspHost = getNuageVspHost(network.getPhysicalNetworkId());
+                ReleaseVmVspCommand cmd = new ReleaseVmVspCommand(network.getUuid(), vm.getUuid(), vm.getInstanceName());
+                ReleaseVmVspAnswer answer = (ReleaseVmVspAnswer)_agentMgr.easySend(nuageVspHost.getId(), cmd);
+                if (answer == null || !answer.getResult()) {
+                    s_logger.error("ReleaseVmNuageVspCommand for VM " + vm.getUuid() + " failed");
+                    if ((null != answer) && (null != answer.getDetails())) {
+                        s_logger.error(answer.getDetails());
+                    }
+                }
+            } catch (InsufficientVirtualNetworkCapacityException e) {
+                s_logger.debug("Handling release() call back. Failed to delete CS VM " + vm.getInstanceName() + " in VSP. " + e.getMessage());
+            }
+        } else {
+            s_logger.debug("Handling release() call back. VM " + vm.getInstanceName() + " is in " + vm.getVirtualMachine().getState() + " state. So, the CS VM is not deleted."
+                    + " This could be a case where VM interface is deleted. deallocate() call back should be called later");
+        }
+
+        return super.release(nic, vm, reservationId);
+    }
+
+    @Override
+    @DB
+    public void deallocate(Network network, NicProfile nic, VirtualMachineProfile vm) {
+
+        try {
+            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.getIp4Address() + " from a VM " + vm.getInstanceName() + " with state " + vm.getVirtualMachine().getState());
+            DomainVO networksDomain = _domainDao.findById(network.getDomainId());
+            NicVO nicFrmDd = _nicDao.findById(nic.getId());
+            long networkOfferingId = _ntwkOfferingDao.findById(network.getNetworkOfferingId()).getId();
+            Long vpcId = network.getVpcId();
+            String vpcUuid = null;
+            if (vpcId != null) {
+                Vpc vpcObj = _vpcDao.findById(vpcId);
+                vpcUuid = vpcObj.getUuid();
+            }
+            HostVO nuageVspHost = getNuageVspHost(network.getPhysicalNetworkId());
+            DeallocateVmVspCommand cmd = new DeallocateVmVspCommand(network.getUuid(), nicFrmDd.getUuid(), nic.getMacAddress(), nic.getIp4Address(),
+                    isL3Network(networkOfferingId), vpcUuid, networksDomain.getUuid(), vm.getInstanceName(), vm.getUuid());
+            DeallocateVmVspAnswer answer = (DeallocateVmVspAnswer)_agentMgr.easySend(nuageVspHost.getId(), cmd);
+            if (answer == null || !answer.getResult()) {
+                s_logger.error("DeallocateVmNuageVspCommand for VM " + vm.getUuid() + " failed");
+                if ((null != answer) && (null != answer.getDetails())) {
+                    s_logger.error(answer.getDetails());
+                }
+            }
+        } catch (InsufficientVirtualNetworkCapacityException e) {
+            s_logger.error("Handling deallocate(). VM " + vm.getInstanceName() + " with NIC IP " + nic.getIp4Address()
+                    + " is getting destroyed. REST API failed to update the VM state in NuageVsp", e);
+        }
+        super.deallocate(network, nic, vm);
+    }
+
+    @Override
+    public void shutdown(NetworkProfile profile, NetworkOffering offering) {
+        super.shutdown(profile, offering);
+    }
+
+    @Override
+    public boolean trash(Network network, NetworkOffering offering) {
+
+        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);
+        Long vpcId = network.getVpcId();
+        String vpcUuid = null;
+        if (vpcId != null) {
+            Vpc vpcObj = _vpcDao.findById(vpcId);
+            vpcUuid = vpcObj.getUuid();
+        }
+        try {
+            HostVO nuageVspHost = getNuageVspHost(network.getPhysicalNetworkId());
+            TrashNetworkVspCommand cmd = new TrashNetworkVspCommand(domain.getUuid(), network.getUuid(), isL3Network(offering.getId()), vpcUuid);
+            TrashNetworkVspAnswer answer = (TrashNetworkVspAnswer)_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())) {
+                    s_logger.error(answer.getDetails());
+                }
+            }
+        } catch (Exception e) {
+            s_logger.warn("Failed to clean up network information in Vsp " + e.getMessage());
+        }
+
+        return super.trash(network, offering);
+    }
+
+    private String getVirtualRouterIP(Network network, Collection<String> addressRange) throws InsufficientVirtualNetworkCapacityException {
+        String virtualRouterIp;
+        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.size() > 3) {
+            Iterator<Long> ipIterator = allIPsInCidr.iterator();
+            long vip = ipIterator.next();
+            if (NetUtils.ip2Long(network.getGateway()) == vip) {
+                s_logger.debug("Gateway of the Network(" + network.getUuid() + ") has the first IP " + NetUtils.long2Ip(vip));
+                vip = ipIterator.next();
+                virtualRouterIp = NetUtils.long2Ip(vip);
+                s_logger.debug("So, reserving the 2nd IP " + virtualRouterIp + " for the Virtual Router IP in Network(" + network.getUuid() + ")");
+            } else {
+                virtualRouterIp = NetUtils.long2Ip(vip);
+                s_logger.debug("1nd IP is not used as the gateway IP. So, reserving" + virtualRouterIp + " for the Virtual Router IP for " + "Network(" + network.getUuid() + ")");
+            }
+            addressRange.add(NetUtils.long2Ip(ipIterator.next()));
+            addressRange.add(NetUtils.long2Ip((Long)allIPsInCidr.toArray()[allIPsInCidr.size() - 1]));
+            return virtualRouterIp;
+        }
+
+        throw new InsufficientVirtualNetworkCapacityException("VSP allocates an IP for VirtualRouter." + " So, subnet should have atleast minimum 4 hosts ", Network.class,
+                network.getId());
+    }
+
+    private void setIPGatewayMaskInfo(Network network, NicProfile nic, List<Map<String, String>> vmInterfacesDetails) throws InsufficientVirtualNetworkCapacityException {
+        try {
+            for (Map<String, String> interfaces : vmInterfacesDetails) {
+                String macFromNuage = interfaces.get("mac");
+                if (StringUtils.equals(macFromNuage, nic.getMacAddress())) {
+                    nic.setIp4Address(interfaces.get("ip4Address"));
+                    nic.setGateway(interfaces.get("gateway"));
+                    nic.setNetmask(interfaces.get("netmask"));
+                    break;
+                }
+            }
+        } catch (Exception e) {
+            s_logger.error("Failed to parse the VM interface Json response from VSP REST API. VM interface json string is  " + vmInterfacesDetails, e);
+            throw new InsufficientVirtualNetworkCapacityException("Failed to parse the VM interface Json response from VSP REST API. VM interface Json " + "string is  "
+                    + vmInterfacesDetails + ". So. failed to get IP for the VM from VSP address for network " + network, Network.class, network.getId());
+        }
+    }
+
+    private boolean isL3Network(Long offeringId) {
+        return _ntwkOfferingSrvcDao.areServicesSupportedByNetworkOffering(offeringId, Service.SourceNat)
+                || _ntwkOfferingSrvcDao.areServicesSupportedByNetworkOffering(offeringId, Service.StaticNat);
+    }
+
+    private HostVO getNuageVspHost(long physicalNetworkId) throws InsufficientVirtualNetworkCapacityException {
+        HostVO nuageVspHost;
+        List<NuageVspDeviceVO> nuageVspDevices = _nuageVspDao.listByPhysicalNetwork(physicalNetworkId);
+        if (nuageVspDevices != null && (!nuageVspDevices.isEmpty())) {
+            NuageVspDeviceVO config = nuageVspDevices.iterator().next();
+            nuageVspHost = _hostDao.findById(config.getHostId());
+            _hostDao.loadDetails(nuageVspHost);
+        } else {
+            throw new InsufficientVirtualNetworkCapacityException("Nuage VSD is not configured on physical network ", PhysicalNetwork.class, physicalNetworkId);
+        }
+        return nuageVspHost;
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/03de9cc3/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
new file mode 100644
index 0000000..2b4d2b5
--- /dev/null
+++ b/plugins/network-elements/nuage-vsp/src/com/cloud/network/manager/NuageVspManager.java
@@ -0,0 +1,55 @@
+//
+// 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.manager;
+
+import java.util.List;
+
+import org.apache.cloudstack.framework.config.ConfigKey;
+import org.apache.cloudstack.framework.config.ConfigKey.Scope;
+
+import com.cloud.api.commands.AddNuageVspDeviceCmd;
+import com.cloud.api.commands.DeleteNuageVspDeviceCmd;
+import com.cloud.api.commands.ListNuageVspDevicesCmd;
+import com.cloud.api.response.NuageVspDeviceResponse;
+import com.cloud.network.NuageVspDeviceVO;
+import com.cloud.utils.component.PluggableService;
+
+public interface NuageVspManager extends PluggableService {
+
+    static final String NUAGE_VPC_OFFERING_NAME = "Default VPC offering with NuageVsp";
+
+    static final String NUAGE_VPC_OFFERING_DISPLAY_TEXT = "Default VPC offering with NuageVsp";
+
+    static final ConfigKey<Integer> NuageVspSyncInterval = new ConfigKey<Integer>(Integer.class, "nuagevsp.sync.interval", "Advanced", "480",
+            "The interval (in minutes) to wait before running the next synchronization worker to synchronize the information between CloudStack and NuageVsp", false, Scope.Global,
+            1);
+
+    static final ConfigKey<Integer> NuageVspSyncWorkers = new ConfigKey<Integer>(Integer.class, "nuagevsp.sync.workers", "Advanced", "1",
+            "Number of workers to synchronize the information between CloudStack and NuageVsp", false, Scope.Global, 1);
+
+    NuageVspDeviceVO addNuageVspDevice(AddNuageVspDeviceCmd cmd);
+
+    NuageVspDeviceResponse createNuageVspDeviceResponse(NuageVspDeviceVO nuageVspDeviceVO);
+
+    boolean deleteNuageVspDevice(DeleteNuageVspDeviceCmd cmd);
+
+    List<NuageVspDeviceVO> listNuageVspDevices(ListNuageVspDevicesCmd cmd);
+
+}