mirror of https://github.com/apache/cloudstack.git
CLOUDSTACK-1741 Added ip uuid into the AddIptoVmNicCmd response
Signed-off-by: Abhinandan Prateek <aprateek@apache.org>
This commit is contained in:
parent
1f97b528c5
commit
d5c3f87903
|
|
@ -158,7 +158,7 @@ public interface NetworkService {
|
|||
throws ResourceAllocationException, ConcurrentOperationException, InsufficientCapacityException;
|
||||
|
||||
/* Requests an IP address for the guest nic */
|
||||
String allocateSecondaryGuestIP(Account account, long zoneId, Long nicId,
|
||||
NicSecondaryIp allocateSecondaryGuestIP(Account account, long zoneId, Long nicId,
|
||||
Long networkId, String ipaddress) throws InsufficientAddressCapacityException;
|
||||
|
||||
boolean releaseSecondaryIpFromNic(long ipAddressId);
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import java.text.DecimalFormat;
|
|||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
|
||||
import com.cloud.vm.NicSecondaryIp;
|
||||
import org.apache.cloudstack.affinity.AffinityGroup;
|
||||
import org.apache.cloudstack.affinity.AffinityGroupResponse;
|
||||
import org.apache.cloudstack.api.ApiConstants.HostDetails;
|
||||
|
|
@ -389,8 +390,7 @@ public interface ResponseGenerator {
|
|||
TrafficMonitorResponse createTrafficMonitorResponse(Host trafficMonitor);
|
||||
VMSnapshotResponse createVMSnapshotResponse(VMSnapshot vmSnapshot);
|
||||
|
||||
NicSecondaryIpResponse createSecondaryIPToNicResponse(String ip,
|
||||
Long nicId, Long networkId);
|
||||
NicSecondaryIpResponse createSecondaryIPToNicResponse(NicSecondaryIp result);
|
||||
public NicResponse createNicResponse(Nic result);
|
||||
|
||||
AffinityGroupResponse createAffinityGroupResponse(AffinityGroup group);
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
// under the License.
|
||||
package org.apache.cloudstack.api.command.user.vm;
|
||||
|
||||
import com.cloud.vm.NicSecondaryIp;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
|
|
@ -146,6 +147,7 @@ public class AddIpToVmNicCmd extends BaseAsyncCmd {
|
|||
|
||||
UserContext.current().setEventDetails("Nic Id: " + getNicId() );
|
||||
String ip;
|
||||
NicSecondaryIp result;
|
||||
String secondaryIp = null;
|
||||
if ((ip = getIpaddress()) != null) {
|
||||
if (!NetUtils.isValidIp(ip)) {
|
||||
|
|
@ -154,12 +156,13 @@ public class AddIpToVmNicCmd extends BaseAsyncCmd {
|
|||
}
|
||||
|
||||
try {
|
||||
secondaryIp = _networkService.allocateSecondaryGuestIP(_accountService.getAccount(getEntityOwnerId()), getZoneId(), getNicId(), getNetworkId(), getIpaddress());
|
||||
result = _networkService.allocateSecondaryGuestIP(_accountService.getAccount(getEntityOwnerId()), getZoneId(), getNicId(), getNetworkId(), getIpaddress());
|
||||
} catch (InsufficientAddressCapacityException e) {
|
||||
throw new InvalidParameterValueException("Allocating guest ip for nic failed");
|
||||
}
|
||||
|
||||
if (secondaryIp != null) {
|
||||
if (result != null) {
|
||||
secondaryIp = result.getIp4Address();
|
||||
if (getNetworkType() == NetworkType.Basic) {
|
||||
// add security group rules for the secondary ip addresses
|
||||
boolean success = false;
|
||||
|
|
@ -171,7 +174,7 @@ public class AddIpToVmNicCmd extends BaseAsyncCmd {
|
|||
|
||||
s_logger.info("Associated ip address to NIC : " + secondaryIp);
|
||||
NicSecondaryIpResponse response = new NicSecondaryIpResponse();
|
||||
response = _responseGenerator.createSecondaryIPToNicResponse(secondaryIp, getNicId(), getNetworkId());
|
||||
response = _responseGenerator.createSecondaryIPToNicResponse(result);
|
||||
response.setResponseName(getCommandName());
|
||||
this.setResponseObject(response);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
// under the License.
|
||||
package org.apache.cloudstack.api.command.test;
|
||||
|
||||
import com.cloud.vm.NicSecondaryIp;
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
|
|
@ -64,15 +65,16 @@ public class AddIpToVmNicTest extends TestCase {
|
|||
|
||||
NetworkService networkService = Mockito.mock(NetworkService.class);
|
||||
AddIpToVmNicCmd ipTonicCmd = Mockito.mock(AddIpToVmNicCmd.class);
|
||||
NicSecondaryIp secIp = Mockito.mock(NicSecondaryIp.class);
|
||||
|
||||
Mockito.when(
|
||||
networkService.allocateSecondaryGuestIP(Mockito.any(Account.class), Mockito.anyLong(), Mockito.anyLong(), Mockito.anyLong(), Mockito.anyString())).thenReturn("10.1.1.2");
|
||||
networkService.allocateSecondaryGuestIP(Mockito.any(Account.class), Mockito.anyLong(), Mockito.anyLong(), Mockito.anyLong(), Mockito.anyString())).thenReturn(secIp);
|
||||
|
||||
ipTonicCmd._networkService = networkService;
|
||||
responseGenerator = Mockito.mock(ResponseGenerator.class);
|
||||
|
||||
NicSecondaryIpResponse ipres = Mockito.mock(NicSecondaryIpResponse.class);
|
||||
Mockito.when(responseGenerator.createSecondaryIPToNicResponse(Mockito.anyString(), Mockito.anyLong(), Mockito.anyLong())).thenReturn(ipres);
|
||||
Mockito.when(responseGenerator.createSecondaryIPToNicResponse(secIp)).thenReturn(ipres);
|
||||
|
||||
ipTonicCmd._responseGenerator = responseGenerator;
|
||||
ipTonicCmd.execute();
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ import java.util.TimeZone;
|
|||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import com.cloud.vm.*;
|
||||
import org.apache.cloudstack.acl.ControlledEntity;
|
||||
import org.apache.cloudstack.acl.ControlledEntity.ACLType;
|
||||
import org.apache.cloudstack.api.ApiConstants.HostDetails;
|
||||
|
|
@ -264,13 +265,6 @@ import com.cloud.uservm.UserVm;
|
|||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.StringUtils;
|
||||
import com.cloud.utils.net.NetUtils;
|
||||
import com.cloud.vm.ConsoleProxyVO;
|
||||
import com.cloud.vm.InstanceGroup;
|
||||
import com.cloud.vm.Nic;
|
||||
import com.cloud.vm.NicProfile;
|
||||
import com.cloud.vm.NicVO;
|
||||
import com.cloud.vm.VMInstanceVO;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
import com.cloud.vm.VirtualMachine.Type;
|
||||
import com.cloud.vm.dao.NicSecondaryIpVO;
|
||||
import com.cloud.vm.snapshot.VMSnapshot;
|
||||
|
|
@ -288,7 +282,6 @@ import org.apache.cloudstack.region.Region;
|
|||
import org.apache.cloudstack.usage.Usage;
|
||||
import org.apache.cloudstack.usage.UsageService;
|
||||
import org.apache.cloudstack.usage.UsageTypes;
|
||||
import com.cloud.vm.VmStats;
|
||||
import com.cloud.vm.dao.UserVmData;
|
||||
import com.cloud.vm.dao.UserVmData.NicData;
|
||||
import com.cloud.vm.dao.UserVmData.SecurityGroupData;
|
||||
|
|
@ -3646,11 +3639,12 @@ public class ApiResponseHelper implements ResponseGenerator {
|
|||
return response;
|
||||
}
|
||||
|
||||
public NicSecondaryIpResponse createSecondaryIPToNicResponse(String ipAddr, Long nicId, Long networkId) {
|
||||
public NicSecondaryIpResponse createSecondaryIPToNicResponse(NicSecondaryIp result) {
|
||||
NicSecondaryIpResponse response = new NicSecondaryIpResponse();
|
||||
NicVO nic = _entityMgr.findById(NicVO.class, nicId);
|
||||
NetworkVO network = _entityMgr.findById(NetworkVO.class, networkId);
|
||||
response.setIpAddr(ipAddr);
|
||||
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");
|
||||
|
|
|
|||
|
|
@ -483,7 +483,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
|
|||
}
|
||||
|
||||
|
||||
public String allocateSecondaryGuestIP (Account ipOwner, long zoneId, Long nicId, Long networkId, String requestedIp) throws InsufficientAddressCapacityException {
|
||||
public NicSecondaryIp allocateSecondaryGuestIP (Account ipOwner, long zoneId, Long nicId, Long networkId, String requestedIp) throws InsufficientAddressCapacityException {
|
||||
|
||||
Long accountId = null;
|
||||
Long domainId = null;
|
||||
|
|
@ -565,6 +565,7 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
|
|||
return null;
|
||||
}
|
||||
|
||||
NicSecondaryIpVO secondaryIpVO;
|
||||
if (ipaddr != null) {
|
||||
// we got the ip addr so up the nics table and secodary ip
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
|
|
@ -580,11 +581,13 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
|
|||
|
||||
s_logger.debug("Setting nic_secondary_ip table ...");
|
||||
vmId = nicVO.getInstanceId();
|
||||
NicSecondaryIpVO secondaryIpVO = new NicSecondaryIpVO(nicId, ipaddr, vmId, accountId, domainId, networkId);
|
||||
secondaryIpVO = new NicSecondaryIpVO(nicId, ipaddr, vmId, accountId, domainId, networkId);
|
||||
_nicSecondaryIpDao.persist(secondaryIpVO);
|
||||
txn.commit();
|
||||
return getNicSecondaryIp(secondaryIpVO.getId());
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return ipaddr;
|
||||
}
|
||||
|
||||
@DB
|
||||
|
|
@ -676,6 +679,14 @@ public class NetworkServiceImpl extends ManagerBase implements NetworkService {
|
|||
return true;
|
||||
}
|
||||
|
||||
NicSecondaryIp getNicSecondaryIp (long id) {
|
||||
NicSecondaryIp nicSecIp = _nicSecondaryIpDao.findById(id);
|
||||
if (nicSecIp == null) {
|
||||
return null;
|
||||
}
|
||||
return nicSecIp;
|
||||
}
|
||||
|
||||
@Override
|
||||
@DB
|
||||
@ActionEvent(eventType = EventTypes.EVENT_NET_IP_RELEASE, eventDescription = "disassociating Ip", async = true)
|
||||
|
|
|
|||
|
|
@ -835,7 +835,7 @@ public class MockNetworkManagerImpl extends ManagerBase implements NetworkManage
|
|||
}
|
||||
|
||||
@Override
|
||||
public String allocateSecondaryGuestIP(Account account, long zoneId,
|
||||
public NicSecondaryIp allocateSecondaryGuestIP(Account account, long zoneId,
|
||||
Long nicId, Long networkId, String ipaddress) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -1316,7 +1316,7 @@ public class MockNetworkManagerImpl extends ManagerBase implements NetworkManage
|
|||
}
|
||||
|
||||
@Override
|
||||
public String allocateSecondaryGuestIP(Account account, long zoneId,
|
||||
public NicSecondaryIp allocateSecondaryGuestIP(Account account, long zoneId,
|
||||
Long nicId, Long networkId, String ipaddress) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
|
|
|
|||
Loading…
Reference in New Issue