use of com.cloud.legacymodel.network.vpc.Vpc in project cosmic by MissionCriticalCloud.
the class QueryManagerImpl method listWhoHasThisIp.
@Override
public ListResponse<WhoHasThisAddressResponse> listWhoHasThisIp(final ListWhoHasThisIpCmd cmd) {
final ListResponse<WhoHasThisAddressResponse> whoHasThisIpList = new ListResponse<>();
final List<WhoHasThisAddressResponse> responsesList = new ArrayList<>();
final String cleanedIpAddress = StringUtils.deleteWhitespace(cmd.getIpAddress());
final List<IPAddressVO> ipAddresses = _ipAddressDao.listByIpAddress(cleanedIpAddress);
ipAddresses.forEach(ipAddress -> {
final WhoHasThisAddressResponse response = new WhoHasThisAddressResponse();
response.setObjectName("whohasthisip");
response.setIpAddress(ipAddress.getAddress().toString());
response.setUuid(ipAddress.getUuid());
response.setState(ipAddress.getState().toString());
final Domain domain = _domainDao.findById(ipAddress.getDomainId());
if (domain != null) {
response.setDomainName(domain.getName());
response.setDomainUuid(domain.getUuid());
}
final Network network = _networkDao.findById(ipAddress.getNetworkId());
if (network != null) {
response.setNetworkUuid(network.getUuid());
response.setCreated(ipAddress.getAllocatedTime());
response.setMode(network.getMode());
}
if (ipAddress.getVpcId() != null) {
final Vpc vpc = _vpcDao.findById(ipAddress.getVpcId());
if (vpc != null) {
response.setNetworkName(vpc.getName());
response.setVpcName(vpc.getName());
response.setVpcUuid(vpc.getUuid());
}
} else if (network != null && !StringUtils.isEmpty(network.getName())) {
response.setNetworkName(network.getName());
}
final Network associatedNetwork = _networkDao.findById(ipAddress.getAssociatedWithNetworkId());
if (associatedNetwork != null) {
response.setAssociatedNetworkName(associatedNetwork.getName());
response.setAssociatedNetworkUuid(associatedNetwork.getUuid());
}
responsesList.add(response);
});
final List<NicVO> nics = _nicDao.listByIpAddress(cleanedIpAddress);
nics.forEach(nic -> {
final WhoHasThisAddressResponse response = new WhoHasThisAddressResponse();
response.setObjectName("whohasthisip");
queryNicsTableResponse(responsesList, nic, response);
});
final List<NicSecondaryIpVO> nicSecondaryIps = _nicSecondaryIpDao.listByIpAddress(cleanedIpAddress);
nicSecondaryIps.forEach(nicSecondaryIp -> {
final WhoHasThisAddressResponse response = new WhoHasThisAddressResponse();
response.setObjectName("whohasthisip");
response.setIpAddress(nicSecondaryIp.getIp4Address());
response.setUuid(nicSecondaryIp.getUuid());
response.setCreated(nicSecondaryIp.getCreated());
final NicVO nicVO = _nicDao.findById(nicSecondaryIp.getNicId());
if (nicVO != null) {
response.setMode(nicVO.getMode());
response.setBroadcastUri(nicVO.getBroadcastUri());
response.setNetmask(nicVO.getIPv4Netmask());
response.setMacAddress(nicVO.getMacAddress());
response.setState(nicVO.getState().toString());
}
final Network network = _networkDao.findById(nicSecondaryIp.getNetworkId());
if (network != null) {
response.setNetworkUuid(network.getUuid());
if (!StringUtils.isEmpty(network.getName())) {
response.setNetworkName(network.getName());
}
}
final VMInstanceVO vm = _vmInstanceDao.findById(nicSecondaryIp.getVmId());
getVMInfo(response, nicVO, vm);
responsesList.add(response);
});
final Account account = CallContext.current().getCallingAccount();
final Domain domain = _domainDao.findById(account.getDomainId());
final List<WhoHasThisAddressResponse> filteredResponsesList = responsesList.stream().filter(response -> ((account.getDomainId() == Domain.ROOT_DOMAIN || domain.getUuid().equals(response.getDomainUuid())) && (StringUtils.isEmpty(cmd.getUuid()) || (!StringUtils.isEmpty(cmd.getUuid()) && response.getUuid().equals(cmd.getUuid()))))).skip(cmd.getStartIndex()).limit(cmd.getPageSizeVal()).collect(Collectors.toList());
whoHasThisIpList.setResponses(filteredResponsesList);
return whoHasThisIpList;
}
use of com.cloud.legacymodel.network.vpc.Vpc in project cosmic by MissionCriticalCloud.
the class VpcVirtualRouterElement method implement.
@Override
public boolean implement(final Network network, final NetworkOffering offering, final DeployDestination dest, final ReservationContext context) throws ResourceUnavailableException, ConcurrentOperationException, InsufficientCapacityException {
final Long vpcId = network.getVpcId();
if (vpcId == null) {
s_logger.trace("Network " + network + " is not associated with any VPC");
return false;
}
final Vpc vpc = _vpcMgr.getActiveVpc(vpcId);
if (vpc == null) {
s_logger.warn("Unable to find Enabled VPC by id " + vpcId);
return false;
}
final Map<VirtualMachineProfile.Param, Object> params = new HashMap<>(1);
params.put(VirtualMachineProfile.Param.ReProgramGuestNetworks, true);
final RouterDeploymentDefinition routerDeploymentDefinition = routerDeploymentDefinitionBuilder.create().setGuestNetwork(network).setVpc(vpc).setDeployDestination(dest).setAccountOwner(_accountMgr.getAccount(vpc.getAccountId())).setParams(params).build();
final List<DomainRouterVO> routers = routerDeploymentDefinition.deployVirtualRouter();
if (routers == null || routers.size() == 0) {
throw new ResourceUnavailableException("Can't find at least one running router!", DataCenter.class, network.getDataCenterId());
}
configureGuestNetwork(network, routers);
return true;
}
use of com.cloud.legacymodel.network.vpc.Vpc in project cosmic by MissionCriticalCloud.
the class VpcVirtualRouterElement method prepare.
@Override
public boolean prepare(final Network network, final NicProfile nic, final VirtualMachineProfile vm, final DeployDestination dest, final ReservationContext context) throws ConcurrentOperationException, InsufficientCapacityException, ResourceUnavailableException, IllegalVirtualMachineException {
final Long vpcId = network.getVpcId();
if (vpcId == null) {
s_logger.trace("Network " + network + " is not associated with any VPC");
return false;
}
final Vpc vpc = _vpcMgr.getActiveVpc(vpcId);
if (vpc == null) {
s_logger.warn("Unable to find Enabled VPC by id " + vpcId);
return false;
}
if (vm.getType() == VirtualMachineType.User) {
final Map<VirtualMachineProfile.Param, Object> params = new HashMap<>(1);
params.put(VirtualMachineProfile.Param.ReProgramGuestNetworks, true);
final RouterDeploymentDefinition routerDeploymentDefinition = routerDeploymentDefinitionBuilder.create().setGuestNetwork(network).setVpc(vpc).setDeployDestination(dest).setAccountOwner(_accountMgr.getAccount(vpc.getAccountId())).setParams(params).build();
final List<DomainRouterVO> routers = routerDeploymentDefinition.deployVirtualRouter();
if (routers == null || routers.size() == 0) {
throw new ResourceUnavailableException("Can't find at least one running router!", DataCenter.class, network.getDataCenterId());
}
configureGuestNetwork(network, routers);
}
return true;
}
use of com.cloud.legacymodel.network.vpc.Vpc in project cosmic by MissionCriticalCloud.
the class VpcVirtualRouterElement method applyVpnUsers.
@Override
public String[] applyVpnUsers(final RemoteAccessVpn vpn, final List<? extends VpnUser> users) throws ResourceUnavailableException {
final Long vpcId = vpn.getVpcId();
if (vpcId == null) {
return null;
}
final List<DomainRouterVO> routers = _vpcRouterMgr.getVpcRouters(vpcId);
if (routers == null) {
s_logger.debug("Cannot apply vpn users on the backend; virtual router doesn't exist in the network " + vpcId);
return null;
}
final Vpc vpc = _entityMgr.findById(Vpc.class, vpcId);
final Zone zone = zoneRepository.findById(vpc.getZoneId()).orElse(null);
final NetworkTopology networkTopology = networkTopologyContext.retrieveNetworkTopology(zone);
String[] result;
final List<String> combinedResults = new ArrayList<>();
for (final DomainRouterVO domainRouterVO : routers) {
result = networkTopology.applyVpnUsers(vpn, users, domainRouterVO);
combinedResults.addAll(Arrays.asList(result));
}
result = new String[combinedResults.size()];
final Object[] resultCast = combinedResults.toArray();
System.arraycopy(resultCast, 0, result, 0, resultCast.length);
return result;
}
use of com.cloud.legacymodel.network.vpc.Vpc in project cosmic by MissionCriticalCloud.
the class VpcVirtualRouterElement method startSite2SiteVpn.
@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;
}
Aggregations