use of com.cloud.legacymodel.dc.DataCenter in project cosmic by MissionCriticalCloud.
the class ApiResponseHelper method createVpcResponse.
@Override
public VpcResponse createVpcResponse(final ResponseView view, final Vpc vpc) {
final VpcResponse response = new VpcResponse();
response.setId(vpc.getUuid());
response.setName(vpc.getName());
response.setDisplayText(vpc.getDisplayText());
response.setState(vpc.getState().name());
final VpcOffering voff = ApiDBUtils.findVpcOfferingById(vpc.getVpcOfferingId());
if (voff != null) {
response.setVpcOfferingId(voff.getUuid());
response.setVpcOfferingName(voff.getName());
response.setVpcOfferingDisplayText(voff.getDisplayText());
}
response.setCidr(vpc.getCidr());
response.setRestartRequired(vpc.isRestartRequired());
response.setNetworkDomain(vpc.getNetworkDomain());
response.setForDisplay(vpc.isDisplay());
response.setRedundantRouter(vpc.isRedundant());
response.setSourceNatList(vpc.getSourceNatList());
response.setSyslogServerList(vpc.getSyslogServerList());
response.setAdvertInterval(vpc.getAdvertInterval());
response.setAdvertMethod(vpc.getAdvertMethod());
response.setComplianceStatus(vpc.getComplianceStatus());
final Map<Service, Set<Provider>> serviceProviderMap = ApiDBUtils.listVpcOffServices(vpc.getVpcOfferingId());
final List<ServiceResponse> serviceResponses = getServiceResponses(serviceProviderMap);
final List<NetworkResponse> networkResponses = new ArrayList<>();
final List<? extends Network> networks = ApiDBUtils.listVpcNetworks(vpc.getId());
for (final Network network : networks) {
final NetworkResponse ntwkRsp = createNetworkResponse(view, network);
networkResponses.add(ntwkRsp);
}
final DataCenter zone = ApiDBUtils.findZoneById(vpc.getZoneId());
if (zone != null) {
response.setZoneId(zone.getUuid());
response.setZoneName(zone.getName());
}
response.setNetworks(networkResponses);
response.setServices(serviceResponses);
populateOwner(response, vpc);
// set tag information
final List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(ResourceObjectType.Vpc, vpc.getId());
final List<ResourceTagResponse> tagResponses = new ArrayList<>();
for (final ResourceTag tag : tags) {
final ResourceTagResponse tagResponse = createResourceTagResponse(tag, true);
if (tagResponse != null) {
tagResponses.add(tagResponse);
}
}
response.setTags(tagResponses);
response.setObjectName("vpc");
return response;
}
use of com.cloud.legacymodel.dc.DataCenter in project cosmic by MissionCriticalCloud.
the class ApiResponseHelper method createPodResponse.
@Override
public PodResponse createPodResponse(final Pod pod, final Boolean showCapacities) {
String[] ipRange = new String[2];
if (pod.getDescription() != null && pod.getDescription().length() > 0) {
ipRange = pod.getDescription().split("-");
} else {
ipRange[0] = pod.getDescription();
}
final PodResponse podResponse = new PodResponse();
podResponse.setId(pod.getUuid());
podResponse.setName(pod.getName());
final DataCenter zone = ApiDBUtils.findZoneById(pod.getDataCenterId());
if (zone != null) {
podResponse.setZoneId(zone.getUuid());
podResponse.setZoneName(zone.getName());
}
podResponse.setNetmask(NetUtils.getCidrNetmask(pod.getCidrSize()));
podResponse.setStartIp(ipRange[0]);
podResponse.setEndIp(ipRange.length > 1 && ipRange[1] != null ? ipRange[1] : "");
podResponse.setGateway(pod.getGateway());
podResponse.setAllocationState(pod.getAllocationState().toString());
if (showCapacities != null && showCapacities) {
final List<SummedCapacity> capacities = ApiDBUtils.getCapacityByClusterPodZone(null, pod.getId(), null);
final Set<CapacityResponse> capacityResponses = new HashSet<>();
for (final SummedCapacity capacity : capacities) {
final CapacityResponse capacityResponse = new CapacityResponse();
capacityResponse.setCapacityType(capacity.getCapacityType());
capacityResponse.setCapacityUsed(capacity.getUsedCapacity() + capacity.getReservedCapacity());
if (capacity.getCapacityType() == Capacity.CAPACITY_TYPE_STORAGE_ALLOCATED) {
final List<SummedCapacity> c = ApiDBUtils.findNonSharedStorageForClusterPodZone(null, pod.getId(), null);
capacityResponse.setCapacityTotal(capacity.getTotalCapacity() - c.get(0).getTotalCapacity());
capacityResponse.setCapacityUsed(capacity.getUsedCapacity() - c.get(0).getUsedCapacity());
} else {
capacityResponse.setCapacityTotal(capacity.getTotalCapacity());
}
if (capacityResponse.getCapacityTotal() != 0) {
capacityResponse.setPercentageAllocated(s_percentFormat.format((float) capacityResponse.getCapacityUsed() / (float) capacityResponse.getCapacityTotal() * 100f));
} else {
capacityResponse.setPercentageAllocated(s_percentFormat.format(0L));
}
capacityResponses.add(capacityResponse);
}
// Do it for stats as well.
capacityResponses.addAll(getStatsCapacityresponse(null, null, pod.getId(), pod.getDataCenterId()));
podResponse.setCapacitites(new ArrayList<>(capacityResponses));
}
podResponse.setObjectName("pod");
return podResponse;
}
use of com.cloud.legacymodel.dc.DataCenter in project cosmic by MissionCriticalCloud.
the class ApiResponseHelper method createSystemVmResponse.
@Override
public SystemVmResponse createSystemVmResponse(final VirtualMachine vm) {
final SystemVmResponse vmResponse = new SystemVmResponse();
if (vm.getType() == VirtualMachineType.SecondaryStorageVm || vm.getType() == VirtualMachineType.ConsoleProxy || vm.getType() == VirtualMachineType.DomainRouter) {
// SystemVm vm = (SystemVm) systemVM;
vmResponse.setId(vm.getUuid());
// vmResponse.setObjectId(vm.getId());
vmResponse.setSystemVmType(vm.getType().toString().toLowerCase());
vmResponse.setName(vm.getHostName());
if (vm.getPodIdToDeployIn() != null) {
final HostPodVO pod = ApiDBUtils.findPodById(vm.getPodIdToDeployIn());
if (pod != null) {
vmResponse.setPodId(pod.getUuid());
}
}
final VMTemplateVO template = ApiDBUtils.findTemplateById(vm.getTemplateId());
if (template != null) {
vmResponse.setTemplateId(template.getUuid());
}
vmResponse.setCreated(vm.getCreated());
if (vm.getHostId() != null) {
final Host host = ApiDBUtils.findHostById(vm.getHostId());
if (host != null) {
vmResponse.setHostId(host.getUuid());
vmResponse.setHostName(host.getName());
vmResponse.setHypervisor(host.getHypervisorType().toString());
}
}
if (vm.getState() != null) {
vmResponse.setState(vm.getState().toString());
}
// for console proxies, add the active sessions
if (vm.getType() == VirtualMachineType.ConsoleProxy) {
final ConsoleProxyVO proxy = ApiDBUtils.findConsoleProxy(vm.getId());
// proxy can be already destroyed
if (proxy != null) {
vmResponse.setActiveViewerSessions(proxy.getActiveSession());
}
}
final DataCenter zone = ApiDBUtils.findZoneById(vm.getDataCenterId());
if (zone != null) {
vmResponse.setZoneId(zone.getUuid());
vmResponse.setZoneName(zone.getName());
vmResponse.setDns1(zone.getDns1());
vmResponse.setDns2(zone.getDns2());
}
final List<NicProfile> nicProfiles = ApiDBUtils.getNics(vm);
for (final NicProfile singleNicProfile : nicProfiles) {
final Network network = ApiDBUtils.findNetworkById(singleNicProfile.getNetworkId());
if (network != null) {
if (network.getTrafficType() == TrafficType.Management) {
vmResponse.setPrivateIp(singleNicProfile.getIPv4Address());
vmResponse.setPrivateMacAddress(singleNicProfile.getMacAddress());
vmResponse.setPrivateNetmask(singleNicProfile.getIPv4Netmask());
} else if (network.getTrafficType() == TrafficType.Control) {
vmResponse.setLinkLocalIp(singleNicProfile.getIPv4Address());
vmResponse.setLinkLocalMacAddress(singleNicProfile.getMacAddress());
vmResponse.setLinkLocalNetmask(singleNicProfile.getIPv4Netmask());
} else if (network.getTrafficType() == TrafficType.Public) {
vmResponse.setPublicIp(singleNicProfile.getIPv4Address());
vmResponse.setPublicMacAddress(singleNicProfile.getMacAddress());
vmResponse.setPublicNetmask(singleNicProfile.getIPv4Netmask());
vmResponse.setGateway(singleNicProfile.getIPv4Gateway());
} else if (network.getTrafficType() == TrafficType.Guest) {
/*
* In basic zone, public ip has TrafficType.Guest in case EIP service is not enabled.
* When EIP service is enabled in the basic zone, system VM by default get the public
* IP allocated for EIP. So return the guest/public IP accordingly.
* */
final NetworkOffering networkOffering = ApiDBUtils.findNetworkOfferingById(network.getNetworkOfferingId());
if (networkOffering.getElasticIp()) {
final IpAddress ip = ApiDBUtils.findIpByAssociatedVmId(vm.getId());
if (ip != null) {
final Vlan vlan = ApiDBUtils.findVlanById(ip.getVlanId());
vmResponse.setPublicIp(ip.getAddress().addr());
vmResponse.setPublicNetmask(vlan.getVlanNetmask());
vmResponse.setGateway(vlan.getVlanGateway());
}
} else {
vmResponse.setPublicIp(singleNicProfile.getIPv4Address());
vmResponse.setPublicMacAddress(singleNicProfile.getMacAddress());
vmResponse.setPublicNetmask(singleNicProfile.getIPv4Netmask());
vmResponse.setGateway(singleNicProfile.getIPv4Gateway());
}
}
}
}
}
vmResponse.setObjectName("systemvm");
return vmResponse;
}
use of com.cloud.legacymodel.dc.DataCenter in project cosmic by MissionCriticalCloud.
the class ApiResponseHelper method createVlanIpRangeResponse.
@Override
public VlanIpRangeResponse createVlanIpRangeResponse(final Vlan vlan) {
final Long podId = ApiDBUtils.getPodIdForVlan(vlan.getId());
final VlanIpRangeResponse vlanResponse = new VlanIpRangeResponse();
vlanResponse.setId(vlan.getUuid());
if (vlan.getVlanType() != null) {
vlanResponse.setForVirtualNetwork(vlan.getVlanType().equals(VlanType.VirtualNetwork));
}
vlanResponse.setVlan(vlan.getVlanTag());
final DataCenter zone = ApiDBUtils.findZoneById(vlan.getDataCenterId());
if (zone != null) {
vlanResponse.setZoneId(zone.getUuid());
}
if (podId != null) {
final HostPodVO pod = ApiDBUtils.findPodById(podId);
if (pod != null) {
vlanResponse.setPodId(pod.getUuid());
vlanResponse.setPodName(pod.getName());
}
}
vlanResponse.setGateway(vlan.getVlanGateway());
vlanResponse.setNetmask(vlan.getVlanNetmask());
// get start ip and end ip of corresponding vlan
final String ipRange = vlan.getIpRange();
if (ipRange != null) {
final String[] range = ipRange.split("-");
vlanResponse.setStartIp(range[0]);
vlanResponse.setEndIp(range[1]);
}
vlanResponse.setIp6Gateway(vlan.getIp6Gateway());
vlanResponse.setIp6Cidr(vlan.getIp6Cidr());
final String ip6Range = vlan.getIp6Range();
if (ip6Range != null) {
final String[] range = ip6Range.split("-");
vlanResponse.setStartIpv6(range[0]);
vlanResponse.setEndIpv6(range[1]);
}
if (vlan.getNetworkId() != null) {
final Network nw = ApiDBUtils.findNetworkById(vlan.getNetworkId());
if (nw != null) {
vlanResponse.setNetworkId(nw.getUuid());
}
}
final Account owner = ApiDBUtils.getVlanAccount(vlan.getId());
if (owner != null) {
populateAccount(vlanResponse, owner.getId());
populateDomain(vlanResponse, owner.getDomainId());
} else {
final Domain domain = ApiDBUtils.getVlanDomain(vlan.getId());
if (domain != null) {
populateDomain(vlanResponse, domain.getId());
} else {
final Long networkId = vlan.getNetworkId();
if (networkId != null) {
final Network network = this._ntwkModel.getNetwork(networkId);
if (network != null) {
final Long accountId = network.getAccountId();
populateAccount(vlanResponse, accountId);
populateDomain(vlanResponse, ApiDBUtils.findAccountById(accountId).getDomainId());
}
}
}
}
if (vlan.getPhysicalNetworkId() != null) {
final PhysicalNetwork pnw = ApiDBUtils.findPhysicalNetworkById(vlan.getPhysicalNetworkId());
if (pnw != null) {
vlanResponse.setPhysicalNetworkId(pnw.getUuid());
}
}
vlanResponse.setObjectName("vlan");
return vlanResponse;
}
use of com.cloud.legacymodel.dc.DataCenter in project cosmic by MissionCriticalCloud.
the class ApiResponseHelper method createIPAddressResponse.
@Override
public IPAddressResponse createIPAddressResponse(final ResponseView view, final IpAddress ipAddr) {
final VlanVO vlan = ApiDBUtils.findVlanById(ipAddr.getVlanId());
final boolean forVirtualNetworks = vlan.getVlanType().equals(VlanType.VirtualNetwork);
final long zoneId = ipAddr.getDataCenterId();
final IPAddressResponse ipResponse = new IPAddressResponse();
ipResponse.setId(ipAddr.getUuid());
ipResponse.setIpAddress(ipAddr.getAddress().toString());
if (ipAddr.getAllocatedTime() != null) {
ipResponse.setAllocated(ipAddr.getAllocatedTime());
}
final DataCenter zone = ApiDBUtils.findZoneById(ipAddr.getDataCenterId());
if (zone != null) {
ipResponse.setZoneId(zone.getUuid());
ipResponse.setZoneName(zone.getName());
}
ipResponse.setSourceNat(ipAddr.isSourceNat());
ipResponse.setIsSystem(ipAddr.getSystem());
// get account information
if (ipAddr.getAllocatedToAccountId() != null) {
populateOwner(ipResponse, ipAddr);
}
ipResponse.setForVirtualNetwork(forVirtualNetworks);
ipResponse.setStaticNat(ipAddr.isOneToOneNat());
if (ipAddr.getAssociatedWithVmId() != null) {
final UserVm vm = ApiDBUtils.findUserVmById(ipAddr.getAssociatedWithVmId());
if (vm != null) {
ipResponse.setVirtualMachineId(vm.getUuid());
ipResponse.setVirtualMachineName(vm.getHostName());
if (vm.getDisplayName() != null) {
ipResponse.setVirtualMachineDisplayName(vm.getDisplayName());
} else {
ipResponse.setVirtualMachineDisplayName(vm.getHostName());
}
}
}
if (ipAddr.getVmIp() != null) {
ipResponse.setVirtualMachineIp(ipAddr.getVmIp());
}
if (ipAddr.getAssociatedWithNetworkId() != null) {
final Network ntwk = ApiDBUtils.findNetworkById(ipAddr.getAssociatedWithNetworkId());
if (ntwk != null) {
ipResponse.setAssociatedNetworkId(ntwk.getUuid());
ipResponse.setAssociatedNetworkName(ntwk.getName());
}
}
if (ipAddr.getVpcId() != null) {
final Vpc vpc = ApiDBUtils.findVpcById(ipAddr.getVpcId());
if (vpc != null) {
ipResponse.setVpcId(vpc.getUuid());
}
}
// Network id the ip is associated with (if associated networkId is
// null, try to get this information from vlan)
final Long vlanNetworkId = ApiDBUtils.getVlanNetworkId(ipAddr.getVlanId());
// Network id the ip belongs to
final Long networkId;
if (vlanNetworkId != null) {
networkId = vlanNetworkId;
} else {
networkId = ApiDBUtils.getPublicNetworkIdByZone(zoneId);
}
if (networkId != null) {
final NetworkVO nw = ApiDBUtils.findNetworkById(networkId);
if (nw != null) {
ipResponse.setNetworkId(nw.getUuid());
ipResponse.setAssociatedNetworkName(nw.getName());
}
}
ipResponse.setState(ipAddr.getState().toString());
final NetworkACL acl = ApiDBUtils.findByNetworkACLId(ipAddr.getIpACLId());
if (acl != null) {
ipResponse.setAclId(acl.getUuid());
ipResponse.setAclName(acl.getName());
}
if (ipAddr.getPhysicalNetworkId() != null) {
final PhysicalNetworkVO pnw = ApiDBUtils.findPhysicalNetworkById(ipAddr.getPhysicalNetworkId());
if (pnw != null) {
ipResponse.setPhysicalNetworkId(pnw.getUuid());
}
}
// show this info to full view only
if (view == ResponseView.Full) {
final VlanVO vl = ApiDBUtils.findVlanById(ipAddr.getVlanId());
if (vl != null) {
ipResponse.setVlanId(vl.getUuid());
ipResponse.setVlanName(vl.getVlanTag());
}
}
if (ipAddr.getSystem()) {
if (ipAddr.isOneToOneNat()) {
ipResponse.setPurpose(IpAddress.Purpose.StaticNat.toString());
} else {
ipResponse.setPurpose(IpAddress.Purpose.Lb.toString());
}
}
ipResponse.setForDisplay(ipAddr.isDisplay());
// set tag information
final List<? extends ResourceTag> tags = ApiDBUtils.listByResourceTypeAndId(ResourceObjectType.PublicIpAddress, ipAddr.getId());
final List<ResourceTagResponse> tagResponses = new ArrayList<>();
for (final ResourceTag tag : tags) {
final ResourceTagResponse tagResponse = createResourceTagResponse(tag, true);
if (tagResponse != null) {
tagResponses.add(tagResponse);
}
}
ipResponse.setTags(tagResponses);
ipResponse.setObjectName("ipaddress");
return ipResponse;
}
Aggregations