def put(self, target_environment): environment = abort_if_obj_doesnt_exist(self.filter_by, str(target_environment), Environment, blame_for_all=False) self.parser.add_argument('taskid', type=str, required=True) self.parser.add_argument('status', type=str) self.parser.add_argument('response', type=str) reqdata = self.parser.parse_args() try: task = Task.objects(taskid=str(reqdata['taskid'])).first() if reqdata['status']: task.update(status=str(reqdata['status'])) if reqdata['response']: task.update(response=str(reqdata['response'])) return { 'response': 'task sucessfully updated taskid:[%s]' % reqdata['taskid'] }, 201 except Exception, e: logger.error('Error trying to update task %s' % e) abort(404, message='Error trying to update task %s' % reqdata['taskid'])
def get(self, target_environment, reqdata=None): environment = abort_if_obj_doesnt_exist(self.filter_by, str(target_environment), Environment, blame_for_all=False) if not reqdata: self.parser.add_argument('server', type=str, action='append', location='args') self.parser.add_argument('status', type=str, action='append', location='args') self.parser.add_argument('action', type=str, action='append', location='args') reqdata = self.parser.parse_args() data = [] for server in environment.servers: # filter by server if reqdata['server'] and server.name not in reqdata['server']: continue try: tasks = Task.objects(server = server.name, environment = environment.name) for task in tasks: # filter status if reqdata['status'] and task.status not in reqdata['status']: continue # filter action if reqdata['action'] and task.action not in reqdata['action']: continue data.append(TaskSchema().dump(task).data) except Exception, e: logger.warn('Error trying to retrieve task %s' % e)
def get(self, target_environment, reqdata=None): environment = abort_if_obj_doesnt_exist(self.filter_by, str(target_environment), Environment, blame_for_all=False) if not reqdata: self.parser.add_argument('server', type=str, action='append', location='args') self.parser.add_argument('status', type=str, action='append', location='args') self.parser.add_argument('action', type=str, action='append', location='args') reqdata = self.parser.parse_args() data = [] for server in environment.servers: # filter by server if reqdata['server'] and server.name not in reqdata['server']: continue try: tasks = Task.objects(server=server.name, environment=environment.name) for task in tasks: # filter status if reqdata['status'] and task.status not in reqdata[ 'status']: continue # filter action if reqdata['action'] and task.action not in reqdata[ 'action']: continue data.append(TaskSchema().dump(task).data) except Exception, e: logger.warn('Error trying to retrieve task %s' % e)
def put(self, target_environment): environment = abort_if_obj_doesnt_exist(self.filter_by, str(target_environment), Environment, blame_for_all=False) self.parser.add_argument('taskid', type=str, required=True) self.parser.add_argument('status', type=str) self.parser.add_argument('response', type=str) reqdata = self.parser.parse_args() try: task = Task.objects(taskid=str(reqdata['taskid'])).first() if reqdata['status']: task.update(status = str(reqdata['status'])) if reqdata['response']: task.update(response = str(reqdata['response'])) return { 'response': 'task sucessfully updated taskid:[%s]' % reqdata['taskid'] }, 201 except Exception, e: logger.error('Error trying to update task %s' % e) abort(404, message='Error trying to update task %s' % reqdata['taskid'])