Hello.
How can get variables from a xml template in a hook?
I have the hook:
ARGUMENTS = "$TEMPLATE"
ARGUMENTS_STDIN = yes
COMMAND = "test/test.sh"
NAME = "test"
ON = "CUSTOM"
STATE = "ACTIVE"
LCM_STATE = "RUNNING"
REMOTE = "no"
RESOURCE = VM
TYPE = state
And i need get ETH0_IP and NAME from xml.
How correctly do it?
And the file /tmp/template-test.txt contains a full template)
But the script doesn’t work correctly and i get the error:
base64: invalid input
/var/lib/one/remotes/datastore/xpath.rb:70:in `block in <main>': undefined method `elements' for nil:NilClass (NoMethodError)
from /var/lib/one/remotes/datastore/xpath.rb:64:in `each'
from /var/lib/one/remotes/datastore/xpath.rb:64:in `<main>'
# Be sure input is base64 encoded
echo "$1" > /tmp/first-arg.txt
# First argument is a filename, so read standard input
TEMPLATE=$(echo -n $1 | base64 -d)
echo "$TEMPLATE" > /tmp/template-test.txt
In your case, if the stdin stream is base64 encoded, you need to just read it with cat and use xpath.rb to do the decode to raw XML the following sample should work
XPATH="/var/lib/one/remotes/datastore/xpath.rb --stdin"
TEMPLATE="$(cat)"
unset i j XPATH_ELEMENTS
while IFS= read -r -d '' element; do
XPATH_ELEMENTS[i++]="$element"
done < <($XPATH -b $TEMPLATE '/VM/ID')
VM_ID="${XPATH_ELEMENTS[j++]}"
Hello @atodorov_storpool@ahuertas@amarti
I am facing some issues with API Hook for VM actions.
Can we create hook on adding actions to VM? like I want to run script as soon as I have added action on VM such as poweroff or terminate.
I am using below hook tmpl but not working.
NAME = hook-API
TYPE = api
COMMAND = “log_new_action.rb”
ARGUMENTS = $API
CALL = “one.user.action”
ARGUMENTS_STDIN = yes