|
55 | 55 | import javax.xml.parsers.ParserConfigurationException; |
56 | 56 |
|
57 | 57 | import com.cloud.network.NetworkService; |
| 58 | +import com.cloud.network.addr.PublicIp; |
| 59 | +import com.cloud.utils.db.TransactionCallback; |
58 | 60 | import org.apache.cloudstack.acl.ControlledEntity; |
59 | 61 | import org.apache.cloudstack.acl.ControlledEntity.ACLType; |
60 | 62 | import org.apache.cloudstack.acl.SecurityChecker.AccessType; |
@@ -8995,28 +8997,30 @@ public UserVm importVM(final DataCenter zone, final Host host, final VirtualMach |
8995 | 8997 | final long accountId, final long userId, final ServiceOffering serviceOffering, final String sshPublicKeys, |
8996 | 8998 | final String hostName, final HypervisorType hypervisorType, final Map<String, String> customParameters, |
8997 | 8999 | final VirtualMachine.PowerState powerState, final LinkedHashMap<String, List<NicProfile>> networkNicMap) throws InsufficientCapacityException { |
8998 | | - if (zone == null) { |
8999 | | - throw new InvalidParameterValueException("Unable to import virtual machine with invalid zone"); |
9000 | | - } |
9001 | | - if (host == null && hypervisorType == HypervisorType.VMware) { |
9002 | | - throw new InvalidParameterValueException("Unable to import virtual machine with invalid host"); |
9003 | | - } |
| 9000 | + return Transaction.execute((TransactionCallbackWithException<UserVm, InsufficientCapacityException>) status -> { |
| 9001 | + if (zone == null) { |
| 9002 | + throw new InvalidParameterValueException("Unable to import virtual machine with invalid zone"); |
| 9003 | + } |
| 9004 | + if (host == null && hypervisorType == HypervisorType.VMware) { |
| 9005 | + throw new InvalidParameterValueException("Unable to import virtual machine with invalid host"); |
| 9006 | + } |
9004 | 9007 |
|
9005 | | - final long id = _vmDao.getNextInSequence(Long.class, "id"); |
| 9008 | + final long id = _vmDao.getNextInSequence(Long.class, "id"); |
9006 | 9009 |
|
9007 | | - if (hostName != null) { |
9008 | | - // Check is hostName is RFC compliant |
9009 | | - checkNameForRFCCompliance(hostName); |
9010 | | - } |
| 9010 | + if (hostName != null) { |
| 9011 | + // Check is hostName is RFC compliant |
| 9012 | + checkNameForRFCCompliance(hostName); |
| 9013 | + } |
9011 | 9014 |
|
9012 | | - final String uuidName = _uuidMgr.generateUuid(UserVm.class, null); |
9013 | | - final Host lastHost = powerState != VirtualMachine.PowerState.PowerOn ? host : null; |
9014 | | - final Boolean dynamicScalingEnabled = checkIfDynamicScalingCanBeEnabled(null, serviceOffering, template, zone.getId()); |
9015 | | - return commitUserVm(true, zone, host, lastHost, template, hostName, displayName, owner, |
9016 | | - null, null, userData, null, null, isDisplayVm, keyboard, |
9017 | | - accountId, userId, serviceOffering, template.getFormat().equals(ImageFormat.ISO), sshPublicKeys, networkNicMap, |
9018 | | - id, instanceName, uuidName, hypervisorType, customParameters, |
9019 | | - null, null, null, powerState, dynamicScalingEnabled, null, serviceOffering.getDiskOfferingId(), null); |
| 9015 | + final String uuidName = _uuidMgr.generateUuid(UserVm.class, null); |
| 9016 | + final Host lastHost = powerState != VirtualMachine.PowerState.PowerOn ? host : null; |
| 9017 | + final Boolean dynamicScalingEnabled = checkIfDynamicScalingCanBeEnabled(null, serviceOffering, template, zone.getId()); |
| 9018 | + return commitUserVm(true, zone, host, lastHost, template, hostName, displayName, owner, |
| 9019 | + null, null, userData, null, null, isDisplayVm, keyboard, |
| 9020 | + accountId, userId, serviceOffering, template.getFormat().equals(ImageFormat.ISO), sshPublicKeys, networkNicMap, |
| 9021 | + id, instanceName, uuidName, hypervisorType, customParameters, |
| 9022 | + null, null, null, powerState, dynamicScalingEnabled, null, serviceOffering.getDiskOfferingId(), null); |
| 9023 | + }); |
9020 | 9024 | } |
9021 | 9025 |
|
9022 | 9026 | @Override |
|
0 commit comments