You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ch...@apache.org on 2013/01/17 01:38:51 UTC
[13/15] git commit: WIP rename device to resource to better reflect
nature of VNMC
WIP rename device to resource to better reflect nature of VNMC
Signed-off-by: Chiradeep Vittal <ch...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/1ae21ea4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/1ae21ea4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/1ae21ea4
Branch: refs/heads/cisco-vnmc-api-integration
Commit: 1ae21ea49a5535a3e839aba0ccfe95c7e9d9abbd
Parents: 84d218f
Author: Chiradeep Vittal <ch...@apache.org>
Authored: Wed Jan 16 15:33:01 2013 -0800
Committer: Chiradeep Vittal <ch...@apache.org>
Committed: Wed Jan 16 15:33:01 2013 -0800
----------------------------------------------------------------------
.../scripts/network/cisco/vsm/generate_vsm_cli.sh | 2 +-
.../cloud/api/commands/AddCiscoVnmcDeviceCmd.java | 121 ---
.../api/commands/AddCiscoVnmcResourceCmd.java | 117 +++
.../api/commands/DeleteCiscoVnmcDeviceCmd.java | 92 --
.../api/commands/DeleteCiscoVnmcResourceCmd.java | 92 ++
.../api/commands/ListCiscoVnmcDevicesCmd.java | 106 --
.../api/commands/ListCiscoVnmcResourcesCmd.java | 106 ++
.../api/response/CiscoVnmcDeviceResponse.java | 53 -
.../api/response/CiscoVnmcResourceResponse.java | 68 ++
.../cloud/network/cisco/CiscoVnmcConnection.java | 60 ++
.../network/cisco/CiscoVnmcConnectionImpl.java | 757 +++++++++++++++
.../com/cloud/network/cisco/CiscoVnmcDeviceVO.java | 95 --
.../com/cloud/network/cisco/CiscoVnmcManager.java | 59 +-
.../cloud/network/cisco/CiscoVnmcResourceVO.java | 95 ++
.../cisco/test/CiscoVnmcConnectionTest.java | 258 +++++
.../src/com/cloud/network/dao/CiscoVnmcDao.java | 6 +-
.../com/cloud/network/dao/CiscoVnmcDaoImpl.java | 10 +-
.../cloud/network/element/CiscoVnmcElement.java | 14 +-
.../network/element/CiscoVnmcElementService.java | 20 +-
.../cloud/network/resource/CiscoVnmcResource.java | 720 +--------------
.../resource/test/CiscoVnmcResourceTest.java | 257 -----
21 files changed, 1627 insertions(+), 1481 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/1ae21ea4/plugins/network-elements/cisco-vnmc/scripts/network/cisco/vsm/generate_vsm_cli.sh
----------------------------------------------------------------------
diff --git a/plugins/network-elements/cisco-vnmc/scripts/network/cisco/vsm/generate_vsm_cli.sh b/plugins/network-elements/cisco-vnmc/scripts/network/cisco/vsm/generate_vsm_cli.sh
index f84e736..851a872 100644
--- a/plugins/network-elements/cisco-vnmc/scripts/network/cisco/vsm/generate_vsm_cli.sh
+++ b/plugins/network-elements/cisco-vnmc/scripts/network/cisco/vsm/generate_vsm_cli.sh
@@ -1,4 +1,4 @@
-for ((vlanid=2002; vlanid <=2030; vlanid++));
+for ((vlanid=2000; vlanid <=2020; vlanid++));
do
#sed "s/vlanid/$vlanid/g" vsm_asa_inside_profiles;
sed "s/vlanid/$vlanid/g" vservice_node ;
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/1ae21ea4/plugins/network-elements/cisco-vnmc/src/com/cloud/api/commands/AddCiscoVnmcDeviceCmd.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/cisco-vnmc/src/com/cloud/api/commands/AddCiscoVnmcDeviceCmd.java b/plugins/network-elements/cisco-vnmc/src/com/cloud/api/commands/AddCiscoVnmcDeviceCmd.java
deleted file mode 100644
index 3da9506..0000000
--- a/plugins/network-elements/cisco-vnmc/src/com/cloud/api/commands/AddCiscoVnmcDeviceCmd.java
+++ /dev/null
@@ -1,121 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package com.cloud.api.commands;
-
-import org.apache.log4j.Logger;
-
-import com.cloud.api.ApiConstants;
-import com.cloud.api.BaseAsyncCmd;
-import com.cloud.api.BaseCmd;
-import com.cloud.api.IdentityMapper;
-import com.cloud.api.Implementation;
-import com.cloud.api.Parameter;
-import com.cloud.api.PlugService;
-import com.cloud.api.ServerApiException;
-import com.cloud.api.BaseCmd.CommandType;
-import com.cloud.api.response.CiscoVnmcDeviceResponse;
-import com.cloud.event.EventTypes;
-import com.cloud.exception.ConcurrentOperationException;
-import com.cloud.exception.InsufficientCapacityException;
-import com.cloud.exception.InvalidParameterValueException;
-import com.cloud.exception.NetworkRuleConflictException;
-import com.cloud.exception.ResourceAllocationException;
-import com.cloud.exception.ResourceUnavailableException;
-import com.cloud.network.ExternalLoadBalancerDeviceVO;
-import com.cloud.network.cisco.CiscoVnmcDeviceVO;
-import com.cloud.network.element.CiscoVnmcElementService;
-import com.cloud.user.UserContext;
-import com.cloud.utils.exception.CloudRuntimeException;
-
-@Implementation(responseObject=CiscoVnmcDeviceResponse.class, description="Adds a Cisco Vnmc Controller")
-public class AddCiscoVnmcDeviceCmd extends BaseCmd {
- private static final Logger s_logger = Logger.getLogger(AddCiscoVnmcDeviceCmd.class.getName());
- private static final String s_name = "addCiscoVnmcdevice";
- @PlugService CiscoVnmcElementService _ciscoVnmcElementService;
-
- /////////////////////////////////////////////////////
- //////////////// API parameters /////////////////////
- /////////////////////////////////////////////////////
-
- @IdentityMapper(entityTableName="physical_network")
- @Parameter(name=ApiConstants.PHYSICAL_NETWORK_ID, type=CommandType.LONG, required=true, description="the Physical Network ID")
- private Long physicalNetworkId;
-
- @Parameter(name=ApiConstants.HOST_NAME, type=CommandType.STRING, required = true, description="Hostname of ip address of the ciscoVnmc NVP Controller.")
- private String host;
-
- @Parameter(name=ApiConstants.USERNAME, type=CommandType.STRING, required = true, description="Credentials to access the ciscoVnmc Controller API")
- private String username;
-
- @Parameter(name=ApiConstants.PASSWORD, type=CommandType.STRING, required = true, description="Credentials to access the ciscoVnmc Controller API")
- private String password;
-
-
- /////////////////////////////////////////////////////
- /////////////////// Accessors ///////////////////////
- /////////////////////////////////////////////////////
-
- public Long getPhysicalNetworkId() {
- return physicalNetworkId;
- }
-
- public String getHost() {
- return host;
- }
-
- public String getUsername() {
- return username;
- }
-
- public String getPassword() {
- return password;
- }
-
-
- /////////////////////////////////////////////////////
- /////////////// API Implementation///////////////////
- /////////////////////////////////////////////////////
-
- @Override
- public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
- try {
- CiscoVnmcDeviceVO CiscoVnmcDeviceVO = _ciscoVnmcElementService.addCiscoVnmcDevice(this);
- if (CiscoVnmcDeviceVO != null) {
- CiscoVnmcDeviceResponse response = _ciscoVnmcElementService.createCiscoVnmcDeviceResponse(CiscoVnmcDeviceVO);
- response.setObjectName("CiscoVnmcdevice");
- response.setResponseName(getCommandName());
- this.setResponseObject(response);
- } else {
- throw new ServerApiException(BaseAsyncCmd.INTERNAL_ERROR, "Failed to add ciscoVnmc NVP device due to internal error.");
- }
- } catch (InvalidParameterValueException invalidParamExcp) {
- throw new ServerApiException(BaseCmd.PARAM_ERROR, invalidParamExcp.getMessage());
- } catch (CloudRuntimeException runtimeExcp) {
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, runtimeExcp.getMessage());
- }
- }
-
- @Override
- public String getCommandName() {
- return s_name;
- }
-
- @Override
- public long getEntityOwnerId() {
- return UserContext.current().getCaller().getId();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/1ae21ea4/plugins/network-elements/cisco-vnmc/src/com/cloud/api/commands/AddCiscoVnmcResourceCmd.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/cisco-vnmc/src/com/cloud/api/commands/AddCiscoVnmcResourceCmd.java b/plugins/network-elements/cisco-vnmc/src/com/cloud/api/commands/AddCiscoVnmcResourceCmd.java
new file mode 100644
index 0000000..aa41611
--- /dev/null
+++ b/plugins/network-elements/cisco-vnmc/src/com/cloud/api/commands/AddCiscoVnmcResourceCmd.java
@@ -0,0 +1,117 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.api.commands;
+
+import org.apache.log4j.Logger;
+
+import com.cloud.api.ApiConstants;
+import com.cloud.api.BaseAsyncCmd;
+import com.cloud.api.BaseCmd;
+import com.cloud.api.IdentityMapper;
+import com.cloud.api.Implementation;
+import com.cloud.api.Parameter;
+import com.cloud.api.PlugService;
+import com.cloud.api.ServerApiException;
+import com.cloud.api.response.CiscoVnmcResourceResponse;
+import com.cloud.exception.ConcurrentOperationException;
+import com.cloud.exception.InsufficientCapacityException;
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.exception.ResourceAllocationException;
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.network.cisco.CiscoVnmcResourceVO;
+import com.cloud.network.element.CiscoVnmcElementService;
+import com.cloud.user.UserContext;
+import com.cloud.utils.exception.CloudRuntimeException;
+
+@Implementation(responseObject=CiscoVnmcResourceResponse.class, description="Adds a Cisco Vnmc Controller")
+public class AddCiscoVnmcResourceCmd extends BaseCmd {
+ private static final Logger s_logger = Logger.getLogger(AddCiscoVnmcResourceCmd.class.getName());
+ private static final String s_name = "addCiscoVnmcResource";
+ @PlugService CiscoVnmcElementService _ciscoVnmcElementService;
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+
+ @IdentityMapper(entityTableName="physical_network")
+ @Parameter(name=ApiConstants.PHYSICAL_NETWORK_ID, type=CommandType.LONG, required=true, description="the Physical Network ID")
+ private Long physicalNetworkId;
+
+ @Parameter(name=ApiConstants.HOST_NAME, type=CommandType.STRING, required = true, description="Hostname of ip address of the Cisco VNMC Controller.")
+ private String host;
+
+ @Parameter(name=ApiConstants.USERNAME, type=CommandType.STRING, required = true, description="Credentials to access the Cisco VNMC Controller API")
+ private String username;
+
+ @Parameter(name=ApiConstants.PASSWORD, type=CommandType.STRING, required = true, description="Credentials to access the Cisco VNMC Controller API")
+ private String password;
+
+
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+
+ public Long getPhysicalNetworkId() {
+ return physicalNetworkId;
+ }
+
+ public String getHost() {
+ return host;
+ }
+
+ public String getUsername() {
+ return username;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ /////////////////////////////////////////////////////
+
+ @Override
+ public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
+ try {
+ CiscoVnmcResourceVO CiscoVnmcResourceVO = _ciscoVnmcElementService.addCiscoVnmcResource(this);
+ if (CiscoVnmcResourceVO != null) {
+ CiscoVnmcResourceResponse response = _ciscoVnmcElementService.createCiscoVnmcResourceResponse(CiscoVnmcResourceVO);
+ response.setObjectName("CiscoVnmcResource");
+ response.setResponseName(getCommandName());
+ this.setResponseObject(response);
+ } else {
+ throw new ServerApiException(BaseAsyncCmd.INTERNAL_ERROR, "Failed to add Cisco VNMC controller due to internal error.");
+ }
+ } catch (InvalidParameterValueException invalidParamExcp) {
+ throw new ServerApiException(BaseCmd.PARAM_ERROR, invalidParamExcp.getMessage());
+ } catch (CloudRuntimeException runtimeExcp) {
+ throw new ServerApiException(BaseCmd.INTERNAL_ERROR, runtimeExcp.getMessage());
+ }
+ }
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ @Override
+ public long getEntityOwnerId() {
+ return UserContext.current().getCaller().getId();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/1ae21ea4/plugins/network-elements/cisco-vnmc/src/com/cloud/api/commands/DeleteCiscoVnmcDeviceCmd.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/cisco-vnmc/src/com/cloud/api/commands/DeleteCiscoVnmcDeviceCmd.java b/plugins/network-elements/cisco-vnmc/src/com/cloud/api/commands/DeleteCiscoVnmcDeviceCmd.java
deleted file mode 100644
index 7939338..0000000
--- a/plugins/network-elements/cisco-vnmc/src/com/cloud/api/commands/DeleteCiscoVnmcDeviceCmd.java
+++ /dev/null
@@ -1,92 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package com.cloud.api.commands;
-
-import org.apache.log4j.Logger;
-
-import com.cloud.api.ApiConstants;
-import com.cloud.api.BaseCmd;
-import com.cloud.api.IdentityMapper;
-import com.cloud.api.Implementation;
-import com.cloud.api.Parameter;
-import com.cloud.api.PlugService;
-import com.cloud.api.ServerApiException;
-import com.cloud.api.response.SuccessResponse;
-import com.cloud.exception.ConcurrentOperationException;
-import com.cloud.exception.InsufficientCapacityException;
-import com.cloud.exception.InvalidParameterValueException;
-import com.cloud.exception.ResourceAllocationException;
-import com.cloud.exception.ResourceUnavailableException;
-import com.cloud.network.element.CiscoVnmcElementService;
-import com.cloud.user.UserContext;
-import com.cloud.utils.exception.CloudRuntimeException;
-
-@Implementation(responseObject=SuccessResponse.class, description=" delete a ciscoVnmc nvp device")
-public class DeleteCiscoVnmcDeviceCmd extends BaseCmd {
- private static final Logger s_logger = Logger.getLogger(DeleteCiscoVnmcDeviceCmd.class.getName());
- private static final String s_name = "addCiscoVnmcdevice";
- @PlugService CiscoVnmcElementService _ciscoVnmcElementService;
-
- /////////////////////////////////////////////////////
- //////////////// API parameters /////////////////////
- /////////////////////////////////////////////////////
-
- @IdentityMapper(entityTableName="external_ciscoVnmc_nvp_devices")
- @Parameter(name=ApiConstants.DEVICE_ID, type=CommandType.LONG, required=true, description="Cisco Vnmc device ID")
- private Long CiscoVnmcDeviceId;
-
- /////////////////////////////////////////////////////
- /////////////////// Accessors ///////////////////////
- /////////////////////////////////////////////////////
-
- public Long getCiscoVnmcDeviceId() {
- return CiscoVnmcDeviceId;
- }
-
- /////////////////////////////////////////////////////
- /////////////// API Implementation///////////////////
- /////////////////////////////////////////////////////
-
- @Override
- public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
- try {
- boolean result = _ciscoVnmcElementService.deleteCiscoVnmcDevice(this);
- if (result) {
- SuccessResponse response = new SuccessResponse(getCommandName());
- response.setResponseName(getCommandName());
- this.setResponseObject(response);
- } else {
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete ciscoVnmc device.");
- }
- } catch (InvalidParameterValueException invalidParamExcp) {
- throw new ServerApiException(BaseCmd.PARAM_ERROR, invalidParamExcp.getMessage());
- } catch (CloudRuntimeException runtimeExcp) {
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, runtimeExcp.getMessage());
- }
- }
-
- @Override
- public String getCommandName() {
- return s_name;
- }
-
- @Override
- public long getEntityOwnerId() {
- return UserContext.current().getCaller().getId();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/1ae21ea4/plugins/network-elements/cisco-vnmc/src/com/cloud/api/commands/DeleteCiscoVnmcResourceCmd.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/cisco-vnmc/src/com/cloud/api/commands/DeleteCiscoVnmcResourceCmd.java b/plugins/network-elements/cisco-vnmc/src/com/cloud/api/commands/DeleteCiscoVnmcResourceCmd.java
new file mode 100644
index 0000000..71b221d
--- /dev/null
+++ b/plugins/network-elements/cisco-vnmc/src/com/cloud/api/commands/DeleteCiscoVnmcResourceCmd.java
@@ -0,0 +1,92 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.api.commands;
+
+import org.apache.log4j.Logger;
+
+import com.cloud.api.ApiConstants;
+import com.cloud.api.BaseCmd;
+import com.cloud.api.IdentityMapper;
+import com.cloud.api.Implementation;
+import com.cloud.api.Parameter;
+import com.cloud.api.PlugService;
+import com.cloud.api.ServerApiException;
+import com.cloud.api.response.SuccessResponse;
+import com.cloud.exception.ConcurrentOperationException;
+import com.cloud.exception.InsufficientCapacityException;
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.exception.ResourceAllocationException;
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.network.element.CiscoVnmcElementService;
+import com.cloud.user.UserContext;
+import com.cloud.utils.exception.CloudRuntimeException;
+
+@Implementation(responseObject=SuccessResponse.class, description=" delete a Cisco Vnmc Resource")
+public class DeleteCiscoVnmcResourceCmd extends BaseCmd {
+ private static final Logger s_logger = Logger.getLogger(DeleteCiscoVnmcResourceCmd.class.getName());
+ private static final String s_name = "addCiscoVnmcResource";
+ @PlugService CiscoVnmcElementService _ciscoVnmcElementService;
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+
+ @IdentityMapper(entityTableName="external_cisco_vnmc_resources")
+ @Parameter(name=ApiConstants.RESOURCE_ID, type=CommandType.LONG, required=true, description="Cisco Vnmc resource ID")
+ private Long CiscoVnmcResourceId;
+
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+
+ public Long getCiscoVnmcResourceId() {
+ return CiscoVnmcResourceId;
+ }
+
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ /////////////////////////////////////////////////////
+
+ @Override
+ public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
+ try {
+ boolean result = _ciscoVnmcElementService.deleteCiscoVnmcResource(this);
+ if (result) {
+ SuccessResponse response = new SuccessResponse(getCommandName());
+ response.setResponseName(getCommandName());
+ this.setResponseObject(response);
+ } else {
+ throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete Cisco Vnmc resource.");
+ }
+ } catch (InvalidParameterValueException invalidParamExcp) {
+ throw new ServerApiException(BaseCmd.PARAM_ERROR, invalidParamExcp.getMessage());
+ } catch (CloudRuntimeException runtimeExcp) {
+ throw new ServerApiException(BaseCmd.INTERNAL_ERROR, runtimeExcp.getMessage());
+ }
+ }
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ @Override
+ public long getEntityOwnerId() {
+ return UserContext.current().getCaller().getId();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/1ae21ea4/plugins/network-elements/cisco-vnmc/src/com/cloud/api/commands/ListCiscoVnmcDevicesCmd.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/cisco-vnmc/src/com/cloud/api/commands/ListCiscoVnmcDevicesCmd.java b/plugins/network-elements/cisco-vnmc/src/com/cloud/api/commands/ListCiscoVnmcDevicesCmd.java
deleted file mode 100644
index eb6a288..0000000
--- a/plugins/network-elements/cisco-vnmc/src/com/cloud/api/commands/ListCiscoVnmcDevicesCmd.java
+++ /dev/null
@@ -1,106 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package com.cloud.api.commands;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.log4j.Logger;
-
-import com.cloud.api.ApiConstants;
-import com.cloud.api.BaseCmd;
-import com.cloud.api.BaseListCmd;
-import com.cloud.api.IdentityMapper;
-import com.cloud.api.Implementation;
-import com.cloud.api.Parameter;
-import com.cloud.api.PlugService;
-import com.cloud.api.ServerApiException;
-import com.cloud.api.response.ListResponse;
-import com.cloud.api.response.CiscoVnmcDeviceResponse;
-import com.cloud.exception.ConcurrentOperationException;
-import com.cloud.exception.InsufficientCapacityException;
-import com.cloud.exception.InvalidParameterValueException;
-import com.cloud.exception.ResourceAllocationException;
-import com.cloud.exception.ResourceUnavailableException;
-import com.cloud.network.cisco.CiscoVnmcDeviceVO;
-import com.cloud.network.element.CiscoVnmcElementService;
-import com.cloud.utils.exception.CloudRuntimeException;
-
-@Implementation(responseObject=CiscoVnmcDeviceResponse.class, description="Lists ciscoVnmc NVP devices")
-public class ListCiscoVnmcDevicesCmd extends BaseListCmd {
- private static final Logger s_logger = Logger.getLogger(ListCiscoVnmcDevicesCmd.class.getName());
- private static final String s_name = "listCiscoVnmcDevices";
- @PlugService CiscoVnmcElementService _ciscoVnmcElementService;
-
- /////////////////////////////////////////////////////
- //////////////// API parameters /////////////////////
- /////////////////////////////////////////////////////
-
- @IdentityMapper(entityTableName="physical_network")
- @Parameter(name=ApiConstants.PHYSICAL_NETWORK_ID, type=CommandType.LONG, description="the Physical Network ID")
- private Long physicalNetworkId;
-
- @IdentityMapper(entityTableName="external_cisco_vnmc_devices")
- @Parameter(name=ApiConstants.DEVICE_ID, type=CommandType.LONG, description="Cisco Vnmc device ID")
- private Long CiscoVnmcDeviceId;
-
- /////////////////////////////////////////////////////
- /////////////////// Accessors ///////////////////////
- /////////////////////////////////////////////////////
-
- public Long getCiscoVnmcDeviceId() {
- return CiscoVnmcDeviceId;
- }
-
- public Long getPhysicalNetworkId() {
- return physicalNetworkId;
- }
-
- /////////////////////////////////////////////////////
- /////////////// API Implementation///////////////////
- /////////////////////////////////////////////////////
-
- @Override
- public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
- try {
- List<CiscoVnmcDeviceVO> ciscoVnmcDevices = _ciscoVnmcElementService.listCiscoVnmcDevices(this);
- ListResponse<CiscoVnmcDeviceResponse> response = new ListResponse<CiscoVnmcDeviceResponse>();
- List<CiscoVnmcDeviceResponse> ciscoVnmcDevicesResponse = new ArrayList<CiscoVnmcDeviceResponse>();
-
- if (ciscoVnmcDevices != null && !ciscoVnmcDevices.isEmpty()) {
- for (CiscoVnmcDeviceVO ciscoVnmcDeviceVO : ciscoVnmcDevices) {
- CiscoVnmcDeviceResponse ciscoVnmcDeviceResponse = _ciscoVnmcElementService.createCiscoVnmcDeviceResponse(ciscoVnmcDeviceVO);
- ciscoVnmcDevicesResponse.add(ciscoVnmcDeviceResponse);
- }
- }
-
- response.setResponses(ciscoVnmcDevicesResponse);
- response.setResponseName(getCommandName());
- this.setResponseObject(response);
- } catch (InvalidParameterValueException invalidParamExcp) {
- throw new ServerApiException(BaseCmd.PARAM_ERROR, invalidParamExcp.getMessage());
- } catch (CloudRuntimeException runtimeExcp) {
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, runtimeExcp.getMessage());
- }
- }
-
- @Override
- public String getCommandName() {
- return s_name;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/1ae21ea4/plugins/network-elements/cisco-vnmc/src/com/cloud/api/commands/ListCiscoVnmcResourcesCmd.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/cisco-vnmc/src/com/cloud/api/commands/ListCiscoVnmcResourcesCmd.java b/plugins/network-elements/cisco-vnmc/src/com/cloud/api/commands/ListCiscoVnmcResourcesCmd.java
new file mode 100644
index 0000000..577a170
--- /dev/null
+++ b/plugins/network-elements/cisco-vnmc/src/com/cloud/api/commands/ListCiscoVnmcResourcesCmd.java
@@ -0,0 +1,106 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.api.commands;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+
+import com.cloud.api.ApiConstants;
+import com.cloud.api.BaseCmd;
+import com.cloud.api.BaseListCmd;
+import com.cloud.api.IdentityMapper;
+import com.cloud.api.Implementation;
+import com.cloud.api.Parameter;
+import com.cloud.api.PlugService;
+import com.cloud.api.ServerApiException;
+import com.cloud.api.response.ListResponse;
+import com.cloud.api.response.CiscoVnmcResourceResponse;
+import com.cloud.exception.ConcurrentOperationException;
+import com.cloud.exception.InsufficientCapacityException;
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.exception.ResourceAllocationException;
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.network.cisco.CiscoVnmcResourceVO;
+import com.cloud.network.element.CiscoVnmcElementService;
+import com.cloud.utils.exception.CloudRuntimeException;
+
+@Implementation(responseObject=CiscoVnmcResourceResponse.class, description="Lists Cisco VNMC controllers")
+public class ListCiscoVnmcResourcesCmd extends BaseListCmd {
+ private static final Logger s_logger = Logger.getLogger(ListCiscoVnmcResourcesCmd.class.getName());
+ private static final String s_name = "listCiscoVnmcResources";
+ @PlugService CiscoVnmcElementService _ciscoVnmcElementService;
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+
+ @IdentityMapper(entityTableName="physical_network")
+ @Parameter(name=ApiConstants.PHYSICAL_NETWORK_ID, type=CommandType.LONG, description="the Physical Network ID")
+ private Long physicalNetworkId;
+
+ @IdentityMapper(entityTableName="external_cisco_vnmc_resources")
+ @Parameter(name=ApiConstants.RESOURCE_ID, type=CommandType.LONG, description="Cisco VNMC resource ID")
+ private Long ciscoVnmcResourceId;
+
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+
+ public Long getCiscoVnmcResourceId() {
+ return ciscoVnmcResourceId;
+ }
+
+ public Long getPhysicalNetworkId() {
+ return physicalNetworkId;
+ }
+
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ /////////////////////////////////////////////////////
+
+ @Override
+ public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
+ try {
+ List<CiscoVnmcResourceVO> CiscoVnmcResources = _ciscoVnmcElementService.listCiscoVnmcResources(this);
+ ListResponse<CiscoVnmcResourceResponse> response = new ListResponse<CiscoVnmcResourceResponse>();
+ List<CiscoVnmcResourceResponse> CiscoVnmcResourcesResponse = new ArrayList<CiscoVnmcResourceResponse>();
+
+ if (CiscoVnmcResources != null && !CiscoVnmcResources.isEmpty()) {
+ for (CiscoVnmcResourceVO CiscoVnmcResourceVO : CiscoVnmcResources) {
+ CiscoVnmcResourceResponse CiscoVnmcResourceResponse = _ciscoVnmcElementService.createCiscoVnmcResourceResponse(CiscoVnmcResourceVO);
+ CiscoVnmcResourcesResponse.add(CiscoVnmcResourceResponse);
+ }
+ }
+
+ response.setResponses(CiscoVnmcResourcesResponse);
+ response.setResponseName(getCommandName());
+ this.setResponseObject(response);
+ } catch (InvalidParameterValueException invalidParamExcp) {
+ throw new ServerApiException(BaseCmd.PARAM_ERROR, invalidParamExcp.getMessage());
+ } catch (CloudRuntimeException runtimeExcp) {
+ throw new ServerApiException(BaseCmd.INTERNAL_ERROR, runtimeExcp.getMessage());
+ }
+ }
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/1ae21ea4/plugins/network-elements/cisco-vnmc/src/com/cloud/api/response/CiscoVnmcDeviceResponse.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/cisco-vnmc/src/com/cloud/api/response/CiscoVnmcDeviceResponse.java b/plugins/network-elements/cisco-vnmc/src/com/cloud/api/response/CiscoVnmcDeviceResponse.java
deleted file mode 100644
index 3648182..0000000
--- a/plugins/network-elements/cisco-vnmc/src/com/cloud/api/response/CiscoVnmcDeviceResponse.java
+++ /dev/null
@@ -1,53 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package com.cloud.api.response;
-
-import com.cloud.api.ApiConstants;
-import com.cloud.serializer.Param;
-import com.cloud.utils.IdentityProxy;
-import com.google.gson.annotations.SerializedName;
-
-public class CiscoVnmcDeviceResponse extends BaseResponse {
- @SerializedName(ApiConstants.DEVICE_ID) @Param(description="device id of the Cisco VNMC controller")
- private IdentityProxy id = new IdentityProxy("external_devices");
-
- @SerializedName(ApiConstants.PHYSICAL_NETWORK_ID) @Param(description="the physical network to which this Nirica Nvp belongs to")
- private IdentityProxy physicalNetworkId = new IdentityProxy("physical_network");
-
- @SerializedName(ApiConstants.PROVIDER) @Param(description="name of the provider")
- private String providerName;
-
- @SerializedName(ApiConstants.DEVICE_NAME) @Param(description="device name")
- private String deviceName;
-
- public void setId(long nvpDeviceId) {
- this.id.setValue(nvpDeviceId);
- }
-
- public void setPhysicalNetworkId(long physicalNetworkId) {
- this.physicalNetworkId.setValue(physicalNetworkId);
- }
-
- public void setProviderName(String providerName) {
- this.providerName = providerName;
- }
-
- public void setDeviceName(String deviceName) {
- this.deviceName = deviceName;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/1ae21ea4/plugins/network-elements/cisco-vnmc/src/com/cloud/api/response/CiscoVnmcResourceResponse.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/cisco-vnmc/src/com/cloud/api/response/CiscoVnmcResourceResponse.java b/plugins/network-elements/cisco-vnmc/src/com/cloud/api/response/CiscoVnmcResourceResponse.java
new file mode 100644
index 0000000..b3774c5
--- /dev/null
+++ b/plugins/network-elements/cisco-vnmc/src/com/cloud/api/response/CiscoVnmcResourceResponse.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.api.response;
+
+import com.cloud.api.ApiConstants;
+import com.cloud.serializer.Param;
+import com.cloud.utils.IdentityProxy;
+import com.google.gson.annotations.SerializedName;
+
+public class CiscoVnmcResourceResponse extends BaseResponse {
+ public static final String RESOURCE_NAME = "resourcename";
+
+ @SerializedName(ApiConstants.RESOURCE_ID) @Param(description="resource id of the Cisco VNMC controller")
+ private IdentityProxy id = new IdentityProxy("external_cisco_vnmc_resources");
+
+ @SerializedName(ApiConstants.PHYSICAL_NETWORK_ID) @Param(description="the physical network to which this VNMC belongs to")
+ private IdentityProxy physicalNetworkId = new IdentityProxy("physical_network");
+
+ public IdentityProxy getPhysicalNetworkId() {
+ return physicalNetworkId;
+ }
+
+ public String getProviderName() {
+ return providerName;
+ }
+
+ public String getResourceName() {
+ return resourceName;
+ }
+
+ @SerializedName(ApiConstants.PROVIDER) @Param(description="name of the provider")
+ private String providerName;
+
+ @SerializedName(RESOURCE_NAME)
+ @Param(description="Cisco VNMC resource name")
+ private String resourceName;
+
+ public void setId(long ciscoVnmcResourceId) {
+ this.id.setValue(ciscoVnmcResourceId);
+ }
+
+ public void setPhysicalNetworkId(long physicalNetworkId) {
+ this.physicalNetworkId.setValue(physicalNetworkId);
+ }
+
+ public void setProviderName(String providerName) {
+ this.providerName = providerName;
+ }
+
+ public void setResourceName(String resourceName) {
+ this.resourceName = resourceName;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/1ae21ea4/plugins/network-elements/cisco-vnmc/src/com/cloud/network/cisco/CiscoVnmcConnection.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/cisco-vnmc/src/com/cloud/network/cisco/CiscoVnmcConnection.java b/plugins/network-elements/cisco-vnmc/src/com/cloud/network/cisco/CiscoVnmcConnection.java
new file mode 100644
index 0000000..0770b5e
--- /dev/null
+++ b/plugins/network-elements/cisco-vnmc/src/com/cloud/network/cisco/CiscoVnmcConnection.java
@@ -0,0 +1,60 @@
+package com.cloud.network.cisco;
+
+import java.util.List;
+
+import com.cloud.utils.exception.ExecutionException;
+
+public interface CiscoVnmcConnection {
+
+ public boolean createTenant(String tenantName) throws ExecutionException;
+
+ public boolean createTenantVDC(String tenantName) throws ExecutionException;
+
+ public boolean createTenantVDCEdgeDeviceProfile(String tenantName)
+ throws ExecutionException;
+
+ public boolean createTenantVDCEdgeStaticRoutePolicy(String tenantName)
+ throws ExecutionException;
+
+ public boolean createTenantVDCEdgeStaticRoute(String tenantName,
+ String nextHopIp, String outsideIntf, String destination,
+ String netmask) throws ExecutionException;
+
+ public boolean associateTenantVDCEdgeStaticRoutePolicy(String tenantName)
+ throws ExecutionException;
+
+ public boolean associateTenantVDCEdgeDhcpPolicy(String tenantName,
+ String intfName) throws ExecutionException;
+
+ public boolean createTenantVDCEdgeDhcpPolicy(String tenantName,
+ String startIp, String endIp, String subnet, String nameServerIp,
+ String domain) throws ExecutionException;
+
+ public boolean associateTenantVDCEdgeDhcpServerPolicy(String tenantName,
+ String intfName) throws ExecutionException;
+
+ public boolean createTenantVDCEdgeSecurityProfile(String tenantName)
+ throws ExecutionException;
+
+ public boolean createTenantVDCSourceNATPool(String tenantName,
+ String publicIp) throws ExecutionException;
+
+ public boolean createTenantVDCSourceNATPolicy(String tenantName,
+ String startSourceIp, String endSourceIp) throws ExecutionException;
+
+ public boolean createTenantVDCNatPolicySet(String tenantName)
+ throws ExecutionException;
+
+ public boolean associateNatPolicySet(String tenantName)
+ throws ExecutionException;
+
+ public boolean createEdgeFirewall(String tenantName, String publicIp,
+ String insideIp, String insideSubnet, String outsideSubnet)
+ throws ExecutionException;
+
+ public List<String> listUnAssocAsa1000v() throws ExecutionException;
+
+ public boolean assocAsa1000v(String tenantName, String firewallDn)
+ throws ExecutionException;
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/1ae21ea4/plugins/network-elements/cisco-vnmc/src/com/cloud/network/cisco/CiscoVnmcConnectionImpl.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/cisco-vnmc/src/com/cloud/network/cisco/CiscoVnmcConnectionImpl.java b/plugins/network-elements/cisco-vnmc/src/com/cloud/network/cisco/CiscoVnmcConnectionImpl.java
new file mode 100644
index 0000000..943be02
--- /dev/null
+++ b/plugins/network-elements/cisco-vnmc/src/com/cloud/network/cisco/CiscoVnmcConnectionImpl.java
@@ -0,0 +1,757 @@
+package com.cloud.network.cisco;
+
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpStatus;
+import org.apache.commons.httpclient.contrib.ssl.EasySSLProtocolSocketFactory;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.log4j.Logger;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.InputSource;
+
+import com.cloud.utils.exception.ExecutionException;
+import com.cloud.utils.script.Script;
+
+public class CiscoVnmcConnectionImpl implements CiscoVnmcConnection {
+
+ private String _ip;
+ private String _username;
+ private String _password;
+ private String _cookie;
+
+ private final Logger s_logger = Logger.getLogger(CiscoVnmcConnectionImpl.class);
+
+ private enum VnmcXml {
+ LOGIN("login.xml", "mgmt-controller"),
+ CREATE_TENANT("create-tenant.xml", "service-reg"),
+ CREATE_VDC("create-vdc.xml", "service-reg"),
+ CREATE_EDGE_DEVICE_PROFILE("create-edge-device-profile.xml", "policy-mgr"),
+ CREATE_EDGE_ROUTE_POLICY("create-edge-device-route-policy.xml", "policy-mgr"),
+ CREATE_EDGE_ROUTE("create-edge-device-route.xml", "policy-mgr"),
+ RESOLVE_EDGE_ROUTE_POLICY("associate-route-policy.xml", "policy-mgr"),
+ RESOLVE_EDGE_DHCP_POLICY("associate-dhcp-policy.xml", "policy-mgr"),
+ CREATE_DHCP_POLICY("create-dhcp-policy.xml", "policy-mgr"),
+ RESOLVE_EDGE_DHCP_SERVER_POLICY("associate-dhcp-server.xml", "policy-mgr"),
+ CREATE_EDGE_SECURITY_PROFILE("create-edge-security-profile.xml", "policy-mgr"),
+ CREATE_SOURCE_NAT_POOL("create-source-nat-pool.xml", "policy-mgr"),
+ CREATE_SOURCE_NAT_POLICY("create-source-nat-policy.xml", "policy-mgr"),
+ CREATE_NAT_POLICY_SET("create-nat-policy-set.xml", "policy-mgr"),
+ RESOLVE_NAT_POLICY_SET("associate-nat-policy-set.xml", "policy-mgr"),
+ CREATE_EDGE_FIREWALL("create-edge-firewall.xml", "resource-mgr"),
+ LIST_UNASSOC_ASA1000V("list-unassigned-asa1000v.xml", "resource-mgr"),
+ ASSIGN_ASA1000V("assoc-asa1000v.xml", "resource-mgr");
+
+ private String scriptsDir = "scripts/network/cisco";
+ private String xml;
+ private String service;
+ private final Logger s_logger = Logger.getLogger(CiscoVnmcConnectionImpl.class);
+
+
+ private VnmcXml(String filename, String service) {
+ this.xml = getXml(filename);
+ this.service = service;
+ }
+
+ public String getXml() {
+ return xml;
+ }
+
+ private String getXml(String filename) {
+ try {
+ String xmlFilePath = Script.findScript(scriptsDir, filename);
+
+ if (xmlFilePath == null) {
+ throw new Exception("Failed to find Cisco VNMC XML file: " + filename);
+ }
+
+ FileReader fr = new FileReader(xmlFilePath);
+ BufferedReader br = new BufferedReader(fr);
+
+ String xml = "";
+ String line;
+ while ((line = br.readLine()) != null) {
+ //xml += line.replaceAll("\n"," ");
+ xml += line;
+ }
+
+ return xml;
+ } catch (Exception e) {
+ s_logger.debug(e);
+ return null;
+ }
+ }
+
+ public String getService() {
+ return service;
+ }
+ }
+
+ public CiscoVnmcConnectionImpl(String hostIp, String userName, String password) {
+ this._ip = hostIp;
+ this._username = userName;
+ this._password = password;
+
+ }
+
+ public boolean login() throws ExecutionException {
+ String xml = VnmcXml.LOGIN.getXml();
+ String service = VnmcXml.LOGIN.getService();
+ xml = replaceXmlValue(xml, "username", _username);
+ xml = replaceXmlValue(xml, "password", _password);
+ String response = sendRequest(service, xml);
+ Map<String, String> checked = checkResponse(response, "outCookie", "errorCode", "response");
+
+ if (checked.get("errorCode") != null)
+ return false;
+ _cookie = checked.get("outCookie");
+ if (_cookie == null) {
+ return false;
+ }
+ return true;
+ }
+
+ private String getDnForTenant(String tenantName) {
+ return "org-root/org-" + tenantName;
+ }
+
+ private String getDnForTenantVDC(String tenantName) {
+ return getDnForTenant(tenantName) + "/org-VDC-" + tenantName;
+ }
+
+ private String getDnForTenantVDCEdgeDeviceProfile(String tenantName) {
+ return getDnForTenantVDC(tenantName) + "/edsp-" + getNameForEdgeDeviceServiceProfile(tenantName);
+ }
+
+ private String getDnForTenantVDCEdgeSecurityProfile(String tenantName) {
+ return getDnForTenantVDC(tenantName) + "/vnep-" + getNameForEdgeDeviceSecurityProfile(tenantName);
+ }
+
+ private String getDnForEdgeDeviceRoutingPolicy(String tenantName) {
+ return getDnForTenantVDC(tenantName) + "/routing-policy-" + getNameForEdgeDeviceRoutePolicy(tenantName);
+ //FIXME: any other construct is unreliable. why?
+ }
+
+ private String getDnForEdgeDeviceRoute(String tenantName, int id) {
+ return getDnForEdgeDeviceRoutingPolicy(tenantName) + "/sroute-" + id ;
+ }
+
+ private String getDnForDhcpPolicy(String tenantName, String intfName) {
+ return getDnForTenantVDCEdgeDeviceProfile(tenantName) + "/dhcp-" + intfName;
+ }
+
+ private String getNameForDhcpPolicy(String tenantName) {
+ return tenantName + "-Dhcp-Policy";
+ }
+
+ private String getNameForDhcpServer(String tenantName) {
+ return tenantName + "-Dhcp-Server";
+ }
+
+ private String getDnForDhcpServerPolicy(String tenantName) {
+ return getDnForTenantVDC(tenantName) + "/dhcp-server-" + getNameForDhcpPolicy(tenantName);
+ }
+
+ private String getNameForIpRange() {
+ return "iprange";
+ }
+
+ private String getDnForDhcpIpRange(String tenantName) {
+ return getDnForDhcpServerPolicy(tenantName) + "/ip-range-" + getNameForIpRange();
+ }
+
+ private String getNameForDNSService(String tenantName) {
+ return tenantName + "-DNS";
+ }
+
+
+ private String getDnForDnsService(String tenantName) {
+ return getDnForDhcpServerPolicy(tenantName) + "/dns-svc-" + getNameForDNSService(tenantName);
+ }
+
+ private String getDnForDnsServer(String tenantName, String dnsip) {
+ return getDnForDnsService(tenantName) + "/dns-" + dnsip;
+ }
+
+ private String getNameForTenantVDC(String tenantName) {
+ return "VDC-" + tenantName;
+ }
+
+ private String getNameForEdgeDeviceServiceProfile(String tenantName) {
+ return "EDSP-" + tenantName;
+ }
+
+ private String getNameForEdgeDeviceSecurityProfile(String tenantName) {
+ return "ESP-" + tenantName;
+ }
+
+ private String getNameForEdgeDeviceRoutePolicy(String tenantName) {
+ return "EDSP-" + tenantName + "-Routes";//FIXME: this has to match DN somehow?
+ }
+
+ /* (non-Javadoc)
+ * @see com.cloud.network.resource.CiscoVnmcConnection#createTenant(java.lang.String)
+ */
+ @Override
+ public boolean createTenant(String tenantName) throws ExecutionException {
+ String xml = VnmcXml.CREATE_TENANT.getXml();
+ String service = VnmcXml.CREATE_TENANT.getService();
+ xml = replaceXmlValue(xml, "cookie", _cookie);
+ xml = replaceXmlValue(xml, "descr", "Tenant for account " + tenantName);
+ xml = replaceXmlValue(xml, "name", tenantName);
+ xml = replaceXmlValue(xml, "dn", getDnForTenant(tenantName));
+
+ String response = sendRequest(service, xml);
+ return verifySuccess(response);
+ }
+
+ /* (non-Javadoc)
+ * @see com.cloud.network.resource.CiscoVnmcConnection#createTenantVDC(java.lang.String)
+ */
+ @Override
+ public boolean createTenantVDC(String tenantName) throws ExecutionException {
+ String xml = VnmcXml.CREATE_VDC.getXml();
+ String service = VnmcXml.CREATE_VDC.getService();
+ xml = replaceXmlValue(xml, "cookie", _cookie);
+ xml = replaceXmlValue(xml, "descr", "VDC for Tenant" + tenantName);
+ xml = replaceXmlValue(xml, "name", getNameForTenantVDC(tenantName));
+ xml = replaceXmlValue(xml, "dn", getDnForTenantVDC(tenantName));
+
+ String response = sendRequest(service, xml);
+
+ return verifySuccess(response);
+ }
+
+ /* (non-Javadoc)
+ * @see com.cloud.network.resource.CiscoVnmcConnection#createTenantVDCEdgeDeviceProfile(java.lang.String)
+ */
+ @Override
+ public boolean createTenantVDCEdgeDeviceProfile(String tenantName) throws ExecutionException {
+ String xml = VnmcXml.CREATE_EDGE_DEVICE_PROFILE.getXml();
+ String service = VnmcXml.CREATE_EDGE_DEVICE_PROFILE.getService();
+ xml = replaceXmlValue(xml, "cookie", _cookie);
+ xml = replaceXmlValue(xml, "descr", "Edge Device Profile for Tenant VDC" + tenantName);
+ xml = replaceXmlValue(xml, "name", getNameForEdgeDeviceServiceProfile(tenantName));
+ xml = replaceXmlValue(xml, "dn", getDnForTenantVDCEdgeDeviceProfile(tenantName));
+
+ String response = sendRequest(service, xml);
+
+ return verifySuccess(response);
+ }
+
+ /* (non-Javadoc)
+ * @see com.cloud.network.resource.CiscoVnmcConnection#createTenantVDCEdgeStaticRoutePolicy(java.lang.String)
+ */
+ @Override
+ public boolean createTenantVDCEdgeStaticRoutePolicy(String tenantName) throws ExecutionException {
+ String xml = VnmcXml.CREATE_EDGE_ROUTE_POLICY.getXml();
+ String service = VnmcXml.CREATE_EDGE_ROUTE_POLICY.getService();
+ xml = replaceXmlValue(xml, "cookie", _cookie);
+ xml = replaceXmlValue(xml, "name", getNameForEdgeDeviceRoutePolicy(tenantName));//FIXME: this has to match DN somehow?
+ xml = replaceXmlValue(xml, "routepolicydn", getDnForEdgeDeviceRoutingPolicy(tenantName));
+ xml = replaceXmlValue(xml, "descr", "Routing Policy for Edge Device for Tenant " + tenantName);
+
+
+ String response = sendRequest(service, xml);
+ return verifySuccess(response);
+ }
+
+ /* (non-Javadoc)
+ * @see com.cloud.network.resource.CiscoVnmcConnection#createTenantVDCEdgeStaticRoute(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
+ */
+ @Override
+ public boolean createTenantVDCEdgeStaticRoute(String tenantName,
+ String nextHopIp, String outsideIntf,
+ String destination, String netmask) throws ExecutionException {
+ String xml = VnmcXml.CREATE_EDGE_ROUTE.getXml();
+ String service = VnmcXml.CREATE_EDGE_ROUTE.getService();
+ xml = replaceXmlValue(xml, "cookie", _cookie);
+ xml = replaceXmlValue(xml, "routedn", getDnForEdgeDeviceRoute(tenantName, 2));//TODO: why 2?
+ xml = replaceXmlValue(xml, "id", "2"); // TODO:2?
+ xml = replaceXmlValue(xml, "nexthop", nextHopIp);
+ xml = replaceXmlValue(xml, "nexthopintf", outsideIntf);
+ xml = replaceXmlValue(xml, "destination", destination);
+ xml = replaceXmlValue(xml, "netmask", netmask);
+
+ //TODO: this adds default route, make it more generic
+
+ String response = sendRequest(service, xml);
+ return verifySuccess(response);
+ }
+
+ /* (non-Javadoc)
+ * @see com.cloud.network.resource.CiscoVnmcConnection#associateTenantVDCEdgeStaticRoutePolicy(java.lang.String)
+ */
+ @Override
+ public boolean associateTenantVDCEdgeStaticRoutePolicy(String tenantName) throws ExecutionException {
+ String xml = VnmcXml.RESOLVE_EDGE_ROUTE_POLICY.getXml();
+ String service = VnmcXml.RESOLVE_EDGE_ROUTE_POLICY.getService();
+ xml = replaceXmlValue(xml, "cookie", _cookie);
+ xml = replaceXmlValue(xml, "profilename", getNameForEdgeDeviceServiceProfile(tenantName));
+ xml = replaceXmlValue(xml, "profiledn", getDnForTenantVDC(tenantName) + "/edsp-" + getNameForEdgeDeviceServiceProfile(tenantName));
+ xml = replaceXmlValue(xml, "routepolicyname", getNameForEdgeDeviceRoutePolicy(tenantName));
+
+ String response = sendRequest(service, xml);
+ return verifySuccess(response);
+ }
+
+ /* (non-Javadoc)
+ * @see com.cloud.network.resource.CiscoVnmcConnection#associateTenantVDCEdgeDhcpPolicy(java.lang.String, java.lang.String)
+ */
+ @Override
+ public boolean associateTenantVDCEdgeDhcpPolicy(String tenantName, String intfName) throws ExecutionException {
+ String xml = VnmcXml.RESOLVE_EDGE_DHCP_POLICY.getXml();
+ String service = VnmcXml.RESOLVE_EDGE_DHCP_POLICY.getService();
+ xml = replaceXmlValue(xml, "cookie", _cookie);
+ xml = replaceXmlValue(xml, "dhcpdn", getDnForDhcpPolicy(tenantName, intfName));
+ xml = replaceXmlValue(xml, "insideintf", intfName);
+
+ String response = sendRequest(service, xml);
+
+ return verifySuccess(response);
+ }
+
+ /* (non-Javadoc)
+ * @see com.cloud.network.resource.CiscoVnmcConnection#createTenantVDCEdgeDhcpPolicy(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
+ */
+ @Override
+ public boolean createTenantVDCEdgeDhcpPolicy(String tenantName,
+ String startIp, String endIp, String subnet, String nameServerIp, String domain) throws ExecutionException {
+ String xml = VnmcXml.CREATE_DHCP_POLICY.getXml();
+ String service = VnmcXml.CREATE_DHCP_POLICY.getService();
+ xml = replaceXmlValue(xml, "cookie", _cookie);
+ xml = replaceXmlValue(xml, "dhcpserverdn", getDnForDhcpServerPolicy(tenantName));
+ xml = replaceXmlValue(xml, "dhcpserverdescr", "DHCP server for " + tenantName);
+ xml = replaceXmlValue(xml, "dhcpservername", getNameForDhcpPolicy(tenantName));
+ xml = replaceXmlValue(xml, "iprangedn", getDnForDhcpIpRange(tenantName));
+ xml = replaceXmlValue(xml, "startip", startIp);
+ xml = replaceXmlValue(xml, "endip", endIp);
+ xml = replaceXmlValue(xml, "subnet", subnet);
+ xml = replaceXmlValue(xml, "domain", domain);
+ xml = replaceXmlValue(xml, "dnsservicedn", getDnForDnsService(tenantName));
+ xml = replaceXmlValue(xml, "dnsservicename", getNameForDNSService(tenantName));
+ xml = replaceXmlValue(xml, "nameserverip", nameServerIp);
+ xml = replaceXmlValue(xml, "nameserverdn", getDnForDnsServer(tenantName, nameServerIp));
+
+ String response = sendRequest(service, xml);
+ return verifySuccess(response);
+ }
+
+ /* (non-Javadoc)
+ * @see com.cloud.network.resource.CiscoVnmcConnection#associateTenantVDCEdgeDhcpServerPolicy(java.lang.String, java.lang.String)
+ */
+ @Override
+ public boolean associateTenantVDCEdgeDhcpServerPolicy(String tenantName, String intfName) throws ExecutionException {
+ String xml = VnmcXml.RESOLVE_EDGE_DHCP_SERVER_POLICY.getXml();
+ String service = VnmcXml.RESOLVE_EDGE_DHCP_SERVER_POLICY.getService();
+ xml = replaceXmlValue(xml, "cookie", _cookie);
+ xml = replaceXmlValue(xml, "dhcpdn", getDnForDhcpPolicy(tenantName, intfName));
+ xml = replaceXmlValue(xml, "insideintf", intfName);
+ xml = replaceXmlValue(xml, "dhcpserverpolicyname", getNameForDhcpServer(tenantName));
+
+ String response = sendRequest(service, xml);
+ return verifySuccess(response);
+ }
+
+ /* (non-Javadoc)
+ * @see com.cloud.network.resource.CiscoVnmcConnection#createTenantVDCEdgeSecurityProfile(java.lang.String)
+ */
+ @Override
+ public boolean createTenantVDCEdgeSecurityProfile(String tenantName) throws ExecutionException {
+ String xml = VnmcXml.CREATE_EDGE_SECURITY_PROFILE.getXml();
+ String service = VnmcXml.CREATE_EDGE_SECURITY_PROFILE.getService();
+ xml = replaceXmlValue(xml, "cookie", _cookie);
+ xml = replaceXmlValue(xml, "descr", "Edge Security Profile for Tenant VDC" + tenantName);
+ xml = replaceXmlValue(xml, "name", getNameForEdgeDeviceSecurityProfile(tenantName));
+ xml = replaceXmlValue(xml, "espdn", getDnForTenantVDCEdgeSecurityProfile(tenantName));
+ xml = replaceXmlValue(xml, "egressref", "default-egress");
+ xml = replaceXmlValue(xml, "ingressref", "default-ingress"); //FIXME: allows everything
+
+ String response = sendRequest(service, xml);
+
+ return verifySuccess(response);
+ }
+
+ private String getNameForSourceNatPool(String tenantName) {
+ return "Source-NAT-Pool-For-" + tenantName;
+ }
+
+ private String getDnForSourceNatPool(String tenantName) {
+ return getDnForTenantVDC(tenantName) + "/objgrp-" + getNameForSourceNatPool(tenantName);
+ }
+
+ private String getDnForSourceNatPoolExpr(String tenantName) {
+ return getDnForSourceNatPool(tenantName) + "/objgrp-expr-2";
+ }
+
+ private String getDnForSourceNatPublicIp(String tenantName) {
+ return getDnForSourceNatPoolExpr(tenantName) + "/nw-ip-2";
+ }
+
+ /* (non-Javadoc)
+ * @see com.cloud.network.resource.CiscoVnmcConnection#createTenantVDCSourceNATPool(java.lang.String, java.lang.String)
+ */
+ @Override
+ public boolean createTenantVDCSourceNATPool(String tenantName, String publicIp) throws ExecutionException {
+ String xml = VnmcXml.CREATE_SOURCE_NAT_POOL.getXml();
+ String service = VnmcXml.CREATE_SOURCE_NAT_POOL.getService();
+ xml = replaceXmlValue(xml, "cookie", _cookie);
+ xml = replaceXmlValue(xml, "descr", "Source NAT pool for Tenant VDC " + tenantName);
+ xml = replaceXmlValue(xml, "name", getNameForSourceNatPool(tenantName));
+ xml = replaceXmlValue(xml, "snatpooldn", getDnForSourceNatPool(tenantName));
+ xml = replaceXmlValue(xml, "snatpoolexprdn", getDnForSourceNatPoolExpr(tenantName));
+ xml = replaceXmlValue(xml, "publicipdn", getDnForSourceNatPublicIp(tenantName));
+ xml = replaceXmlValue(xml, "publicip", publicIp);
+
+ String response = sendRequest(service, xml);
+
+ return verifySuccess(response);
+ }
+
+
+ private String getNameForSourceNatPolicy(String tenantName) {
+ return "Source-NAT-For-" + tenantName;
+ }
+
+ private String getDnForSourceNatPolicy(String tenantName) {
+ return getDnForTenantVDC(tenantName) + "/natpol-" + getNameForSourceNatPolicy(tenantName);
+ }
+
+ private String getNameForSourceNatRule(String tenantName) {
+ return "Source-NAT-Policy-Rule-" + tenantName;
+ }
+
+ private String getDnForSourceNatRule(String tenantName) {
+ return getDnForSourceNatPolicy(tenantName) + "/rule-" + getNameForSourceNatRule(tenantName);
+ }
+
+ private String getDnForSourceNatRuleAction(String tenantName) {
+ return getDnForSourceNatRule(tenantName) + "/nat-action";
+ }
+
+ private String getDnForSourceNatRuleRule(String tenantName) {
+ return getDnForSourceNatRule(tenantName) + "/rule-cond-2";
+ }
+
+ private String getDnForSourceNatRuleRange(String tenantName) {
+ return getDnForSourceNatRuleRule(tenantName) + "/nw-expr2";
+ }
+
+ private String getDnForSourceNatRuleRangeIp(String tenantName, int id) {
+ return getDnForSourceNatRuleRange(tenantName) + "/nw-ip-" + id;
+ }
+
+ private String getDnForSourceNatRuleRangeAttr(String tenantName) {
+ return getDnForSourceNatRuleRange(tenantName) + "/nw-attr-qual";
+ }
+
+ /* (non-Javadoc)
+ * @see com.cloud.network.resource.CiscoVnmcConnection#createTenantVDCSourceNATPolicy(java.lang.String, java.lang.String, java.lang.String)
+ */
+ @Override
+ public boolean createTenantVDCSourceNATPolicy(String tenantName,
+ String startSourceIp, String endSourceIp) throws ExecutionException {
+
+ String xml = VnmcXml.CREATE_SOURCE_NAT_POLICY.getXml();
+ String service = VnmcXml.CREATE_SOURCE_NAT_POLICY.getService();
+ xml = replaceXmlValue(xml, "cookie", _cookie);
+ xml = replaceXmlValue(xml, "descr", "Source NAT Policy for Tenant VDC " + tenantName);
+ xml = replaceXmlValue(xml, "srcTranslatedIpPool", getNameForSourceNatPool(tenantName));
+ xml = replaceXmlValue(xml, "natrulename", getNameForSourceNatRule(tenantName));
+ xml = replaceXmlValue(xml, "natpolname", getNameForSourceNatPolicy(tenantName));
+ xml = replaceXmlValue(xml, "natruleruledescr", "Source NAT Policy for Tenant " + tenantName);
+ xml = replaceXmlValue(xml, "natpoldescr", "Source NAT Rule for Tenant " + tenantName);
+ xml = replaceXmlValue(xml, "natpoldn", getDnForSourceNatPolicy(tenantName));
+ xml = replaceXmlValue(xml, "natruledn", getDnForSourceNatRule(tenantName));
+ xml = replaceXmlValue(xml, "sourcestartip", startSourceIp);
+ xml = replaceXmlValue(xml, "sourceendip", endSourceIp);
+ xml = replaceXmlValue(xml, "sourcenatpoolname", getNameForSourceNatPool(tenantName));
+
+
+ xml = replaceXmlValue(xml, "natactiondn", getDnForSourceNatRuleAction(tenantName));
+ xml = replaceXmlValue(xml, "natruleruledn", getDnForSourceNatRuleRule(tenantName));
+ xml = replaceXmlValue(xml, "natrangedn", getDnForSourceNatRuleRange(tenantName));
+ xml = replaceXmlValue(xml, "natipdn2", getDnForSourceNatRuleRangeIp(tenantName, 2));
+ xml = replaceXmlValue(xml, "natipdn3", getDnForSourceNatRuleRangeIp(tenantName, 3));
+
+ xml = replaceXmlValue(xml, "natsnatruleconddn", getDnForSourceNatRuleRangeAttr(tenantName));
+
+ String response = sendRequest(service, xml);
+
+ return verifySuccess(response);
+ }
+
+ private String getNameForNatPolicySet(String tenantName) {
+ return "NAT-Policy-Set-" + tenantName;
+ }
+
+ private String getDnForNatPolicySet(String tenantName) {
+ return getDnForTenantVDC(tenantName) + "/natpset-" + getNameForNatPolicySet(tenantName) ;
+ }
+
+ private String getDnForNatPolicySetRef(String tenantName) {
+ return getDnForNatPolicySet(tenantName) + "/polref-" + getNameForSourceNatPolicy(tenantName) ;
+ }
+
+ /* (non-Javadoc)
+ * @see com.cloud.network.resource.CiscoVnmcConnection#createTenantVDCNatPolicySet(java.lang.String)
+ */
+ @Override
+ public boolean createTenantVDCNatPolicySet(String tenantName) throws ExecutionException {
+ String xml = VnmcXml.CREATE_NAT_POLICY_SET.getXml();
+ String service = VnmcXml.CREATE_NAT_POLICY_SET.getService();
+ xml = replaceXmlValue(xml, "cookie", _cookie);
+ //xml = replaceXmlValue(xml, "descr", "Nat Policy Set for Tenant VDC " + tenantName);
+ xml = replaceXmlValue(xml, "natpolicyname", getNameForSourceNatPolicy(tenantName));
+ xml = replaceXmlValue(xml, "natpolicysetname", getNameForNatPolicySet(tenantName));
+ xml = replaceXmlValue(xml, "natpolicysetdn", getDnForNatPolicySet(tenantName));
+ xml = replaceXmlValue(xml, "natpolicyrefdn", getDnForNatPolicySetRef(tenantName));
+
+ String response = sendRequest(service, xml);
+
+ return verifySuccess(response);
+ }
+
+ /* (non-Javadoc)
+ * @see com.cloud.network.resource.CiscoVnmcConnection#associateNatPolicySet(java.lang.String)
+ */
+ @Override
+ public boolean associateNatPolicySet(String tenantName) throws ExecutionException {
+ String xml = VnmcXml.RESOLVE_NAT_POLICY_SET.getXml();
+ String service = VnmcXml.RESOLVE_NAT_POLICY_SET.getService();
+ xml = replaceXmlValue(xml, "cookie", _cookie);
+ xml = replaceXmlValue(xml, "descr", "Edge Security Profile for Tenant VDC" + tenantName);
+ xml = replaceXmlValue(xml, "name", getNameForEdgeDeviceSecurityProfile(tenantName));
+ xml = replaceXmlValue(xml, "espdn", getDnForTenantVDCEdgeSecurityProfile(tenantName));
+ xml = replaceXmlValue(xml, "egressref", "default-egress");
+ xml = replaceXmlValue(xml, "ingressref", "default-ingress");
+ xml = replaceXmlValue(xml, "natpolicysetname", getNameForNatPolicySet(tenantName));
+
+ String response = sendRequest(service, xml);
+
+ return verifySuccess(response);
+ }
+
+ private String getNameForEdgeFirewall(String tenantName) {
+ return "ASA-1000v-" + tenantName;
+ }
+
+ private String getDnForEdgeFirewall(String tenantName) {
+ return getDnForTenantVDC(tenantName) + "/efw-" + getNameForEdgeFirewall(tenantName);
+ }
+
+ private String getNameForEdgeInsideIntf(String tenantName) {
+ return "Edge_Inside"; //TODO: make this configurable
+ }
+
+ private String getNameForEdgeOutsideIntf(String tenantName) {
+ return "Edge_Outside"; //TODO: make this configurable
+ }
+
+ private String getDnForOutsideIntf(String tenantName) {
+ return getDnForEdgeFirewall(tenantName) + "/interface-" + getNameForEdgeOutsideIntf(tenantName);
+ }
+
+ private String getDnForInsideIntf(String tenantName) {
+ return getDnForEdgeFirewall(tenantName) + "/interface-" + getNameForEdgeInsideIntf(tenantName);
+ }
+
+ /* (non-Javadoc)
+ * @see com.cloud.network.resource.CiscoVnmcConnection#createEdgeFirewall(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
+ */
+ @Override
+ public boolean createEdgeFirewall(String tenantName, String publicIp, String insideIp,
+ String insideSubnet, String outsideSubnet) throws ExecutionException {
+
+ String xml = VnmcXml.CREATE_EDGE_FIREWALL.getXml();
+ String service = VnmcXml.CREATE_EDGE_FIREWALL.getService();
+ xml = replaceXmlValue(xml, "cookie", _cookie);
+ xml = replaceXmlValue(xml, "edgefwdescr", "Edge Firewall for Tenant VDC " + tenantName);
+ xml = replaceXmlValue(xml, "edgefwname", getNameForEdgeFirewall(tenantName));
+ xml = replaceXmlValue(xml, "edgefwdn", getDnForEdgeFirewall(tenantName));
+ xml = replaceXmlValue(xml, "insideintfname", getNameForEdgeInsideIntf(tenantName));
+ xml = replaceXmlValue(xml, "outsideintfname", getNameForEdgeOutsideIntf(tenantName));
+
+ xml = replaceXmlValue(xml, "insideintfdn", getDnForInsideIntf(tenantName));
+ xml = replaceXmlValue(xml, "outsideintfdn", getDnForOutsideIntf(tenantName));
+
+ xml = replaceXmlValue(xml, "deviceserviceprofiledn", getDnForEdgeFirewall(tenantName) + "/device-service-profile");
+ xml = replaceXmlValue(xml, "outsideintfsp", getDnForOutsideIntf(tenantName) + "/interface-service-profile");
+
+ xml = replaceXmlValue(xml, "secprofileref", getNameForEdgeDeviceSecurityProfile(tenantName));
+ xml = replaceXmlValue(xml, "deviceserviceprofile", getNameForEdgeDeviceServiceProfile(tenantName));
+
+
+ xml = replaceXmlValue(xml, "insideip", insideIp);
+ xml = replaceXmlValue(xml, "publicip", publicIp);
+ xml = replaceXmlValue(xml, "insidesubnet", insideSubnet);
+ xml = replaceXmlValue(xml, "outsidesubnet", outsideSubnet);
+
+ String response = sendRequest(service, xml);
+
+ return verifySuccess(response);
+
+ }
+
+
+ /* (non-Javadoc)
+ * @see com.cloud.network.resource.CiscoVnmcConnection#listUnAssocAsa1000v()
+ */
+ @Override
+ public List<String> listUnAssocAsa1000v() throws ExecutionException {
+
+ String xml = VnmcXml.LIST_UNASSOC_ASA1000V.getXml();
+ String service = VnmcXml.LIST_UNASSOC_ASA1000V.getService();
+ xml = replaceXmlValue(xml, "cookie", _cookie);
+
+
+ String response = sendRequest(service, xml);
+
+ List<String> result = new ArrayList<String>();
+
+ Document xmlDoc = getDocument(response);
+ xmlDoc.normalize();
+ NodeList fwList = xmlDoc.getElementsByTagName("fwInstance");
+ for (int j=0; j < fwList.getLength(); j++) {
+ Node fwNode = fwList.item(j);
+ result.add (fwNode.getAttributes().getNamedItem("dn").getNodeValue());
+
+ }
+
+ return result;
+
+ }
+
+ /* (non-Javadoc)
+ * @see com.cloud.network.resource.CiscoVnmcConnection#assocAsa1000v(java.lang.String, java.lang.String)
+ */
+ @Override
+ public boolean assocAsa1000v(String tenantName, String firewallDn) throws ExecutionException {
+
+ String xml = VnmcXml.ASSIGN_ASA1000V.getXml();
+ String service = VnmcXml.ASSIGN_ASA1000V.getService();
+ xml = replaceXmlValue(xml, "cookie", _cookie);
+ xml = replaceXmlValue(xml, "binddn", getDnForEdgeFirewall(tenantName) + "/binding");
+ xml = replaceXmlValue(xml, "fwdn", firewallDn);
+
+ String response = sendRequest(service, xml);
+
+ return verifySuccess(response);
+
+ }
+
+
+ private String sendRequest(String service, String xmlRequest) throws ExecutionException {
+ org.apache.commons.httpclient.protocol.Protocol myhttps =
+ new org.apache.commons.httpclient.protocol.Protocol("https", new EasySSLProtocolSocketFactory(), 443);
+ HttpClient client = new HttpClient();
+ client.getHostConfiguration().setHost(_ip, 443, myhttps);
+ byte[] response = null;
+ PostMethod method = new PostMethod("/xmlIM/" + service);
+
+ method.setRequestBody(xmlRequest);
+
+ try{
+ int statusCode = client.executeMethod(method);
+
+ if (statusCode != HttpStatus.SC_OK) {
+ throw new Exception("Error code : " + statusCode);
+ }
+ response = method.getResponseBody();
+ }catch(Exception e){
+ System.out.println(e.getMessage());
+ throw new ExecutionException(e.getMessage());
+ }
+ System.out.println(new String(response));
+ return new String(response);
+ }
+
+ private Map<String, String> checkResponse(String xmlResponse, String... keys) throws ExecutionException {
+ Document xmlDoc = getDocument(xmlResponse);
+ Map<String, String> result = new HashMap<String, String>();
+ Node topElement = xmlDoc.getChildNodes().item(0);
+ if (topElement != null) {
+ for (String key: keys){
+ Node valueNode = topElement.getAttributes().getNamedItem(key);
+ result.put(key, valueNode==null?null:valueNode.getNodeValue());
+ }
+ }
+ return result;
+ }
+
+ private boolean verifySuccess(String xmlResponse) throws ExecutionException {
+ Map<String, String> checked = checkResponse(xmlResponse, "errorCode", "errorDescr");
+
+ if (checked.get("errorCode") != null) {
+ String errorCode = checked.get("errorCode");
+ if (errorCode.equals("103")) {
+ //tenant already exists
+ return true;
+ }
+ String errorDescr = checked.get("errorDescr");
+ throw new ExecutionException(errorDescr);
+ }
+ return true;
+ }
+
+ /*
+ * XML utils
+ */
+
+ private Document getDocument(String xml) throws ExecutionException {
+ StringReader xmlReader = new StringReader("<?xml version=\"1.0\"?> \n" + xml.trim());
+ InputSource xmlSource = new InputSource(xmlReader);
+ Document doc = null;
+
+ try {
+ doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(xmlSource);
+
+ } catch (Exception e) {
+ s_logger.error(e);
+ throw new ExecutionException(e.getMessage());
+ }
+
+ if (doc == null) {
+ throw new ExecutionException("Failed to parse xml " + xml);
+ } else {
+ return doc;
+ }
+ }
+
+ private String replaceXmlTag(String xml, String oldTag, String newTag) {
+ return xml.replaceAll(oldTag, newTag);
+ }
+
+ private String replaceXmlValue(String xml, String marker, String value) {
+ marker = "\\s*%" + marker + "%\\s*";
+
+ if (value == null) {
+ value = "";
+ }
+
+ return xml.replaceAll(marker, value);
+ }
+
+ private String extractXml(String xml, String marker) {
+ String startMarker = "<" + marker + ">";
+ String endMarker = "</" + marker + ">";
+ if (xml.contains(startMarker) && xml.contains(endMarker)) {
+ return xml.substring(xml.indexOf(startMarker) + startMarker.length(), xml.indexOf(endMarker));
+ } else {
+ return null;
+ }
+
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/1ae21ea4/plugins/network-elements/cisco-vnmc/src/com/cloud/network/cisco/CiscoVnmcDeviceVO.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/cisco-vnmc/src/com/cloud/network/cisco/CiscoVnmcDeviceVO.java b/plugins/network-elements/cisco-vnmc/src/com/cloud/network/cisco/CiscoVnmcDeviceVO.java
deleted file mode 100644
index e3a6d6d..0000000
--- a/plugins/network-elements/cisco-vnmc/src/com/cloud/network/cisco/CiscoVnmcDeviceVO.java
+++ /dev/null
@@ -1,95 +0,0 @@
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-package com.cloud.network.cisco;
-
-import java.util.UUID;
-
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.GenerationType;
-import javax.persistence.Id;
-import javax.persistence.Table;
-
-@Entity
-@Table(name="external_cisco_vnmc_devices")
-public class CiscoVnmcDeviceVO {
-
- @Id
- @GeneratedValue(strategy = GenerationType.IDENTITY)
- @Column(name="id")
- private long id;
-
- @Column(name="uuid")
- private String uuid;
-
- @Column(name="host_id")
- private long hostId;
-
- @Column(name="physical_network_id")
- private long physicalNetworkId;
-
- @Column(name="provider_name")
- private String providerName;
-
- @Column(name="device_name")
- private String deviceName;
-
-
- public CiscoVnmcDeviceVO() {
- this.uuid = UUID.randomUUID().toString();
- }
-
- public CiscoVnmcDeviceVO(long hostId, long physicalNetworkId,
- String providerName, String deviceName) {
- super();
- this.hostId = hostId;
- this.physicalNetworkId = physicalNetworkId;
- this.providerName = providerName;
- this.deviceName = deviceName;
- this.uuid = UUID.randomUUID().toString();
- }
-
- public long getId() {
- return id;
- }
-
- public String getUuid() {
- return uuid;
- }
-
- public void setUuid(String uuid) {
- this.uuid = uuid;
- }
-
- public long getPhysicalNetworkId() {
- return physicalNetworkId;
- }
-
- public long getHostId() {
- return hostId;
- }
-
- public String getProviderName() {
- return providerName;
- }
-
- public String getDeviceName() {
- return deviceName;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/1ae21ea4/plugins/network-elements/cisco-vnmc/src/com/cloud/network/cisco/CiscoVnmcManager.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/cisco-vnmc/src/com/cloud/network/cisco/CiscoVnmcManager.java b/plugins/network-elements/cisco-vnmc/src/com/cloud/network/cisco/CiscoVnmcManager.java
index fcae7c0..5a60a7a 100644
--- a/plugins/network-elements/cisco-vnmc/src/com/cloud/network/cisco/CiscoVnmcManager.java
+++ b/plugins/network-elements/cisco-vnmc/src/com/cloud/network/cisco/CiscoVnmcManager.java
@@ -1,5 +1,6 @@
package com.cloud.network.cisco;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -8,10 +9,10 @@ import java.util.UUID;
import javax.naming.ConfigurationException;
import com.cloud.agent.AgentManager;
-import com.cloud.api.commands.AddCiscoVnmcDeviceCmd;
-import com.cloud.api.commands.DeleteCiscoVnmcDeviceCmd;
-import com.cloud.api.commands.ListCiscoVnmcDevicesCmd;
-import com.cloud.api.response.CiscoVnmcDeviceResponse;
+import com.cloud.api.commands.AddCiscoVnmcResourceCmd;
+import com.cloud.api.commands.DeleteCiscoVnmcResourceCmd;
+import com.cloud.api.commands.ListCiscoVnmcResourcesCmd;
+import com.cloud.api.response.CiscoVnmcResourceResponse;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.host.DetailVO;
import com.cloud.host.Host;
@@ -53,17 +54,19 @@ public class CiscoVnmcManager implements Manager, CiscoVnmcElementService {
@Inject
NetworkDao _networkDao;
+ CiscoVnmcConnection _vnmcConnection;
+
@Override
public String getPropertiesFile() {
return null;
}
@Override
- public CiscoVnmcDeviceVO addCiscoVnmcDevice(AddCiscoVnmcDeviceCmd cmd) {
+ public CiscoVnmcResourceVO addCiscoVnmcResource(AddCiscoVnmcResourceCmd cmd) {
String deviceName = CiscoVnmc.getName();
NetworkDevice networkDevice = NetworkDevice.getNetworkDevice(deviceName);
Long physicalNetworkId = cmd.getPhysicalNetworkId();
- CiscoVnmcDeviceVO ciscoVnmcDevice = null;
+ CiscoVnmcResourceVO CiscoVnmcResource = null;
PhysicalNetworkVO physicalNetwork = _physicalNetworkDao.findById(physicalNetworkId);
if (physicalNetwork == null) {
@@ -107,14 +110,14 @@ public class CiscoVnmcManager implements Manager, CiscoVnmcElementService {
if (host != null) {
txn.start();
- ciscoVnmcDevice = new CiscoVnmcDeviceVO(host.getId(), physicalNetworkId, ntwkSvcProvider.getProviderName(), deviceName);
- _ciscoVnmcDao.persist(ciscoVnmcDevice);
+ CiscoVnmcResource = new CiscoVnmcResourceVO(host.getId(), physicalNetworkId, ntwkSvcProvider.getProviderName(), deviceName);
+ _ciscoVnmcDao.persist(CiscoVnmcResource);
- DetailVO detail = new DetailVO(host.getId(), "deviceid", String.valueOf(ciscoVnmcDevice.getId()));
+ DetailVO detail = new DetailVO(host.getId(), "deviceid", String.valueOf(CiscoVnmcResource.getId()));
_hostDetailsDao.persist(detail);
txn.commit();
- return ciscoVnmcDevice;
+ return CiscoVnmcResource;
} else {
throw new CloudRuntimeException("Failed to add Cisco Vnmc Device due to internal error.");
}
@@ -125,14 +128,14 @@ public class CiscoVnmcManager implements Manager, CiscoVnmcElementService {
}
@Override
- public CiscoVnmcDeviceResponse createCiscoVnmcDeviceResponse(
- CiscoVnmcDeviceVO ciscoVnmcDeviceVO) {
+ public CiscoVnmcResourceResponse createCiscoVnmcResourceResponse(
+ CiscoVnmcResourceVO CiscoVnmcResourceVO) {
// TODO Auto-generated method stub
return null;
}
@Override
- public boolean deleteCiscoVnmcDevice(DeleteCiscoVnmcDeviceCmd cmd) {
+ public boolean deleteCiscoVnmcResource(DeleteCiscoVnmcResourceCmd cmd) {
// TODO Auto-generated method stub
return false;
}
@@ -140,10 +143,32 @@ public class CiscoVnmcManager implements Manager, CiscoVnmcElementService {
@Override
- public List<CiscoVnmcDeviceVO> listCiscoVnmcDevices(
- ListCiscoVnmcDevicesCmd cmd) {
- // TODO Auto-generated method stub
- return null;
+ public List<CiscoVnmcResourceVO> listCiscoVnmcResources(
+ ListCiscoVnmcResourcesCmd cmd) {
+ Long physicalNetworkId = cmd.getPhysicalNetworkId();
+ Long CiscoVnmcResourceId = cmd.getCiscoVnmcResourceId();
+ List<CiscoVnmcResourceVO> responseList = new ArrayList<CiscoVnmcResourceVO>();
+
+ if (physicalNetworkId == null && CiscoVnmcResourceId == null) {
+ throw new InvalidParameterValueException("Either physical network Id or vnmc device Id must be specified");
+ }
+
+ if (CiscoVnmcResourceId != null) {
+ CiscoVnmcResourceVO CiscoVnmcResource = _ciscoVnmcDao.findById(CiscoVnmcResourceId);
+ if (CiscoVnmcResource == null) {
+ throw new InvalidParameterValueException("Could not find Cisco Vnmc device with id: " + CiscoVnmcResource);
+ }
+ responseList.add(CiscoVnmcResource);
+ }
+ else {
+ PhysicalNetworkVO physicalNetwork = _physicalNetworkDao.findById(physicalNetworkId);
+ if (physicalNetwork == null) {
+ throw new InvalidParameterValueException("Could not find a physical network with id: " + physicalNetworkId);
+ }
+ responseList = _ciscoVnmcDao.listByPhysicalNetwork(physicalNetworkId);
+ }
+
+ return responseList;
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/1ae21ea4/plugins/network-elements/cisco-vnmc/src/com/cloud/network/cisco/CiscoVnmcResourceVO.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/cisco-vnmc/src/com/cloud/network/cisco/CiscoVnmcResourceVO.java b/plugins/network-elements/cisco-vnmc/src/com/cloud/network/cisco/CiscoVnmcResourceVO.java
new file mode 100644
index 0000000..f57c6f5
--- /dev/null
+++ b/plugins/network-elements/cisco-vnmc/src/com/cloud/network/cisco/CiscoVnmcResourceVO.java
@@ -0,0 +1,95 @@
+// 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.cisco;
+
+import java.util.UUID;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+@Entity
+@Table(name="external_cisco_vnmc_devices")
+public class CiscoVnmcResourceVO {
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ @Column(name="id")
+ private long id;
+
+ @Column(name="uuid")
+ private String uuid;
+
+ @Column(name="host_id")
+ private long hostId;
+
+ @Column(name="physical_network_id")
+ private long physicalNetworkId;
+
+ @Column(name="provider_name")
+ private String providerName;
+
+ @Column(name="device_name")
+ private String deviceName;
+
+
+ public CiscoVnmcResourceVO() {
+ this.uuid = UUID.randomUUID().toString();
+ }
+
+ public CiscoVnmcResourceVO(long hostId, long physicalNetworkId,
+ String providerName, String deviceName) {
+ super();
+ this.hostId = hostId;
+ this.physicalNetworkId = physicalNetworkId;
+ this.providerName = providerName;
+ this.deviceName = deviceName;
+ this.uuid = UUID.randomUUID().toString();
+ }
+
+ public long getId() {
+ return id;
+ }
+
+ public String getUuid() {
+ return uuid;
+ }
+
+ public void setUuid(String uuid) {
+ this.uuid = uuid;
+ }
+
+ public long getPhysicalNetworkId() {
+ return physicalNetworkId;
+ }
+
+ public long getHostId() {
+ return hostId;
+ }
+
+ public String getProviderName() {
+ return providerName;
+ }
+
+ public String getDeviceName() {
+ return deviceName;
+ }
+
+}