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

Example for targeting policy based on guest name? #26

Open
inflatador opened this issue Sep 3, 2024 · 0 comments
Open

Example for targeting policy based on guest name? #26

inflatador opened this issue Sep 3, 2024 · 0 comments

Comments

@inflatador
Copy link
Contributor

inflatador commented Sep 3, 2024

MoM's policy DSL is extremely powerful, but I've been struggling with how to apply it as the documentation is pretty minimal.

I've been trying to write a policy that is selectively applied based on hostname. I've written a helper function (see below), but I can't figure out how to apply it.

# Kubernetes and nomad are orchestrators, so we don't want to apply the balloon policy to them.
# Set "1" (true) if the host is an orchestrator
(def is_orchestrator (guest)
{ (defvar guest_name (guest.Prop "name"))
    (defvar is_orchestrator 0)
    (if (or (== guest_name "kubernetes.example.com")
        (== guest_name "nomad.example.com"))
        (set is_orchestrator 1)
        is_orchestrator)
}
)

Debug logging shows the value is correctly set. The below result [1, 1, 0, 0] shows that the code finds the 4 guests on the host and correctly sets the is_orchestator value (1 for kubernetes/nomad, 0 for the other hosts):

2024-09-02 17:49:22,183 - mom.Policy - DEBUG - Results: [0.25, 0.1, 0.2, 0.75, 0.01,
'is_orchestrator', 'change_big_enough', 'shrink_guest', 'grow_guest', [1, 1, 0, 0], 0
.2393567666022347, [0, 0, 0, 0]]

I'm stuck at the next step; I can't seem to apply the policy conditionally. Various permutations of if statements/parenthesis end up with arity errors or empty results.

Any suggestions on how to write the policy would be appreciated. I'm happy to make a PR for updating the docs once I have a working example. Thanks for your time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant