use of com.cloud.api.response.IPAddressResponse in project cosmic by MissionCriticalCloud.
the class ListPublicIpAddressesCmd method execute.
@Override
public void execute() {
final Pair<List<? extends IpAddress>, Integer> result = _mgr.searchForIPAddresses(this);
final ListResponse<IPAddressResponse> response = new ListResponse<>();
final List<IPAddressResponse> ipAddrResponses = new ArrayList<>();
for (final IpAddress ipAddress : result.first()) {
final IPAddressResponse ipResponse = _responseGenerator.createIPAddressResponse(ResponseView.Restricted, ipAddress);
ipResponse.setObjectName("publicipaddress");
ipAddrResponses.add(ipResponse);
}
response.setResponses(ipAddrResponses, result.second());
response.setResponseName(getCommandName());
setResponseObject(response);
}
use of com.cloud.api.response.IPAddressResponse 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;
}
use of com.cloud.api.response.IPAddressResponse in project cosmic by MissionCriticalCloud.
the class AssociateIPAddrCmdByAdmin method execute.
@Override
public void execute() throws ResourceUnavailableException, ResourceAllocationException, ConcurrentOperationException, InsufficientCapacityException {
CallContext.current().setEventDetails("Ip Id: " + getEntityId());
IpAddress result = null;
if (getVpcId() != null) {
result = _vpcService.associateIPToVpc(getEntityId(), getVpcId());
} else if (getNetworkId() != null) {
result = _networkService.associateIPToNetwork(getEntityId(), getNetworkId());
}
if (result != null) {
final IPAddressResponse ipResponse = _responseGenerator.createIPAddressResponse(ResponseView.Full, result);
ipResponse.setResponseName(getCommandName());
setResponseObject(ipResponse);
} else {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to assign ip address");
}
}
Aggregations