include password in journal
This commit is contained in:
parent
e020a6c64c
commit
037946df66
5 changed files with 44 additions and 9 deletions
17
control.py
Normal file
17
control.py
Normal 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)
|
||||||
|
|
|
@ -3,5 +3,10 @@
|
||||||
#makes jsons human (and machine) readable
|
#makes jsons human (and machine) readable
|
||||||
|
|
||||||
#TODO: scan for all jsons and rewrite them.
|
#TODO: scan for all jsons and rewrite them.
|
||||||
|
echo " "
|
||||||
|
echo "JOURNAL:"
|
||||||
cat journal.json | python3 -m json.tool
|
cat journal.json | python3 -m json.tool
|
||||||
|
echo " "
|
||||||
|
echo "CLIENTS:"
|
||||||
|
cat clients.json | python3 -m json.tool
|
||||||
|
|
||||||
|
|
19
journaldb.py
19
journaldb.py
|
@ -11,7 +11,7 @@ import json
|
||||||
import ioconfig
|
import ioconfig
|
||||||
import utils
|
import utils
|
||||||
|
|
||||||
def createjnode(vmid, regionid, slaveid):
|
def createjnode(vmid, regionid, slaveid, vmpasswd):
|
||||||
""" create new record into the journal. invoked on vm creation """
|
""" create new record into the journal. invoked on vm creation """
|
||||||
journaldb = readjournal()
|
journaldb = readjournal()
|
||||||
if str(vmid) in journaldb:
|
if str(vmid) in journaldb:
|
||||||
|
@ -20,8 +20,8 @@ def createjnode(vmid, regionid, slaveid):
|
||||||
jnode = { str(vmid):{} }
|
jnode = { str(vmid):{} }
|
||||||
journaldb.update(jnode)
|
journaldb.update(jnode)
|
||||||
|
|
||||||
ioconfig.logger.info ('journal> r[{}] s[{}] -> id[{}]'.format(regionid, slaveid, vmid))
|
ioconfig.logger.info ('journal> write: r[{}]s[{}]id[{}] => {}'.format(regionid, slaveid, vmid, vmpasswd))
|
||||||
jdata = { 'vmid':str(vmid), 'slaveid':str(slaveid), 'regionid':str(regionid) }
|
jdata = { 'vmid':str(vmid), 'slaveid':str(slaveid), 'regionid':str(regionid), 'passwd':str(vmpasswd) }
|
||||||
journaldb[str(vmid)] = jdata
|
journaldb[str(vmid)] = jdata
|
||||||
writedb(journaldb)
|
writedb(journaldb)
|
||||||
|
|
||||||
|
@ -32,12 +32,23 @@ def getjnode(vmid):
|
||||||
try:
|
try:
|
||||||
regionid = journaldb[str(vmid)]['regionid']
|
regionid = journaldb[str(vmid)]['regionid']
|
||||||
slaveid = journaldb[str(vmid)]['slaveid']
|
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:
|
except:
|
||||||
ioconfig.logger.error('journal> invalid id[{}] !'.format(vmid))
|
ioconfig.logger.error('journal> invalid id[{}] !'.format(vmid))
|
||||||
else:
|
else:
|
||||||
return regionid, slaveid
|
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():
|
def readjournal():
|
||||||
""" read journal """
|
""" read journal """
|
||||||
|
|
10
plugin.py
10
plugin.py
|
@ -65,21 +65,21 @@ def vmcreate(req):
|
||||||
slave_id = str(grid.query_happiness(region_id))
|
slave_id = str(grid.query_happiness(region_id))
|
||||||
vm_id = str(grid.generate_vmid())
|
vm_id = str(grid.generate_vmid())
|
||||||
vm_ipv4 = grid.generate_ipv4(region_id, req['vps_ipv4'])
|
vm_ipv4 = grid.generate_ipv4(region_id, req['vps_ipv4'])
|
||||||
ipv4_dict = {}
|
|
||||||
ipidx = 0
|
|
||||||
|
|
||||||
vm_name = req['hostname']
|
vm_name = req['hostname']
|
||||||
|
vm_pass = req['password']
|
||||||
client_id = req['clientid']
|
client_id = req['clientid']
|
||||||
client_name = req['clientname']
|
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.
|
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']
|
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)
|
#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:
|
for ip in vm_ipv4:
|
||||||
ipv4_dict[str(ipidx)] = str(ip)
|
ipv4_dict[str(ipidx)] = str(ip)
|
||||||
ipidx += 1
|
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'
|
disk_filename = 'vm-' + vm_id + '-disk-1'
|
||||||
description = vm_name + ' (' + vm_id + ')\n'
|
description = vm_name + ' (' + vm_id + ')\n'
|
||||||
|
@ -107,7 +107,7 @@ def vmcreate(req):
|
||||||
if req['vps_type'] == 'LXC':
|
if req['vps_type'] == 'LXC':
|
||||||
create_result = proxobject.nodes(slave_name).lxc.post(vmid=vm_id,
|
create_result = proxobject.nodes(slave_name).lxc.post(vmid=vm_id,
|
||||||
hostname=vm_name,
|
hostname=vm_name,
|
||||||
password=req['password'],
|
password=vm_pass,
|
||||||
sockets=1,
|
sockets=1,
|
||||||
cores=req['vps_cpu'],
|
cores=req['vps_cpu'],
|
||||||
memory=req['vps_ram'],
|
memory=req['vps_ram'],
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
uwsgi
|
uwsgi
|
||||||
pyOpenSSL
|
pyOpenSSL
|
||||||
|
bcrypt
|
||||||
requests
|
requests
|
||||||
falcon
|
falcon
|
||||||
urllib
|
urllib
|
||||||
netaddr
|
netaddr
|
||||||
proxmoxer
|
proxmoxer
|
||||||
websockify
|
websockify
|
||||||
|
flask
|
||||||
|
|
Loading…
Reference in a new issue