include password in journal

This commit is contained in:
deflax 2016-02-20 04:26:04 +02:00
parent e020a6c64c
commit 037946df66
5 changed files with 44 additions and 9 deletions

17
control.py Normal file
View file

@ -0,0 +1,17 @@
import journaldb
import bcrypt
from flask import Flask
app = Flask(__name__)
@app.route('/')
def index():
return "pxmp v0.1"
@app.route('/fu')
def fu():
return "FU!"
if __name__ == '__main__':
app.run(host='0.0.0.0', debug=True)

View file

@ -3,5 +3,10 @@
#makes jsons human (and machine) readable
#TODO: scan for all jsons and rewrite them.
echo " "
echo "JOURNAL:"
cat journal.json | python3 -m json.tool
echo " "
echo "CLIENTS:"
cat clients.json | python3 -m json.tool

View file

@ -11,7 +11,7 @@ import json
import ioconfig
import utils
def createjnode(vmid, regionid, slaveid):
def createjnode(vmid, regionid, slaveid, vmpasswd):
""" create new record into the journal. invoked on vm creation """
journaldb = readjournal()
if str(vmid) in journaldb:
@ -20,8 +20,8 @@ def createjnode(vmid, regionid, slaveid):
jnode = { str(vmid):{} }
journaldb.update(jnode)
ioconfig.logger.info ('journal> r[{}] s[{}] -> id[{}]'.format(regionid, slaveid, vmid))
jdata = { 'vmid':str(vmid), 'slaveid':str(slaveid), 'regionid':str(regionid) }
ioconfig.logger.info ('journal> write: r[{}]s[{}]id[{}] => {}'.format(regionid, slaveid, vmid, vmpasswd))
jdata = { 'vmid':str(vmid), 'slaveid':str(slaveid), 'regionid':str(regionid), 'passwd':str(vmpasswd) }
journaldb[str(vmid)] = jdata
writedb(journaldb)
@ -32,12 +32,23 @@ def getjnode(vmid):
try:
regionid = journaldb[str(vmid)]['regionid']
slaveid = journaldb[str(vmid)]['slaveid']
ioconfig.logger.info('journal> read: id[{}] -> r[{}] s[{}]'.format(vmid, regionid, slaveid))
ioconfig.logger.info('journal> read: id[{}] => r[{}]s[{}]'.format(vmid, regionid, slaveid))
except:
ioconfig.logger.error('journal> invalid id[{}] !'.format(vmid))
else:
return regionid, slaveid
def getpass(vmid):
""" query the database for the recorded vmid password. """
journaldb = readjournal()
try:
vmpasswd = journaldb[str(vmid)]['passwd']
ioconfig.logger.info('journal> read: id[{}] => {}'.format(vmid, vmpasswd))
except:
ioconfig.logger.error('journal> invalid id[{}] !'.format(vmid))
else:
return vmpasswd
def readjournal():
""" read journal """

View file

@ -65,21 +65,21 @@ def vmcreate(req):
slave_id = str(grid.query_happiness(region_id))
vm_id = str(grid.generate_vmid())
vm_ipv4 = grid.generate_ipv4(region_id, req['vps_ipv4'])
ipv4_dict = {}
ipidx = 0
vm_name = req['hostname']
vm_pass = req['password']
client_id = req['clientid']
client_name = req['clientname']
proxobject = auth(slave_id) #we dont know the ip of slave_id so we leave the auth function to find it itself.
slave_name = proxobject.cluster.status.get()[0]['name']
ipv4_dict = {}
ipidx = 0
#ioconfig.logger.info('grid[' + slave_name + ']> recieved data: %s, %s, %s, %s, %s', region_id, slave_id, vm_id, vm_ipv4, req)
for ip in vm_ipv4:
ipv4_dict[str(ipidx)] = str(ip)
ipidx += 1
response = { 'status':'CREATE', 'vmid':vm_id, 'name':vm_name, 'password':'TODO', 'ipv4_0':vm_ipv4[0] }
response = { 'status':'CREATE', 'vmid':vm_id, 'name':vm_name, 'password':vm_pass, 'ipv4_0':vm_ipv4[0] }
disk_filename = 'vm-' + vm_id + '-disk-1'
description = vm_name + ' (' + vm_id + ')\n'
@ -107,7 +107,7 @@ def vmcreate(req):
if req['vps_type'] == 'LXC':
create_result = proxobject.nodes(slave_name).lxc.post(vmid=vm_id,
hostname=vm_name,
password=req['password'],
password=vm_pass,
sockets=1,
cores=req['vps_cpu'],
memory=req['vps_ram'],

View file

@ -1,8 +1,10 @@
uwsgi
pyOpenSSL
bcrypt
requests
falcon
urllib
netaddr
proxmoxer
websockify
flask