S2S VPN: Add name field for customer gateway

Easier for user to identify the correct gateway


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

Branch: refs/heads/vpc
Commit: 72a4b2f41037a95f5d5dbcdec784d8100cd5eddb
Parents: 2fc1dc0
Author: Sheng Yang <[email protected]>
Authored: Fri Jul 27 15:54:21 2012 -0700
Committer: Sheng Yang <[email protected]>
Committed: Fri Jul 27 16:27:36 2012 -0700

----------------------------------------------------------------------
 .../api/commands/CreateVpnCustomerGatewayCmd.java  |    7 +++++++
 .../response/Site2SiteCustomerGatewayResponse.java |    7 +++++++
 .../cloud/network/Site2SiteCustomerGateway.java    |    1 +
 server/src/com/cloud/api/ApiResponseHelper.java    |    1 +
 .../cloud/network/Site2SiteCustomerGatewayVO.java  |   15 ++++++++++++++-
 .../network/dao/Site2SiteCustomerGatewayDao.java   |    1 +
 .../dao/Site2SiteCustomerGatewayDaoImpl.java       |    8 ++++++++
 .../cloud/network/vpn/Site2SiteVpnManagerImpl.java |    9 ++++++++-
 setup/db/create-schema.sql                         |    1 +
 9 files changed, 48 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/72a4b2f4/api/src/com/cloud/api/commands/CreateVpnCustomerGatewayCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/CreateVpnCustomerGatewayCmd.java 
b/api/src/com/cloud/api/commands/CreateVpnCustomerGatewayCmd.java
index 7d47eee..abfe28e 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;
     }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/72a4b2f4/api/src/com/cloud/api/response/Site2SiteCustomerGatewayResponse.java
----------------------------------------------------------------------
diff --git 
a/api/src/com/cloud/api/response/Site2SiteCustomerGatewayResponse.java 
b/api/src/com/cloud/api/response/Site2SiteCustomerGatewayResponse.java
index 829a9f6..1773187 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;
     }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/72a4b2f4/api/src/com/cloud/network/Site2SiteCustomerGateway.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/network/Site2SiteCustomerGateway.java 
b/api/src/com/cloud/network/Site2SiteCustomerGateway.java
index 423d8d1..d4facc3 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();
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/72a4b2f4/server/src/com/cloud/api/ApiResponseHelper.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/ApiResponseHelper.java 
b/server/src/com/cloud/api/ApiResponseHelper.java
index 01b1f79..ab6ccf9 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());

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/72a4b2f4/server/src/com/cloud/network/Site2SiteCustomerGatewayVO.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/Site2SiteCustomerGatewayVO.java 
b/server/src/com/cloud/network/Site2SiteCustomerGatewayVO.java
index 8e0afca..5063f78 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;
@@ -70,6 +74,15 @@ public class Site2SiteCustomerGatewayVO implements 
Site2SiteCustomerGateway {
     }
 
     @Override
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    @Override
     public String getGatewayIp() {
         return gatewayIp;
     }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/72a4b2f4/server/src/com/cloud/network/dao/Site2SiteCustomerGatewayDao.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/dao/Site2SiteCustomerGatewayDao.java 
b/server/src/com/cloud/network/dao/Site2SiteCustomerGatewayDao.java
index a27903b..5b39dbd 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, Long> {
     Site2SiteCustomerGatewayVO findByGatewayIp(String ip);
+    Site2SiteCustomerGatewayVO findByName(String name);
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/72a4b2f4/server/src/com/cloud/network/dao/Site2SiteCustomerGatewayDaoImpl.java
----------------------------------------------------------------------
diff --git 
a/server/src/com/cloud/network/dao/Site2SiteCustomerGatewayDaoImpl.java 
b/server/src/com/cloud/network/dao/Site2SiteCustomerGatewayDaoImpl.java
index 6c5fb3f..80b5c02 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<Site2SiteCus
     protected Site2SiteCustomerGatewayDaoImpl() {
         AllFieldsSearch = createSearchBuilder();
         AllFieldsSearch.and("gatewayIp", 
AllFieldsSearch.entity().getGatewayIp(), SearchCriteria.Op.EQ);
+        AllFieldsSearch.and("name", AllFieldsSearch.entity().getName(), 
SearchCriteria.Op.EQ);
         AllFieldsSearch.done();
     }
     
@@ -28,4 +29,11 @@ public class Site2SiteCustomerGatewayDaoImpl extends 
GenericDaoBase<Site2SiteCus
         return findOneBy(sc);
     }
 
+    @Override
+    public Site2SiteCustomerGatewayVO findByName(String name) {
+        SearchCriteria<Site2SiteCustomerGatewayVO> sc = 
AllFieldsSearch.create();
+        sc.setParameters("name", name);
+        return findOneBy(sc);
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/72a4b2f4/server/src/com/cloud/network/vpn/Site2SiteVpnManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/vpn/Site2SiteVpnManagerImpl.java 
b/server/src/com/cloud/network/vpn/Site2SiteVpnManagerImpl.java
index 696e4c0..899e3af 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;

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/72a4b2f4/setup/db/create-schema.sql
----------------------------------------------------------------------
diff --git a/setup/db/create-schema.sql b/setup/db/create-schema.sql
index 0009cea..ad6ea24 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),

Reply via email to