diff --git a/api/src/com/cloud/api/commands/CreateVpnCustomerGatewayCmd.java b/api/src/com/cloud/api/commands/CreateVpnCustomerGatewayCmd.java index 7d47eee94d5..abfe28ee438 100644 --- a/api/src/com/cloud/api/commands/CreateVpnCustomerGatewayCmd.java +++ b/api/src/com/cloud/api/commands/CreateVpnCustomerGatewayCmd.java @@ -40,6 +40,9 @@ public class CreateVpnCustomerGatewayCmd extends BaseAsyncCmd { ///////////////////////////////////////////////////// //////////////// 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; @@ -74,6 +77,10 @@ public class CreateVpnCustomerGatewayCmd extends BaseAsyncCmd { return "s2s_customer_gateway"; } + public String getName() { + return name; + } + public String getIpsecPsk() { return ipsecPsk; } diff --git a/api/src/com/cloud/api/response/Site2SiteCustomerGatewayResponse.java b/api/src/com/cloud/api/response/Site2SiteCustomerGatewayResponse.java index 829a9f6417e..17731872d40 100644 --- a/api/src/com/cloud/api/response/Site2SiteCustomerGatewayResponse.java +++ b/api/src/com/cloud/api/response/Site2SiteCustomerGatewayResponse.java @@ -28,6 +28,9 @@ public class Site2SiteCustomerGatewayResponse extends BaseResponse implements Co @SerializedName(ApiConstants.ID) @Param(description="the vpn gateway ID") private IdentityProxy id = new IdentityProxy("s2s_customer_gateway"); + @SerializedName(ApiConstants.NAME) @Param(description="name of the customer gateway") + private String name; + @SerializedName(ApiConstants.GATEWAY) @Param(description="public ip address id of the customer gateway") private String gatewayIp; @@ -62,6 +65,10 @@ public class Site2SiteCustomerGatewayResponse extends BaseResponse implements Co this.id.setValue(id); } + public void setName(String name) { + this.name = name; + } + public void setGatewayIp(String gatewayIp) { this.gatewayIp = gatewayIp; } diff --git a/api/src/com/cloud/network/Site2SiteCustomerGateway.java b/api/src/com/cloud/network/Site2SiteCustomerGateway.java index 423d8d1f533..d4facc34e75 100644 --- a/api/src/com/cloud/network/Site2SiteCustomerGateway.java +++ b/api/src/com/cloud/network/Site2SiteCustomerGateway.java @@ -10,4 +10,5 @@ public interface Site2SiteCustomerGateway extends ControlledEntity { public String getGuestCidrList(); public String getIpsecPsk(); public Date getRemoved(); + String getName(); } diff --git a/server/src/com/cloud/api/ApiResponseHelper.java b/server/src/com/cloud/api/ApiResponseHelper.java index 01b1f79ba42..ab6ccf9be1f 100755 --- a/server/src/com/cloud/api/ApiResponseHelper.java +++ b/server/src/com/cloud/api/ApiResponseHelper.java @@ -3785,6 +3785,7 @@ public class ApiResponseHelper implements ResponseGenerator { public Site2SiteCustomerGatewayResponse createSite2SiteCustomerGatewayResponse(Site2SiteCustomerGateway result) { Site2SiteCustomerGatewayResponse response = new Site2SiteCustomerGatewayResponse(); response.setId(result.getId()); + response.setName(result.getName()); response.setGatewayIp(result.getGatewayIp()); response.setGuestCidrList(result.getGuestCidrList()); response.setIpsecPsk(result.getIpsecPsk()); diff --git a/server/src/com/cloud/network/Site2SiteCustomerGatewayVO.java b/server/src/com/cloud/network/Site2SiteCustomerGatewayVO.java index 8e0afca7d3f..5063f780b30 100644 --- a/server/src/com/cloud/network/Site2SiteCustomerGatewayVO.java +++ b/server/src/com/cloud/network/Site2SiteCustomerGatewayVO.java @@ -23,6 +23,9 @@ public class Site2SiteCustomerGatewayVO implements Site2SiteCustomerGateway { @Column(name="uuid") private String uuid; + @Column(name="name") + private String name; + @Column(name="gateway_ip") private String gatewayIp; @@ -52,7 +55,8 @@ public class Site2SiteCustomerGatewayVO implements Site2SiteCustomerGateway { public Site2SiteCustomerGatewayVO() { } - public Site2SiteCustomerGatewayVO(long accountId, long domainId, String gatewayIp, String guestCidrList, String ipsecPsk, String ikePolicy, String espPolicy, long lifetime) { + public Site2SiteCustomerGatewayVO(String name, long accountId, long domainId, String gatewayIp, String guestCidrList, String ipsecPsk, String ikePolicy, String espPolicy, long lifetime) { + this.name = name; this.gatewayIp = gatewayIp; this.guestCidrList = guestCidrList; this.ipsecPsk = ipsecPsk; @@ -69,6 +73,15 @@ public class Site2SiteCustomerGatewayVO implements Site2SiteCustomerGateway { return id; } + @Override + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + @Override public String getGatewayIp() { return gatewayIp; diff --git a/server/src/com/cloud/network/dao/Site2SiteCustomerGatewayDao.java b/server/src/com/cloud/network/dao/Site2SiteCustomerGatewayDao.java index a27903b9ee1..5b39dbdb080 100644 --- a/server/src/com/cloud/network/dao/Site2SiteCustomerGatewayDao.java +++ b/server/src/com/cloud/network/dao/Site2SiteCustomerGatewayDao.java @@ -5,4 +5,5 @@ import com.cloud.utils.db.GenericDao; public interface Site2SiteCustomerGatewayDao extends GenericDao { Site2SiteCustomerGatewayVO findByGatewayIp(String ip); + Site2SiteCustomerGatewayVO findByName(String name); } diff --git a/server/src/com/cloud/network/dao/Site2SiteCustomerGatewayDaoImpl.java b/server/src/com/cloud/network/dao/Site2SiteCustomerGatewayDaoImpl.java index 6c5fb3fc74f..80b5c02f512 100644 --- a/server/src/com/cloud/network/dao/Site2SiteCustomerGatewayDaoImpl.java +++ b/server/src/com/cloud/network/dao/Site2SiteCustomerGatewayDaoImpl.java @@ -18,6 +18,7 @@ public class Site2SiteCustomerGatewayDaoImpl extends GenericDaoBase sc = AllFieldsSearch.create(); + sc.setParameters("name", name); + return findOneBy(sc); + } + } diff --git a/server/src/com/cloud/network/vpn/Site2SiteVpnManagerImpl.java b/server/src/com/cloud/network/vpn/Site2SiteVpnManagerImpl.java index 696e4c08f97..899e3af55ec 100644 --- a/server/src/com/cloud/network/vpn/Site2SiteVpnManagerImpl.java +++ b/server/src/com/cloud/network/vpn/Site2SiteVpnManagerImpl.java @@ -113,10 +113,14 @@ public class Site2SiteVpnManagerImpl implements Site2SiteVpnManager, Manager { @Override public Site2SiteCustomerGateway createCustomerGateway(CreateVpnCustomerGatewayCmd cmd) { + String name = cmd.getName(); String gatewayIp = cmd.getGatewayIp(); if (!NetUtils.isValidIp(gatewayIp)) { throw new InvalidParameterValueException("The customer gateway ip " + gatewayIp + " is invalid!"); } + if (name == null) { + name = "VPN-" + gatewayIp; + } String guestCidrList = cmd.getGuestCidrList(); if (!NetUtils.validateGuestCidrList(guestCidrList)) { throw new InvalidParameterValueException("The customer gateway guest cidr list " + guestCidrList + " is invalid guest cidr!"); @@ -141,12 +145,15 @@ public class Site2SiteVpnManagerImpl implements Site2SiteVpnManager, Manager { if (_customerGatewayDao.findByGatewayIp(gatewayIp) != null) { throw new InvalidParameterValueException("The customer gateway with ip " + gatewayIp + " already existed!"); } + if (_customerGatewayDao.findByName(name) != null) { + throw new InvalidParameterValueException("The customer gateway with name " + name + " already existed!"); + } Long accountId = cmd.getEntityOwnerId(); Long domainId = cmd.getDomainId(); if (domainId == null) { domainId = Domain.ROOT_DOMAIN; } - Site2SiteCustomerGatewayVO gw = new Site2SiteCustomerGatewayVO(accountId, domainId, gatewayIp, guestCidrList, ipsecPsk, + Site2SiteCustomerGatewayVO gw = new Site2SiteCustomerGatewayVO(name, accountId, domainId, gatewayIp, guestCidrList, ipsecPsk, ikePolicy, espPolicy, lifetime); _customerGatewayDao.persist(gw); return gw; diff --git a/setup/db/create-schema.sql b/setup/db/create-schema.sql index 0009cea1517..ad6ea24ea16 100755 --- a/setup/db/create-schema.sql +++ b/setup/db/create-schema.sql @@ -2156,6 +2156,7 @@ CREATE TABLE `cloud`.`s2s_vpn_gateway` ( CREATE TABLE `cloud`.`s2s_customer_gateway` ( `id` bigint unsigned NOT NULL auto_increment COMMENT 'id', `uuid` varchar(40), + `name` varchar(255) NOT NULL, `gateway_ip` char(40) NOT NULL, `guest_cidr_list` varchar(200) NOT NULL, `ipsec_psk` varchar(256),