mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
xenserver: attach regular iso with configdrive (#9216)
* xenserver: attach regular iso with configdrive Fixes #7902 This PR allows attaching a regular ISO to a VM when it already has the config drive ISO attached. Config-drive ISO is now attached with the SR name-label <VM-NAME>-CONFIGDRIVE-ISO. While regular ISOs continue to attach with SR name-label <VM-NAME>-ISO. VM which already have the configdrive ISO attached before this fix will return an appropriate error and will need to be stopped-start.
This commit is contained in:
parent
22cd00ffb1
commit
53faf0f66a
@ -62,6 +62,7 @@ import org.apache.cloudstack.diagnostics.DiagnosticsService;
|
||||
import org.apache.cloudstack.hypervisor.xenserver.ExtraConfigurationUtility;
|
||||
import org.apache.cloudstack.storage.command.browser.ListDataStoreObjectsAnswer;
|
||||
import org.apache.cloudstack.storage.command.browser.ListDataStoreObjectsCommand;
|
||||
import org.apache.cloudstack.storage.configdrive.ConfigDrive;
|
||||
import org.apache.cloudstack.storage.to.TemplateObjectTO;
|
||||
import org.apache.cloudstack.storage.to.VolumeObjectTO;
|
||||
import org.apache.cloudstack.utils.security.ParserUtils;
|
||||
@ -222,6 +223,8 @@ public abstract class CitrixResourceBase extends ServerResourceBase implements S
|
||||
|
||||
private final static String VM_NAME_ISO_SUFFIX = "-ISO";
|
||||
|
||||
private final static String VM_NAME_CONFIGDRIVE_ISO_SUFFIX = "-CONFIGDRIVE-ISO";
|
||||
|
||||
private final static String VM_FILE_ISO_SUFFIX = ".iso";
|
||||
public final static int DEFAULTDOMRSSHPORT = 3922;
|
||||
|
||||
@ -1020,12 +1023,13 @@ public abstract class CitrixResourceBase extends ServerResourceBase implements S
|
||||
protected SR createIsoSRbyURI(final Connection conn, final URI uri, final String vmName, final boolean shared) {
|
||||
try {
|
||||
final Map<String, String> deviceConfig = new HashMap<String, String>();
|
||||
final boolean isConfigDrive = uri.toString().endsWith(ConfigDrive.CONFIGDRIVEDIR);
|
||||
String path = uri.getPath();
|
||||
path = path.replace("//", "/");
|
||||
deviceConfig.put("location", uri.getHost() + ":" + path);
|
||||
final Host host = Host.getByUuid(conn, _host.getUuid());
|
||||
final SR sr = SR.create(conn, host, deviceConfig, new Long(0), uri.getHost() + path, "iso", "iso", "iso", shared, new HashMap<String, String>());
|
||||
sr.setNameLabel(conn, vmName + "-ISO");
|
||||
sr.setNameLabel(conn, vmName + (isConfigDrive ? VM_NAME_CONFIGDRIVE_ISO_SUFFIX: VM_NAME_ISO_SUFFIX));
|
||||
sr.setNameDescription(conn, deviceConfig.get("location"));
|
||||
|
||||
sr.scan(conn);
|
||||
@ -2648,9 +2652,10 @@ public abstract class CitrixResourceBase extends ServerResourceBase implements S
|
||||
return scsiid;
|
||||
}
|
||||
|
||||
public SR getISOSRbyVmName(final Connection conn, final String vmName) {
|
||||
public SR getISOSRbyVmName(final Connection conn, final String vmName, boolean isConfigDrive) {
|
||||
try {
|
||||
final Set<SR> srs = SR.getByNameLabel(conn, vmName + "-ISO");
|
||||
final Set<SR> srs = SR.getByNameLabel(conn, vmName +
|
||||
(isConfigDrive ? VM_NAME_CONFIGDRIVE_ISO_SUFFIX : VM_NAME_ISO_SUFFIX));
|
||||
if (srs.size() == 0) {
|
||||
return null;
|
||||
} else if (srs.size() == 1) {
|
||||
@ -2697,9 +2702,20 @@ public abstract class CitrixResourceBase extends ServerResourceBase implements S
|
||||
} catch (final URISyntaxException e) {
|
||||
throw new CloudRuntimeException("isoURL is wrong: " + isoURL);
|
||||
}
|
||||
isoSR = getISOSRbyVmName(conn, vmName);
|
||||
isoSR = getISOSRbyVmName(conn, vmName, false);
|
||||
if (isoSR == null) {
|
||||
isoSR = createIsoSRbyURI(conn, uri, vmName, false);
|
||||
} else {
|
||||
try {
|
||||
String description = isoSR.getNameDescription(conn);
|
||||
if (description.endsWith(ConfigDrive.CONFIGDRIVEDIR)) {
|
||||
throw new CloudRuntimeException(String.format("VM %s already has %s ISO attached. Please " +
|
||||
"stop-start VM to allow attaching-detaching both ISOs", vmName, ConfigDrive.CONFIGDRIVEDIR));
|
||||
}
|
||||
} catch (XenAPIException | XmlRpcException e) {
|
||||
throw new CloudRuntimeException(String.format("Unable to retrieve name description for the already " +
|
||||
"attached ISO on VM %s", vmName));
|
||||
}
|
||||
}
|
||||
|
||||
final String isoName = isoURL.substring(index + 1);
|
||||
@ -5667,7 +5683,7 @@ public abstract class CitrixResourceBase extends ServerResourceBase implements S
|
||||
s_logger.debug("Attaching config drive iso device for the VM " + vmName + " In host " + ipAddr);
|
||||
Set<VM> vms = VM.getByNameLabel(conn, vmName);
|
||||
|
||||
SR sr = getSRByNameLabel(conn, vmName + VM_NAME_ISO_SUFFIX);
|
||||
SR sr = getSRByNameLabel(conn, vmName + VM_NAME_CONFIGDRIVE_ISO_SUFFIX);
|
||||
//Here you will find only two vdis with the <vmname>.iso.
|
||||
//one is from source host and second from dest host
|
||||
Set<VDI> vdis = VDI.getByNameLabel(conn, vmName + VM_FILE_ISO_SUFFIX);
|
||||
|
||||
@ -144,8 +144,10 @@ public final class CitrixStopCommandWrapper extends CommandWrapper<StopCommand,
|
||||
networks.add(vif.getNetwork(conn));
|
||||
}
|
||||
vm.destroy(conn);
|
||||
final SR sr = citrixResourceBase.getISOSRbyVmName(conn, command.getVmName());
|
||||
final SR sr = citrixResourceBase.getISOSRbyVmName(conn, command.getVmName(), false);
|
||||
citrixResourceBase.removeSR(conn, sr);
|
||||
final SR configDriveSR = citrixResourceBase.getISOSRbyVmName(conn, command.getVmName(), true);
|
||||
citrixResourceBase.removeSR(conn, configDriveSR);
|
||||
// Disable any VLAN networks that aren't used
|
||||
// anymore
|
||||
for (final Network network : networks) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user