vmngr / libvirt-old

Libvirt bindings for Node.js®
https://vmngr.com/
MIT License
11 stars 7 forks source link

Modify XML file #9

Closed mlibre closed 4 years ago

mlibre commented 4 years ago

Hey. Is there any way I can fetch a VM XML, modify it and save it there again. Like:

let domainXMLDes = await hypervisor.domainGetXMLDesc(domain);
// Some changes in domainXMLDes //
hypervisor.domainXMLModify(domain, domainXMLDes)
leonrinkel commented 4 years ago

Hi, I think you're looking for domainDefineXML(xml: string): Promise<Domain>. The xml does already contain the domains name, uuid, id etc. and libvirt should therefore not define a new domain but modify the existing one.

mlibre commented 4 years ago

Oh, that is cool. I will try. thanks.

mlibre commented 4 years ago

Unfortunately it does not work: (node:29223) UnhandledPromiseRejectionWarning: operation failed: domain 'ubuntu18.04' is already defined with uuid 703ecb98-536a-45dd-b101-bc460f587c62

leonrinkel commented 4 years ago

I’ve read this in the documentation for the define function: “A previous definition for this domain would be overridden if it already exists.” That’s basically what I mentioned earlier. It’s like doing virsh dumpxml and virsh define to edit the domain.

Are you trying to change the name of the domain?

According to http://rcritical.blogspot.com/2011/02/kvm-virtual-machine-renaming.html?m=1 the error you encountered, occurs when trying to change the domains name. It seems that changing the name requires to undefined the domain first and then define it using the new name.

mlibre commented 4 years ago

Oh. yes, I was trying to change the name. So is there any way to undefine the domain with your library?

libvirtadept commented 4 years ago

Currently no. I can implement it in next PR while @leonrinkel busy

mlibre commented 4 years ago

ok. thank you