aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--templating/templates/switch.txt19
-rwxr-xr-xtemplating/templating.py15
2 files changed, 32 insertions, 2 deletions
diff --git a/templating/templates/switch.txt b/templating/templates/switch.txt
new file mode 100644
index 0000000..0fd9754
--- /dev/null
+++ b/templating/templates/switch.txt
@@ -0,0 +1,19 @@
+{#
+ This can be used through GET /templating/switch.txt?switch=e41-2
+
+ It is provided as a simple demo of how to combine "GET parameters" with
+ templating.
+
+ #}
+{% set sw = options["switch"] %}
+{% set s = objects["public/switches"].switches[sw] %}
+{% if s %}
+{% set mg = objects["read/switches-management"].switches[sw] %}
+
+Switch {{ sw }} has management ip {{ mg.mgmt_v4_addr }}
+
+It is assoicated with distro {{ s.distro_name }}
+{% else %}
+Switch not found
+{% endif %}
+
diff --git a/templating/templating.py b/templating/templating.py
index 5144b89..57d81b1 100755
--- a/templating/templating.py
+++ b/templating/templating.py
@@ -24,9 +24,20 @@ class MyHandler(http.server.BaseHTTPRequestHandler):
def do_GET(self):
print (self.path[1:])
updateData()
+ url = self.path[1:]
+ options = dict()
+ if url.find("?") != -1:
+ (url, tmpoptions) = url.split("?")
+ print (tmpoptions)
+ tmptuples = tmpoptions.split("&")
+ print (tmptuples)
+ for a in tmptuples:
+ (x,y) = a.split("=")
+ options[x] = y
+
try:
- template = env.get_template(self.path[1:])
- body = template.render(objects=objects).encode('UTF-8')
+ template = env.get_template(url)
+ body = template.render(objects=objects, options=options).encode('UTF-8')
self.send_response(200)
except:
body = "baaad\n".encode('UTF-8')