Search in sources :

Example 6 with ResourceTagJoinVO

use of com.cloud.api.query.vo.ResourceTagJoinVO in project cosmic by MissionCriticalCloud.

the class TemplateJoinDaoImpl method newTemplateResponse.

@Override
public TemplateResponse newTemplateResponse(final ResponseView view, final TemplateJoinVO template) {
    final TemplateResponse templateResponse = new TemplateResponse();
    templateResponse.setId(template.getUuid());
    templateResponse.setName(template.getName());
    templateResponse.setDisplayText(template.getDisplayText());
    templateResponse.setPublic(template.isPublicTemplate());
    templateResponse.setCreated(template.getCreatedOnStore());
    templateResponse.setReady(template.getState() == ObjectInDataStoreStateMachine.State.Ready);
    templateResponse.setFeatured(template.isFeatured());
    templateResponse.setExtractable(template.isExtractable() && !(template.getTemplateType() == TemplateType.SYSTEM));
    templateResponse.setPasswordEnabled(template.isEnablePassword());
    templateResponse.setDynamicallyScalable(template.isDynamicallyScalable());
    templateResponse.setSshKeyEnabled(template.isEnableSshKey());
    templateResponse.setCrossZones(template.isCrossZones());
    templateResponse.setFormat(template.getFormat());
    templateResponse.setUrl(template.getUrl());
    if (template.getTemplateType() != null) {
        templateResponse.setTemplateType(template.getTemplateType().toString());
    }
    templateResponse.setHypervisor(template.getHypervisorType().toString());
    templateResponse.setOsTypeId(template.getGuestOSUuid());
    templateResponse.setOsTypeName(template.getGuestOSName());
    // populate owner.
    ApiResponseHelper.populateOwner(templateResponse, template);
    // populate domain
    templateResponse.setDomainId(template.getDomainUuid());
    templateResponse.setDomainName(template.getDomainName());
    // If the user is an 'Admin' or 'the owner of template', add the template download status
    final Account caller = CallContext.current().getCallingAccount();
    if (view == ResponseView.Full || _accountMgr.isDomainAdmin(caller.getId()) || template.getAccountId() == CallContext.current().getCallingAccount().getId()) {
        final String templateStatus = getTemplateStatus(template);
        if (templateStatus != null) {
            templateResponse.setStatus(templateStatus);
        }
    }
    if (template.getDataCenterId() > 0) {
        templateResponse.setZoneId(template.getDataCenterUuid());
        templateResponse.setZoneName(template.getDataCenterName());
    }
    final Long templateSize = template.getSize();
    if (templateSize > 0) {
        templateResponse.setSize(templateSize);
    }
    templateResponse.setChecksum(template.getChecksum());
    if (template.getSourceTemplateId() != null) {
        templateResponse.setSourceTemplateId(template.getSourceTemplateUuid());
    }
    templateResponse.setTemplateTag(template.getTemplateTag());
    // set details map
    if (template.getDetailName() != null) {
        final Map<String, String> details = new HashMap<>();
        details.put(template.getDetailName(), template.getDetailValue());
        templateResponse.setDetails(details);
    }
    // update tag information
    final long tag_id = template.getTagId();
    if (tag_id > 0) {
        final ResourceTagJoinVO vtag = ApiDBUtils.findResourceTagViewById(tag_id);
        if (vtag != null) {
            templateResponse.addTag(ApiDBUtils.newResourceTagResponse(vtag, false));
        }
    }
    templateResponse.setObjectName("template");
    return templateResponse;
}
Also used : Account(com.cloud.user.Account) HashMap(java.util.HashMap) TemplateResponse(com.cloud.api.response.TemplateResponse) ResourceTagJoinVO(com.cloud.api.query.vo.ResourceTagJoinVO)

Example 7 with ResourceTagJoinVO

use of com.cloud.api.query.vo.ResourceTagJoinVO in project cosmic by MissionCriticalCloud.

the class VolumeJoinDaoImpl method newVolumeResponse.

