You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by re...@apache.org on 2015/12/28 11:22:25 UTC

[01/16] git commit: updated refs/heads/master to 67b753c

Repository: cloudstack
Updated Branches:
  refs/heads/master 60f006569 -> 67b753c11


CLOUDSTACK-9074: Add NetworkGuruAdditionalFunctions license


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/0b20ed40
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/0b20ed40
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/0b20ed40

Branch: refs/heads/master
Commit: 0b20ed4074484113973d8f447b8b8a79c778210d
Parents: c285d6c
Author: nvazquez <ni...@gmail.com>
Authored: Thu Dec 24 11:33:06 2015 -0300
Committer: nvazquez <ni...@gmail.com>
Committed: Thu Dec 24 16:07:06 2015 -0300

----------------------------------------------------------------------
 .../guru/NetworkGuruAdditionalFunctions.java        | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/0b20ed40/api/src/com/cloud/network/guru/NetworkGuruAdditionalFunctions.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/network/guru/NetworkGuruAdditionalFunctions.java b/api/src/com/cloud/network/guru/NetworkGuruAdditionalFunctions.java
index 43a1871..b318221 100644
--- a/api/src/com/cloud/network/guru/NetworkGuruAdditionalFunctions.java
+++ b/api/src/com/cloud/network/guru/NetworkGuruAdditionalFunctions.java
@@ -1,3 +1,19 @@
+// 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.Map;


[16/16] git commit: updated refs/heads/master to 67b753c

Posted by re...@apache.org.
Merge pull request #1094 from nvazquez/sharedNiciraNVP

CLOUDSTACK-9074: Support shared networking in NiciraNVP PluginJIRA TICKET:
https://issues.apache.org/jira/browse/CLOUDSTACK-9074

Design Document:
https://cwiki.apache.org/confluence/display/CLOUDSTACK/Support+shared+networking+in+NiciraNVP+Plugin

* pr/1094:
  CLOUDSTACK-9074: Move sql to 4.8.0 schema
  CLOUDSTACK-9074: Add NetworkGuruAdditionalFunctions license
  Use NSX specific config values instead of zone config values
  Fix method call bugs when accessign non defined variables
  Use helper method to migrate router vm
  Add helper method to migrate router vms
  Only set L2 Gateway in NSX device if defined
  CLOUDSTACK-9074: Marvin tests for NSX Shared Networks Support
  CLOUDSTACK-9074: Drop nicira_nvp_router_map unique index on logicalrouter_uuid
  CLOUDSTACK-9074: API add Gateway Service Find method
  CLOUDSTACK-9074: Support Shared Networks in NiciraNVP Plugin
  CLOUDSTACK-9074: New NiciraNVP classes for FindLRouterPort and DeleteLRouterPort API methods
  CLOUDSTACK-9074: New NiciraNVP classes to support Shared Networks
  CLOUDSTACK-9074: API Changes: Add nsxLogicalSwitch and nsxLogicalSwitchPort to listNics
  CLOUDSTACK-9074: API Changes: Add l2gatewayserviceuuid to NVP devices

Signed-off-by: Remi Bergsma <gi...@remi.nl>


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/67b753c1
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/67b753c1
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/67b753c1

Branch: refs/heads/master
Commit: 67b753c11bab236187a0a68d92ca8e49cef1b3fd
Parents: 60f0065 de23c94
Author: Remi Bergsma <gi...@remi.nl>
Authored: Mon Dec 28 11:21:56 2015 +0100
Committer: Remi Bergsma <gi...@remi.nl>
Committed: Mon Dec 28 11:21:56 2015 +0100

----------------------------------------------------------------------
 .../guru/NetworkGuruAdditionalFunctions.java    |  28 ++
 .../org/apache/cloudstack/api/ApiConstants.java |   1 +
 .../cloudstack/api/response/NicResponse.java    |  16 ++
 .../classes/resources/messages.properties       |   1 +
 .../com/cloud/vm/VirtualMachineManagerImpl.java |   8 +-
 .../orchestration/NetworkOrchestrator.java      | 113 +++++---
 .../src/com/cloud/network/dao/NetworkVO.java    |  11 +
 engine/schema/src/com/cloud/vm/NicVO.java       |  23 ++
 .../api/ConfigureSharedNetworkUuidAnswer.java   |  32 +++
 .../api/ConfigureSharedNetworkUuidCommand.java  |  85 +++++++
 .../api/ConfigureSharedNetworkVlanIdAnswer.java |  31 +++
 .../ConfigureSharedNetworkVlanIdCommand.java    |  84 ++++++
 .../api/DeleteLogicalRouterPortAnswer.java      |  31 +++
 .../api/DeleteLogicalRouterPortCommand.java     |  53 ++++
 .../agent/api/FindL2GatewayServiceAnswer.java   |  38 +++
 .../agent/api/FindL2GatewayServiceCommand.java  |  46 ++++
 .../agent/api/FindLogicalRouterPortAnswer.java  |  38 +++
 .../agent/api/FindLogicalRouterPortCommand.java |  59 +++++
 .../api/commands/AddNiciraNvpDeviceCmd.java     |  10 +
 .../api/response/NiciraNvpDeviceResponse.java   |   7 +
 .../network/dao/NiciraNvpRouterMappingDao.java  |   2 +
 .../dao/NiciraNvpRouterMappingDaoImpl.java      |   9 +
 .../cloud/network/element/NiciraNvpElement.java |  86 ++++++-
 .../network/guru/NiciraNvpGuestNetworkGuru.java | 129 +++++++++-
 .../network/nicira/GatewayServiceConfig.java    |  47 ++++
 .../network/nicira/L2GatewayAttachment.java     |  53 ++++
 .../network/nicira/L2GatewayServiceConfig.java  |  30 +++
 .../cloud/network/nicira/NiciraConstants.java   |   3 +
 .../com/cloud/network/nicira/NiciraNvpApi.java  |  58 ++++-
 .../network/nicira/NiciraNvpApiException.java   |  25 ++
 .../cloud/network/nicira/NiciraRestClient.java  |   6 +-
 ...onfigureSharedNetworkUuidCommandWrapper.java | 196 ++++++++++++++
 ...figureSharedNetworkVlanIdCommandWrapper.java | 118 +++++++++
 ...vpDeleteLogicalRouterPortCommandWrapper.java |  59 +++++
 ...raNvpFindL2GatewayServiceCommandWrapper.java |  69 +++++
 ...aNvpFindLogicalRouterPortCommandWrapper.java |  68 +++++
 .../network/element/NiciraNvpElementTest.java   | 213 +++++++++++++++-
 .../guru/NiciraNvpGuestNetworkGuruTest.java     |   6 +-
 server/src/com/cloud/api/ApiResponseHelper.java |   9 +
 .../cloud/network/guru/DirectNetworkGuru.java   |   3 +-
 setup/db/db/schema-461to470.sql                 |   1 +
 setup/db/db/schema-471to480.sql                 |   2 +
 .../plugins/test_nicira_controller.py           | 255 +++++++++++++++----
 tools/marvin/marvin/lib/base.py                 |  13 +-
 tools/marvin/marvin/lib/common.py               |  24 +-
 ui/dictionary.jsp                               |   1 +
 ui/scripts/system.js                            |  21 +-
 .../utils/rest/CloudstackRESTException.java     |  16 ++
 .../cloud/utils/rest/HttpStatusCodeHelper.java  |   4 +
 .../cloud/utils/rest/RESTServiceConnector.java  |   2 +-
 50 files changed, 2118 insertions(+), 125 deletions(-)
----------------------------------------------------------------------



[08/16] git commit: updated refs/heads/master to 67b753c

Posted by re...@apache.org.
CLOUDSTACK-9074: API add Gateway Service Find method


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/eb889c0c
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/eb889c0c
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/eb889c0c

Branch: refs/heads/master
Commit: eb889c0c49313184609d31d4492c58eb0ff19f31
Parents: c676371
Author: nvazquez <ni...@gmail.com>
Authored: Wed Dec 9 10:55:30 2015 -0800
Committer: nvazquez <ni...@gmail.com>
Committed: Thu Dec 24 16:07:06 2015 -0300

----------------------------------------------------------------------
 .../agent/api/FindL2GatewayServiceAnswer.java   | 38 +++++++++++
 .../agent/api/FindL2GatewayServiceCommand.java  | 46 +++++++++++++
 .../network/guru/NiciraNvpGuestNetworkGuru.java | 37 ++++++++++-
 .../network/nicira/GatewayServiceConfig.java    | 47 +++++++++++++
 .../network/nicira/L2GatewayServiceConfig.java  | 30 +++++++++
 .../cloud/network/nicira/NiciraConstants.java   |  2 +
 .../com/cloud/network/nicira/NiciraNvpApi.java  | 46 +++++++++----
 .../network/nicira/NiciraNvpApiException.java   | 25 +++++++
 .../cloud/network/nicira/NiciraRestClient.java  |  4 +-
 ...raNvpFindL2GatewayServiceCommandWrapper.java | 69 ++++++++++++++++++++
 .../guru/NiciraNvpGuestNetworkGuruTest.java     |  2 +-
 .../utils/rest/CloudstackRESTException.java     | 16 +++++
 .../cloud/utils/rest/RESTServiceConnector.java  |  2 +-
 13 files changed, 346 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/eb889c0c/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/agent/api/FindL2GatewayServiceAnswer.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/agent/api/FindL2GatewayServiceAnswer.java b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/agent/api/FindL2GatewayServiceAnswer.java
