Exemplo n.º 1
0
Arquivo: base.py Projeto: harche/wok
        def wrapper(*args, **kwargs):
            method = 'POST'
            validate_method((method), self.role_key, self.admin_methods)
            try:
                self.lookup()
                if not self.is_authorized():
                    raise UnauthorizedError('WOKAPI0009E')

                model_args = list(self.model_args)
                request = parse_request()
                validate_params(request, self, action_name)
                if action_args is not None:
                    model_args.extend(
                        request[key] if key in request.keys() else None
                        for key in action_args
                    )

                action_fn = getattr(self.model, model_fn(self, action_name))
                action_result = action_fn(*model_args)

                # log request
                reqParams = utf8_dict(self.log_args, request)
                RequestRecord(
                    self.getRequestMessage(method, action_name) % reqParams,
                    app=get_plugin_from_request(),
                    req=method,
                    user=cherrypy.session.get(USER_NAME, 'N/A')
                ).log()

                if destructive is False or \
                    ('persistent' in self.info.keys() and
                     self.info['persistent'] is True):
                    return render_fn(self, action_result)
            except MissingParameter, e:
                raise cherrypy.HTTPError(400, e.message)
Exemplo n.º 2
0
 def _get_resources(self, flag_filter):
     """
     Overriden this method, here get_list should return list dict
     which will be set to the resource, this way we avoid calling lookup
     again for each device.
     :param flag_filter:
     :return: list of resources.
     """
     try:
         get_list = getattr(self.model, model_fn(self, 'get_list'))
         idents = get_list(*self.model_args, **flag_filter)
         res_list = []
         for ident in idents:
             # internal text, get_list changes ident to unicode for sorted
             args = self.resource_args + [ident]
             res = self.resource(self.model, *args)
             res.info = ident
             # Excluding devices with mpath_member
             if res.info['fstype'] == 'mpath_member':
                 continue
             else:
                 res_list.append(res)
         return res_list
     except AttributeError:
         return []
Exemplo n.º 3
0
        def wrapper(*args, **kwargs):
            method = 'POST'
            validate_method((method), self.role_key, self.admin_methods)
            try:
                self.lookup()
                if not self.is_authorized():
                    raise UnauthorizedError('WOKAPI0009E')

                model_args = list(self.model_args)
                request = parse_request()
                validate_params(request, self, action_name)
                if action_args is not None:
                    model_args.extend(
                        request[key] if key in request.keys() else None
                        for key in action_args
                    )

                action_fn = getattr(self.model, model_fn(self, action_name))
                action_result = action_fn(*model_args)
                if destructive is False or \
                    ('persistent' in self.info.keys() and
                     self.info['persistent'] is True):
                    return render_fn(self, action_result)
            except MissingParameter, e:
                raise cherrypy.HTTPError(400, e.message)
Exemplo n.º 4
0
Arquivo: base.py Projeto: biancafc/wok
 def _get_resources(self, flag_filter):
     try:
         get_list = getattr(self.model, model_fn(self, 'get_list'))
         idents = get_list(*self.model_args, **flag_filter)
         res_list = []
         for ident in idents:
             # internal text, get_list changes ident to unicode for sorted
             args = self.resource_args + [ident]
             res = self.resource(self.model, *args)
             try:
                 res.lookup()
             except Exception as e:
                 # In case of errors when fetching a resource info, pass and
                 # log the error, so, other resources are returned
                 # Encoding error message as ident is also encoded value.
                 # This has to be done to avoid unicode error,
                 # as combination of encoded and unicode value results into
                 # unicode error.
                 wok_log.error("Problem in lookup of resource '%s'. "
                               "Detail: %s" % (ident,
                                               encode_value(e.message)))
                 continue
             res_list.append(res)
         return res_list
     except AttributeError:
         return []