@Override
public VolumeResponse newVolumeResponse(final ResponseView view, final VolumeJoinVO volume) {
    final VolumeResponse volResponse = new VolumeResponse();
    volResponse.setId(volume.getUuid());
    if (volume.getName() != null) {
        volResponse.setName(volume.getName());
    } else {
        volResponse.setName("");
    }
    volResponse.setZoneId(volume.getDataCenterUuid());
    volResponse.setZoneName(volume.getDataCenterName());
    volResponse.setVolumeType(volume.getVolumeType().toString());
    volResponse.setDeviceId(volume.getDeviceId());
    final long instanceId = volume.getVmId();
    if (instanceId > 0 && volume.getState() != Volume.State.Destroy) {
        volResponse.setVirtualMachineId(volume.getVmUuid());
        volResponse.setVirtualMachineName(volume.getVmName());
        volResponse.setVirtualMachineState(volume.getVmState().toString());
        if (volume.getVmDisplayName() != null) {
            volResponse.setVirtualMachineDisplayName(volume.getVmDisplayName());
        } else {
            volResponse.setVirtualMachineDisplayName(volume.getVmName());
        }
    }
    volResponse.setProvisioningType(volume.getProvisioningType().toString());
    // Show the virtual size of the volume
    volResponse.setSize(volume.getSize());
    volResponse.setMinIops(volume.getMinIops());
    volResponse.setMaxIops(volume.getMaxIops());
    volResponse.setCreated(volume.getCreated());
    volResponse.setState(volume.getState().toString());
    if (volume.getState() == Volume.State.UploadOp) {
        // com.cloud.storage.VolumeHostVO volumeHostRef =
        // ApiDBUtils.findVolumeHostRef(volume.getId(),
        // volume.getDataCenterId());
        volResponse.setSize(volume.getVolumeStoreSize());
        volResponse.setCreated(volume.getCreatedOnStore());
        if (view == ResponseView.Full) {
            volResponse.setHypervisor(ApiDBUtils.getHypervisorTypeFromFormat(volume.getDataCenterId(), volume.getFormat()).toString());
        }
        if (volume.getDownloadState() != Status.DOWNLOADED) {
            final String volumeStatus;
            if (volume.getDownloadState() == VMTemplateHostVO.Status.DOWNLOAD_IN_PROGRESS) {
                if (volume.getDownloadPercent() == 100) {
                    volumeStatus = "Checking Volume";
                } else {
                    volumeStatus = volume.getDownloadPercent() + "% Uploaded";
                }
                volResponse.setState("Uploading");
            } else {
                volumeStatus = volume.getErrorString();
                if (volume.getDownloadState() == VMTemplateHostVO.Status.NOT_DOWNLOADED) {
                    volResponse.setState("UploadNotStarted");
                } else {
                    volResponse.setState("UploadError");
                }
            }
            volResponse.setStatus(volumeStatus);
        } else if (volume.getDownloadState() == VMTemplateHostVO.Status.DOWNLOADED) {
            volResponse.setStatus("Upload Complete");
            volResponse.setState("Uploaded");
        } else {
            volResponse.setStatus("Successfully Installed");
        }
    }
    final Account caller = CallContext.current().getCallingAccount();
    // return the path on disk to root admins and admins
    if (!_accountMgr.isNormalUser(caller.getId())) {
        volResponse.setPath(volume.getPath());
    }
    // populate owner.
    ApiResponseHelper.populateOwner(volResponse, volume);
    // ApiDBUtils.findDiskOfferingById(volume.getDiskOfferingId());
    if (volume.getDiskOfferingId() > 0) {
        boolean isServiceOffering = false;
        if (volume.getVolumeType().equals(Volume.Type.ROOT)) {
            isServiceOffering = true;
        } else {
            // can't rely on the fact that the volume is the datadisk as it might have been created as a root, and
            // then detached later
            final long offeringId = volume.getDiskOfferingId();
            if (ApiDBUtils.findDiskOfferingById(offeringId) == null) {
                isServiceOffering = true;
            }
        }
        if (isServiceOffering) {
            volResponse.setServiceOfferingId(volume.getDiskOfferingUuid());
            volResponse.setServiceOfferingName(volume.getDiskOfferingName());
            volResponse.setServiceOfferingDisplayText(volume.getDiskOfferingDisplayText());
        } else {
            volResponse.setDiskOfferingId(volume.getDiskOfferingUuid());
            volResponse.setDiskOfferingName(volume.getDiskOfferingName());
            volResponse.setDiskOfferingDisplayText(volume.getDiskOfferingDisplayText());
        }
        volResponse.setStorageType(volume.isUseLocalStorage() ? ServiceOffering.StorageType.local.toString() : ServiceOffering.StorageType.shared.toString());
        volResponse.setBytesReadRate(volume.getBytesReadRate());
        volResponse.setBytesWriteRate(volume.getBytesReadRate());
        volResponse.setIopsReadRate(volume.getIopsWriteRate());
        volResponse.setIopsWriteRate(volume.getIopsWriteRate());
    }
    if (!_accountMgr.isNormalUser(caller.getId())) {
        // return hypervisor and storage pool info to root admins and admins
        if (volume.getState() != Volume.State.UploadOp) {
            if (volume.getHypervisorType() != null) {
                volResponse.setHypervisor(volume.getHypervisorType().toString());
            } else {
                volResponse.setHypervisor(ApiDBUtils.getHypervisorTypeFromFormat(volume.getDataCenterId(), volume.getFormat()).toString());
            }
        }
        final Long poolId = volume.getPoolId();
        final String poolName = (poolId == null) ? "none" : volume.getPoolName();
        volResponse.setStoragePoolName(poolName);
        volResponse.setStoragePoolId(volume.getPoolUuid());
    }
    volResponse.setAttached(volume.getAttached());
    volResponse.setDestroyed(volume.getState() == Volume.State.Destroy);
    boolean isExtractable = true;
    if (volume.getVolumeType() != Volume.Type.DATADISK) {
        // dependence.
        if (volume.getTemplateId() > 0) {
            // For ISO based volumes template
            // = null and we allow extraction
            // of all ISO based volumes
            isExtractable = volume.isExtractable() && volume.getTemplateType() != Storage.TemplateType.SYSTEM;
        }
    }
    // update tag information
    final long tag_id = volume.getTagId();
    if (tag_id > 0) {
        final ResourceTagJoinVO vtag = ApiDBUtils.findResourceTagViewById(tag_id);
        if (vtag != null) {
            volResponse.addTag(ApiDBUtils.newResourceTagResponse(vtag, false));
        }
    }
    volResponse.setExtractable(isExtractable);
    volResponse.setDisplayVolume(volume.isDisplayVolume());
    volResponse.setChainInfo(volume.getChainInfo());
    volResponse.setTemplateId(volume.getTemplateUuid());
    volResponse.setTemplateName(volume.getTemplateName());
    volResponse.setTemplateDisplayText(volume.getTemplateDisplayText());
    volResponse.setIsoId(volume.getIsoUuid());
    volResponse.setIsoName(volume.getIsoName());
    volResponse.setIsoDisplayText(volume.getIsoDisplayText());
    // set async job
    if (volume.getJobId() != null) {
        volResponse.setJobId(volume.getJobUuid());
        volResponse.setJobStatus(volume.getJobStatus());
    }
    volResponse.setObjectName("volume");
    return volResponse;
}
Also used : Account(com.cloud.user.Account) VolumeResponse(com.cloud.api.response.VolumeResponse) ResourceTagJoinVO(com.cloud.api.query.vo.ResourceTagJoinVO)

