CLOUDSTACK-8121. Data disk properties are not updated upon Creation/Deletion of VM snapshots.

Update the path and size of data volumes after snapshot creation/deletion by correctly trimming only the snapshot postfix of a disk.
This commit is contained in:
Likitha Shetty 2014-12-04 19:20:45 +05:30
parent b1bca2a2c0
commit ac491c9607
3 changed files with 16 additions and 45 deletions

View File

@ -1159,36 +1159,6 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
return size;
}
private String extractSnapshotBaseFileName(String input) {
if (input == null) {
return null;
}
String result = input;
final String fileType = ".vmdk";
if (result.endsWith(fileType)) {
// get rid of fileType
result = result.substring(0, result.length() - (fileType).length());
}
final String token = "-";
String[] str = result.split(token);
int length = str.length;
if (length == 1 || length == 2) {
return result;
}
if (length > 2) {
return str[0] + token + str[1];
}
return result;
}
@Override
public CreateVMSnapshotAnswer execute(VmwareHostService hostService, CreateVMSnapshotCommand cmd) {
List<VolumeObjectTO> volumeTOs = cmd.getVolumeTOs();
@ -1291,7 +1261,7 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
vmdkName = vmdkName.substring(vmdkName.indexOf(token) + token.length());
}
baseName = extractSnapshotBaseFileName(vmdkName);
baseName = VmwareHelper.trimSnapshotDeltaPostfix(vmdkName);
}
mapNewDisk.put(baseName, vmdkName);
@ -1316,7 +1286,7 @@ public class VmwareStorageManagerImpl implements VmwareStorageManager {
baseName = oldPath.substring(1, oldPath.length() - 1);
}
else {
baseName = extractSnapshotBaseFileName(volumeTO.getPath());
baseName = VmwareHelper.trimSnapshotDeltaPostfix(volumeTO.getPath());
}
String newPath = mapNewDisk.get(baseName);

View File

@ -34,7 +34,6 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import com.google.gson.Gson;
@ -1918,24 +1917,13 @@ public class VirtualMachineMO extends BaseMO {
}
}
private static String trimSnapshotDeltaPostfix(String name) {
String[] tokens = name.split("-");
if (tokens.length > 1 && tokens[tokens.length - 1].matches("[0-9]{6,}")) {
List<String> trimmedTokens = new ArrayList<String>();
for (int i = 0; i < tokens.length - 1; i++)
trimmedTokens.add(tokens[i]);
return StringUtils.join(trimmedTokens, "-");
}
return name;
}
// return pair of VirtualDisk and disk device bus name(ide0:0, etc)
public Pair<VirtualDisk, String> getDiskDevice(String vmdkDatastorePath, boolean matchExactly) throws Exception {
List<VirtualDevice> devices = _context.getVimClient().getDynamicProperty(_mor, "config.hardware.device");
DatastoreFile dsSrcFile = new DatastoreFile(vmdkDatastorePath);
String srcBaseName = dsSrcFile.getFileBaseName();
String trimmedSrcBaseName = trimSnapshotDeltaPostfix(srcBaseName);
String trimmedSrcBaseName = VmwareHelper.trimSnapshotDeltaPostfix(srcBaseName);
if (matchExactly) {
s_logger.info("Look for disk device info from volume : " + vmdkDatastorePath + " with base name: " + srcBaseName);

View File

@ -29,6 +29,7 @@ import java.util.List;
import java.util.Random;
import java.util.UUID;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import com.vmware.vim25.DistributedVirtualSwitchPortConnection;
@ -703,4 +704,16 @@ public class VmwareHelper {
// Object name that is greater than 32 is not safe in vCenter
return UUID.randomUUID().toString().replaceAll("-", "");
}
public static String trimSnapshotDeltaPostfix(String name) {
String[] tokens = name.split("-");
if (tokens.length > 1 && tokens[tokens.length - 1].matches("[0-9]{6,}")) {
List<String> trimmedTokens = new ArrayList<String>();
for (int i = 0; i < tokens.length - 1; i++)
trimmedTokens.add(tokens[i]);
return StringUtils.join(trimmedTokens, "-");
}
return name;
}
}