diff --git a/site.conf b/site.conf new file mode 100644 index 0000000..90dbfec --- /dev/null +++ b/site.conf @@ -0,0 +1,6 @@ +[global] +server.socket_host: '127.0.0.1' +server.socket_port: 8080 +server.thread_pool: 4 +log.screen: False +engine.autoreload.on: False diff --git a/virtpool.py b/virtpool.py new file mode 100644 index 0000000..791952b --- /dev/null +++ b/virtpool.py @@ -0,0 +1,74 @@ +#!/usr/bin/python3 +"""Agent for setting up accounts for sysdeploy clients""" +# pylint: disable=subprocess-run-check,too-few-public-methods +import os +import sys + +import cherrypy +import libvirt + + +class Client(): + """Main manager class""" + uris = { + 'qemu+ssh://pool@reserve.homedevops/system', + 'qemu+ssh://root@check2.homedevops/system', + 'qemu+ssh://root@check3.homedevops/system' + } + + def __init__(self): + self.status = {} + self.connections = {} + for i in self.uris: + self.connections[i] = libvirt.open(i) + + @cherrypy.expose + def getavailable(self): + out = "" + for n, c in self.connections.items(): + # cmap = c.getCPUMap() + # out += "CPUs: {}".format(str(cmap[0])) + # out += "Available: {}".format(str(cmap[1])) + nodeinfo = c.getInfo() + mem = nodeinfo[1] + cpus = nodeinfo[2] + usedmem = 0 + usedcpus = 0 + + domain_ids = c.listDomainsID() + for did in domain_ids: + dom = c.lookupByID(did) + state, maxmem, mem2, cpus, cput = dom.info() + usedmem += maxmem/1024 + usedcpus += cpus + + out += "{}: {}/{} CPUs free,{}MiB/{}MiB memory free
\n".format( + n, + cpus - usedcpus, cpus, + str((mem - usedmem)), + str(mem)) + return out + + +ROOT = Client() +CONF = os.path.join(os.path.dirname(__file__), 'site.conf') + +if __name__ == '__main__': + # cherrypy.config.update(CONF) + cherrypy.server.socket_host = '127.0.0.1' + cherrypy.server.socket_port = 8080 + ENGINE = cherrypy.engine + # cherrypy.process.plugins.Daemonizer(engine).subscribe() + # cherrypy.process.plugins.DropPrivileges( + # ENGINE, uid='cherrypy', gid='cherrypy').subscribe() + cherrypy.tree.mount(Client()) + if hasattr(ENGINE, "signal_handler"): + ENGINE.signal_handler.subscribe() + if hasattr(ENGINE, "console_control_handler"): + ENGINE.console_control_handler.subscribe() + try: + ENGINE.start() + except Exception: # pylint: disable=broad-except + sys.exit(1) + else: + ENGINE.block()