Example 8 with ResourceTagJoinVO

use of com.cloud.api.query.vo.ResourceTagJoinVO in project cosmic by MissionCriticalCloud.

the class DataCenterJoinDaoImpl method newDataCenterResponse.

@Override
public ZoneResponse newDataCenterResponse(final ResponseView view, final DataCenterJoinVO dataCenter, final Boolean showCapacities) {
    final ZoneResponse zoneResponse = new ZoneResponse();
    zoneResponse.setId(dataCenter.getUuid());
    zoneResponse.setName(dataCenter.getName());
    zoneResponse.setLocalStorageEnabled(dataCenter.isLocalStorageEnabled());
    if ((dataCenter.getDescription() != null) && !dataCenter.getDescription().equalsIgnoreCase("null")) {
        zoneResponse.setDescription(dataCenter.getDescription());
    }
    if (view == ResponseView.Full) {
        zoneResponse.setDns1(dataCenter.getDns1());
        zoneResponse.setDns2(dataCenter.getDns2());
        zoneResponse.setIp6Dns1(dataCenter.getIp6Dns1());
        zoneResponse.setIp6Dns2(dataCenter.getIp6Dns2());
        zoneResponse.setInternalDns1(dataCenter.getInternalDns1());
        zoneResponse.setInternalDns2(dataCenter.getInternalDns2());
        // FIXME zoneResponse.setVlan(dataCenter.get.getVnet());
        zoneResponse.setGuestCidrAddress(dataCenter.getGuestNetworkCidr());
        if (showCapacities != null && showCapacities) {
            zoneResponse.setCapacitites(ApiResponseHelper.getDataCenterCapacityResponse(dataCenter.getId()));
        }
    }
    // set network domain info
    zoneResponse.setDomain(dataCenter.getDomain());
    // set domain info
    zoneResponse.setDomainId(dataCenter.getDomainUuid());
    zoneResponse.setDomainName(dataCenter.getDomainName());
    zoneResponse.setType(dataCenter.getNetworkType().toString());
    zoneResponse.setAllocationState(dataCenter.getAllocationState().toString());
    zoneResponse.setZoneToken(dataCenter.getZoneToken());
    zoneResponse.setDhcpProvider(dataCenter.getDhcpProvider());
    // update tag information
    final List<ResourceTagJoinVO> resourceTags = ApiDBUtils.listResourceTagViewByResourceUUID(dataCenter.getUuid(), ResourceObjectType.Zone);
    for (final ResourceTagJoinVO resourceTag : resourceTags) {
        final ResourceTagResponse tagResponse = ApiDBUtils.newResourceTagResponse(resourceTag, false);
        zoneResponse.addTag(tagResponse);
    }
    zoneResponse.setResourceDetails(ApiDBUtils.getResourceDetails(dataCenter.getId(), ResourceObjectType.Zone));
    zoneResponse.setObjectName("zone");
    return zoneResponse;
}
Also used : ZoneResponse(com.cloud.api.response.ZoneResponse) ResourceTagResponse(com.cloud.api.response.ResourceTagResponse) ResourceTagJoinVO(com.cloud.api.query.vo.ResourceTagJoinVO)