Exemplo n.º 5
0
    def update(self, *args, **kargs):
        params = parse_request()

        try:
            update = getattr(self.model, model_fn(self, 'update'))
        except AttributeError:
            e = InvalidOperation('WOKAPI0003E', {'resource':
                                                 get_class_name(self)})
            raise cherrypy.HTTPError(405, e.message)
        finally:
            method = 'PUT'
            RequestRecord(
                self.getRequestMessage(method) % params,
                app=get_plugin_from_request(),
                req=method,
                user=cherrypy.session.get(USER_NAME, 'N/A')
            ).log()

        validate_params(params, self, 'update')

        args = list(self.model_args) + [params]
        ident = update(*args)
        self._redirect(ident)
        self.lookup()
        return self.get()
Exemplo n.º 6
0
 def _get_resources(self, flag_filter):
     """
     Overriden this method, here get_list should return list dict
     which will be set to the resource, this way we avoid calling lookup
     again for each device.
     :param flag_filter:
     :return: list of resources.
     """
     try:
         get_list = getattr(self.model, model_fn(self, 'get_list'))
         idents = get_list(*self.model_args, **flag_filter)
         res_list = []
         for ident in idents:
             # internal text, get_list changes ident to unicode for sorted
             args = self.resource_args + [ident]
             res = self.resource(self.model, *args)
             res.info = ident
             # Excluding devices with mpath_member
             if res.info['fstype'] == 'mpath_member':
                 continue
             else:
                 res_list.append(res)
         return res_list
     except AttributeError:
         return []
Exemplo n.º 7
0
 def _get_resources(self, flag_filter):
     try:
         get_list = getattr(self.model, model_fn(self, 'get_list'))
         idents = get_list(*self.model_args, **flag_filter)
         res_list = []
         for ident in idents:
             # internal text, get_list changes ident to unicode for sorted
             args = self.resource_args + [ident]
             res = self.resource(self.model, *args)
             try:
                 res.lookup()
             except Exception as e:
                 # In case of errors when fetching a resource info, pass and
                 # log the error, so, other resources are returned
                 # log the error, so, other resources are returned.
                 # Encoding error message as ident is also encoded value.
                 # This has to be done to avoid unicode error,
                 # as combination of encoded and unicode value results into
                 # unicode error.
                 wok_log.error("Problem in lookup of resource '%s'. "
                               "Detail: %s" % (ident,
                                               encode_value(e.message)))
                 continue
             res_list.append(res)
         return res_list
     except AttributeError:
         return []
Exemplo n.º 8
0
        def wrapper(*args, **kwargs):
            method = 'POST'
            validate_method((method), self.role_key, self.admin_methods)
            try:
                self.lookup()
                if not self.is_authorized():
                    raise UnauthorizedError('WOKAPI0009E')

                model_args = list(self.model_args)
                request = parse_request()
                validate_params(request, self, action_name)
                if action_args is not None:
                    model_args.extend(
                        request[key] if key in request.keys() else None
                        for key in action_args)

                action_fn = getattr(self.model, model_fn(self, action_name))
                action_result = action_fn(*model_args)

                # log request
                reqParams = utf8_dict(self.log_args, request)
                RequestRecord(
                    self.getRequestMessage(method, action_name) % reqParams,
                    app=get_plugin_from_request(),
                    req=method,
                    user=cherrypy.session.get(USER_NAME, 'N/A')).log()

                if destructive is False or \
                    ('persistent' in self.info.keys() and
                     self.info['persistent'] is True):
                    return render_fn(self, action_result)
            except MissingParameter, e:
                raise cherrypy.HTTPError(400, e.message)
Exemplo n.º 9
0
    def create(self, params, *args):
        try:
            create = getattr(self.model, model_fn(self, 'create'))
        except AttributeError:
            e = InvalidOperation(
                'WOKAPI0005E', {'resource': get_class_name(self)})
            raise cherrypy.HTTPError(405, str(e))

        validate_params(params, self, 'create')
        args = self.model_args + [params]
        task = create(*args)
        cherrypy.response.status = 202

        # log request
        method = 'POST'
        code = self.getRequestMessage(method)
        reqParams = utf8_dict(self.log_args, params)
        log_id = log_request(
            code,
            reqParams,
            None,
            method,
            cherrypy.response.status,
            class_name=get_class_name(self),
        )
        save_request_log_id(log_id, task['id'])

        return wok.template.render('Task', task)
