mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
configdrive: make fewer mountpoints on hosts (#2716)
This ensure that fewer mount points are made on hosts for either primary storagepools or secondary storagepools. Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
This commit is contained in:
parent
08a59e89c3
commit
39471c8c00
@ -19,7 +19,6 @@ package org.apache.cloudstack.storage.configdrive;
|
||||
|
||||
public class ConfigDrive {
|
||||
|
||||
public final static String CONFIGDRIVEFILENAME = "configdrive.iso";
|
||||
public final static String CONFIGDRIVEDIR = "configdrive";
|
||||
|
||||
public static final String cloudStackConfigDriveName = "/cloudstack/";
|
||||
@ -27,11 +26,20 @@ public class ConfigDrive {
|
||||
|
||||
/**
|
||||
* Creates the path to ISO file relative to mount point.
|
||||
* The config driver path will have the following formated: {@link #CONFIGDRIVEDIR} + / + instanceName + / + {@link #CONFIGDRIVEFILENAME}
|
||||
* The config driver path will have the following format: {@link #CONFIGDRIVEDIR} + / + instanceName + ".iso"
|
||||
*
|
||||
* @return config drive ISO file path
|
||||
*/
|
||||
public static String createConfigDrivePath(String instanceName) {
|
||||
return ConfigDrive.CONFIGDRIVEDIR + "/" + instanceName + "/" + ConfigDrive.CONFIGDRIVEFILENAME;
|
||||
return ConfigDrive.CONFIGDRIVEDIR + "/" + configIsoFileName(instanceName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Config Drive iso file name for an instance name
|
||||
* @param instanceName
|
||||
* @return
|
||||
*/
|
||||
public static String configIsoFileName(String instanceName) {
|
||||
return instanceName + ".iso";
|
||||
}
|
||||
}
|
||||
@ -79,6 +79,11 @@ public class ConfigDriveBuilder {
|
||||
public static File base64StringToFile(String encodedIsoData, String folder, String fileName) throws IOException {
|
||||
byte[] decoded = Base64.decodeBase64(encodedIsoData.getBytes(StandardCharsets.US_ASCII));
|
||||
Path destPath = Paths.get(folder, fileName);
|
||||
try {
|
||||
Files.createDirectories(destPath.getParent());
|
||||
} catch (final IOException e) {
|
||||
LOG.warn("Exception hit while trying to recreate directory: " + destPath.getParent().toString());
|
||||
}
|
||||
return Files.write(destPath, decoded).toFile();
|
||||
}
|
||||
|
||||
|
||||
@ -26,7 +26,7 @@ public class ConfigDriveTest {
|
||||
|
||||
@Test
|
||||
public void testConfigDriveIsoPath() throws IOException {
|
||||
Assert.assertEquals(ConfigDrive.createConfigDrivePath("i-x-y"), "configdrive/i-x-y/configdrive.iso");
|
||||
Assert.assertEquals(ConfigDrive.createConfigDrivePath("i-x-y"), "configdrive/i-x-y.iso");
|
||||
}
|
||||
|
||||
}
|
||||
@ -24,7 +24,6 @@ import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import org.apache.cloudstack.storage.configdrive.ConfigDriveBuilder;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.agent.api.Answer;
|
||||
@ -67,7 +66,7 @@ public final class LibvirtHandleConfigDriveCommandWrapper extends CommandWrapper
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
FileUtils.deleteDirectory(isoPath.getParent().toFile());
|
||||
Files.deleteIfExists(isoPath);
|
||||
} catch (IOException e) {
|
||||
LOG.warn("Failed to delete config drive: " + isoPath.toAbsolutePath().toString());
|
||||
return new Answer(command, false, "Failed due to exception: " + e.getMessage());
|
||||
|
||||
@ -375,8 +375,9 @@ public class ConfigDriveNetworkElement extends AdapterBase implements NetworkEle
|
||||
|
||||
LOG.debug("Creating config drive ISO for vm: " + profile.getInstanceName());
|
||||
|
||||
final String isoFileName = ConfigDrive.configIsoFileName(profile.getInstanceName());
|
||||
final String isoPath = ConfigDrive.createConfigDrivePath(profile.getInstanceName());
|
||||
final String isoData = ConfigDriveBuilder.buildConfigDrive(profile.getVmData(), ConfigDrive.CONFIGDRIVEFILENAME, profile.getConfigDriveLabel());
|
||||
final String isoData = ConfigDriveBuilder.buildConfigDrive(profile.getVmData(), isoFileName, profile.getConfigDriveLabel());
|
||||
final HandleConfigDriveIsoCommand configDriveIsoCommand = new HandleConfigDriveIsoCommand(isoPath, isoData, dataStore.getTO(), true);
|
||||
|
||||
final Answer answer = agentManager.easySend(agentId, configDriveIsoCommand);
|
||||
|
||||
@ -42,6 +42,7 @@ import java.io.UnsupportedEncodingException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.URI;
|
||||
import java.net.UnknownHostException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.ArrayList;
|
||||
@ -337,7 +338,7 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
|
||||
Path tempDir = null;
|
||||
try {
|
||||
tempDir = java.nio.file.Files.createTempDirectory(ConfigDrive.CONFIGDRIVEDIR);
|
||||
File tmpIsoFile = ConfigDriveBuilder.base64StringToFile(cmd.getIsoData(), tempDir.toAbsolutePath().toString(), ConfigDrive.CONFIGDRIVEFILENAME);
|
||||
File tmpIsoFile = ConfigDriveBuilder.base64StringToFile(cmd.getIsoData(), tempDir.toAbsolutePath().toString(), cmd.getIsoFile());
|
||||
copyLocalToNfs(tmpIsoFile, new File(cmd.getIsoFile()), cmd.getDestStore());
|
||||
} catch (IOException | ConfigurationException e) {
|
||||
return new Answer(cmd, false, "Failed due to exception: " + e.getMessage());
|
||||
@ -355,11 +356,11 @@ public class NfsSecondaryStorageResource extends ServerResourceBase implements S
|
||||
DataStoreTO dstore = cmd.getDestStore();
|
||||
if (dstore instanceof NfsTO) {
|
||||
NfsTO nfs = (NfsTO) dstore;
|
||||
String relativeTemplatePath = new File(cmd.getIsoFile()).getParent();
|
||||
String relativeTemplatePath = new File(cmd.getIsoFile()).getPath();
|
||||
String nfsMountPoint = getRootDir(nfs.getUrl(), _nfsVersion);
|
||||
File tmpltPath = new File(nfsMountPoint, relativeTemplatePath);
|
||||
try {
|
||||
FileUtils.deleteDirectory(tmpltPath);
|
||||
Files.deleteIfExists(tmpltPath.toPath());
|
||||
} catch (IOException e) {
|
||||
return new Answer(cmd, e);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user