diff --git a/api/src/com/cloud/api/commands/CreateVpnConnectionCmd.java b/api/src/com/cloud/api/commands/CreateVpnConnectionCmd.java index a9828d14803..61af0fa01b1 100644 --- a/api/src/com/cloud/api/commands/CreateVpnConnectionCmd.java +++ b/api/src/com/cloud/api/commands/CreateVpnConnectionCmd.java @@ -33,6 +33,8 @@ import com.cloud.exception.NetworkRuleConflictException; import com.cloud.exception.ResourceUnavailableException; import com.cloud.network.IpAddress; import com.cloud.network.Site2SiteVpnConnection; +import com.cloud.network.Site2SiteVpnGateway; +import com.cloud.network.vpc.Vpc; import com.cloud.user.Account; import com.cloud.user.UserContext; @@ -53,14 +55,6 @@ public class CreateVpnConnectionCmd extends BaseAsyncCreateCmd { @Parameter(name=ApiConstants.S2S_CUSTOMER_GATEWAY_ID, type=CommandType.LONG, required=true, description="id of the customer gateway") private Long customerGatewayId; - @Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="the account associated with the connection. 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 connection. " + - "If used with the account parameter returns the connection associated with the account for the specified domain.") - private Long domainId; - ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// @@ -77,14 +71,6 @@ public class CreateVpnConnectionCmd extends BaseAsyncCreateCmd { return customerGatewayId; } - public String getAccountName() { - return accountName; - } - - public Long getDomainId() { - return domainId; - } - ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// @@ -97,11 +83,8 @@ public class CreateVpnConnectionCmd extends BaseAsyncCreateCmd { @Override public long getEntityOwnerId() { - Long accountId = finalyzeAccountId(accountName, domainId, null, true); - if (accountId == null) { - accountId = UserContext.current().getCaller().getId(); - } - return accountId; + Vpc vpc = _vpcService.getVpc(getVpnGateway().getVpcId()); + return vpc.getAccountId(); } @Override @@ -155,14 +138,10 @@ public class CreateVpnConnectionCmd extends BaseAsyncCreateCmd { @Override public Long getSyncObjId() { - return getIp().getVpcId(); + return getVpnGateway().getVpcId(); } - private IpAddress getIp() { - IpAddress ip = _s2sVpnService.getVpnGatewayIp(vpnGatewayId); - if (ip == null) { - throw new InvalidParameterValueException("Unable to find ip address by vpn gateway id " + vpnGatewayId); - } - return ip; + private Site2SiteVpnGateway getVpnGateway() { + return _s2sVpnService.getVpnGateway(vpnGatewayId); } } diff --git a/api/src/com/cloud/api/commands/CreateVpnGatewayCmd.java b/api/src/com/cloud/api/commands/CreateVpnGatewayCmd.java index 0cb4412799e..445c52a4734 100644 --- a/api/src/com/cloud/api/commands/CreateVpnGatewayCmd.java +++ b/api/src/com/cloud/api/commands/CreateVpnGatewayCmd.java @@ -28,13 +28,14 @@ import com.cloud.api.ServerApiException; import com.cloud.api.response.Site2SiteVpnGatewayResponse; import com.cloud.event.EventTypes; import com.cloud.network.Site2SiteVpnGateway; +import com.cloud.network.vpc.Vpc; import com.cloud.user.Account; import com.cloud.user.UserContext; @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"; ///////////////////////////////////////////////////// @@ -44,14 +45,6 @@ public class CreateVpnGatewayCmd extends BaseAsyncCmd { @Parameter(name=ApiConstants.VPC_ID, type=CommandType.LONG, required=true, description="public ip address id of the vpn gateway") private Long vpcId; - @Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="the account associated with the connection. 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 connection. " + - "If used with the account parameter returns the connection associated with the account for the specified domain.") - private Long domainId; - ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// @@ -64,14 +57,6 @@ public class CreateVpnGatewayCmd extends BaseAsyncCmd { return vpcId; } - public String getAccountName() { - return accountName; - } - - public Long getDomainId() { - return domainId; - } - ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// @@ -84,11 +69,8 @@ public class CreateVpnGatewayCmd extends BaseAsyncCmd { @Override public long getEntityOwnerId() { - Long accountId = finalyzeAccountId(accountName, domainId, null, true); - if (accountId == null) { - accountId = UserContext.current().getCaller().getId(); - } - return accountId; + Vpc vpc = _vpcService.getVpc(vpcId); + return vpc.getAccountId(); } @Override diff --git a/api/src/com/cloud/network/vpn/Site2SiteVpnService.java b/api/src/com/cloud/network/vpn/Site2SiteVpnService.java index ccad9617dc3..0e98b9e8786 100644 --- a/api/src/com/cloud/network/vpn/Site2SiteVpnService.java +++ b/api/src/com/cloud/network/vpn/Site2SiteVpnService.java @@ -40,7 +40,7 @@ public interface Site2SiteVpnService { Site2SiteVpnGateway createVpnGateway(CreateVpnGatewayCmd cmd); Site2SiteCustomerGateway createCustomerGateway(CreateVpnCustomerGatewayCmd cmd); Site2SiteVpnConnection startVpnConnection(long id) throws ResourceUnavailableException; - IpAddress getVpnGatewayIp(Long vpnGatewayId); + Site2SiteVpnGateway getVpnGateway(Long vpnGatewayId); Site2SiteVpnConnection createVpnConnection(CreateVpnConnectionCmd cmd) throws NetworkRuleConflictException; boolean deleteCustomerGateway(DeleteVpnCustomerGatewayCmd deleteVpnCustomerGatewayCmd); boolean deleteVpnGateway(DeleteVpnGatewayCmd deleteVpnGatewayCmd); diff --git a/server/src/com/cloud/network/vpn/Site2SiteVpnManagerImpl.java b/server/src/com/cloud/network/vpn/Site2SiteVpnManagerImpl.java index 2af0389e50f..c0be55e3701 100644 --- a/server/src/com/cloud/network/vpn/Site2SiteVpnManagerImpl.java +++ b/server/src/com/cloud/network/vpn/Site2SiteVpnManagerImpl.java @@ -265,10 +265,8 @@ public class Site2SiteVpnManagerImpl implements Site2SiteVpnManager, Manager { } @Override - public IpAddress getVpnGatewayIp(Long vpnGatewayId) { - Site2SiteVpnGatewayVO gateway = _vpnGatewayDao.findById(vpnGatewayId); - IpAddress ip = _networkMgr.getIp(gateway.getAddrId()); - return ip; + public Site2SiteVpnGateway getVpnGateway(Long vpnGatewayId) { + return _vpnGatewayDao.findById(vpnGatewayId); } @Override