Exemplo n.º 10
0
    def delete(self):
        try:
            fn = getattr(self.model, model_fn(self, 'delete'))
            task = fn(*self.model_args)
        except AttributeError:
            e = InvalidOperation(
                'WOKAPI0002E', {'resource': get_class_name(self)})
            raise cherrypy.HTTPError(405, str(e))

        cherrypy.response.status = 202

        # log request
        method = 'DELETE'
        code = self.getRequestMessage(method)
        reqParams = utf8_dict(self.log_args)
        log_id = log_request(
            code,
            reqParams,
            None,
            method,
            cherrypy.response.status,
            class_name=get_class_name(self),
        )
        save_request_log_id(log_id, task['id'])

        return wok.template.render('Task', task)
Exemplo n.º 11
0
Arquivo: base.py Projeto: lcorreia/wok
        def wrapper(*args, **kwargs):
            # status must be always set in order to request be logged.
            # use 500 as fallback for "exception not handled" cases.
            status = 500

            method = 'POST'
            validate_method((method), self.role_key, self.admin_methods)
            try:
                request = parse_request()
                validate_params(request, self, action_name)

                self.lookup()
                if not self.is_authorized():
                    raise UnauthorizedError('WOKAPI0009E')

                model_args = list(self.model_args)
                if action_args is not None:
                    model_args.extend(
                        request[key] if key in request.keys() else None
                        for key in action_args
                    )

                action_fn = getattr(self.model, model_fn(self, action_name))
                action_result = action_fn(*model_args)
                status = 200

                if destructive is False or \
                    ('persistent' in self.info.keys() and
                     self.info['persistent'] is True):
                    result = render_fn(self, action_result)
                    status = cherrypy.response.status
                    return result
            except WokException, e:
                status = e.getHttpStatusCode()
                raise cherrypy.HTTPError(status, e.message)
Exemplo n.º 12
0
 def get(self, filter_params):
     res_list = []
     try:
         get_list = getattr(self.model, model_fn(self, 'get_list'))
         res_list = get_list(*self.model_args)
     except AttributeError:
         pass
     return wok.template.render(get_class_name(self), res_list)
Exemplo n.º 13
0
Arquivo: base.py Projeto: harche/wok
 def get(self, filter_params):
     res_list = []
     try:
         get_list = getattr(self.model, model_fn(self, 'get_list'))
         res_list = get_list(*self.model_args)
     except AttributeError:
         pass
     return wok.template.render(get_class_name(self), res_list)
Exemplo n.º 14
0
 def delete(self):
     try:
         fn = getattr(self.model, model_fn(self, 'delete'))
         fn(*self.model_args)
         cherrypy.response.status = 204
     except AttributeError:
         e = InvalidOperation('WOKAPI0002E', {'resource':
                                              get_class_name(self)})
         raise cherrypy.HTTPError(405, e.message)
Exemplo n.º 15
0
    def lookup(self):
        try:
            lookup = getattr(self.model, model_fn(self, 'lookup'))
            self.info = lookup(*self.model_args)
        except AttributeError:
            self.info = {}

        cherrypy.response.status = 202
        return wok.template.render('Task', self.info)
Exemplo n.º 16
0
Arquivo: base.py Projeto: lcorreia/wok
 def delete(self):
     try:
         fn = getattr(self.model, model_fn(self, 'delete'))
         fn(*self.model_args)
         cherrypy.response.status = 204
     except AttributeError:
         e = InvalidOperation('WOKAPI0002E', {'resource':
                                              get_class_name(self)})
         raise cherrypy.HTTPError(405, e.message)
Exemplo n.º 17
0
Arquivo: base.py Projeto: harche/wok
    def lookup(self):
        try:
            lookup = getattr(self.model, model_fn(self, 'lookup'))
            self.info = lookup(*self.model_args)
        except AttributeError:
            self.info = {}

        cherrypy.response.status = 202
        return wok.template.render('Task', self.info)
