@@ -315,46 +315,41 @@ public Answer execute(VmwareHostService hostService, BackupSnapshotCommand cmd)
315315 String prevBackupUuid = cmd .getPrevBackupUuid ();
316316 VirtualMachineMO workerVm =null ;
317317 String workerVMName = null ;
318- String volumePath = cmd .getVolumePath ();
319- ManagedObjectReference morDs = null ;
320- DatastoreMO dsMo =null ;
321-
322- // By default assume failure
323- String details = null ;
324- boolean success = false ;
325- String snapshotBackupUuid = null ;
326-
327- VmwareContext context = hostService .getServiceContext (cmd );
328- VirtualMachineMO vmMo = null ;
329- try {
330- VmwareHypervisorHost hyperHost = hostService .getHyperHost (context , cmd );
331- morDs = HypervisorHostHelper .findDatastoreWithBackwardsCompatibility (hyperHost , cmd .getPool ().getUuid ());
332-
333- try {
334- vmMo = hyperHost .findVmOnHyperHost (cmd .getVmName ());
335- if (vmMo == null ) {
336- if (s_logger .isDebugEnabled ())
337- s_logger .debug ("Unable to find owner VM for BackupSnapshotCommand on host " + hyperHost .getHyperHostName () + ", will try within datacenter" );
338-
339- vmMo = hyperHost .findVmOnPeerHyperHost (cmd .getVmName ());
340- if (vmMo == null ) {
341- dsMo = new DatastoreMO (hyperHost .getContext (), morDs );
342-
343- workerVMName = hostService .getWorkerName (context , cmd , 0 );
344-
345- // attach a volume to dummay wrapper VM for taking snapshot and exporting the VM for backup
346- if (!hyperHost .createBlankVm (workerVMName , null , 1 , 512 , 0 , false , 4 , 0 , VirtualMachineGuestOsIdentifier .OTHER_GUEST .value (), morDs , false )) {
347- String msg = "Unable to create worker VM to execute BackupSnapshotCommand" ;
348- s_logger .error (msg );
349- throw new Exception (msg );
350- }
351- vmMo = hyperHost .findVmOnHyperHost (workerVMName );
352- if (vmMo == null ) {
353- throw new Exception ("Failed to find the newly create or relocated VM. vmName: " + workerVMName );
354- }
355- workerVm = vmMo ;
356-
357- // attach volume to worker VM
318+ String volumePath = cmd .getVolumePath ();
319+ ManagedObjectReference morDs = null ;
320+ DatastoreMO dsMo =null ;
321+
322+ // By default assume failure
323+ String details = null ;
324+ boolean success = false ;
325+ String snapshotBackupUuid = null ;
326+
327+ VmwareContext context = hostService .getServiceContext (cmd );
328+ VirtualMachineMO vmMo = null ;
329+ try {
330+ VmwareHypervisorHost hyperHost = hostService .getHyperHost (context , cmd );
331+ morDs = HypervisorHostHelper .findDatastoreWithBackwardsCompatibility (hyperHost , cmd .getPool ().getUuid ());
332+
333+ try {
334+ vmMo = hyperHost .findVmOnHyperHost (cmd .getVmName ());
335+ if (vmMo == null ) {
336+ if (s_logger .isDebugEnabled ()) {
337+ s_logger .debug ("Unable to find owner VM for BackupSnapshotCommand on host " + hyperHost .getHyperHostName () + ", will try within datacenter" );
338+ }
339+
340+ vmMo = hyperHost .findVmOnPeerHyperHost (cmd .getVmName ());
341+ if (vmMo == null ) {
342+ dsMo = new DatastoreMO (hyperHost .getContext (), morDs );
343+
344+ workerVMName = hostService .getWorkerName (context , cmd , 0 );
345+ vmMo = HypervisorHostHelper .createWorkerVM (hyperHost , dsMo , workerVMName );
346+
347+ if (vmMo == null ) {
348+ throw new Exception ("Failed to find the newly create or relocated VM. vmName: " + workerVMName );
349+ }
350+ workerVm = vmMo ;
351+
352+ // attach volume to worker VM
358353 String datastoreVolumePath = getVolumePathInDatastore (dsMo , volumePath + ".vmdk" );
359354 vmMo .attachDisk (new String [] { datastoreVolumePath }, morDs );
360355 }
@@ -1071,28 +1066,8 @@ private Pair<String, String> copyVolumeToSecStorage(VmwareHostService hostServic
10711066 if (vmMo == null ) {
10721067 // create a dummy worker vm for attaching the volume
10731068 DatastoreMO dsMo = new DatastoreMO (hyperHost .getContext (), morDs );
1074- //restrict VM name to 32 chars, (else snapshot descriptor file name will be truncated to 32 chars of vm name)
1075- VirtualMachineConfigSpec vmConfig = new VirtualMachineConfigSpec ();
1076- vmConfig .setName (workerVmName );
1077- vmConfig .setMemoryMB ((long ) 4 );
1078- vmConfig .setNumCPUs (1 );
1079- vmConfig .setGuestId (VirtualMachineGuestOsIdentifier .OTHER_GUEST .value ());
1080- VirtualMachineFileInfo fileInfo = new VirtualMachineFileInfo ();
1081- fileInfo .setVmPathName (String .format ("[%s]" , dsMo .getName ()));
1082- vmConfig .setFiles (fileInfo );
1083-
1084- // Scsi controller
1085- VirtualLsiLogicController scsiController = new VirtualLsiLogicController ();
1086- scsiController .setSharedBus (VirtualSCSISharing .NO_SHARING );
1087- scsiController .setBusNumber (0 );
1088- scsiController .setKey (1 );
1089- VirtualDeviceConfigSpec scsiControllerSpec = new VirtualDeviceConfigSpec ();
1090- scsiControllerSpec .setDevice (scsiController );
1091- scsiControllerSpec .setOperation (VirtualDeviceConfigSpecOperation .ADD );
1092- vmConfig .getDeviceChange ().add (scsiControllerSpec );
1093-
1094- hyperHost .createVm (vmConfig );
1095- workerVm = hyperHost .findVmOnHyperHost (workerVmName );
1069+ workerVm = HypervisorHostHelper .createWorkerVM (hyperHost , dsMo , workerVmName );
1070+
10961071 if (workerVm == null ) {
10971072 String msg = "Unable to create worker VM to execute CopyVolumeCommand" ;
10981073 s_logger .error (msg );
0 commit comments