Per instance contexts

Hello,

I’ve been toying with 4.14b1 for a couple of days now and it looks really nice and simple, but I have one question (for now), how can I contextualize various stuff per instance?

I’d like for example to set a ROOT_PASSWORD that the VM can use and apply at creation and so on.

Thanks!

Hi,

You’re looking for something like this:

There’s also the opennebula-context package, you might want to install on your OS disks

I haven’t tried any of them, as I am using my own scripts.
Assuming your template template defines some USERPASS, and maybe some USERNAME (my script sets it to ‘root’ if empty), then you may use something like this:

. /mnt/context.sh [...] if test "$USERPASS"; then echo "$USERNAME:$USERPASS" | chpasswd fi if test "$SSH_PUBLIC_KEY"; then mkdir -p $HOMEDIR/.ssh echo "$SSH_PUBLIC_KEY oneadmin@nebula" >>$HOMEDIR/.ssh/authorized_keys chown -R $USERNAME:$USERNAME $HOMEDIR/.ssh find $HOMEDIR/.ssh -type f -exec chmod 0600 {} \; find $HOMEDIR/.ssh -type d -exec chmod 0700 {} \; if test "$USERNAME" = root; then ssh-keygen -t dsa -N '' -f id_dsa else su -l $USERNAME -c "ssh-keygen -t dsa -N '' -f id_dsa" fi fi

An other snippet that would help you finding your CONTEXT disk:

[code]try_disk()
{
local isdone
isdone=false
test “$1” || return 2
if mount -t iso9660 /dev/$1 /mnt >/dev/null 2>&1; then
if test -s /mnt/context.sh; then
$$your_cloud_init_function_name_here$$
isdone=true
fi
umount /mnt
if $isdone; then
return 0
fi
fi

return 1

}

nebula_generic_cloud_init()
{
if test -L /dev/disk/by-label/CONTEXT; then
try_disk disk/by-label/CONTEXT
else
for dev in awk '{print $3}' /proc/diskstats
do
echo $dev | grep loop >/dev/null && continue
try_disk $dev && break
done
fi
if test -L /dev/disk/by-label/swap; then
swapon -L swap
fi
}
[/code]

Then, some ugly way to do it would be do patch your /etc/rc.local with the following:

if test -e /oneboot; then . /usr/lib/nebula/context-init nebula_generic_cloud_init rm -f /oneboot fi

Thanks Samuel, what I am after is a way to sey a root password per instance.
i know the template allows me to set $ROOT_PASSWORD=XYZ, but I need “XYZ” to be something I am setting per VM/instance, so each machine has its own individual and unique password etc.

I don’t see any feature like the above, at least not in the UI or docs.

Lucian

Hi,

You can set a different password each time the template is instantiated with the template user inputs:
http://docs.opennebula.org/4.12/user/virtual_resource_management/vm_guide.html#ask-for-user-inputs

Holy cow, those input+context things can potentially be very powerful, thanks for letting me know.