diff --git a/checkdb.py b/checkdb.py index 6375cf0..64d4dee 100755 --- a/checkdb.py +++ b/checkdb.py @@ -3,11 +3,28 @@ import ZODB import ZODB.FileStorage +# def main(): +# storage = ZODB.FileStorage.FileStorage("pupper.db") +# db = ZODB.DB(storage) +# for k, v in db.open().root.nodes.items(): +# print(k, v.name, ":", v, "\n\t", v.body, "\n") + +# def main(): +# storage = ZODB.FileStorage.FileStorage("pupper.db") +# db = ZODB.DB(storage) +# for k, v in db.open().root.nodes["foo2"].classes.items(): +# # print(k, v.name, ":", v, "\n\t", v.body, "\n") +# print(v.conf) + + def main(): storage = ZODB.FileStorage.FileStorage("pupper.db") db = ZODB.DB(storage) - for k, v in db.open().root.nodes.items(): - print(k, v.name, ":", v, "\n\t", v.body, "\n") + with db.transaction() as c: + del c.root.nodes["puppettest5.scc.net.davepedu.com"].classes["base2"] + # for k, v in db.open().root.nodes["foo2"].classes.items(): + # # print(k, v.name, ":", v, "\n\t", v.body, "\n") + # print(v.conf if __name__ == "__main__": main() diff --git a/nodepupper/daemon.py b/nodepupper/daemon.py index dca0288..d1c55ac 100644 --- a/nodepupper/daemon.py +++ b/nodepupper/daemon.py @@ -7,6 +7,7 @@ from jinja2 import Environment, FileSystemLoader, select_autoescape from nodepupper.common import pwhash import math from urllib.parse import urlparse +import yaml APPROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "../")) @@ -58,7 +59,7 @@ class AppWeb(object): """ with self.nodes.db.transaction() as c: ret = { - "classes": c.root.classes, + "classnames": c.root.classes.keys(), # "all_albums": [], "path": cherrypy.request.path_info, "auth": True or auth() @@ -67,7 +68,6 @@ class AppWeb(object): @cherrypy.expose def node_edit(self, node=None, op=None, body=None, fqdn=None): - print(op, body, fqdn) if op in ("Edit", "Create") and body and fqdn: with self.nodes.db.transaction() as c: obj = c.root.nodes[fqdn] if fqdn in c.root.nodes else NObject(fqdn, body) @@ -85,6 +85,20 @@ class AppWeb(object): yield self.render("nodes.html", nodes=c.root.nodes.values()) # raise cherrypy.HTTPRedirect('feed', 302) + @cherrypy.expose + def puppet(self, fqdn): + with self.nodes.db.transaction() as c: + node = c.root.nodes[fqdn] + doc = {"environment": "production", + "classes": {k: yaml.load(v.conf) or {} for k, v in node.classes.items()}, + "parameters": {}} + + for name, attachment in node.classes.items(): + print(name) + + yield "---\n" + yield yaml.dump(doc, default_flow_style=False) + @cherrypy.expose def login(self): """ @@ -122,6 +136,13 @@ class NodesWeb(object): with self.nodes.db.transaction() as c: yield self.render("node.html", node=c.root.nodes[node]) + @cherrypy.expose + def op(self, node, op, clsname, config): + with self.nodes.db.transaction() as c: + # TODO validate yaml + c.root.nodes[node].classes[clsname] = NClassAttachment(c.root.classes[clsname], config) + raise cherrypy.HTTPRedirect("/node/{}".format(node), 302) + @cherrypy.popargs("cls") class ClassWeb(object): @@ -131,7 +152,7 @@ class ClassWeb(object): self.render = root.render @cherrypy.expose - def index(self, cls): + def index(self, cls=None): # with self.nodes.db.transaction() as c: yield self.render("classes.html") @@ -140,6 +161,14 @@ class ClassWeb(object): # with self.nodes.db.transaction() as c: yield self.render("classes.html") + @cherrypy.expose + def add(self, op, name): + with self.nodes.db.transaction() as c: + if op == "Create": + if name not in c.root.classes: + c.root.classes[name] = NClass(name) + raise cherrypy.HTTPRedirect("/classes/{}".format(name), 302) + def main(): import argparse diff --git a/templates/classes.html b/templates/classes.html index 1ab4c4a..2ae5701 100644 --- a/templates/classes.html +++ b/templates/classes.html @@ -1,22 +1,29 @@ {% extends "page.html" %} {% block title %}All classes{% endblock %} -{% block subtitle %}Add{% endblock %} +{% block subtitle %}{% endblock %} {% block buttons %}{% endblock %} {% block body %}
- {% for node in classes %} + {% for cls in classnames %}
-

{{ node.fqdn }}

-

- view edit -

-
-{{ node.body }}
-            
+

{{ cls }}

{% endfor %}
+
+
+
+
+ +
+
+ +
+
+
+
+ {% endblock %} diff --git a/templates/node.html b/templates/node.html index f873011..f225a1d 100644 --- a/templates/node.html +++ b/templates/node.html @@ -27,12 +27,26 @@

Classes

- {% for class in node.classes %} + {% for name, class in node.classes.items() %}
{{ class.cls.name }}
+
+
{{ class.conf }}
+
{% endfor %}
+
+
+ + + +
+