add vm rrd generator
This commit is contained in:
parent
010957966b
commit
97efded2d0
3 changed files with 39 additions and 4 deletions
|
@ -67,7 +67,7 @@ def setencpasswd(clientemail, newpass):
|
|||
|
||||
|
||||
def checkin(clientid):
|
||||
""" return list of owned vmids if client id matches the client database. (logged-in users)"""
|
||||
""" returns a list of owned vmids if client id matches the client database. (logged-in users)"""
|
||||
#1. search for the client
|
||||
try:
|
||||
clientsdb = readclientsdb()
|
||||
|
@ -82,7 +82,7 @@ def checkin(clientid):
|
|||
|
||||
|
||||
def validate(clientemail, password):
|
||||
""" return list of owned vmids if credentials match an user from the database. (fresh logins)"""
|
||||
""" returns a list of owned vmids if credentials match an user from the database. (fresh logins)"""
|
||||
#1. search for the client
|
||||
try:
|
||||
clientsdb = readclientsdb()
|
||||
|
|
25
plugin.py
25
plugin.py
|
@ -231,6 +231,26 @@ def vmresume(vm_id):
|
|||
return response
|
||||
|
||||
|
||||
def vmrrd(vm_id):
|
||||
""" retrieve rrd graphs (PNG) """
|
||||
slave_id, vm_type = grid.query_vm(vm_id)
|
||||
proxobject = auth(slave_id)
|
||||
vm_type = vm_type.lower()
|
||||
slave_name = proxobject.cluster.status.get()[0]['name']
|
||||
ioconfig.logger.info('slave[%s]> query rrd of %s %s' % (slave_name, vm_type, vm_id))
|
||||
|
||||
result = {}
|
||||
if vm_type == 'kvm':
|
||||
result['cpu'] = proxobject.nodes(slave_name).qemu(vm_id).rrd.get(node=slave_name, vmid=vm_id, timeframe='day', cf='AVERAGE', ds='cpu')
|
||||
result['mem'] = proxobject.nodes(slave_name).qemu(vm_id).rrd.get(node=slave_name, vmid=vm_id, timeframe='day', cf='AVERAGE', ds='mem,maxmem')
|
||||
result['net'] = proxobject.nodes(slave_name).qemu(vm_id).rrd.get(node=slave_name, vmid=vm_id, timeframe='day', cf='AVERAGE', ds='netin,netout')
|
||||
result['hdd'] = proxobject.nodes(slave_name).qemu(vm_id).rrd.get(node=slave_name, vmid=vm_id, timeframe='day', cf='AVERAGE', ds='diskread,diskwrite')
|
||||
|
||||
if vm_type == 'lxc':
|
||||
result = proxobject.nodes(slave_name).lxc(vm_id).rrd.get()
|
||||
repsonse = { 'status':'RRD', 'vmid':vm_id, rrd:result }
|
||||
|
||||
|
||||
def vmvnc(vm_id):
|
||||
""" invoke vnc ticket """
|
||||
slave_id, vm_type = grid.query_vm(vm_id)
|
||||
|
@ -269,9 +289,10 @@ def vmvnc(vm_id):
|
|||
external_url = ioconfig.parser.get('general', 'novnc_url')
|
||||
prefix = external_url + "/?host=" + myip + "&port=" + listenport + "&encrypt=0&true_color=1&password="
|
||||
vnc_url = prefix + ticket['ticket']
|
||||
ioconfig.logger.info('slave[{}]> {}'.format(slave_name, vnc_url))
|
||||
|
||||
response = { 'status':'VNC', 'fqdn':external_url, 'host':myip, 'port':listenport, 'encrypt':'0', 'true_color':'1', 'ticket':ticket['ticket'] }
|
||||
ioconfig.logger.info('slave[{}]> vnc port {} ready'.format(slave_name, listenport))
|
||||
#response = { 'status':'VNC', 'fqdn':external_url, 'host':myip, 'port':listenport, 'encrypt':'0', 'true_color':'1', 'ticket':ticket['ticket'] }
|
||||
response = { 'status':'VNC', 'url':vnc_url }
|
||||
return response
|
||||
|
||||
|
||||
|
|
|
@ -70,6 +70,9 @@ def selector(fn, req, vmid=0):
|
|||
elif fn == 'vmstop':
|
||||
body = plugin.vmstop(vmid)
|
||||
|
||||
elif fn == 'vmrrd':
|
||||
body = plugin.vmrrd(vmid)
|
||||
|
||||
elif fn == 'vmvnc':
|
||||
body = plugin.vmvnc(vmid)
|
||||
|
||||
|
@ -222,6 +225,14 @@ class StopResource(object):
|
|||
resp.status, response = selector('vmstop', req, vmid)
|
||||
req.context['result'] = response
|
||||
|
||||
class RRDResource(object):
|
||||
@falcon.before(max_body(64 * 1024))
|
||||
def on_post(self, req, resp, vmid):
|
||||
""" Generate rrd pngs """
|
||||
logger.info('grid> rrd ' + str(vmid))
|
||||
resp.status, response = selector('vmrrd', req, vmid)
|
||||
req.context['result' = response
|
||||
|
||||
class VNCResource(object):
|
||||
@falcon.before(max_body(64 * 1024))
|
||||
def on_post(self, req, resp, vmid):
|
||||
|
@ -269,6 +280,9 @@ api.add_route('/vmshutdown/{vmid}', res_shutdown)
|
|||
res_stop = StopResource()
|
||||
api.add_route('/vmstop/{vmid}', res_stop)
|
||||
|
||||
res_rrd = RRDResource()
|
||||
api.add_route('vmrrd/{vmid}', res_rrd)
|
||||
|
||||
res_vnc = VNCResource()
|
||||
api.add_route('/vmvnc/{vmid}', res_vnc)
|
||||
|
||||
|
|
Loading…
Reference in a new issue