Search in sources :

Example 1 with NicSecondaryIpResponse

use of org.apache.cloudstack.api.response.NicSecondaryIpResponse in project cloudstack by apache.

the class UserVmJoinDaoImpl method setUserVmResponse.

@Override
public UserVmResponse setUserVmResponse(ResponseView view, UserVmResponse userVmData, UserVmJoinVO uvo) {
    Long securityGroupId = uvo.getSecurityGroupId();
    if (securityGroupId != null && securityGroupId.longValue() != 0) {
        SecurityGroupResponse resp = new SecurityGroupResponse();
        resp.setId(uvo.getSecurityGroupUuid());
        resp.setName(uvo.getSecurityGroupName());
        resp.setDescription(uvo.getSecurityGroupDescription());
        resp.setObjectName("securitygroup");
        if (uvo.getAccountType() == Account.ACCOUNT_TYPE_PROJECT) {
            resp.setProjectId(uvo.getProjectUuid());
            resp.setProjectName(uvo.getProjectName());
        } else {
            resp.setAccountName(uvo.getAccountName());
        }
        userVmData.addSecurityGroup(resp);
    }
    long nic_id = uvo.getNicId();
    if (nic_id > 0) {
        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());
        List<NicSecondaryIpVO> secondaryIps = ApiDBUtils.findNicSecondaryIps(uvo.getNicId());
        if (secondaryIps != null) {
            List<NicSecondaryIpResponse> ipList = new ArrayList<NicSecondaryIpResponse>();
            for (NicSecondaryIpVO ip : secondaryIps) {
                NicSecondaryIpResponse ipRes = new NicSecondaryIpResponse();
                ipRes.setId(ip.getUuid());
                ipRes.setIpAddr(ip.getIp4Address());
                ipList.add(ipRes);
            }
            nicResponse.setSecondaryIps(ipList);
        }
        nicResponse.setObjectName("nic");
        userVmData.addNic(nicResponse);
    }
    long tag_id = uvo.getTagId();
    if (tag_id > 0 && !userVmData.containTag(tag_id)) {
        addTagInformation(uvo, userVmData);
    }
    Long affinityGroupId = uvo.getAffinityGroupId();
    if (affinityGroupId != null && affinityGroupId.longValue() != 0) {
        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(org.apache.cloudstack.api.response.NicSecondaryIpResponse) NicSecondaryIpVO(com.cloud.vm.dao.NicSecondaryIpVO) AffinityGroupResponse(org.apache.cloudstack.affinity.AffinityGroupResponse) ArrayList(java.util.ArrayList) SecurityGroupResponse(org.apache.cloudstack.api.response.SecurityGroupResponse) NicResponse(org.apache.cloudstack.api.response.NicResponse)

Example 2 with NicSecondaryIpResponse

use of org.apache.cloudstack.api.response.NicSecondaryIpResponse in project cloudstack by apache.

the class AddIpToVmNicCmd method execute.

@Override
public void execute() throws ResourceUnavailableException, ResourceAllocationException, ConcurrentOperationException, InsufficientCapacityException {
    CallContext.current().setEventDetails("Nic Id: " + getNicId());
    NicSecondaryIp result = _entityMgr.findById(NicSecondaryIp.class, getEntityId());
    if (result != null) {
        CallContext.current().setEventDetails("secondary Ip Id: " + getEntityId());
        boolean success = false;
        success = _networkService.configureNicSecondaryIp(result, isZoneSGEnabled());
        if (success == false) {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to set security group rules for the secondary ip");
        }
        NicSecondaryIpResponse response = _responseGenerator.createSecondaryIPToNicResponse(result);
        response.setResponseName(getCommandName());
        this.setResponseObject(response);
    } else {
        throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to assign secondary ip to nic");
    }
}
Also used : NicSecondaryIpResponse(org.apache.cloudstack.api.response.NicSecondaryIpResponse) ServerApiException(org.apache.cloudstack.api.ServerApiException) NicSecondaryIp(com.cloud.vm.NicSecondaryIp)

Example 3 with NicSecondaryIpResponse

use of org.apache.cloudstack.api.response.NicSecondaryIpResponse in project cloudstack by apache.

the class ApiResponseHelper method createSecondaryIPToNicResponse.

@Override
public NicSecondaryIpResponse createSecondaryIPToNicResponse(NicSecondaryIp result) {
    NicSecondaryIpResponse response = new NicSecondaryIpResponse();
    NicVO nic = _entityMgr.findById(NicVO.class, result.getNicId());
    NetworkVO network = _entityMgr.findById(NetworkVO.class, result.getNetworkId());
    response.setId(result.getUuid());
    response.setIpAddr(result.getIp4Address());
    response.setNicId(nic.getUuid());
    response.setNwId(network.getUuid());
    response.setObjectName("nicsecondaryip");
    return response;
}
Also used : NicSecondaryIpResponse(org.apache.cloudstack.api.response.NicSecondaryIpResponse) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) NicVO(com.cloud.vm.NicVO)

