Last active
November 22, 2018 12:25
-
-
Save mpdehaan/87d0ea05ed11a9b723d555a566d27ee3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# I don't know about this? | |
# most people should prefer the Python DSL | |
# but what if some teams don't want to learn Python? | |
# here's an OPTIONAL idea for a new capability | |
# ================== | |
class FooRole(Foo): | |
def set_bundles(self): | |
return [ "ext/foo.yml" ] | |
def set_resources(self): | |
# you can still add resources the normal way, they will come before before bundle | |
def set_handlers(self): | |
# same | |
============= | |
# ext/foo.yml | |
search_path: | |
- opsmop.core.types | |
resources: | |
- Set: | |
mode: 0770 | |
x: 4567 | |
- File: | |
name: "/etc/motd" | |
from_template: "templates/motd.j2" | |
mode__eval: "mode" # just to show we can load variables, but we still need to be explicit. | |
signals: "spork" | |
- Echo: | |
msg: "hello {{ x }}, sometimes" | |
when__eval: "Chaos.random() > 2.5" | |
handlers: | |
- Echo: | |
msg: "foo" | |
handles: "spork" | |
========= | |
if I do this, this would clearly be a second class citizen to the main behaviors | |
limitations: when always results in an Eval() | |
if you want any variables you need to Eval() | |
implementation: reads YAML file, dynamically returns resources from it. | |
you could still mix bundle files with regular python resources, even in the same role. | |
A good TOML alternative idea from the Forum thread - https://talk.vespene.io/t/are-there-some-folks-that-do-think-yaml-might-be-useful-as-an-option/73/11?u=mpdehaan - this is currently winning in my mind at the moment.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
an example use case for this might be if we wanted to have a file with a lot of User definitions in it and load those from a file rather than keep them in the .py - this file would be easier for anyone on the team to edit without neccessarily making sure they didn't make a syntax error
we could also implement this with a Bundle() type object:
We could do this in other ways:
def set_resources(self):
return Resources(
Bundle("files/bundle.yml", section="resources"),
)
And that would allow intermixing with resources however.
Another idea might be to make it only work for one type of resource, actually being a Collection object in OpsMop:
def set_resources(self):
return Resources(
Bundle(type=User, file="files/bundle.yml")
)
And that could get all the parameters but make it impossible to mix types in the same file.