@@ -8989,34 +8989,47 @@ private void destroyVolumeInContext(UserVmVO vm, boolean expunge, VolumeVO volum
8989
8989
}
8990
8990
}
8991
8991
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
+
8992
9000
@ 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 ,
8994
9002
final Account owner , final String userData , final Account caller , final Boolean isDisplayVm , final String keyboard ,
8995
9003
final long accountId , final long userId , final ServiceOffering serviceOffering , final String sshPublicKeys ,
8996
9004
final String hostName , final HypervisorType hypervisorType , final Map <String , String > customParameters ,
8997
9005
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
+ }
9004
9013
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 ;
9006
9018
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
+ }
9011
9023
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
+ });
9020
9033
}
9021
9034
9022
9035
@ Override
0 commit comments