Skip to content

Commit ef97500

Browse files
committed
[Veeam] Fix create new instance from backup using VSAN storage
1 parent 35ac91e commit ef97500

3 files changed

Lines changed: 50 additions & 3 deletions

File tree

plugins/backup/veeam/src/main/java/org/apache/cloudstack/backup/veeam/VeeamClient.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import javax.net.ssl.SSLContext;
4242
import javax.net.ssl.X509TrustManager;
4343

44+
import com.cloud.utils.UuidUtils;
4445
import org.apache.cloudstack.api.ApiErrorCode;
4546
import org.apache.cloudstack.api.ServerApiException;
4647
import org.apache.cloudstack.backup.Backup;
@@ -906,7 +907,9 @@ public Pair<Boolean, String> restoreVMToDifferentLocation(String restorePointId,
906907
if (restoreLocation == null) {
907908
restoreLocation = RESTORE_VM_SUFFIX + UUID.randomUUID().toString();
908909
}
909-
final String datastoreId = dataStoreUuid.replace("-","");
910+
final String datastoreId = UuidUtils.isUuid(dataStoreUuid) ?
911+
dataStoreUuid.replace("-","") :
912+
dataStoreUuid;
910913
final List<String> cmds = Arrays.asList(
911914
"$points = Get-VBRRestorePoint",
912915
String.format("foreach($point in $points) { if ($point.Id -eq '%s') { $restorePoint = $point; break; } }", restorePointId),

server/src/main/java/org/apache/cloudstack/backup/BackupManagerImpl.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,7 +1391,8 @@ public boolean restoreBackupToVM(final Long backupId, final Long vmId) throws Cl
13911391
if (!"nas".equals(offering.getProvider())) {
13921392
Pair<HostVO, StoragePoolVO> restoreInfo = getRestoreVolumeHostAndDatastore(vm);
13931393
host = restoreInfo.first().getPrivateIpAddress();
1394-
dataStore = restoreInfo.second().getUuid();
1394+
String[] datastorePossibleValues = getDatastorePossibleValues(restoreInfo.second());
1395+
dataStore = datastorePossibleValues[0];
13951396
}
13961397
result = backupProvider.restoreBackupToVM(vm, backup, host, dataStore);
13971398

@@ -1481,7 +1482,7 @@ public boolean restoreBackupVolumeAndAttachToVM(final String backedUpVolumeUuid,
14811482
logger.debug(String.format("Trying to restore volume using host private IP address: [%s].", host.getPrivateIpAddress()));
14821483

14831484
String[] hostPossibleValues = {host.getPrivateIpAddress(), host.getName()};
1484-
String[] datastoresPossibleValues = {datastore.getUuid(), datastore.getName()};
1485+
String[] datastoresPossibleValues = getDatastorePossibleValues(datastore);
14851486

14861487
Pair<Boolean, String> result = restoreBackedUpVolume(backupVolumeInfo, backup, backupProvider, hostPossibleValues, datastoresPossibleValues, vm);
14871488

@@ -1496,6 +1497,20 @@ public boolean restoreBackupVolumeAndAttachToVM(final String backedUpVolumeUuid,
14961497
return true;
14971498
}
14981499

1500+
/**
1501+
* For VMFS datastores, the identifier to be used for Veeam restore is the datastore name.
1502+
* Otherwise, possible values are the datastore UUID and the datastore name..
1503+
*/
1504+
protected String[] getDatastorePossibleValues(StoragePoolVO datastore) {
1505+
if (datastore == null) {
1506+
return new String[0];
1507+
}
1508+
if (Storage.StoragePoolType.VMFS == datastore.getPoolType()) {
1509+
return new String[]{datastore.getName()};
1510+
}
1511+
return new String[]{datastore.getUuid(), datastore.getName()};
1512+
}
1513+
14991514
protected Pair<Boolean, String> restoreBackedUpVolume(final Backup.VolumeInfo backupVolumeInfo, final BackupVO backup,
15001515
BackupProvider backupProvider, String[] hostPossibleValues, String[] datastoresPossibleValues, VMInstanceVO vm) {
15011516
Pair<Boolean, String> result = new Pair<>(false, "");

server/src/test/java/org/apache/cloudstack/backup/BackupManagerTest.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2242,4 +2242,33 @@ public void testRestoreBackupVolumeMismatch() {
22422242
verify(vmInstanceDao, times(1)).findByIdIncludingRemoved(vmId);
22432243
verify(volumeDao, times(1)).findByInstance(vmId);
22442244
}
2245+
2246+
@Test
2247+
public void testGetDatastorePossibleValuesNFS() {
2248+
String poolName = "NFS-Pool-Name";
2249+
String poolUuid = UUID.randomUUID().toString();
2250+
2251+
StoragePoolVO pool = Mockito.mock(StoragePoolVO.class);
2252+
when(pool.getPoolType()).thenReturn(Storage.StoragePoolType.NetworkFilesystem);
2253+
when(pool.getName()).thenReturn(poolName);
2254+
when(pool.getUuid()).thenReturn(poolUuid);
2255+
2256+
String[] datastorePossibleValues = backupManager.getDatastorePossibleValues(pool);
2257+
Assert.assertEquals(2, datastorePossibleValues.length);
2258+
Assert.assertEquals(poolUuid, datastorePossibleValues[0]);
2259+
Assert.assertEquals(poolName, datastorePossibleValues[1]);
2260+
}
2261+
2262+
@Test
2263+
public void testGetDatastorePossibleValuesVSAN() {
2264+
String poolName = "VSAN-Pool-Name";
2265+
2266+
StoragePoolVO pool = Mockito.mock(StoragePoolVO.class);
2267+
when(pool.getPoolType()).thenReturn(Storage.StoragePoolType.VMFS);
2268+
when(pool.getName()).thenReturn(poolName);
2269+
2270+
String[] datastorePossibleValues = backupManager.getDatastorePossibleValues(pool);
2271+
Assert.assertEquals(1, datastorePossibleValues.length);
2272+
Assert.assertEquals(poolName, datastorePossibleValues[0]);
2273+
}
22452274
}

0 commit comments

Comments
 (0)