Exemplo n.º 18
0
        def wrapper(*args, **kwargs):
            # status must be always set in order to request be logged.
            # use 500 as fallback for "exception not handled" cases.
            if protected is not None and protected:
                wokauth()

            details = None
            status = 500

            method = 'POST'
            validate_method(method, self.admin_methods)
            try:
                request = parse_request()
                validate_params(request, self, action_name)
                self.lookup()
                if not self.is_authorized():
                    raise UnauthorizedError('WOKAPI0009E')

                model_args = list(self.model_args)
                if action_args is not None:
                    model_args.extend(
                        request[key] if key in request.keys() else None
                        for key in action_args
                    )

                action_fn = getattr(self.model, model_fn(self, action_name))
                action_result = action_fn(*model_args)
                status = 200

                if destructive is False or (
                    'persistent' in self.info.keys(
                    ) and self.info['persistent'] is True
                ):
                    result = render_fn(self, action_result)
                    status = cherrypy.response.status

                    return result
            except WokException as e:
                details = e
                status = e.getHttpStatusCode()
                raise cherrypy.HTTPError(status, str(e))
            finally:
                # log request
                code = self.getRequestMessage(method, action_name)
                reqParams = utf8_dict(self.log_args, request)
                log_id = log_request(
                    code,
                    reqParams,
                    details,
                    method,
                    status,
                    class_name=get_class_name(self),
                    action_name=action_name,
                )
                if status == 202:
                    save_request_log_id(log_id, action_result['id'])
Exemplo n.º 19
0
Arquivo: base.py Projeto: biancafc/wok
 def delete(self):
     try:
         fn = getattr(self.model, model_fn(self, 'delete'))
         task = fn(*self.model_args)
     except AttributeError:
         e = InvalidOperation('WOKAPI0002E', {'resource':
                                              get_class_name(self)})
         raise cherrypy.HTTPError(405, e.message)
     except OperationFailed, e:
         raise cherrypy.HTTPError(500, e.message)
Exemplo n.º 20
0
 def delete(self):
     try:
         fn = getattr(self.model, model_fn(self, "delete"))
         fn(*self.model_args)
         cherrypy.response.status = 204
     except AttributeError:
         e = InvalidOperation("WOKAPI0002E", {"resource": get_class_name(self)})
         raise cherrypy.HTTPError(405, e.message)
     except OperationFailed, e:
         raise cherrypy.HTTPError(500, e.message)
Exemplo n.º 21
0
 def delete(self):
     try:
         fn = getattr(self.model, model_fn(self, 'delete'))
         task = fn(*self.model_args)
     except AttributeError:
         e = InvalidOperation('WOKAPI0002E', {'resource':
                                              get_class_name(self)})
         raise cherrypy.HTTPError(405, e.message)
     except OperationFailed, e:
         raise cherrypy.HTTPError(500, e.message)
Exemplo n.º 22
0
Arquivo: base.py Projeto: lcorreia/wok
    def delete(self):
        try:
            fn = getattr(self.model, model_fn(self, 'delete'))
            task = fn(*self.model_args)
        except AttributeError:
            e = InvalidOperation('WOKAPI0002E', {'resource':
                                                 get_class_name(self)})
            raise cherrypy.HTTPError(405, e.message)

        cherrypy.response.status = 202
        return wok.template.render("Task", task)
Exemplo n.º 23
0
    def create(self, params, *args):
        try:
            create = getattr(self.model, model_fn(self, "create"))
        except AttributeError:
            e = InvalidOperation("WOKAPI0005E", {"resource": get_class_name(self)})
            raise cherrypy.HTTPError(405, e.message)

        validate_params(params, self, "create")
        args = self.model_args + [params]
        task = create(*args)
        cherrypy.response.status = 202
        return wok.template.render("Task", task)
Exemplo n.º 24
0
    def create(self, params, *args):
        try:
            create = getattr(self.model, model_fn(self, 'create'))
        except AttributeError:
            e = InvalidOperation('WOKAPI0005E',
                                 {'resource': get_class_name(self)})
            raise cherrypy.HTTPError(405, e.message)

        validate_params(params, self, 'create')
        args = self.model_args + [params]
        task = create(*args)
        cherrypy.response.status = 202
        return wok.template.render("Task", task)
