}
public static void moveVolumeToRootFolder(DatacenterMO dcMo, List<String> detachedDisks) throws Exception {
if(detachedDisks.size() > 0) {
for(String fileFullDsPath : detachedDisks) {
DatastoreFile file = new DatastoreFile(fileFullDsPath);
s_logger.info("Check if we need to move " + fileFullDsPath + " to its root location");
DatastoreMO dsMo = new DatastoreMO(dcMo.getContext(), dcMo.findDatastore(file.getDatastoreName()));
if(dsMo.getMor() != null) {
DatastoreFile targetFile = new DatastoreFile(file.getDatastoreName(), file.getFileName());
if(!targetFile.getPath().equalsIgnoreCase(file.getPath())) {
s_logger.info("Move " + file.getPath() + " -> " + targetFile.getPath());
dsMo.moveDatastoreFile(file.getPath(), dcMo.getMor(), dsMo.getMor(), targetFile.getPath(), dcMo.getMor(), true);
String pairSrcFilePath = file.getCompanionPath(file.getFileBaseName() + "-flat.vmdk");
String pairTargetFilePath = targetFile.getCompanionPath(file.getFileBaseName() + "-flat.vmdk");
if(dsMo.fileExists(pairSrcFilePath)) {
s_logger.info("Move " + pairSrcFilePath + " -> " + pairTargetFilePath);
dsMo.moveDatastoreFile(pairSrcFilePath, dcMo.getMor(), dsMo.getMor(), pairTargetFilePath, dcMo.getMor(), true);
}
pairSrcFilePath = file.getCompanionPath(file.getFileBaseName() + "-delta.vmdk");
pairTargetFilePath = targetFile.getCompanionPath(file.getFileBaseName() + "-delta.vmdk");
if(dsMo.fileExists(pairSrcFilePath)) {
s_logger.info("Move " + pairSrcFilePath + " -> " + pairTargetFilePath);
dsMo.moveDatastoreFile(pairSrcFilePath, dcMo.getMor(), dsMo.getMor(), pairTargetFilePath, dcMo.getMor(), true);
}
}