Exemple #1
0
    def index(self):
        c.objects = dict()
        c.commands = dict()
        description = dict()
        input = open('/opt/aquilon/etc/input.xml')
        etree = ETree.parse(input)
        for cmdnode in etree.getroot().findall("command"):
            name = cmdnode.attrib['name']
            if name == '*':
                continue
            description[name] = cmdnode.text
            objectmatch = re.compile('((?:add)|(?:del)|(?:update)|(?:show)|(?:search))_(.*)')
            m = objectmatch.match(name)
            if m:
                if m.group(2) not in c.objects:
                    c.objects[m.group(2)] = dict()
                c.objects[m.group(2)][m.group(1)] = name
            else:
                c.commands[name] = cmdnode.text

        # After we've partitioned all the commands into CRUD objects and
        # non-crud stuff, we may have guessed some of it wrongly...
        for obj in c.objects.keys():
            if len(c.objects[obj].keys()) < 2:
                origcmd = c.objects[obj].values()[0]
                c.commands[origcmd] = description[origcmd]
                del c.objects[obj]
 
        return render('/commands.mako')
    def log(self, log):
        if log == 'aqd':
            c.title = "Aquilon Broker"
            logfile = "/var/log/aqd.log"
        elif log == 'pylons':
            c.title = "Web Interface"
            logfile = "/var/quattor/logs/pylons/current"
        elif log == 'warehouse':
            c.title = "Datawarehouse"
            logfile = "/usr/local/var/log/couchdb/couch.log"
        else:
            c.log = log
            return render('/badlog.mako')

        c.log = tail(logfile)
        return render('/log.mako')
 def upload(self):
     cmd = ["/opt/aquilon/bin/upload-profiles"]
     p = Popen(cmd, stdout=PIPE, stderr=PIPE)
     (c.stdout, c.stderr) = p.communicate();
     if c.stderr == "":
          redirect('/')
     return render('/warehouse/upload-failed.mako')
    def krb5configure(self):
        cfg = ConfigParser.ConfigParser()
        cfg.read(["/opt/aquilon/etc/aqd.conf.defaults", "/etc/aqd.conf"])

        cmd = ["/opt/aquilon/bin/change_realm", request.params['realm']]
        env = dict()
        env["KRB5CCNAME"] = "FILE:/var/spool/tickets/cdb"
        status = subprocess.Popen(cmd, stdout=subprocess.PIPE,
                                  env=env, close_fds=True).communicate()[0];
        if status == 0:
             return redirect('krb5display')
        return render('/krbupdate-failed.mako')
    def status(self):
        cfg = ConfigParser.ConfigParser()
        cfg.read(["/opt/aquilon/etc/aqd.conf.defaults", "/etc/aqd.conf"])

        c.base = request.environ["HTTP_HOST"]
        c.base = c.base.replace(":" + request.environ["SERVER_PORT"], "")

        # Get the broker status
        d = Daemontool("aqd")
        stat = d.status()
        if stat == 200:
            c.broker = ["Daemon: aqd broker is running"]
            (stdout, stderr) = aq(["status"])
            c.brokererr = []
            if stdout:
                c.broker.extend(stdout.split("\n"));
            if stderr:
                c.brokererr.extend(stderr.split("\n"));

            (stdout, stderr) = aq(["show_host", "--all"])
            if stdout:
                c.broker.append("Managed hosts:%s" % len(stdout.split("\n")));
            if stderr:
                c.brokererr.extend(stderr.split("\n"));
            c.brokererr = []
        else:
            c.broker = ["Daemon: aqd broker is not running"]

        # And the warehouse status
        warehouse_bin = "/opt/aquilon/bin/warehouse"
        if os.path.exists(warehouse_bin):
            cmd = [warehouse_bin, "status"]
            status = subprocess.Popen(cmd, stdout=subprocess.PIPE, close_fds=True).communicate()[0];
            c.warehouse = status.split("\n");

        units = 1024*1024 # MiB
        c.units_as_text = "MiB"

        c.space = dict()

        # Look at the disk space used
        if os.path.isdir("/var/lib/pgsql/"):
            c.space["PostgreSQL"] = space_used("/var/lib/pgsql/", units)
        if os.path.isdir("/var/lib/couchdb/"):
            c.space["CouchDB"] = space_used("/var/lib/couchdb", units)
        c.space["Logs"] = space_used("/var/log", units)
        c.space["Domains"] = space_used(cfg.get("broker", "domainsdir"), units)
        c.space["Plenary"] = space_used(cfg.get("broker", "plenarydir"), units)
        c.space["Sandboxes"] = space_used(cfg.get("broker", "templatesdir"), units)
        c.space["Git King"] = space_used(cfg.get("broker", "kingdir"), units)
        c.space["Profiles"] = space_used(cfg.get("broker", "profilesdir"), units)

        return render('/status.mako')