Example 9 with ResourceTagJoinVO

use of com.cloud.api.query.vo.ResourceTagJoinVO 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;
}
Also used : NicSecondaryIpResponse(com.cloud.api.response.NicSecondaryIpResponse) NicSecondaryIpVO(com.cloud.vm.dao.NicSecondaryIpVO) AffinityGroupResponse(com.cloud.affinity.AffinityGroupResponse) ArrayList(java.util.ArrayList) ResourceTagJoinVO(com.cloud.api.query.vo.ResourceTagJoinVO) NicResponse(com.cloud.api.response.NicResponse)

Example 10 with ResourceTagJoinVO

use of com.cloud.api.query.vo.ResourceTagJoinVO in project cosmic by MissionCriticalCloud.

the class UserVmJoinDaoImpl method newUserVmResponse.

@Override
public UserVmResponse newUserVmResponse(final ResponseView view, final String objectName, final UserVmJoinVO userVm, final EnumSet<VMDetails> details, final Account caller) {
    final UserVmResponse userVmResponse = new UserVmResponse();
    if (userVm.getHypervisorType() != null) {
        userVmResponse.setHypervisor(userVm.getHypervisorType().toString());
    }
    userVmResponse.setId(userVm.getUuid());
    userVmResponse.setName(userVm.getName());
    if (userVm.getDisplayName() != null) {
        userVmResponse.setDisplayName(userVm.getDisplayName());
    } else {
        userVmResponse.setDisplayName(userVm.getName());
    }
    if (userVm.getAccountType() == Account.ACCOUNT_TYPE_PROJECT) {
        userVmResponse.setProjectId(userVm.getProjectUuid());
        userVmResponse.setProjectName(userVm.getProjectName());
    } else {
        userVmResponse.setAccountName(userVm.getAccountName());
    }
    final User user = _userDao.getUser(userVm.getUserId());
    if (user != null) {
        userVmResponse.setUserId(user.getUuid());
        userVmResponse.setUserName(user.getUsername());
    }
    userVmResponse.setDomainId(userVm.getDomainUuid());
    userVmResponse.setDomainName(userVm.getDomainName());
    userVmResponse.setCreated(userVm.getCreated());
    userVmResponse.setDisplayVm(userVm.isDisplayVm());
    if (userVm.getState() != null) {
        userVmResponse.setState(userVm.getState().toString());
    }
    userVmResponse.setHaEnable(userVm.isHaEnabled());
    if (details.contains(VMDetails.all) || details.contains(VMDetails.group)) {
        userVmResponse.setGroupId(userVm.getInstanceGroupUuid());
        userVmResponse.setGroup(userVm.getInstanceGroupName());
    }
    userVmResponse.setZoneId(userVm.getDataCenterUuid());
    userVmResponse.setZoneName(userVm.getDataCenterName());
    if (view == ResponseView.Full) {
        userVmResponse.setHostId(userVm.getHostUuid());
    }
    userVmResponse.setInstanceName(userVm.getInstanceName());
    userVmResponse.setHostName(userVm.getHostName());
    if (details.contains(VMDetails.all) || details.contains(VMDetails.tmpl)) {
        userVmResponse.setTemplateId(userVm.getTemplateUuid());
        userVmResponse.setTemplateName(userVm.getTemplateName());
        userVmResponse.setTemplateDisplayText(userVm.getTemplateDisplayText());
        userVmResponse.setPasswordEnabled(userVm.isPasswordEnabled());
    }
    if (details.contains(VMDetails.all) || details.contains(VMDetails.iso)) {
        userVmResponse.setIsoId(userVm.getIsoUuid());
        userVmResponse.setIsoName(userVm.getIsoName());
        userVmResponse.setIsoDisplayText(userVm.getIsoDisplayText());
    }
    if (details.contains(VMDetails.all) || details.contains(VMDetails.servoff)) {
        userVmResponse.setServiceOfferingId(userVm.getServiceOfferingUuid());
        userVmResponse.setServiceOfferingName(userVm.getServiceOfferingName());
    }
    if (details.contains(VMDetails.all) || details.contains(VMDetails.diskoff)) {
        userVmResponse.setDiskOfferingId(userVm.getDiskOfferingUuid());
        userVmResponse.setDiskOfferingName(userVm.getDiskOfferingName());
    }
    if (details.contains(VMDetails.all) || details.contains(VMDetails.servoff) || details.contains(VMDetails.stats)) {
        userVmResponse.setCpuNumber(userVm.getCpu());
        userVmResponse.setMemory(userVm.getRamSize());
        final ServiceOfferingDetailsVO serviceOfferingDetail = ApiDBUtils.findServiceOfferingDetail(userVm.getServiceOfferingId(), GPU.Keys.vgpuType.toString());
        if (serviceOfferingDetail != null) {
            userVmResponse.setVgpu(serviceOfferingDetail.getValue());
        }
    }
    userVmResponse.setGuestOsId(userVm.getGuestOsUuid());
    if (details.contains(VMDetails.all) || details.contains(VMDetails.volume)) {
        userVmResponse.setRootDeviceId(userVm.getVolumeDeviceId());
        if (userVm.getVolumeType() != null) {
            userVmResponse.setRootDeviceType(userVm.getVolumeType().toString());
        }
    }
    userVmResponse.setPassword(userVm.getPassword());
    if (userVm.getJobId() != null) {
        userVmResponse.setJobId(userVm.getJobUuid());
        userVmResponse.setJobStatus(userVm.getJobStatus());
    }
    // userVmResponse.setForVirtualNetwork(userVm.getForVirtualNetwork());
    userVmResponse.setPublicIpId(userVm.getPublicIpUuid());
    userVmResponse.setPublicIp(userVm.getPublicIpAddress());
    userVmResponse.setKeyPairName(userVm.getKeypairName());
    userVmResponse.setOsTypeId(userVm.getGuestOsId());
    if (details.contains(VMDetails.all) || details.contains(VMDetails.stats)) {
        // stats calculation
        final VmStats vmStats = ApiDBUtils.getVmStatistics(userVm.getId());
        if (vmStats != null) {
            userVmResponse.setCpuUsed(new DecimalFormat("#.##").format(vmStats.getCPUUtilization()) + "%");
            userVmResponse.setNetworkKbsRead((long) vmStats.getNetworkReadKBs());
            userVmResponse.setNetworkKbsWrite((long) vmStats.getNetworkWriteKBs());
            if ((userVm.getHypervisorType() != null) && (userVm.getHypervisorType().equals(HypervisorType.KVM) || userVm.getHypervisorType().equals(HypervisorType.XenServer))) {
                // support KVM and XenServer only util 2013.06.25
                userVmResponse.setDiskKbsRead((long) vmStats.getDiskReadKBs());
                userVmResponse.setDiskKbsWrite((long) vmStats.getDiskWriteKBs());
                userVmResponse.setDiskIORead((long) vmStats.getDiskReadIOs());
                userVmResponse.setDiskIOWrite((long) vmStats.getDiskWriteIOs());
            }
        }
    }
    if (details.contains(VMDetails.all) || details.contains(VMDetails.nics)) {
        final long nic_id = userVm.getNicId();
        if (nic_id > 0) {
            final NicResponse nicResponse = new NicResponse();
            nicResponse.setId(userVm.getNicUuid());
            nicResponse.setIpaddress(userVm.getIpAddress());
            nicResponse.setGateway(userVm.getGateway());
            nicResponse.setNetmask(userVm.getNetmask());
            nicResponse.setNetworkid(userVm.getNetworkUuid());
            nicResponse.setNetworkName(userVm.getNetworkName());
            nicResponse.setMacAddress(userVm.getMacAddress());
            nicResponse.setIp6Address(userVm.getIp6Address());
            nicResponse.setIp6Gateway(userVm.getIp6Gateway());
            nicResponse.setIp6Cidr(userVm.getIp6Cidr());
            if (userVm.getBroadcastUri() != null) {
                nicResponse.setBroadcastUri(userVm.getBroadcastUri().toString());
            }
            if (userVm.getIsolationUri() != null) {
                nicResponse.setIsolationUri(userVm.getIsolationUri().toString());
            }
            if (userVm.getTrafficType() != null) {
                nicResponse.setTrafficType(userVm.getTrafficType().toString());
            }
            if (userVm.getGuestType() != null) {
                nicResponse.setType(userVm.getGuestType().toString());
            }
            nicResponse.setIsDefault(userVm.isDefaultNic());
            final List<NicSecondaryIpVO> secondaryIps = ApiDBUtils.findNicSecondaryIps(userVm.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");
            userVmResponse.addNic(nicResponse);
        }
    }
    // update tag information
    final long tag_id = userVm.getTagId();
    if (tag_id > 0 && !userVmResponse.containTag(tag_id)) {
        final ResourceTagJoinVO vtag = ApiDBUtils.findResourceTagViewById(tag_id);
        if (vtag != null) {
            userVmResponse.addTag(ApiDBUtils.newResourceTagResponse(vtag, false));
        }
    }
    if (details.contains(VMDetails.all) || details.contains(VMDetails.affgrp)) {
        final Long affinityGroupId = userVm.getAffinityGroupId();
        if (affinityGroupId != null && affinityGroupId.longValue() != 0) {
            final AffinityGroupResponse resp = new AffinityGroupResponse();
            resp.setId(userVm.getAffinityGroupUuid());
            resp.setName(userVm.getAffinityGroupName());
            resp.setDescription(userVm.getAffinityGroupDescription());
            resp.setObjectName("affinitygroup");
            resp.setAccountName(userVm.getAccountName());
            userVmResponse.addAffinityGroup(resp);
        }
    }
    // set resource details map
    // only hypervisortoolsversion can be returned to the end user
    final UserVmDetailVO hypervisorToolsVersion = _userVmDetailsDao.findDetail(userVm.getId(), VmDetailConstants.HYPERVISOR_TOOLS_VERSION);
    if (hypervisorToolsVersion != null) {
        final Map<String, String> resourceDetails = new HashMap<>();
        resourceDetails.put(hypervisorToolsVersion.getName(), hypervisorToolsVersion.getValue());
        userVmResponse.setDetails(resourceDetails);
    }
    userVmResponse.setObjectName(objectName);
    if (userVm.isDynamicallyScalable() == null) {
        userVmResponse.setDynamicallyScalable(false);
    } else {
        userVmResponse.setDynamicallyScalable(userVm.isDynamicallyScalable());
    }
    return userVmResponse;
}
Also used : User(com.cloud.user.User) HashMap(java.util.HashMap) DecimalFormat(java.text.DecimalFormat) ArrayList(java.util.ArrayList) ServiceOfferingDetailsVO(com.cloud.service.ServiceOfferingDetailsVO) UserVmResponse(com.cloud.api.response.UserVmResponse) NicSecondaryIpResponse(com.cloud.api.response.NicSecondaryIpResponse) UserVmDetailVO(com.cloud.vm.UserVmDetailVO) NicSecondaryIpVO(com.cloud.vm.dao.NicSecondaryIpVO) AffinityGroupResponse(com.cloud.affinity.AffinityGroupResponse) VmStats(com.cloud.vm.VmStats) ResourceTagJoinVO(com.cloud.api.query.vo.ResourceTagJoinVO) NicResponse(com.cloud.api.response.NicResponse)

Aggregations

ResourceTagJoinVO (com.cloud.api.query.vo.ResourceTagJoinVO)19 Account (com.cloud.user.Account)9 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 AccountJoinVO (com.cloud.api.query.vo.AccountJoinVO)3 TemplateResponse (com.cloud.api.response.TemplateResponse)3 ResourceTagResponse (org.apache.cloudstack.api.response.ResourceTagResponse)3 AffinityGroupResponse (com.cloud.affinity.AffinityGroupResponse)2 SecurityGroupJoinVO (com.cloud.api.query.vo.SecurityGroupJoinVO)2 NicResponse (com.cloud.api.response.NicResponse)2 NicSecondaryIpResponse (com.cloud.api.response.NicSecondaryIpResponse)2 ListProjectResourcesCriteria (com.cloud.projects.Project.ListProjectResourcesCriteria)2 TemplateFilter (com.cloud.template.VirtualMachineTemplate.TemplateFilter)2 User (com.cloud.user.User)2 Ternary (com.cloud.utils.Ternary)2 Filter (com.cloud.utils.db.Filter)2 NicSecondaryIpVO (com.cloud.vm.dao.NicSecondaryIpVO)2 HashSet (java.util.HashSet)2 List (java.util.List)2 ChildTemplateResponse (org.apache.cloudstack.api.response.ChildTemplateResponse)2