Commit 6960ff2d authored by Jason Frisvold's avatar Jason Frisvold
Browse files

- Defaults for mysql database connection

- Add code for MySQL to retrieve server list
- Add requirement of netaddr for IP manipulation
parent f3c1bb2e
......@@ -20,3 +20,21 @@
# DO NOT DELETE OR ALTER THIS FILE
[skynet]
# Name of the master skynet database
dbname = skynet
# Username for accessing the database
dbuser = skynet
# Password for accessing the database
dbpass = cloud
# Host where the database is located
dbhost = localhost
# Port where the database can be accessed
dbport = 3306
# Location of the gpg binary. This should be the full path and binary name.
gpg_binary = /usr/bin/gpg
\ No newline at end of file
......@@ -27,6 +27,7 @@ from datetime import datetime
import os, os.path
import re
import MySQLdb
from netaddr import IPAddress
# Global Variables
verbose = False
......@@ -88,21 +89,32 @@ def main(argv):
# Determine if we should be running now
# Get a MySQL database handle
try:
dbhandle = MySQLdb.connect(host = cfg['dbhost'],
port = int(cfg['dbport']),
user = cfg['dbuser'],
passwd = cfg['dbpass'],
db = cfg['dbname'])
except MySQLdb.Error, e:
logger.exception("MySQL Error [%d]: %s" % (e.args[0], e.args[1]))
sys.exit()
# Get the list of servers to access
serverlist = get_servers()
serverlist = get_servers(dbhandle)
# Loop through the list
if (len(serverlist) > 0):
for server in serverlist:
# Get the key for each server
key = get_serverkey(server)
logger.debug('Processing server ' + str(server['id']) +
' (' + server['ip'] + ')')
# Build configs (based on what criteria? always? Only when changed?)
# Build configs (based on what criteria? always?
# Only when changed?)
configlist = build_config(server)
# SCP configs over (if there are configs)
push_config(server, key)
if (len(configlist) > 0):
push_config(server, key)
# Get results from server
get_results(server, key)
......@@ -130,20 +142,37 @@ def loadconfig():
global cfg
cfg['configdir'] = config.get('skynet', 'configdir')
cfg['datadir'] = config.get('skynet', 'datadir')
cfg['dbname'] = config.get('skynet', 'dbname')
cfg['dbhost'] = config.get('skynet', 'dbhost')
cfg['dbport'] = config.get('skynet', 'dbport')
cfg['dbuser'] = config.get('skynet', 'dbuser')
cfg['dbpass'] = config.get('skynet', 'dbpass')
logger.debug('configdir = {0}'.format(cfg['configdir']))
logger.debug('datadir = {0}'.format(cfg['datadir']))
for k, v in cfg.items():
logger.debug('{0} = {1}'.format(k, v))
def get_servers():
def get_servers(dbhandle):
logger.info('Loading server list')
def get_serverkey(server):
logger.info('Retrieving server key')
cur = dbhandle.cursor()
cur.execute("SELECT id, server_ip, gpg_key, ssh_key FROM cloud")
serverlist = []
rows = cur.fetchall()
if (len(rows) > 0) :
for row in rows :
serverlist.append({ 'id' : row[0], 'ip' : str(IPAddress(row[1])),
'gpg_key' : row[2], 'ssh_key' : row[3]})
return serverlist
def build_config(server):
logger.info('Building server configuration')
configlist = []
return configlist
def push_config(server, key):
logger.info('Pushing server configuration')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment