moke Posted February 7, 2021 Share Posted February 7, 2021 Does Unraid have any plugin or functionality to create and configure VM programatically? I need to create system where virtual machines are created on demand . Quote Link to comment
JonathanM Posted February 7, 2021 Share Posted February 7, 2021 Not that I'm aware of. You could look at some of spaceinvader one's recent work, he is doing something along the same idea. Quote Link to comment
SimonF Posted February 11, 2021 Share Posted February 11, 2021 (edited) On 2/7/2021 at 9:58 PM, moke said: Does Unraid have any plugin or functionality to create and configure VM programatically? I need to create system where virtual machines are created on demand . You can create an XML and pass that into virsh to create VMs and destroy them. https://libvirt.org/manpages/virsh.html Edited February 11, 2021 by SimonF Quote Link to comment
SimonF Posted February 12, 2021 Share Posted February 12, 2021 function virsh_device_by_bus($action, $vmname, $usbbus, $usbdev) { $usbstr = ''; if (!empty($usbbus)) { $usbbus=ltrim($usbbus, "0"); $usbdev=ltrim($usbdev, "0") ; $usbstr .= "<hostdev mode='subsystem' type='usb'> <source> <address bus='${usbbus}' device='${usbdev}' /> </source> </hostdev>"; } $filename = '/tmp/libvirthotplugusbbybus'.$vmname.'.xml'; file_put_contents($filename,$usbstr); return shell_exec("/usr/sbin/virsh $action-device '$vmname' '".$filename."' 2>&1"); #echo "Running virsh ${COMMAND} ${DOMAIN} for USB bus=${BUSNUM} device=${DEVNUM}:" >&2 #virsh "${COMMAND}" "${DOMAIN}" /dev/stdin <<END #<hostdev mode='subsystem' type='usb'> # <source> # <address bus='${BUSNUM}' device='${DEVNUM}' /> # </source> #</hostdev> #END } Here is some PHP code that I use for hotplugging USB devices into a VM. 2 Quote Link to comment
moke Posted February 12, 2021 Author Share Posted February 12, 2021 5 hours ago, SimonF said: ...... Here is some PHP code that I use for hotplugging USB devices into a VM. Thanks a lot. That gives me the start I need. Does Unraid detect these virsh created machines and show them in server UI? Quote Link to comment
SimonF Posted February 12, 2021 Share Posted February 12, 2021 I believe they should, but can't safe 100% for sure as not tested it myself. Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.