Feature #4805

Condition for exec hooks BEFORE or AFTER certain state

Added by kvaps kvaps about 4 years ago. Updated over 3 years ago.

Status:ClosedStart date:09/20/2016
Priority:NormalDue date:
Assignee:-% Done:

0%

Category:-
Target version:-
Resolution:worksforme Pull request:

Description

In continuation of the discussion:
https://forum.opennebula.org/t/how-to-exec-hook-before-suspend-state/2938/6

It seems to me that it would be right to enhance the hook system:
Add additional parameter into hook system: BEFORE and AFTER state. Example I want do like in config:

VM_HOOK = [
name = "my_hook",
on = "CUSTOM",
state = "ACTIVE",
lcm_state = "SAVE_SUSPEND",
condition = "BEFORE"
command = "my_hook.sh",
arguments = "$ID $TEMPLATE" ]

And hook will be executed before suspend state, only after this status of vm will change.
In case AFTER condition, the hook will be executed at once after the change of status, regardless of what status will be after.

This can be implemented as optional feature:
You may set the condition option, and hooks will be executed before or after changing state of vm.
Or not set the condition option, in this case, and hooks will be executed as is.

Thanks! :slight_smile:

History

#1 Updated by Ruben S. Montero about 4 years ago

  • Status changed from Pending to Closed
  • Resolution set to worksforme

This is actually implemented with the PREV_LCM_STATE and PREV_STATE, If want to execute the hook just after the SAVE_SUSPEND succeeded. Just look for the final state or states you are looking for. For example

VM_HOOK = [
state = "SUSPENDED",
areguments = "$PREV_LCM_STATE",
...
]

Then in your hook exists if we are not coming after a SAVE_SUSPEND


#6 = 
if [ "$1" != "SAVE_SUSPEND" ] ; then
  exit 0
fi

... 

#2 Updated by Ruben S. Montero about 4 years ago

In any case, if this is not a solution we'll reopen it to address the requirements

#3 Updated by kvaps kvaps over 3 years ago

I think we need to enhance opennebula's hook system by adding non-asynchronic hook's too.

You leave no choice except changing default vmm scripts.
In my opinion this is wrong. What if I needed to run some actions before vm will be touched? Before deploy or before suspend...
For to do this at now I need to add this code directly into the vmm script.
This is really wrong, because vmm script will be overridden after update, and I need to track any changes on it.
You do not even consider the possibility of the creation of a vmm script bound to a specific tm driver. (see #5081)

Non-asynchronic hook system would solve all these problems.

In addition I'm convinced that it's quite easy to implement, it is just needed to have check for these hooks before and after every action.

If someone thinks so, please type about it.

I hope for your understanding, thanks!
Opennebula has always been famous for its flexibility.

Also available in: Atom PDF