|
62 | 62 | import org.apache.cloudstack.hypervisor.xenserver.ExtraConfigurationUtility; |
63 | 63 | import org.apache.cloudstack.storage.command.browser.ListDataStoreObjectsAnswer; |
64 | 64 | import org.apache.cloudstack.storage.command.browser.ListDataStoreObjectsCommand; |
| 65 | +import org.apache.cloudstack.storage.configdrive.ConfigDrive; |
65 | 66 | import org.apache.cloudstack.storage.to.TemplateObjectTO; |
66 | 67 | import org.apache.cloudstack.storage.to.VolumeObjectTO; |
67 | 68 | import org.apache.cloudstack.utils.security.ParserUtils; |
@@ -222,6 +223,8 @@ public String toString() { |
222 | 223 |
|
223 | 224 | private final static String VM_NAME_ISO_SUFFIX = "-ISO"; |
224 | 225 |
|
| 226 | + private final static String VM_NAME_CONFIGDRIVE_ISO_SUFFIX = "-CONFIGDRIVE-ISO"; |
| 227 | + |
225 | 228 | private final static String VM_FILE_ISO_SUFFIX = ".iso"; |
226 | 229 | public final static int DEFAULTDOMRSSHPORT = 3922; |
227 | 230 |
|
@@ -1020,12 +1023,13 @@ public ExecutionResult copyPatchFilesToVR(final String routerIp, final String pa |
1020 | 1023 | protected SR createIsoSRbyURI(final Connection conn, final URI uri, final String vmName, final boolean shared) { |
1021 | 1024 | try { |
1022 | 1025 | final Map<String, String> deviceConfig = new HashMap<String, String>(); |
| 1026 | + final boolean isConfigDrive = uri.toString().endsWith(ConfigDrive.CONFIGDRIVEDIR); |
1023 | 1027 | String path = uri.getPath(); |
1024 | 1028 | path = path.replace("//", "/"); |
1025 | 1029 | deviceConfig.put("location", uri.getHost() + ":" + path); |
1026 | 1030 | final Host host = Host.getByUuid(conn, _host.getUuid()); |
1027 | 1031 | 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)); |
1029 | 1033 | sr.setNameDescription(conn, deviceConfig.get("location")); |
1030 | 1034 |
|
1031 | 1035 | sr.scan(conn); |
@@ -2648,9 +2652,10 @@ private String probeScisiId(Connection conn, Host host, Map<String, String> devi |
2648 | 2652 | return scsiid; |
2649 | 2653 | } |
2650 | 2654 |
|
2651 | | - public SR getISOSRbyVmName(final Connection conn, final String vmName) { |
| 2655 | + public SR getISOSRbyVmName(final Connection conn, final String vmName, boolean isConfigDrive) { |
2652 | 2656 | 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)); |
2654 | 2659 | if (srs.size() == 0) { |
2655 | 2660 | return null; |
2656 | 2661 | } else if (srs.size() == 1) { |
@@ -2697,9 +2702,20 @@ public VDI getIsoVDIByURL(final Connection conn, final String vmName, final Stri |
2697 | 2702 | } catch (final URISyntaxException e) { |
2698 | 2703 | throw new CloudRuntimeException("isoURL is wrong: " + isoURL); |
2699 | 2704 | } |
2700 | | - isoSR = getISOSRbyVmName(conn, vmName); |
| 2705 | + isoSR = getISOSRbyVmName(conn, vmName, false); |
2701 | 2706 | if (isoSR == null) { |
2702 | 2707 | 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 | + } |
2703 | 2719 | } |
2704 | 2720 |
|
2705 | 2721 | final String isoName = isoURL.substring(index + 1); |
@@ -5667,7 +5683,7 @@ public boolean attachConfigDriveToMigratedVm(Connection conn, String vmName, Str |
5667 | 5683 | s_logger.debug("Attaching config drive iso device for the VM " + vmName + " In host " + ipAddr); |
5668 | 5684 | Set<VM> vms = VM.getByNameLabel(conn, vmName); |
5669 | 5685 |
|
5670 | | - SR sr = getSRByNameLabel(conn, vmName + VM_NAME_ISO_SUFFIX); |
| 5686 | + SR sr = getSRByNameLabel(conn, vmName + VM_NAME_CONFIGDRIVE_ISO_SUFFIX); |
5671 | 5687 | //Here you will find only two vdis with the <vmname>.iso. |
5672 | 5688 | //one is from source host and second from dest host |
5673 | 5689 | Set<VDI> vdis = VDI.getByNameLabel(conn, vmName + VM_FILE_ISO_SUFFIX); |
|
0 commit comments