Search in sources :

Example 11 with Site2SiteVpnGateway

use of com.cloud.network.Site2SiteVpnGateway in project cosmic by MissionCriticalCloud.

the class Site2SiteVpnManagerImpl method createVpnConnection.

@Override
@ActionEvent(eventType = EventTypes.EVENT_S2S_VPN_CONNECTION_CREATE, eventDescription = "creating s2s vpn connection", create = true)
public Site2SiteVpnConnection createVpnConnection(final CreateVpnConnectionCmd cmd) throws NetworkRuleConflictException {
    final Account caller = CallContext.current().getCallingAccount();
    final Account owner = _accountMgr.getAccount(cmd.getEntityOwnerId());
    // Verify that caller can perform actions in behalf of vpc owner
    _accountMgr.checkAccess(caller, null, false, owner);
    final Long customerGatewayId = cmd.getCustomerGatewayId();
    final Site2SiteCustomerGateway customerGateway = _customerGatewayDao.findById(customerGatewayId);
    if (customerGateway == null) {
        throw new InvalidParameterValueException("Unable to found specified Site to Site VPN customer gateway " + customerGatewayId + " !");
    }
    _accountMgr.checkAccess(caller, null, false, customerGateway);
    final Long vpnGatewayId = cmd.getVpnGatewayId();
    final Site2SiteVpnGateway vpnGateway = _vpnGatewayDao.findById(vpnGatewayId);
    if (vpnGateway == null) {
        throw new InvalidParameterValueException("Unable to found specified Site to Site VPN gateway " + vpnGatewayId + " !");
    }
    _accountMgr.checkAccess(caller, null, false, vpnGateway);
    if (customerGateway.getAccountId() != vpnGateway.getAccountId() || customerGateway.getDomainId() != vpnGateway.getDomainId()) {
        throw new InvalidParameterValueException("VPN connection can only be esitablished between same account's VPN gateway and customer gateway!");
    }
    if (_vpnConnectionDao.findByVpnGatewayIdAndCustomerGatewayId(vpnGatewayId, customerGatewayId) != null) {
        throw new InvalidParameterValueException("The vpn connection with customer gateway id " + customerGatewayId + " and vpn gateway id " + vpnGatewayId + " already existed!");
    }
    final String[] cidrList = customerGateway.getGuestCidrList().split(",");
    // Remote sub nets cannot overlap VPC's sub net
    final String vpcCidr = _vpcDao.findById(vpnGateway.getVpcId()).getCidr();
    for (final String cidr : cidrList) {
        if (NetUtils.isNetworksOverlap(vpcCidr, cidr)) {
            throw new InvalidParameterValueException("The subnets of customer gateway " + customerGatewayId + "'s subnet " + cidr + " is overlapped with VPC cidr " + vpcCidr + "!");
        }
    }
    // We also need to check if the new connection's remote CIDR is overlapped with existed connections
    final List<Site2SiteVpnConnectionVO> conns = _vpnConnectionDao.listByVpnGatewayId(vpnGatewayId);
    if (conns.size() >= _connLimit) {
        throw new InvalidParameterValueException("There are too many VPN connections with current VPN gateway! The limit is " + _connLimit);
    }
    for (final Site2SiteVpnConnectionVO vc : conns) {
        if (vc == null) {
            continue;
        }
        final Site2SiteCustomerGatewayVO gw = _customerGatewayDao.findById(vc.getCustomerGatewayId());
        final String[] oldCidrList = gw.getGuestCidrList().split(",");
        for (final String oldCidr : oldCidrList) {
            for (final String cidr : cidrList) {
                if (NetUtils.isNetworksOverlap(cidr, oldCidr)) {
                    throw new InvalidParameterValueException("The new connection's remote subnet " + cidr + " is overlapped with existed VPN connection to customer gateway " + gw.getName() + "'s subnet " + oldCidr);
                }
            }
        }
    }
    final Site2SiteVpnConnectionVO conn = new Site2SiteVpnConnectionVO(owner.getAccountId(), owner.getDomainId(), vpnGatewayId, customerGatewayId, cmd.isPassive());
    conn.setState(State.Pending);
    if (cmd.getDisplay() != null) {
        conn.setDisplay(cmd.getDisplay());
    }
    _vpnConnectionDao.persist(conn);
    return conn;
}
Also used : Account(com.cloud.user.Account) Site2SiteVpnGateway(com.cloud.network.Site2SiteVpnGateway) InvalidParameterValueException(com.cloud.utils.exception.InvalidParameterValueException) Site2SiteCustomerGatewayVO(com.cloud.network.dao.Site2SiteCustomerGatewayVO) Site2SiteVpnConnectionVO(com.cloud.network.dao.Site2SiteVpnConnectionVO) Site2SiteCustomerGateway(com.cloud.network.Site2SiteCustomerGateway) ActionEvent(com.cloud.event.ActionEvent)

