Skip to content

Commit bfb28da

Browse files
committed
Trim postfix appended to the disk name by vCenter after snapshot operation when we are locating disk chain by name
1 parent 87effa4 commit bfb28da

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

vmware-base/src/com/cloud/hypervisor/vmware/mo/VirtualMachineMO.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import java.util.concurrent.Executors;
3535
import java.util.concurrent.Future;
3636

37+
import org.apache.commons.lang.StringUtils;
3738
import org.apache.log4j.Logger;
3839

3940
import com.google.gson.Gson;
@@ -1939,14 +1940,28 @@ public void ensureScsiDeviceController() throws Exception {
19391940
}
19401941
}
19411942

1943+
private static String trimSnapshotDeltaPostfix(String name) {
1944+
String[] tokens = name.split("-");
1945+
if (tokens.length > 1 && tokens[tokens.length - 1].matches("[0-9]{6,}")) {
1946+
List<String> trimmedTokens = new ArrayList<String>();
1947+
for (int i = 0; i < tokens.length - 1; i++)
1948+
trimmedTokens.add(tokens[i]);
1949+
return StringUtils.join(trimmedTokens, "-");
1950+
}
1951+
return name;
1952+
}
1953+
19421954
// return pair of VirtualDisk and disk device bus name(ide0:0, etc)
19431955
public Pair<VirtualDisk, String> getDiskDevice(String vmdkDatastorePath, boolean matchExactly) throws Exception {
19441956
List<VirtualDevice> devices = _context.getVimClient().getDynamicProperty(_mor, "config.hardware.device");
19451957

1946-
s_logger.info("Look for disk device info from volume : " + vmdkDatastorePath);
19471958
DatastoreFile dsSrcFile = new DatastoreFile(vmdkDatastorePath);
19481959
String srcBaseName = dsSrcFile.getFileBaseName();
19491960

1961+
srcBaseName = trimSnapshotDeltaPostfix(srcBaseName);
1962+
1963+
s_logger.info("Look for disk device info from volume : " + vmdkDatastorePath + " with trimmed base name: " + srcBaseName);
1964+
19501965
if (devices != null && devices.size() > 0) {
19511966
for (VirtualDevice device : devices) {
19521967
if (device instanceof VirtualDisk) {

0 commit comments

Comments
 (0)