Trim postfix appended to the disk name by vCenter after snapshot operation when we are locating disk chain by name

This commit is contained in:
Kelven Yang 2014-07-11 14:42:46 -07:00
parent 87effa40ea
commit bfb28da9fc
1 changed files with 16 additions and 1 deletions

View File

@ -34,6 +34,7 @@ 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;
@ -1939,14 +1940,28 @@ 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");
s_logger.info("Look for disk device info from volume : " + vmdkDatastorePath);
DatastoreFile dsSrcFile = new DatastoreFile(vmdkDatastorePath);
String srcBaseName = dsSrcFile.getFileBaseName();
srcBaseName = trimSnapshotDeltaPostfix(srcBaseName);
s_logger.info("Look for disk device info from volume : " + vmdkDatastorePath + " with trimmed base name: " + srcBaseName);
if (devices != null && devices.size() > 0) {
for (VirtualDevice device : devices) {
if (device instanceof VirtualDisk) {