Exemple #6
0
    def process_form(self, cmd):
        # turn request object into something to run via an aq command
        c.cmd = cmd
        opttypes = dict()
        input = open('/opt/aquilon/etc/input.xml')
        etree = ETree.parse(input)
        for cmdnode in etree.getroot().findall("command"):
            if cmdnode.attrib['name'] != cmd:
                continue
            c.text = cmdnode.text
            for group in cmdnode.findall("optgroup"):
                self.parse_group(group, opttypes)

        args = list()
        args.append(cmd)
        for key in request.params.keys():
            
            if key in opttypes:
                if opttypes[key] == 'boolean' or opttypes[key] == 'flag':
                    if request.params[key] == "1":
                        args.append("--%s" % key)
                else:
                    if request.params[key] != "":
                        args.append("--%s=%s" % (key, request.params[key]))

            elif key.startswith("_input_"):
                # This is a faked up key that we made!
                m = re.match("_input_(.*)", key)
                selector = m.group(1)
                if selector in request.params:
                    realopt = request.params[selector]
                    if realopt in opttypes and (
                        opttypes[realopt] == 'flag' or
                        opttypes[realopt] == 'boolean'):
                        args.append("--%s" % realopt)
                    else:
                        args.append("--%s=%s" % (realopt,
                                                 request.params[key]))

        (c.stdout, c.stderr) = aq(args)
        if c.stderr == "acquired compile lock\nreleasing compile lock\n":
            c.stderr = ""
        compileoutput = re.compile(".*BUILD SUCCESSFUL.*", re.DOTALL)
        if compileoutput.match(c.stderr):
            c.stdout = c.stderr
            c.stderr = ""
        if c.stderr == "" and "_return" in request.params:
            return redirect(request.params["_return"])
        return render('/formresults.mako')
Exemple #7
0
    def generate_form(self, cmd):
        c.form = list()
        c.cmd = cmd
        c.documentation = None
        if os.path.exists("/opt/aquilon/doc/html/%s.html" % cmd):
            c.documentation = "/aqdocs/%s.html" % cmd
        input = open('/opt/aquilon/etc/input.xml')
        etree = ETree.parse(input)
        for cmdnode in etree.getroot().findall("command"):
            if cmdnode.attrib['name'] != cmd:
                continue

            c.text = cmdnode.text
            for group in cmdnode.findall("optgroup"):
                self.emitfields(cmd, group)

        if "_return" in request.params:
            c.form.append("<input type='hidden' name='_return' value='%s'\>" % 
                          request.params["_return"])
        c.form.append("<input type='submit' value='%s' class='btn btn-primary' />" % cmd.replace("_", " "))

        return render('/form.mako')
 def krb5display(self):
     c.realm = get_realm()
     return render('/kerberos-setup.mako')
 def index(self):
     # Return a rendered template
     return render('/index.mako')
Exemple #10
0
 def about(self):
     return render('/credits.mako')
Exemple #11
0
    def sandboxes(self):
        # If we can, check how the sandboxes are doing
        if os.path.exists("/opt/aquilon/bin/sandbox_status_json"):
            c.sandboxes = json.loads(subprocess.Popen(["/opt/aquilon/bin/sandbox_status_json"], stdout=subprocess.PIPE, close_fds=True).communicate()[0])

        return render('/sandboxes.mako')
Exemple #12
0
 def document(self):
     """Render the error document"""
     request = self._py_object.request
     c.resp = request.environ.get('pylons.original_response')
     return render('/error.mako')
Exemple #13
0
 def index(self):
     couch = couchdb.Server()
     db = couch["profiles"]
     c.base = request.environ["HTTP_HOST"]
     c.base = c.base.replace(":" + request.environ["SERVER_PORT"], "")
     return render('/warehouse/status.mako')