Post

2 followers Follow
0
Avatar

VM hook

Hi there,

I'm working with VM_HOOK on vOneCloud 3.4.1.

I was reading from http://lists.ceph.com/pipermail/users-opennebula.org/2011-September/033915.html and I'm trying to get the same result :

The user john_doe (8) wants to deploy a VM with
VM ID  : 31
CPU    : 2
MEMORY : 1024
DISK   : IMAGE ID 15
         Ubuntu Server
         10G


Here is my work :

VM_HOOK = [
     name          = "on_creation_email",
     on              = "CUSTOM",
     state          =  "HOLD",
     lcm_state   =  "LCM_INIT",
     command   =  "vcenter/mail_notify.sh",
     arguments  = " ????? " ]---> I don't exactly know what to use here.

mail_notify.sh content :

#!/bin/bash
mail -s "New VM request" -r noreplay@mydomain.com mymail@mydomain.com << EOF
Dear Administrator

The user $user wants to deploy a VM with :
VM ID       : $ID
CPU         : $CPU
MEMORY : $MEM
DISK         : $DISK

EOF

How can I get the value of my variable from vonecloud ?

Thank you for your help.
Regards

Yacine FETOUH

Please sign in to leave a comment.

4 comments

0
Avatar

Hello, we are happy to help you.

First of all, we recommend that you consult this link within the OpenNebula documentation.

http://docs.opennebula.org/5.8/integration/infrastructure_integration/hooks.html#developing-your-hooks

This explains how you can create your own hooks and get the value of the variables passed to the script.

And about the arguments, these are the arguments that are passed to the script you want to execute. And in the previously shared link you can see how to use them.

Please, any questions just let us know.

Carlos J. Herrera Matos 0 votes
Comment actions Permalink
0
Avatar

Hi !

Thank you for your replay.

I was able to get the username and the id using this syntax:
xpath=/var/lib/one/remotes/datastore/xpath.rb
user_name=`$xpath -b $t64 UNAME`
vm_id=`$xpath -b $t64 ID`

According to doc UNAME and ID are a pre-defined variables.

How can à get the name of non pre-defined vars ? I've tried this but not working

vm_name=`$xpath -b $t64 VMNAME`
cpu=`$xpath -b $t64 CPU`
mem=`$xpath -b $t64 MEMORY`

Yacine FETOUH 0 votes
Comment actions Permalink
0
Avatar

Hi there,
vm_name=`$xpath -b $t64 NAME` works well to get vm name.

still can't have vcpu and memory with :

`$xpath -b $t64 VCPU`
`$xpath -b $t64 MEMORY`

Yacine FETOUH 0 votes
Comment actions Permalink
0
Avatar

Please note that VCPU and MEMORY are not at the same level that NAME

You must enter to TEMPLATE and then get VCPU and MEMORY for that you can use slash "/". See example bellow.

MEMORY=`$XPATH -b $T64 TEMPLATE/MEMORY`
VCPU=`$XPATH -b $T64 TEMPLATE/VCPU`
Carlos J. Herrera Matos 0 votes
Comment actions Permalink