@@ -8989,34 +8989,47 @@ private void destroyVolumeInContext(UserVmVO vm, boolean expunge, VolumeVO volum
89898989 }
89908990 }
89918991
8992+ private String getInternalName (long accountId , long vmId ) {
8993+ String instanceSuffix = _configDao .getValue (Config .InstanceName .key ());
8994+ if (instanceSuffix == null ) {
8995+ instanceSuffix = "DEFAULT" ;
8996+ }
8997+ return VirtualMachineName .getVmName (vmId , accountId , instanceSuffix );
8998+ }
8999+
89929000 @ Override
8993- public UserVm importVM (final DataCenter zone , final Host host , final VirtualMachineTemplate template , final String instanceName , final String displayName ,
9001+ public UserVm importVM (final DataCenter zone , final Host host , final VirtualMachineTemplate template , final String instanceNameInternal , final String displayName ,
89949002 final Account owner , final String userData , final Account caller , final Boolean isDisplayVm , final String keyboard ,
89959003 final long accountId , final long userId , final ServiceOffering serviceOffering , final String sshPublicKeys ,
89969004 final String hostName , final HypervisorType hypervisorType , final Map <String , String > customParameters ,
89979005 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- }
9006+ return Transaction .execute ((TransactionCallbackWithException <UserVm , InsufficientCapacityException >) status -> {
9007+ if (zone == null ) {
9008+ throw new InvalidParameterValueException ("Unable to import virtual machine with invalid zone" );
9009+ }
9010+ if (host == null && hypervisorType == HypervisorType .VMware ) {
9011+ throw new InvalidParameterValueException ("Unable to import virtual machine with invalid host" );
9012+ }
90049013
9005- final long id = _vmDao .getNextInSequence (Long .class , "id" );
9014+ final long id = _vmDao .getNextInSequence (Long .class , "id" );
9015+ String instanceName = StringUtils .isBlank (instanceNameInternal ) ?
9016+ getInternalName (owner .getAccountId (), id ) :
9017+ instanceNameInternal ;
90069018
9007- if (hostName != null ) {
9008- // Check is hostName is RFC compliant
9009- checkNameForRFCCompliance (hostName );
9010- }
9019+ if (hostName != null ) {
9020+ // Check is hostName is RFC compliant
9021+ checkNameForRFCCompliance (hostName );
9022+ }
90119023
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 );
9024+ final String uuidName = _uuidMgr .generateUuid (UserVm .class , null );
9025+ final Host lastHost = powerState != VirtualMachine .PowerState .PowerOn ? host : null ;
9026+ final Boolean dynamicScalingEnabled = checkIfDynamicScalingCanBeEnabled (null , serviceOffering , template , zone .getId ());
9027+ return commitUserVm (true , zone , host , lastHost , template , hostName , displayName , owner ,
9028+ null , null , userData , null , null , isDisplayVm , keyboard ,
9029+ accountId , userId , serviceOffering , template .getFormat ().equals (ImageFormat .ISO ), sshPublicKeys , networkNicMap ,
9030+ id , instanceName , uuidName , hypervisorType , customParameters ,
9031+ null , null , null , powerState , dynamicScalingEnabled , null , serviceOffering .getDiskOfferingId (), null );
9032+ });
90209033 }
90219034
90229035 @ Override
0 commit comments