mirror of https://github.com/apache/cloudstack.git
Bug fixing on default base folder
This commit is contained in:
parent
bef00b1cfb
commit
3d9edeeb9d
|
|
@ -51,12 +51,45 @@ public class VmwareStorageLayoutHelper {
|
|||
return filePair;
|
||||
|
||||
case CLOUDSTACK_LEGACY:
|
||||
filePair[0] = getLegacyDatastorePathFromVmdkFileName(dsMo, vmdkName + ".vmdk");
|
||||
filePair[0] = getDatastorePathBaseFolderFromVmdkFileName(dsMo, vmdkName + ".vmdk");
|
||||
|
||||
if (linkedVmdk)
|
||||
filePair[1] = getLegacyDatastorePathFromVmdkFileName(dsMo, vmdkName + "-delta.vmdk");
|
||||
filePair[1] = getDatastorePathBaseFolderFromVmdkFileName(dsMo, vmdkName + "-delta.vmdk");
|
||||
else
|
||||
filePair[1] = getLegacyDatastorePathFromVmdkFileName(dsMo, vmdkName + "-flat.vmdk");
|
||||
filePair[1] = getDatastorePathBaseFolderFromVmdkFileName(dsMo, vmdkName + "-flat.vmdk");
|
||||
return filePair;
|
||||
|
||||
default:
|
||||
assert (false);
|
||||
break;
|
||||
}
|
||||
|
||||
assert (false);
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String[] getVmdkFilePairManagedDatastorePath(DatastoreMO dsMo, String vmName, String vmdkName, VmwareStorageLayoutType layoutType, boolean linkedVmdk)
|
||||
throws Exception {
|
||||
|
||||
String[] filePair = new String[2];
|
||||
switch (layoutType) {
|
||||
case VMWARE:
|
||||
assert (vmName != null && !vmName.isEmpty());
|
||||
filePair[0] = getVmwareDatastorePathFromVmdkFileName(dsMo, vmName, vmdkName + ".vmdk");
|
||||
|
||||
if (linkedVmdk)
|
||||
filePair[1] = getVmwareDatastorePathFromVmdkFileName(dsMo, vmName, vmdkName + "-delta.vmdk");
|
||||
else
|
||||
filePair[1] = getVmwareDatastorePathFromVmdkFileName(dsMo, vmName, vmdkName + "-flat.vmdk");
|
||||
return filePair;
|
||||
|
||||
case CLOUDSTACK_LEGACY:
|
||||
filePair[0] = getDeprecatedLegacyDatastorePathFromVmdkFileName(dsMo, vmdkName + ".vmdk");
|
||||
|
||||
if (linkedVmdk)
|
||||
filePair[1] = getDeprecatedLegacyDatastorePathFromVmdkFileName(dsMo, vmdkName + "-delta.vmdk");
|
||||
else
|
||||
filePair[1] = getDeprecatedLegacyDatastorePathFromVmdkFileName(dsMo, vmdkName + "-flat.vmdk");
|
||||
return filePair;
|
||||
|
||||
default:
|
||||
|
|
@ -161,7 +194,7 @@ public class VmwareStorageLayoutHelper {
|
|||
DatastoreFile srcDsFile = new DatastoreFile(fileDsFullPath);
|
||||
String companionFilePath = srcDsFile.getCompanionPath(vmdkName + "-flat.vmdk");
|
||||
if (ds.fileExists(companionFilePath)) {
|
||||
String targetPath = getLegacyDatastorePathFromVmdkFileName(ds, vmdkName + "-flat.vmdk");
|
||||
String targetPath = getDatastorePathBaseFolderFromVmdkFileName(ds, vmdkName + "-flat.vmdk");
|
||||
|
||||
s_logger.info("Fixup folder-synchronization. move " + companionFilePath + " -> " + targetPath);
|
||||
ds.moveDatastoreFile(companionFilePath, dcMo.getMor(), ds.getMor(), targetPath, dcMo.getMor(), true);
|
||||
|
|
@ -169,14 +202,14 @@ public class VmwareStorageLayoutHelper {
|
|||
|
||||
companionFilePath = srcDsFile.getCompanionPath(vmdkName + "-delta.vmdk");
|
||||
if (ds.fileExists(companionFilePath)) {
|
||||
String targetPath = getLegacyDatastorePathFromVmdkFileName(ds, vmdkName + "-delta.vmdk");
|
||||
String targetPath = getDatastorePathBaseFolderFromVmdkFileName(ds, vmdkName + "-delta.vmdk");
|
||||
|
||||
s_logger.info("Fixup folder-synchronization. move " + companionFilePath + " -> " + targetPath);
|
||||
ds.moveDatastoreFile(companionFilePath, dcMo.getMor(), ds.getMor(), targetPath, dcMo.getMor(), true);
|
||||
}
|
||||
|
||||
// move the identity VMDK file the last
|
||||
String targetPath = getLegacyDatastorePathFromVmdkFileName(ds, vmdkName + ".vmdk");
|
||||
String targetPath = getDatastorePathBaseFolderFromVmdkFileName(ds, vmdkName + ".vmdk");
|
||||
s_logger.info("Fixup folder-synchronization. move " + fileDsFullPath + " -> " + targetPath);
|
||||
ds.moveDatastoreFile(fileDsFullPath, dcMo.getMor(), ds.getMor(), targetPath, dcMo.getMor(), true);
|
||||
|
||||
|
|
@ -310,17 +343,20 @@ public class VmwareStorageLayoutHelper {
|
|||
}
|
||||
}
|
||||
|
||||
//This method call is for the volumes which actually exists
|
||||
public static String getLegacyDatastorePathFromVmdkFileName(DatastoreMO dsMo, String vmdkFileName) throws Exception {
|
||||
String vmdkDatastorePath = String.format("[%s] %s/%s", dsMo.getName(), HypervisorHostHelper.VSPHERE_DATASTORE_BASE_FOLDER, vmdkFileName);
|
||||
if (!dsMo.fileExists(vmdkDatastorePath)) {
|
||||
vmdkDatastorePath = String.format("[%s] %s/%s", dsMo.getName(), HypervisorHostHelper.VSPHERE_FCD_DEFAULT_FOLDER, vmdkFileName);
|
||||
}
|
||||
if (!dsMo.fileExists(vmdkDatastorePath)) {
|
||||
vmdkDatastorePath = getDeprecatedLegacyDatastorePathFromVmdkFileName(dsMo, vmdkFileName);
|
||||
}
|
||||
return vmdkDatastorePath;
|
||||
}
|
||||
|
||||
//This method call is for the volumes to be created or can also be for volumes already exists
|
||||
public static String getDatastorePathBaseFolderFromVmdkFileName(DatastoreMO dsMo, String vmdkFileName) throws Exception {
|
||||
return String.format("[%s] %s/%s", dsMo.getName(), HypervisorHostHelper.VSPHERE_DATASTORE_BASE_FOLDER, vmdkFileName);
|
||||
}
|
||||
|
||||
public static String getDeprecatedLegacyDatastorePathFromVmdkFileName(DatastoreMO dsMo, String vmdkFileName) throws Exception {
|
||||
return String.format("[%s] %s", dsMo.getName(), vmdkFileName);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -665,9 +665,9 @@ public class VmwareStorageProcessor implements StorageProcessor {
|
|||
VirtualMachineMO vmMo = vmInfo.first();
|
||||
vmMo.unregisterVm();
|
||||
|
||||
String[] vmwareLayoutFilePair = VmwareStorageLayoutHelper.getVmdkFilePairDatastorePath(dsMo, managedStoragePoolRootVolumeName,
|
||||
String[] vmwareLayoutFilePair = VmwareStorageLayoutHelper.getVmdkFilePairManagedDatastorePath(dsMo, managedStoragePoolRootVolumeName,
|
||||
managedStoragePoolRootVolumeName, VmwareStorageLayoutType.VMWARE, false);
|
||||
String[] legacyCloudStackLayoutFilePair = VmwareStorageLayoutHelper.getVmdkFilePairDatastorePath(dsMo, null,
|
||||
String[] legacyCloudStackLayoutFilePair = VmwareStorageLayoutHelper.getVmdkFilePairManagedDatastorePath(dsMo, null,
|
||||
managedStoragePoolRootVolumeName, VmwareStorageLayoutType.CLOUDSTACK_LEGACY, false);
|
||||
|
||||
dsMo.moveDatastoreFile(vmwareLayoutFilePair[0], dcMo.getMor(), dsMo.getMor(), legacyCloudStackLayoutFilePair[0], dcMo.getMor(), true);
|
||||
|
|
|
|||
|
|
@ -279,47 +279,6 @@ public class DatastoreMO extends BaseMO {
|
|||
return false;
|
||||
}
|
||||
|
||||
public String[] getVmdkFileChain(String rootVmdkDatastoreFullPath) throws Exception {
|
||||
Pair<DatacenterMO, String> dcPair = getOwnerDatacenter();
|
||||
|
||||
List<String> files = new ArrayList<>();
|
||||
files.add(rootVmdkDatastoreFullPath);
|
||||
|
||||
String currentVmdkFullPath = rootVmdkDatastoreFullPath;
|
||||
while (true) {
|
||||
String url = getContext().composeDatastoreBrowseUrl(dcPair.second(), currentVmdkFullPath);
|
||||
byte[] content = getContext().getResourceContent(url);
|
||||
if (content == null || content.length == 0)
|
||||
break;
|
||||
|
||||
VmdkFileDescriptor descriptor = new VmdkFileDescriptor();
|
||||
descriptor.parse(content);
|
||||
|
||||
String parentFileName = descriptor.getParentFileName();
|
||||
if (parentFileName == null)
|
||||
break;
|
||||
|
||||
if (parentFileName.startsWith("/")) {
|
||||
// when parent file is not at the same directory as it is, assume it is at parent directory
|
||||
// this is only valid in Apache CloudStack primary storage deployment
|
||||
DatastoreFile dsFile = new DatastoreFile(currentVmdkFullPath);
|
||||
String dir = dsFile.getDir();
|
||||
if (dir != null && dir.lastIndexOf('/') > 0)
|
||||
dir = dir.substring(0, dir.lastIndexOf('/'));
|
||||
else
|
||||
dir = "";
|
||||
|
||||
currentVmdkFullPath = new DatastoreFile(dsFile.getDatastoreName(), dir, parentFileName.substring(parentFileName.lastIndexOf('/') + 1)).getPath();
|
||||
files.add(currentVmdkFullPath);
|
||||
} else {
|
||||
currentVmdkFullPath = DatastoreFile.getCompanionDatastorePath(currentVmdkFullPath, parentFileName);
|
||||
files.add(currentVmdkFullPath);
|
||||
}
|
||||
}
|
||||
|
||||
return files.toArray(new String[0]);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public String[] listDirContent(String path) throws Exception {
|
||||
String fullPath = path;
|
||||
|
|
|
|||
|
|
@ -138,8 +138,7 @@ public class HypervisorHostHelper {
|
|||
private static final String UNTAGGED_VLAN_NAME = "untagged";
|
||||
private static final String VMDK_PACK_DIR = "ova";
|
||||
private static final String OVA_OPTION_KEY_BOOTDISK = "cloud.ova.bootdisk";
|
||||
public static final String VSPHERE_DATASTORE_BASE_FOLDER = ".cloudstack.base.folder";
|
||||
public static final String VSPHERE_FCD_DEFAULT_FOLDER = "fcd";
|
||||
public static final String VSPHERE_DATASTORE_BASE_FOLDER = "fcd";
|
||||
|
||||
public static VirtualMachineMO findVmFromObjectContent(VmwareContext context, ObjectContent[] ocs, String name, String instanceNameCustomField) {
|
||||
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ import java.util.concurrent.Future;
|
|||
|
||||
import com.vmware.vim25.VStorageObject;
|
||||
import com.vmware.vim25.VStorageObjectConfigInfo;
|
||||
import com.vmware.vim25.VirtualMachineRelocateTransformation;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ import javax.xml.datatype.DatatypeConfigurationException;
|
|||
import javax.xml.datatype.DatatypeFactory;
|
||||
import javax.xml.datatype.XMLGregorianCalendar;
|
||||
|
||||
import com.vmware.vim25.VirtualDiskType;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue