1

How can I modify the xml definition of a VM over ssh? I know that I can do this interactively by logging into the host and using:

virsh edit <domain name>

But I want to automate this modification of xml using a script that runs on a remote host and then executes commands over ssh on the KVM box.

From what I have observed is that virsh edit is opening the default editor (vi in my case) for me to edit the file. I want to somehow overwrite this file (which is interactively opened by virsh edit command) with vm definition contained in another text file.

I have found threads on how text can be piped to vi using:

cat <file name> | vi -

But that wont work in my case since,

  1. virsh is opening up default editor with arguments that I have no control over. (or at least I don't know how to modify those arguments)
  2. The default editor could be different on different KVM boxes.

Thanks in advance for helping out.

Edit: Just wanted to make clear that I do not have an option to power off the VM and redefine it. I want to modify a running domain.

  • Even i'm working on similar thing. Did it work with virsh dumpxml & virsh define? Please let me know – varun_rapelly Feb 4 '16 at 5:26
4

Use virsh dumpxml to get the XML, and then virsh define to replace the domain definition with your modifications.

| improve this answer | |
  • Thanks Mike, I tried that but when I dump the xml definition again, I don't see the changes that I made before redefining the VM. – LinuxGuru-Wannabe Sep 28 '14 at 6:11
  • 1
    You didn't tell us you tried that! Tell us everything you did. – Michael Hampton Sep 28 '14 at 6:13
  • And remember that some changes take effect the next time you shut down the guest. – Michael Hampton Sep 28 '14 at 6:14
  • Oh, I just tried that after receiving your suggestion. – LinuxGuru-Wannabe Sep 28 '14 at 6:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.