use of com.cloud.api.response.NicResponse in project cosmic by MissionCriticalCloud.
the class ListNicsCmd method execute.
// ///////////////////////////////////////////////////
// ///////////// API Implementation///////////////////
// ///////////////////////////////////////////////////
@Override
public void execute() throws ResourceUnavailableException, ResourceAllocationException, ConcurrentOperationException, InsufficientCapacityException {
try {
final List<? extends Nic> results = _networkService.listNics(this);
final ListResponse<NicResponse> response = new ListResponse<>();
List<NicResponse> resList = null;
if (results != null) {
resList = new ArrayList<>(results.size());
for (final Nic r : results) {
final NicResponse resp = _responseGenerator.createNicResponse(r);
resp.setObjectName("nic");
resList.add(resp);
}
response.setResponses(resList);
}
response.setResponses(resList);
response.setResponseName(getCommandName());
this.setResponseObject(response);
} catch (final Exception e) {
s_logger.warn("Failed to list secondary ip address per nic ");
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
}
}
use of com.cloud.api.response.NicResponse in project cosmic by MissionCriticalCloud.
the class DomainRouterJoinDaoImpl method newDomainRouterResponse.
@Override
public DomainRouterResponse newDomainRouterResponse(final DomainRouterJoinVO router, final Account caller) {
final DomainRouterResponse routerResponse = new DomainRouterResponse();
routerResponse.setId(router.getUuid());
routerResponse.setZoneId(router.getDataCenterUuid());
routerResponse.setName(router.getName());
routerResponse.setTemplateId(router.getTemplateUuid());
routerResponse.setCreated(router.getCreated());
routerResponse.setState(router.getState());
routerResponse.setIsRedundantRouter(router.isRedundantRouter());
routerResponse.setRedundantState(router.getRedundantState().toString());
if (router.getTemplateVersion() != null) {
final String routerVersion = Version.trimRouterVersion(router.getTemplateVersion());
routerResponse.setVersion(routerVersion);
routerResponse.setRequiresUpgrade((Version.compare(routerVersion, NetworkOrchestrationService.MinVRVersion.valueIn(router.getDataCenterId())) < 0));
} else {
routerResponse.setVersion("UNKNOWN");
routerResponse.setRequiresUpgrade(true);
}
if (_accountMgr.isRootAdmin(caller.getId()) || (_accountMgr.isDomainAdmin(caller.getId()))) {
if (router.getHostId() != null) {
routerResponse.setHostId(router.getHostUuid());
routerResponse.setHostName(router.getHostName());
routerResponse.setHypervisor(router.getHypervisorType().toString());
}
routerResponse.setPodId(router.getPodUuid());
final long nic_id = router.getNicId();
if (nic_id > 0) {
final TrafficType ty = router.getTrafficType();
if (ty != null) {
// nics response object
if (ty == TrafficType.Public) {
routerResponse.setPublicIp(router.getIpAddress());
routerResponse.setPublicMacAddress(router.getMacAddress());
routerResponse.setPublicNetmask(router.getNetmask());
routerResponse.setGateway(router.getGateway());
routerResponse.setPublicNetworkId(router.getNetworkUuid());
} else if (ty == TrafficType.Control) {
routerResponse.setLinkLocalIp(router.getIpAddress());
routerResponse.setLinkLocalMacAddress(router.getMacAddress());
routerResponse.setLinkLocalNetmask(router.getNetmask());
routerResponse.setLinkLocalNetworkId(router.getNetworkUuid());
} else if (ty == TrafficType.Guest) {
routerResponse.setGuestIpAddress(router.getIpAddress());
routerResponse.setGuestMacAddress(router.getMacAddress());
routerResponse.setGuestNetmask(router.getNetmask());
routerResponse.setGuestNetworkId(router.getNetworkUuid());
routerResponse.setGuestNetworkName(router.getNetworkName());
routerResponse.setNetworkDomain(router.getNetworkDomain());
}
}
final NicResponse nicResponse = new NicResponse();
nicResponse.setId(router.getNicUuid());
nicResponse.setIpaddress(router.getIpAddress());
nicResponse.setGateway(router.getGateway());
nicResponse.setNetmask(router.getNetmask());
nicResponse.setNetworkid(router.getNetworkUuid());
nicResponse.setNetworkName(router.getNetworkName());
nicResponse.setMacAddress(router.getMacAddress());
nicResponse.setIp6Address(router.getIp6Address());
nicResponse.setIp6Gateway(router.getIp6Gateway());
nicResponse.setIp6Cidr(router.getIp6Cidr());
if (router.getBroadcastUri() != null) {
nicResponse.setBroadcastUri(router.getBroadcastUri().toString());
}
if (router.getIsolationUri() != null) {
nicResponse.setIsolationUri(router.getIsolationUri().toString());
}
if (router.getTrafficType() != null) {
nicResponse.setTrafficType(router.getTrafficType().toString());
}
if (router.getGuestType() != null) {
nicResponse.setType(router.getGuestType().toString());
}
nicResponse.setIsDefault(router.isDefaultNic());
nicResponse.setObjectName("nic");
routerResponse.addNic(nicResponse);
}
}
routerResponse.setServiceOfferingId(router.getServiceOfferingUuid());
routerResponse.setServiceOfferingName(router.getServiceOfferingName());
// populate owner.
ApiResponseHelper.populateOwner(routerResponse, router);
routerResponse.setDomainId(router.getDomainUuid());
routerResponse.setDomainName(router.getDomainName());
routerResponse.setZoneName(router.getDataCenterName());
routerResponse.setDns1(router.getDns1());
routerResponse.setDns2(router.getDns2());
routerResponse.setIp6Dns1(router.getIp6Dns1());
routerResponse.setIp6Dns2(router.getIp6Dns2());
routerResponse.setVpcId(router.getVpcUuid());
routerResponse.setVpcName(router.getVpcName());
routerResponse.setRole(router.getRole().toString());
// set async job
if (router.getJobId() != null) {
routerResponse.setJobId(router.getJobUuid());
routerResponse.setJobStatus(router.getJobStatus());
}
routerResponse.setObjectName("router");
return routerResponse;
}
use of com.cloud.api.response.NicResponse in project cosmic by MissionCriticalCloud.
the class ApiResponseHelper method createNicResponse.
@Override
public NicResponse createNicResponse(final Nic result) {
final NicResponse response = new NicResponse();
final NetworkVO network = _entityMgr.findById(NetworkVO.class, result.getNetworkId());
final VMInstanceVO vm = _entityMgr.findById(VMInstanceVO.class, result.getInstanceId());
response.setId(result.getUuid());
response.setNetworkid(network.getUuid());
if (vm != null) {
response.setVmId(vm.getUuid());
}
response.setIpaddress(result.getIPv4Address());
if (result.getSecondaryIp()) {
final List<NicSecondaryIpVO> secondaryIps = ApiDBUtils.findNicSecondaryIps(result.getId());
if (secondaryIps != null) {
final List<NicSecondaryIpResponse> ipList = new ArrayList<>();
for (final NicSecondaryIpVO ip : secondaryIps) {
final NicSecondaryIpResponse ipRes = new NicSecondaryIpResponse();
ipRes.setId(ip.getUuid());
ipRes.setIpAddr(ip.getIp4Address());
ipList.add(ipRes);
}
response.setSecondaryIps(ipList);
}
}
response.setGateway(result.getIPv4Gateway());
response.setNetmask(result.getIPv4Netmask());
response.setMacAddress(result.getMacAddress());
if (result.getIPv6Address() != null) {
response.setIp6Address(result.getIPv6Address());
}
response.setIsDefault(result.isDefaultNic());
return response;
}
use of com.cloud.api.response.NicResponse in project cosmic by MissionCriticalCloud.
the class DomainRouterJoinDaoImpl method setDomainRouterResponse.
@Override
public DomainRouterResponse setDomainRouterResponse(final DomainRouterResponse vrData, final DomainRouterJoinVO vr) {
final long nic_id = vr.getNicId();
if (nic_id > 0) {
final TrafficType ty = vr.getTrafficType();
if (ty != null) {
// nics response object
if (ty == TrafficType.Public) {
vrData.setPublicIp(vr.getIpAddress());
vrData.setPublicMacAddress(vr.getMacAddress());
vrData.setPublicNetmask(vr.getNetmask());
vrData.setGateway(vr.getGateway());
vrData.setPublicNetworkId(vr.getNetworkUuid());
} else if (ty == TrafficType.Control) {
vrData.setLinkLocalIp(vr.getIpAddress());
vrData.setLinkLocalMacAddress(vr.getMacAddress());
vrData.setLinkLocalNetmask(vr.getNetmask());
vrData.setLinkLocalNetworkId(vr.getNetworkUuid());
} else if (ty == TrafficType.Guest) {
vrData.setGuestIpAddress(vr.getIpAddress());
vrData.setGuestMacAddress(vr.getMacAddress());
vrData.setGuestNetmask(vr.getNetmask());
vrData.setGuestNetworkId(vr.getNetworkUuid());
vrData.setGuestNetworkName(vr.getNetworkName());
vrData.setNetworkDomain(vr.getNetworkDomain());
}
}
final NicResponse nicResponse = new NicResponse();
nicResponse.setId(vr.getNicUuid());
nicResponse.setIpaddress(vr.getIpAddress());
nicResponse.setGateway(vr.getGateway());
nicResponse.setNetmask(vr.getNetmask());
nicResponse.setNetworkid(vr.getNetworkUuid());
nicResponse.setNetworkName(vr.getNetworkName());
nicResponse.setMacAddress(vr.getMacAddress());
nicResponse.setIp6Address(vr.getIp6Address());
nicResponse.setIp6Gateway(vr.getIp6Gateway());
nicResponse.setIp6Cidr(vr.getIp6Cidr());
if (vr.getBroadcastUri() != null) {
nicResponse.setBroadcastUri(vr.getBroadcastUri().toString());
}
if (vr.getIsolationUri() != null) {
nicResponse.setIsolationUri(vr.getIsolationUri().toString());
}
if (vr.getTrafficType() != null) {
nicResponse.setTrafficType(vr.getTrafficType().toString());
}
if (vr.getGuestType() != null) {
nicResponse.setType(vr.getGuestType().toString());
}
nicResponse.setIsDefault(vr.isDefaultNic());
nicResponse.setObjectName("nic");
vrData.addNic(nicResponse);
}
return vrData;
}
use of com.cloud.api.response.NicResponse in project cosmic by MissionCriticalCloud.
the class UserVmJoinDaoImpl method setUserVmResponse.
@Override
public UserVmResponse setUserVmResponse(final ResponseView view, final UserVmResponse userVmData, final UserVmJoinVO uvo) {
final long nic_id = uvo.getNicId();
if (nic_id > 0) {
final NicResponse nicResponse = new NicResponse();
nicResponse.setId(uvo.getNicUuid());
nicResponse.setIpaddress(uvo.getIpAddress());
nicResponse.setGateway(uvo.getGateway());
nicResponse.setNetmask(uvo.getNetmask());
nicResponse.setNetworkid(uvo.getNetworkUuid());
nicResponse.setNetworkName(uvo.getNetworkName());
nicResponse.setMacAddress(uvo.getMacAddress());
nicResponse.setIp6Address(uvo.getIp6Address());
nicResponse.setIp6Gateway(uvo.getIp6Gateway());
nicResponse.setIp6Cidr(uvo.getIp6Cidr());
if (uvo.getBroadcastUri() != null) {
nicResponse.setBroadcastUri(uvo.getBroadcastUri().toString());
}
if (uvo.getIsolationUri() != null) {
nicResponse.setIsolationUri(uvo.getIsolationUri().toString());
}
if (uvo.getTrafficType() != null) {
nicResponse.setTrafficType(uvo.getTrafficType().toString());
}
if (uvo.getGuestType() != null) {
nicResponse.setType(uvo.getGuestType().toString());
}
nicResponse.setIsDefault(uvo.isDefaultNic());
final List<NicSecondaryIpVO> secondaryIps = ApiDBUtils.findNicSecondaryIps(uvo.getNicId());
if (secondaryIps != null) {
final List<NicSecondaryIpResponse> ipList = new ArrayList<>();
for (final NicSecondaryIpVO ip : secondaryIps) {
final NicSecondaryIpResponse ipRes = new NicSecondaryIpResponse();
ipRes.setId(ip.getUuid());
ipRes.setIpAddr(ip.getIp4Address());
ipList.add(ipRes);
}
nicResponse.setSecondaryIps(ipList);
}
nicResponse.setObjectName("nic");
userVmData.addNic(nicResponse);
}
final long tag_id = uvo.getTagId();
if (tag_id > 0 && !userVmData.containTag(tag_id)) {
final ResourceTagJoinVO vtag = ApiDBUtils.findResourceTagViewById(tag_id);
if (vtag != null) {
userVmData.addTag(ApiDBUtils.newResourceTagResponse(vtag, false));
}
}
final Long affinityGroupId = uvo.getAffinityGroupId();
if (affinityGroupId != null && affinityGroupId.longValue() != 0) {
final AffinityGroupResponse resp = new AffinityGroupResponse();
resp.setId(uvo.getAffinityGroupUuid());
resp.setName(uvo.getAffinityGroupName());
resp.setDescription(uvo.getAffinityGroupDescription());
resp.setObjectName("affinitygroup");
resp.setAccountName(uvo.getAccountName());
userVmData.addAffinityGroup(resp);
}
return userVmData;
}
Aggregations