new file mode 100644
index 0000000..16f24eb
--- /dev/null
+++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/agent/api/FindL2GatewayServiceAnswer.java
@@ -0,0 +1,38 @@
+//
+// 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.agent.api;
+
+public class FindL2GatewayServiceAnswer extends Answer {
+
+    private String gatewayServiceUuid;
+
+    public FindL2GatewayServiceAnswer(final Command command, final boolean success, final String details, final String gatewayServiceUuid) {
+        super(command, success, details);
+        this.gatewayServiceUuid = gatewayServiceUuid;
+    }
+
+    public FindL2GatewayServiceAnswer(final Command command, final Exception e) {
+        super(command, e);
+    }
+
+    public String getGatewayServiceUuid() {
+        return gatewayServiceUuid;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/eb889c0c/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/agent/api/FindL2GatewayServiceCommand.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/agent/api/FindL2GatewayServiceCommand.java b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/agent/api/FindL2GatewayServiceCommand.java
new file mode 100644
index 0000000..a3ec1dc
--- /dev/null
+++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/agent/api/FindL2GatewayServiceCommand.java
@@ -0,0 +1,46 @@
+//
+// 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.agent.api;
+
+import com.cloud.network.nicira.GatewayServiceConfig;
+import com.cloud.network.nicira.L2GatewayServiceConfig;
+
+public class FindL2GatewayServiceCommand extends Command {
+
+    private L2GatewayServiceConfig gatewayServiceConfig;
+
+    public FindL2GatewayServiceCommand(L2GatewayServiceConfig config) {
+        this.gatewayServiceConfig = config;
+    }
+
+    @Override
+    public boolean executeInSequence() {
+        return false;
+    }
+
+    public GatewayServiceConfig getGatewayServiceConfig() {
+        return gatewayServiceConfig;
+    }
+
+    public void setGatewayServiceConfig(L2GatewayServiceConfig gatewayServiceConfig) {
+        this.gatewayServiceConfig = gatewayServiceConfig;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/eb889c0c/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/guru/NiciraNvpGuestNetworkGuru.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/guru/NiciraNvpGuestNetworkGuru.java b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/guru/NiciraNvpGuestNetworkGuru.java
index f83f8ee..551269c 100644
--- a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/guru/NiciraNvpGuestNetworkGuru.java
+++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/guru/NiciraNvpGuestNetworkGuru.java
@@ -36,6 +36,8 @@ import com.cloud.agent.api.DeleteLogicalRouterPortAnswer;
 import com.cloud.agent.api.DeleteLogicalRouterPortCommand;
 import com.cloud.agent.api.DeleteLogicalSwitchAnswer;
 import com.cloud.agent.api.DeleteLogicalSwitchCommand;
+import com.cloud.agent.api.FindL2GatewayServiceAnswer;
+import com.cloud.agent.api.FindL2GatewayServiceCommand;
 import com.cloud.agent.api.FindLogicalRouterPortAnswer;
 import com.cloud.agent.api.FindLogicalRouterPortCommand;
 import com.cloud.dc.DataCenter;
@@ -54,10 +56,10 @@ import com.cloud.network.Network.Service;
 import com.cloud.network.Network.State;
 import com.cloud.network.NetworkModel;
 import com.cloud.network.NetworkProfile;
-import com.cloud.network.NiciraNvpNicMappingVO;
-import com.cloud.network.NiciraNvpRouterMappingVO;
 import com.cloud.network.Networks.BroadcastDomainType;
 import com.cloud.network.NiciraNvpDeviceVO;
+import com.cloud.network.NiciraNvpNicMappingVO;
+import com.cloud.network.NiciraNvpRouterMappingVO;
 import com.cloud.network.PhysicalNetwork;
 import com.cloud.network.PhysicalNetwork.IsolationMethod;
 import com.cloud.network.dao.NetworkDao;
@@ -67,6 +69,7 @@ import com.cloud.network.dao.NiciraNvpNicMappingDao;
 import com.cloud.network.dao.NiciraNvpRouterMappingDao;
 import com.cloud.network.dao.PhysicalNetworkDao;
 import com.cloud.network.dao.PhysicalNetworkVO;
+import com.cloud.network.nicira.L2GatewayServiceConfig;
 import com.cloud.offering.NetworkOffering;
 import com.cloud.offerings.dao.NetworkOfferingServiceMapDao;
 import com.cloud.resource.ResourceManager;
@@ -209,6 +212,16 @@ public class NiciraNvpGuestNetworkGuru extends GuestNetworkGuru implements Netwo
         final String transportzoneuuid = niciraNvpHost.getDetail("transportzoneuuid");
         final String transportzoneisotype = niciraNvpHost.getDetail("transportzoneisotype");
 
+        if (offering.getGuestType().equals(GuestType.Shared)) {
+            try {
+                checkL2GatewayServiceSharedNetwork(niciraNvpHost);
+            }
+            catch (Exception e){
+                s_logger.error("L2 Gateway Service Issue: " + e.getMessage());
+                return null;
+            }
+        }
+
         final CreateLogicalSwitchCommand cmd = new CreateLogicalSwitchCommand(transportzoneuuid, transportzoneisotype, name, context.getDomain().getName() + "-"
                 + context.getAccount().getAccountName());
         final CreateLogicalSwitchAnswer answer = (CreateLogicalSwitchAnswer) agentMgr.easySend(niciraNvpHost.getId(), cmd);
@@ -230,6 +243,26 @@ public class NiciraNvpGuestNetworkGuru extends GuestNetworkGuru implements Netwo
         return implemented;
     }
 
+    private void checkL2GatewayServiceSharedNetwork(HostVO niciraNvpHost) throws Exception {
+        String l2GatewayServiceUuid = niciraNvpHost.getDetail("l2gatewayserviceuuid");
+        if (l2GatewayServiceUuid == null){
+            throw new Exception("No L2 Gateway Service found");
+        }
+        else {
+            final FindL2GatewayServiceCommand cmdL2GWService = new FindL2GatewayServiceCommand(new L2GatewayServiceConfig(l2GatewayServiceUuid));
+            final FindL2GatewayServiceAnswer answerL2GWService = (FindL2GatewayServiceAnswer) agentMgr.easySend(niciraNvpHost.getId(), cmdL2GWService);
+            if (answerL2GWService == null || !answerL2GWService.getResult()){
+                throw new Exception("No L2 Gateway Service found with uuid " + l2GatewayServiceUuid);
+            }
+            else {
+                String uuidFound = answerL2GWService.getGatewayServiceUuid();
+                if (! uuidFound.equals(l2GatewayServiceUuid)){
+                    throw new Exception("Found L2 Gateway Service " + uuidFound + " instead of " + l2GatewayServiceUuid);
+                }
+            }
+        }
+    }
+
     @Override
     public void reserve(final NicProfile nic, final Network network, final VirtualMachineProfile vm, final DeployDestination dest, final ReservationContext context)
             throws InsufficientVirtualNetworkCapacityException, InsufficientAddressCapacityException {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/eb889c0c/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/GatewayServiceConfig.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/GatewayServiceConfig.java b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/GatewayServiceConfig.java
new file mode 100644
index 0000000..abfd273
--- /dev/null
+++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/GatewayServiceConfig.java
@@ -0,0 +1,47 @@
+//
+// 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.nicira;
+
+import java.io.Serializable;
+
+public abstract class GatewayServiceConfig implements Serializable {
+
+    private String uuid;
+    private String displayName;
+    private String type;
+
+    public GatewayServiceConfig(String uuid, String type) {
+        this.uuid = uuid;
+        this.type = type;
+    }
+
+    public String getUuid() {
+        return uuid;
+    }
+
+    public String getDisplayName() {
+        return displayName;
+    }
+
+    public String getType() {
+        return type;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/eb889c0c/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/L2GatewayServiceConfig.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/L2GatewayServiceConfig.java b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/L2GatewayServiceConfig.java
new file mode 100644
index 0000000..7f2a41a
--- /dev/null
+++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/L2GatewayServiceConfig.java
@@ -0,0 +1,30 @@
+//
+// 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.nicira;
+
+public class L2GatewayServiceConfig extends GatewayServiceConfig {
+
+    private static final String L2GWTServiceConfigType = "L2GatewayServiceConfig";
+
+    public L2GatewayServiceConfig(String uuid) {
+        super(uuid, L2GWTServiceConfigType);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/eb889c0c/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraConstants.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraConstants.java b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraConstants.java
index d5f7ca6..f89b8ad 100644
--- a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraConstants.java
+++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraConstants.java
@@ -25,6 +25,7 @@ public class NiciraConstants {
     public static final String ACL_URI_PREFIX = "/ws.v1/acl";
     public static final String SWITCH_URI_PREFIX = "/ws.v1/lswitch";
     public static final String ROUTER_URI_PREFIX = "/ws.v1/lrouter";
+    public static final String GATEWAY_SERVICE_PREFIX = "/ws.v1/gateway-service";
     public static final String LOGIN_URL = "/ws.v1/login";
     public static final String CONTROL_CLUSTER_STATUS_URL = "/ws.v1/control-cluster/status";
 
@@ -39,5 +40,6 @@ public class NiciraConstants {
     public static final String WILDCARD_QUERY_PARAMETER = "*";
     public static final String UUID_QUERY_PARAMETER = "uuid";
     public static final String FIELDS_QUERY_PARAMETER = "fields";
+    public static final String TYPES_QUERY_PARAMETER = "types";
 
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/eb889c0c/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraNvpApi.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraNvpApi.java b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraNvpApi.java
index b1113a2..293c5a8 100644
--- a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraNvpApi.java
+++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraNvpApi.java
@@ -42,6 +42,7 @@ public class NiciraNvpApi {
 
     private static final String SWITCH_URI_PREFIX = NiciraConstants.SWITCH_URI_PREFIX;
     private static final String ROUTER_URI_PREFIX = NiciraConstants.ROUTER_URI_PREFIX;
+    private static final String GATEWAY_SERVICE_PREFIX = NiciraConstants.GATEWAY_SERVICE_PREFIX;
 
     private static final String ATTACHMENT_PATH_SEGMENT = NiciraConstants.ATTACHMENT_PATH_SEGMENT;
     private static final String NAT_PATH_SEGMENT = NiciraConstants.NAT_PATH_SEGMENT;
@@ -51,6 +52,7 @@ public class NiciraNvpApi {
     private static final String WILDCARD_QUERY_PARAMETER = NiciraConstants.WILDCARD_QUERY_PARAMETER;
     private static final String UUID_QUERY_PARAMETER = NiciraConstants.UUID_QUERY_PARAMETER;
     private static final String FIELDS_QUERY_PARAMETER = NiciraConstants.FIELDS_QUERY_PARAMETER;
+    private static final String TYPES_QUERY_PARAMETER = NiciraConstants.TYPES_QUERY_PARAMETER;
 
     private static final int DEFAULT_MAX_RETRIES = 5;
 
@@ -131,7 +133,7 @@ public class NiciraNvpApi {
         try {
             createdEntity = restConnector.executeCreateObject(entity, uri, Collections.<String, String> emptyMap());
         } catch (final CloudstackRESTException e) {
-            throw new NiciraNvpApiException(e);
+            throw new NiciraNvpApiException(e, e.getErrorCode());
         }
 
         return createdEntity;
@@ -157,7 +159,7 @@ public class NiciraNvpApi {
         try {
             entities = restConnector.executeRetrieveObject(listTypeMap.get(clazz), uri, params);
         } catch (final CloudstackRESTException e) {
-            throw new NiciraNvpApiException(e);
+            throw new NiciraNvpApiException(e, e.getErrorCode());
         }
 
         if (entities == null) {
@@ -190,7 +192,7 @@ public class NiciraNvpApi {
         try {
             restConnector.executeUpdateObject(item, uri, Collections.<String, String> emptyMap());
         } catch (final CloudstackRESTException e) {
-            throw new NiciraNvpApiException(e);
+            throw new NiciraNvpApiException(e, e.getErrorCode());
         }
     }
 
@@ -215,7 +217,7 @@ public class NiciraNvpApi {
         try {
             restConnector.executeDeleteObject(uri);
         } catch (final CloudstackRESTException e) {
-            throw new NiciraNvpApiException(e);
+            throw new NiciraNvpApiException(e, e.getErrorCode());
         }
     }
 
@@ -394,7 +396,7 @@ public class NiciraNvpApi {
             }.getType();
             niciraList = restConnector.executeRetrieveObject(niciraListType, uri, params);
         } catch (final CloudstackRESTException e) {
-            throw new NiciraNvpApiException(e);
+            throw new NiciraNvpApiException(e, e.getErrorCode());
         }
 
         final List<LogicalSwitchPort> lspl = niciraList.getResults();
@@ -413,7 +415,7 @@ public class NiciraNvpApi {
         try {
             return restConnector.executeRetrieveObject(ControlClusterStatus.class, uri, new HashMap<String, String>());
         } catch (final CloudstackRESTException e) {
-            throw new NiciraNvpApiException(e);
+            throw new NiciraNvpApiException(e, e.getErrorCode());
         }
     }
 
@@ -427,7 +429,7 @@ public class NiciraNvpApi {
             }.getType();
             return restConnector.<NiciraNvpList<LogicalSwitchPort>> executeRetrieveObject(niciraListType, uri, params).getResults();
         } catch (final CloudstackRESTException e) {
-            throw new NiciraNvpApiException(e);
+            throw new NiciraNvpApiException(e, e.getErrorCode());
         }
     }
 
@@ -441,7 +443,7 @@ public class NiciraNvpApi {
             }.getType();
             return restConnector.<NiciraNvpList<LogicalRouterPort>> executeRetrieveObject(niciraListType, uri, params).getResults();
         } catch (final CloudstackRESTException e) {
-            throw new NiciraNvpApiException(e);
+            throw new NiciraNvpApiException(e, e.getErrorCode());
         }
     }
 
@@ -522,7 +524,7 @@ public class NiciraNvpApi {
             }.getType();
             return restConnector.<NiciraNvpList<LogicalRouterPort>> executeRetrieveObject(niciraListType, uri, params).getResults();
         } catch (final CloudstackRESTException e) {
-            throw new NiciraNvpApiException(e);
+            throw new NiciraNvpApiException(e, e.getErrorCode());
         }
     }
 
@@ -536,7 +538,7 @@ public class NiciraNvpApi {
             }.getType();
             return restConnector.<NiciraNvpList<LogicalRouterPort>> executeRetrieveObject(niciraListType, uri, params).getResults();
         } catch (final CloudstackRESTException e) {
-            throw new NiciraNvpApiException(e);
+            throw new NiciraNvpApiException(e, e.getErrorCode());
         }
     }
 
@@ -549,7 +551,7 @@ public class NiciraNvpApi {
             }.getType();
             return restConnector.<NiciraNvpList<NatRule>> executeRetrieveObject(niciraListType, uri, params).getResults();
         } catch (final CloudstackRESTException e) {
-            throw new NiciraNvpApiException(e);
+            throw new NiciraNvpApiException(e, e.getErrorCode());
         }
     }
 
@@ -564,10 +566,30 @@ public class NiciraNvpApi {
             }.getType();
             return restConnector.<NiciraNvpList<LogicalRouterPort>> executeRetrieveObject(niciraListType, uri, params).getResults();
         } catch (final CloudstackRESTException e) {
-            throw new NiciraNvpApiException(e);
+            throw new NiciraNvpApiException(e, e.getErrorCode());
         }
     }
 
+    public List<L2GatewayServiceConfig> findL2GatewayServiceByUuidAndType(final String gatewayServiceUuid, final String serviceConfigType) throws NiciraNvpApiException{
+        final String uri = buildGatewayServiceUri();
+        final Map<String, String> params = buildBasicParametersMap(WILDCARD_QUERY_PARAMETER);
+        params.put(UUID_QUERY_PARAMETER, gatewayServiceUuid);
+        params.put(TYPES_QUERY_PARAMETER, serviceConfigType);
+
+        try {
+            final Type niciraListType = new TypeToken<NiciraNvpList<L2GatewayServiceConfig>>() {
+            }.getType();
+            return restConnector.<NiciraNvpList<L2GatewayServiceConfig>> executeRetrieveObject(niciraListType, uri, params).getResults();
+        }
+        catch (final CloudstackRESTException e){
+            throw new NiciraNvpApiException(e, e.getErrorCode());
+        }
+    }
+
+    private static String buildGatewayServiceUri(){
+        return GATEWAY_SERVICE_PREFIX;
+    }
+
     private static Map<String, String> buildBasicParametersMap(final String fieldsQueryValue) {
         final Map<String, String> params = new HashMap<String, String>();
         params.put(FIELDS_QUERY_PARAMETER, fieldsQueryValue);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/eb889c0c/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraNvpApiException.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraNvpApiException.java b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraNvpApiException.java
index 0d27820..f8b3c07 100644
--- a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraNvpApiException.java
+++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraNvpApiException.java
@@ -21,6 +21,8 @@ package com.cloud.network.nicira;
 
 public class NiciraNvpApiException extends Exception {
 
+    private int errorCode;
+
     public NiciraNvpApiException() {
     }
 
@@ -36,4 +38,27 @@ public class NiciraNvpApiException extends Exception {
         super(message, cause);
     }
 
+    public NiciraNvpApiException(final String message, final int errorCode){
+        super(message);
+        this.errorCode = errorCode;
+    }
+
+    public NiciraNvpApiException(final Throwable cause, final int errorCode) {
+        super(cause);
+        this.errorCode = errorCode;
+    }
+
+    public NiciraNvpApiException(final String message, final Throwable cause, final int errorCode) {
+        super(message, cause);
+        this.errorCode = errorCode;
+    }
+
+    public int getErrorCode() {
+        return errorCode;
+    }
+
+    public void setErrorCode(int errorCode) {
+        this.errorCode = errorCode;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/eb889c0c/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraRestClient.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraRestClient.java b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraRestClient.java
index b850c4b..fb66066 100644
--- a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraRestClient.java
+++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraRestClient.java
@@ -92,9 +92,9 @@ public class NiciraRestClient extends BasicRestClient {
         } else if (HttpStatusCodeHelper.isSuccess(statusCode)) {
             return handleSuccessResponse(request, response);
         } else if (HttpStatusCodeHelper.isConflict(statusCode)) {
-            throw new CloudstackRESTException("Conflict: " + statusLine.getReasonPhrase());
+            throw new CloudstackRESTException("Conflict: " + statusLine.getReasonPhrase(), statusCode);
         } else {
-            throw new CloudstackRESTException("Unexpected status code: " + statusCode);
+            throw new CloudstackRESTException("Unexpected status code: " + statusCode, statusCode);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/eb889c0c/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraNvpFindL2GatewayServiceCommandWrapper.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraNvpFindL2GatewayServiceCommandWrapper.java b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraNvpFindL2GatewayServiceCommandWrapper.java
new file mode 100644
index 0000000..621f503
--- /dev/null
+++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraNvpFindL2GatewayServiceCommandWrapper.java
@@ -0,0 +1,69 @@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+
+package com.cloud.network.resource.wrapper;
+
+import static com.cloud.network.resource.NiciraNvpResource.NUM_RETRIES;
+
+import java.util.List;
+
+import org.apache.log4j.Logger;
+
+import com.cloud.agent.api.Answer;
+import com.cloud.agent.api.FindL2GatewayServiceAnswer;
+import com.cloud.agent.api.FindL2GatewayServiceCommand;
+import com.cloud.network.nicira.GatewayServiceConfig;
+import com.cloud.network.nicira.L2GatewayServiceConfig;
+import com.cloud.network.nicira.NiciraNvpApi;
+import com.cloud.network.nicira.NiciraNvpApiException;
+import com.cloud.network.resource.NiciraNvpResource;
+import com.cloud.network.utils.CommandRetryUtility;
+import com.cloud.resource.CommandWrapper;
+import com.cloud.resource.ResourceWrapper;
+
+@ResourceWrapper(handles =  FindL2GatewayServiceCommand.class)
+public class NiciraNvpFindL2GatewayServiceCommandWrapper extends CommandWrapper<FindL2GatewayServiceCommand, Answer, NiciraNvpResource> {
+
+    private static final Logger s_logger = Logger.getLogger(NiciraNvpFindL2GatewayServiceCommandWrapper.class);
+
+    @Override
+    public Answer execute(FindL2GatewayServiceCommand command, NiciraNvpResource niciraNvpResource) {
+        final GatewayServiceConfig config = command.getGatewayServiceConfig();
+        final String uuid = config.getUuid();
+        final String type = config.getType();
+        final NiciraNvpApi niciraNvpApi = niciraNvpResource.getNiciraNvpApi();
+
+        s_logger.info("Looking for L2 Gateway Service " + uuid + " of type " + type);
+
+        try {
+            List<L2GatewayServiceConfig> lstGW = niciraNvpApi.findL2GatewayServiceByUuidAndType(uuid, type);
+            if (lstGW.size() == 0) {
+                return new FindL2GatewayServiceAnswer(command, false, "L2 Gateway Service not found", null);
+            } else {
+                return new FindL2GatewayServiceAnswer(command, true, "L2 Gateway Service " + lstGW.get(0).getDisplayName()+ " found", lstGW.get(0).getUuid());
+            }
+        } catch (NiciraNvpApiException e) {
+            s_logger.error("Error finding Gateway Service due to: " + e.getMessage());
+            final CommandRetryUtility retryUtility = niciraNvpResource.getRetryUtility();
+            retryUtility.addRetry(command, NUM_RETRIES);
+            return retryUtility.retry(command, FindL2GatewayServiceAnswer.class, e);
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/eb889c0c/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/guru/NiciraNvpGuestNetworkGuruTest.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/guru/NiciraNvpGuestNetworkGuruTest.java b/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/guru/NiciraNvpGuestNetworkGuruTest.java
index d7c83b4..f1737c1 100644
--- a/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/guru/NiciraNvpGuestNetworkGuruTest.java
+++ b/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/guru/NiciraNvpGuestNetworkGuruTest.java
@@ -473,4 +473,4 @@ public class NiciraNvpGuestNetworkGuruTest {
         verify(agentmgr, times(1)).easySend(eq(NETWORK_ID), (Command)any());
         verify(implementednetwork, times(1)).setBroadcastUri(null);
     }
-}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/eb889c0c/utils/src/main/java/com/cloud/utils/rest/CloudstackRESTException.java
----------------------------------------------------------------------
diff --git a/utils/src/main/java/com/cloud/utils/rest/CloudstackRESTException.java b/utils/src/main/java/com/cloud/utils/rest/CloudstackRESTException.java
index 2078d57..9b703c6 100644
--- a/utils/src/main/java/com/cloud/utils/rest/CloudstackRESTException.java
+++ b/utils/src/main/java/com/cloud/utils/rest/CloudstackRESTException.java
@@ -22,6 +22,8 @@ package com.cloud.utils.rest;
 @SuppressWarnings("serial")
 public class CloudstackRESTException extends Exception {
 
+    private int errorCode;
+
     public CloudstackRESTException(final String message) {
         super(message);
     }
@@ -30,4 +32,18 @@ public class CloudstackRESTException extends Exception {
         super(message, cause);
     }
 
+    public CloudstackRESTException(final String message, final int errorCode) {
+        super(message);
+        this.errorCode = errorCode;
+    }
+
+    public CloudstackRESTException(final String message, final Throwable cause, final int errorCode) {
+        super(message, cause);
+        this.errorCode = errorCode;
+    }
+
+    public int getErrorCode() {
+        return errorCode;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/eb889c0c/utils/src/main/java/com/cloud/utils/rest/RESTServiceConnector.java
----------------------------------------------------------------------
diff --git a/utils/src/main/java/com/cloud/utils/rest/RESTServiceConnector.java b/utils/src/main/java/com/cloud/utils/rest/RESTServiceConnector.java
index fc5bae3..ffa2905 100644
--- a/utils/src/main/java/com/cloud/utils/rest/RESTServiceConnector.java
+++ b/utils/src/main/java/com/cloud/utils/rest/RESTServiceConnector.java
@@ -127,7 +127,7 @@ public class RESTServiceConnector {
         final HttpEntity entity = response.getEntity();
         try {
             final String stringEntity = EntityUtils.toString(entity);
-            s_logger.debug("Response entity: " + stringEntity);
+            //s_logger.debug("Response entity: " + stringEntity);
             EntityUtils.consumeQuietly(entity);
             return gson.fromJson(stringEntity, type);
         } catch (final IOException e) {


[10/16] git commit: updated refs/heads/master to 67b753c

Posted by re...@apache.org.
CLOUDSTACK-9074: Marvin tests for NSX Shared Networks Support


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/4ac27377
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/4ac27377
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/4ac27377

Branch: refs/heads/master
Commit: 4ac2737754a20c0ff8ccb3f1b9622e0651fe1b8b
Parents: 0726420
Author: nvazquez <ni...@gmail.com>
Authored: Wed Dec 9 10:58:02 2015 -0800
Committer: nvazquez <ni...@gmail.com>
Committed: Thu Dec 24 16:07:06 2015 -0300

----------------------------------------------------------------------
 .../plugins/test_nicira_controller.py           | 210 ++++++++++++++++---
 tools/marvin/marvin/lib/base.py                 |   9 +-
 2 files changed, 189 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4ac27377/test/integration/plugins/test_nicira_controller.py
----------------------------------------------------------------------
diff --git a/test/integration/plugins/test_nicira_controller.py b/test/integration/plugins/test_nicira_controller.py
index 6c625b6..c2523b7 100644
--- a/test/integration/plugins/test_nicira_controller.py
+++ b/test/integration/plugins/test_nicira_controller.py
@@ -54,28 +54,52 @@ class TestNiciraContoller(cloudstackTestCase):
 
         cls.physical_networks = cls.config.zones[0].physical_networks
         cls.nicira_hosts      = cls.config.niciraNvp.hosts
+		
+        cls.l2gatewayserviceuuid   = cls.config.niciraNvp.l2gatewayserviceuuid
 
         cls.physical_network_id = cls.get_nicira_enabled_physical_network_id(cls.physical_networks)
 
-        cls.network_offerring_services = {
-            'name':              'NiciraEnabledNetwork',
-            'displaytext':       'NiciraEnabledNetwork',
-            'guestiptype':       'Isolated',
-            'supportedservices': 'SourceNat,Dhcp,Dns,Firewall,PortForwarding,Connectivity',
-            'traffictype':       'GUEST',
-            'availability':      'Optional',
-            'serviceProviderList': {
-                    'SourceNat':      'VirtualRouter',
-                    'Dhcp':           'VirtualRouter',
-                    'Dns':            'VirtualRouter',
-                    'Firewall':       'VirtualRouter',
-                    'PortForwarding': 'VirtualRouter',
-                    'Connectivity':   'NiciraNvp'
-            }
-        }
-
-        cls.network_offering = NetworkOffering.create(cls.api_client, cls.network_offerring_services)
-        cls.network_offering.update(cls.api_client, state='Enabled')
+        cls.network_offerring_services = [
+			{
+				'name':              'NiciraEnabledNetwork',
+				'displaytext':       'NiciraEnabledNetwork',
+				'guestiptype':       'Isolated',
+            			'supportedservices': 'SourceNat,Dhcp,Dns,Firewall,PortForwarding,Connectivity',
+				'traffictype':       'GUEST',
+				'availability':      'Optional',
+				'serviceProviderList': {
+						'SourceNat':      'VirtualRouter',
+                    				'Dhcp':           'VirtualRouter',
+                    				'Dns':            'VirtualRouter',
+						'Firewall':       'VirtualRouter',
+						'PortForwarding': 'VirtualRouter',
+						'Connectivity':   'NiciraNvp'
+				}
+			},
+			{
+				'name':              'NiciraEnabledSharedNetwork',
+				'displaytext':       'NiciraEnabledSharedNetwork',
+				'guestiptype':       'Shared',
+				'supportedservices': 'Connectivity,Dhcp,UserData',
+				'traffictype':       'GUEST',
+				'availability':      'Optional',
+				'specifyVlan':		'true',
+				'specifyIpRanges':	'true',
+				'serviceProviderList': {
+						'Connectivity':   	'NiciraNvp',
+						'Dhcp':       		'VirtualRouter',
+						'UserData': 		'VirtualRouter'
+				}
+			}
+		]
+
+        cls.network_offering_isolated = NetworkOffering.create(cls.api_client, cls.network_offerring_services[0])
+        cls.network_offering_isolated.update(cls.api_client, state='Enabled')
+
+        cls.network_offering_shared = NetworkOffering.create(cls.api_client, cls.network_offerring_services[1])
+        cls.network_offering_shared.update(cls.api_client, state='Enabled')
+		
+        cls.ip_ranges_shared = cls.config.zones[0].ipranges[0]
 
         cls.nicira_credentials = {
             'username': 'admin',
@@ -123,6 +147,7 @@ class TestNiciraContoller(cloudstackTestCase):
                     'cpunumber':   1,
                     'cpuspeed':    100,
                     'memory':      64,
+					'offerha':		'true'
                 }
             }
         }
@@ -136,8 +161,9 @@ class TestNiciraContoller(cloudstackTestCase):
         )
 
         cls.cleanup = [
-            cls.network_offering,
-            cls.service_offering
+            cls.network_offering_isolated,
+            cls.service_offering,
+			cls.network_offering_shared
         ]
 
         cls.logger = logging.getLogger('TestNiciraContoller')
@@ -230,13 +256,86 @@ class TestNiciraContoller(cloudstackTestCase):
             transportzoneuuid=self.transport_zone_uuid)
         self.test_cleanup.append(nicira_device)
 
+    def add_nicira_device_l2gateway(self, hostname):
+        nicira_device = NiciraNvp.add(
+            self.api_client,
+            None,
+            self.physical_network_id,
+            hostname=hostname,
+            username=self.nicira_credentials['username'],
+            password=self.nicira_credentials['password'],
+            transportzoneuuid=self.transport_zone_uuid,
+            l2gatewayserviceuuid=self.l2gatewayserviceuuid)
+        self.test_cleanup.append(nicira_device)
+
+    def create_guest_isolated_network(self):
+        network_services = {
+            'name'            : 'nicira_enabled_network_isolated',
+            'displaytext'     : 'nicira_enabled_network_isolated',
+            'zoneid'          : self.zone.id,
+            'networkoffering' : self.network_offering_isolated.id
+        }
+        network = Network.create(
+            self.api_client,
+            network_services,
+            accountid='admin',
+            domainid=self.domain.id,
+        )
+        self.test_cleanup.append(network)
+        return network
+
+    def create_guest_shared_network_numerical_vlanid(self):
+        network_services = {
+            'name'            : 'nicira_enabled_network_shared',
+            'displaytext'     : 'nicira_enabled_network_shared',
+            'zoneid'          : self.zone.id,
+            'networkoffering' : self.network_offering_shared.id,
+			'startip'			: self.ip_ranges_shared.startip,
+			'endip'				: self.ip_ranges_shared.endip,
+			'netmask'			: self.ip_ranges_shared.netmask,
+			'gateway'			: self.ip_ranges_shared.gateway
+        }
+        network = Network.create(
+            self.api_client,
+            network_services,
+            accountid='admin',
+            domainid=self.domain.id,
+			vlan=self.ip_ranges_shared.vlan
+        )
+        self.test_cleanup.append(network)
+        return network
+
+    def create_guest_shared_network_uuid_vlanid(self):
+        network_services = {
+            'name'            : 'nicira_enabled_network_shared',
+            'displaytext'     : 'nicira_enabled_network_shared',
+            'zoneid'          : self.zone.id,
+            'networkoffering' : self.network_offering_shared.id,
+			'startip'			: self.ip_ranges_shared.startip,
+			'endip'				: self.ip_ranges_shared.endip,
+			'netmask'			: self.ip_ranges_shared.netmask,
+			'gateway'			: self.ip_ranges_shared.gateway
+        }
+        network = Network.create(
+            self.api_client,
+            network_services,
+            accountid='admin',
+            domainid=self.domain.id,
+			vlan=self.ip_ranges_shared.vlan_uuid
+        )
+        self.test_cleanup.append(network)
+        return network
 
-    def create_guest_network(self):
+    def create_guest_shared_network_services(self):
         network_services = {
-            'name'            : 'nicira_enabled_network',
-            'displaytext'     : 'nicira_enabled_network',
+            'name'            : 'nicira_enabled_network_shared',
+            'displaytext'     : 'nicira_enabled_network_shared',
             'zoneid'          : self.zone.id,
-            'networkoffering' : self.network_offering.id
+            'networkoffering' : self.network_offering_shared.id,
+			'startip'			: self.ip_ranges_shared.startip,
+			'endip'				: self.ip_ranges_shared.endip,
+			'netmask'			: self.ip_ranges_shared.netmask,
+			'gateway'			: self.ip_ranges_shared.gateway
         }
         network = Network.create(
             self.api_client,
@@ -261,6 +360,19 @@ class TestNiciraContoller(cloudstackTestCase):
         self.test_cleanup.append(virtual_machine)
         return virtual_machine
 
+    def create_virtual_machine_shared_networks(self, network):
+        virtual_machine = VirtualMachine.create(
+            self.api_client,
+            self.vm_services['small'],
+            accountid='admin',
+            domainid=self.domain.id,
+            serviceofferingid=self.service_offering.id,
+            networkids=[network.id],
+            mode='BASIC'
+        )
+        self.test_cleanup.append(virtual_machine)
+        return virtual_machine
+
 
     def get_routers_for_network(self, network):
         return list_routers(
@@ -336,7 +448,7 @@ class TestNiciraContoller(cloudstackTestCase):
     def test_01_nicira_controller(self):
         self.add_nicira_device(self.nicira_master_controller)
 
-        network         = self.create_guest_network()
+        network         = self.create_guest_isolated_network()
         virtual_machine = self.create_virtual_machine(network)
 
         list_vm_response = VirtualMachine.list(self.api_client, id=virtual_machine.id)
@@ -367,7 +479,7 @@ class TestNiciraContoller(cloudstackTestCase):
 
         self.add_nicira_device(nicira_slave)
 
-        network         = self.create_guest_network()
+        network         = self.create_guest_isolated_network()
         virtual_machine = self.create_virtual_machine(network)
 
         list_vm_response = VirtualMachine.list(self.api_client, id=virtual_machine.id)
@@ -384,7 +496,7 @@ class TestNiciraContoller(cloudstackTestCase):
     @attr(tags = ["advanced", "smoke", "nicira"], required_hardware="true")
     def test_03_nicira_tunnel_guest_network(self):
         self.add_nicira_device(self.nicira_master_controller)
-        network         = self.create_guest_network()
+        network         = self.create_guest_isolated_network()
         virtual_machine = self.create_virtual_machine(network)
         public_ip       = self.acquire_publicip(network)
         nat_rule        = self.create_natrule(virtual_machine, public_ip, network)
@@ -415,3 +527,45 @@ class TestNiciraContoller(cloudstackTestCase):
             self.fail("SSH Access failed for %s: %s" % (vmObj.get_ip(), e))
 
         self.assertEqual(result.count('3 packets received'), 1, 'Ping to outside world from VM should be successful')
+		
+    @attr(tags = ["advanced", "smoke", "nicira"], required_hardware="true")
+    def test_04_nicira_shared_networks_numerical_vlanid(self):
+        """
+            Shared Networks Support
+            CASE 1) Numerical VLAN_ID provided in network creation
+        """
+        self.debug("Starting test case 1 for Shared Networks")
+        self.add_nicira_device_l2gateway(self.nicira_master_controller)
+        network = self.create_guest_shared_network_numerical_vlanid()
+        virtual_machine = self.create_virtual_machine_shared_networks(network)
+		
+        list_vm_response = VirtualMachine.list(self.api_client, id=virtual_machine.id)
+        self.debug("Verify listVirtualMachines response for virtual machine: %s" % virtual_machine.id)
+
+        self.assertEqual(isinstance(list_vm_response, list), True, 'Response did not return a valid list')
+        self.assertNotEqual(len(list_vm_response), 0, 'List of VMs is empty')
+
+        vm_response = list_vm_response[0]
+        self.assertEqual(vm_response.id, virtual_machine.id, 'Virtual machine in response does not match request')
+        self.assertEqual(vm_response.state, 'Running', 'VM is not in Running state')
+
+    @attr(tags = ["advanced", "smoke", "nicira"], required_hardware="true")
+    def test_05_nicira_shared_networks_lrouter_uuid_vlan_id(self):
+        """
+            Shared Networks Support
+            CASE 2) Logical Router's UUID as VLAN_ID provided in network creation
+        """
+        self.debug("Starting test case 2 for Shared Networks")
+        self.add_nicira_device_l2gateway(self.nicira_master_controller)
+        network = self.create_guest_shared_network_uuid_vlanid()
+        virtual_machine = self.create_virtual_machine_shared_networks(network)
+		
+        list_vm_response = VirtualMachine.list(self.api_client, id=virtual_machine.id)
+        self.debug("Verify listVirtualMachines response for virtual machine: %s" % virtual_machine.id)
+
+        self.assertEqual(isinstance(list_vm_response, list), True, 'Response did not return a valid list')
+        self.assertNotEqual(len(list_vm_response), 0, 'List of VMs is empty')
+
+        vm_response = list_vm_response[0]
+        self.assertEqual(vm_response.id, virtual_machine.id, 'Virtual machine in response does not match request')
+        self.assertEqual(vm_response.state, 'Running', 'VM is not in Running state')
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4ac27377/tools/marvin/marvin/lib/base.py
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/lib/base.py b/tools/marvin/marvin/lib/base.py
index ab15a78..379ecd9 100755
--- a/tools/marvin/marvin/lib/base.py
+++ b/tools/marvin/marvin/lib/base.py
@@ -3853,7 +3853,7 @@ class NiciraNvp:
 
     @classmethod
     def add(cls, apiclient, services, physicalnetworkid,
-            hostname=None, username=None, password=None, transportzoneuuid=None):
+            hostname=None, username=None, password=None, transportzoneuuid=None, l2gatewayserviceuuid=None):
         cmd = addNiciraNvpDevice.addNiciraNvpDeviceCmd()
         cmd.physicalnetworkid = physicalnetworkid
         if hostname:
@@ -3876,7 +3876,12 @@ class NiciraNvp:
         else:
             cmd.transportzoneuuid = services['transportZoneUuid']
 
-        return NiciraNvp(apiclient.addNiciraNvpDevice(cmd).__dict__)
+        if l2gatewayserviceuuid:
+            cmd.l2gatewayserviceuuid = l2gatewayserviceuuid
+        else:
+            cmd.l2gatewayserviceuuid = services['l2gatewayserviceuuid']
+
+	return NiciraNvp(apiclient.addNiciraNvpDevice(cmd).__dict__)
 
     def delete(self, apiclient):
         cmd = deleteNiciraNvpDevice.deleteNiciraNvpDeviceCmd()


[06/16] git commit: updated refs/heads/master to 67b753c

Posted by re...@apache.org.
CLOUDSTACK-9074: Support Shared Networks in NiciraNVP Plugin


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/c6763718
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/c6763718
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/c6763718

Branch: refs/heads/master
Commit: c67637180f9d7be627a4fe36fd2709c58c952e94
Parents: 55f4607
Author: nvazquez <ni...@gmail.com>
Authored: Tue Dec 1 11:54:27 2015 -0800
Committer: nvazquez <ni...@gmail.com>
Committed: Thu Dec 24 16:07:06 2015 -0300

----------------------------------------------------------------------
 .../com/cloud/vm/VirtualMachineManagerImpl.java |   8 +-
 .../orchestration/NetworkOrchestrator.java      | 113 ++++++----
 .../src/com/cloud/network/dao/NetworkVO.java    |  11 +
 .../network/dao/NiciraNvpRouterMappingDao.java  |   2 +
 .../dao/NiciraNvpRouterMappingDaoImpl.java      |   9 +
 .../cloud/network/element/NiciraNvpElement.java |  86 +++++++-
 .../network/guru/NiciraNvpGuestNetworkGuru.java |  96 ++++++++-
 .../network/element/NiciraNvpElementTest.java   | 213 ++++++++++++++++++-
 .../guru/NiciraNvpGuestNetworkGuruTest.java     |   4 +-
 .../cloud/network/guru/DirectNetworkGuru.java   |   3 +-
 10 files changed, 493 insertions(+), 52 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c6763718/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java b/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java
index 5c58389..aa3b7ce 100644
--- a/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java
+++ b/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java
@@ -4575,7 +4575,13 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac
         }
         assert vm != null;
 
-        orchestrateStart(vm.getUuid(), work.getParams(), work.getPlan(), _dpMgr.getDeploymentPlannerByName(work.getDeploymentPlanner()));
+        try{
+            orchestrateStart(vm.getUuid(), work.getParams(), work.getPlan(), _dpMgr.getDeploymentPlannerByName(work.getDeploymentPlanner()));
+        }
+        catch (CloudRuntimeException e){
+            s_logger.info("Caught CloudRuntimeException, returning job failed");
+            return new Pair<JobInfo.Status, String>(JobInfo.Status.FAILED, null);
+        }
         return new Pair<JobInfo.Status, String>(JobInfo.Status.SUCCEEDED, null);
     }
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c6763718/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java b/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java
index d99c9ef..fa6cd82 100644
--- a/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java
+++ b/engine/orchestration/src/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java
@@ -140,6 +140,7 @@ import com.cloud.network.element.NetworkElement;
 import com.cloud.network.element.StaticNatServiceProvider;
 import com.cloud.network.element.UserDataServiceProvider;
 import com.cloud.network.guru.NetworkGuru;
+import com.cloud.network.guru.NetworkGuruAdditionalFunctions;
 import com.cloud.network.lb.LoadBalancingRulesManager;
 import com.cloud.network.rules.FirewallManager;
 import com.cloud.network.rules.FirewallRule;
@@ -168,6 +169,7 @@ import com.cloud.user.ResourceLimitService;
 import com.cloud.user.User;
 import com.cloud.user.dao.AccountDao;
 import com.cloud.utils.Pair;
+import com.cloud.utils.UuidUtils;
 import com.cloud.utils.component.AdapterBase;
 import com.cloud.utils.component.ManagerBase;
 import com.cloud.utils.concurrency.NamedThreadFactory;
@@ -670,8 +672,14 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
                                 vpcId, offering.getRedundantRouter());
                         vo.setDisplayNetwork(isDisplayNetworkEnabled == null ? true : isDisplayNetworkEnabled);
                         vo.setStrechedL2Network(offering.getSupportsStrechedL2());
-                        networks.add(_networksDao.persist(vo, vo.getGuestType() == Network.GuestType.Isolated,
-                                finalizeServicesAndProvidersForNetwork(offering, plan.getPhysicalNetworkId())));
+                        NetworkVO networkPersisted = _networksDao.persist(vo, vo.getGuestType() == Network.GuestType.Isolated,
+                                finalizeServicesAndProvidersForNetwork(offering, plan.getPhysicalNetworkId()));
+                        networks.add(networkPersisted);
+
+                        if (predefined instanceof NetworkVO && guru instanceof NetworkGuruAdditionalFunctions){
+                            NetworkGuruAdditionalFunctions functions = (NetworkGuruAdditionalFunctions) guru;
+                            functions.finalizeNetworkDesign(networkPersisted.getId(), ((NetworkVO)predefined).getVlanIdAsUUID());
+                        }
 
                         if (domainId != null && aclType == ACLType.Domain) {
                             _networksDao.addDomainToNetwork(id, domainId, subdomainAccess == null ? true : subdomainAccess);
@@ -1020,6 +1028,9 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
         } catch (NoTransitionException e) {
             s_logger.error(e.getMessage());
             return null;
+        } catch (CloudRuntimeException e) {
+            s_logger.error("Caught exception: " + e.getMessage());
+            return null;
         } finally {
             if (implemented.first() == null) {
                 s_logger.debug("Cleaning up because we're unable to implement the network " + network);
@@ -1911,43 +1922,45 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
                 throw new InvalidParameterValueException("The VLAN tag " + vlanId + " is already being used for dynamic vlan allocation for the guest network in zone "
                         + zone.getName());
             }
-            String uri = BroadcastDomainType.fromString(vlanId).toString();
-            // For Isolated networks, don't allow to create network with vlan that already exists in the zone
-            if (ntwkOff.getGuestType() == GuestType.Isolated) {
-                if (_networksDao.countByZoneAndUri(zoneId, uri) > 0) {
-                    throw new InvalidParameterValueException("Network with vlan " + vlanId + " already exists in zone " + zoneId);
-                } else {
-                    List<DataCenterVnetVO> dcVnets = _datacenterVnetDao.findVnet(zoneId, vlanId.toString());
-                    //for the network that is created as part of private gateway,
-                    //the vnet is not coming from the data center vnet table, so the list can be empty
-                    if (!dcVnets.isEmpty()) {
-                        DataCenterVnetVO dcVnet = dcVnets.get(0);
-                        // Fail network creation if specified vlan is dedicated to a different account
-                        if (dcVnet.getAccountGuestVlanMapId() != null) {
-                            Long accountGuestVlanMapId = dcVnet.getAccountGuestVlanMapId();
-                            AccountGuestVlanMapVO map = _accountGuestVlanMapDao.findById(accountGuestVlanMapId);
-                            if (map.getAccountId() != owner.getAccountId()) {
-                                throw new InvalidParameterValueException("Vlan " + vlanId + " is dedicated to a different account");
-                            }
-                            // Fail network creation if owner has a dedicated range of vlans but the specified vlan belongs to the system pool
-                        } else {
-                            List<AccountGuestVlanMapVO> maps = _accountGuestVlanMapDao.listAccountGuestVlanMapsByAccount(owner.getAccountId());
-                            if (maps != null && !maps.isEmpty()) {
-                                int vnetsAllocatedToAccount = _datacenterVnetDao.countVnetsAllocatedToAccount(zoneId, owner.getAccountId());
-                                int vnetsDedicatedToAccount = _datacenterVnetDao.countVnetsDedicatedToAccount(zoneId, owner.getAccountId());
-                                if (vnetsAllocatedToAccount < vnetsDedicatedToAccount) {
-                                    throw new InvalidParameterValueException("Specified vlan " + vlanId + " doesn't belong" + " to the vlan range dedicated to the owner "
-                                            + owner.getAccountName());
+            if (! UuidUtils.validateUUID(vlanId)){
+                String uri = BroadcastDomainType.fromString(vlanId).toString();
+                // For Isolated networks, don't allow to create network with vlan that already exists in the zone
+                if (ntwkOff.getGuestType() == GuestType.Isolated) {
+                    if (_networksDao.countByZoneAndUri(zoneId, uri) > 0) {
+                        throw new InvalidParameterValueException("Network with vlan " + vlanId + " already exists in zone " + zoneId);
+                    } else {
+                        List<DataCenterVnetVO> dcVnets = _datacenterVnetDao.findVnet(zoneId, vlanId.toString());
+                        //for the network that is created as part of private gateway,
+                        //the vnet is not coming from the data center vnet table, so the list can be empty
+                        if (!dcVnets.isEmpty()) {
+                            DataCenterVnetVO dcVnet = dcVnets.get(0);
+                            // Fail network creation if specified vlan is dedicated to a different account
+                            if (dcVnet.getAccountGuestVlanMapId() != null) {
+                                Long accountGuestVlanMapId = dcVnet.getAccountGuestVlanMapId();
+                                AccountGuestVlanMapVO map = _accountGuestVlanMapDao.findById(accountGuestVlanMapId);
+                                if (map.getAccountId() != owner.getAccountId()) {
+                                    throw new InvalidParameterValueException("Vlan " + vlanId + " is dedicated to a different account");
+                                }
+                                // Fail network creation if owner has a dedicated range of vlans but the specified vlan belongs to the system pool
+                            } else {
+                                List<AccountGuestVlanMapVO> maps = _accountGuestVlanMapDao.listAccountGuestVlanMapsByAccount(owner.getAccountId());
+                                if (maps != null && !maps.isEmpty()) {
+                                    int vnetsAllocatedToAccount = _datacenterVnetDao.countVnetsAllocatedToAccount(zoneId, owner.getAccountId());
+                                    int vnetsDedicatedToAccount = _datacenterVnetDao.countVnetsDedicatedToAccount(zoneId, owner.getAccountId());
+                                    if (vnetsAllocatedToAccount < vnetsDedicatedToAccount) {
+                                        throw new InvalidParameterValueException("Specified vlan " + vlanId + " doesn't belong" + " to the vlan range dedicated to the owner "
+                                                + owner.getAccountName());
+                                    }
                                 }
                             }
                         }
                     }
-                }
-            } else {
-                // don't allow to creating shared network with given Vlan ID, if there already exists a isolated network or
-                // shared network with same Vlan ID in the zone
-                if (_networksDao.countByZoneUriAndGuestType(zoneId, uri, GuestType.Isolated) > 0 ) {
-                    throw new InvalidParameterValueException("There is a isolated/shared network with vlan id: " + vlanId + " already exists " + "in zone " + zoneId);
+                } else {
+                    // don't allow to creating shared network with given Vlan ID, if there already exists a isolated network or
+                    // shared network with same Vlan ID in the zone
+                    if (_networksDao.countByZoneUriAndGuestType(zoneId, uri, GuestType.Isolated) > 0 ) {
+                        throw new InvalidParameterValueException("There is a isolated/shared network with vlan id: " + vlanId + " already exists " + "in zone " + zoneId);
+                    }
                 }
             }
 
@@ -2038,7 +2051,14 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
 
                 if (vlanIdFinal != null) {
                     if (isolatedPvlan == null) {
-                        URI uri = BroadcastDomainType.fromString(vlanIdFinal);
+                        URI uri = null;
+                        if (UuidUtils.validateUUID(vlanIdFinal)){
+                            //Logical router's UUID provided as VLAN_ID
+                            userNetwork.setVlanIdAsUUID(vlanIdFinal); //Set transient field
+                        }
+                        else {
+                            uri = BroadcastDomainType.fromString(vlanIdFinal);
+                        }
                         userNetwork.setBroadcastUri(uri);
                         if (!vlanIdFinal.equalsIgnoreCase(Vlan.UNTAGGED)) {
                             userNetwork.setBroadcastDomainType(BroadcastDomainType.Vlan);
@@ -2647,6 +2667,27 @@ public class NetworkOrchestrator extends ManagerBase implements NetworkOrchestra
         } else {
             result = _nicDao.listByVmIdAndNicIdAndNtwkId(vmId, nicId, networkId);
         }
+
+        for (NicVO nic : result) {
+            if (_networkModel.isProviderForNetwork(Provider.NiciraNvp, nic.getNetworkId())) {
+                //For NSX Based networks, add nsxlogicalswitch, nsxlogicalswitchport to each result
+                s_logger.info("Listing NSX logical switch and logical switch por for each nic");
+                NetworkVO network = _networksDao.findById(nic.getNetworkId());
+                NetworkGuru guru = AdapterBase.getAdapterByName(networkGurus, network.getGuruName());
+                NetworkGuruAdditionalFunctions guruFunctions = (NetworkGuruAdditionalFunctions) guru;
+
+                Map<String, ? extends Object> nsxParams = guruFunctions.listAdditionalNicParams(nic.getUuid());
+                if (nsxParams != null){
+                    String lswitchUuuid = (nsxParams.containsKey(NetworkGuruAdditionalFunctions.NSX_LSWITCH_UUID))
+                            ? (String) nsxParams.get(NetworkGuruAdditionalFunctions.NSX_LSWITCH_UUID) : null;
+                    String lswitchPortUuuid = (nsxParams.containsKey(NetworkGuruAdditionalFunctions.NSX_LSWITCHPORT_UUID))
+                            ? (String) nsxParams.get(NetworkGuruAdditionalFunctions.NSX_LSWITCHPORT_UUID) : null;
+                    nic.setNsxLogicalSwitchUuid(lswitchUuuid);
+                    nic.setNsxLogicalSwitchPortUuid(lswitchPortUuuid);
+                }
+            }
+        }
+
         return result;
     }
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c6763718/engine/schema/src/com/cloud/network/dao/NetworkVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/network/dao/NetworkVO.java b/engine/schema/src/com/cloud/network/dao/NetworkVO.java
index 65929d5..5b8ded7 100644
--- a/engine/schema/src/com/cloud/network/dao/NetworkVO.java
+++ b/engine/schema/src/com/cloud/network/dao/NetworkVO.java
@@ -172,6 +172,17 @@ public class NetworkVO implements Network {
     @Column(name = "streched_l2")
     boolean strechedL2Network = false;
 
+    @Transient
+    transient String vlanIdAsUUID;
+
+    public String getVlanIdAsUUID() {
+        return vlanIdAsUUID;
+    }
+
+    public void setVlanIdAsUUID(String vlanIdAsUUID) {
+        this.vlanIdAsUUID = vlanIdAsUUID;
+    }
+
     public NetworkVO() {
         uuid = UUID.randomUUID().toString();
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c6763718/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/dao/NiciraNvpRouterMappingDao.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/dao/NiciraNvpRouterMappingDao.java b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/dao/NiciraNvpRouterMappingDao.java
index b64fb90..b7e999b 100644
--- a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/dao/NiciraNvpRouterMappingDao.java
+++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/dao/NiciraNvpRouterMappingDao.java
@@ -25,4 +25,6 @@ import com.cloud.utils.db.GenericDao;
 public interface NiciraNvpRouterMappingDao extends GenericDao<NiciraNvpRouterMappingVO, Long> {
 
     public NiciraNvpRouterMappingVO findByNetworkId(long id);
+
+    public boolean existsMappingForNetworkId(long id);
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c6763718/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/dao/NiciraNvpRouterMappingDaoImpl.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/dao/NiciraNvpRouterMappingDaoImpl.java b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/dao/NiciraNvpRouterMappingDaoImpl.java
index 239072f..ef6acb4 100644
--- a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/dao/NiciraNvpRouterMappingDaoImpl.java
+++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/dao/NiciraNvpRouterMappingDaoImpl.java
@@ -19,6 +19,7 @@
 
 package com.cloud.network.dao;
 
+import java.util.List;
 
 import org.springframework.stereotype.Component;
 
@@ -46,4 +47,12 @@ public class NiciraNvpRouterMappingDaoImpl extends GenericDaoBase<NiciraNvpRoute
         return findOneBy(sc);
     }
 
+    @Override
+    public boolean existsMappingForNetworkId(long id) {
+        SearchCriteria<NiciraNvpRouterMappingVO> sc = networkSearch.create();
+        sc.setParameters("network_id", id);
+        List<NiciraNvpRouterMappingVO> mappings = search(sc, null);
+        return mappings.size() > 0;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c6763718/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/element/NiciraNvpElement.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/element/NiciraNvpElement.java b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/element/NiciraNvpElement.java
index 909134d..1146a54 100644
--- a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/element/NiciraNvpElement.java
+++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/element/NiciraNvpElement.java
@@ -33,7 +33,6 @@ import javax.naming.ConfigurationException;
 
 import org.apache.log4j.Logger;
 import org.springframework.stereotype.Component;
-
 import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
 import org.apache.cloudstack.network.ExternalNetworkDeviceManager.NetworkDevice;
 
@@ -42,6 +41,10 @@ import com.cloud.agent.api.ConfigurePortForwardingRulesOnLogicalRouterAnswer;
 import com.cloud.agent.api.ConfigurePortForwardingRulesOnLogicalRouterCommand;
 import com.cloud.agent.api.ConfigurePublicIpsOnLogicalRouterAnswer;
 import com.cloud.agent.api.ConfigurePublicIpsOnLogicalRouterCommand;
+import com.cloud.agent.api.ConfigureSharedNetworkUuidAnswer;
+import com.cloud.agent.api.ConfigureSharedNetworkUuidCommand;
+import com.cloud.agent.api.ConfigureSharedNetworkVlanIdAnswer;
+import com.cloud.agent.api.ConfigureSharedNetworkVlanIdCommand;
 import com.cloud.agent.api.ConfigureStaticNatRulesOnLogicalRouterAnswer;
 import com.cloud.agent.api.ConfigureStaticNatRulesOnLogicalRouterCommand;
 import com.cloud.agent.api.CreateLogicalRouterAnswer;
@@ -67,6 +70,7 @@ import com.cloud.api.commands.ListNiciraNvpDevicesCmd;
 import com.cloud.api.response.NiciraNvpDeviceResponse;
 import com.cloud.configuration.ConfigurationManager;
 import com.cloud.dc.Vlan;
+import com.cloud.dc.VlanVO;
 import com.cloud.dc.dao.VlanDao;
 import com.cloud.deploy.DeployDestination;
 import com.cloud.exception.ConcurrentOperationException;
@@ -82,6 +86,7 @@ import com.cloud.network.IpAddress;
 import com.cloud.network.IpAddressManager;
 import com.cloud.network.Network;
 import com.cloud.network.Network.Capability;
+import com.cloud.network.Network.GuestType;
 import com.cloud.network.Network.Provider;
 import com.cloud.network.Network.Service;
 import com.cloud.network.NetworkModel;
@@ -239,8 +244,14 @@ NiciraNvpElementService, ResourceStateAdapter, IpDeployer {
          * multiple operations that should be done only once.
          */
 
-        // Implement SourceNat immediately as we have al the info already
-        if (networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.SourceNat, Provider.NiciraNvp)) {
+        if (network.getGuestType().equals(GuestType.Shared)){
+            //Support Shared Networks
+            String lSwitchUuid = BroadcastDomainType.getValue(network.getBroadcastUri());
+            String ownerName = context.getDomain().getName() + "-" + context.getAccount().getAccountName();
+            return sharedNetworkSupport(network, lSwitchUuid, ownerName, niciraNvpHost);
+        }
+        else if (network.getGuestType().equals(GuestType.Isolated) && networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.SourceNat, Provider.NiciraNvp)) {
+            // Implement SourceNat immediately as we have al the info already
             s_logger.debug("Apparently we are supposed to provide SourceNat on this network");
 
             PublicIp sourceNatIp = ipAddrMgr.assignSourceNatIpAddressToGuestNetwork(owner, network);
@@ -271,14 +282,74 @@ NiciraNvpElementService, ResourceStateAdapter, IpDeployer {
                 return false;
             }
 
-            // Store the uuid so we can easily find it during cleanup
             NiciraNvpRouterMappingVO routermapping = new NiciraNvpRouterMappingVO(answer.getLogicalRouterUuid(), network.getId());
             niciraNvpRouterMappingDao.persist(routermapping);
+
+        }
+
+        return true;
+    }
+
+    private boolean sharedNetworkSupport(Network network, String lSwitchUuid, String ownerName, HostVO niciraNvpHost) {
+        //Support Shared Networks, we won’t be creating logical router, 2 cases:
+        //Case 1) UUID Supplied for VLAN -> This is UUID of the logical router to attach lswitch
+        //Case 2) Numerical ID supplied for VLAN -> lswitch is connected to L2 gateway service that we have as an attribute of the NVP device. If no L2 gateway attribute exists then exception.
+
+        if (niciraNvpRouterMappingDao.existsMappingForNetworkId(network.getId())){
+            //Case 1)
+            return sharedNetworkSupportUUIDVlanId(network, lSwitchUuid, ownerName, niciraNvpHost);
+        }
+        else {
+            //Case 2)
+            return sharedNetworkSupportNumericalVlanId(network, lSwitchUuid, ownerName, niciraNvpHost);
+        }
+    }
+
+    private boolean sharedNetworkSupportUUIDVlanId(Network network, String lSwitchUuid, String ownerName, HostVO niciraNvpHost) {
+        String networkCidr = network.getCidr();
+        String vlanGateway = network.getGateway();
+        String portIpAddress = createLogicalRouterPortIpAddress(networkCidr, vlanGateway);
+        NiciraNvpRouterMappingVO mapRouterNetwork = niciraNvpRouterMappingDao.findByNetworkId(network.getId());
+        String lRouterUuid = mapRouterNetwork.getLogicalRouterUuid();
+        ConfigureSharedNetworkUuidCommand cmd =
+                new ConfigureSharedNetworkUuidCommand(lRouterUuid, lSwitchUuid, portIpAddress, ownerName, network.getId());
+        ConfigureSharedNetworkUuidAnswer answer = (ConfigureSharedNetworkUuidAnswer)agentMgr.easySend(niciraNvpHost.getId(), cmd);
+        if (answer.getResult() == false) {
+            s_logger.error("Failed to configure Logical Router for Shared network " + network.getDisplayText());
+            return false;
         }
+        return true;
+    }
 
+    private boolean sharedNetworkSupportNumericalVlanId(Network network, String lSwitchUuid, String ownerName, HostVO niciraNvpHost) {
+        List<VlanVO> networkVlans = vlanDao.listVlansByNetworkId(network.getId());
+        if (networkVlans.size() == 1){
+            for (VlanVO vlanVO : networkVlans) {
+                long vlanId = Long.parseLong(vlanVO.getVlanTag());
+                String l2GatewayServiceUuid = niciraNvpHost.getDetail("l2gatewayserviceuuid");
+                if (l2GatewayServiceUuid == null){
+                    throw new CloudRuntimeException("No L2 Gateway Service Uuid found on " + niciraNvpHost.getName());
+                }
+                ConfigureSharedNetworkVlanIdCommand cmd =
+                        new ConfigureSharedNetworkVlanIdCommand(lSwitchUuid, l2GatewayServiceUuid , vlanId, ownerName, network.getId());
+                ConfigureSharedNetworkVlanIdAnswer answer = (ConfigureSharedNetworkVlanIdAnswer)agentMgr.easySend(niciraNvpHost.getId(), cmd);
+                if (answer.getResult() == false) {
+                    s_logger.error("Failed to configure Shared network " + network.getDisplayText());
+                    return false;
+                }
+            }
+        }
         return true;
     }
 
+
+    private String createLogicalRouterPortIpAddress(String networkCidr, String vlanGateway) {
+        if (networkCidr != null && vlanGateway != null){
+            return networkCidr.replaceFirst("[\\d]{1,3}.[\\d]{1,3}.[\\d]{1,3}.[\\d]{1,3}", vlanGateway);
+        }
+        return null;
+    }
+
     @Override
     public boolean prepare(Network network, NicProfile nic, VirtualMachineProfile vm, DeployDestination dest, ReservationContext context)
             throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
@@ -393,7 +464,8 @@ NiciraNvpElementService, ResourceStateAdapter, IpDeployer {
         NiciraNvpDeviceVO niciraNvpDevice = devices.get(0);
         HostVO niciraNvpHost = hostDao.findById(niciraNvpDevice.getHostId());
 
-        if (networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.SourceNat, Provider.NiciraNvp)) {
+        //Dont destroy logical router when removing Shared Networks
+        if (! network.getGuestType().equals(GuestType.Shared) && networkModel.isProviderSupportServiceInNetwork(network.getId(), Service.SourceNat, Provider.NiciraNvp)) {
             s_logger.debug("Apparently we were providing SourceNat on this network");
 
             // Deleting the LogicalRouter will also take care of all provisioned
@@ -537,6 +609,9 @@ NiciraNvpElementService, ResourceStateAdapter, IpDeployer {
         if (cmd.getL3GatewayServiceUuid() != null) {
             params.put("l3gatewayserviceuuid", cmd.getL3GatewayServiceUuid());
         }
+        if (cmd.getL2GatewayServiceUuid() != null) {
+            params.put("l2gatewayserviceuuid", cmd.getL2GatewayServiceUuid());
+        }
 
         Map<String, Object> hostdetails = new HashMap<String, Object>();
         hostdetails.putAll(params);
@@ -582,6 +657,7 @@ NiciraNvpElementService, ResourceStateAdapter, IpDeployer {
         response.setHostName(niciraNvpHost.getDetail("ip"));
         response.setTransportZoneUuid(niciraNvpHost.getDetail("transportzoneuuid"));
         response.setL3GatewayServiceUuid(niciraNvpHost.getDetail("l3gatewayserviceuuid"));
+        response.setL2GatewayServiceUuid(niciraNvpHost.getDetail("l2gatewayserviceuuid"));
         response.setObjectName("niciranvpdevice");
         return response;
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c6763718/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/guru/NiciraNvpGuestNetworkGuru.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/guru/NiciraNvpGuestNetworkGuru.java b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/guru/NiciraNvpGuestNetworkGuru.java
index fc41286..f83f8ee 100644
--- a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/guru/NiciraNvpGuestNetworkGuru.java
+++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/guru/NiciraNvpGuestNetworkGuru.java
@@ -21,7 +21,9 @@ package com.cloud.network.guru;
 
 import java.net.URI;
 import java.net.URISyntaxException;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import javax.inject.Inject;
 
@@ -30,8 +32,12 @@ import org.apache.log4j.Logger;
 import com.cloud.agent.AgentManager;
 import com.cloud.agent.api.CreateLogicalSwitchAnswer;
 import com.cloud.agent.api.CreateLogicalSwitchCommand;
+import com.cloud.agent.api.DeleteLogicalRouterPortAnswer;
+import com.cloud.agent.api.DeleteLogicalRouterPortCommand;
 import com.cloud.agent.api.DeleteLogicalSwitchAnswer;
 import com.cloud.agent.api.DeleteLogicalSwitchCommand;
+import com.cloud.agent.api.FindLogicalRouterPortAnswer;
+import com.cloud.agent.api.FindLogicalRouterPortCommand;
 import com.cloud.dc.DataCenter;
 import com.cloud.dc.DataCenter.NetworkType;
 import com.cloud.dc.dao.DataCenterDao;
@@ -48,6 +54,8 @@ import com.cloud.network.Network.Service;
 import com.cloud.network.Network.State;
 import com.cloud.network.NetworkModel;
 import com.cloud.network.NetworkProfile;
+import com.cloud.network.NiciraNvpNicMappingVO;
+import com.cloud.network.NiciraNvpRouterMappingVO;
 import com.cloud.network.Networks.BroadcastDomainType;
 import com.cloud.network.NiciraNvpDeviceVO;
 import com.cloud.network.PhysicalNetwork;
@@ -55,6 +63,8 @@ import com.cloud.network.PhysicalNetwork.IsolationMethod;
 import com.cloud.network.dao.NetworkDao;
 import com.cloud.network.dao.NetworkVO;
 import com.cloud.network.dao.NiciraNvpDao;
+import com.cloud.network.dao.NiciraNvpNicMappingDao;
+import com.cloud.network.dao.NiciraNvpRouterMappingDao;
 import com.cloud.network.dao.PhysicalNetworkDao;
 import com.cloud.network.dao.PhysicalNetworkVO;
 import com.cloud.offering.NetworkOffering;
@@ -66,7 +76,7 @@ import com.cloud.vm.NicProfile;
 import com.cloud.vm.ReservationContext;
 import com.cloud.vm.VirtualMachineProfile;
 
-public class NiciraNvpGuestNetworkGuru extends GuestNetworkGuru {
+public class NiciraNvpGuestNetworkGuru extends GuestNetworkGuru implements NetworkGuruAdditionalFunctions{
     private static final int MAX_NAME_LENGTH = 40;
 
     private static final Logger s_logger = Logger.getLogger(NiciraNvpGuestNetworkGuru.class);
@@ -93,6 +103,10 @@ public class NiciraNvpGuestNetworkGuru extends GuestNetworkGuru {
     protected HostDetailsDao hostDetailsDao;
     @Inject
     protected NetworkOfferingServiceMapDao ntwkOfferingSrvcDao;
+    @Inject
+    protected NiciraNvpRouterMappingDao niciraNvpRouterMappingDao;
+    @Inject
+    protected NiciraNvpNicMappingDao niciraNvpNicMappingDao;
 
     public NiciraNvpGuestNetworkGuru() {
         super();
@@ -102,15 +116,24 @@ public class NiciraNvpGuestNetworkGuru extends GuestNetworkGuru {
     @Override
     protected boolean canHandle(final NetworkOffering offering, final NetworkType networkType, final PhysicalNetwork physicalNetwork) {
         // This guru handles only Guest Isolated network that supports Source nat service
-        if (networkType == NetworkType.Advanced && isMyTrafficType(offering.getTrafficType()) && offering.getGuestType() == Network.GuestType.Isolated
+        if (networkType == NetworkType.Advanced && isMyTrafficType(offering.getTrafficType())
+                && supportedGuestTypes(offering, Network.GuestType.Isolated, Network.GuestType.Shared)
                 && isMyIsolationMethod(physicalNetwork) && ntwkOfferingSrvcDao.areServicesSupportedByNetworkOffering(offering.getId(), Service.Connectivity)) {
             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;
         }
     }
 
+    private boolean supportedGuestTypes(NetworkOffering offering, GuestType... types) {
+        for (GuestType guestType : types) {
+            if (offering.getGuestType().equals(guestType)){
+                return true;
+            }
+        }
+        return false;
+    }
+
     @Override
     public Network design(final NetworkOffering offering, final DeploymentPlan plan, final Network userSpecified, final Account owner) {
         // Check of the isolation type of the related physical network is supported
@@ -134,6 +157,9 @@ public class NiciraNvpGuestNetworkGuru extends GuestNetworkGuru {
             return null;
         }
         networkObject.setBroadcastDomainType(BroadcastDomainType.Lswitch);
+        if (offering.getGuestType().equals(GuestType.Shared)){
+            networkObject.setState(State.Allocated);
+        }
 
         return networkObject;
     }
@@ -231,7 +257,13 @@ public class NiciraNvpGuestNetworkGuru extends GuestNetworkGuru {
         final NiciraNvpDeviceVO niciraNvpDevice = devices.get(0);
         final HostVO niciraNvpHost = hostDao.findById(niciraNvpDevice.getHostId());
 
-        final DeleteLogicalSwitchCommand cmd = new DeleteLogicalSwitchCommand(BroadcastDomainType.getValue(networkObject.getBroadcastUri()));
+        String logicalSwitchUuid = BroadcastDomainType.getValue(networkObject.getBroadcastUri());
+
+        if (offering.getGuestType().equals(GuestType.Shared)){
+            sharedNetworksCleanup(networkObject, logicalSwitchUuid, niciraNvpHost);
+        }
+
+        final DeleteLogicalSwitchCommand cmd = new DeleteLogicalSwitchCommand(logicalSwitchUuid);
         final DeleteLogicalSwitchAnswer answer = (DeleteLogicalSwitchAnswer) agentMgr.easySend(niciraNvpHost.getId(), cmd);
 
         if (answer == null || !answer.getResult()) {
@@ -241,9 +273,65 @@ public class NiciraNvpGuestNetworkGuru extends GuestNetworkGuru {
         super.shutdown(profile, offering);
     }
 
+    private void sharedNetworksCleanup(NetworkVO networkObject, String logicalSwitchUuid, HostVO niciraNvpHost) {
+        NiciraNvpRouterMappingVO routermapping = niciraNvpRouterMappingDao.findByNetworkId(networkObject.getId());
+        if (routermapping == null) {
+            // Case 1: Numerical Vlan Provided -> No lrouter used.
+            s_logger.info("Shared Network " + networkObject.getDisplayText() + " didn't use Logical Router");
+        }
+        else {
+            //Case 2: Logical Router's UUID provided as Vlan id -> Remove lrouter port but not lrouter.
+            String lRouterUuid = routermapping.getLogicalRouterUuid();
+            s_logger.debug("Finding Logical Router Port on Logical Router " + lRouterUuid + " with attachment_lswitch_uuid=" + logicalSwitchUuid + " to delete it");
+            final FindLogicalRouterPortCommand cmd = new FindLogicalRouterPortCommand(lRouterUuid, logicalSwitchUuid);
+            final FindLogicalRouterPortAnswer answer = (FindLogicalRouterPortAnswer) agentMgr.easySend(niciraNvpHost.getId(), cmd);
+
+            if (answer != null && answer.getResult()) {
+                String logicalRouterPortUuid = answer.getLogicalRouterPortUuid();
+                s_logger.debug("Found Logical Router Port " + logicalRouterPortUuid + ", deleting it");
+                final DeleteLogicalRouterPortCommand cmdDeletePort = new DeleteLogicalRouterPortCommand(lRouterUuid, logicalRouterPortUuid);
+                final DeleteLogicalRouterPortAnswer answerDelete = (DeleteLogicalRouterPortAnswer) agentMgr.easySend(niciraNvpHost.getId(), cmdDeletePort);
+
+                if (answerDelete != null && answerDelete.getResult()){
+                    s_logger.info("Successfully deleted Logical Router Port " + logicalRouterPortUuid);
+                }
+                else {
+                    s_logger.error("Could not delete Logical Router Port " + logicalRouterPortUuid);
+                }
+            }
+            else {
+                s_logger.error("Find Logical Router Port failed");
+            }
+        }
+    }
+
     @Override
     public boolean trash(final Network network, final NetworkOffering offering) {
+        //Since NVP Plugin supports Shared networks, remove mapping when deleting network implemented or allocated
+        if (network.getGuestType() == GuestType.Shared && niciraNvpRouterMappingDao.existsMappingForNetworkId(network.getId())){
+            NiciraNvpRouterMappingVO mappingVO = niciraNvpRouterMappingDao.findByNetworkId(network.getId());
+            niciraNvpRouterMappingDao.remove(mappingVO.getId());
+        }
         return super.trash(network, offering);
     }
 
+    @Override
+    public void finalizeNetworkDesign(long networkId, String vlanIdAsUUID) {
+        if (vlanIdAsUUID == null) return;
+        NiciraNvpRouterMappingVO routermapping = new NiciraNvpRouterMappingVO(vlanIdAsUUID, networkId);
+        niciraNvpRouterMappingDao.persist(routermapping);
+    }
+
+    @Override
+    public Map<String, ? extends Object> listAdditionalNicParams(String nicUuid) {
+        NiciraNvpNicMappingVO mapping = niciraNvpNicMappingDao.findByNicUuid(nicUuid);
+        if (mapping != null){
+            Map<String, String> result = new HashMap<String, String>();
+            result.put(NetworkGuruAdditionalFunctions.NSX_LSWITCH_UUID, mapping.getLogicalSwitchUuid());
+            result.put(NetworkGuruAdditionalFunctions.NSX_LSWITCHPORT_UUID, mapping.getLogicalSwitchPortUuid());
+            return result;
+        }
+        return null;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c6763718/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/element/NiciraNvpElementTest.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/element/NiciraNvpElementTest.java b/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/element/NiciraNvpElementTest.java
index bf8ce18..858e908 100644
--- a/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/element/NiciraNvpElementTest.java
+++ b/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/element/NiciraNvpElementTest.java
@@ -29,7 +29,10 @@ import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
+import java.net.URI;
+import java.net.URISyntaxException;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
@@ -40,12 +43,17 @@ import javax.naming.ConfigurationException;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.ArgumentMatcher;
-
 import org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService;
 
 import com.cloud.agent.AgentManager;
+import com.cloud.agent.api.Command;
 import com.cloud.agent.api.ConfigurePublicIpsOnLogicalRouterAnswer;
 import com.cloud.agent.api.ConfigurePublicIpsOnLogicalRouterCommand;
+import com.cloud.agent.api.ConfigureSharedNetworkUuidAnswer;
+import com.cloud.agent.api.ConfigureSharedNetworkVlanIdAnswer;
+import com.cloud.agent.api.CreateLogicalRouterAnswer;
+import com.cloud.dc.VlanVO;
+import com.cloud.dc.dao.VlanDao;
 import com.cloud.deploy.DeployDestination;
 import com.cloud.domain.Domain;
 import com.cloud.exception.ConcurrentOperationException;
@@ -61,21 +69,27 @@ import com.cloud.network.Network.Service;
 import com.cloud.network.NetworkModel;
 import com.cloud.network.Networks.BroadcastDomainType;
 import com.cloud.network.Networks.TrafficType;
+import com.cloud.network.IpAddressManager;
 import com.cloud.network.NiciraNvpDeviceVO;
 import com.cloud.network.NiciraNvpRouterMappingVO;
 import com.cloud.network.PublicIpAddress;
+import com.cloud.network.addr.PublicIp;
 import com.cloud.network.dao.NetworkServiceMapDao;
 import com.cloud.network.dao.NiciraNvpDao;
 import com.cloud.network.dao.NiciraNvpRouterMappingDao;
 import com.cloud.offering.NetworkOffering;
 import com.cloud.resource.ResourceManager;
 import com.cloud.user.Account;
+import com.cloud.utils.exception.CloudRuntimeException;
 import com.cloud.utils.net.Ip;
 import com.cloud.vm.ReservationContext;
 
 public class NiciraNvpElementTest {
 
     private static final long NETWORK_ID = 42L;
+    private static final long NICIRA_NVP_HOST_ID = 9L;
+    private static final String NETWORK_CIDR = "10.0.0.0/24";
+    private static final String NETWORK_GATEWAY = "10.0.0.1";
     NiciraNvpElement element = new NiciraNvpElement();
     NetworkOrchestrationService networkManager = mock(NetworkOrchestrationService.class);
     NetworkModel networkModel = mock(NetworkModel.class);
@@ -84,6 +98,8 @@ public class NiciraNvpElementTest {
     HostDao hostDao = mock(HostDao.class);
     NiciraNvpDao niciraNvpDao = mock(NiciraNvpDao.class);
     NiciraNvpRouterMappingDao niciraNvpRouterMappingDao = mock(NiciraNvpRouterMappingDao.class);
+    VlanDao vlanDao = mock(VlanDao.class);
+    IpAddressManager ipAddressManager = mock(IpAddressManager.class);
 
     @Before
     public void setUp() throws ConfigurationException {
@@ -95,6 +111,8 @@ public class NiciraNvpElementTest {
         element.hostDao = hostDao;
         element.niciraNvpDao = niciraNvpDao;
         element.niciraNvpRouterMappingDao = niciraNvpRouterMappingDao;
+        element.vlanDao = vlanDao;
+        element.ipAddrMgr = ipAddressManager;
 
         // Standard responses
         when(networkModel.isProviderForNetwork(Provider.NiciraNvp, NETWORK_ID)).thenReturn(true);
@@ -133,17 +151,32 @@ public class NiciraNvpElementTest {
     }
 
     @Test
-    public void implementTest() throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
+    public void implementIsolatedNetworkTest() throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException, URISyntaxException {
         final Network network = mock(Network.class);
         when(network.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Lswitch);
+        when(network.getBroadcastUri()).thenReturn(new URI("lswitch:aaaaa"));
         when(network.getId()).thenReturn(NETWORK_ID);
+        when(network.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
+        when(network.getGuestType()).thenReturn(GuestType.Isolated);
+
+        when(networkModel.isProviderForNetwork(Provider.NiciraNvp, NETWORK_ID)).thenReturn(true);
+        when(ntwkSrvcDao.canProviderSupportServiceInNetwork(NETWORK_ID, Service.Connectivity, Provider.NiciraNvp)).thenReturn(true);
+
+        final NiciraNvpDeviceVO device = mock(NiciraNvpDeviceVO.class);
+        when(niciraNvpDao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Arrays.asList(new NiciraNvpDeviceVO[] {device}));
+        when(device.getId()).thenReturn(1L);
+        when(device.getHostId()).thenReturn(NICIRA_NVP_HOST_ID);
+
+        HostVO niciraNvpHost = mock(HostVO.class);
+        when(niciraNvpHost.getId()).thenReturn(NICIRA_NVP_HOST_ID);
+        when(hostDao.findById(NICIRA_NVP_HOST_ID)).thenReturn(niciraNvpHost);
 
         final NetworkOffering offering = mock(NetworkOffering.class);
         when(offering.getId()).thenReturn(NETWORK_ID);
         when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
         when(offering.getGuestType()).thenReturn(GuestType.Isolated);
 
-        mock(DeployDestination.class);
+        final DeployDestination dest = mock(DeployDestination.class);
 
         final Domain dom = mock(Domain.class);
         when(dom.getName()).thenReturn("domain");
@@ -152,6 +185,26 @@ public class NiciraNvpElementTest {
         final ReservationContext context = mock(ReservationContext.class);
         when(context.getDomain()).thenReturn(dom);
         when(context.getAccount()).thenReturn(acc);
+
+        //ISOLATED NETWORK
+        when(networkModel.isProviderSupportServiceInNetwork(NETWORK_ID, Service.SourceNat, Provider.NiciraNvp)).thenReturn(true);
+
+        PublicIp sourceNatIp = mock(PublicIp.class);
+        Ip ip = mock(Ip.class);
+        when(ip.addr()).thenReturn("10.0.0.0");
+        when(sourceNatIp.getAddress()).thenReturn(ip);
+        when(sourceNatIp.getVlanNetmask()).thenReturn("255.255.255.0");
+        when(sourceNatIp.getVlanTag()).thenReturn("111");
+
+        when(ipAddressManager.assignSourceNatIpAddressToGuestNetwork(acc, network)).thenReturn(sourceNatIp);
+        when(network.getGateway()).thenReturn(NETWORK_GATEWAY);
+        when(network.getCidr()).thenReturn(NETWORK_CIDR);
+
+        final CreateLogicalRouterAnswer answer = mock(CreateLogicalRouterAnswer.class);
+        when(answer.getResult()).thenReturn(true);
+        when(agentManager.easySend(eq(NICIRA_NVP_HOST_ID), (Command)any())).thenReturn(answer);
+
+        assertTrue(element.implement(network, offering, dest, context));
     }
 
     @Test
@@ -214,4 +267,158 @@ public class NiciraNvpElementTest {
             }
         }));
     }
+
+    @Test
+    public void implementSharedNetworkUuidVlanIdTest() throws URISyntaxException, ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
+        // SHARED NETWORKS CASE 1: LOGICAL ROUTER'S UUID AS VLAN ID
+        final Network network = mock(Network.class);
+        when(network.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Lswitch);
+        when(network.getBroadcastUri()).thenReturn(new URI("lswitch:aaaaa"));
+        when(network.getId()).thenReturn(NETWORK_ID);
+        when(network.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
+        when(network.getGuestType()).thenReturn(GuestType.Shared);
+
+        when(networkModel.isProviderForNetwork(Provider.NiciraNvp, NETWORK_ID)).thenReturn(true);
+        when(ntwkSrvcDao.canProviderSupportServiceInNetwork(NETWORK_ID, Service.Connectivity, Provider.NiciraNvp)).thenReturn(true);
+
+        final NiciraNvpDeviceVO device = mock(NiciraNvpDeviceVO.class);
+        when(niciraNvpDao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Arrays.asList(new NiciraNvpDeviceVO[] {device}));
+        when(device.getId()).thenReturn(1L);
+        when(device.getHostId()).thenReturn(NICIRA_NVP_HOST_ID);
+
+        HostVO niciraNvpHost = mock(HostVO.class);
+        when(niciraNvpHost.getId()).thenReturn(NICIRA_NVP_HOST_ID);
+        when(hostDao.findById(NICIRA_NVP_HOST_ID)).thenReturn(niciraNvpHost);
+
+        final NetworkOffering offering = mock(NetworkOffering.class);
+        when(offering.getId()).thenReturn(NETWORK_ID);
+        when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
+        when(offering.getGuestType()).thenReturn(GuestType.Shared);
+
+        final DeployDestination dest = mock(DeployDestination.class);
+
+        final Domain dom = mock(Domain.class);
+        when(dom.getName()).thenReturn("domain");
+        final Account acc = mock(Account.class);
+        when(acc.getAccountName()).thenReturn("accountname");
+        final ReservationContext context = mock(ReservationContext.class);
+        when(context.getDomain()).thenReturn(dom);
+        when(context.getAccount()).thenReturn(acc);
+
+        //SHARED NETWORKS CASE 1
+        when(niciraNvpRouterMappingDao.existsMappingForNetworkId(NETWORK_ID)).thenReturn(true);
+        when(network.getCidr()).thenReturn(NETWORK_CIDR);
+        when(network.getGateway()).thenReturn(NETWORK_GATEWAY);
+
+        NiciraNvpRouterMappingVO mapping = mock(NiciraNvpRouterMappingVO.class);
+        when(mapping.getLogicalRouterUuid()).thenReturn("xxxx-xxxx-xxxx");
+        when(niciraNvpRouterMappingDao.findByNetworkId(NETWORK_ID)).thenReturn(mapping);
+
+        final ConfigureSharedNetworkUuidAnswer answer = mock(ConfigureSharedNetworkUuidAnswer.class);
+        when(answer.getResult()).thenReturn(true);
+        when(agentManager.easySend(eq(NICIRA_NVP_HOST_ID), (Command)any())).thenReturn(answer);
+
+        assertTrue(element.implement(network, offering, dest, context));
+    }
+
+    @Test
+    public void implementSharedNetworkNumericalVlanIdTest() throws URISyntaxException, ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
+        // SHARED NETWORKS CASE 2: NUMERICAL VLAN ID
+        final Network network = mock(Network.class);
+        when(network.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Lswitch);
+        when(network.getBroadcastUri()).thenReturn(new URI("lswitch:aaaaa"));
+        when(network.getId()).thenReturn(NETWORK_ID);
+        when(network.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
+        when(network.getGuestType()).thenReturn(GuestType.Shared);
+
+        when(networkModel.isProviderForNetwork(Provider.NiciraNvp, NETWORK_ID)).thenReturn(true);
+        when(ntwkSrvcDao.canProviderSupportServiceInNetwork(NETWORK_ID, Service.Connectivity, Provider.NiciraNvp)).thenReturn(true);
+
+        final NiciraNvpDeviceVO device = mock(NiciraNvpDeviceVO.class);
+        when(niciraNvpDao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Arrays.asList(new NiciraNvpDeviceVO[] {device}));
+        when(device.getId()).thenReturn(1L);
+        when(device.getHostId()).thenReturn(NICIRA_NVP_HOST_ID);
+
+        HostVO niciraNvpHost = mock(HostVO.class);
+        when(niciraNvpHost.getId()).thenReturn(NICIRA_NVP_HOST_ID);
+        when(hostDao.findById(NICIRA_NVP_HOST_ID)).thenReturn(niciraNvpHost);
+
+        final NetworkOffering offering = mock(NetworkOffering.class);
+        when(offering.getId()).thenReturn(NETWORK_ID);
+        when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
+        when(offering.getGuestType()).thenReturn(GuestType.Shared);
+
+        final DeployDestination dest = mock(DeployDestination.class);
+
+        final Domain dom = mock(Domain.class);
+        when(dom.getName()).thenReturn("domain");
+        final Account acc = mock(Account.class);
+        when(acc.getAccountName()).thenReturn("accountname");
+        final ReservationContext context = mock(ReservationContext.class);
+        when(context.getDomain()).thenReturn(dom);
+        when(context.getAccount()).thenReturn(acc);
+
+        //SHARED NETWORKS CASE 2
+        when(niciraNvpRouterMappingDao.existsMappingForNetworkId(NETWORK_ID)).thenReturn(false);
+
+        VlanVO vlanVO = mock(VlanVO.class);
+        when(vlanVO.getVlanTag()).thenReturn("111");
+        when(vlanDao.listVlansByNetworkId(NETWORK_ID)).thenReturn(Arrays.asList(new VlanVO[] {vlanVO}));
+
+        when(niciraNvpHost.getDetail("l2gatewayserviceuuid")).thenReturn("bbbb-bbbb-bbbb");
+
+        final ConfigureSharedNetworkVlanIdAnswer answer = mock(ConfigureSharedNetworkVlanIdAnswer.class);
+        when(answer.getResult()).thenReturn(true);
+        when(agentManager.easySend(eq(NICIRA_NVP_HOST_ID), (Command)any())).thenReturn(answer);
+
+        assertTrue(element.implement(network, offering, dest, context));
+    }
+
+    @Test(expected=CloudRuntimeException.class)
+    public void implementSharedNetworkNumericalVlanIdWithoutL2GatewayService() throws URISyntaxException, ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException{
+        final Network network = mock(Network.class);
+        when(network.getBroadcastDomainType()).thenReturn(BroadcastDomainType.Lswitch);
+        when(network.getBroadcastUri()).thenReturn(new URI("lswitch:aaaaa"));
+        when(network.getId()).thenReturn(NETWORK_ID);
+        when(network.getPhysicalNetworkId()).thenReturn(NETWORK_ID);
+        when(network.getGuestType()).thenReturn(GuestType.Shared);
+
+        when(networkModel.isProviderForNetwork(Provider.NiciraNvp, NETWORK_ID)).thenReturn(true);
+        when(ntwkSrvcDao.canProviderSupportServiceInNetwork(NETWORK_ID, Service.Connectivity, Provider.NiciraNvp)).thenReturn(true);
+
+        final NiciraNvpDeviceVO device = mock(NiciraNvpDeviceVO.class);
+        when(niciraNvpDao.listByPhysicalNetwork(NETWORK_ID)).thenReturn(Arrays.asList(new NiciraNvpDeviceVO[] {device}));
+        when(device.getId()).thenReturn(1L);
+        when(device.getHostId()).thenReturn(NICIRA_NVP_HOST_ID);
+
+        HostVO niciraNvpHost = mock(HostVO.class);
+        when(niciraNvpHost.getId()).thenReturn(NICIRA_NVP_HOST_ID);
+        when(hostDao.findById(NICIRA_NVP_HOST_ID)).thenReturn(niciraNvpHost);
+
+        final NetworkOffering offering = mock(NetworkOffering.class);
+        when(offering.getId()).thenReturn(NETWORK_ID);
+        when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
+        when(offering.getGuestType()).thenReturn(GuestType.Shared);
+
+        final DeployDestination dest = mock(DeployDestination.class);
+
+        final Domain dom = mock(Domain.class);
+        when(dom.getName()).thenReturn("domain");
+        final Account acc = mock(Account.class);
+        when(acc.getAccountName()).thenReturn("accountname");
+        final ReservationContext context = mock(ReservationContext.class);
+        when(context.getDomain()).thenReturn(dom);
+        when(context.getAccount()).thenReturn(acc);
+
+        //SHARED NETWORKS CASE 2
+        when(niciraNvpRouterMappingDao.existsMappingForNetworkId(NETWORK_ID)).thenReturn(false);
+
+        VlanVO vlanVO = mock(VlanVO.class);
+        when(vlanVO.getVlanTag()).thenReturn("111");
+        when(vlanDao.listVlansByNetworkId(NETWORK_ID)).thenReturn(Arrays.asList(new VlanVO[] {vlanVO}));
+
+        when(niciraNvpHost.getDetail("l2gatewayserviceuuid")).thenReturn(null);
+
+        element.implement(network, offering, dest, context);
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c6763718/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/guru/NiciraNvpGuestNetworkGuruTest.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/guru/NiciraNvpGuestNetworkGuruTest.java b/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/guru/NiciraNvpGuestNetworkGuruTest.java
index 36e4643..d7c83b4 100644
--- a/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/guru/NiciraNvpGuestNetworkGuruTest.java
+++ b/plugins/network-elements/nicira-nvp/src/test/java/com/cloud/network/guru/NiciraNvpGuestNetworkGuruTest.java
@@ -129,10 +129,10 @@ public class NiciraNvpGuestNetworkGuruTest {
         when(offering.getTrafficType()).thenReturn(TrafficType.Management);
         assertFalse(guru.canHandle(offering, NetworkType.Advanced, physnet) == true);
 
-        // Not supported: GuestType Shared
+        // Supported: GuestType Shared
         when(offering.getTrafficType()).thenReturn(TrafficType.Guest);
         when(offering.getGuestType()).thenReturn(GuestType.Shared);
-        assertFalse(guru.canHandle(offering, NetworkType.Advanced, physnet) == true);
+        assertTrue(guru.canHandle(offering, NetworkType.Advanced, physnet));
 
         // Not supported: Basic networking
         when(offering.getGuestType()).thenReturn(GuestType.Isolated);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c6763718/server/src/com/cloud/network/guru/DirectNetworkGuru.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/guru/DirectNetworkGuru.java b/server/src/com/cloud/network/guru/DirectNetworkGuru.java
index f741651..09afd6b 100644
--- a/server/src/com/cloud/network/guru/DirectNetworkGuru.java
+++ b/server/src/com/cloud/network/guru/DirectNetworkGuru.java
@@ -120,7 +120,8 @@ public class DirectNetworkGuru extends AdapterBase implements NetworkGuru {
     protected boolean canHandle(NetworkOffering offering, DataCenter dc) {
         // this guru handles only Guest networks in Advance zone with source nat service disabled
         if (dc.getNetworkType() == NetworkType.Advanced && isMyTrafficType(offering.getTrafficType()) && offering.getGuestType() == GuestType.Shared
-                && !_ntwkOfferingSrvcDao.isProviderForNetworkOffering(offering.getId(), Network.Provider.NuageVsp)) {
+                && !_ntwkOfferingSrvcDao.isProviderForNetworkOffering(offering.getId(), Network.Provider.NuageVsp)
+                && !_ntwkOfferingSrvcDao.isProviderForNetworkOffering(offering.getId(), Network.Provider.NiciraNvp)) {
             return true;
         } else {
             s_logger.trace("We only take care of Guest networks of type " + GuestType.Shared);


[03/16] git commit: updated refs/heads/master to 67b753c

Posted by re...@apache.org.
Add helper method to migrate router vms


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/3dba689f
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/3dba689f
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/3dba689f

Branch: refs/heads/master
Commit: 3dba689f31a89f6b17b3018dfb2dc6f689698812
Parents: 88774a9
Author: Miguel Ferreira <mi...@me.com>
Authored: Thu Dec 24 11:08:59 2015 +0100
Committer: nvazquez <ni...@gmail.com>
Committed: Thu Dec 24 16:07:06 2015 -0300

----------------------------------------------------------------------
 tools/marvin/marvin/lib/common.py | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/3dba689f/tools/marvin/marvin/lib/common.py
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/lib/common.py b/tools/marvin/marvin/lib/common.py
index fa45299..5f738f4 100644
--- a/tools/marvin/marvin/lib/common.py
+++ b/tools/marvin/marvin/lib/common.py
@@ -56,7 +56,8 @@ from marvin.cloudstackAPI import (listConfigurations,
                                   listVirtualRouterElements,
                                   listNetworkOfferings,
                                   listResourceLimits,
-                                  listVPCOfferings)
+                                  listVPCOfferings,
+                                  migrateSystemVm)
 from marvin.sshClient import SshClient
 from marvin.codes import (PASS, FAILED, ISOLATED_NETWORK, VPC_NETWORK,
                           BASIC_ZONE, FAIL, NAT_RULE, STATIC_NAT_RULE,
@@ -64,8 +65,8 @@ from marvin.codes import (PASS, FAILED, ISOLATED_NETWORK, VPC_NETWORK,
                           RESOURCE_CPU, RESOURCE_MEMORY, PUBLIC_TRAFFIC,
                           GUEST_TRAFFIC, MANAGEMENT_TRAFFIC, STORAGE_TRAFFIC,
                           VMWAREDVS)
-from marvin.lib.utils import (validateList, 
-                              xsplit, 
+from marvin.lib.utils import (validateList,
+                              xsplit,
                               get_process_status,
                               random_gen,
                               format_volume_to_ext3)
@@ -1419,13 +1420,13 @@ def isNetworkDeleted(apiclient, networkid, timeout=600):
     return networkDeleted
 
 
-def createChecksum(service=None, 
-                   virtual_machine=None, 
-                   disk=None, 
+def createChecksum(service=None,
+                   virtual_machine=None,
+                   disk=None,
                    disk_type=None):
 
     """ Calculate the MD5 checksum of the disk by writing \
-		data on the disk where disk_type is either root disk or data disk 
+		data on the disk where disk_type is either root disk or data disk
 	@return: returns the calculated checksum"""
 
     random_data_0 = random_gen(size=100)
@@ -1440,7 +1441,7 @@ def createChecksum(service=None,
             virtual_machine.username,
             virtual_machine.password
         )
-    except Exception: 
+    except Exception:
         raise Exception("SSH access failed for server with IP address: %s" %
                     virtual_machine.ssh_ip)
 
@@ -1898,3 +1899,10 @@ def verifyVCenterPortGroups(
     except Exception as e:
         return [FAIL, e]
     return [PASS, None]
+
+def migrate_router(apiclient, router_id, host_id):
+    cmd = migrateSystemVm.migrateSystemVmCmd()
+    cmd.hostid = host_id
+    cmd.virtualmachineid = router_id
+
+    apiclient.migrateSystemVm(cmd)


[11/16] git commit: updated refs/heads/master to 67b753c

Posted by re...@apache.org.
CLOUDSTACK-9074: API Changes: Add l2gatewayserviceuuid to NVP devices


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/46f9fbab
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/46f9fbab
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/46f9fbab

Branch: refs/heads/master
Commit: 46f9fbabdf2fdb3aa7ca92fd8a54a9a0a9443f4d
Parents: 60f0065
Author: nvazquez <ni...@gmail.com>
Authored: Tue Dec 1 11:46:22 2015 -0800
Committer: nvazquez <ni...@gmail.com>
Committed: Thu Dec 24 16:07:06 2015 -0300

----------------------------------------------------------------------
 .../org/apache/cloudstack/api/ApiConstants.java |  1 +
 .../classes/resources/messages.properties       |  1 +
 .../api/commands/AddNiciraNvpDeviceCmd.java     | 10 ++++++++++
 .../api/response/NiciraNvpDeviceResponse.java   |  7 +++++++
 ui/dictionary.jsp                               |  1 +
 ui/scripts/system.js                            | 21 ++++++++++++++++++--
 6 files changed, 39 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/46f9fbab/api/src/org/apache/cloudstack/api/ApiConstants.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/ApiConstants.java b/api/src/org/apache/cloudstack/api/ApiConstants.java
index 742d2f4..4f68930 100644
--- a/api/src/org/apache/cloudstack/api/ApiConstants.java
+++ b/api/src/org/apache/cloudstack/api/ApiConstants.java
@@ -498,6 +498,7 @@ public class ApiConstants {
     public static final String NICIRA_NVP_TRANSPORT_ZONE_UUID = "transportzoneuuid";
     public static final String NICIRA_NVP_DEVICE_NAME = "niciradevicename";
     public static final String NICIRA_NVP_GATEWAYSERVICE_UUID = "l3gatewayserviceuuid";
+    public static final String NICIRA_NVP_L2_GATEWAYSERVICE_UUID = "l2gatewayserviceuuid";
     public static final String S3_ACCESS_KEY = "accesskey";
     public static final String S3_SECRET_KEY = "secretkey";
     public static final String S3_END_POINT = "endpoint";

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/46f9fbab/client/WEB-INF/classes/resources/messages.properties
----------------------------------------------------------------------
diff --git a/client/WEB-INF/classes/resources/messages.properties b/client/WEB-INF/classes/resources/messages.properties
index e7beaa9..a487ea7 100644
--- a/client/WEB-INF/classes/resources/messages.properties
+++ b/client/WEB-INF/classes/resources/messages.properties
@@ -942,6 +942,7 @@ label.nfs.storage=NFS Storage
 label.nfs=NFS
 label.nic.adapter.type=NIC adapter type
 label.nicira.controller.address=Controller Address
+label.nicira.l2gatewayserviceuuid=L2 Gateway Service Uuid
 label.nicira.l3gatewayserviceuuid=L3 Gateway Service Uuid
 label.nicira.transportzoneuuid=Transport Zone Uuid
 label.brocade.vcs.address=Vcs Switch Address

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/46f9fbab/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/api/commands/AddNiciraNvpDeviceCmd.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/api/commands/AddNiciraNvpDeviceCmd.java b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/api/commands/AddNiciraNvpDeviceCmd.java
index 1a9be28..1bde3b7 100644
--- a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/api/commands/AddNiciraNvpDeviceCmd.java
+++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/api/commands/AddNiciraNvpDeviceCmd.java
@@ -80,6 +80,12 @@ public class AddNiciraNvpDeviceCmd extends BaseAsyncCmd {
                description = "The L3 Gateway Service UUID configured on the Nicira Controller")
     private String l3gatewayserviceuuid;
 
+    @Parameter(name = ApiConstants.NICIRA_NVP_L2_GATEWAYSERVICE_UUID,
+            type = CommandType.STRING,
+            required = false,
+            description = "The L2 Gateway Service UUID configured on the Nicira Controller")
+    private String l2gatewayserviceuuid;
+
     /////////////////////////////////////////////////////
     /////////////////// Accessors ///////////////////////
     /////////////////////////////////////////////////////
@@ -108,6 +114,10 @@ public class AddNiciraNvpDeviceCmd extends BaseAsyncCmd {
         return l3gatewayserviceuuid;
     }
 
+    public String getL2GatewayServiceUuid() {
+        return l2gatewayserviceuuid;
+     }
+
     /////////////////////////////////////////////////////
     /////////////// API Implementation///////////////////
     /////////////////////////////////////////////////////

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/46f9fbab/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/api/response/NiciraNvpDeviceResponse.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/api/response/NiciraNvpDeviceResponse.java b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/api/response/NiciraNvpDeviceResponse.java
index 46287aa..dedccef 100644
--- a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/api/response/NiciraNvpDeviceResponse.java
+++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/api/response/NiciraNvpDeviceResponse.java
@@ -58,6 +58,10 @@ public class NiciraNvpDeviceResponse extends BaseResponse {
     @Param(description = "this L3 gateway service Uuid")
     private String l3GatewayServiceUuid;
 
+    @SerializedName(ApiConstants.NICIRA_NVP_L2_GATEWAYSERVICE_UUID)
+    @Param(description = "this L2 gateway service Uuid")
+    private String l2GatewayServiceUuid;
+
     public void setId(String nvpDeviceId) {
         this.id = nvpDeviceId;
     }
@@ -86,4 +90,7 @@ public class NiciraNvpDeviceResponse extends BaseResponse {
         this.l3GatewayServiceUuid = l3GatewayServiceUuid;
     }
 
+    public void setL2GatewayServiceUuid(final String l2GatewayServiceUuid) {
+        this.l2GatewayServiceUuid = l2GatewayServiceUuid;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/46f9fbab/ui/dictionary.jsp
----------------------------------------------------------------------
diff --git a/ui/dictionary.jsp b/ui/dictionary.jsp
index e82ae19..b97141c 100644
--- a/ui/dictionary.jsp
+++ b/ui/dictionary.jsp
@@ -934,6 +934,7 @@ dictionary = {
 'label.nfs.storage': '<fmt:message key="label.nfs.storage" />',
 'label.nic.adapter.type': '<fmt:message key="label.nic.adapter.type" />',
 'label.nicira.controller.address': '<fmt:message key="label.nicira.controller.address" />',
+'label.nicira.l2gatewayserviceuuid': '<fmt:message key="label.nicira.l2gatewayserviceuuid" />',
 'label.nicira.l3gatewayserviceuuid': '<fmt:message key="label.nicira.l3gatewayserviceuuid" />',
 'label.nicira.transportzoneuuid': '<fmt:message key="label.nicira.transportzoneuuid" />',
 'label.brocade.vcs.address': '<fmt:message key="label.brocade.vcs.address" />',

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/46f9fbab/ui/scripts/system.js
----------------------------------------------------------------------
diff --git a/ui/scripts/system.js b/ui/scripts/system.js
index af69359..faa388c 100644
--- a/ui/scripts/system.js
+++ b/ui/scripts/system.js
@@ -5774,6 +5774,9 @@
                                         },
                                         l3gatewayserviceuuid: {
                                             label: 'label.nicira.l3gatewayserviceuuid'
+                                        },
+										l2gatewayserviceuuid: {
+                                            label: 'label.nicira.l2gatewayserviceuuid'
                                         }
                                     }
                                 },
@@ -12539,6 +12542,9 @@
                         },
                         l3gatewayserviceuuid: {
                             label: 'label.nicira.l3gatewayserviceuuid'
+                        },
+						l2gatewayserviceuuid: {
+                            label: 'label.nicira.l2gatewayserviceuuid'
                         }
                     },
                     actions: {
@@ -12569,7 +12575,10 @@
                                     },
                                     l3gatewayserviceuuid: {
                                         label: 'label.nicira.l3gatewayserviceuuid'
-                                    }
+                                    },
+									l2gatewayserviceuuid: {
+										label: 'label.nicira.l2gatewayserviceuuid'
+									}
                                 }
                             },
                             action: function (args) {
@@ -12687,7 +12696,10 @@
                                     },
                                     l3gatewayserviceuuid: {
                                         label: 'label.nicira.l3gatewayserviceuuid'
-                                    }
+                                    },
+									l2gatewayserviceuuid: {
+										label: 'label.nicira.l2gatewayserviceuuid'
+									}
                                 }],
                                 dataProvider: function (args) {
                                     $.ajax({
@@ -20324,6 +20336,11 @@
         if (l3GatewayServiceUuid != null && l3GatewayServiceUuid.length > 0) {
             array1.push("&l3gatewayserviceuuid=" + todb(args.data.l3gatewayserviceuuid));
         }
+		
+		var l2GatewayServiceUuid = args.data.l2gatewayserviceuuid;
+        if (l2GatewayServiceUuid != null && l2GatewayServiceUuid.length > 0) {
+            array1.push("&l2gatewayserviceuuid=" + todb(args.data.l2gatewayserviceuuid));
+        }
 
         $.ajax({
             url: createURL(apiCmd + array1.join("")),


[09/16] git commit: updated refs/heads/master to 67b753c

Posted by re...@apache.org.
CLOUDSTACK-9074: Drop nicira_nvp_router_map unique index on logicalrouter_uuid


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/07264204
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/07264204
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/07264204

Branch: refs/heads/master
Commit: 07264204f55ccf5ccf724c539ec1f477dc88a190
Parents: eb889c0
Author: nvazquez <ni...@gmail.com>
Authored: Wed Dec 9 10:57:12 2015 -0800
Committer: nvazquez <ni...@gmail.com>
Committed: Thu Dec 24 16:07:06 2015 -0300

----------------------------------------------------------------------
 setup/db/db/schema-461to470.sql | 2 ++
 1 file changed, 2 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/07264204/setup/db/db/schema-461to470.sql
----------------------------------------------------------------------
diff --git a/setup/db/db/schema-461to470.sql b/setup/db/db/schema-461to470.sql
index 238acb5..7cc249c 100644
--- a/setup/db/db/schema-461to470.sql
+++ b/setup/db/db/schema-461to470.sql
@@ -250,3 +250,5 @@ CREATE VIEW `cloud`.`domain_router_view` AS
 INSERT IGNORE INTO `cloud`.`hypervisor_capabilities` values (25,UUID(),'VMware','6.0',128,0,13,32,1,1);
 INSERT IGNORE INTO `cloud`.`guest_os_hypervisor` (uuid,hypervisor_type, hypervisor_version, guest_os_name, guest_os_id, created, is_user_defined) VALUES (UUID(),'VMware', '5.5', 'rhel7_64Guest', 245, utc_timestamp(), 0);
 INSERT IGNORE INTO `cloud`.`guest_os_hypervisor` (uuid,hypervisor_type, hypervisor_version, guest_os_name, guest_os_id, created, is_user_defined) SELECT UUID(),'VMware', '6.0', guest_os_name, guest_os_id, utc_timestamp(), 0  FROM `cloud`.`guest_os_hypervisor` WHERE hypervisor_type='VMware' AND hypervisor_version='5.5' AND (guest_os_id NOT IN (1,2,3,4,62,63,64,65,156,157,221,222) AND guest_os_id NOT BETWEEN 121 AND 130);
+
+ALTER TABLE `cloud`.`nicira_nvp_router_map` DROP INDEX `logicalrouter_uuid` ;


[14/16] git commit: updated refs/heads/master to 67b753c

Posted by re...@apache.org.
Only set L2 Gateway in NSX device if defined


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/88774a93
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/88774a93
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/88774a93

Branch: refs/heads/master
Commit: 88774a93e88d83bdf2868b382f66ecfae441a69a
Parents: 4ac2737
Author: Miguel Ferreira <mi...@me.com>
Authored: Thu Dec 24 11:08:42 2015 +0100
Committer: nvazquez <ni...@gmail.com>
Committed: Thu Dec 24 16:07:06 2015 -0300

----------------------------------------------------------------------
 tools/marvin/marvin/lib/base.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/88774a93/tools/marvin/marvin/lib/base.py
----------------------------------------------------------------------
diff --git a/tools/marvin/marvin/lib/base.py b/tools/marvin/marvin/lib/base.py
index 379ecd9..35d0b27 100755
--- a/tools/marvin/marvin/lib/base.py
+++ b/tools/marvin/marvin/lib/base.py
@@ -3878,7 +3878,7 @@ class NiciraNvp:
 
         if l2gatewayserviceuuid:
             cmd.l2gatewayserviceuuid = l2gatewayserviceuuid
-        else:
+        elif services and 'l2gatewayserviceuuid' in services:
             cmd.l2gatewayserviceuuid = services['l2gatewayserviceuuid']
 
 	return NiciraNvp(apiclient.addNiciraNvpDevice(cmd).__dict__)
@@ -4060,9 +4060,9 @@ class VpcOffering:
     @classmethod
     def create(cls, apiclient, services):
         """Create vpc offering"""
-        
+
         import logging
-        
+
         cmd = createVPCOffering.createVPCOfferingCmd()
         cmd.name = "-".join([services["name"], random_gen()])
         cmd.displaytext = services["displaytext"]


[07/16] git commit: updated refs/heads/master to 67b753c

Posted by re...@apache.org.
CLOUDSTACK-9074: New NiciraNVP classes for FindLRouterPort and DeleteLRouterPort API methods


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/55f46077
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/55f46077
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/55f46077

Branch: refs/heads/master
Commit: 55f460772e5e9872115947b47fa40579c9026dfe
Parents: 06d5b46
Author: nvazquez <ni...@gmail.com>
Authored: Fri Dec 4 10:20:44 2015 -0800
Committer: nvazquez <ni...@gmail.com>
Committed: Thu Dec 24 16:07:06 2015 -0300

----------------------------------------------------------------------
 .../api/DeleteLogicalRouterPortAnswer.java      | 31 +++++++++
 .../api/DeleteLogicalRouterPortCommand.java     | 53 +++++++++++++++
 .../agent/api/FindLogicalRouterPortAnswer.java  | 38 +++++++++++
 .../agent/api/FindLogicalRouterPortCommand.java | 59 +++++++++++++++++
 .../cloud/network/nicira/NiciraConstants.java   |  1 +
 .../com/cloud/network/nicira/NiciraNvpApi.java  | 14 ++++
 ...vpDeleteLogicalRouterPortCommandWrapper.java | 59 +++++++++++++++++
 ...aNvpFindLogicalRouterPortCommandWrapper.java | 68 ++++++++++++++++++++
 8 files changed, 323 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/55f46077/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/agent/api/DeleteLogicalRouterPortAnswer.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/agent/api/DeleteLogicalRouterPortAnswer.java b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/agent/api/DeleteLogicalRouterPortAnswer.java
new file mode 100644
index 0000000..2850047
--- /dev/null
+++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/agent/api/DeleteLogicalRouterPortAnswer.java
@@ -0,0 +1,31 @@
+//
+// 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.agent.api;
+
+public class DeleteLogicalRouterPortAnswer extends Answer {
+
+    public DeleteLogicalRouterPortAnswer(final Command command, final boolean success, final String details) {
+        super(command, success, details);
+    }
+
+    public DeleteLogicalRouterPortAnswer(final Command command, final Exception e) {
+        super(command, e);
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/55f46077/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/agent/api/DeleteLogicalRouterPortCommand.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/agent/api/DeleteLogicalRouterPortCommand.java b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/agent/api/DeleteLogicalRouterPortCommand.java
new file mode 100644
index 0000000..7295358
--- /dev/null
+++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/agent/api/DeleteLogicalRouterPortCommand.java
@@ -0,0 +1,53 @@
+//
+// 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.agent.api;
+
+public class DeleteLogicalRouterPortCommand extends Command {
+
+    private String logicalRouterUuid;
+    private String logicalRouterPortUuid;
+
+    public DeleteLogicalRouterPortCommand(String logicalRouterUuid, String logicalRouterPortUuid) {
+        this.logicalRouterUuid = logicalRouterUuid;
+        this.logicalRouterPortUuid = logicalRouterPortUuid;
+    }
+
+    @Override
+    public boolean executeInSequence() {
+        return false;
+    }
+
+    public String getLogicalRouterUuid() {
+        return logicalRouterUuid;
+    }
+
+    public void setLogicalRouterUuid(String logicalRouterUuid) {
+        this.logicalRouterUuid = logicalRouterUuid;
+    }
+
+    public String getLogicalRouterPortUuid() {
+        return logicalRouterPortUuid;
+    }
+
+    public void setLogicalRouterPortUuid(String logicalRouterPortUuid) {
+        this.logicalRouterPortUuid = logicalRouterPortUuid;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/55f46077/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/agent/api/FindLogicalRouterPortAnswer.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/agent/api/FindLogicalRouterPortAnswer.java b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/agent/api/FindLogicalRouterPortAnswer.java
new file mode 100644
index 0000000..2ec211b
--- /dev/null
+++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/agent/api/FindLogicalRouterPortAnswer.java
@@ -0,0 +1,38 @@
+//
+// 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.agent.api;
+
+public class FindLogicalRouterPortAnswer extends Answer {
+
+    private String logicalRouterPortUuid;
+
+    public FindLogicalRouterPortAnswer(final Command command, final boolean success, final String details, final String lRouterPortUuid) {
+        super(command, success, details);
+        this.logicalRouterPortUuid = lRouterPortUuid;
+    }
+
+    public FindLogicalRouterPortAnswer(final Command command, final Exception e) {
+        super(command, e);
+    }
+
+    public String getLogicalRouterPortUuid() {
+        return logicalRouterPortUuid;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/55f46077/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/agent/api/FindLogicalRouterPortCommand.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/agent/api/FindLogicalRouterPortCommand.java b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/agent/api/FindLogicalRouterPortCommand.java
new file mode 100644
index 0000000..965f65b
--- /dev/null
+++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/agent/api/FindLogicalRouterPortCommand.java
@@ -0,0 +1,59 @@
+//
+// 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.agent.api;
+
+public class FindLogicalRouterPortCommand extends Command {
+
+    private String logicalRouterUuid;
+    private String attachmentLswitchUuid;
+
+    public FindLogicalRouterPortCommand(String logicalRouterUuid) {
+        super();
+        this.logicalRouterUuid = logicalRouterUuid;
+    }
+
+    public FindLogicalRouterPortCommand(String logicalRouterUuid, String attachmentLswitchUuid) {
+        super();
+        this.logicalRouterUuid = logicalRouterUuid;
+        this.attachmentLswitchUuid = attachmentLswitchUuid;
+    }
+
+    @Override
+    public boolean executeInSequence() {
+        return false;
+    }
+
+    public String getLogicalRouterUuid() {
+        return logicalRouterUuid;
+    }
+
+    public void setLogicalRouterUuid(String logicalRouterUuid) {
+        this.logicalRouterUuid = logicalRouterUuid;
+    }
+
+    public String getAttachmentLswitchUuid() {
+        return attachmentLswitchUuid;
+    }
+
+    public void setAttachmentLswitchUuid(String attachmentLswitchUuid) {
+        this.attachmentLswitchUuid = attachmentLswitchUuid;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/55f46077/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraConstants.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraConstants.java b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraConstants.java
index 31adf9d..d5f7ca6 100644
--- a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraConstants.java
+++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraConstants.java
@@ -35,6 +35,7 @@ public class NiciraConstants {
     public static final String ATTACHMENT_VIF_UUID_QUERY_PARAMETER_NAME = "attachment_vif_uuid";
     public static final String ATTACHMENT_VLAN_PARAMETER = "attachment_vlan";
     public static final String ATTACHMENT_GWSVC_UUID_QUERY_PARAMETER = "attachment_gwsvc_uuid";
+    public static final String ATTACHMENT_LSWITCH_UUID = "attachment_lswitch_uuid";
     public static final String WILDCARD_QUERY_PARAMETER = "*";
     public static final String UUID_QUERY_PARAMETER = "uuid";
     public static final String FIELDS_QUERY_PARAMETER = "fields";

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/55f46077/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraNvpApi.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraNvpApi.java b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraNvpApi.java
index 093d90d..b1113a2 100644
--- a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraNvpApi.java
+++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraNvpApi.java
@@ -526,6 +526,20 @@ public class NiciraNvpApi {
         }
     }
 
+    public List<LogicalRouterPort> findLogicalRouterPortByAttachmentLSwitchUuid(final String logicalRouterUuid, final String attachmentLSwitchUuid) throws NiciraNvpApiException{
+        final String uri = buildLogicalRouterElementUri(logicalRouterUuid, LPORT_PATH_SEGMENT);
+        final Map<String, String> params = buildBasicParametersMap(WILDCARD_QUERY_PARAMETER);
+        params.put(NiciraConstants.ATTACHMENT_LSWITCH_UUID, attachmentLSwitchUuid);
+
+        try{
+            final Type niciraListType = new TypeToken<NiciraNvpList<LogicalRouterPort>>() {
+            }.getType();
+            return restConnector.<NiciraNvpList<LogicalRouterPort>> executeRetrieveObject(niciraListType, uri, params).getResults();
+        } catch (final CloudstackRESTException e) {
+            throw new NiciraNvpApiException(e);
+        }
+    }
+
     public List<NatRule> findNatRulesByLogicalRouterUuid(final String logicalRouterUuid) throws NiciraNvpApiException {
         final String uri = buildLogicalRouterElementUri(logicalRouterUuid, NAT_PATH_SEGMENT);
         final Map<String, String> params = buildBasicParametersMap(WILDCARD_QUERY_PARAMETER);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/55f46077/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraNvpDeleteLogicalRouterPortCommandWrapper.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraNvpDeleteLogicalRouterPortCommandWrapper.java b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraNvpDeleteLogicalRouterPortCommandWrapper.java
new file mode 100644
index 0000000..a087f07
--- /dev/null
+++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraNvpDeleteLogicalRouterPortCommandWrapper.java
@@ -0,0 +1,59 @@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+
+package com.cloud.network.resource.wrapper;
+
+import static com.cloud.network.resource.NiciraNvpResource.NUM_RETRIES;
+
+import org.apache.log4j.Logger;
+
+import com.cloud.agent.api.Answer;
+import com.cloud.agent.api.DeleteLogicalRouterPortAnswer;
+import com.cloud.agent.api.DeleteLogicalRouterPortCommand;
+import com.cloud.network.nicira.NiciraNvpApi;
+import com.cloud.network.nicira.NiciraNvpApiException;
+import com.cloud.network.resource.NiciraNvpResource;
+import com.cloud.network.utils.CommandRetryUtility;
+import com.cloud.resource.CommandWrapper;
+import com.cloud.resource.ResourceWrapper;
+
+@ResourceWrapper(handles =  DeleteLogicalRouterPortCommand.class)
+public class NiciraNvpDeleteLogicalRouterPortCommandWrapper extends CommandWrapper<DeleteLogicalRouterPortCommand, Answer, NiciraNvpResource> {
+
+    private static final Logger s_logger = Logger.getLogger(NiciraNvpDeleteLogicalRouterPortCommandWrapper.class);
+
+    @Override
+    public Answer execute(DeleteLogicalRouterPortCommand command, NiciraNvpResource niciraNvpResource) {
+        final String logicalRouterUuid = command.getLogicalRouterUuid();
+        final String logicalRouterPortUuid = command.getLogicalRouterPortUuid();
+        final NiciraNvpApi niciraNvpApi = niciraNvpResource.getNiciraNvpApi();
+
+        s_logger.debug("Deleting Logical Router Port " + logicalRouterPortUuid + " in Logical Router " + logicalRouterUuid);
+        try {
+            niciraNvpApi.deleteLogicalRouterPort(logicalRouterUuid, logicalRouterPortUuid);
+            return new DeleteLogicalRouterPortAnswer(command, true, "Logical Router Port " + logicalRouterPortUuid + " deleted");
+        }
+        catch (NiciraNvpApiException e){
+            final CommandRetryUtility retryUtility = niciraNvpResource.getRetryUtility();
+            retryUtility.addRetry(command, NUM_RETRIES);
+            return retryUtility.retry(command, DeleteLogicalRouterPortAnswer.class, e);
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/55f46077/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraNvpFindLogicalRouterPortCommandWrapper.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraNvpFindLogicalRouterPortCommandWrapper.java b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraNvpFindLogicalRouterPortCommandWrapper.java
new file mode 100644
index 0000000..364d478
--- /dev/null
+++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraNvpFindLogicalRouterPortCommandWrapper.java
@@ -0,0 +1,68 @@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+
+package com.cloud.network.resource.wrapper;
+
+import static com.cloud.network.resource.NiciraNvpResource.NUM_RETRIES;
+
+import java.util.List;
+
+import org.apache.log4j.Logger;
+
+import com.cloud.agent.api.Answer;
+import com.cloud.agent.api.FindLogicalRouterPortAnswer;
+import com.cloud.agent.api.FindLogicalRouterPortCommand;
+import com.cloud.network.nicira.LogicalRouterPort;
+import com.cloud.network.nicira.NiciraNvpApi;
+import com.cloud.network.nicira.NiciraNvpApiException;
+import com.cloud.network.resource.NiciraNvpResource;
+import com.cloud.network.utils.CommandRetryUtility;
+import com.cloud.resource.CommandWrapper;
+import com.cloud.resource.ResourceWrapper;
+
+@ResourceWrapper(handles =  FindLogicalRouterPortCommand.class)
+public class NiciraNvpFindLogicalRouterPortCommandWrapper extends CommandWrapper<FindLogicalRouterPortCommand, Answer, NiciraNvpResource> {
+
+    private static final Logger s_logger = Logger.getLogger(NiciraNvpFindLogicalRouterPortCommandWrapper.class);
+
+    @Override
+    public Answer execute(FindLogicalRouterPortCommand command, NiciraNvpResource niciraNvpResource) {
+        final String logicalRouterUuid = command.getLogicalRouterUuid();
+        final String attachmentLswitchUuid = command.getAttachmentLswitchUuid();
+        final NiciraNvpApi niciraNvpApi = niciraNvpResource.getNiciraNvpApi();
+
+        s_logger.debug("Finding Logical Router Port in Logical Router " + logicalRouterUuid + " and attachmentLSwitchUuid " + attachmentLswitchUuid);
+
+        try{
+            List<LogicalRouterPort> lRouterPorts = niciraNvpApi.findLogicalRouterPortByAttachmentLSwitchUuid(logicalRouterUuid, attachmentLswitchUuid);
+            if (lRouterPorts.size() == 0) {
+                return new FindLogicalRouterPortAnswer(command, false, "Logical Router Port not found", null);
+            } else {
+                return new FindLogicalRouterPortAnswer(command, true, "Logical Router Port found", lRouterPorts.get(0).getUuid());
+            }
+        }
+        catch (NiciraNvpApiException e){
+            s_logger.error("Error finding Logical Router Port due to: " + e.getMessage());
+            final CommandRetryUtility retryUtility = niciraNvpResource.getRetryUtility();
+            retryUtility.addRetry(command, NUM_RETRIES);
+            return retryUtility.retry(command, FindLogicalRouterPortAnswer.class, e);
+        }
+    }
+
+}


[12/16] git commit: updated refs/heads/master to 67b753c

Posted by re...@apache.org.
Use NSX specific config values instead of zone config values


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/c285d6cf
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/c285d6cf
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/c285d6cf

Branch: refs/heads/master
Commit: c285d6cfb4f7aaf53bd317cfd80382a5894dfcec
Parents: acdc42c
Author: Miguel Ferreira <mi...@me.com>
Authored: Thu Dec 24 11:12:41 2015 +0100
Committer: nvazquez <ni...@gmail.com>
Committed: Thu Dec 24 16:07:06 2015 -0300

----------------------------------------------------------------------
 .../plugins/test_nicira_controller.py           | 190 ++++++++++---------
 1 file changed, 101 insertions(+), 89 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c285d6cf/test/integration/plugins/test_nicira_controller.py
----------------------------------------------------------------------
diff --git a/test/integration/plugins/test_nicira_controller.py b/test/integration/plugins/test_nicira_controller.py
index fd83f2b..75f94af 100644
--- a/test/integration/plugins/test_nicira_controller.py
+++ b/test/integration/plugins/test_nicira_controller.py
@@ -45,6 +45,23 @@ import logging
 
 class TestNiciraContoller(cloudstackTestCase):
 
+    '''
+    Example of marvin config with NSX specific values
+        "niciraNvp": {
+            "hosts": [ "nsxcon1.cloud.lan", "nsxcon2.cloud.lan", "nsxcon3.cloud.lan" ],
+            "shared_network": {
+                "l2gatewayserviceuuid": "3595ca67-959f-47d4-8f01-0492a8e96205",
+                "iprange" : {
+                    "startip": "192.168.26.2",
+                    "endip": "192.168.26.20",
+                    "netmask": "255.255.255.0",
+                    "gateway": "192.168.26.1",
+                    "vlan": "50",
+                    "vlan_uuid": "5cdaa49d-06cd-488a-9ca4-e954a3181f54"
+                }
+            }
+        }
+    '''
     @classmethod
     def setUpClass(cls):
         test_case = super(TestNiciraContoller, cls)
@@ -55,52 +72,55 @@ class TestNiciraContoller(cloudstackTestCase):
 
         cls.physical_networks = cls.config.zones[0].physical_networks
         cls.nicira_hosts      = cls.config.niciraNvp.hosts
-		
-        cls.l2gatewayserviceuuid   = cls.config.niciraNvp.l2gatewayserviceuuid
+
+        cls.nicira_shared_network_iprange = cls.config.niciraNvp.shared_network.iprange
+        cls.l2gatewayserviceuuid          = cls.config.niciraNvp.shared_network.l2gatewayserviceuuid
 
         cls.physical_network_id = cls.get_nicira_enabled_physical_network_id(cls.physical_networks)
 
         cls.network_offerring_services = [
-			{
-				'name':              'NiciraEnabledNetwork',
-				'displaytext':       'NiciraEnabledNetwork',
-				'guestiptype':       'Isolated',
-            			'supportedservices': 'SourceNat,Dhcp,Dns,Firewall,PortForwarding,Connectivity',
-				'traffictype':       'GUEST',
-				'availability':      'Optional',
-				'serviceProviderList': {
-						'SourceNat':      'VirtualRouter',
-                    				'Dhcp':           'VirtualRouter',
-                    				'Dns':            'VirtualRouter',
-						'Firewall':       'VirtualRouter',
-						'PortForwarding': 'VirtualRouter',
-						'Connectivity':   'NiciraNvp'
-				}
-			},
-			{
-				'name':              'NiciraEnabledSharedNetwork',
-				'displaytext':       'NiciraEnabledSharedNetwork',
-				'guestiptype':       'Shared',
-				'supportedservices': 'Connectivity,Dhcp,UserData',
-				'traffictype':       'GUEST',
-				'availability':      'Optional',
-				'specifyVlan':		'true',
-				'specifyIpRanges':	'true',
-				'serviceProviderList': {
-						'Connectivity':   	'NiciraNvp',
-						'Dhcp':       		'VirtualRouter',
-						'UserData': 		'VirtualRouter'
-				}
-			}
-		]
+            {
+                'name':              'NiciraEnabledIsolatedNetwork',
+                'displaytext':       'NiciraEnabledIsolatedNetwork',
+                'guestiptype':       'Isolated',
+                'supportedservices': 'SourceNat,Dhcp,Dns,Firewall,PortForwarding,Connectivity',
+                'traffictype':       'GUEST',
+                'availability':      'Optional',
+                'serviceProviderList': {
+                        'SourceNat':      'VirtualRouter',
+                        'Dhcp':           'VirtualRouter',
+                        'Dns':            'VirtualRouter',
+                        'Firewall':       'VirtualRouter',
+                        'PortForwarding': 'VirtualRouter',
+                        'Connectivity':   'NiciraNvp'
+                }
+            },
+            {
+                'name':              'NiciraEnabledSharedNetwork',
+                'displaytext':       'NiciraEnabledSharedNetwork',
+                'guestiptype':       'Shared',
+                'supportedservices': 'Connectivity,Dhcp,UserData,SourceNat,StaticNat,Lb,PortForwarding',
+                'traffictype':       'GUEST',
+                'availability':      'Optional',
+                'specifyVlan':        'true',
+                'specifyIpRanges':    'true',
+                'serviceProviderList': {
+                        'Connectivity':   'NiciraNvp',
+                        'Dhcp':           'VirtualRouter',
+                        'SourceNat':      'VirtualRouter',
+                        'StaticNat':      'VirtualRouter',
+                        'Lb':             'VirtualRouter',
+                        'PortForwarding': 'VirtualRouter',
+                        'UserData':       'VirtualRouter'
+                }
+            }
+        ]
 
         cls.network_offering_isolated = NetworkOffering.create(cls.api_client, cls.network_offerring_services[0])
         cls.network_offering_isolated.update(cls.api_client, state='Enabled')
 
         cls.network_offering_shared = NetworkOffering.create(cls.api_client, cls.network_offerring_services[1])
         cls.network_offering_shared.update(cls.api_client, state='Enabled')
-		
-        cls.ip_ranges_shared = cls.config.zones[0].ipranges[0]
 
         cls.nicira_credentials = {
             'username': 'admin',
@@ -117,7 +137,9 @@ class TestNiciraContoller(cloudstackTestCase):
             cls.nicira_credentials
         )
 
-        cls.domain = get_domain(cls.api_client)
+        cls.admin_account   = 'admin'
+        cls.admin_domain    = get_domain(cls.api_client)
+
         cls.zone   = get_zone(cls.api_client, test_client.getZoneForTests())
 
         template = get_template(
@@ -148,7 +170,7 @@ class TestNiciraContoller(cloudstackTestCase):
                     'cpunumber':   1,
                     'cpuspeed':    100,
                     'memory':      64,
-					'offerha':		'true'
+                    'offerha':     'true'
                 }
             }
         }
@@ -164,7 +186,7 @@ class TestNiciraContoller(cloudstackTestCase):
         cls.cleanup = [
             cls.network_offering_isolated,
             cls.service_offering,
-			cls.network_offering_shared
+            cls.network_offering_shared
         ]
 
         cls.logger = logging.getLogger('TestNiciraContoller')
@@ -246,18 +268,7 @@ class TestNiciraContoller(cloudstackTestCase):
             raise Exception("None of the supplied hosts (%s) is a Nicira slave" % hosts)
 
 
-    def add_nicira_device(self, hostname):
-        nicira_device = NiciraNvp.add(
-            self.api_client,
-            None,
-            self.physical_network_id,
-            hostname=hostname,
-            username=self.nicira_credentials['username'],
-            password=self.nicira_credentials['password'],
-            transportzoneuuid=self.transport_zone_uuid)
-        self.test_cleanup.append(nicira_device)
-
-    def add_nicira_device_l2gateway(self, hostname):
+    def add_nicira_device(self, hostname, l2gatewayserviceuuid=None):
         nicira_device = NiciraNvp.add(
             self.api_client,
             None,
@@ -266,7 +277,8 @@ class TestNiciraContoller(cloudstackTestCase):
             username=self.nicira_credentials['username'],
             password=self.nicira_credentials['password'],
             transportzoneuuid=self.transport_zone_uuid,
-            l2gatewayserviceuuid=self.l2gatewayserviceuuid)
+            l2gatewayserviceuuid=l2gatewayserviceuuid
+        )
         self.test_cleanup.append(nicira_device)
 
     def create_guest_isolated_network(self):
@@ -279,8 +291,8 @@ class TestNiciraContoller(cloudstackTestCase):
         network = Network.create(
             self.api_client,
             network_services,
-            accountid='admin',
-            domainid=self.domain.id,
+            accountid=self.admin_account,
+            domainid=self.admin_domain.id
         )
         self.test_cleanup.append(network)
         return network
@@ -291,17 +303,17 @@ class TestNiciraContoller(cloudstackTestCase):
             'displaytext'     : 'nicira_enabled_network_shared',
             'zoneid'          : self.zone.id,
             'networkoffering' : self.network_offering_shared.id,
-			'startip'			: self.ip_ranges_shared.startip,
-			'endip'				: self.ip_ranges_shared.endip,
-			'netmask'			: self.ip_ranges_shared.netmask,
-			'gateway'			: self.ip_ranges_shared.gateway
+            'startip'         : self.nicira_shared_network_iprange.startip,
+            'endip'           : self.nicira_shared_network_iprange.endip,
+            'netmask'         : self.nicira_shared_network_iprange.netmask,
+            'gateway'         : self.nicira_shared_network_iprange.gateway,
+            'vlan'            : self.nicira_shared_network_iprange.vlan
         }
         network = Network.create(
             self.api_client,
             network_services,
-            accountid='admin',
-            domainid=self.domain.id,
-			vlan=self.ip_ranges_shared.vlan
+            accountid=self.admin_account,
+            domainid=self.admin_domain.id
         )
         self.test_cleanup.append(network)
         return network
@@ -312,17 +324,17 @@ class TestNiciraContoller(cloudstackTestCase):
             'displaytext'     : 'nicira_enabled_network_shared',
             'zoneid'          : self.zone.id,
             'networkoffering' : self.network_offering_shared.id,
-			'startip'			: self.ip_ranges_shared.startip,
-			'endip'				: self.ip_ranges_shared.endip,
-			'netmask'			: self.ip_ranges_shared.netmask,
-			'gateway'			: self.ip_ranges_shared.gateway
+            'startip'         : self.nicira_shared_network_iprange.startip,
+            'endip'           : self.nicira_shared_network_iprange.endip,
+            'netmask'         : self.nicira_shared_network_iprange.netmask,
+            'gateway'         : self.nicira_shared_network_iprange.gateway,
+            'vlan'            : self.nicira_shared_network_iprange.vlan_uuid
         }
         network = Network.create(
             self.api_client,
             network_services,
-            accountid='admin',
-            domainid=self.domain.id,
-			vlan=self.ip_ranges_shared.vlan_uuid
+            accountid=self.admin_account,
+            domainid=self.admin_domain.id
         )
         self.test_cleanup.append(network)
         return network
@@ -333,16 +345,16 @@ class TestNiciraContoller(cloudstackTestCase):
             'displaytext'     : 'nicira_enabled_network_shared',
             'zoneid'          : self.zone.id,
             'networkoffering' : self.network_offering_shared.id,
-			'startip'			: self.ip_ranges_shared.startip,
-			'endip'				: self.ip_ranges_shared.endip,
-			'netmask'			: self.ip_ranges_shared.netmask,
-			'gateway'			: self.ip_ranges_shared.gateway
+            'startip'         : self.nicira_shared_network_iprange.startip,
+            'endip'           : self.nicira_shared_network_iprange.endip,
+            'netmask'         : self.nicira_shared_network_iprange.netmask,
+            'gateway'         : self.nicira_shared_network_iprange.gateway
         }
         network = Network.create(
             self.api_client,
             network_services,
-            accountid='admin',
-            domainid=self.domain.id,
+            accountid=self.admin_account,
+            domainid=self.admin_domain.id,
         )
         self.test_cleanup.append(network)
         return network
@@ -352,8 +364,8 @@ class TestNiciraContoller(cloudstackTestCase):
         virtual_machine = VirtualMachine.create(
             self.api_client,
             self.vm_services['small'],
-            accountid='admin',
-            domainid=self.domain.id,
+            accountid=self.admin_account,
+            domainid=self.admin_domain.id,
             serviceofferingid=self.service_offering.id,
             networkids=[network.id],
             mode=self.vm_services['mode']
@@ -365,8 +377,8 @@ class TestNiciraContoller(cloudstackTestCase):
         virtual_machine = VirtualMachine.create(
             self.api_client,
             self.vm_services['small'],
-            accountid='admin',
-            domainid=self.domain.id,
+            accountid=self.admin_account,
+            domainid=self.admin_domain.id,
             serviceofferingid=self.service_offering.id,
             networkids=[network.id],
             mode='BASIC'
@@ -378,8 +390,8 @@ class TestNiciraContoller(cloudstackTestCase):
     def get_routers_for_network(self, network):
         return list_routers(
             self.api_client,
-            account='admin',
-            domainid=self.domain.id,
+            accountid=self.admin_account,
+            domainid=self.admin_domain.id,
             networkid=network.id
         )
 
@@ -387,8 +399,8 @@ class TestNiciraContoller(cloudstackTestCase):
     def get_hosts(self):
         return list_hosts(
             self.api_client,
-            account='admin',
-            domainid=self.domain.id
+            accountid=self.admin_account,
+            domainid=self.admin_domain.id
         )
 
 
@@ -421,9 +433,9 @@ class TestNiciraContoller(cloudstackTestCase):
         self.logger.debug("Associating public IP for network: %s" % network.name)
         public_ip = PublicIPAddress.create(
             self.api_client,
-            accountid='admin',
+            accountid=self.admin_account,
             zoneid=self.zone.id,
-            domainid=self.domain.id,
+            domainid=self.admin_domain.id,
             networkid=network.id
         )
         self.logger.debug("Associated %s with network %s" % (public_ip.ipaddress.ipaddress, network.id))
@@ -536,10 +548,10 @@ class TestNiciraContoller(cloudstackTestCase):
             CASE 1) Numerical VLAN_ID provided in network creation
         """
         self.debug("Starting test case 1 for Shared Networks")
-        self.add_nicira_device_l2gateway(self.nicira_master_controller)
+        self.add_nicira_device(self.nicira_master_controller, self.l2gatewayserviceuuid)
         network = self.create_guest_shared_network_numerical_vlanid()
         virtual_machine = self.create_virtual_machine_shared_networks(network)
-		
+
         list_vm_response = VirtualMachine.list(self.api_client, id=virtual_machine.id)
         self.debug("Verify listVirtualMachines response for virtual machine: %s" % virtual_machine.id)
 
@@ -557,10 +569,10 @@ class TestNiciraContoller(cloudstackTestCase):
             CASE 2) Logical Router's UUID as VLAN_ID provided in network creation
         """
         self.debug("Starting test case 2 for Shared Networks")
-        self.add_nicira_device_l2gateway(self.nicira_master_controller)
+        self.add_nicira_device(self.nicira_master_controller, self.l2gatewayserviceuuid)
         network = self.create_guest_shared_network_uuid_vlanid()
         virtual_machine = self.create_virtual_machine_shared_networks(network)
-		
+
         list_vm_response = VirtualMachine.list(self.api_client, id=virtual_machine.id)
         self.debug("Verify listVirtualMachines response for virtual machine: %s" % virtual_machine.id)
 
@@ -569,4 +581,4 @@ class TestNiciraContoller(cloudstackTestCase):
 
         vm_response = list_vm_response[0]
         self.assertEqual(vm_response.id, virtual_machine.id, 'Virtual machine in response does not match request')
-        self.assertEqual(vm_response.state, 'Running', 'VM is not in Running state')
\ No newline at end of file
+        self.assertEqual(vm_response.state, 'Running', 'VM is not in Running state')


[04/16] git commit: updated refs/heads/master to 67b753c

Posted by re...@apache.org.
CLOUDSTACK-9074: API Changes: Add nsxLogicalSwitch and nsxLogicalSwitchPort to listNics


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/81490816
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/81490816
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/81490816

Branch: refs/heads/master
Commit: 8149081658738a2d4d9ee088241310460b2d9077
Parents: 46f9fba
Author: nvazquez <ni...@gmail.com>
Authored: Tue Dec 1 11:48:27 2015 -0800
Committer: nvazquez <ni...@gmail.com>
Committed: Thu Dec 24 16:07:06 2015 -0300

----------------------------------------------------------------------
 .../cloudstack/api/response/NicResponse.java    | 16 ++++++++++++++
 engine/schema/src/com/cloud/vm/NicVO.java       | 23 ++++++++++++++++++++
 .../cloud/network/nicira/NiciraRestClient.java  |  6 +++--
 server/src/com/cloud/api/ApiResponseHelper.java |  9 ++++++++
 .../cloud/utils/rest/HttpStatusCodeHelper.java  |  4 ++++
 5 files changed, 56 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/81490816/api/src/org/apache/cloudstack/api/response/NicResponse.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/response/NicResponse.java b/api/src/org/apache/cloudstack/api/response/NicResponse.java
index 2f79d7f..7335836 100644
--- a/api/src/org/apache/cloudstack/api/response/NicResponse.java
+++ b/api/src/org/apache/cloudstack/api/response/NicResponse.java
@@ -102,6 +102,14 @@ public class NicResponse extends BaseResponse {
     @Param(description = "Id of the vm to which the nic belongs")
     private String vmId;
 
+    @SerializedName("nsxlogicalswitch")
+    @Param(description = "Id of the NSX Logical Switch (if NSX based), null otherwise", since="4.6.0")
+    private String nsxLogicalSwitch;
+
+    @SerializedName("nsxlogicalswitchport")
+    @Param(description = "Id of the NSX Logical Switch Port (if NSX based), null otherwise", since="4.6.0")
+    private String nsxLogicalSwitchPort;
+
     public void setVmId(String vmId) {
         this.vmId = vmId;
     }
@@ -205,4 +213,12 @@ public class NicResponse extends BaseResponse {
         this.secondaryIps = ipList;
     }
 
+    public void setNsxLogicalSwitch(String nsxLogicalSwitch) {
+        this.nsxLogicalSwitch = nsxLogicalSwitch;
+    }
+
+    public void setNsxLogicalSwitchPort(String nsxLogicalSwitchPort) {
+        this.nsxLogicalSwitchPort = nsxLogicalSwitchPort;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/81490816/engine/schema/src/com/cloud/vm/NicVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/vm/NicVO.java b/engine/schema/src/com/cloud/vm/NicVO.java
index 8154297..2a7c696 100644
--- a/engine/schema/src/com/cloud/vm/NicVO.java
+++ b/engine/schema/src/com/cloud/vm/NicVO.java
@@ -28,6 +28,7 @@ import javax.persistence.GeneratedValue;
 import javax.persistence.GenerationType;
 import javax.persistence.Id;
 import javax.persistence.Table;
+import javax.persistence.Transient;
 
 import com.cloud.network.Networks.AddressFormat;
 import com.cloud.network.Networks.Mode;
@@ -123,6 +124,12 @@ public class NicVO implements Nic {
     @Column(name = "secondary_ip")
     boolean secondaryIp;
 
+    @Transient
+    transient String nsxLogicalSwitchUuid;
+
+    @Transient
+    transient String nsxLogicalSwitchPortUuid;
+
     public NicVO(String reserver, Long instanceId, long configurationId, VirtualMachine.Type vmType) {
         this.reserver = reserver;
         this.instanceId = instanceId;
@@ -371,4 +378,20 @@ public class NicVO implements Nic {
     public void setVmType(VirtualMachine.Type vmType) {
         this.vmType = vmType;
     }
+
+    public String getNsxLogicalSwitchUuid() {
+        return nsxLogicalSwitchUuid;
+    }
+
+    public void setNsxLogicalSwitchUuid(String nsxLogicalSwitchUuid) {
+        this.nsxLogicalSwitchUuid = nsxLogicalSwitchUuid;
+    }
+
+    public String getNsxLogicalSwitchPortUuid() {
+        return nsxLogicalSwitchPortUuid;
+    }
+
+    public void setNsxLogicalSwitchPortUuid(String nsxLogicalSwitchPortUuid) {
+        this.nsxLogicalSwitchPortUuid = nsxLogicalSwitchPortUuid;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/81490816/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraRestClient.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraRestClient.java b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraRestClient.java
index de58a42..b850c4b 100644
--- a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraRestClient.java
+++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/NiciraRestClient.java
@@ -91,8 +91,10 @@ public class NiciraRestClient extends BasicRestClient {
             return handleUnauthorizedResponse(request, previousStatusCode, response, statusCode);
         } else if (HttpStatusCodeHelper.isSuccess(statusCode)) {
             return handleSuccessResponse(request, response);
+        } else if (HttpStatusCodeHelper.isConflict(statusCode)) {
+            throw new CloudstackRESTException("Conflict: " + statusLine.getReasonPhrase());
         } else {
-            throw new CloudstackRESTException("Unexpecetd status code: " + statusCode);
+            throw new CloudstackRESTException("Unexpected status code: " + statusCode);
         }
     }
 
@@ -201,4 +203,4 @@ public class NiciraRestClient extends BasicRestClient {
         }
 
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/81490816/server/src/com/cloud/api/ApiResponseHelper.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/ApiResponseHelper.java b/server/src/com/cloud/api/ApiResponseHelper.java
index 5d691c6..8c9e437 100644
--- a/server/src/com/cloud/api/ApiResponseHelper.java
+++ b/server/src/com/cloud/api/ApiResponseHelper.java
@@ -3467,6 +3467,15 @@ public class ApiResponseHelper implements ResponseGenerator {
         response.setDeviceId(String.valueOf(result.getDeviceId()));
 
         response.setIsDefault(result.isDefaultNic());
+
+        if (result instanceof NicVO){
+            if (((NicVO)result).getNsxLogicalSwitchUuid() != null){
+                response.setNsxLogicalSwitch(((NicVO)result).getNsxLogicalSwitchUuid());
+            }
+            if (((NicVO)result).getNsxLogicalSwitchPortUuid() != null){
+                response.setNsxLogicalSwitchPort(((NicVO)result).getNsxLogicalSwitchPortUuid());
+            }
+        }
         return response;
     }
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/81490816/utils/src/main/java/com/cloud/utils/rest/HttpStatusCodeHelper.java
----------------------------------------------------------------------
diff --git a/utils/src/main/java/com/cloud/utils/rest/HttpStatusCodeHelper.java b/utils/src/main/java/com/cloud/utils/rest/HttpStatusCodeHelper.java
index 9492920..98c88ba 100644
--- a/utils/src/main/java/com/cloud/utils/rest/HttpStatusCodeHelper.java
+++ b/utils/src/main/java/com/cloud/utils/rest/HttpStatusCodeHelper.java
@@ -31,4 +31,8 @@ public class HttpStatusCodeHelper {
         return statusCode == HttpStatus.SC_UNAUTHORIZED;
     }
 
+    public static boolean isConflict(final int statusCode){
+        return statusCode == HttpStatus.SC_CONFLICT;
+    }
+
 }


[05/16] git commit: updated refs/heads/master to 67b753c

Posted by re...@apache.org.
CLOUDSTACK-9074: New NiciraNVP classes to support Shared Networks


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/06d5b46e
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/06d5b46e
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/06d5b46e

Branch: refs/heads/master
Commit: 06d5b46e538ba4d1a88995bff4aef5fe2e5275e7
Parents: 8149081
Author: nvazquez <ni...@gmail.com>
Authored: Tue Dec 1 11:50:52 2015 -0800
Committer: nvazquez <ni...@gmail.com>
Committed: Thu Dec 24 16:07:06 2015 -0300

----------------------------------------------------------------------
 .../guru/NetworkGuruAdditionalFunctions.java    |  12 ++
 .../api/ConfigureSharedNetworkUuidAnswer.java   |  32 +++
 .../api/ConfigureSharedNetworkUuidCommand.java  |  85 ++++++++
 .../api/ConfigureSharedNetworkVlanIdAnswer.java |  31 +++
 .../ConfigureSharedNetworkVlanIdCommand.java    |  84 ++++++++
 .../network/nicira/L2GatewayAttachment.java     |  53 +++++
 ...onfigureSharedNetworkUuidCommandWrapper.java | 196 +++++++++++++++++++
 ...figureSharedNetworkVlanIdCommandWrapper.java | 118 +++++++++++
 8 files changed, 611 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/06d5b46e/api/src/com/cloud/network/guru/NetworkGuruAdditionalFunctions.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/network/guru/NetworkGuruAdditionalFunctions.java b/api/src/com/cloud/network/guru/NetworkGuruAdditionalFunctions.java
new file mode 100644
index 0000000..43a1871
--- /dev/null
+++ b/api/src/com/cloud/network/guru/NetworkGuruAdditionalFunctions.java
@@ -0,0 +1,12 @@
+package com.cloud.network.guru;
+
+import java.util.Map;
+
+public interface NetworkGuruAdditionalFunctions {
+
+    public static final String NSX_LSWITCH_UUID = "logicalswitch";
+    public static final String NSX_LSWITCHPORT_UUID = "logicalswitchport";
+
+    void finalizeNetworkDesign(long networkId, String vlanIdAsUUID);
+    Map<String, ? extends Object> listAdditionalNicParams(String nicUuid);
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/06d5b46e/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/agent/api/ConfigureSharedNetworkUuidAnswer.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/agent/api/ConfigureSharedNetworkUuidAnswer.java b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/agent/api/ConfigureSharedNetworkUuidAnswer.java
new file mode 100644
index 0000000..46fc8f5
--- /dev/null
+++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/agent/api/ConfigureSharedNetworkUuidAnswer.java
@@ -0,0 +1,32 @@
+//
+// 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.agent.api;
+
+public class ConfigureSharedNetworkUuidAnswer extends Answer {
+
+    public ConfigureSharedNetworkUuidAnswer(final Command command, final boolean success, final String details) {
+        super(command, success, details);
+    }
+
+    public ConfigureSharedNetworkUuidAnswer(final Command command, final Exception e) {
+        super(command, e);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/06d5b46e/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/agent/api/ConfigureSharedNetworkUuidCommand.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/agent/api/ConfigureSharedNetworkUuidCommand.java b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/agent/api/ConfigureSharedNetworkUuidCommand.java
new file mode 100644
index 0000000..4dd361b
--- /dev/null
+++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/agent/api/ConfigureSharedNetworkUuidCommand.java
@@ -0,0 +1,85 @@
+//
+// 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.agent.api;
+
+public class ConfigureSharedNetworkUuidCommand extends Command {
+
+    private String logicalRouterUuid;
+    private String logicalSwitchUuid;
+    private String portIpAddress;
+    private String ownerName;
+    private long networkId;
+
+    public ConfigureSharedNetworkUuidCommand(final String logicalRouterUuid, final String logicalSwitchUuid,
+            final String portIpAddress, final String ownerName, final long networkId) {
+        super();
+        this.logicalRouterUuid = logicalRouterUuid;
+        this.logicalSwitchUuid = logicalSwitchUuid;
+        this.portIpAddress = portIpAddress;
+        this.ownerName = ownerName;
+        this.networkId = networkId;
+    }
+
+    @Override
+    public boolean executeInSequence() {
+        return false;
+    }
+
+    public String getLogicalRouterUuid() {
+        return logicalRouterUuid;
+    }
+
+    public void setLogicalRouterUuid(String logicalRouterUuid) {
+        this.logicalRouterUuid = logicalRouterUuid;
+    }
+
+    public String getLogicalSwitchUuid() {
+        return logicalSwitchUuid;
+    }
+
+    public void setLogicalSwitchUuid(String logicalSwitchUuid) {
+        this.logicalSwitchUuid = logicalSwitchUuid;
+    }
+
+    public String getPortIpAddress() {
+        return portIpAddress;
+    }
+
+    public void setPortIpAddress(String portIpAddress) {
+        this.portIpAddress = portIpAddress;
+    }
+
+    public String getOwnerName() {
+        return ownerName;
+    }
+
+    public void setOwnerName(String ownerName) {
+        this.ownerName = ownerName;
+    }
+
+    public long getNetworkId() {
+        return networkId;
+    }
+
+    public void setNetworkId(long networkId) {
+        this.networkId = networkId;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/06d5b46e/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/agent/api/ConfigureSharedNetworkVlanIdAnswer.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/agent/api/ConfigureSharedNetworkVlanIdAnswer.java b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/agent/api/ConfigureSharedNetworkVlanIdAnswer.java
new file mode 100644
index 0000000..1295569
--- /dev/null
+++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/agent/api/ConfigureSharedNetworkVlanIdAnswer.java
@@ -0,0 +1,31 @@
+//
+// 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.agent.api;
+
+public class ConfigureSharedNetworkVlanIdAnswer extends Answer {
+
+    public ConfigureSharedNetworkVlanIdAnswer(final Command command, final boolean success, final String details) {
+        super(command, success, details);
+    }
+
+    public ConfigureSharedNetworkVlanIdAnswer(final Command command, final Exception e) {
+        super(command, e);
+    }
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/06d5b46e/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/agent/api/ConfigureSharedNetworkVlanIdCommand.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/agent/api/ConfigureSharedNetworkVlanIdCommand.java b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/agent/api/ConfigureSharedNetworkVlanIdCommand.java
new file mode 100644
index 0000000..c6837dd
--- /dev/null
+++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/agent/api/ConfigureSharedNetworkVlanIdCommand.java
@@ -0,0 +1,84 @@
+//
+// 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.agent.api;
+
+public class ConfigureSharedNetworkVlanIdCommand extends Command {
+
+    private String logicalSwitchUuid;
+    private String l2GatewayServiceUuid;
+    private long vlanId;
+    private String ownerName;
+    private long networkId;
+
+    public ConfigureSharedNetworkVlanIdCommand(final String logicalSwitchUuid, final String l2GatewayServiceUuid,
+            final long vlanId, final String ownerName, final long networkId) {
+        this.logicalSwitchUuid = logicalSwitchUuid;
+        this.l2GatewayServiceUuid = l2GatewayServiceUuid;
+        this.vlanId = vlanId;
+        this.ownerName = ownerName;
+        this.networkId = networkId;
+    }
+
+    @Override
+    public boolean executeInSequence() {
+        return false;
+    }
+
+    public String getLogicalSwitchUuid() {
+        return logicalSwitchUuid;
+    }
+
+    public void setLogicalSwitchUuid(String logicalSwitchUuid) {
+        this.logicalSwitchUuid = logicalSwitchUuid;
+    }
+
+    public String getL2GatewayServiceUuid() {
+        return l2GatewayServiceUuid;
+    }
+
+    public void setL2GatewayServiceUuid(String l2GatewayServiceUuid) {
+        this.l2GatewayServiceUuid = l2GatewayServiceUuid;
+    }
+
+    public long getVlanId() {
+        return vlanId;
+    }
+
+    public void setVlanId(long vlanId) {
+        this.vlanId = vlanId;
+    }
+
+    public String getOwnerName() {
+        return ownerName;
+    }
+
+    public void setOwnerName(String ownerName) {
+        this.ownerName = ownerName;
+    }
+
+    public long getNetworkId() {
+        return networkId;
+    }
+
+    public void setNetworkId(long networkId) {
+        this.networkId = networkId;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/06d5b46e/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/L2GatewayAttachment.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/L2GatewayAttachment.java b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/L2GatewayAttachment.java
new file mode 100644
index 0000000..2ef294e
--- /dev/null
+++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/nicira/L2GatewayAttachment.java
@@ -0,0 +1,53 @@
+//
+// 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.nicira;
+
+public class L2GatewayAttachment extends Attachment {
+
+    private String l2GatewayServiceUuid;
+    private final String type = "L2GatewayAttachment";
+    private Long vlanId;
+
+    public L2GatewayAttachment(String l2GatewayServiceUuid) {
+        this.l2GatewayServiceUuid = l2GatewayServiceUuid;
+    }
+
+    public L2GatewayAttachment(final String l2GatewayServiceUuid, final long vlanId) {
+        this.l2GatewayServiceUuid = l2GatewayServiceUuid;
+        this.vlanId = vlanId;
+    }
+
+    public String getL2GatewayServiceUuid() {
+        return l2GatewayServiceUuid;
+    }
+    public void setL2GatewayServiceUuid(String l2GatewayServiceUuid) {
+        this.l2GatewayServiceUuid = l2GatewayServiceUuid;
+    }
+    public Long getVlanId() {
+        return vlanId;
+    }
+    public void setVlanId(Long vlanId) {
+        this.vlanId = vlanId;
+    }
+    public String getType() {
+        return type;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/06d5b46e/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraNvpConfigureSharedNetworkUuidCommandWrapper.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraNvpConfigureSharedNetworkUuidCommandWrapper.java b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraNvpConfigureSharedNetworkUuidCommandWrapper.java
new file mode 100644
index 0000000..3a1d2cb
--- /dev/null
+++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraNvpConfigureSharedNetworkUuidCommandWrapper.java
@@ -0,0 +1,196 @@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+
+package com.cloud.network.resource.wrapper;
+
+import static com.cloud.network.resource.NiciraNvpResource.NAME_MAX_LEN;
+import static com.cloud.network.resource.NiciraNvpResource.NUM_RETRIES;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+
+import com.cloud.agent.api.Answer;
+import com.cloud.agent.api.ConfigureSharedNetworkUuidAnswer;
+import com.cloud.agent.api.ConfigureSharedNetworkUuidCommand;
+import com.cloud.network.nicira.LogicalRouterPort;
+import com.cloud.network.nicira.LogicalSwitch;
+import com.cloud.network.nicira.LogicalSwitchPort;
+import com.cloud.network.nicira.NiciraNvpApi;
+import com.cloud.network.nicira.NiciraNvpApiException;
+import com.cloud.network.nicira.NiciraNvpTag;
+import com.cloud.network.nicira.PatchAttachment;
+import com.cloud.network.resource.NiciraNvpResource;
+import com.cloud.network.utils.CommandRetryUtility;
+import com.cloud.resource.CommandWrapper;
+import com.cloud.resource.ResourceWrapper;
+import com.cloud.utils.exception.CloudRuntimeException;
+import com.cloud.utils.rest.HttpStatusCodeHelper;
+
+@ResourceWrapper(handles =  ConfigureSharedNetworkUuidCommand.class)
+public final class NiciraNvpConfigureSharedNetworkUuidCommandWrapper extends CommandWrapper<ConfigureSharedNetworkUuidCommand, Answer, NiciraNvpResource>{
+
+    private static final Logger s_logger = Logger.getLogger(NiciraNvpConfigureSharedNetworkUuidCommandWrapper.class);
+
+    @Override
+    public Answer execute(ConfigureSharedNetworkUuidCommand command, NiciraNvpResource niciraNvpResource) {
+        final String logicalRouterUuid = command.getLogicalRouterUuid();
+        final String logicalSwitchUuid = command.getLogicalSwitchUuid();
+        final String portIpAddress = command.getPortIpAddress();
+        final List<NiciraNvpTag> tags = new ArrayList<NiciraNvpTag>();
+        tags.add(new NiciraNvpTag("cs_account", command.getOwnerName()));
+        final long networkId = command.getNetworkId();
+
+        final NiciraNvpApi niciraNvpApi = niciraNvpResource.getNiciraNvpApi();
+
+        s_logger.debug("Attaching Logical Switch " + logicalSwitchUuid + " on Logical Router " + logicalRouterUuid + " for Shared Network " + networkId);
+
+        //Step 1: Get lSwitch displayName
+        s_logger.info("Looking for Logical Switch " + logicalSwitchUuid + " display name");
+        String logicalSwitchDisplayName;
+        try{
+            List<LogicalSwitch> lSwitchList = niciraNvpApi.findLogicalSwitch(logicalSwitchUuid);
+            if (lSwitchList != null){
+                if (lSwitchList.size() == 1){
+                    logicalSwitchDisplayName = lSwitchList.get(0).getDisplayName();
+                }
+                else {
+                    s_logger.error("More than one Logical Switch found with uuid " + logicalSwitchUuid);
+                    throw new CloudRuntimeException("More than one Logical Switch found with uuid=" + logicalSwitchUuid);
+                }
+            }
+            else {
+                s_logger.error("Logical Switch " + logicalSwitchUuid + " not found");
+                throw new CloudRuntimeException("Logical Switch " + logicalSwitchUuid + " not found");
+            }
+        }
+        catch (NiciraNvpApiException e){
+            s_logger.warn("Logical Switch " + logicalSwitchUuid + " not found, retrying");
+            final CommandRetryUtility retryUtility = niciraNvpResource.getRetryUtility();
+            retryUtility.addRetry(command, NUM_RETRIES);
+            return retryUtility.retry(command, ConfigureSharedNetworkUuidAnswer.class, e);
+        }
+        catch (CloudRuntimeException e){
+            s_logger.info("Shared network UUID vlan id failed due to : " + e.getMessage());
+            return new ConfigureSharedNetworkUuidAnswer(command, false, e.getMessage());
+        }
+        s_logger.info("Found display name " + logicalSwitchDisplayName + " for Logical Switch " + logicalSwitchUuid);
+
+
+        //Step 2: Create lRouterPort
+        s_logger.debug("Creating Logical Router Port in Logical Router " + logicalRouterUuid);
+        LogicalRouterPort lRouterPort = null;
+        try {
+            lRouterPort = new LogicalRouterPort();
+            lRouterPort.setAdminStatusEnabled(true);
+            lRouterPort.setDisplayName(niciraNvpResource.truncate(logicalSwitchDisplayName + "-uplink", NAME_MAX_LEN));
+            lRouterPort.setTags(tags);
+            final List<String> ipAddresses = new ArrayList<String>();
+            ipAddresses.add(portIpAddress);
+            lRouterPort.setIpAddresses(ipAddresses);
+            lRouterPort = niciraNvpApi.createLogicalRouterPort(logicalRouterUuid, lRouterPort);
+        }
+        catch (NiciraNvpApiException e){
+            s_logger.warn("Could not create Logical Router Port on Logical Router " + logicalRouterUuid + " due to: " + e.getMessage() + ", retrying");
+            return handleException(e, command, niciraNvpResource);
+        }
+        s_logger.debug("Logical Router Port " + lRouterPort.getUuid() + " (" + lRouterPort.getDisplayName() + ") successfully created in Logical Router " + logicalRouterUuid);
+
+
+        //Step 3: Create lSwitchPort
+        s_logger.debug("Creating Logical Switch Port in Logical Switch " + logicalSwitchUuid + " (" + logicalSwitchDisplayName + ")");
+        LogicalSwitchPort lSwitchPort = null;
+        try {
+            lSwitchPort = new LogicalSwitchPort(niciraNvpResource.truncate("lrouter-uplink", NAME_MAX_LEN), tags, true);
+            lSwitchPort = niciraNvpApi.createLogicalSwitchPort(logicalSwitchUuid, lSwitchPort);
+        }
+        catch (NiciraNvpApiException e){
+            s_logger.warn("Could not create Logical Switch Port on Logical Switch " + logicalSwitchUuid + " (" + logicalSwitchDisplayName + ")  due to: " + e.getMessage());
+            cleanupLRouterPort(logicalRouterUuid, lRouterPort, niciraNvpApi);
+            return handleException(e, command, niciraNvpResource);
+        }
+        s_logger.debug("Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") successfully created in Logical Switch " + logicalSwitchUuid + " (" + logicalSwitchDisplayName + ")");
+
+
+        //Step 4: Attach lRouterPort to lSwitchPort with a PatchAttachment
+        s_logger.debug("Attaching Logical Router Port " + lRouterPort.getUuid() + " (" + lRouterPort.getDisplayName() + ") to Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") with a PatchAttachment");
+        try {
+            niciraNvpApi.updateLogicalRouterPortAttachment(logicalRouterUuid, lRouterPort.getUuid(), new PatchAttachment(lSwitchPort.getUuid()));
+        }
+        catch (NiciraNvpApiException e) {
+            s_logger.warn("Could not attach Logical Router Port " + lRouterPort.getUuid() + " (" + lRouterPort.getDisplayName() + ") to Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") due to: " + e.getMessage() + ", retrying");
+            cleanupLRouterPort(logicalRouterUuid, lRouterPort, niciraNvpApi);
+            cleanupLSwitchPort(logicalSwitchUuid, lSwitchPort, niciraNvpApi);
+            return handleException(e, command, niciraNvpResource);
+        }
+        s_logger.debug("Logical Router Port " + lRouterPort.getUuid() + " (" + lRouterPort.getDisplayName() + ") successfully attached to to Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") with a PatchAttachment");
+
+
+        //Step 5: Attach lSwitchPort to lRouterPort with a PatchAttachment
+        s_logger.debug("Attaching Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") to Logical Router Port " + lRouterPort.getUuid() + " (" + lRouterPort.getDisplayName() + ") with a PatchAttachment");
+        try {
+            niciraNvpApi.updateLogicalSwitchPortAttachment(logicalSwitchUuid, lSwitchPort.getUuid(), new PatchAttachment(lRouterPort.getUuid()));
+        }
+        catch (NiciraNvpApiException e){
+            s_logger.warn("Could not attach Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") to Logical Router Port " + lRouterPort.getUuid() + " (" + lRouterPort.getDisplayName() + ") due to: " + e.getMessage() + ", retrying");
+            cleanupLRouterPort(logicalRouterUuid, lRouterPort, niciraNvpApi);
+            cleanupLSwitchPort(logicalSwitchUuid, lSwitchPort, niciraNvpApi);
+            return handleException(e, command, niciraNvpResource);
+        }
+        s_logger.debug("Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") successfully attached to to Logical Router Port " + lRouterPort.getUuid() + " (" + lRouterPort.getDisplayName() + ") with a PatchAttachment");
+
+        s_logger.info("Successfully attached Logical Switch " + logicalSwitchUuid + " on Logical Router " + logicalRouterUuid + " for Shared Network " + networkId);
+        return new ConfigureSharedNetworkUuidAnswer(command, true, "OK");
+    }
+
+    private void cleanupLSwitchPort(String logicalSwitchUuid, LogicalSwitchPort lSwitchPort, NiciraNvpApi niciraNvpApi) {
+        s_logger.warn("Deleting previously created Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") from Logical Switch " + logicalSwitchUuid);
+        try {
+            niciraNvpApi.deleteLogicalSwitchPort(logicalSwitchUuid, lSwitchPort.getUuid());
+        } catch (NiciraNvpApiException exceptionDeleteLSwitchPort) {
+            s_logger.error("Error while deleting Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") from Logical Switch " + logicalSwitchUuid + " due to: " + exceptionDeleteLSwitchPort.getMessage());
+        }
+        s_logger.warn("Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") successfully deleted");
+    }
+
+    private void cleanupLRouterPort(String logicalRouterUuid, LogicalRouterPort lRouterPort, NiciraNvpApi niciraNvpApi) {
+        s_logger.warn("Deleting previously created Logical Router Port " + lRouterPort.getUuid() + " (" + lRouterPort.getDisplayName() + ") from Logical Router " + logicalRouterUuid + " and retrying");
+        try {
+            niciraNvpApi.deleteLogicalRouterPort(logicalRouterUuid, lRouterPort.getUuid());
+        } catch (NiciraNvpApiException exceptionDelete) {
+            s_logger.error("Error while deleting Logical Router Port " + lRouterPort.getUuid() + " (" + lRouterPort.getDisplayName() + ") from Logical Router " + logicalRouterUuid + " due to: " + exceptionDelete.getMessage());
+        }
+        s_logger.warn("Logical Router Port " + lRouterPort.getUuid() + " (" + lRouterPort.getDisplayName() + ") successfully deleted");
+    }
+
+    private Answer handleException(NiciraNvpApiException e, ConfigureSharedNetworkUuidCommand command, NiciraNvpResource niciraNvpResource) {
+        if (HttpStatusCodeHelper.isConflict(e.getErrorCode())){
+            s_logger.warn("There's been a conflict in NSX side, aborting implementation");
+            return new ConfigureSharedNetworkUuidAnswer(command, false, "FAILED: There's been a conflict in NSX side");
+        }
+        else {
+            s_logger.warn("Error code: " + e.getErrorCode() + ", retrying");
+            final CommandRetryUtility retryUtility = niciraNvpResource.getRetryUtility();
+            retryUtility.addRetry(command, NUM_RETRIES);
+            return retryUtility.retry(command, ConfigureSharedNetworkUuidAnswer.class, e);
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/06d5b46e/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraNvpConfigureSharedNetworkVlanIdCommandWrapper.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraNvpConfigureSharedNetworkVlanIdCommandWrapper.java b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraNvpConfigureSharedNetworkVlanIdCommandWrapper.java
new file mode 100644
index 0000000..4fa9876
--- /dev/null
+++ b/plugins/network-elements/nicira-nvp/src/main/java/com/cloud/network/resource/wrapper/NiciraNvpConfigureSharedNetworkVlanIdCommandWrapper.java
@@ -0,0 +1,118 @@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+
+package com.cloud.network.resource.wrapper;
+
+import static com.cloud.network.resource.NiciraNvpResource.NAME_MAX_LEN;
+import static com.cloud.network.resource.NiciraNvpResource.NUM_RETRIES;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+
+import com.cloud.agent.api.Answer;
+import com.cloud.agent.api.ConfigureSharedNetworkVlanIdAnswer;
+import com.cloud.agent.api.ConfigureSharedNetworkVlanIdCommand;
+import com.cloud.network.nicira.L2GatewayAttachment;
+import com.cloud.network.nicira.LogicalSwitchPort;
+import com.cloud.network.nicira.NiciraNvpApi;
+import com.cloud.network.nicira.NiciraNvpApiException;
+import com.cloud.network.nicira.NiciraNvpTag;
+import com.cloud.network.resource.NiciraNvpResource;
+import com.cloud.network.utils.CommandRetryUtility;
+import com.cloud.resource.CommandWrapper;
+import com.cloud.resource.ResourceWrapper;
+import com.cloud.utils.rest.HttpStatusCodeHelper;
+
+@ResourceWrapper(handles =  ConfigureSharedNetworkVlanIdCommand.class)
+public class NiciraNvpConfigureSharedNetworkVlanIdCommandWrapper extends CommandWrapper<ConfigureSharedNetworkVlanIdCommand, Answer, NiciraNvpResource>{
+
+    private static final Logger s_logger = Logger.getLogger(NiciraNvpConfigureSharedNetworkVlanIdCommandWrapper.class);
+
+    @Override
+    public Answer execute(ConfigureSharedNetworkVlanIdCommand command, NiciraNvpResource niciraNvpResource) {
+        final String logicalSwitchUuid = command.getLogicalSwitchUuid();
+        final String l2GatewayServiceUuid = command.getL2GatewayServiceUuid();
+        long vlanId = command.getVlanId();
+        final List<NiciraNvpTag> tags = new ArrayList<NiciraNvpTag>();
+        tags.add(new NiciraNvpTag("cs_account", command.getOwnerName()));
+        final long networkId = command.getNetworkId();
+
+        s_logger.debug("Connecting Logical Switch " + logicalSwitchUuid + " to L2 Gateway Service " + l2GatewayServiceUuid + ", vlan id " + vlanId + " network " + networkId);
+        final NiciraNvpApi niciraNvpApi = niciraNvpResource.getNiciraNvpApi();
+
+        s_logger.debug("Creating Logical Switch Port in Logical Switch " + logicalSwitchUuid);
+        LogicalSwitchPort lSwitchPort = null;
+        try {
+            lSwitchPort = new LogicalSwitchPort();
+            lSwitchPort.setAdminStatusEnabled(true);
+            lSwitchPort.setDisplayName(niciraNvpResource.truncate(networkId + "-l2Gateway-port", NAME_MAX_LEN));
+            lSwitchPort.setTags(tags);
+            lSwitchPort = niciraNvpApi.createLogicalSwitchPort(logicalSwitchUuid, lSwitchPort);
+        }
+        catch (NiciraNvpApiException e){
+            s_logger.warn("Could not create Logical Switch Port on Logical Switch " + logicalSwitchUuid + " due to: " + e.getMessage() + ", retrying");
+            return handleException(e, command, niciraNvpResource);
+        }
+        s_logger.debug("Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") successfully created in Logical Switch " + logicalSwitchUuid);
+
+        s_logger.debug("Attaching Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") on VLAN " + command.getVlanId() + " using L2GatewayAttachment");
+        try {
+            final L2GatewayAttachment attachment = new L2GatewayAttachment(l2GatewayServiceUuid);
+            if (command.getVlanId() != 0) {
+                attachment.setVlanId(command.getVlanId());
+            }
+            niciraNvpApi.updateLogicalSwitchPortAttachment(logicalSwitchUuid, lSwitchPort.getUuid(), attachment);
+        }
+        catch (NiciraNvpApiException e){
+            s_logger.warn("Could not attach Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") to Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") due to: " + e.getMessage() + ", errorCode: " + e.getErrorCode());
+            cleanup(logicalSwitchUuid, lSwitchPort, niciraNvpApi);
+            return handleException(e, command, niciraNvpResource);
+        }
+        s_logger.debug("Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") successfully attached on VLAN " + command.getVlanId() + " using L2GatewayAttachment");
+
+        s_logger.debug("Successfully connected Logical Switch " + logicalSwitchUuid + " to L2 Gateway Service " + l2GatewayServiceUuid + ", vlan id " + vlanId + ", network " + networkId + ", through Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ")");
+        return new ConfigureSharedNetworkVlanIdAnswer(command, true, "OK");
+    }
+
+    private void cleanup(String logicalSwitchUuid, LogicalSwitchPort lSwitchPort, NiciraNvpApi niciraNvpApi) {
+        s_logger.warn("Deleting previously created Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") from Logical Switch " + logicalSwitchUuid);
+        try {
+            niciraNvpApi.deleteLogicalSwitchPort(logicalSwitchUuid, lSwitchPort.getUuid());
+        } catch (NiciraNvpApiException exceptionDeleteLSwitchPort) {
+            s_logger.error("Error while deleting Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") from Logical Switch " + logicalSwitchUuid + " due to: " + exceptionDeleteLSwitchPort.getMessage());
+        }
+        s_logger.warn("Logical Switch Port " + lSwitchPort.getUuid() + " (" + lSwitchPort.getDisplayName() + ") successfully deteled");
+    }
+
+    private Answer handleException(NiciraNvpApiException e, ConfigureSharedNetworkVlanIdCommand command, NiciraNvpResource niciraNvpResource) {
+        if (HttpStatusCodeHelper.isConflict(e.getErrorCode())){
+            s_logger.warn("There's been a conflict in NSX side, aborting implementation");
+            return new ConfigureSharedNetworkVlanIdAnswer(command, false, "FAILED: There's been a conflict in NSX side");
+        }
+        else {
+            s_logger.warn("Error code: " + e.getErrorCode() + ", retrying");
+            final CommandRetryUtility retryUtility = niciraNvpResource.getRetryUtility();
+            retryUtility.addRetry(command, NUM_RETRIES);
+            return retryUtility.retry(command, ConfigureSharedNetworkVlanIdAnswer.class, e);
+        }
+    }
+
+}


[13/16] git commit: updated refs/heads/master to 67b753c

Posted by re...@apache.org.
Fix method call bugs when accessign non defined variables


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/acdc42cb
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/acdc42cb
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/acdc42cb

Branch: refs/heads/master
Commit: acdc42cb48f66e76f6337844f3409460da7631b1
Parents: f804c97
Author: Miguel Ferreira <mi...@me.com>
Authored: Thu Dec 24 11:11:00 2015 +0100
Committer: nvazquez <ni...@gmail.com>
Committed: Thu Dec 24 16:07:06 2015 -0300

----------------------------------------------------------------------
 test/integration/plugins/test_nicira_controller.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/acdc42cb/test/integration/plugins/test_nicira_controller.py
----------------------------------------------------------------------
diff --git a/test/integration/plugins/test_nicira_controller.py b/test/integration/plugins/test_nicira_controller.py
index b41c0e6..fd83f2b 100644
--- a/test/integration/plugins/test_nicira_controller.py
+++ b/test/integration/plugins/test_nicira_controller.py
@@ -214,7 +214,7 @@ class TestNiciraContoller(cloudstackTestCase):
             if result_count == 0:
                 raise Exception('Nicira controller did not return any Transport Zones')
             elif result_count > 1:
-                self.logger.debug("Nicira controller returned %s Transport Zones, picking first one" % resultCount)
+                cls.logger.debug("Nicira controller returned %s Transport Zones, picking first one" % resultCount)
             transport_zone_api_url = list_transport_zone_response['results'][0]['_href']
             r3 = requests.get(
                 "https://%s%s" % (controller_host, transport_zone_api_url),
@@ -525,10 +525,10 @@ class TestNiciraContoller(cloudstackTestCase):
             result = str(ssh.execute(ssh_command))
             self.logger.debug("SSH result: %s; COUNT is ==> %s" % (result, result.count("3 packets received")))
         except Exception as e:
-            self.fail("SSH Access failed for %s: %s" % (vmObj.get_ip(), e))
+            self.fail("SSH Access failed for %s: %s" % (virtual_machine.get_ip(), e))
 
         self.assertEqual(result.count('3 packets received'), 1, 'Ping to outside world from VM should be successful')
-		
+
     @attr(tags = ["advanced", "smoke", "nicira"], required_hardware="true")
     def test_04_nicira_shared_networks_numerical_vlanid(self):
         """


[15/16] git commit: updated refs/heads/master to 67b753c

Posted by re...@apache.org.
CLOUDSTACK-9074: Move sql to 4.8.0 schema


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/de23c94f
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/de23c94f
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/de23c94f

Branch: refs/heads/master
Commit: de23c94f33c51cb3c72ceb801e86f3888cfb8604
Parents: 0b20ed4
Author: nvazquez <ni...@gmail.com>
Authored: Thu Dec 24 16:12:01 2015 -0300
Committer: nvazquez <ni...@gmail.com>
Committed: Thu Dec 24 16:12:01 2015 -0300

----------------------------------------------------------------------
 setup/db/db/schema-461to470.sql | 1 -
 setup/db/db/schema-471to480.sql | 2 ++
 2 files changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/de23c94f/setup/db/db/schema-461to470.sql
----------------------------------------------------------------------
diff --git a/setup/db/db/schema-461to470.sql b/setup/db/db/schema-461to470.sql
index 7cc249c..7c70199 100644
--- a/setup/db/db/schema-461to470.sql
+++ b/setup/db/db/schema-461to470.sql
@@ -251,4 +251,3 @@ INSERT IGNORE INTO `cloud`.`hypervisor_capabilities` values (25,UUID(),'VMware',
 INSERT IGNORE INTO `cloud`.`guest_os_hypervisor` (uuid,hypervisor_type, hypervisor_version, guest_os_name, guest_os_id, created, is_user_defined) VALUES (UUID(),'VMware', '5.5', 'rhel7_64Guest', 245, utc_timestamp(), 0);
 INSERT IGNORE INTO `cloud`.`guest_os_hypervisor` (uuid,hypervisor_type, hypervisor_version, guest_os_name, guest_os_id, created, is_user_defined) SELECT UUID(),'VMware', '6.0', guest_os_name, guest_os_id, utc_timestamp(), 0  FROM `cloud`.`guest_os_hypervisor` WHERE hypervisor_type='VMware' AND hypervisor_version='5.5' AND (guest_os_id NOT IN (1,2,3,4,62,63,64,65,156,157,221,222) AND guest_os_id NOT BETWEEN 121 AND 130);
 
-ALTER TABLE `cloud`.`nicira_nvp_router_map` DROP INDEX `logicalrouter_uuid` ;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/de23c94f/setup/db/db/schema-471to480.sql
----------------------------------------------------------------------
diff --git a/setup/db/db/schema-471to480.sql b/setup/db/db/schema-471to480.sql
index fea0017..58cca38 100644
--- a/setup/db/db/schema-471to480.sql
+++ b/setup/db/db/schema-471to480.sql
@@ -18,3 +18,5 @@
 --;
 -- Schema upgrade from 4.7.1 to 4.8.0;
 --;
+
+ALTER TABLE `cloud`.`nicira_nvp_router_map` DROP INDEX `logicalrouter_uuid` ;


[02/16] git commit: updated refs/heads/master to 67b753c

Posted by re...@apache.org.
Use helper method to migrate router vm


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/f804c975
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/f804c975
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/f804c975

Branch: refs/heads/master
Commit: f804c9756d07fcff70aa18a9c50bc30841374f92
Parents: 3dba689
Author: Miguel Ferreira <mi...@me.com>
Authored: Thu Dec 24 11:10:18 2015 +0100
Committer: nvazquez <ni...@gmail.com>
Committed: Thu Dec 24 16:07:06 2015 -0300

----------------------------------------------------------------------
 test/integration/plugins/test_nicira_controller.py | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/f804c975/test/integration/plugins/test_nicira_controller.py
----------------------------------------------------------------------
diff --git a/test/integration/plugins/test_nicira_controller.py b/test/integration/plugins/test_nicira_controller.py
index c2523b7..b41c0e6 100644
--- a/test/integration/plugins/test_nicira_controller.py
+++ b/test/integration/plugins/test_nicira_controller.py
@@ -35,7 +35,8 @@ from marvin.lib.common import (
     get_template,
     list_routers,
     list_hosts,
-    findSuitableHostForMigration
+    findSuitableHostForMigration,
+    migrate_router
 )
 from nose.plugins.attrib import attr
 from marvin.codes import (FAILED, PASS)
@@ -408,8 +409,8 @@ class TestNiciraContoller(cloudstackTestCase):
             self.logger.debug("Master Router VM is on the same host as VM")
             host = findSuitableHostForMigration(self.api_client, router.id)
             if host is not None:
-                router.migrate(self.api_client, host)
-                self.logger.debug("Migrated Master Router VM to host %s" % host)
+                migrate_router(self.api_client, router.id, host.id)
+                self.logger.debug("Migrated Master Router VM to host %s" % host.name)
             else:
                 self.fail('No suitable host to migrate Master Router VM to')
         else: