Search in sources :

Example 1 with NicSecondaryIpResponse

use of com.cloud.api.response.NicSecondaryIpResponse in project cosmic by MissionCriticalCloud.

the class ApiResponseHelper method createSecondaryIPToNicResponse.

@Override
public NicSecondaryIpResponse createSecondaryIPToNicResponse(final NicSecondaryIp result) {
    final NicSecondaryIpResponse response = new NicSecondaryIpResponse();
    final NicVO nic = _entityMgr.findById(NicVO.class, result.getNicId());
    final 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(com.cloud.api.response.NicSecondaryIpResponse) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) NicVO(com.cloud.vm.NicVO)

Example 2 with NicSecondaryIpResponse

use of com.cloud.api.response.NicSecondaryIpResponse in project cosmic by MissionCriticalCloud.

the class AddIpToVmNicCmd method execute.

@Override
public void execute() throws ResourceUnavailableException, ResourceAllocationException, ConcurrentOperationException, InsufficientCapacityException {
    CallContext.current().setEventDetails("Nic Id: " + getNicId());
    final NicSecondaryIp result = _entityMgr.findById(NicSecondaryIp.class, getEntityId());
    if (result != null) {
        CallContext.current().setEventDetails("secondary Ip Id: " + getEntityId());
        boolean success;
        success = _networkService.configureNicSecondaryIp(result);
        if (!success) {
            throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to set security group rules for the secondary ip");
        }
        final 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(com.cloud.api.response.NicSecondaryIpResponse) ServerApiException(com.cloud.api.ServerApiException) NicSecondaryIp(com.cloud.vm.NicSecondaryIp)

Example 3 with NicSecondaryIpResponse

use of com.cloud.api.response.NicSecondaryIpResponse in project cosmic by MissionCriticalCloud.

the class AddIpToVmNicTest method testCreateSuccess.

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

Example 4 with NicSecondaryIpResponse

use of com.cloud.api.response.NicSecondaryIpResponse 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;
}
Also used : NicSecondaryIpResponse(com.cloud.api.response.NicSecondaryIpResponse) NicSecondaryIpVO(com.cloud.vm.dao.NicSecondaryIpVO) PhysicalNetworkVO(com.cloud.network.dao.PhysicalNetworkVO) NetworkVO(com.cloud.network.dao.NetworkVO) ArrayList(java.util.ArrayList) VMInstanceVO(com.cloud.vm.VMInstanceVO) NicResponse(com.cloud.api.response.NicResponse)

Example 5 with NicSecondaryIpResponse

use of com.cloud.api.response.NicSecondaryIpResponse 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)

Aggregations

NicSecondaryIpResponse (com.cloud.api.response.NicSecondaryIpResponse)6 NicResponse (com.cloud.api.response.NicResponse)3 NicSecondaryIpVO (com.cloud.vm.dao.NicSecondaryIpVO)3 ArrayList (java.util.ArrayList)3 AffinityGroupResponse (com.cloud.affinity.AffinityGroupResponse)2 ResourceTagJoinVO (com.cloud.api.query.vo.ResourceTagJoinVO)2 NetworkVO (com.cloud.network.dao.NetworkVO)2 PhysicalNetworkVO (com.cloud.network.dao.PhysicalNetworkVO)2 NicSecondaryIp (com.cloud.vm.NicSecondaryIp)2 ResponseGenerator (com.cloud.api.ResponseGenerator)1 ServerApiException (com.cloud.api.ServerApiException)1 AddIpToVmNicCmd (com.cloud.api.command.user.vm.AddIpToVmNicCmd)1 UserVmResponse (com.cloud.api.response.UserVmResponse)1 NetworkService (com.cloud.network.NetworkService)1 ServiceOfferingDetailsVO (com.cloud.service.ServiceOfferingDetailsVO)1 User (com.cloud.user.User)1 NicVO (com.cloud.vm.NicVO)1 UserVmDetailVO (com.cloud.vm.UserVmDetailVO)1 VMInstanceVO (com.cloud.vm.VMInstanceVO)1 VmStats (com.cloud.vm.VmStats)1