Skip to content

Commit 53faf0f

Browse files
authored
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.
1 parent 22cd00f commit 53faf0f

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/CitrixResourceBase.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
import org.apache.cloudstack.hypervisor.xenserver.ExtraConfigurationUtility;
6363
import org.apache.cloudstack.storage.command.browser.ListDataStoreObjectsAnswer;
6464
import org.apache.cloudstack.storage.command.browser.ListDataStoreObjectsCommand;
65+
import org.apache.cloudstack.storage.configdrive.ConfigDrive;
6566
import org.apache.cloudstack.storage.to.TemplateObjectTO;
6667
import org.apache.cloudstack.storage.to.VolumeObjectTO;
6768
import org.apache.cloudstack.utils.security.ParserUtils;
@@ -222,6 +223,8 @@ public String toString() {
222223

223224
private final static String VM_NAME_ISO_SUFFIX = "-ISO";
224225

226+
private final static String VM_NAME_CONFIGDRIVE_ISO_SUFFIX = "-CONFIGDRIVE-ISO";
227+
225228
private final static String VM_FILE_ISO_SUFFIX = ".iso";
226229
public final static int DEFAULTDOMRSSHPORT = 3922;
227230

@@ -1020,12 +1023,13 @@ public ExecutionResult copyPatchFilesToVR(final String routerIp, final String pa
10201023
protected SR createIsoSRbyURI(final Connection conn, final URI uri, final String vmName, final boolean shared) {
10211024
try {
10221025
final Map<String, String> deviceConfig = new HashMap<String, String>();
1026+
final boolean isConfigDrive = uri.toString().endsWith(ConfigDrive.CONFIGDRIVEDIR);
10231027
String path = uri.getPath();
10241028
path = path.replace("//", "/");
10251029
deviceConfig.put("location", uri.getHost() + ":" + path);
10261030
final Host host = Host.getByUuid(conn, _host.getUuid());
10271031
final SR sr = SR.create(conn, host, deviceConfig, new Long(0), uri.getHost() + path, "iso", "iso", "iso", shared, new HashMap<String, String>());
1028-
sr.setNameLabel(conn, vmName + "-ISO");
1032+
sr.setNameLabel(conn, vmName + (isConfigDrive ? VM_NAME_CONFIGDRIVE_ISO_SUFFIX: VM_NAME_ISO_SUFFIX));
10291033
sr.setNameDescription(conn, deviceConfig.get("location"));
10301034

10311035
sr.scan(conn);
@@ -2648,9 +2652,10 @@ private String probeScisiId(Connection conn, Host host, Map<String, String> devi
26482652
return scsiid;
26492653
}
26502654

2651-
public SR getISOSRbyVmName(final Connection conn, final String vmName) {
2655+
public SR getISOSRbyVmName(final Connection conn, final String vmName, boolean isConfigDrive) {
26522656
try {
2653-
final Set<SR> srs = SR.getByNameLabel(conn, vmName + "-ISO");
2657+
final Set<SR> srs = SR.getByNameLabel(conn, vmName +
2658+
(isConfigDrive ? VM_NAME_CONFIGDRIVE_ISO_SUFFIX : VM_NAME_ISO_SUFFIX));
26542659
if (srs.size() == 0) {
26552660
return null;
26562661
} else if (srs.size() == 1) {
@@ -2697,9 +2702,20 @@ public VDI getIsoVDIByURL(final Connection conn, final String vmName, final Stri
26972702
} catch (final URISyntaxException e) {
26982703
throw new CloudRuntimeException("isoURL is wrong: " + isoURL);
26992704
}
2700-
isoSR = getISOSRbyVmName(conn, vmName);
2705+
isoSR = getISOSRbyVmName(conn, vmName, false);
27012706
if (isoSR == null) {
27022707
isoSR = createIsoSRbyURI(conn, uri, vmName, false);
2708+
} else {
2709+
try {
2710+
String description = isoSR.getNameDescription(conn);
2711+
if (description.endsWith(ConfigDrive.CONFIGDRIVEDIR)) {
2712+
throw new CloudRuntimeException(String.format("VM %s already has %s ISO attached. Please " +
2713+
"stop-start VM to allow attaching-detaching both ISOs", vmName, ConfigDrive.CONFIGDRIVEDIR));
2714+
}
2715+
} catch (XenAPIException | XmlRpcException e) {
2716+
throw new CloudRuntimeException(String.format("Unable to retrieve name description for the already " +
2717+
"attached ISO on VM %s", vmName));
2718+
}
27032719
}
27042720

27052721
final String isoName = isoURL.substring(index + 1);
@@ -5667,7 +5683,7 @@ public boolean attachConfigDriveToMigratedVm(Connection conn, String vmName, Str
56675683
s_logger.debug("Attaching config drive iso device for the VM " + vmName + " In host " + ipAddr);
56685684
Set<VM> vms = VM.getByNameLabel(conn, vmName);
56695685

5670-
SR sr = getSRByNameLabel(conn, vmName + VM_NAME_ISO_SUFFIX);
5686+
SR sr = getSRByNameLabel(conn, vmName + VM_NAME_CONFIGDRIVE_ISO_SUFFIX);
56715687
//Here you will find only two vdis with the <vmname>.iso.
56725688
//one is from source host and second from dest host
56735689
Set<VDI> vdis = VDI.getByNameLabel(conn, vmName + VM_FILE_ISO_SUFFIX);

plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/wrapper/xenbase/CitrixStopCommandWrapper.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,10 @@ public Answer execute(final StopCommand command, final CitrixResourceBase citrix
144144
networks.add(vif.getNetwork(conn));
145145
}
146146
vm.destroy(conn);
147-
final SR sr = citrixResourceBase.getISOSRbyVmName(conn, command.getVmName());
147+
final SR sr = citrixResourceBase.getISOSRbyVmName(conn, command.getVmName(), false);
148148
citrixResourceBase.removeSR(conn, sr);
149+
final SR configDriveSR = citrixResourceBase.getISOSRbyVmName(conn, command.getVmName(), true);
150+
citrixResourceBase.removeSR(conn, configDriveSR);
149151
// Disable any VLAN networks that aren't used
150152
// anymore
151153
for (final Network network : networks) {

0 commit comments

Comments
 (0)