Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Adding hook support #456

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

[WIP] Adding hook support #456

wants to merge 1 commit into from

Conversation

gbenhaim
Copy link
Member

  1. The hooks are defined in the init file and
    can be any type of script (shell, python...).

  2. The hooks will be run on the host which runs Lago.

  3. Hooks will be only supported for functions that were
    decorated with "hooks.with_hooks" (for now just start / stop)

Signed-off-by: gbenhaim [email protected]

Copy link

@mykaul mykaul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the use case for the hooks? It was not mentioned in the commit message.

lago/hooks.py Outdated
@@ -0,0 +1,254 @@
# coding=utf-8
import functools
import os
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we care about import order, alphabetically or something?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will fix.

hooks = Hooks(prefix.paths.hooks())
hooks.run_pre_hooks(cmd)
result = func(*args, **kwargs)
hooks.run_post_hooks(cmd)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hooks run regardless of the result, and are not aware of the result. Perhaps worth passing it to them?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Post hook won't run if 'func' throws an exception, do we want to change this behavior ?
  2. When passing 'result' to the post hook I need to assume that it is a string, or can be evaluated to a meaningful string, I'm not sure that I can take this assumption.

try:
with utils.DirLockWithTimeout(cmd_dir):
self._run_hooks(
sorted([path.join(hook_dir, hook) for hook in hooks])
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hooks are running alphabetically?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to preserve the order in which the hooks were mentioned in the init file, but now I realize that I didn't prefix them with an index. will fix.

@nvgoldin
Copy link
Contributor

  1. I think the hooks should be at the VM level.
  2. I think the hooks should be separated to different types:
  • VM hooks - executed by Lago itself on the VM(by using SSH), similarly to 'deploy', and as result, possible only at post-start, pre-stop, etc.
  • Host hooks - executed on the host. For those I'm not 100% sure they are really needed, as this can just be wrapped in a bash command instead. It feels weird IMO that lago takes 'general' control of the host without direct relation to what it manages. Though I can understand the freedom it gives.
  1. With 1 and 2, adding support for 'global' hooks, which are ran once per lago command, shouldn't be difficult.

@nvgoldin
Copy link
Contributor

Some possible use-cases of VM hooks:

  1. Pre-stop: Generate SOS report before VM shut-down, dump postgresql db when running 'lago stop', etc.
  2. Post-start: Install a service and assert it is running.

Some possible use-cases of Host hooks:

  1. OST Pre-host-stop: Run API calls on the engine before stopping the VM.
  2. OST Pre-host-stop: shut-down storage properly.

1. The hooks are defined in the init file and
   can be any type of script (shell, python...).

2. The hooks will be run on the host which runs Lago.

3. Hooks will be only supported for functions that were
   decorated with "hooks.with_hooks" (for now just start / stop)

Signed-off-by: gbenhaim <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants