示例#1
0
 def details(self, id):
     with db_session(self.dburl) as session:
         macros = session.query(ParametricJobs)\
                         .filter(ParametricJobs.request_id == id)\
                         .all()
         if not macros:
             return "Error: No macro information!"
         return self.template_env.get_template(
             'html/subtables.html').render({'macros': macros})
示例#2
0
    def DELETE(self, reqid):  # pylint: disable=C0103
        """REST Delete method."""
        print "IN DELETE: reqid=(%s)" % reqid

        if cherrypy.request.verified_user.admin:
            with db_session(self.dburl) as session:
                session.query(Requests)\
                       .filter(Requests.id == reqid)\
                       .delete(synchronize_session=False)
        return self.GET()
示例#3
0
    def PUT(self, reqid, **kwargs):  # pylint: disable=C0103
        """REST Put method."""
        print "IN PUT: reqid=(%s)" % reqid, kwargs
        requester = cherrypy.request.verified_user

        with db_session(self.dburl) as session:
            query = session.query(Requests).filter(Requests.id == reqid)
            if not requester.admin:
                query = query.filter(Requests.requester_id == requester.id)
            query.update(kwargs)
示例#4
0
    def GET(self):  # pylint: disable=C0103
        """
        REST GET Method.

        Returns:
            str: The rendered HTML containing the users admin status as toggles.
        """
        with db_session(self._users_dburl) as session:
            return self._template_env.get_template('html/admins.html')\
                                     .render({'users': [
                                         User(user.id, user.admin, name_from_dn(user.dn))
                                         for user in session.query(Users).all()
                                     ]})
示例#5
0
    def PUT(self, user_id, admin):  # pylint: disable=C0103
        """
        REST PUT Method.

        Args:
            user_id (str): The id number of the user to modify
            admin (str): The status of the admin flag true/false
                         (note passed through un-capitalised.)
        """
        print "IN PUT(Admins)", user_id, admin
        # could use ast.literal_eval(admin.capitalize()) but not sure if I trust it yet
        admin = (admin.lower() == 'true')
        with db_session(self._users_dburl) as session:
            session.query(Users).filter(Users.id == int(user_id)).update(
                {'admin': admin})
示例#6
0
    def GET(self, reqid=None):  # pylint: disable=C0103
        """REST Get method."""
        print "IN GET: reqid=(%s)" % reqid
        requester = cherrypy.request.verified_user

        with db_session(self.dburl) as session:
            if reqid is None:
                if not requester.admin:
                    query = session.query(Requests.id,
                                          Requests.request_date,
                                          Requests.sim_lead,
                                          Requests.status,
                                          Requests.description)\
                                   .filter(Requests.requester_id == requester.id)
                    return json.dumps({
                        'data': [
                            dict(zip(COLUMNS, request))
                            for request in query.all()
                        ]
                    })
                query = session.query(Requests.id,
                                      Requests.request_date,
                                      Requests.sim_lead,
                                      Requests.status,
                                      Requests.description,
                                      Users.dn)\
                               .join(Users, Requests.requester_id == Users.id)
                data = []
                for request in query.all():
                    tmp = dict(zip(COLUMNS, request))
                    tmp['requester'] = name_from_dn(request.dn)
                    data.append(tmp)

                return json.dumps({'data': data})

            table = html.HTML().table(border='1')
            request = session.query(Requests).filter(
                Requests.id == reqid).first()
            if request is not None:
                for colname, value in request.iteritems():
                    row = table.tr()
                    row.td(colname)
                    row.td(str(value))
        return str(table)
