Search in sources :

Example 11 with Vpc

use of com.cloud.legacymodel.network.vpc.Vpc in project cosmic by MissionCriticalCloud.

the class NetworkACLServiceImpl method replaceNetworkACL.

@Override
public boolean replaceNetworkACL(final long aclId, final long networkId) throws ResourceUnavailableException {
    final Account caller = CallContext.current().getCallingAccount();
    final NetworkVO network = _networkDao.findById(networkId);
    if (network == null) {
        throw new InvalidParameterValueException("Unable to find specified Network");
    }
    final NetworkACL acl = _networkACLDao.findById(aclId);
    if (acl == null) {
        throw new InvalidParameterValueException("Unable to find specified NetworkACL");
    }
    if (network.getVpcId() == null) {
        throw new InvalidParameterValueException("Network is not part of a VPC: " + network.getUuid());
    }
    if (network.getTrafficType() != TrafficType.Guest) {
        throw new InvalidParameterValueException("Network ACL can be created just for networks of type " + TrafficType.Guest);
    }
    if (aclId != NetworkACL.DEFAULT_DENY && aclId != NetworkACL.DEFAULT_ALLOW) {
        // ACL is not default DENY/ALLOW
        // ACL should be associated with a VPC
        final Vpc vpc = _entityMgr.findById(Vpc.class, acl.getVpcId());
        if (vpc == null) {
            throw new InvalidParameterValueException("Unable to find Vpc associated with the NetworkACL");
        }
        _accountMgr.checkAccess(caller, null, true, vpc);
        if (!network.getVpcId().equals(acl.getVpcId())) {
            throw new InvalidParameterValueException("Network: " + networkId + " and ACL: " + aclId + " do not belong to the same VPC");
        }
    }
    return _networkAclMgr.replaceNetworkACL(acl, network);
}
Also used : Account(com.cloud.legacymodel.user.Account) NetworkVO(com.cloud.network.dao.NetworkVO) InvalidParameterValueException(com.cloud.legacymodel.exceptions.InvalidParameterValueException) Vpc(com.cloud.legacymodel.network.vpc.Vpc) NetworkACL(com.cloud.legacymodel.network.vpc.NetworkACL)

Example 12 with Vpc

use of com.cloud.legacymodel.network.vpc.Vpc in project cosmic by MissionCriticalCloud.

the class VpcVirtualRouterElement method refreshSite2SiteVpn.

@Override
public boolean refreshSite2SiteVpn(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 refresh site-to-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.refreshSite2SiteVpn(conn, domainRouterVO);
    }
    return result;
}
Also used : Site2SiteVpnGateway(com.cloud.network.Site2SiteVpnGateway) Capability(com.cloud.legacymodel.network.Network.Capability) Vpc(com.cloud.legacymodel.network.vpc.Vpc) ResourceUnavailableException(com.cloud.legacymodel.exceptions.ResourceUnavailableException) IpAddress(com.cloud.network.IpAddress) PublicIpAddress(com.cloud.network.PublicIpAddress) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 13 with Vpc

use of com.cloud.legacymodel.network.vpc.Vpc in project cosmic by MissionCriticalCloud.

the class VpcVirtualRouterElement method getRouters.

@Override
protected List<DomainRouterVO> getRouters(final Network network, final DeployDestination dest) {
    // 1st time it runs the domain router of the VM shall be returned
    List<DomainRouterVO> routers = super.getRouters(network, dest);
    if (routers.size() > 0) {
        return routers;
    }
    // For the 2nd time it returns the VPC routers.
    final Long vpcId = network.getVpcId();
    if (vpcId == null) {
        s_logger.error("Network " + network + " is not associated with any VPC");
        return routers;
    }
    final Vpc vpc = _vpcMgr.getActiveVpc(vpcId);
    if (vpc == null) {
        s_logger.warn("Unable to find Enabled VPC by id " + vpcId);
        return routers;
    }
    final RouterDeploymentDefinition routerDeploymentDefinition = routerDeploymentDefinitionBuilder.create().setGuestNetwork(network).setVpc(vpc).setDeployDestination(dest).setAccountOwner(_accountMgr.getAccount(vpc.getAccountId())).build();
    try {
        routers = routerDeploymentDefinition.deployVirtualRouter();
    } catch (final ConcurrentOperationException e) {
        s_logger.error("Error occurred when loading routers from routerDeploymentDefinition.deployVirtualRouter()!", e);
    } catch (final InsufficientCapacityException e) {
        s_logger.error("Error occurred when loading routers from routerDeploymentDefinition.deployVirtualRouter()!", e);
    } catch (final ResourceUnavailableException e) {
        s_logger.error("Error occurred when loading routers from routerDeploymentDefinition.deployVirtualRouter()!", e);
    }
    return routers;
}
Also used : RouterDeploymentDefinition(com.cloud.network.router.deployment.RouterDeploymentDefinition) Vpc(com.cloud.legacymodel.network.vpc.Vpc) ResourceUnavailableException(com.cloud.legacymodel.exceptions.ResourceUnavailableException) InsufficientCapacityException(com.cloud.legacymodel.exceptions.InsufficientCapacityException) ConcurrentOperationException(com.cloud.legacymodel.exceptions.ConcurrentOperationException) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 14 with Vpc

use of com.cloud.legacymodel.network.vpc.Vpc in project cosmic by MissionCriticalCloud.

the class VpcVirtualRouterElement method stopSite2SiteVpn.

@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;
}
Also used : Site2SiteVpnGateway(com.cloud.network.Site2SiteVpnGateway) Capability(com.cloud.legacymodel.network.Network.Capability) Vpc(com.cloud.legacymodel.network.vpc.Vpc) ResourceUnavailableException(com.cloud.legacymodel.exceptions.ResourceUnavailableException) IpAddress(com.cloud.network.IpAddress) PublicIpAddress(com.cloud.network.PublicIpAddress) DomainRouterVO(com.cloud.vm.DomainRouterVO)

