S2S VPN: Add name field for customer gateway

Easier for user to identify the correct gateway
This commit is contained in:
Sheng Yang 2012-07-27 15:54:21 -07:00
parent 2fc1dc0df6
commit 72a4b2f410
9 changed files with 48 additions and 2 deletions

View File

@ -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;
}

View File

@ -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;
}

View File

@ -10,4 +10,5 @@ public interface Site2SiteCustomerGateway extends ControlledEntity {
public String getGuestCidrList();
public String getIpsecPsk();
public Date getRemoved();
String getName();
}

View File

@ -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());

View File

@ -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;

View File

@ -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);
}

View File

@ -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);
}
}

View File

@ -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;

View File

@ -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),