Commit 3422889b authored by Jason Frisvold's avatar Jason Frisvold
Browse files

- Move config directories into the database

- Move SFTP username into the database
- Modifications to retrieve additional config from database
- Start of config push routine
parent 0d406490
......@@ -22,11 +22,10 @@
[spawner]
# The configuration directory is where new instructions are placed by the server
# This can be an absolute or relative path.
configdir = config
configdir = /opt/skynet/config
# The data directory is where the spawner will store internal data.
datadir = spawner_data
datadir = /opt/skynet/spawner_data
# This defines the name of the sqlite database used for timing data. It will be
# located in the datadir.
......
......@@ -37,7 +37,4 @@ dbhost = localhost
dbport = 3306
# Location of the gpg binary. This should be the full path and binary name.
gpg_binary = /usr/bin/gpg
# Username for SFTP process
sftp_username = skynet
\ No newline at end of file
gpg_binary = /usr/bin/gpg
\ No newline at end of file
......@@ -113,17 +113,21 @@ def main(argv):
# Build configs
configlist = build_configs(dbhandle, server['id'])
server_conn = connect_server(server['ip'], server['key_type'],
server_conn = connect_server(server['ip'],
server['ssh_username'],
server['key_type'],
server['ssh_key'])
# SCP configs over (if there are configs)
if (len(configlist) > 0):
push_configs(server_conn, configlist)
# Get results from server
get_results(dbhandle, server_conn, str(server['id']))
server_conn.close()
if (server_conn):
# SCP configs over (if there are configs)
if (len(configlist) > 0):
push_configs(server_conn, configlist,
server['config_dir'])
# Get results from server
get_results(dbhandle, server_conn, str(server['id']))
server_conn.close()
# Process results, update database, store results
......@@ -153,7 +157,6 @@ def loadconfig():
cfg['dbport'] = config.get('skynet', 'dbport')
cfg['dbuser'] = config.get('skynet', 'dbuser')
cfg['dbpass'] = config.get('skynet', 'dbpass')
cfg['sftp_user'] = config.get('skynet', 'sftp_username')
for k, v in cfg.items():
logger.debug('{0} = {1}'.format(k, v))
......@@ -161,7 +164,8 @@ def loadconfig():
def get_servers(dbhandle):
logger.info('Loading server list')
sql = '''SELECT DISTINCT c.id, c.server_ip, c.key_type, c.ssh_key, c.gpg_key
sql = '''SELECT DISTINCT c.id, c.server_ip, c.key_type, c.ssh_key,
c.gpg_key, c.config_dir, c.output_dir, c.ssh_username
FROM cloud AS c, timers AS ti, target AS t, spawn AS s WHERE
(ti.cloud_id = c.id AND ti.spawn_id = s.id AND ti.target_id = t.id)
AND (c.last_contacted <= c.last_modified OR c.last_contacted <=
......@@ -183,11 +187,12 @@ def get_servers(dbhandle):
logger.debug('Database Retrieval : ' + str(row))
serverlist.append({ 'id' : row[0], 'ip' : str(IPAddress(row[1])),
'key_type' : row[2], 'ssh_key' : row[3],
'gpg_key' : row[4]})
'gpg_key' : row[4], 'config_dir' : row[5],
'output_dir' : row[6], 'ssh_username' : row[7]})
return serverlist
def connect_server(server_ip, key_type, ssh_key):
def connect_server(server_ip, username, key_type, ssh_key):
logger.info('Creating SSH connection to server {0}'.format(server_ip))
if (key_type == 'RSA'):
......@@ -198,12 +203,13 @@ def connect_server(server_ip, key_type, ssh_key):
try:
transport = paramiko.Transport((server_ip))
transport.start_client()
transport.auth_publickey(cfg['sftp_user'], server_key)
transport.auth_publickey(username, server_key)
sftp = paramiko.SFTPClient.from_transport(transport)
except:
e = sys.exc_info()[0]
logger.exception('BROKED = {0}'.format(e))
logger.exception('Unable to create SFTP connection : {0}'.format(e))
return None
return sftp
......@@ -238,9 +244,11 @@ def build_configs(dbhandle, server_id):
return configlist
def push_configs(server_conn, configlist):
def push_configs(server_conn, configlist, config_path):
logger.info('Pushing server configuration')
server_conn.chdir(config_path)
def get_results(dbhandle, server_conn, server_id):
logger.info('Retrieving results from server')
......
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