Example 15 with Vpc

use of com.cloud.legacymodel.network.vpc.Vpc in project cosmic by MissionCriticalCloud.

the class VpcVirtualRouterElementTest method testApplyVpnUsers.

@Test
public void testApplyVpnUsers() {
    vpcVirtualRouterElement._vpcRouterMgr = _vpcRouterMgr;
    final AdvancedNetworkTopology advancedNetworkTopology = Mockito.mock(AdvancedNetworkTopology.class);
    final BasicNetworkTopology basicNetworkTopology = Mockito.mock(BasicNetworkTopology.class);
    networkTopologyContext.setAdvancedNetworkTopology(advancedNetworkTopology);
    networkTopologyContext.setBasicNetworkTopology(basicNetworkTopology);
    networkTopologyContext.init();
    final Vpc vpc = Mockito.mock(Vpc.class);
    final Zone zone = Mockito.mock(Zone.class);
    final RemoteAccessVpn remoteAccessVpn = Mockito.mock(RemoteAccessVpn.class);
    final DomainRouterVO domainRouterVO1 = Mockito.mock(DomainRouterVO.class);
    final DomainRouterVO domainRouterVO2 = Mockito.mock(DomainRouterVO.class);
    final VpnUser vpnUser1 = Mockito.mock(VpnUser.class);
    final VpnUser vpnUser2 = Mockito.mock(VpnUser.class);
    final List<VpnUser> users = new ArrayList<>();
    users.add(vpnUser1);
    users.add(vpnUser2);
    final List<DomainRouterVO> routers = new ArrayList<>();
    routers.add(domainRouterVO1);
    routers.add(domainRouterVO2);
    final Long vpcId = new Long(1l);
    final Long zoneId = new Long(1l);
    when(remoteAccessVpn.getVpcId()).thenReturn(vpcId);
    when(_vpcRouterMgr.getVpcRouters(vpcId)).thenReturn(routers);
    when(_entityMgr.findById(Vpc.class, vpcId)).thenReturn(vpc);
    when(vpc.getZoneId()).thenReturn(zoneId);
    when(zoneRepository.findById(zoneId)).thenReturn(Optional.of(zone));
    when(networkTopologyContext.retrieveNetworkTopology(zone)).thenReturn(advancedNetworkTopology);
    try {
        when(advancedNetworkTopology.applyVpnUsers(remoteAccessVpn, users, domainRouterVO1)).thenReturn(new String[] { "user1", "user2" });
        when(advancedNetworkTopology.applyVpnUsers(remoteAccessVpn, users, domainRouterVO2)).thenReturn(new String[] { "user3", "user4" });
    } catch (final ResourceUnavailableException e) {
        fail(e.getMessage());
    }
    try {
        final String[] results = vpcVirtualRouterElement.applyVpnUsers(remoteAccessVpn, users);
        assertNotNull(results);
        assertEquals(results[0], "user1");
        assertEquals(results[1], "user2");
        assertEquals(results[2], "user3");
        assertEquals(results[3], "user4");
    } catch (final ResourceUnavailableException e) {
        fail(e.getMessage());
    }
    verify(remoteAccessVpn, times(1)).getVpcId();
    verify(vpc, times(1)).getZoneId();
    verify(zoneRepository, times(1)).findById(zoneId);
    verify(networkTopologyContext, times(1)).retrieveNetworkTopology(zone);
}
Also used : BasicNetworkTopology(com.cloud.network.topology.BasicNetworkTopology) Zone(com.cloud.db.model.Zone) Vpc(com.cloud.legacymodel.network.vpc.Vpc) ArrayList(java.util.ArrayList) AdvancedNetworkTopology(com.cloud.network.topology.AdvancedNetworkTopology) VpnUser(com.cloud.legacymodel.network.VpnUser) ResourceUnavailableException(com.cloud.legacymodel.exceptions.ResourceUnavailableException) RemoteAccessVpn(com.cloud.network.RemoteAccessVpn) DomainRouterVO(com.cloud.vm.DomainRouterVO) Test(org.junit.Test)

Aggregations

Vpc (com.cloud.legacymodel.network.vpc.Vpc)60 InvalidParameterValueException (com.cloud.legacymodel.exceptions.InvalidParameterValueException)24 Account (com.cloud.legacymodel.user.Account)24 ResourceUnavailableException (com.cloud.legacymodel.exceptions.ResourceUnavailableException)17 DomainRouterVO (com.cloud.vm.DomainRouterVO)17 Network (com.cloud.legacymodel.network.Network)15 ArrayList (java.util.ArrayList)14 NetworkACL (com.cloud.legacymodel.network.vpc.NetworkACL)11 ActionEvent (com.cloud.event.ActionEvent)9 ConcurrentOperationException (com.cloud.legacymodel.exceptions.ConcurrentOperationException)9 CloudRuntimeException (com.cloud.legacymodel.exceptions.CloudRuntimeException)8 NetworkVO (com.cloud.network.dao.NetworkVO)8 List (java.util.List)8 ServerApiException (com.cloud.api.ServerApiException)7 InsufficientCapacityException (com.cloud.legacymodel.exceptions.InsufficientCapacityException)7 IPAddressVO (com.cloud.network.dao.IPAddressVO)7 DB (com.cloud.utils.db.DB)7 VpcResponse (com.cloud.api.response.VpcResponse)6 CallContext (com.cloud.context.CallContext)6 DataCenter (com.cloud.legacymodel.dc.DataCenter)6