basic classing
This commit is contained in:
parent
e96c0f533c
commit
444cca48de
21
checkdb.py
21
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()
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,22 +1,29 @@
|
|||
{% extends "page.html" %}
|
||||
{% block title %}All classes{% endblock %}
|
||||
{% block subtitle %}<a href="/node_edit">Add</a>{% endblock %}
|
||||
{% block subtitle %}{% endblock %}
|
||||
{% block buttons %}{% endblock %}
|
||||
|
||||
{% block body %}
|
||||
|
||||
<div class="classes-all">
|
||||
{% for node in classes %}
|
||||
{% for cls in classnames %}
|
||||
<div class="class">
|
||||
<h2>{{ node.fqdn }}</h2>
|
||||
<p>
|
||||
<a href="/node/{{ node.fqdn }}">view</a> <a href="/node_edit?node={{ node.fqdn }}">edit</a>
|
||||
</p>
|
||||
<pre>
|
||||
{{ node.body }}
|
||||
</pre>
|
||||
<h2>{{ cls }}</h2>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
<div class="class-add">
|
||||
<form action="/classes/add" method="post" class="pure-form pure-form-stacked">
|
||||
<fieldset>
|
||||
<fieldset class="pure-group pure-u-1">
|
||||
<input name="name" type="text" class="pure-input-1" placeholder="Name" value="" />
|
||||
</fieldset>
|
||||
<div class="pure-u-1">
|
||||
<input type="submit" name="op" class="pure-button pure-button-primary" value="Create" />
|
||||
</div>
|
||||
</fieldset>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
|
|
|
@ -27,12 +27,26 @@
|
|||
<div class="node-classes">
|
||||
<h2>Classes</h2>
|
||||
<div class="class-list">
|
||||
{% for class in node.classes %}
|
||||
{% for name, class in node.classes.items() %}
|
||||
<div class="class">
|
||||
{{ class.cls.name }}
|
||||
</div>
|
||||
<div class="class-conf">
|
||||
<pre>{{ class.conf }}</pre>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
<div class="node-add-class">
|
||||
<form action="/node/{{ node.fqdn }}/op" method="post" class="pure-form pure-form-stacked">
|
||||
<select name="clsname">
|
||||
{% for cls in classnames %}
|
||||
<option value="{{ cls }}">{{ cls }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
<textarea name="config" cols="30" rows="10" placeholder="Yaml config"></textarea>
|
||||
<input type="submit" name="op" class="pure-button pure-button-primary" value="Attach"/>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue