aboutsummaryrefslogtreecommitdiffstats
path: root/junos-bootstrap/httpd
diff options
context:
space:
mode:
authorJonas Lindstad <jonaslindstad@gmail.com>2015-03-16 23:09:40 +0100
committerJonas Lindstad <jonaslindstad@gmail.com>2015-03-16 23:09:40 +0100
commit939b606944b6892d26581bce598c66c790786de9 (patch)
tree6780dc26bd26c22ca8dce6a7832841b5f4efc37a /junos-bootstrap/httpd
parent88dfb934e546d02d1f4356032e91277f9f5b94f1 (diff)
rename + fixes
Diffstat (limited to 'junos-bootstrap/httpd')
-rw-r--r--junos-bootstrap/httpd/ex2200.template73
-rw-r--r--junos-bootstrap/httpd/postgres_queries20
-rw-r--r--junos-bootstrap/httpd/server_http.py142
-rw-r--r--junos-bootstrap/httpd/terminal.log14
4 files changed, 0 insertions, 249 deletions
diff --git a/junos-bootstrap/httpd/ex2200.template b/junos-bootstrap/httpd/ex2200.template
deleted file mode 100644
index b786f64..0000000
--- a/junos-bootstrap/httpd/ex2200.template
+++ /dev/null
@@ -1,73 +0,0 @@
-system {
- host-name $hostname;
- root-authentication {
- encrypted-password "$1$oQTnGCDI$UZpSpT5z7uHhFvniCzY5w/"; ## SECRET-DATA
- }
-}
-chassis {
- aggregated-devices {
- ethernet {
- device-count 1;
- }
- }
-}
-interfaces {
- ge-0/0/0 {
- description ae0;
- ether-options {
- 802.3ad ae0;
- }
- }
- ge-0/0/1 {
- description ae0;
- ether-options {
- 802.3ad ae0;
- }
- }
- ge-0/0/2 {
- description ae0;
- ether-options {
- 802.3ad ae0;
- }
- }
- ae0 {
- description "Aggregation towards $distro_name $distro_phy_port";
- aggregated-ether-options {
- minimum-links 2;
- lacp {
- active;
- }
- }
- unit 0 {
- family ethernet-switching {
- port-mode trunk;
- vlan {
- members [ deltagere mgmt ];
- }
- }
- }
- }
- vlan {
- unit $mgmt_vlan {
- description "Management L3 interface";
- family inet {
- address $mgmt_addr/$mgmt_cidr;
- }
- }
- }
-}
-vlans {
- deltagere {
- vlan-id 200;
- }
- mgmt {
- vlan-id $mgmt_vlan;
- l3-interface vlan.$mgmt_vlan;
- }
-}
-
-routing-options {
- static {
- route 0.0.0.0/0 next-hop $mgmt_gw;
- }
-}
diff --git a/junos-bootstrap/httpd/postgres_queries b/junos-bootstrap/httpd/postgres_queries
deleted file mode 100644
index d7c07f2..0000000
--- a/junos-bootstrap/httpd/postgres_queries
+++ /dev/null
@@ -1,20 +0,0 @@
-CREATE TABLE switches (
- id serial primary key,
- hostname varchar(20) NOT NULL,
- distro_name varchar(100) NOT NULL,
- distro_phy_port varchar(100) NOT NULL,
- mgmt_addr varchar(15) NOT NULL,
- mgmt_cidr smallint NOT NULL,
- mgmt_gw varchar(15) NOT NULL,
- mgmt_vlan smallint NOT NULL,
- last_config_fetch integer default NULL,
- current_mac varchar(17) default NULL
-);
-
-
-
-insert into switches (hostname, distro_name, distro_phy_port, mgmt_addr, mgmt_cidr, mgmt_gw, mgmt_vlan) values
-('e-00-0-test', 'distro-test', 'ge-0/0/0', '10.0.200.2', '24', '10.0.200.1', '300'),
-('e-00-1-test', 'distro-test', 'ge-0/0/3', '10.0.200.3', '24', '10.0.200.1', '300'),
-('e-00-2-test', 'distro-test', 'ge-0/0/6', '10.0.200.4', '24', '10.0.200.1', '300'),
-('e-60-0-test', 'distro-test', 'ge-0/0/9', '10.0.200.5', '24', '10.0.200.1', '300');
diff --git a/junos-bootstrap/httpd/server_http.py b/junos-bootstrap/httpd/server_http.py
deleted file mode 100644
index ea74dd4..0000000
--- a/junos-bootstrap/httpd/server_http.py
+++ /dev/null
@@ -1,142 +0,0 @@
-#!/usr/bin/python
-# -*- coding: utf-8 -*-
-
-from http.server import BaseHTTPRequestHandler, HTTPServer
-from string import Template
-import time
-import psycopg2
-import psycopg2.extras
-import sys
-import os
-
-def main():
- #
- # Settings
- #
- settings = {
- 'db': {
- 'user': 'bootstrap',
- 'password': 'asdf',
- 'dbname': 'bootstrap',
- 'host': 'localhost'
- },
- 'http': {
- 'host': '0.0.0.0',
- 'port': 80
- }
- }
-
- #
- # Connect to DB
- #
- try:
- connect_params = ("dbname='%s' user='%s' host='%s' password='%s'" % (settings['db']['dbname'], settings['db']['user'], settings['db']['host'], settings['db']['password']))
- conn = psycopg2.connect(connect_params)
- cur = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
- # cur.execute("""SELECT * from switches""")
- # rows = cur.fetchall()
- # print ("\nSwitches in DB during server_http.py startup:")
- # for row in rows:
- # print (" --> %s, connected to %s port %s" % (row['hostname'], row['distro_name'], row['distro_phy_port']))
-
- except (psycopg2.DatabaseError, psycopg2.OperationalError) as e:
- print ('Error: %s' % e)
- sys.exit(1)
-
- except:
- print(sys.exc_info()[0])
- sys.exit(1)
-
- def template_get(model):
- return open('junos-bootstrap/httpd/' + model + '.template').read()
-
- def template_parse(template_src, hostname):
- cur.execute("SELECT * FROM switches WHERE hostname = '%s'" % hostname)
- if(cur.rowcount == 1):
- row = cur.fetchall()[0]
- d={
- 'hostname': row['hostname'],
- 'distro_name': row['distro_name'],
- 'distro_phy_port': row['distro_phy_port'],
- 'mgmt_addr': row['mgmt_addr'],
- 'mgmt_cidr': row['mgmt_cidr'],
- 'mgmt_gw': row['mgmt_gw'],
- 'mgmt_vlan': row['mgmt_vlan']
- }
- cur.execute("UPDATE switches SET last_config_fetch = '%s' WHERE hostname = '%s'" % (str(time.time()).split('.')[0], hostname)) # updated DB with last config fetch
- conn.commit()
- return Template(template_src).safe_substitute(d)
- else:
- return False
-
- class httpd(BaseHTTPRequestHandler):
- def do_GET(self):
- print('[%s] [%s] Incoming HTTP GET URI:%s ' % (self.client_address[0], time.asctime(), self.path))
-
- # Client asks for the config file
- if '/tg-edge/' in self.path:
- hostname = self.path.split('/tg-edge/')[1]
- if len(hostname) > 0:
- print('[%s] --> Hostname "%s" accepted, fetching info from DB' % (self.client_address[0], hostname))
- template_parsed = template_parse(template_get('ex2200'), hostname)
- if template_parsed:
- print('[%s] --> Template successfully populated' % self.client_address[0])
- print('[%s] --> Sending response to client' % self.client_address[0])
- self.send_response(200)
- self.send_header("Content-type", "text/plain")
- self.end_headers()
- self.wfile.write(bytes(template_parsed, "utf-8"))
- print('[%s] --> Success - %s bytes sent to client' % (self.client_address[0], len(template_parsed)))
- else:
- print('[%s] --> Error - could not find hostname "%s" in DB' % (self.client_address[0], hostname))
- else:
- print('[%s] --> Rejected due to missing hostname' % self.client_address[0])
-
- # Client asks for a file download - most likely a JunOS file
- elif '/files/' in self.path:
- # It seems that "http.server" escapes nastiness from the URL - ("/files/../../../root_file" => "/files/root_file")
- requested_file = self.path.split('/files/')[1]
- files_dir = 'junos-bootstrap/httpd/files/'
- print('[%s] --> File request for "%s" in "%s"' % (self.client_address[0], requested_file, files_dir))
- if os.path.isfile(files_dir + requested_file):
- print('[%s] --> File found' % self.client_address[0])
- try:
- f = open(files_dir + requested_file)
- self.send_response(200)
- self.send_header('Content-type', 'application/x-gzip') # correct content type for tar.gz
- self.end_headers()
- print('[%s] --> File transfer started' % self.client_address[0])
- f = open(files_dir + requested_file, 'rb')
- self.wfile.write(f.read())
- f.close()
- print('[%s] --> File transfer completed' % self.client_address[0])
- return
- except IOError:
- self.send_error(404,'File Not Found: %s' % self.path)
- print('[%s] --> ERROR 404 - File not found' % self.client_address[0])
- pass
- except:
- print('[%s] --> Generic error during file reading' % self.client_address[0])
- pass
- else:
- print('[%s] --> File request rejected due to nonexisting file' % self.client_address[0])
- else:
- print('[%s] --> rejected due to bad URI' % self.client_address[0])
- # silence stderr from BaseHTTPRequestHandler
- # source: http://stackoverflow.com/questions/3389305/how-to-silent-quiet-httpserver-and-basichttprequesthandlers-stderr-output
- def log_message(self, format, *args):
- return
-
- httpd_instance = HTTPServer((settings['http']['host'], settings['http']['port']), httpd)
- print("\n[%s] Server Starts - %s:%s" % (time.asctime(), settings['http']['host'], settings['http']['port']))
-
- try:
- httpd_instance.serve_forever()
- except KeyboardInterrupt:
- pass
-
- httpd_instance.server_close()
- print("\n\n[%s] HTTP Server stopped\n" % time.asctime())
-
-if __name__ == "__main__":
- main()
diff --git a/junos-bootstrap/httpd/terminal.log b/junos-bootstrap/httpd/terminal.log
deleted file mode 100644
index eaf6356..0000000
--- a/junos-bootstrap/httpd/terminal.log
+++ /dev/null
@@ -1,14 +0,0 @@
-j@lappie:~/git/tgmanage$ sudo python3 junos-bootstrap/httpd/server_http.py
-
-[Thu Feb 19 23:15:45 2015] Server Starts - 0.0.0.0:80
-[10.0.200.101] [Fri Feb 20 00:18:25 2015] Incoming HTTP GET URI://tg-edge/e-00-1
-[10.0.200.101] --> Hostname "e-00-1" accepted, fetching info from DB
-[10.0.200.101] --> Template successfully populated
-[10.0.200.101] --> Sending response to client
-[10.0.200.101] --> Success - 1437 bytes sent to client
-[10.0.200.101] [Fri Feb 20 00:18:26 2015] Incoming HTTP GET URI://files/jinstall-ex-2200-12.3R6.6-domestic-signed.tgz
-[10.0.200.101] --> File request for "jinstall-ex-2200-12.3R6.6-domestic-signed.tgz" in "junos-bootstrap/httpd/files/"
-[10.0.200.101] --> File found
-[10.0.200.101] --> File transfer started
-[10.0.200.101] --> File transfer completed
-