Softaculous


Topic : Pass QEMU command line arguments in plans/new virtual servers


Posted By: m9shyamalan on July 25, 2019, 11:36 pm
Hi Guys,

I have recently run into a situation where for some of our VM's require us to pass QEMU command line arguments to get functionality from our Virtual Servers that aren't achievable from the Virtualizor interface. To do this we are using 'virsh edit', but the issue is that these changes:

a) Can't be applied until after the Virtual Server has already been created
b) Have to be done manually for each Virtual Server, with no API support
c) Are reverted if the Virtualizor Interface/API is ever used to edit the Virtual Server

Currently our edits are just the following:
Change the top line of the XML from

PHP Code

 <domain type='kvm' id='2'


to
PHP Code

 <domain type='kvm' id='2' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'


After </devices> in the xml, we are adding the following section:
PHP Code

 <qemu:commandline>
    <
command line arguements/>
  </
qemu:commandline



Would it be possible for plans and new virtual server pages to have a tickbox for QEMU Command Line Arguments, which would unhide a free text box to add these command line options to, or even a standard KVM template to which we could add these changes?

Alternatively, if someone can suggest an existing method to add QEMU command line arguments automatically to new Virtual Servers/Plans, I would love to hear it!

Thanks

Posted By: jevingala on July 26, 2019, 3:03 pm | Post: 1
Hi,

You can try using hooks to write custom config in vps config file :

https://www.virtualizor.com/docs/developers/hooks/#after_config_write

-----------------------
Regards,
Virtualizor Team.
http://virtualizor.com/

Posted By: m9shyamalan on July 29, 2019, 6:44 am | Post: 2
Quote From : jevingala July 26, 2019, 3:03 pm
Hi,

You can try using hooks to write custom config in vps config file :

https://www.virtualizor.com/docs/developers/hooks/#after_config_write


Exactly what I was looking for! Thanks, I will give it a shot and report back.

Posted By: m9shyamalan on August 2, 2019, 1:39 am | Post: 3
Quote From : jevingala July 26, 2019, 3:03 pm
Hi,

You can try using hooks to write custom config in vps config file :

https://www.virtualizor.com/docs/developers/hooks/#after_config_write


Hi Jev,

Do you know if these hooks output logs anywhere? I Couldn't find any information in the documentation, and I'm trying to troubleshoot an error.

I am seeing  "There was an error in editing the VPS" when the after_config_write.php hook is in place. The VM is being edited as per the changes on the GUI, but the hook is not running.

I am able to manually run the function from the command line, which is running as expected, so I am hoping to find the output Virtualizor is seeing to track down the problem.

Thanks

Posted By: chirag on August 2, 2019, 9:04 am | Post: 4
Hi,

Sir can you send us the hook file ?
So that we can check on our server ?

-----------------------
Virtualizor - VPS Control Panel
Follow us on Facebook

Posted By: m9shyamalan on August 14, 2019, 6:45 am | Post: 5
Hey Guys,

This issue is now resolved, just wanted to post back so if anyone else has this issue.

I read the document linked by jevingala:
https://www.virtualizor.com/docs/developers/hooks/#after_config_write

and built off the example function, but was getting an error message every time I edited a VM. My mistake was not correctly adding the PHP codes at the start and end of the document, and following the documentation blindly.

FYI my complete script looks like this:
PHP Code

<?php
function __after_config_write($vps){
$path '/etc/libvirt/qemu/'.$vps['vps_name'].'.xml';
$xml file_get_contents($path);
$schema str_replace("<domain type='kvm'>""<domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>"$xml);
file_put_contents($path$schema);
$xml file_get_contents($path);
$cpu str_replace("</devices>""</devices>n    <qemu:commandline>n        insert your arguments heren    </qemu:commandline>"$xml);
file_put_contents($path$cpu);
}
?>



Hope this helps anyone else having issues

Posted By: chirag on August 14, 2019, 7:19 am | Post: 6
Hi,

Sir glad to know that your issue is resolved.
Let us know for further information.
We will be happy to help you.

-----------------------
Virtualizor - VPS Control Panel
Follow us on Facebook

Powered By AEF 1.0.8 © 2007-2008 Electron Inc.