Get the updater zapping nicely

This commit is contained in:
Reid 'arrdem' McKenzie 2021-08-12 14:28:57 -06:00
parent f04740bde5
commit 767574cb44
3 changed files with 12 additions and 8 deletions

View file

@ -4,7 +4,7 @@ py_library(
name = "gandi", name = "gandi",
srcs = glob(["src/python/gandi/client.py"]), srcs = glob(["src/python/gandi/client.py"]),
imports = [ imports = [
"src/python" "src/python",
], ],
deps = [ deps = [
py_requirement("requests"), py_requirement("requests"),

View file

@ -1,6 +1,9 @@
py_binary( zapp_binary(
name = "updater", name = "updater",
main = "src/python/arrdem/updater/__main__.py", main = "src/python/arrdem/updater/__main__.py",
imports = [
"src/python",
],
deps = [ deps = [
"//projects/gandi", "//projects/gandi",
py_requirement("jinja2"), py_requirement("jinja2"),

View file

@ -9,9 +9,6 @@ import re
import sys import sys
for e in sys.path:
print(e)
from gandi.client import GandiAPI from gandi.client import GandiAPI
import jinja2 import jinja2
import meraki import meraki
@ -30,8 +27,10 @@ RECORD_LINE_PATTERN = re.compile(
def update(m, k, f, *args, **kwargs): def update(m, k, f, *args, **kwargs):
"""clojure.core/update for Python's stateful maps.""" """clojure.core/update for Python's stateful maps."""
if k in m: if k in m:
m[k] = f(m[k], *args, **kwargs) m[k] = f(m[k], *args, **kwargs)
return m return m
@ -70,8 +69,8 @@ def template_and_parse_zone(template_file, template_bindings):
assert template_file is not None assert template_file is not None
assert template_bindings is not None assert template_bindings is not None
with open(template_file) as f: with open(template_file) as fp:
dat = jinja2.Template(f.read()).render(**template_bindings) dat = jinja2.Template(fp.read()).render(**template_bindings)
uncommitted_records = [] uncommitted_records = []
for line in dat.splitlines(): for line in dat.splitlines():
@ -138,7 +137,9 @@ parser.add_argument("--dry-run", dest="dry", action="store_true", default=False)
def main(): def main():
args = parser.parse_args() args = parser.parse_args()
config = yaml.safe_load(open(args.config_file, "r"))
with open(args.config_file, "r") as fp:
config = yaml.safe_load(fp)
dashboard = meraki.DashboardAPI(config["meraki"]["key"], output_log=False) dashboard = meraki.DashboardAPI(config["meraki"]["key"], output_log=False)
org = config["meraki"]["organization"] org = config["meraki"]["organization"]