diff --git a/src/components/vm/disks/diskAdd.jsx b/src/components/vm/disks/diskAdd.jsx index 3ec8480be..ff16fbea8 100644 --- a/src/components/vm/disks/diskAdd.jsx +++ b/src/components/vm/disks/diskAdd.jsx @@ -509,7 +509,6 @@ export class AddDiskModalBody extends React.Component { permanent: this.state.permanent, hotplug: this.state.hotplug, vmName: vm.name, - vmId: vm.id, cacheMode: this.state.cacheMode, busType: this.state.busType }) @@ -540,7 +539,6 @@ export class AddDiskModalBody extends React.Component { permanent: this.state.permanent, hotplug: this.state.hotplug, vmName: vm.name, - vmId: vm.id, cacheMode: this.state.cacheMode, shareable: volume && volume.format === "raw" && isVolumeUsed[this.state.existingVolumeName], busType: this.state.busType diff --git a/src/libvirt-xml-create.js b/src/libvirt-xml-create.js index ae67e4520..526939c4e 100644 --- a/src/libvirt-xml-create.js +++ b/src/libvirt-xml-create.js @@ -1,41 +1,3 @@ -export function getDiskXML(type, file, device, poolName, volumeName, format, target, cacheMode, shareable, busType) { - const doc = document.implementation.createDocument('', '', null); - - const diskElem = doc.createElement('disk'); - diskElem.setAttribute('type', type); - diskElem.setAttribute('device', device); - - const driverElem = doc.createElement('driver'); - driverElem.setAttribute('name', 'qemu'); - if (format && ['qcow2', 'raw'].includes(format)) - driverElem.setAttribute('type', format); - driverElem.setAttribute('cache', cacheMode); - diskElem.appendChild(driverElem); - - const sourceElem = doc.createElement('source'); - if (type === 'file') { - sourceElem.setAttribute('file', file); - } else { - sourceElem.setAttribute('volume', volumeName); - sourceElem.setAttribute('pool', poolName); - } - diskElem.appendChild(sourceElem); - - const targetElem = doc.createElement('target'); - targetElem.setAttribute('dev', target); - targetElem.setAttribute('bus', busType); - diskElem.appendChild(targetElem); - - if (shareable) { - const shareableElem = doc.createElement('shareable'); - diskElem.appendChild(shareableElem); - } - - doc.appendChild(diskElem); - - return new XMLSerializer().serializeToString(doc.documentElement); -} - export function getIfaceXML(sourceType, source, model, mac) { const doc = document.implementation.createDocument('', '', null); diff --git a/src/libvirtApi/domain.js b/src/libvirtApi/domain.js index 8bd65c7bf..afc81b055 100644 --- a/src/libvirtApi/domain.js +++ b/src/libvirtApi/domain.js @@ -39,7 +39,6 @@ import { updateVm, } from '../actions/store-actions.js'; import { - getDiskXML, getMemoryBackingXML, } from '../libvirt-xml-create.js'; import { @@ -96,17 +95,6 @@ function buildConsoleVVFile(consoleDetail) { 'fullscreen=0\n'; } -function domainAttachDevice({ connectionName, vmId, permanent, hotplug, xmlDesc }) { - let flags = Enum.VIR_DOMAIN_AFFECT_CURRENT; - if (hotplug) - flags |= Enum.VIR_DOMAIN_AFFECT_LIVE; - if (permanent) - flags |= Enum.VIR_DOMAIN_AFFECT_CONFIG; - - // Error handling is done from the calling side - return call(connectionName, vmId, 'org.libvirt.Domain', 'AttachDevice', [xmlDesc, flags], { timeout, type: 'su' }); -} - export function getPythonPath() { return cockpit.spawn(["/bin/sh", "-c", "which /usr/libexec/platform-python 2>/dev/null || which python3 2>/dev/null || which python"]).then(pyexe => { pythonPath = pyexe.trim() }); } @@ -120,7 +108,6 @@ export function domainAttachDisk({ volumeName, format, target, - vmId, vmName, permanent, hotplug, @@ -128,9 +115,29 @@ export function domainAttachDisk({ shareable, busType, }) { - const xmlDesc = getDiskXML(type, file, device, poolName, volumeName, format, target, cacheMode, shareable, busType); + const options = { err: "message" }; + if (connectionName === "system") + options.superuser = "try"; + let update = ""; + if (hotplug) + update = "--update"; + let define = "--define"; + if (hotplug && !permanent) + define = "--no-define"; + let source = ""; + if (type === 'file') + source = `,source.file=${file}`; + else + source = `,source.pool=${poolName},source.volume=${volumeName}`; + let driverType = ""; + if (format && ['qcow2', 'raw'].includes(format)) + driverType = `,driver.type=${format}`; + const shareableOption = shareable ? "yes" : "no"; - return domainAttachDevice({ connectionName, vmId, permanent, hotplug, xmlDesc }); + return cockpit.script( + `virt-xml -c qemu:///${connectionName} ${vmName} --add-device --disk type=${type},shareable=${shareableOption},target.bus=${busType},target.dev=${target},driver.name=qemu,cache=${cacheMode},device=${device}${source}${driverType} ${define} ${update}`, + options + ); } export function domainAttachIface({ connectionName, vmName, mac, permanent, hotplug, sourceType, source, model }) { diff --git a/src/libvirtApi/storageVolume.js b/src/libvirtApi/storageVolume.js index 8ac8ba7ec..ac8faeb29 100644 --- a/src/libvirtApi/storageVolume.js +++ b/src/libvirtApi/storageVolume.js @@ -46,7 +46,6 @@ export function storageVolumeCreateAndAttach({ size, format, target, - vmId, vmName, permanent, hotplug, @@ -63,7 +62,7 @@ export function storageVolumeCreateAndAttach({ }); }) .then((volPath) => { - return domainAttachDisk({ connectionName, type: "volume", device: "disk", poolName, volumeName, format, target, vmId, permanent, hotplug, cacheMode, busType }); + return domainAttachDisk({ connectionName, type: "volume", device: "disk", poolName, volumeName, format, target, vmName, permanent, hotplug, cacheMode, busType }); }); }