diff --git a/.gitignore b/.gitignore
index 0100637..ce2d01e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -90,3 +90,6 @@ ENV/
# Windows
*.ini
+
+# Project specific files
+database.py
diff --git a/README.md b/README.md
index 190196d..df34cb9 100644
--- a/README.md
+++ b/README.md
@@ -28,12 +28,12 @@ Install Python requirements:
Update the PSQL connection parameters in `jumpbox/database.py`
```bash
- # vi /opt/jumpbox/jumpbox/database.py
+ # cp /opt/jumpbox/jumpbox/database.example.py /opt/jumpbox/jumpbox/database.py
```
+Change `username` and `127.0.0.1` to be the username and IP address of your PSQL host
```python
- # These are located on lines 29 and 30
- db_username = 'username' # This is the username of your PSQL database
- db_host = '127.0.0.1' # This is the IP address where your PSQL database lives
+ # Line 65
+ conn = psycopg2.connect("user = 'username' host = '127.0.0.1'")
```
Create Jumpbox User:
diff --git a/jumpbox/_version.py b/jumpbox/_version.py
index a3de065..dc65715 100644
--- a/jumpbox/_version.py
+++ b/jumpbox/_version.py
@@ -15,4 +15,4 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
-__version__ = '1.0.0'
+__version__ = '1.1.0'
diff --git a/jumpbox/database.example.py b/jumpbox/database.example.py
new file mode 100644
index 0000000..352caec
--- /dev/null
+++ b/jumpbox/database.example.py
@@ -0,0 +1,78 @@
+# Copyright (C) 2017 Bradley Sakdol
+#
+# This file is part of Jumpbox
+#
+# Jumpbox is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see .
+"""This module handles database connectivity"""
+
+import psycopg2
+import sys
+
+
+class DBHandler(object):
+
+ # This function returns data from a query for all devices
+ def all_devices_query(self):
+ query_all_devices = '\
+ SELECT dcim_device.name AS "Device Name", \
+ ipam_ipaddress.address AS "IP Address" \
+ FROM dcim_device, ipam_ipaddress \
+ WHERE dcim_device.primary_ip4_id = ipam_ipaddress.id \
+ ORDER BY dcim_device.name ASC;'
+
+ rows = self.dbconnect(query_all_devices)
+ return rows
+
+ # This function returns data from a query for all sites
+ def all_sites_query(self):
+ query_all_sites = '\
+ SELECT dcim_site.id, dcim_site.name, dcim_site.facility \
+ FROM dcim_site \
+ ORDER BY dcim_site.facility ASC;'
+
+ rows = self.dbconnect(query_all_sites)
+ return rows
+
+ # This function returns data from a query for devices from a single site
+ def one_site_query(self, site_id):
+ query_one_site = '\
+ SELECT dcim_device.name AS "Device Name", \
+ ipam_ipaddress.address AS "IP Address" \
+ FROM dcim_device \
+ JOIN ipam_ipaddress ON dcim_device.primary_ip4_id = ipam_ipaddress.id \
+ JOIN dcim_rack ON dcim_rack.id = dcim_device.rack_id \
+ JOIN dcim_site ON dcim_rack.site_id = dcim_site.id \
+ AND dcim_site.id =' + str(site_id) + '\
+ ORDER BY dcim_device.name ASC;'
+
+ rows = self.dbconnect(query_one_site)
+ return rows
+
+ # This function makes the connection to the database
+ def dbconnect(self, query):
+ try:
+ conn = psycopg2.connect("user = 'username' host = '127.0.0.1'")
+ cur = conn.cursor()
+ cur.execute(query)
+ rows = cur.fetchall()
+
+ return rows
+
+ except psycopg2.DatabaseError, err:
+ print 'Error %s' % err
+ sys.exit(1)
+
+ finally:
+ if conn:
+ conn.close()
diff --git a/jumpbox/database.py b/jumpbox/database.py
index 4f37d6d..27e9e61 100644
--- a/jumpbox/database.py
+++ b/jumpbox/database.py
@@ -22,13 +22,6 @@
class DBHandler(object):
-
- def __init__(self):
-
- # Modify the following vars to be the connection parameters for your database
- db_username = 'username'
- db_host = '127.0.0.1'
-
# This function returns data from a query for all devices
def all_devices_query(self):
query_all_devices = '\
@@ -69,7 +62,7 @@ def one_site_query(self, site_id):
# This function makes the connection to the database
def dbconnect(self, query):
try:
- conn = psycopg2.connect("user = " + db_username + " host = " + db_host + "'")
+ conn = psycopg2.connect("user = 'netbox' host = '10.7.65.33'")
cur = conn.cursor()
cur.execute(query)
rows = cur.fetchall()
diff --git a/jumpbox/main.py b/jumpbox/main.py
old mode 100644
new mode 100755
diff --git a/jumpbox/menu.py b/jumpbox/menu.py
index 73362d9..8498213 100644
--- a/jumpbox/menu.py
+++ b/jumpbox/menu.py
@@ -52,5 +52,9 @@ def __init__(self):
'type': MENU,
'options': menu_all_sites
},
+ {
+ 'title': "Quick Connect",
+ 'type': PROMPT
+ },
]
}
diff --git a/jumpbox/ui.py b/jumpbox/ui.py
index dcb6c94..071f031 100644
--- a/jumpbox/ui.py
+++ b/jumpbox/ui.py
@@ -17,6 +17,7 @@
"""This module handles the Jumpbox UI"""
import curses
+import curses.panel
import os
from menu import Menu
@@ -65,6 +66,18 @@ def processmenu(self, menu, parent=None):
curses.curs_set(1)
curses.curs_set(0)
+ elif menu['options'][selected]['type'] == "prompt":
+ curses.def_prog_mode()
+ os.system('reset')
+ ip_address = raw_input('IP / Hostname: ')
+ os.system('clear')
+ username = raw_input('Username: ')
+ os.system('ssh ' + username + '@' + ip_address)
+ self.stdscr.clear()
+ curses.reset_prog_mode()
+ curses.curs_set(1)
+ curses.curs_set(0)
+
def runmenu(self, menu, parent):
self.stdscr.refresh()
diff --git a/scripts/cibuild.sh b/scripts/cibuild.sh
old mode 100644
new mode 100755
index fd83b2d..89fd031
--- a/scripts/cibuild.sh
+++ b/scripts/cibuild.sh
@@ -35,4 +35,4 @@ fi
END=$(date +%s)
echo "$(info) exiting with code $EXIT after $(($END - $START)) seconds."
-exit $EXIT
\ No newline at end of file
+exit $EXIT
diff --git a/upgrade.sh b/upgrade.sh
new file mode 100755
index 0000000..ed8ffa4
--- /dev/null
+++ b/upgrade.sh
@@ -0,0 +1,26 @@
+#!/bin/bash
+#
+# This script will prepare Jumpbox to run after a release upgrade.
+#
+
+# If not already "root", script must be run with "sudo"
+if [ "$(whoami)" = "root" ]; then
+ # As "root", ask the user to confirm before continuing
+ read -n1 -rsp $'Running Jumpbox as root, press any key to continue or ^C to cancel\n'
+ PREFIX=""
+
+fi
+
+# Pull Jumpbox updates
+COMMAND="${PREFIX}git checkout master"
+echo "Checkout master Git repo ($COMMAND)..."
+COMMAND="${PREFIX}git pull origin master"
+echo "Pull updated Jumpbox files ($COMMAND)..."
+
+# Install new Python packages
+COMMAND="${PREFIX}pip install -r requirements.txt --upgrade"
+echo "Updating required Python packages ($COMMAND)..."
+eval $COMMAND
+
+# Update complete notification
+echo "Jumpbox update complete."