Exemplo n.º 25
0
 def _get_resources(self, flag_filter):
     try:
         get_list = getattr(self.model, model_fn(self, 'get_list'))
         idents = get_list(*self.model_args, **flag_filter)
         res_list = []
         for ident in idents:
             args = self.resource_args + [ident]
             res = self.resource(self.model, *args)
             res.info = ident
             res_list.append(res)
         return res_list
     except AttributeError:
         return []
Exemplo n.º 26
0
 def _get_resources(self, flag_filter):
     try:
         get_list = getattr(self.model, model_fn(self, 'get_list'))
         idents = get_list(*self.model_args, **flag_filter)
         res_list = []
         for ident in idents:
             # internal text, get_list changes ident to unicode for sorted
             args = self.resource_args + [ident]
             res = self.resource(self.model, *args)
             res.lookup()
             res_list.append(res)
         return res_list
     except AttributeError:
         return []
Exemplo n.º 27
0
Arquivo: base.py Projeto: harche/wok
 def _get_resources(self, flag_filter):
     try:
         get_list = getattr(self.model, model_fn(self, 'get_list'))
         idents = get_list(*self.model_args, **flag_filter)
         res_list = []
         for ident in idents:
             # internal text, get_list changes ident to unicode for sorted
             args = self.resource_args + [ident]
             res = self.resource(self.model, *args)
             res.lookup()
             res_list.append(res)
         return res_list
     except AttributeError:
         return []
Exemplo n.º 28
0
    def update(self, *args, **kargs):
        try:
            update = getattr(self.model, model_fn(self, "update"))
        except AttributeError:
            e = InvalidOperation("WOKAPI0003E", {"resource": get_class_name(self)})
            raise cherrypy.HTTPError(405, e.message)

        params = parse_request()
        validate_params(params, self, "update")

        args = list(self.model_args) + [params]
        ident = update(*args)
        self._redirect(ident)

        return self.get()
Exemplo n.º 29
0
    def create(self, params, *args):
        try:
            create = getattr(self.model, model_fn(self, "create"))
        except AttributeError:
            e = InvalidOperation("WOKAPI0005E", {"resource": get_class_name(self)})
            raise cherrypy.HTTPError(405, e.message)

        validate_params(params, self, "create")
        args = self.model_args + [params]
        name = create(*args)
        cherrypy.response.status = 201
        args = self.resource_args + [name]
        res = self.resource(self.model, *args)

        return res.get()
Exemplo n.º 30
0
    def create(self, params, *args):
        try:
            create = getattr(self.model, model_fn(self, 'create'))
        except AttributeError:
            e = InvalidOperation('WOKAPI0005E',
                                 {'resource': get_class_name(self)})
            raise cherrypy.HTTPError(405, e.message)

        validate_params(params, self, 'create')
        args = self.model_args + [params]
        name = create(*args)
        cherrypy.response.status = 201
        args = self.resource_args + [name]
        res = self.resource(self.model, *args)
        res.lookup()
        return res.get()
Exemplo n.º 31
0
    def update(self, *args, **kargs):
        try:
            update = getattr(self.model, model_fn(self, 'update'))
        except AttributeError:
            e = InvalidOperation('WOKAPI0003E',
                                 {'resource': get_class_name(self)})
            raise cherrypy.HTTPError(405, e.message)

        params = parse_request()
        validate_params(params, self, 'update')

        args = list(self.model_args) + [params]
        ident = update(*args)
        self._redirect(ident)

        return self.get()
Exemplo n.º 32
0
    def update(self, *args, **kargs):
        params = parse_request()

        try:
            update = getattr(self.model, model_fn(self, 'update'))
        except AttributeError:
            e = InvalidOperation('WOKAPI0003E', {'resource':
                                                 get_class_name(self)})
            raise cherrypy.HTTPError(405, e.message)

        validate_params(params, self, 'update')

        args = list(self.model_args) + [params]
        ident = update(*args)
        self._redirect(ident)
        cherrypy.response.status = 200
        self.lookup()
        return self.get()