Example 12 with Site2SiteVpnGateway

use of com.cloud.network.Site2SiteVpnGateway in project cloudstack by apache.

the class ListVpnGatewaysCmd method execute.

@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());
    setResponseObject(response);
}
Also used : Site2SiteVpnGateway(com.cloud.network.Site2SiteVpnGateway) Site2SiteVpnGatewayResponse(org.apache.cloudstack.api.response.Site2SiteVpnGatewayResponse) ListResponse(org.apache.cloudstack.api.response.ListResponse) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 13 with Site2SiteVpnGateway

use of com.cloud.network.Site2SiteVpnGateway in project cloudstack by apache.

the class CreateVpnGatewayCmd method create.

@Override
public void create() throws ResourceAllocationException {
    Site2SiteVpnGateway result = _s2sVpnService.createVpnGateway(this);
    if (result != null) {
        setEntityId(result.getId());
        setEntityUuid(result.getUuid());
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create VPN gateway");
    }
}
Also used : Site2SiteVpnGateway(com.cloud.network.Site2SiteVpnGateway) ServerApiException(org.apache.cloudstack.api.ServerApiException)

Example 14 with Site2SiteVpnGateway

use of com.cloud.network.Site2SiteVpnGateway in project cloudstack by apache.

the class CreateVpnGatewayCmd method execute.

@Override
public void execute() {
    CallContext.current().setEventDetails("VPN gateway Id: " + getEntityId());
    Site2SiteVpnGateway result = _s2sVpnService.getVpnGateway(getEntityId());
    if (result != null) {
        Site2SiteVpnGatewayResponse response = _responseGenerator.createSite2SiteVpnGatewayResponse(result);
        response.setResponseName(getCommandName());
        setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create VPN gateway");
    }
}
Also used : Site2SiteVpnGateway(com.cloud.network.Site2SiteVpnGateway) Site2SiteVpnGatewayResponse(org.apache.cloudstack.api.response.Site2SiteVpnGatewayResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException)

Example 15 with Site2SiteVpnGateway

use of com.cloud.network.Site2SiteVpnGateway in project cloudstack by apache.

the class UpdateVpnGatewayCmd method execute.

// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() {
    Site2SiteVpnGateway result = _s2sVpnService.updateVpnGateway(id, this.getCustomId(), getDisplay());
    if (result != null) {
        Site2SiteVpnGatewayResponse response = _responseGenerator.createSite2SiteVpnGatewayResponse(result);
        response.setResponseName(getCommandName());
    }
}
Also used : Site2SiteVpnGateway(com.cloud.network.Site2SiteVpnGateway) Site2SiteVpnGatewayResponse(org.apache.cloudstack.api.response.Site2SiteVpnGatewayResponse)

Aggregations

Site2SiteVpnGateway (com.cloud.network.Site2SiteVpnGateway)19 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)5 IpAddress (com.cloud.network.IpAddress)5 Capability (com.cloud.network.Network.Capability)5 PublicIpAddress (com.cloud.network.PublicIpAddress)5 Vpc (com.cloud.network.vpc.Vpc)5 DomainRouterVO (com.cloud.vm.DomainRouterVO)5 ActionEvent (com.cloud.event.ActionEvent)4 Site2SiteCustomerGateway (com.cloud.network.Site2SiteCustomerGateway)4 Account (com.cloud.user.Account)4 Site2SiteVpnGatewayResponse (com.cloud.api.response.Site2SiteVpnGatewayResponse)3 Site2SiteVpnGatewayResponse (org.apache.cloudstack.api.response.Site2SiteVpnGatewayResponse)3 ServerApiException (com.cloud.api.ServerApiException)2 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)2 IPAddressVO (com.cloud.network.dao.IPAddressVO)2 Site2SiteCustomerGatewayVO (com.cloud.network.dao.Site2SiteCustomerGatewayVO)2 Site2SiteVpnConnectionVO (com.cloud.network.dao.Site2SiteVpnConnectionVO)2 InvalidParameterValueException (com.cloud.utils.exception.InvalidParameterValueException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2