Adding an Image to template during a CREATE Hook

(Greg Brown) #1

I have a CREATE VM hook that gets the template data and based on User templates and VM template it creates an DATABLOCK image, and uploads it to Opennebula. I have the VM ID and IMAGE ID (In ready state), and I want to add it to the VM before it boots.
I have tried:

onevm disk-attach "$VMID" --image "$IMAGEID"

and get

[VirtualMachineAttach] VM is not running in any host

Any suggestions?

(Jaime Melis) #2

hooks are asynchronous, you cannot guarantee that the datastore will be created before that. However I think you can accomplish what you want by using a VOLATILE disk.

(Greg Brown) #3

Thanks Jaime, I got this working, my next question is, is there a way to get the total number of nic cards attached to a VM using Hooks? Someting like:


Doesn’t working

Any thoughts, thanks

(Anton Todorov) #4

Hello Greg,

I think this is what you are looking for:

[oneadmin]$ onevm show 34 -x | /var/lib/one/remotes/datastore/xpath.rb -s %m%TEMPLATE/NIC/MAC
02:00:0a:02:08:80 02:00:0a:c7:c7:01

Then count the returned elements…

Kind Regards,
Anton Todorov