Exemplo n.º 33
0
    def delete(self):
        try:
            fn = getattr(self.model, model_fn(self, 'delete'))
            task = fn(*self.model_args)
        except AttributeError:
            e = InvalidOperation('WOKAPI0002E', {'resource':
                                                 get_class_name(self)})
            raise cherrypy.HTTPError(405, e.message)

        cherrypy.response.status = 202

        # log request
        method = 'DELETE'
        code = self.getRequestMessage(method)
        reqParams = utf8_dict(self.log_args)
        log_id = log_request(code, reqParams, None, method,
                             cherrypy.response.status)
        save_request_log_id(log_id, task['id'])

        return wok.template.render("Task", task)
Exemplo n.º 34
0
    def create(self, params, *args):
        try:
            create = getattr(self.model, model_fn(self, 'create'))
        except AttributeError:
            error = 'Create is not allowed for %s' % get_class_name(self)
            raise cherrypy.HTTPError(405, error)

        validate_params(params, self, 'create')
        args = self.model_args + [params]
        name = create(*args)
        args = self.resource_args + [name]
        res = self.resource(self.model, *args)
        resp = res.get()

        if 'task_id' in res.data:
            cherrypy.response.status = 202
        else:
            cherrypy.response.status = 201

        return resp
Exemplo n.º 35
0
    def create(self, params, *args):
        try:
            create = getattr(self.model, model_fn(self, 'create'))
        except AttributeError:
            error = 'Create is not allowed for %s' % get_class_name(self)
            raise cherrypy.HTTPError(405, error)

        validate_params(params, self, 'create')
        args = self.model_args + [params]
        name = create(*args)
        args = self.resource_args + [name]
        res = self.resource(self.model, *args)
        resp = res.get()

        if 'task_id' in res.data:
            cherrypy.response.status = 202
        else:
            cherrypy.response.status = 201

        return resp
Exemplo n.º 36
0
        def wrapper(*args, **kwargs):
            validate_method(('POST'), self.role_key, self.admin_methods)
            try:
                self.lookup()
                if not self.is_authorized():
                    raise UnauthorizedError('WOKAPI0009E')

                model_args = list(self.model_args)
                if action_args is not None:
                    request = parse_request()
                    model_args.extend(request[key] for key in action_args)

                action_fn = getattr(self.model, model_fn(self, action_name))
                action_result = action_fn(*model_args)
                if destructive is False or \
                    ('persistent' in self.info.keys() and
                     self.info['persistent'] is True):
                    return render_fn(self, action_result)
            except MissingParameter, e:
                raise cherrypy.HTTPError(400, e.message)
Exemplo n.º 37
0
        def wrapper(*args, **kwargs):
            # status must be always set in order to request be logged.
            # use 500 as fallback for "exception not handled" cases.
            if protected is not None and protected:
                wokauth()

            details = None
            status = 500

            method = 'POST'
            validate_method((method), self.admin_methods)
            try:
                request = parse_request()
                validate_params(request, self, action_name)

                self.lookup()
                if not self.is_authorized():
                    raise UnauthorizedError('WOKAPI0009E')

                model_args = list(self.model_args)
                if action_args is not None:
                    model_args.extend(
                        request[key] if key in request.keys() else None
                        for key in action_args
                    )

                action_fn = getattr(self.model, model_fn(self, action_name))
                action_result = action_fn(*model_args)
                status = 200

                if destructive is False or \
                    ('persistent' in self.info.keys() and
                     self.info['persistent'] is True):
                    result = render_fn(self, action_result)
                    status = cherrypy.response.status

                    return result
            except WokException, e:
                details = e
                status = e.getHttpStatusCode()
                raise cherrypy.HTTPError(status, e.message)
Exemplo n.º 38
0
 def _get_resources(self, flag_filter):
     """
     Overriden this method, here get_list should return list dict
     which will be set to the resource, this way we avoid calling lookup
     and hence avoiding lsdasd -l command execution again for each device.
     :param flag_filter:
     :return: list of resources.
     """
     try:
         get_list = getattr(self.model, model_fn(self, 'get_list'))
         idents = get_list(*self.model_args, **flag_filter)
         res_list = []
         for ident in idents:
             # internal text, get_list changes ident to unicode for sorted
             args = self.resource_args + [ident]
             res = self.resource(self.model, *args)
             res.info = ident
             res_list.append(res)
         return res_list
     except AttributeError:
         return []