示例#7
0
    def POST(self, **kwargs):  # pylint: disable=C0103
        """REST Post method."""
        print "IN POST", kwargs
        kwargs['request_date'] = datetime.now().strftime('%d/%m/%Y')
        kwargs['status'] = 'Requested'
        selected_macros = kwargs.pop('selected_macros', [])
        if not isinstance(selected_macros, list):
            selected_macros = [selected_macros]

        with db_session(self.dburl) as session:
            request = Requests(requester_id=cherrypy.request.verified_user.id,
                               request_date=kwargs['request_date'],
                               source=kwargs['source'],
                               detector=kwargs['detector'],
                               sim_lead=kwargs['sim_lead'],
                               status=kwargs['status'],
                               description=kwargs['description'])
            session.add(request)
            session.flush()
            session.refresh(request)

            macros = []
            for macro in selected_macros:
                path, njobs, nevents, seed = macro.split()
                macros.append(
                    ParametricJobs(
                        request_id=request.id,
                        status="Requested",
                        macro=path,
                        tag=kwargs.pop('tag'),
                        app=kwargs.pop('app'),
                        request=kwargs.pop('request', None),
                        reduction_version=kwargs.pop('reduction_version'),
                        reduced_lfns=[],
                        njobs=njobs,
                        nevents=nevents,
                        seed=seed,
                        app_version=kwargs.pop('app_version'),
                        dirac_jobs={}))

            session.add_all(macros)
        return self.GET()
示例#8
0
    def index(self):
        """Return the index page."""
        data = {'user': cherrypy.request.verified_user}
        data['index_script'] = self.template_env.get_template('javascript/index.js')\
                                                .render(data)
        with db_session(self.dburl) as session:
            gangad = session.query(Services).filter(
                Services.name == 'gangad').one_or_none()
            if gangad is None:
                data.update({
                    'gangad_status': 'Not in DB!',
                    'gangad_status_colour': 'red'
                })
                return self.template_env.get_template(
                    'html/index.html').render(data)

            nongangad_services = session.query(Services).filter(
                Services.name != 'gangad').all()
            out_of_date = (datetime.now() -
                           gangad.timestamp).total_seconds() > 30. * MINS
            if gangad.status == 'down' or out_of_date:
                nongangad_services = (Services(name=service.name,
                                               status='unknown')
                                      for service in nongangad_services)
                if gangad.status != 'down':
                    gangad = Services(name=gangad.name,
                                      status='stuck%3F')  # %3F = ?

            data.update({
                'gangad_status':
                gangad.status,
                'gangad_status_colour':
                SERVICE_COLOUR_MAP[gangad.status]
            })
            for service in nongangad_services:
                data.update({
                    service.name + '_status':
                    service.status,
                    service.name + '_status_colour':
                    SERVICE_COLOUR_MAP[service.status]
                })
        return self.template_env.get_template('html/index.html').render(data)
示例#9
0
    def __call__(self, path):
        """Dispatch."""
        required_headers = set(['Ssl-Client-S-Dn', 'Ssl-Client-I-Dn', 'Ssl-Client-Verify'])
        missing_headers = required_headers.difference(cherrypy.request.headers.iterkeys())
        if missing_headers:
            raise cherrypy.HTTPError(401, 'Unauthorized: Incomplete certificate information '
                                     'available, required: %s' % list(missing_headers))

        client_dn, client_ca = apache_client_convert(cherrypy.request.headers['Ssl-Client-S-Dn'],
                                                     cherrypy.request.headers['Ssl-Client-I-Dn'])
        client_verified = cherrypy.request.headers['Ssl-Client-Verify']
        if client_verified != 'SUCCESS':
            raise cherrypy.HTTPError(401, 'Unauthorized: Cert not verified for user DN: %s, CA: %s.'
                                     % (client_dn, client_ca))

        create_db(self._users_dburl)
        with db_session(self._users_dburl) as session:
            users = session.query(Users)\
                           .filter(Users.dn == client_dn)\
                           .filter(Users.ca == client_ca)\
                           .all()
            if not users:
                raise cherrypy.HTTPError(403, 'Forbidden: Unknown user. user: (%s, %s)'
                                         % (client_dn, client_ca))
            if len(users) > 1:
                raise cherrypy.HTTPError(500, 'Internal Server Error: Duplicate user detected. user: (%s, %s)'
                                         % (client_dn, client_ca))
            if users[0].suspended:
                raise cherrypy.HTTPError(403, 'Forbidden: User is suspended by VO. user: (%s, %s)'
                                         % (client_dn, client_ca))

            if self._admin_only and not users[0].admin:
                raise cherrypy.HTTPError(403, 'Forbidden: Admin users only')

            cherrypy.request.verified_user = VerifiedUser(users[0].id,
                                                          users[0].dn,
                                                          users[0].ca,
                                                          users[0].admin)
        return self._dispatcher(path)