Example 4 with NicSecondaryIpResponse

use of org.apache.cloudstack.api.response.NicSecondaryIpResponse in project cloudstack by apache.

the class AddIpToVmNicTest method testCreateSuccess.

@Test
public void testCreateSuccess() throws ResourceAllocationException, ResourceUnavailableException, ConcurrentOperationException, InsufficientCapacityException {
    NetworkService networkService = Mockito.mock(NetworkService.class);
    AddIpToVmNicCmd ipTonicCmd = Mockito.mock(AddIpToVmNicCmd.class);
    NicSecondaryIp secIp = Mockito.mock(NicSecondaryIp.class);
    Mockito.when(networkService.allocateSecondaryGuestIP(Matchers.anyLong(), Matchers.anyString())).thenReturn(secIp);
    ipTonicCmd._networkService = networkService;
    responseGenerator = Mockito.mock(ResponseGenerator.class);
    NicSecondaryIpResponse ipres = Mockito.mock(NicSecondaryIpResponse.class);
    Mockito.when(responseGenerator.createSecondaryIPToNicResponse(secIp)).thenReturn(ipres);
    ipTonicCmd._responseGenerator = responseGenerator;
    ipTonicCmd.execute();
}
Also used : NicSecondaryIpResponse(org.apache.cloudstack.api.response.NicSecondaryIpResponse) AddIpToVmNicCmd(org.apache.cloudstack.api.command.user.vm.AddIpToVmNicCmd) ResponseGenerator(org.apache.cloudstack.api.ResponseGenerator) NicSecondaryIp(com.cloud.vm.NicSecondaryIp) NetworkService(com.cloud.network.NetworkService) Test(org.junit.Test)

Example 5 with NicSecondaryIpResponse

use of org.apache.cloudstack.api.response.NicSecondaryIpResponse in project cloudstack by apache.

the class UserVmJoinDaoImpl method newUserVmResponse.

