Skip to content
This repository has been archived by the owner on Mar 27, 2020. It is now read-only.

Commit

Permalink
Merge pull request #1 from bradical987/develop
Browse files Browse the repository at this point in the history
v1.1.0
  • Loading branch information
bsakdol committed Mar 2, 2017
2 parents 8612b2a + 00fb871 commit 02e14f0
Show file tree
Hide file tree
Showing 10 changed files with 131 additions and 14 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,6 @@ ENV/

# Windows
*.ini

# Project specific files
database.py
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion jumpbox/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

__version__ = '1.0.0'
__version__ = '1.1.0'
78 changes: 78 additions & 0 deletions jumpbox/database.example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Copyright (C) 2017 Bradley Sakdol <bsakdol@turnitin.com>
#
# 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 <http://www.gnu.org/licenses/>.
"""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()
9 changes: 1 addition & 8 deletions jumpbox/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '\
Expand Down Expand Up @@ -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()
Expand Down
Empty file modified jumpbox/main.py
100644 → 100755
Empty file.
4 changes: 4 additions & 0 deletions jumpbox/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,9 @@ def __init__(self):
'type': MENU,
'options': menu_all_sites
},
{
'title': "Quick Connect",
'type': PROMPT
},
]
}
13 changes: 13 additions & 0 deletions jumpbox/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"""This module handles the Jumpbox UI"""

import curses
import curses.panel
import os

from menu import Menu
Expand Down Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion scripts/cibuild.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ fi
END=$(date +%s)
echo "$(info) exiting with code $EXIT after $(($END - $START)) seconds."

exit $EXIT
exit $EXIT
26 changes: 26 additions & 0 deletions upgrade.sh
Original file line number Diff line number Diff line change
@@ -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."

0 comments on commit 02e14f0

Please sign in to comment.