Exemplo n.º 39
0
 def _get_resources(self, flag_filter):
     """
     Overriding this method to avoid lookup call for each user,
     here get_list should return list of dict
     which will be set to the resource, this way we avoid calling lookup
     and hence avoiding augeas parsing for each user.
     :param flag_filter:
     :return: list of resources.
     """
     try:
         get_list = getattr(self.model, model_fn(self, 'get_list'))
         idents = get_list(*self.model_args, **flag_filter)
         res_list = []
         for ident in idents:
             args = self.resource_args + [ident]
             res = self.resource(self.model, *args)
             res.info = ident
             res_list.append(res)
         return res_list
     except AttributeError:
         return []
Exemplo n.º 40
0
 def _get_resources(self, flag_filter):
     """
     Overriden this method, here get_list should return list dict
     which will be set to the resource, this way we avoid calling lookup
     and hence avaoding lscss command execution again for each device.
     :param flag_filter:
     :return: list of resources.
     """
     try:
         get_list = getattr(self.model, model_fn(self, 'get_list'))
         idents = get_list(*self.model_args, **flag_filter)
         res_list = []
         for ident in idents:
             # internal text, get_list changes ident to unicode for sorted
             args = self.resource_args + [ident]
             res = self.resource(self.model, *args)
             res.info = ident
             res_list.append(res)
         return res_list
     except AttributeError:
         return []
Exemplo n.º 41
0
 def _get_resources(self, flag_filter):
     """
     Overriding this method to avoid lookup call for each user,
     here get_list should return list of dict
     which will be set to the resource, this way we avoid calling lookup
     and hence avoiding augeas parsing for each user.
     :param flag_filter:
     :return: list of resources.
     """
     try:
         get_list = getattr(self.model, model_fn(self, 'get_list'))
         idents = get_list(*self.model_args, **flag_filter)
         res_list = []
         for ident in idents:
             args = self.resource_args + [ident]
             res = self.resource(self.model, *args)
             res.info = ident
             res_list.append(res)
         return res_list
     except AttributeError:
         return []
Exemplo n.º 42
0
    def create(self, params, *args):
        try:
            create = getattr(self.model, model_fn(self, 'create'))
        except AttributeError:
            e = InvalidOperation('WOKAPI0005E', {'resource':
                                                 get_class_name(self)})
            raise cherrypy.HTTPError(405, e.message)

        validate_params(params, self, 'create')
        args = self.model_args + [params]
        task = create(*args)
        cherrypy.response.status = 202

        # log request
        method = 'POST'
        code = self.getRequestMessage(method)
        reqParams = utf8_dict(self.log_args, params)
        log_id = log_request(code, reqParams, None, method,
                             cherrypy.response.status)
        save_request_log_id(log_id, task['id'])

        return wok.template.render("Task", task)
Exemplo n.º 43
0
 def get(self, filter_params):
     res_list = []
     get_list = getattr(self.model, model_fn(self, 'get_list'))
     res_list = get_list(*self.model_args, **filter_params)
     return template.render(get_class_name(self), res_list)
Exemplo n.º 44
0
Arquivo: base.py Projeto: harche/wok
 def lookup(self):
     try:
         lookup = getattr(self.model, model_fn(self, 'lookup'))
         self.info = lookup(*self.model_args)
     except AttributeError:
         self.info = {}
Exemplo n.º 45
0
 def lookup(self):
     try:
         lookup = getattr(self.model, model_fn(self, 'lookup'))
         self.info = lookup(*self.model_args)
     except AttributeError:
         self.info = {}
Exemplo n.º 46
0
 def get(self, filter_params):
     res_list = []
     get_list = getattr(self.model, model_fn(self, 'get_list'))
     res_list = get_list(*self.model_args, **filter_params)
     return template.render(get_class_name(self), res_list)