@Override
public UserVmResponse newUserVmResponse(ResponseView view, String objectName, UserVmJoinVO userVm, EnumSet<VMDetails> details, Account caller) {
    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());
    }
    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.setInstanceName(userVm.getInstanceName());
        userVmResponse.setHostId(userVm.getHostUuid());
        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.setCpuSpeed(userVm.getSpeed());
        userVmResponse.setMemory(userVm.getRamSize());
        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
        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());
            userVmResponse.setDiskKbsRead((long) vmStats.getDiskReadKBs());
            userVmResponse.setDiskKbsWrite((long) vmStats.getDiskWriteKBs());
            userVmResponse.setDiskIORead((long) vmStats.getDiskReadIOs());
            userVmResponse.setDiskIOWrite((long) vmStats.getDiskWriteIOs());
            userVmResponse.setMemoryKBs((long) vmStats.getMemoryKBs());
            userVmResponse.setMemoryIntFreeKBs((long) vmStats.getIntFreeMemoryKBs());
            userVmResponse.setMemoryTargetKBs((long) vmStats.getTargetMemoryKBs());
        }
    }
    if (details.contains(VMDetails.all) || details.contains(VMDetails.secgrp)) {
        Long securityGroupId = userVm.getSecurityGroupId();
        if (securityGroupId != null && securityGroupId.longValue() != 0) {
            SecurityGroupResponse resp = new SecurityGroupResponse();
            resp.setId(userVm.getSecurityGroupUuid());
            resp.setName(userVm.getSecurityGroupName());
            resp.setDescription(userVm.getSecurityGroupDescription());
            resp.setObjectName("securitygroup");
            if (userVm.getAccountType() == Account.ACCOUNT_TYPE_PROJECT) {
                resp.setProjectId(userVm.getProjectUuid());
                resp.setProjectName(userVm.getProjectName());
            } else {
                resp.setAccountName(userVm.getAccountName());
            }
            userVmResponse.addSecurityGroup(resp);
        }
    }
    if (details.contains(VMDetails.all) || details.contains(VMDetails.nics)) {
        long nic_id = userVm.getNicId();
        if (nic_id > 0) {
            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());
            List<NicSecondaryIpVO> secondaryIps = ApiDBUtils.findNicSecondaryIps(userVm.getNicId());
            if (secondaryIps != null) {
                List<NicSecondaryIpResponse> ipList = new ArrayList<NicSecondaryIpResponse>();
                for (NicSecondaryIpVO ip : secondaryIps) {
                    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
    long tag_id = userVm.getTagId();
    if (tag_id > 0 && !userVmResponse.containTag(tag_id)) {
        addTagInformation(userVm, userVmResponse);
    }
    if (details.contains(VMDetails.all) || details.contains(VMDetails.affgrp)) {
        Long affinityGroupId = userVm.getAffinityGroupId();
        if (affinityGroupId != null && affinityGroupId.longValue() != 0) {
            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
    // Allow passing details to end user
    List<UserVmDetailVO> vmDetails = _userVmDetailsDao.listDetails(userVm.getId());
    if (vmDetails != null) {
        Map<String, String> resourceDetails = new HashMap<String, String>();
        for (UserVmDetailVO userVmDetailVO : vmDetails) {
            resourceDetails.put(userVmDetailVO.getName(), userVmDetailVO.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) SecurityGroupResponse(org.apache.cloudstack.api.response.SecurityGroupResponse) UserVmResponse(org.apache.cloudstack.api.response.UserVmResponse) NicSecondaryIpResponse(org.apache.cloudstack.api.response.NicSecondaryIpResponse) UserVmDetailVO(com.cloud.vm.UserVmDetailVO) NicSecondaryIpVO(com.cloud.vm.dao.NicSecondaryIpVO) AffinityGroupResponse(org.apache.cloudstack.affinity.AffinityGroupResponse) VmStats(com.cloud.vm.VmStats) NicResponse(org.apache.cloudstack.api.response.NicResponse)

Aggregations

NicSecondaryIpResponse (org.apache.cloudstack.api.response.NicSecondaryIpResponse)6 NicSecondaryIpVO (com.cloud.vm.dao.NicSecondaryIpVO)3 ArrayList (java.util.ArrayList)3 NicResponse (org.apache.cloudstack.api.response.NicResponse)3 NetworkVO (com.cloud.network.dao.NetworkVO)2 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)2 NicSecondaryIp (com.cloud.vm.NicSecondaryIp)2 NicVO (com.cloud.vm.NicVO)2 AffinityGroupResponse (org.apache.cloudstack.affinity.AffinityGroupResponse)2 SecurityGroupResponse (org.apache.cloudstack.api.response.SecurityGroupResponse)2 UserVmJoinVO (com.cloud.api.query.vo.UserVmJoinVO)1 NetworkService (com.cloud.network.NetworkService)1 ServiceOfferingDetailsVO (com.cloud.service.ServiceOfferingDetailsVO)1 User (com.cloud.user.User)1 UserVmDetailVO (com.cloud.vm.UserVmDetailVO)1 VMInstanceVO (com.cloud.vm.VMInstanceVO)1 VmStats (com.cloud.vm.VmStats)1 DecimalFormat (java.text.DecimalFormat)1 HashMap (java.util.HashMap)1 ResponseGenerator (org.apache.cloudstack.api.ResponseGenerator)1