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;
}
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");
}
}
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();
}
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;
}
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;
}
Aggregations