How to upload an image file from CLI?

Hello!

I am trying to adapt a script (which I initially made for OpenStack)
to download official cloud images for various OSes, upload them to the
local ONE cloud, starting a VM and apply some customizations and then
save back the snapshot as image.

Unfortunately, I’m stuck a the beginning of the process: the
oneimage script, when passed a simple file name in the PATH=...
part of the template, seems to assume that the path is to be located
on the server’s filesystem. Searching around, I have found this
oneimage-upload
script, which uses the trick of starting a local webserver on the
client and pointing SOURCE=... back to it; unfortunately this trick
(or almost anything using SOURCE=...) will not work in my local
setup, as the server is behind strict firewall rules which cannot be
lifted.

Is there any way of uploading VM disk images to ONE from a command
line or a scripting API?

Thanks for any suggestion!

Riccardo

Yes. From the command line you can find an example here.

You can also use the API. There are several APIs in OpenNebula, here you can find an example using the XML-RPC API.

Hello @svega thank you very much for your reply!

Unfortunately, oneimage create does not seem to perform any upload here:

 $ cat centos-7.img.tmpl
NAME="CentOS 7 [upstream, 2019-12-13, md5sum:160aa274e7a69f2edb50e2d89f54270b]"
PATH="CentOS-7-x86_64-GenericCloud.qcow2"
SIZE="899"
DESCRIPTION="Official cloud image for CentOS 7"
TYPE="OS"
DRIVER="qcow2"
MD5="160aa274e7a69f2edb50e2d89f54270b"

 $ ls -lh CentOS-7-x86_64-GenericCloud.qcow2
-rw-rw-r-- 1 rmurri rmurri 899M dic  9 10:36 CentOS-7-x86_64-GenericCloud.qcow2

 $ oneimage create -d 100 centos-7.img.tmpl --path CentOS-7-x86_64-GenericCloud.qcow2
[one.image.allocate] Cannot parse image SIZE: File not found

I tried various combinations of PATH= and SOURCE= and my reading of the above error message is that the ONE server interprets PATH as a local file, i.e., I should somehow upload the qcow2 file to the server and then register it with oneimage create. The same happens with the XML-RPC call you linked; I presume oneimage create is just a wrapper around it.

However, uploading seems to be possible from the web interface so I guess there must be some other way that I am missing?

Thanks,
Riccardo

Perhaps the problem is that the image you are trying to upload is not on a safe dir. By default:

SAFE_DIRS="/var/tmp"

So just try copying your image inside /var/tmp and see if that does the trick. You can also update the SAFE_DIR variable.

Thank you again @svega, unfortunately adding SAFE_DIRS=... to the image template didn’t change much.

Maybe I should specify that I am trying to do the image upload from my laptop as a regular user – I do not have access to the ONE server or its filesystem, which looks to me the root of the problem. I see in the Managing Images section of the documentation that uploads are possible through the web interface (by storing them as temporary files on the server); I hoped the same functionality was exposed through the command-line clients.

Thanks,
Riccardo