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