@Override public Site2SiteVpnGateway getVpnGateway(Long vpnGatewayId) { return _vpnGatewayDao.findById(vpnGatewayId); }
@Override public boolean cleanupVpnGatewayByVpc(long vpcId) { Site2SiteVpnGatewayVO gw = _vpnGatewayDao.findByVpcId(vpcId); if (gw == null) { return true; } doDeleteVpnGateway(gw); return true; }
@Override @ActionEvent(eventType = EventTypes.EVENT_S2S_VPN_GATEWAY_UPDATE, eventDescription = "updating s2s vpn gateway", async = true) public Site2SiteVpnGateway updateVpnGateway(Long id, String customId, Boolean forDisplay) { Account caller = CallContext.current().getCallingAccount(); Site2SiteVpnGatewayVO vpnGateway = _vpnGatewayDao.findById(id); if (vpnGateway == null) { throw new InvalidParameterValueException("Fail to find vpn gateway with " + id); } _accountMgr.checkAccess(caller, null, false, vpnGateway); if (customId != null) { vpnGateway.setUuid(customId); } if (forDisplay != null) { vpnGateway.setDisplay(forDisplay); } _vpnGatewayDao.update(id, vpnGateway); return _vpnGatewayDao.findById(id); } }
Filter searchFilter = new Filter(Site2SiteVpnGatewayVO.class, "id", false, startIndex, pageSizeVal); SearchBuilder<Site2SiteVpnGatewayVO> sb = _vpnGatewayDao.createSearchBuilder(); _accountMgr.buildACLSearchBuilder(sb, domainId, isRecursive, permittedAccounts, listProjectResourcesCriteria); Pair<List<Site2SiteVpnGatewayVO>, Integer> result = _vpnGatewayDao.searchAndCount(sc, searchFilter); return new Pair<List<? extends Site2SiteVpnGateway>, Integer>(result.first(), result.second());
@PostConstruct protected void init() { AllFieldsSearch = createSearchBuilder(); AllFieldsSearch.and("customerGatewayId", AllFieldsSearch.entity().getCustomerGatewayId(), SearchCriteria.Op.EQ); AllFieldsSearch.and("vpnGatewayId", AllFieldsSearch.entity().getVpnGatewayId(), SearchCriteria.Op.EQ); AllFieldsSearch.done(); VpcSearch = createSearchBuilder(); VpnGatewaySearch = _vpnGatewayDao.createSearchBuilder(); VpnGatewaySearch.and("vpcId", VpnGatewaySearch.entity().getVpcId(), SearchCriteria.Op.EQ); VpcSearch.join("vpnGatewaySearch", VpnGatewaySearch, VpnGatewaySearch.entity().getId(), VpcSearch.entity().getVpnGatewayId(), JoinType.INNER); VpcSearch.done(); }
@Override @ActionEvent(eventType = EventTypes.EVENT_S2S_VPN_GATEWAY_CREATE, eventDescription = "creating s2s vpn gateway", async = true) public Site2SiteVpnGateway createVpnGateway(CreateVpnGatewayCmd cmd) { Account caller = CallContext.current().getCallingAccount(); Account owner = _accountMgr.getAccount(cmd.getEntityOwnerId()); //Verify that caller can perform actions in behalf of vpc owner _accountMgr.checkAccess(caller, null, false, owner); Long vpcId = cmd.getVpcId(); VpcVO vpc = _vpcDao.findById(vpcId); if (vpc == null) { throw new InvalidParameterValueException("Invalid VPC " + vpcId + " for site to site vpn gateway creation!"); } Site2SiteVpnGatewayVO gws = _vpnGatewayDao.findByVpcId(vpcId); if (gws != null) { throw new InvalidParameterValueException("The VPN gateway of VPC " + vpcId + " already existed!"); } //Use source NAT ip for VPC List<IPAddressVO> ips = _ipAddressDao.listByAssociatedVpc(vpcId, true); if (ips.size() != 1) { throw new CloudRuntimeException("Cannot found source nat ip of vpc " + vpcId); } Site2SiteVpnGatewayVO gw = new Site2SiteVpnGatewayVO(owner.getAccountId(), owner.getDomainId(), ips.get(0).getId(), vpcId); if (cmd.getDisplay() != null) { gw.setDisplay(cmd.getDisplay()); } _vpnGatewayDao.persist(gw); return gw; }
protected void doDeleteVpnGateway(Site2SiteVpnGateway gw) { List<Site2SiteVpnConnectionVO> conns = _vpnConnectionDao.listByVpnGatewayId(gw.getId()); if (conns != null && conns.size() != 0) { throw new InvalidParameterValueException("Unable to delete VPN gateway " + gw.getId() + " because there is still related VPN connections!"); } _vpnGatewayDao.remove(gw.getId()); }
SearchBuilder<Site2SiteVpnGatewayVO> gwSearch = _vpnGatewayDao.createSearchBuilder(); gwSearch.and("vpcId", gwSearch.entity().getVpcId(), SearchCriteria.Op.EQ); sb.join("gwSearch", gwSearch, sb.entity().getVpnGatewayId(), gwSearch.entity().getId(), JoinBuilder.JoinType.INNER);
public static Site2SiteVpnGatewayVO findVpnGatewayById(Long vpnGatewayId) { return s_site2SiteVpnGatewayDao.findById(vpnGatewayId); }
@Override public boolean startSite2SiteVpn(final Site2SiteVpnConnection conn) throws ResourceUnavailableException { final Site2SiteVpnGateway vpnGw = _vpnGatewayDao.findById(conn.getVpnGatewayId()); final IpAddress ip = _ipAddressDao.findById(vpnGw.getAddrId()); final Map<Capability, String> vpnCapabilities = capabilities.get(Service.Vpn); if (!vpnCapabilities.get(Capability.VpnTypes).contains("s2svpn")) { s_logger.error("try to start site 2 site vpn on unsupported network element?"); return false; } final Long vpcId = ip.getVpcId(); final Vpc vpc = _entityMgr.findById(Vpc.class, vpcId); if (!_ntwkModel.isProviderEnabledInZone(vpc.getZoneId(), Provider.VPCVirtualRouter.getName())) { throw new ResourceUnavailableException("VPC provider is not enabled in zone " + vpc.getZoneId(), DataCenter.class, vpc.getZoneId()); } final List<DomainRouterVO> routers = _vpcRouterMgr.getVpcRouters(ip.getVpcId()); if (routers == null) { throw new ResourceUnavailableException("Cannot enable site-to-site VPN on the backend; virtual router doesn't exist in the vpc " + ip.getVpcId(), DataCenter.class, vpc.getZoneId()); } boolean result = true; for (final DomainRouterVO domainRouterVO : routers) { result = result && _vpcRouterMgr.startSite2SiteVpn(conn, domainRouterVO); } return result; }
@Override public boolean stopSite2SiteVpn(final Site2SiteVpnConnection conn) throws ResourceUnavailableException { final Site2SiteVpnGateway vpnGw = _vpnGatewayDao.findById(conn.getVpnGatewayId()); final IpAddress ip = _ipAddressDao.findById(vpnGw.getAddrId()); final Map<Capability, String> vpnCapabilities = capabilities.get(Service.Vpn); if (!vpnCapabilities.get(Capability.VpnTypes).contains("s2svpn")) { s_logger.error("try to stop site 2 site vpn on unsupported network element?"); return false; } final Long vpcId = ip.getVpcId(); final Vpc vpc = _entityMgr.findById(Vpc.class, vpcId); if (!_ntwkModel.isProviderEnabledInZone(vpc.getZoneId(), Provider.VPCVirtualRouter.getName())) { throw new ResourceUnavailableException("VPC provider is not enabled in zone " + vpc.getZoneId(), DataCenter.class, vpc.getZoneId()); } final List<DomainRouterVO> routers = _vpcRouterMgr.getVpcRouters(ip.getVpcId()); if (routers == null) { throw new ResourceUnavailableException("Cannot enable site-to-site VPN on the backend; virtual router doesn't exist in the vpc " + ip.getVpcId(), DataCenter.class, vpc.getZoneId()); } boolean result = true; for (final DomainRouterVO domainRouterVO : routers) { result = result && _vpcRouterMgr.stopSite2SiteVpn(conn, domainRouterVO); } return result; }
@Override @ActionEvent(eventType = EventTypes.EVENT_S2S_VPN_GATEWAY_DELETE, eventDescription = "deleting s2s vpn gateway", async = true) public boolean deleteVpnGateway(DeleteVpnGatewayCmd cmd) { CallContext.current().setEventDetails(" Id: " + cmd.getId()); Account caller = CallContext.current().getCallingAccount(); Long id = cmd.getId(); Site2SiteVpnGateway vpnGateway = _vpnGatewayDao.findById(id); if (vpnGateway == null) { throw new InvalidParameterValueException("Fail to find vpn gateway with " + id + " !"); } _accountMgr.checkAccess(caller, null, false, vpnGateway); doDeleteVpnGateway(vpnGateway); return true; }
Site2SiteVpnGateway vpnGateway = _vpnGatewayDao.findById(vpnGatewayId); if (vpnGateway == null) { throw new InvalidParameterValueException("Unable to found specified Site to Site VPN gateway " + vpnGatewayId + " !");
public void createSite2SiteVpnCfgCommands(final Site2SiteVpnConnection conn, final boolean isCreate, final VirtualRouter router, final Commands cmds) { final Site2SiteCustomerGatewayVO gw = _s2sCustomerGatewayDao.findById(conn.getCustomerGatewayId()); final Site2SiteVpnGatewayVO vpnGw = _s2sVpnGatewayDao.findById(conn.getVpnGatewayId()); final IpAddress ip = _ipAddressDao.findById(vpnGw.getAddrId()); final Vpc vpc = _vpcDao.findById(ip.getVpcId()); final String localPublicIp = ip.getAddress().toString(); final String localGuestCidr = vpc.getCidr(); final String localPublicGateway = _vlanDao.findById(ip.getVlanId()).getVlanGateway(); final String peerGatewayIp = gw.getGatewayIp(); final String peerGuestCidrList = gw.getGuestCidrList(); final String ipsecPsk = gw.getIpsecPsk(); final String ikePolicy = gw.getIkePolicy(); final String espPolicy = gw.getEspPolicy(); final Long ikeLifetime = gw.getIkeLifetime(); final Long espLifetime = gw.getEspLifetime(); final Boolean dpd = gw.getDpd(); final Boolean encap = gw.getEncap(); final Site2SiteVpnCfgCommand cmd = new Site2SiteVpnCfgCommand(isCreate, localPublicIp, localPublicGateway, localGuestCidr, peerGatewayIp, peerGuestCidrList, ikePolicy, espPolicy, ipsecPsk, ikeLifetime, espLifetime, dpd, conn.isPassive(), encap); cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, _routerControlHelper.getRouterControlIp(router.getId())); cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, _routerControlHelper.getRouterControlIp(router.getId())); cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName()); final DataCenterVO dcVo = _dcDao.findById(router.getDataCenterId()); cmd.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE, dcVo.getNetworkType().toString()); cmds.addCommand("applyS2SVpn", cmd); }