mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
bug 4706: added one more parameter - "ipaddress" to deployVm api. This parameter will apply to default network of vm
status 4706: resolved fixed Merge from master to 2.2.8 branch Conflicts: server/src/com/cloud/vm/UserVmManagerImpl.java
This commit is contained in:
parent
0d2787e2db
commit
5300dd52a9
@ -117,6 +117,9 @@ public class DeployVMCmd extends BaseAsyncCreateCmd {
|
||||
|
||||
@Parameter(name = ApiConstants.IP_NETWORK_LIST, type = CommandType.MAP, description = "ip to network mapping. Can't be specified with networkIds parameter. Example: iptonetworklist[0].ip=10.10.10.11&iptonetworklist[0].networkid=204 - requests to use ip 10.10.10.11 in network id=204")
|
||||
private Map ipToNetworkList;
|
||||
|
||||
@Parameter(name=ApiConstants.IP_ADDRESS, type=CommandType.STRING, description="the ip address for default vm's network")
|
||||
private String ipAddress;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
@ -195,9 +198,9 @@ public class DeployVMCmd extends BaseAsyncCreateCmd {
|
||||
}
|
||||
|
||||
public List<Long> getNetworkIds() {
|
||||
if (ipToNetworkList != null ) {
|
||||
if (networkIds != null) {
|
||||
throw new InvalidParameterValueException("NetworkIds can't be specified along with ipToNetworkMap");
|
||||
if (ipToNetworkList != null) {
|
||||
if (networkIds != null || ipAddress != null) {
|
||||
throw new InvalidParameterValueException("ipToNetworkMap can't be specified along with networkIds or ipAddress");
|
||||
} else {
|
||||
List<Long> networks = new ArrayList<Long>();
|
||||
networks.addAll(getIpToNetworkMap().keySet());
|
||||
@ -220,9 +223,13 @@ public class DeployVMCmd extends BaseAsyncCreateCmd {
|
||||
return hostId;
|
||||
}
|
||||
|
||||
private String getIpAddress() {
|
||||
return ipAddress;
|
||||
}
|
||||
|
||||
private Map<Long, String> getIpToNetworkMap() {
|
||||
if (networkIds != null && ipToNetworkList != null) {
|
||||
throw new InvalidParameterValueException("NetworkIds can't be specified along with ipToNetworkMap");
|
||||
if ((networkIds != null || ipAddress != null) && ipToNetworkList != null) {
|
||||
throw new InvalidParameterValueException("NetworkIds and ipAddress can't be specified along with ipToNetworkMap parameter");
|
||||
}
|
||||
Map<Long, String> ipToNetworkMap = null;
|
||||
if (ipToNetworkList != null && !ipToNetworkList.isEmpty()) {
|
||||
@ -368,18 +375,18 @@ public class DeployVMCmd extends BaseAsyncCreateCmd {
|
||||
throw new InvalidParameterValueException("Can't specify network Ids in Basic zone");
|
||||
} else {
|
||||
vm = _userVmService.createBasicSecurityGroupVirtualMachine(zone, serviceOffering, template, getSecurityGroupIdList(), owner, name,
|
||||
displayName, diskOfferingId, size, group, getHypervisor(), userData, sshKeyPairName, getIpToNetworkMap());
|
||||
displayName, diskOfferingId, size, group, getHypervisor(), userData, sshKeyPairName, getIpToNetworkMap(), ipAddress);
|
||||
}
|
||||
} else {
|
||||
if (zone.isSecurityGroupEnabled()) {
|
||||
vm = _userVmService.createAdvancedSecurityGroupVirtualMachine(zone, serviceOffering, template, getNetworkIds(), getSecurityGroupIdList(),
|
||||
owner, name, displayName, diskOfferingId, size, group, getHypervisor(), userData, sshKeyPairName, getIpToNetworkMap());
|
||||
owner, name, displayName, diskOfferingId, size, group, getHypervisor(), userData, sshKeyPairName, getIpToNetworkMap(), ipAddress);
|
||||
} else {
|
||||
if (getSecurityGroupIdList() != null && !getSecurityGroupIdList().isEmpty()) {
|
||||
throw new InvalidParameterValueException("Can't create vm with security groups; security group feature is not enabled per zone");
|
||||
}
|
||||
vm = _userVmService.createAdvancedVirtualMachine(zone, serviceOffering, template, getNetworkIds(), owner, name, displayName,
|
||||
diskOfferingId, size, group, getHypervisor(), userData, sshKeyPairName, getIpToNetworkMap());
|
||||
diskOfferingId, size, group, getHypervisor(), userData, sshKeyPairName, getIpToNetworkMap(), ipAddress);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -168,6 +168,7 @@ public interface UserVmService {
|
||||
* @param sshKeyPair
|
||||
* - name of the ssh key pair used to login to the virtual machine
|
||||
* @param requestedIps TODO
|
||||
* @param defaultIp TODO
|
||||
* @param accountName
|
||||
* - an optional account for the virtual machine. Must be used with domainId
|
||||
* @param domainId
|
||||
@ -183,7 +184,7 @@ public interface UserVmService {
|
||||
* @throws InsufficientResourcesException
|
||||
*/
|
||||
UserVm createBasicSecurityGroupVirtualMachine(DataCenter zone, ServiceOffering serviceOffering, VirtualMachineTemplate template, List<Long> securityGroupIdList, Account owner, String hostName,
|
||||
String displayName, Long diskOfferingId, Long diskSize, String group, HypervisorType hypervisor, String userData, String sshKeyPair, Map<Long, String> requestedIps)
|
||||
String displayName, Long diskOfferingId, Long diskSize, String group, HypervisorType hypervisor, String userData, String sshKeyPair, Map<Long, String> requestedIps, String defaultIp)
|
||||
throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException, StorageUnavailableException, ResourceAllocationException;
|
||||
|
||||
/**
|
||||
@ -222,6 +223,7 @@ public interface UserVmService {
|
||||
* @param sshKeyPair
|
||||
* - name of the ssh key pair used to login to the virtual machine
|
||||
* @param requestedIps TODO
|
||||
* @param defaultIp TODO
|
||||
* @param accountName
|
||||
* - an optional account for the virtual machine. Must be used with domainId
|
||||
* @param domainId
|
||||
@ -237,7 +239,7 @@ public interface UserVmService {
|
||||
* @throws InsufficientResourcesException
|
||||
*/
|
||||
UserVm createAdvancedSecurityGroupVirtualMachine(DataCenter zone, ServiceOffering serviceOffering, VirtualMachineTemplate template, List<Long> networkIdList, List<Long> securityGroupIdList,
|
||||
Account owner, String hostName, String displayName, Long diskOfferingId, Long diskSize, String group, HypervisorType hypervisor, String userData, String sshKeyPair, Map<Long, String> requestedIps)
|
||||
Account owner, String hostName, String displayName, Long diskOfferingId, Long diskSize, String group, HypervisorType hypervisor, String userData, String sshKeyPair, Map<Long, String> requestedIps, String defaultIp)
|
||||
throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException, StorageUnavailableException, ResourceAllocationException;
|
||||
|
||||
/**
|
||||
@ -274,6 +276,7 @@ public interface UserVmService {
|
||||
* @param sshKeyPair
|
||||
* - name of the ssh key pair used to login to the virtual machine
|
||||
* @param requestedIps TODO
|
||||
* @param defaultIp TODO
|
||||
* @param accountName
|
||||
* - an optional account for the virtual machine. Must be used with domainId
|
||||
* @param domainId
|
||||
@ -289,7 +292,7 @@ public interface UserVmService {
|
||||
* @throws InsufficientResourcesException
|
||||
*/
|
||||
UserVm createAdvancedVirtualMachine(DataCenter zone, ServiceOffering serviceOffering, VirtualMachineTemplate template, List<Long> networkIdList, Account owner, String hostName,
|
||||
String displayName, Long diskOfferingId, Long diskSize, String group, HypervisorType hypervisor, String userData, String sshKeyPair, Map<Long, String> requestedIps)
|
||||
String displayName, Long diskOfferingId, Long diskSize, String group, HypervisorType hypervisor, String userData, String sshKeyPair, Map<Long, String> requestedIps, String defaultIp)
|
||||
throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException, StorageUnavailableException, ResourceAllocationException;
|
||||
|
||||
/**
|
||||
|
||||
@ -2030,7 +2030,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
||||
|
||||
@Override
|
||||
public UserVm createBasicSecurityGroupVirtualMachine(DataCenter zone, ServiceOffering serviceOffering, VirtualMachineTemplate template, List<Long> securityGroupIdList, Account owner,
|
||||
String hostName, String displayName, Long diskOfferingId, Long diskSize, String group, HypervisorType hypervisor, String userData, String sshKeyPair, Map<Long, String> requestedIps)
|
||||
String hostName, String displayName, Long diskOfferingId, Long diskSize, String group, HypervisorType hypervisor, String userData, String sshKeyPair, Map<Long, String> requestedIps, String defaultIp)
|
||||
throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException, StorageUnavailableException, ResourceAllocationException {
|
||||
|
||||
Account caller = UserContext.current().getCaller();
|
||||
@ -2082,13 +2082,13 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
||||
}
|
||||
|
||||
return createVirtualMachine(zone, serviceOffering, template, hostName, displayName, owner, diskOfferingId,
|
||||
diskSize, networkList, securityGroupIdList, group, userData, sshKeyPair, hypervisor, caller, requestedIps);
|
||||
diskSize, networkList, securityGroupIdList, group, userData, sshKeyPair, hypervisor, caller, requestedIps, defaultIp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserVm createAdvancedSecurityGroupVirtualMachine(DataCenter zone, ServiceOffering serviceOffering, VirtualMachineTemplate template, List<Long> networkIdList,
|
||||
List<Long> securityGroupIdList, Account owner, String hostName, String displayName, Long diskOfferingId, Long diskSize, String group, HypervisorType hypervisor, String userData,
|
||||
String sshKeyPair, Map<Long, String> requestedIps) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException, StorageUnavailableException,
|
||||
String sshKeyPair, Map<Long, String> requestedIps, String defaultIp) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException, StorageUnavailableException,
|
||||
ResourceAllocationException {
|
||||
|
||||
Account caller = UserContext.current().getCaller();
|
||||
@ -2193,12 +2193,12 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
||||
}
|
||||
|
||||
return createVirtualMachine(zone, serviceOffering, template, hostName, displayName, owner, diskOfferingId,
|
||||
diskSize, networkList, securityGroupIdList, group, userData, sshKeyPair, hypervisor, caller, requestedIps);
|
||||
diskSize, networkList, securityGroupIdList, group, userData, sshKeyPair, hypervisor, caller, requestedIps, defaultIp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserVm createAdvancedVirtualMachine(DataCenter zone, ServiceOffering serviceOffering, VirtualMachineTemplate template, List<Long> networkIdList, Account owner, String hostName,
|
||||
String displayName, Long diskOfferingId, Long diskSize, String group, HypervisorType hypervisor, String userData, String sshKeyPair, Map<Long, String> requestedIps)
|
||||
String displayName, Long diskOfferingId, Long diskSize, String group, HypervisorType hypervisor, String userData, String sshKeyPair, Map<Long, String> requestedIps, String defaultIp)
|
||||
throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException, StorageUnavailableException, ResourceAllocationException {
|
||||
|
||||
Account caller = UserContext.current().getCaller();
|
||||
@ -2317,15 +2317,17 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
||||
}
|
||||
}
|
||||
|
||||
return createVirtualMachine(zone, serviceOffering, template, hostName, displayName, owner, diskOfferingId, diskSize, networkList, null, group, userData, sshKeyPair, hypervisor, caller, requestedIps);
|
||||
return createVirtualMachine(zone, serviceOffering, template, hostName, displayName, owner, diskOfferingId, diskSize, networkList, null, group, userData, sshKeyPair, hypervisor, caller, requestedIps, defaultIp);
|
||||
}
|
||||
|
||||
@ActionEvent(eventType = EventTypes.EVENT_VM_CREATE, eventDescription = "deploying Vm", create = true)
|
||||
protected UserVm createVirtualMachine(DataCenter zone, ServiceOffering serviceOffering, VirtualMachineTemplate template, String hostName, String displayName, Account owner, Long diskOfferingId,
|
||||
Long diskSize, List<NetworkVO> networkList, List<Long> securityGroupIdList, String group, String userData, String sshKeyPair, HypervisorType hypervisor, Account caller, Map<Long, String> requestedIps) throws InsufficientCapacityException, ResourceUnavailableException, ConcurrentOperationException, StorageUnavailableException, ResourceAllocationException {
|
||||
Long diskSize, List<NetworkVO> networkList, List<Long> securityGroupIdList, String group, String userData, String sshKeyPair, HypervisorType hypervisor, Account caller, Map<Long, String> requestedIps, String defaultNetworkIp) throws InsufficientCapacityException, ResourceUnavailableException, ConcurrentOperationException, StorageUnavailableException, ResourceAllocationException {
|
||||
|
||||
_accountMgr.checkAccess(caller, owner);
|
||||
long accountId = owner.getId();
|
||||
|
||||
assert !(requestedIps != null && defaultNetworkIp != null) : "requestedIp list and defaultNetworkIp should never be specified together";
|
||||
|
||||
if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(caller.getType())) {
|
||||
throw new PermissionDeniedException("Cannot perform this operation, Zone is currently disabled: " + zone.getId());
|
||||
@ -2449,15 +2451,26 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
||||
List<Pair<NetworkVO, NicProfile>> networks = new ArrayList<Pair<NetworkVO, NicProfile>>();
|
||||
short defaultNetworkNumber = 0;
|
||||
for (NetworkVO network : networkList) {
|
||||
|
||||
if (network.getDataCenterId() != zone.getId()) {
|
||||
throw new InvalidParameterValueException("Network id=" + network.getId() + " doesn't belong to zone " + zone.getId());
|
||||
}
|
||||
|
||||
NicProfile profile = null;
|
||||
|
||||
//Add requested ips
|
||||
if (requestedIps != null && requestedIps.get(network.getId()) != null) {
|
||||
profile = new NicProfile(requestedIps.get(network.getId()));
|
||||
}
|
||||
|
||||
if (network.isDefault()) {
|
||||
defaultNetworkNumber++;
|
||||
// if user requested specific ip for default network, add it
|
||||
if (defaultNetworkIp != null) {
|
||||
profile = new NicProfile(defaultNetworkIp);
|
||||
}
|
||||
}
|
||||
|
||||
NicProfile profile = null;
|
||||
if (requestedIps != null && requestedIps.get(network.getId()) != null) {
|
||||
profile = new NicProfile(requestedIps.get(network.getId()));
|
||||
}
|
||||
|
||||
networks.add(new Pair<NetworkVO, NicProfile>(network, profile));
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user