You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by bh...@apache.org on 2012/12/08 04:29:50 UTC
[13/57] api: Refactor command and response classes to
org.apache.cloudstack.api.*
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/e398b1e4/api/src/org/apache/cloudstack/api/command/user/vpc/ListVPCOfferingsCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/vpc/ListVPCOfferingsCmd.java b/api/src/org/apache/cloudstack/api/command/user/vpc/ListVPCOfferingsCmd.java
new file mode 100644
index 0000000..04b2d9a
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/user/vpc/ListVPCOfferingsCmd.java
@@ -0,0 +1,116 @@
+// 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 org.apache.cloudstack.api.command.user.vpc;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseListCmd;
+import org.apache.cloudstack.api.IdentityMapper;
+import org.apache.cloudstack.api.Implementation;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.response.ListResponse;
+import org.apache.cloudstack.api.response.VpcOfferingResponse;
+import com.cloud.network.vpc.VpcOffering;
+
+@Implementation(description="Lists VPC offerings", responseObject=VpcOfferingResponse.class)
+public class ListVPCOfferingsCmd extends BaseListCmd{
+ public static final Logger s_logger = Logger.getLogger(ListVPCOfferingsCmd.class.getName());
+ private static final String _name = "listvpcofferingsresponse";
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+ @IdentityMapper(entityTableName="vpc_offerings")
+ @Parameter(name=ApiConstants.ID, type=CommandType.LONG, description="list VPC offerings by id")
+ private Long id;
+
+ @Parameter(name=ApiConstants.NAME, type=CommandType.STRING, description="list VPC offerings by name")
+ private String vpcOffName;
+
+ @Parameter(name=ApiConstants.DISPLAY_TEXT, type=CommandType.STRING, description="list VPC offerings by display text")
+ private String displayText;
+
+ @Parameter(name=ApiConstants.IS_DEFAULT, type=CommandType.BOOLEAN, description="true if need to list only default " +
+ "VPC offerings. Default value is false")
+ private Boolean isDefault;
+
+ @Parameter(name=ApiConstants.SUPPORTED_SERVICES, type=CommandType.LIST, collectionType=CommandType.STRING,
+ description="list VPC offerings supporting certain services")
+ private List<String> supportedServices;
+
+ @Parameter(name=ApiConstants.STATE, type=CommandType.STRING, description="list VPC offerings by state")
+ private String state;
+
+
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+ public Long getId() {
+ return id;
+ }
+
+ public String getVpcOffName() {
+ return vpcOffName;
+ }
+
+ public String getDisplayText() {
+ return displayText;
+ }
+
+ public Boolean getIsDefault() {
+ return isDefault;
+ }
+
+ public List<String> getSupportedServices() {
+ return supportedServices;
+ }
+
+ public String getState() {
+ return state;
+ }
+
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ /////////////////////////////////////////////////////
+
+ @Override
+ public void execute(){
+ List<? extends VpcOffering> offerings = _vpcService.listVpcOfferings(getId(), getVpcOffName(), getDisplayText(),
+ getSupportedServices(), isDefault, this.getKeyword(), getState(), this.getStartIndex(), this.getPageSizeVal());
+ ListResponse<VpcOfferingResponse> response = new ListResponse<VpcOfferingResponse>();
+ List<VpcOfferingResponse> offeringResponses = new ArrayList<VpcOfferingResponse>();
+ for (VpcOffering offering : offerings) {
+ VpcOfferingResponse offeringResponse = _responseGenerator.createVpcOfferingResponse(offering);
+ offeringResponses.add(offeringResponse);
+ }
+
+ response.setResponses(offeringResponses);
+ response.setResponseName(getCommandName());
+ this.setResponseObject(response);
+ }
+
+
+ @Override
+ public String getCommandName() {
+ return _name;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/e398b1e4/api/src/org/apache/cloudstack/api/command/user/vpc/ListVPCsCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/vpc/ListVPCsCmd.java b/api/src/org/apache/cloudstack/api/command/user/vpc/ListVPCsCmd.java
new file mode 100644
index 0000000..9a244c3
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/user/vpc/ListVPCsCmd.java
@@ -0,0 +1,159 @@
+// 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 org.apache.cloudstack.api.command.user.vpc;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseListTaggedResourcesCmd;
+import org.apache.cloudstack.api.IdentityMapper;
+import org.apache.cloudstack.api.Implementation;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.response.ListResponse;
+import org.apache.cloudstack.api.response.VpcResponse;
+import com.cloud.network.vpc.Vpc;
+
+
+@Implementation(description="Lists VPCs", responseObject=VpcResponse.class)
+public class ListVPCsCmd extends BaseListTaggedResourcesCmd{
+ public static final Logger s_logger = Logger.getLogger(ListVPCsCmd.class.getName());
+ private static final String s_name = "listvpcsresponse";
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+ @IdentityMapper(entityTableName="vpc")
+ @Parameter(name=ApiConstants.ID, type=CommandType.LONG, description="list VPC by id")
+ private Long id;
+
+ @IdentityMapper(entityTableName="data_center")
+ @Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, description="list by zone")
+ private Long zoneId;
+
+ @Parameter(name=ApiConstants.NAME, type=CommandType.STRING, description="list by name of the VPC")
+ private String vpcName;
+
+ @Parameter(name=ApiConstants.DISPLAY_TEXT, type=CommandType.STRING, description="List by display text of " +
+ "the VPC")
+ private String displayText;
+
+ @Parameter(name=ApiConstants.CIDR, type=CommandType.STRING, description="list by cidr of the VPC. All VPC " +
+ "guest networks' cidrs should be within this CIDR")
+ private String cidr;
+
+ @IdentityMapper(entityTableName="vpc_offerings")
+ @Parameter(name=ApiConstants.VPC_OFF_ID, type=CommandType.LONG, description="list by ID of the VPC offering")
+ private Long VpcOffId;
+
+ @Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="list by account associated with the VPC. " +
+ "Must be used with the domainId parameter.")
+ private String accountName;
+
+ @IdentityMapper(entityTableName="domain")
+ @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="list by domain ID associated with the VPC. " +
+ "If used with the account parameter returns the VPC associated with the account for the specified domain.")
+ private Long domainId;
+
+ @Parameter(name=ApiConstants.SUPPORTED_SERVICES, type=CommandType.LIST, collectionType=CommandType.STRING,
+ description="list VPC supporting certain services")
+ private List<String> supportedServices;
+
+ @Parameter(name=ApiConstants.STATE, type=CommandType.STRING, description="list VPCs by state")
+ private String state;
+
+ @Parameter(name=ApiConstants.RESTART_REQUIRED, type=CommandType.BOOLEAN, description="list VPCs by restartRequired option")
+ private Boolean restartRequired;
+
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+
+ public String getAccountName() {
+ return accountName;
+ }
+
+ public Long getDomainId() {
+ return domainId;
+ }
+
+ public Long getZoneId() {
+ return zoneId;
+ }
+
+ public String getVpcName() {
+ return vpcName;
+ }
+
+ public String getCidr() {
+ return cidr;
+ }
+
+ public String getDisplayText() {
+ return displayText;
+ }
+
+ public Long getVpcOffId() {
+ return VpcOffId;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public List<String> getSupportedServices() {
+ return supportedServices;
+ }
+
+ public String getState() {
+ return state;
+ }
+
+ public Boolean getRestartRequired() {
+ return restartRequired;
+ }
+
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ /////////////////////////////////////////////////////
+
+ @Override
+ public void execute() {
+ List<? extends Vpc> vpcs = _vpcService.listVpcs(getId(), getVpcName(), getDisplayText(),
+ getSupportedServices(), getCidr(), getVpcOffId(), getState(), getAccountName(), getDomainId(),
+ this.getKeyword(), this.getStartIndex(), this.getPageSizeVal(), getZoneId(), this.isRecursive(),
+ this.listAll(), getRestartRequired(), getTags(), getProjectId());
+ ListResponse<VpcResponse> response = new ListResponse<VpcResponse>();
+ List<VpcResponse> offeringResponses = new ArrayList<VpcResponse>();
+ for (Vpc vpc : vpcs) {
+ VpcResponse offeringResponse = _responseGenerator.createVpcResponse(vpc);
+ offeringResponses.add(offeringResponse);
+ }
+
+ response.setResponses(offeringResponses);
+ response.setResponseName(getCommandName());
+ this.setResponseObject(response);
+ }
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/e398b1e4/api/src/org/apache/cloudstack/api/command/user/vpc/RestartVPCCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/vpc/RestartVPCCmd.java b/api/src/org/apache/cloudstack/api/command/user/vpc/RestartVPCCmd.java
new file mode 100644
index 0000000..e954474
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/user/vpc/RestartVPCCmd.java
@@ -0,0 +1,110 @@
+// 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 org.apache.cloudstack.api.command.user.vpc;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseAsyncCmd;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.IdentityMapper;
+import org.apache.cloudstack.api.Implementation;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.response.SuccessResponse;
+import org.apache.cloudstack.api.response.VpcResponse;
+import com.cloud.event.EventTypes;
+import com.cloud.exception.ConcurrentOperationException;
+import com.cloud.exception.InsufficientCapacityException;
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.network.vpc.Vpc;
+import com.cloud.user.Account;
+
+@Implementation(description="Restarts a VPC", responseObject=VpcResponse.class)
+public class RestartVPCCmd extends BaseAsyncCmd{
+ public static final Logger s_logger = Logger.getLogger(RestartVPCCmd.class.getName());
+ private static final String _name = "restartvpcresponse";
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+
+ @IdentityMapper(entityTableName="vpc")
+ @Parameter(name=ApiConstants.ID, type=CommandType.LONG, description="the id of the VPC")
+ private Long id;
+
+
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+
+ public Long getId() {
+ return id;
+ }
+
+
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ /////////////////////////////////////////////////////
+ @Override
+ public String getCommandName() {
+ return _name;
+ }
+
+ @Override
+ public long getEntityOwnerId() {
+ Vpc vpc = _entityMgr.findById(Vpc.class, getId());
+ if (vpc != null) {
+ return vpc.getAccountId();
+ }
+
+ return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
+ }
+
+ @Override
+ public void execute(){
+ try {
+ boolean result = _vpcService.restartVpc(getId());
+ if (result) {
+ SuccessResponse response = new SuccessResponse(getCommandName());
+ this.setResponseObject(response);
+ } else {
+ throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to restart VPC");
+ }
+ } catch (ResourceUnavailableException ex) {
+ s_logger.warn("Exception: ", ex);
+ throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
+ } catch (ConcurrentOperationException ex) {
+ s_logger.warn("Exception: ", ex);
+ throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
+ } catch (InsufficientCapacityException ex) {
+ s_logger.info(ex);
+ s_logger.trace(ex);
+ throw new ServerApiException(BaseCmd.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage());
+ }
+ }
+
+ @Override
+ public String getEventType() {
+ return EventTypes.EVENT_VPC_RESTART;
+ }
+
+ @Override
+ public String getEventDescription() {
+ return "restarting VPC id=" + getId();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/e398b1e4/api/src/org/apache/cloudstack/api/command/user/vpc/UpdateVPCCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/vpc/UpdateVPCCmd.java b/api/src/org/apache/cloudstack/api/command/user/vpc/UpdateVPCCmd.java
new file mode 100644
index 0000000..a0c16e1
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/user/vpc/UpdateVPCCmd.java
@@ -0,0 +1,109 @@
+// 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 org.apache.cloudstack.api.command.user.vpc;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseAsyncCmd;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.IdentityMapper;
+import org.apache.cloudstack.api.Implementation;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.response.VpcResponse;
+import com.cloud.event.EventTypes;
+import com.cloud.network.vpc.Vpc;
+import com.cloud.user.Account;
+
+@Implementation(description="Updates a VPC", responseObject=VpcResponse.class)
+public class UpdateVPCCmd extends BaseAsyncCmd{
+ public static final Logger s_logger = Logger.getLogger(UpdateVPCCmd.class.getName());
+ private static final String _name = "updatevpcresponse";
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+
+ @IdentityMapper(entityTableName="vpc")
+ @Parameter(name=ApiConstants.ID, type=CommandType.LONG, description="the id of the VPC")
+ private Long id;
+
+ @Parameter(name=ApiConstants.NAME, type=CommandType.STRING, description="the name of the VPC")
+ private String vpcName;
+
+ @Parameter(name=ApiConstants.DISPLAY_TEXT, type=CommandType.STRING, description="the display text of the VPC")
+ private String displayText;
+
+
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+
+ public String getVpcName() {
+ return vpcName;
+ }
+
+ public String getDisplayText() {
+ return displayText;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ /////////////////////////////////////////////////////
+ @Override
+ public String getCommandName() {
+ return _name;
+ }
+
+ @Override
+ public long getEntityOwnerId() {
+ Vpc vpc = _entityMgr.findById(Vpc.class, getId());
+ if (vpc != null) {
+ return vpc.getAccountId();
+ }
+
+ return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
+ }
+
+ @Override
+ public void execute(){
+ Vpc result = _vpcService.updateVpc(getId(), getVpcName(), getDisplayText());
+ if (result != null) {
+ VpcResponse response = _responseGenerator.createVpcResponse(result);
+ response.setResponseName(getCommandName());
+ this.setResponseObject(response);
+ } else {
+ throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to update VPC");
+ }
+ }
+
+ @Override
+ public String getEventType() {
+ return EventTypes.EVENT_VPC_UPDATE;
+ }
+
+ @Override
+ public String getEventDescription() {
+ return "updating VPC id=" + getId();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/e398b1e4/api/src/org/apache/cloudstack/api/command/user/vpn/CreateRemoteAccessVpnCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/vpn/CreateRemoteAccessVpnCmd.java b/api/src/org/apache/cloudstack/api/command/user/vpn/CreateRemoteAccessVpnCmd.java
new file mode 100644
index 0000000..4d9e685
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/user/vpn/CreateRemoteAccessVpnCmd.java
@@ -0,0 +1,198 @@
+// 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 org.apache.cloudstack.api.command.user.vpn;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseAsyncCmd;
+import org.apache.cloudstack.api.BaseAsyncCreateCmd;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.IdentityMapper;
+import org.apache.cloudstack.api.Implementation;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.response.RemoteAccessVpnResponse;
+import com.cloud.event.EventTypes;
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.exception.NetworkRuleConflictException;
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.network.IpAddress;
+import com.cloud.network.RemoteAccessVpn;
+
+@Implementation(description="Creates a l2tp/ipsec remote access vpn", responseObject=RemoteAccessVpnResponse.class)
+public class CreateRemoteAccessVpnCmd extends BaseAsyncCreateCmd {
+ public static final Logger s_logger = Logger.getLogger(CreateRemoteAccessVpnCmd.class.getName());
+
+ private static final String s_name = "createremoteaccessvpnresponse";
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+ @IdentityMapper(entityTableName="user_ip_address")
+ @Parameter(name=ApiConstants.PUBLIC_IP_ID, type=CommandType.LONG, required=true, description="public ip address id of the vpn server")
+ private Long publicIpId;
+
+ @Parameter(name="iprange", type=CommandType.STRING, required=false, description="the range of ip addresses to allocate to vpn clients. The first ip in the range will be taken by the vpn server")
+ private String ipRange;
+
+ @Deprecated
+ @Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="an optional account for the VPN. Must be used with domainId.")
+ private String accountName;
+
+ @Deprecated
+ @IdentityMapper(entityTableName="domain")
+ @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="an optional domainId for the VPN. If the account parameter is used, domainId must also be used.")
+ private Long domainId;
+
+ @Parameter(name = ApiConstants.OPEN_FIREWALL, type = CommandType.BOOLEAN, description = "if true, firewall rule for source/end pubic port is automatically created; if false - firewall rule has to be created explicitely. Has value true by default")
+ private Boolean openFirewall;
+
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+
+ public String getEntityTable() {
+ return "user_ip_address";
+ }
+
+ public Long getPublicIpId() {
+ return publicIpId;
+ }
+
+ public String getAccountName() {
+ return accountName;
+ }
+
+ public Long getDomainId() {
+ return domainId;
+ }
+
+ public String getIpRange() {
+ return ipRange;
+ }
+
+ public void setIpRange(String ipRange) {
+ this.ipRange = ipRange;
+ }
+
+ public Boolean getOpenFirewall() {
+ if (openFirewall != null) {
+ return openFirewall;
+ } else {
+ return true;
+ }
+ }
+
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ /////////////////////////////////////////////////////
+
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ @Override
+ public long getEntityOwnerId() {
+ IpAddress ip = _networkService.getIp(publicIpId);
+
+ if (ip == null) {
+ throw new InvalidParameterValueException("Unable to find ip address by id=" + publicIpId);
+ }
+
+ return ip.getAccountId();
+ }
+
+ @Override
+ public String getEventDescription() {
+ return "Create Remote Access VPN for account " + getEntityOwnerId() + " using public ip id=" + publicIpId;
+ }
+
+ @Override
+ public String getEventType() {
+ return EventTypes.EVENT_REMOTE_ACCESS_VPN_CREATE;
+ }
+
+ public long getNetworkId() {
+ IpAddress ip = _entityMgr.findById(IpAddress.class, getPublicIpId());
+ Long ntwkId = null;
+
+ if (ip.getAssociatedWithNetworkId() != null) {
+ ntwkId = ip.getAssociatedWithNetworkId();
+ }
+
+ if (ntwkId == null) {
+ throw new InvalidParameterValueException("Unable to create remote access vpn for the ipAddress id=" + getPublicIpId() +
+ " as ip is not associated with any network and no networkId is passed in");
+ }
+ return ntwkId;
+ }
+
+ @Override
+ public void create() {
+ try {
+ RemoteAccessVpn vpn = _ravService.createRemoteAccessVpn(publicIpId, ipRange, getOpenFirewall(), getNetworkId());
+ if (vpn != null) {
+ this.setEntityId(vpn.getServerAddressId());
+ } else {
+ throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create remote access vpn");
+ }
+ } catch (NetworkRuleConflictException e) {
+ s_logger.info("Network rule conflict: " + e.getMessage());
+ s_logger.trace("Network Rule Conflict: ", e);
+ throw new ServerApiException(BaseCmd.NETWORK_RULE_CONFLICT_ERROR, e.getMessage());
+ }
+ }
+
+ @Override
+ public void execute(){
+ try {
+ RemoteAccessVpn result = _ravService.startRemoteAccessVpn(publicIpId, getOpenFirewall());
+ if (result != null) {
+ RemoteAccessVpnResponse response = _responseGenerator.createRemoteAccessVpnResponse(result);
+ response.setResponseName(getCommandName());
+ this.setResponseObject(response);
+ } else {
+ throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create remote access vpn");
+ }
+ } catch (ResourceUnavailableException ex) {
+ s_logger.warn("Exception: ", ex);
+ throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
+ }
+ }
+
+
+ @Override
+ public String getSyncObjType() {
+ return BaseAsyncCmd.networkSyncObject;
+ }
+
+ @Override
+ public Long getSyncObjId() {
+ return getIp().getAssociatedWithNetworkId();
+ }
+
+ private IpAddress getIp() {
+ IpAddress ip = _networkService.getIp(publicIpId);
+ if (ip == null) {
+ throw new InvalidParameterValueException("Unable to find ip address by id " + publicIpId);
+ }
+ return ip;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/e398b1e4/api/src/org/apache/cloudstack/api/command/user/vpn/CreateVpnConnectionCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/vpn/CreateVpnConnectionCmd.java b/api/src/org/apache/cloudstack/api/command/user/vpn/CreateVpnConnectionCmd.java
new file mode 100644
index 0000000..99567bf
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/user/vpn/CreateVpnConnectionCmd.java
@@ -0,0 +1,143 @@
+// 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 org.apache.cloudstack.api.command.user.vpn;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseAsyncCmd;
+import org.apache.cloudstack.api.BaseAsyncCreateCmd;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.IdentityMapper;
+import org.apache.cloudstack.api.Implementation;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.response.Site2SiteVpnConnectionResponse;
+import com.cloud.event.EventTypes;
+import com.cloud.exception.NetworkRuleConflictException;
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.network.Site2SiteVpnConnection;
+import com.cloud.network.Site2SiteVpnGateway;
+import com.cloud.network.vpc.Vpc;
+
+@Implementation(description="Create site to site vpn connection", responseObject=Site2SiteVpnConnectionResponse.class)
+public class CreateVpnConnectionCmd extends BaseAsyncCreateCmd {
+ public static final Logger s_logger = Logger.getLogger(CreateVpnConnectionCmd.class.getName());
+
+ private static final String s_name = "createvpnconnectionresponse";
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+ @IdentityMapper(entityTableName="s2s_vpn_gateway")
+ @Parameter(name=ApiConstants.S2S_VPN_GATEWAY_ID, type=CommandType.LONG, required=true, description="id of the vpn gateway")
+ private Long vpnGatewayId;
+
+ @IdentityMapper(entityTableName="s2s_customer_gateway")
+ @Parameter(name=ApiConstants.S2S_CUSTOMER_GATEWAY_ID, type=CommandType.LONG, required=true, description="id of the customer gateway")
+ private Long customerGatewayId;
+
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+
+ public String getEntityTable() {
+ return "s2s_vpn_connection";
+ }
+
+ public Long getVpnGatewayId() {
+ return vpnGatewayId;
+ }
+
+ public Long getCustomerGatewayId() {
+ return customerGatewayId;
+ }
+
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ /////////////////////////////////////////////////////
+
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ @Override
+ public long getEntityOwnerId() {
+ Vpc vpc = _vpcService.getVpc(getVpnGateway().getVpcId());
+ return vpc.getAccountId();
+ }
+
+ @Override
+ public String getEventDescription() {
+ return "Create site-to-site VPN connection for account " + getEntityOwnerId();
+ }
+
+ @Override
+ public String getEventType() {
+ return EventTypes.EVENT_S2S_VPN_CONNECTION_CREATE;
+ }
+
+ @Override
+ public void create() {
+ try {
+ Site2SiteVpnConnection conn = _s2sVpnService.createVpnConnection(this);
+ if (conn != null) {
+ this.setEntityId(conn.getId());
+ } else {
+ throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create site to site vpn connection");
+ }
+ } catch (NetworkRuleConflictException e) {
+ s_logger.info("Network rule conflict: " + e.getMessage());
+ s_logger.trace("Network Rule Conflict: ", e);
+ throw new ServerApiException(BaseCmd.NETWORK_RULE_CONFLICT_ERROR, e.getMessage());
+ }
+ }
+
+ @Override
+ public void execute(){
+ try {
+ Site2SiteVpnConnection result = _s2sVpnService.startVpnConnection(this.getEntityId());
+ if (result != null) {
+ Site2SiteVpnConnectionResponse response = _responseGenerator.createSite2SiteVpnConnectionResponse(result);
+ response.setResponseName(getCommandName());
+ this.setResponseObject(response);
+ } else {
+ throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create site to site vpn connection");
+ }
+ } catch (ResourceUnavailableException ex) {
+ s_logger.warn("Exception: ", ex);
+ throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
+ }
+ }
+
+
+ @Override
+ public String getSyncObjType() {
+ return BaseAsyncCmd.vpcSyncObject;
+ }
+
+ @Override
+ public Long getSyncObjId() {
+ return getVpnGateway().getVpcId();
+ }
+
+ private Site2SiteVpnGateway getVpnGateway() {
+ return _s2sVpnService.getVpnGateway(vpnGatewayId);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/e398b1e4/api/src/org/apache/cloudstack/api/command/user/vpn/CreateVpnCustomerGatewayCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/vpn/CreateVpnCustomerGatewayCmd.java b/api/src/org/apache/cloudstack/api/command/user/vpn/CreateVpnCustomerGatewayCmd.java
new file mode 100644
index 0000000..af33540
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/user/vpn/CreateVpnCustomerGatewayCmd.java
@@ -0,0 +1,169 @@
+// 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 org.apache.cloudstack.api.command.user.vpn;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseAsyncCmd;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.IdentityMapper;
+import org.apache.cloudstack.api.Implementation;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.response.Site2SiteCustomerGatewayResponse;
+import com.cloud.event.EventTypes;
+import com.cloud.network.Site2SiteCustomerGateway;
+import com.cloud.user.UserContext;
+
+@Implementation(description="Creates site to site vpn customer gateway", responseObject=Site2SiteCustomerGatewayResponse.class)
+public class CreateVpnCustomerGatewayCmd extends BaseAsyncCmd {
+ public static final Logger s_logger = Logger.getLogger(CreateVpnCustomerGatewayCmd.class.getName());
+
+ private static final String s_name = "createcustomergatewayresponse";
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+ @Parameter(name=ApiConstants.NAME, type=CommandType.STRING, required=false, description="name of this customer gateway")
+ private String name;
+
+ @Parameter(name=ApiConstants.GATEWAY, type=CommandType.STRING, required=true, description="public ip address id of the customer gateway")
+ private String gatewayIp;
+
+ @Parameter(name=ApiConstants.CIDR_LIST, type=CommandType.STRING, required=true, description="guest cidr list of the customer gateway")
+ private String guestCidrList;
+
+ @Parameter(name=ApiConstants.IPSEC_PSK, type=CommandType.STRING, required=true, description="IPsec Preshared-Key of the customer gateway")
+ private String ipsecPsk;
+
+ @Parameter(name=ApiConstants.IKE_POLICY, type=CommandType.STRING, required=true, description="IKE policy of the customer gateway")
+ private String ikePolicy;
+
+ @Parameter(name=ApiConstants.ESP_POLICY, type=CommandType.STRING, required=true, description="ESP policy of the customer gateway")
+ private String espPolicy;
+
+ @Parameter(name=ApiConstants.IKE_LIFETIME, type=CommandType.LONG, required=false, description="Lifetime of phase 1 VPN connection to the customer gateway, in seconds")
+ private Long ikeLifetime;
+
+ @Parameter(name=ApiConstants.ESP_LIFETIME, type=CommandType.LONG, required=false, description="Lifetime of phase 2 VPN connection to the customer gateway, in seconds")
+ private Long espLifetime;
+
+ @Parameter(name=ApiConstants.DPD, type=CommandType.BOOLEAN, required=false, description="If DPD is enabled for VPN connection")
+ private Boolean dpd;
+
+ @Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="the account associated with the gateway. Must be used with the domainId parameter.")
+ private String accountName;
+
+ @IdentityMapper(entityTableName="domain")
+ @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="the domain ID associated with the gateway. " +
+ "If used with the account parameter returns the gateway associated with the account for the specified domain.")
+ private Long domainId;
+
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+
+ public String getEntityTable() {
+ return "s2s_customer_gateway";
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getIpsecPsk() {
+ return ipsecPsk;
+ }
+
+ public String getGuestCidrList() {
+ return guestCidrList;
+ }
+
+ public String getGatewayIp() {
+ return gatewayIp;
+ }
+
+ public String getIkePolicy() {
+ return ikePolicy;
+ }
+
+ public String getEspPolicy() {
+ return espPolicy;
+ }
+
+ public Long getIkeLifetime() {
+ return ikeLifetime;
+ }
+
+ public Long getEspLifetime() {
+ return espLifetime;
+ }
+
+ public Boolean getDpd() {
+ return dpd;
+ }
+
+ public String getAccountName() {
+ return accountName;
+ }
+
+ public Long getDomainId() {
+ return domainId;
+ }
+
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ /////////////////////////////////////////////////////
+
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ @Override
+ public long getEntityOwnerId() {
+ Long accountId = finalyzeAccountId(accountName, domainId, null, true);
+ if (accountId == null) {
+ accountId = UserContext.current().getCaller().getId();
+ }
+ return accountId;
+ }
+
+ @Override
+ public String getEventDescription() {
+ return "Create site-to-site VPN customer gateway for account " + getEntityOwnerId();
+ }
+
+ @Override
+ public String getEventType() {
+ return EventTypes.EVENT_S2S_VPN_CUSTOMER_GATEWAY_CREATE;
+ }
+
+ @Override
+ public void execute(){
+ Site2SiteCustomerGateway result = _s2sVpnService.createCustomerGateway(this);
+ if (result != null) {
+ Site2SiteCustomerGatewayResponse response = _responseGenerator.createSite2SiteCustomerGatewayResponse(result);
+ response.setResponseName(getCommandName());
+ this.setResponseObject(response);
+ } else {
+ throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create customer VPN gateway");
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/e398b1e4/api/src/org/apache/cloudstack/api/command/user/vpn/CreateVpnGatewayCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/vpn/CreateVpnGatewayCmd.java b/api/src/org/apache/cloudstack/api/command/user/vpn/CreateVpnGatewayCmd.java
new file mode 100644
index 0000000..22c7751
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/user/vpn/CreateVpnGatewayCmd.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 org.apache.cloudstack.api.command.user.vpn;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseAsyncCmd;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.IdentityMapper;
+import org.apache.cloudstack.api.Implementation;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.response.Site2SiteVpnGatewayResponse;
+import com.cloud.event.EventTypes;
+import com.cloud.network.Site2SiteVpnGateway;
+import com.cloud.network.vpc.Vpc;
+
+@Implementation(description="Creates site to site vpn local gateway", responseObject=Site2SiteVpnGatewayResponse.class)
+public class CreateVpnGatewayCmd extends BaseAsyncCmd {
+ public static final Logger s_logger = Logger.getLogger(CreateVpnGatewayCmd.class.getName());
+
+ private static final String s_name = "createvpngatewayresponse";
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+ @IdentityMapper(entityTableName="vpc")
+ @Parameter(name=ApiConstants.VPC_ID, type=CommandType.LONG, required=true, description="public ip address id of the vpn gateway")
+ private Long vpcId;
+
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+
+ public String getEntityTable() {
+ return "s2s_vpn_gateway";
+ }
+
+ public Long getVpcId() {
+ return vpcId;
+ }
+
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ /////////////////////////////////////////////////////
+
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ @Override
+ public long getEntityOwnerId() {
+ Vpc vpc = _vpcService.getVpc(vpcId);
+ return vpc.getAccountId();
+ }
+
+ @Override
+ public String getEventDescription() {
+ return "Create site-to-site VPN gateway for account " + getEntityOwnerId();
+ }
+
+ @Override
+ public String getEventType() {
+ return EventTypes.EVENT_S2S_VPN_GATEWAY_CREATE;
+ }
+
+ @Override
+ public void execute(){
+ Site2SiteVpnGateway result;
+ result = _s2sVpnService.createVpnGateway(this);
+ if (result != null) {
+ Site2SiteVpnGatewayResponse response = _responseGenerator.createSite2SiteVpnGatewayResponse(result);
+ response.setResponseName(getCommandName());
+ this.setResponseObject(response);
+ } else {
+ throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create VPN gateway");
+ }
+ }
+
+ @Override
+ public String getSyncObjType() {
+ return BaseAsyncCmd.vpcSyncObject;
+ }
+
+ @Override
+ public Long getSyncObjId() {
+ return getVpcId();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/e398b1e4/api/src/org/apache/cloudstack/api/command/user/vpn/DeleteRemoteAccessVpnCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/vpn/DeleteRemoteAccessVpnCmd.java b/api/src/org/apache/cloudstack/api/command/user/vpn/DeleteRemoteAccessVpnCmd.java
new file mode 100644
index 0000000..38a050a
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/user/vpn/DeleteRemoteAccessVpnCmd.java
@@ -0,0 +1,100 @@
+// 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 org.apache.cloudstack.api.command.user.vpn;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseAsyncCmd;
+import org.apache.cloudstack.api.IdentityMapper;
+import org.apache.cloudstack.api.Implementation;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.response.SuccessResponse;
+import com.cloud.event.EventTypes;
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.network.RemoteAccessVpn;
+import com.cloud.user.UserContext;
+
+@Implementation(description="Destroys a l2tp/ipsec remote access vpn", responseObject=SuccessResponse.class)
+public class DeleteRemoteAccessVpnCmd extends BaseAsyncCmd {
+ public static final Logger s_logger = Logger.getLogger(DeleteRemoteAccessVpnCmd.class.getName());
+
+ private static final String s_name = "deleteremoteaccessvpnresponse";
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+ @IdentityMapper(entityTableName="user_ip_address")
+ @Parameter(name=ApiConstants.PUBLIC_IP_ID, type=CommandType.LONG, required=true, description="public ip address id of the vpn server")
+ private Long publicIpId;
+
+ // unexposed parameter needed for events logging
+ @IdentityMapper(entityTableName="account")
+ @Parameter(name=ApiConstants.ACCOUNT_ID, type=CommandType.LONG, expose=false)
+ private Long ownerId;
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ /////////////////////////////////////////////////////
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ @Override
+ public long getEntityOwnerId() {
+ if (ownerId == null) {
+ RemoteAccessVpn vpnEntity = _entityMgr.findById(RemoteAccessVpn.class, publicIpId);
+ if(vpnEntity != null)
+ return vpnEntity.getAccountId();
+
+ throw new InvalidParameterValueException("The specified public ip is not allocated to any account");
+ }
+ return ownerId;
+ }
+
+ @Override
+ public String getEventDescription() {
+ return "Delete Remote Access VPN for account " + getEntityOwnerId() + " for ip id=" + publicIpId;
+ }
+
+ @Override
+ public String getEventType() {
+ return EventTypes.EVENT_REMOTE_ACCESS_VPN_DESTROY;
+ }
+
+ @Override
+ public void execute() throws ResourceUnavailableException {
+ _ravService.destroyRemoteAccessVpn(publicIpId, UserContext.current().getCaller());
+ }
+
+ @Override
+ public String getSyncObjType() {
+ return BaseAsyncCmd.networkSyncObject;
+ }
+
+ @Override
+ public Long getSyncObjId() {
+ return _ravService.getRemoteAccessVpn(publicIpId).getNetworkId();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/e398b1e4/api/src/org/apache/cloudstack/api/command/user/vpn/DeleteVpnConnectionCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/vpn/DeleteVpnConnectionCmd.java b/api/src/org/apache/cloudstack/api/command/user/vpn/DeleteVpnConnectionCmd.java
new file mode 100644
index 0000000..98c0c55
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/user/vpn/DeleteVpnConnectionCmd.java
@@ -0,0 +1,103 @@
+// 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 org.apache.cloudstack.api.command.user.vpn;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseAsyncCmd;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.IdentityMapper;
+import org.apache.cloudstack.api.Implementation;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.response.SuccessResponse;
+import com.cloud.event.EventTypes;
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.network.Site2SiteVpnConnection;
+import com.cloud.user.Account;
+
+@Implementation(description="Delete site to site vpn connection", responseObject=SuccessResponse.class)
+public class DeleteVpnConnectionCmd extends BaseAsyncCmd {
+ public static final Logger s_logger = Logger.getLogger(DeleteVpnConnectionCmd.class.getName());
+
+ private static final String s_name = "deletevpnconnectionresponse";
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+ @IdentityMapper(entityTableName="s2s_vpn_connection")
+ @Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="id of vpn connection")
+ private Long id;
+
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+
+ public String getEntityTable() {
+ return "s2s_vpn_connection";
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ /////////////////////////////////////////////////////
+
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ @Override
+ public long getEntityOwnerId() {
+ Site2SiteVpnConnection conn = _entityMgr.findById(Site2SiteVpnConnection.class, getId());
+ if (conn != null) {
+ return conn.getAccountId();
+ }
+ return Account.ACCOUNT_ID_SYSTEM;
+ }
+
+ @Override
+ public String getEventDescription() {
+ return "Delete site-to-site VPN connection for account " + getEntityOwnerId();
+ }
+
+ @Override
+ public String getEventType() {
+ return EventTypes.EVENT_S2S_VPN_CONNECTION_DELETE;
+ }
+
+ @Override
+ public void execute(){
+ try {
+ boolean result = _s2sVpnService.deleteVpnConnection(this);
+ if (result) {
+ SuccessResponse response = new SuccessResponse(getCommandName());
+ this.setResponseObject(response);
+ } else {
+ throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete site to site VPN connection");
+ }
+ } catch (ResourceUnavailableException ex) {
+ s_logger.warn("Exception: ", ex);
+ throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/e398b1e4/api/src/org/apache/cloudstack/api/command/user/vpn/DeleteVpnCustomerGatewayCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/vpn/DeleteVpnCustomerGatewayCmd.java b/api/src/org/apache/cloudstack/api/command/user/vpn/DeleteVpnCustomerGatewayCmd.java
new file mode 100644
index 0000000..f6c25bf
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/user/vpn/DeleteVpnCustomerGatewayCmd.java
@@ -0,0 +1,97 @@
+// 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 org.apache.cloudstack.api.command.user.vpn;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseAsyncCmd;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.IdentityMapper;
+import org.apache.cloudstack.api.Implementation;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.response.SuccessResponse;
+import com.cloud.event.EventTypes;
+import com.cloud.network.Site2SiteCustomerGateway;
+import com.cloud.user.Account;
+
+@Implementation(description="Delete site to site vpn customer gateway", responseObject=SuccessResponse.class)
+public class DeleteVpnCustomerGatewayCmd extends BaseAsyncCmd {
+ public static final Logger s_logger = Logger.getLogger(DeleteVpnCustomerGatewayCmd.class.getName());
+
+ private static final String s_name = "deletevpncustomergatewayresponse";
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+ @IdentityMapper(entityTableName="s2s_customer_gateway")
+ @Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="id of customer gateway")
+ private Long id;
+
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+
+ public String getEntityTable() {
+ return "s2s_customer_gateway";
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ /////////////////////////////////////////////////////
+
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ @Override
+ public long getEntityOwnerId() {
+ Site2SiteCustomerGateway gw = _entityMgr.findById(Site2SiteCustomerGateway.class, getId());
+ if (gw != null) {
+ return gw.getAccountId();
+ }
+ return Account.ACCOUNT_ID_SYSTEM;
+ }
+
+ @Override
+ public String getEventDescription() {
+ return "Delete site-to-site VPN customer gateway for account " + getEntityOwnerId();
+ }
+
+ @Override
+ public String getEventType() {
+ return EventTypes.EVENT_S2S_VPN_CUSTOMER_GATEWAY_DELETE;
+ }
+
+ @Override
+ public void execute(){
+ boolean result = _s2sVpnService.deleteCustomerGateway(this);
+ if (result) {
+ SuccessResponse response = new SuccessResponse(getCommandName());
+ this.setResponseObject(response);
+ } else {
+ throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete customer VPN gateway");
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/e398b1e4/api/src/org/apache/cloudstack/api/command/user/vpn/DeleteVpnGatewayCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/vpn/DeleteVpnGatewayCmd.java b/api/src/org/apache/cloudstack/api/command/user/vpn/DeleteVpnGatewayCmd.java
new file mode 100644
index 0000000..fcc3c9b
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/user/vpn/DeleteVpnGatewayCmd.java
@@ -0,0 +1,98 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.api.command.user.vpn;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseAsyncCmd;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.IdentityMapper;
+import org.apache.cloudstack.api.Implementation;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.response.SuccessResponse;
+import com.cloud.event.EventTypes;
+import com.cloud.network.Site2SiteVpnGateway;
+import com.cloud.user.Account;
+
+@Implementation(description="Delete site to site vpn gateway", responseObject=SuccessResponse.class)
+public class DeleteVpnGatewayCmd extends BaseAsyncCmd {
+ public static final Logger s_logger = Logger.getLogger(DeleteVpnGatewayCmd.class.getName());
+
+ private static final String s_name = "deletevpngatewayresponse";
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+ @IdentityMapper(entityTableName="s2s_vpn_gateway")
+ @Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="id of customer gateway")
+ private Long id;
+
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+
+ public String getEntityTable() {
+ return "s2s_vpn_gateway";
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ /////////////////////////////////////////////////////
+
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ @Override
+ public long getEntityOwnerId() {
+ Site2SiteVpnGateway gw = _entityMgr.findById(Site2SiteVpnGateway.class, getId());
+ if (gw != null) {
+ return gw.getAccountId();
+ }
+ return Account.ACCOUNT_ID_SYSTEM;
+ }
+
+ @Override
+ public String getEventDescription() {
+ return "Delete site-to-site VPN gateway for account " + getEntityOwnerId();
+ }
+
+ @Override
+ public String getEventType() {
+ return EventTypes.EVENT_S2S_VPN_GATEWAY_DELETE;
+ }
+
+ @Override
+ public void execute(){
+ boolean result = false;
+ result = _s2sVpnService.deleteVpnGateway(this);
+ if (result) {
+ SuccessResponse response = new SuccessResponse(getCommandName());
+ this.setResponseObject(response);
+ } else {
+ throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete customer VPN gateway");
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/e398b1e4/api/src/org/apache/cloudstack/api/command/user/vpn/ListRemoteAccessVpnsCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/vpn/ListRemoteAccessVpnsCmd.java b/api/src/org/apache/cloudstack/api/command/user/vpn/ListRemoteAccessVpnsCmd.java
new file mode 100644
index 0000000..210b864
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/user/vpn/ListRemoteAccessVpnsCmd.java
@@ -0,0 +1,80 @@
+// 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 org.apache.cloudstack.api.command.user.vpn;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseListProjectAndAccountResourcesCmd;
+import org.apache.cloudstack.api.IdentityMapper;
+import org.apache.cloudstack.api.Implementation;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.response.ListResponse;
+import org.apache.cloudstack.api.response.RemoteAccessVpnResponse;
+import com.cloud.network.RemoteAccessVpn;
+import com.cloud.utils.Pair;
+
+@Implementation(description="Lists remote access vpns", responseObject=RemoteAccessVpnResponse.class)
+public class ListRemoteAccessVpnsCmd extends BaseListProjectAndAccountResourcesCmd {
+ public static final Logger s_logger = Logger.getLogger (ListRemoteAccessVpnsCmd.class.getName());
+
+ private static final String s_name = "listremoteaccessvpnsresponse";
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+
+ @IdentityMapper(entityTableName="user_ip_address")
+ @Parameter(name=ApiConstants.PUBLIC_IP_ID, type=CommandType.LONG, required=true, description="public ip address id of the vpn server")
+ private Long publicIpId;
+
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+
+
+ public Long getPublicIpId() {
+ return publicIpId;
+ }
+
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ /////////////////////////////////////////////////////
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ @Override
+ public void execute(){
+ Pair<List<? extends RemoteAccessVpn>, Integer> vpns = _ravService.searchForRemoteAccessVpns(this);
+ ListResponse<RemoteAccessVpnResponse> response = new ListResponse<RemoteAccessVpnResponse>();
+ List<RemoteAccessVpnResponse> vpnResponses = new ArrayList<RemoteAccessVpnResponse>();
+ if (vpns.first() != null && !vpns.first().isEmpty()) {
+ for (RemoteAccessVpn vpn : vpns.first()) {
+ vpnResponses.add(_responseGenerator.createRemoteAccessVpnResponse(vpn));
+ }
+ }
+ response.setResponses(vpnResponses, vpns.second());
+ response.setResponseName(getCommandName());
+ this.setResponseObject(response);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/e398b1e4/api/src/org/apache/cloudstack/api/command/user/vpn/ListVpnConnectionsCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/vpn/ListVpnConnectionsCmd.java b/api/src/org/apache/cloudstack/api/command/user/vpn/ListVpnConnectionsCmd.java
new file mode 100644
index 0000000..36bc89c
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/user/vpn/ListVpnConnectionsCmd.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 org.apache.cloudstack.api.command.user.vpn;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseListProjectAndAccountResourcesCmd;
+import org.apache.cloudstack.api.IdentityMapper;
+import org.apache.cloudstack.api.Implementation;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.response.ListResponse;
+import org.apache.cloudstack.api.response.Site2SiteVpnConnectionResponse;
+import com.cloud.network.Site2SiteVpnConnection;
+import com.cloud.utils.Pair;
+
+@Implementation(description="Lists site to site vpn connection gateways", responseObject=Site2SiteVpnConnectionResponse.class)
+public class ListVpnConnectionsCmd extends BaseListProjectAndAccountResourcesCmd {
+ public static final Logger s_logger = Logger.getLogger (ListVpnConnectionsCmd.class.getName());
+
+ private static final String s_name = "listvpnconnectionsresponse";
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+
+ @IdentityMapper(entityTableName="s2s_vpn_connection")
+ @Parameter(name=ApiConstants.ID, type=CommandType.LONG, description="id of the vpn connection")
+ private Long id;
+
+ @IdentityMapper(entityTableName="vpc")
+ @Parameter(name=ApiConstants.VPC_ID, type=CommandType.LONG, description="id of vpc")
+ private Long vpcId;
+
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+
+
+ public Long getId() {
+ return id;
+ }
+
+ public Long getVpcId() {
+ return vpcId;
+ }
+
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ /////////////////////////////////////////////////////
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ @Override
+ public void execute(){
+ Pair<List<? extends Site2SiteVpnConnection>, Integer> conns = _s2sVpnService.searchForVpnConnections(this);
+ ListResponse<Site2SiteVpnConnectionResponse> response = new ListResponse<Site2SiteVpnConnectionResponse>();
+ List<Site2SiteVpnConnectionResponse> connResponses = new ArrayList<Site2SiteVpnConnectionResponse>();
+ for (Site2SiteVpnConnection conn : conns.first()) {
+ if (conn == null) {
+ continue;
+ }
+ Site2SiteVpnConnectionResponse site2SiteVpnConnectonRes = _responseGenerator.createSite2SiteVpnConnectionResponse(conn);
+ site2SiteVpnConnectonRes.setObjectName("vpnconnection");
+ connResponses.add(site2SiteVpnConnectonRes);
+ }
+
+ response.setResponses(connResponses, conns.second());
+ response.setResponseName(getCommandName());
+ this.setResponseObject(response);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/e398b1e4/api/src/org/apache/cloudstack/api/command/user/vpn/ListVpnCustomerGatewaysCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/vpn/ListVpnCustomerGatewaysCmd.java b/api/src/org/apache/cloudstack/api/command/user/vpn/ListVpnCustomerGatewaysCmd.java
new file mode 100644
index 0000000..b1836e9
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/user/vpn/ListVpnCustomerGatewaysCmd.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 org.apache.cloudstack.api.command.user.vpn;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseListProjectAndAccountResourcesCmd;
+import org.apache.cloudstack.api.IdentityMapper;
+import org.apache.cloudstack.api.Implementation;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.response.ListResponse;
+import org.apache.cloudstack.api.response.Site2SiteCustomerGatewayResponse;
+import com.cloud.network.Site2SiteCustomerGateway;
+import com.cloud.utils.Pair;
+
+@Implementation(description="Lists site to site vpn customer gateways", responseObject=Site2SiteCustomerGatewayResponse.class)
+public class ListVpnCustomerGatewaysCmd extends BaseListProjectAndAccountResourcesCmd {
+ public static final Logger s_logger = Logger.getLogger (ListVpnCustomerGatewaysCmd.class.getName());
+
+ private static final String s_name = "listvpncustomergatewaysresponse";
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+
+ @IdentityMapper(entityTableName="s2s_customer_gateway")
+ @Parameter(name=ApiConstants.ID, type=CommandType.LONG, description="id of the customer gateway")
+ private Long id;
+
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+
+
+ public Long getId() {
+ return id;
+ }
+
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ /////////////////////////////////////////////////////
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ @Override
+ public void execute(){
+ Pair<List<? extends Site2SiteCustomerGateway>, Integer> gws = _s2sVpnService.searchForCustomerGateways(this);
+ ListResponse<Site2SiteCustomerGatewayResponse> response = new ListResponse<Site2SiteCustomerGatewayResponse>();
+ List<Site2SiteCustomerGatewayResponse> gwResponses = new ArrayList<Site2SiteCustomerGatewayResponse>();
+ for (Site2SiteCustomerGateway gw : gws.first()) {
+ if (gw == null) {
+ continue;
+ }
+ Site2SiteCustomerGatewayResponse site2SiteCustomerGatewayRes = _responseGenerator.createSite2SiteCustomerGatewayResponse(gw);
+ site2SiteCustomerGatewayRes.setObjectName("vpncustomergateway");
+ gwResponses.add(site2SiteCustomerGatewayRes);
+ }
+
+ response.setResponses(gwResponses, gws.second());
+ response.setResponseName(getCommandName());
+ this.setResponseObject(response);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/e398b1e4/api/src/org/apache/cloudstack/api/command/user/vpn/ListVpnGatewaysCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/vpn/ListVpnGatewaysCmd.java b/api/src/org/apache/cloudstack/api/command/user/vpn/ListVpnGatewaysCmd.java
new file mode 100644
index 0000000..239d503
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/user/vpn/ListVpnGatewaysCmd.java
@@ -0,0 +1,91 @@
+// 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 org.apache.cloudstack.api.command.user.vpn;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseListProjectAndAccountResourcesCmd;
+import org.apache.cloudstack.api.IdentityMapper;
+import org.apache.cloudstack.api.Implementation;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.response.ListResponse;
+import org.apache.cloudstack.api.response.Site2SiteVpnGatewayResponse;
+import com.cloud.network.Site2SiteVpnGateway;
+import com.cloud.utils.Pair;
+
+@Implementation(description="Lists site 2 site vpn gateways", responseObject=Site2SiteVpnGatewayResponse.class)
+public class ListVpnGatewaysCmd extends BaseListProjectAndAccountResourcesCmd {
+ public static final Logger s_logger = Logger.getLogger (ListVpnGatewaysCmd.class.getName());
+
+ private static final String s_name = "listvpngatewaysresponse";
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+
+ @IdentityMapper(entityTableName="s2s_vpn_gateway")
+ @Parameter(name=ApiConstants.ID, type=CommandType.LONG, description="id of the vpn gateway")
+ private Long id;
+
+ @IdentityMapper(entityTableName="vpc")
+ @Parameter(name=ApiConstants.VPC_ID, type=CommandType.LONG, description="id of vpc")
+ private Long vpcId;
+
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+
+ public Long getId() {
+ return id;
+ }
+
+ public Long getVpcId() {
+ return vpcId;
+ }
+
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ /////////////////////////////////////////////////////
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ @Override
+ public void execute(){
+ Pair<List<? extends Site2SiteVpnGateway>, Integer> gws = _s2sVpnService.searchForVpnGateways(this);
+ ListResponse<Site2SiteVpnGatewayResponse> response = new ListResponse<Site2SiteVpnGatewayResponse>();
+ List<Site2SiteVpnGatewayResponse> gwResponses = new ArrayList<Site2SiteVpnGatewayResponse>();
+ for (Site2SiteVpnGateway gw : gws.first()) {
+ if (gw == null) {
+ continue;
+ }
+ Site2SiteVpnGatewayResponse site2SiteVpnGatewayRes = _responseGenerator.createSite2SiteVpnGatewayResponse(gw);
+ site2SiteVpnGatewayRes.setObjectName("vpngateway");
+ gwResponses.add(site2SiteVpnGatewayRes);
+ }
+
+ response.setResponses(gwResponses, gws.second());
+ response.setResponseName(getCommandName());
+ this.setResponseObject(response);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/e398b1e4/api/src/org/apache/cloudstack/api/command/user/vpn/ResetVpnConnectionCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/vpn/ResetVpnConnectionCmd.java b/api/src/org/apache/cloudstack/api/command/user/vpn/ResetVpnConnectionCmd.java
new file mode 100644
index 0000000..6d6f240
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/user/vpn/ResetVpnConnectionCmd.java
@@ -0,0 +1,120 @@
+// 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 org.apache.cloudstack.api.command.user.vpn;
+
+import org.apache.log4j.Logger;
+
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseAsyncCmd;
+import org.apache.cloudstack.api.BaseCmd;
+import org.apache.cloudstack.api.IdentityMapper;
+import org.apache.cloudstack.api.Implementation;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.ServerApiException;
+import org.apache.cloudstack.api.response.Site2SiteVpnConnectionResponse;
+import com.cloud.event.EventTypes;
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.network.Site2SiteVpnConnection;
+import com.cloud.user.Account;
+import com.cloud.user.UserContext;
+
+@Implementation(description="Reset site to site vpn connection", responseObject=Site2SiteVpnConnectionResponse.class)
+public class ResetVpnConnectionCmd extends BaseAsyncCmd {
+ public static final Logger s_logger = Logger.getLogger(ResetVpnConnectionCmd.class.getName());
+
+ private static final String s_name = "resetvpnconnectionresponse";
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+ @IdentityMapper(entityTableName="s2s_vpn_connection")
+ @Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="id of vpn connection")
+ private Long id;
+
+ @Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="an optional account for connection. Must be used with domainId.")
+ private String accountName;
+
+ @IdentityMapper(entityTableName="domain")
+ @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="an optional domainId for connection. If the account parameter is used, domainId must also be used.")
+ private Long domainId;
+
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+
+ public String getEntityTable() {
+ return "s2s_vpn_connection";
+ }
+
+ public Long getDomainId() {
+ return domainId;
+ }
+
+ public Long getAccountId() {
+ return getEntityOwnerId();
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ /////////////////////////////////////////////////////
+
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ @Override
+ public long getEntityOwnerId() {
+ Long accountId = finalyzeAccountId(accountName, domainId, null, true);
+ if (accountId == null) {
+ return UserContext.current().getCaller().getId();
+ }
+ return Account.ACCOUNT_ID_SYSTEM;
+ }
+
+ @Override
+ public String getEventDescription() {
+ return "Reset site-to-site VPN connection for account " + getEntityOwnerId();
+ }
+
+ @Override
+ public String getEventType() {
+ return EventTypes.EVENT_S2S_VPN_CONNECTION_RESET;
+ }
+
+ @Override
+ public void execute(){
+ try {
+ Site2SiteVpnConnection result = _s2sVpnService.resetVpnConnection(this);
+ if (result != null) {
+ Site2SiteVpnConnectionResponse response = _responseGenerator.createSite2SiteVpnConnectionResponse(result);
+ response.setResponseName(getCommandName());
+ this.setResponseObject(response);
+ } else {
+ throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to reset site to site VPN connection");
+ }
+ } catch (ResourceUnavailableException ex) {
+ s_logger.warn("Exception: ", ex);
+ throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
+ }
+ }
+}