class CreateSchedulerEntry(TaskApiView): summary = 'Create scheduler entry' description = 'Create scheduler entry' definitions = { 'CreateSchedulerEntryResponseSchema': CreateSchedulerEntryResponseSchema, 'CreateSchedulerEntryRequestSchema': CreateSchedulerEntryRequestSchema } parameters = SwaggerHelper().get_parameters(CreateSchedulerEntryBodyRequestSchema) parameters_schema = CreateSchedulerEntryRequestSchema responses = SwaggerApiView.setResponses({ 202: { 'description': 'success', 'schema': CreateSchedulerEntryResponseSchema } }) def post(self, controller, data, *args, **kwargs): scheduler = controller.get_scheduler() data = get_value(data, 'schedule', None, exception=True) name = get_value(data, 'name', None, exception=True) task = get_value(data, 'task', None, exception=True) args = get_value(data, 'args', None) kwargs = get_value(data, 'kwargs', None) options = get_value(data, 'options', {}) relative = get_value(data, 'relative', None) # get schedule schedule = get_value(data, 'schedule', None, exception=True) resp = scheduler.create_update_entry(name, task, schedule, args=args, kwargs=kwargs, options=options, relative=relative) return {'name': name}, 202
class CreateToken(SwaggerApiView): summary = 'Create keyauth token' description = 'Create keyauth token' tags = ['authorization'] definitions = { 'CreateTokenRequestSchema': CreateTokenRequestSchema, 'CreateTokenResponseSchema': CreateTokenResponseSchema } parameters = SwaggerHelper().get_parameters(CreateTokenBodyRequestSchema) parameters_schema = CreateTokenRequestSchema responses = SwaggerApiView.setResponses( {200: { 'description': 'success', 'schema': CreateTokenResponseSchema }}) def post(self, controller, data, *args, **kwargs): innerperms = [(1, 1, 'auth', 'objects', 'ObjectContainer', '*', 1, '*'), (1, 1, 'auth', 'role', 'RoleContainer', '*', 1, '*'), (1, 1, 'auth', 'user', 'UserContainer', '*', 1, '*')] operation.perms = innerperms res = controller.create_keyauth_token(**data) resp = res return resp
class GetSchedulerEntry(TaskApiView): summary = 'Get scheduler entry' description = 'Get scheduler entry' definitions = { 'GetSchedulerEntryResponseSchema': GetSchedulerEntryResponseSchema, } parameters = SwaggerHelper().get_parameters(GetApiObjectRequestSchema) responses = SwaggerApiView.setResponses({ 200: { 'description': 'success', 'schema': GetSchedulerEntryResponseSchema } }) def get(self, controller, data, oid, *args, **kwargs): scheduler = controller.get_scheduler() data = scheduler.get_entries(name=oid)[0] if data is not None: res = data.info() else: raise ApiManagerError('Scheduler entry %s not found' % oid, code=404) resp = { 'schedule': res } return resp
class PurgeAllTasks(TaskApiView): definitions = {} responses = SwaggerApiView.setResponses({204: {'description': 'success'}}) def delete(self, controller, data, *args, **kwargs): """ Delete all tasks Delete all tasks """ task_manager = controller.get_task_manager() resp = task_manager.delete_task_instances() return (resp, 204)
class DeleteTask(TaskApiView): definitions = { 'GetApiObjectRequestSchema': GetApiObjectRequestSchema, } parameters = SwaggerHelper().get_parameters(GetApiObjectRequestSchema) responses = SwaggerApiView.setResponses({204: {'description': 'success'}}) def delete(self, controller, data, oid, *args, **kwargs): """ Delete task Delete task by id """ task_manager = controller.get_task_manager() resp = task_manager.delete_task_instance(oid) return (resp, 204)
class ServerInfo(SwaggerApiView): summary = 'Server info api' description = 'Server info api' tags = ['base'] definitions = { 'ServerInfoResponseSchema': ServerInfoResponseSchema, } responses = SwaggerApiView.setResponses( {200: { 'description': 'success', 'schema': ServerInfoResponseSchema }}) def get(self, controller, data, *args, **kwargs): resp = controller.info() return resp
class DeleteEndpoint(SwaggerApiView): summary = 'Delete catalog endpoint' description = 'Delete catalog endpoint' tags = ['directory'] definitions = {} parameters = SwaggerHelper().get_parameters(GetApiObjectRequestSchema) responses = SwaggerApiView.setResponses({ 204: { 'description': 'no response' } }) def delete(self, controller, data, oid, *args, **kwargs): endpoint = controller.get_endpoint(oid) resp = endpoint.delete() return resp, 204
class DeleteSchedulerEntry(TaskApiView): summary = 'Delete scheduler entry' description = 'Delete scheduler entry' definitions = {} parameters = SwaggerHelper().get_parameters(GetApiObjectRequestSchema) responses = SwaggerApiView.setResponses({ 204: { 'description': 'no response' } }) def delete(self, controller, data, oid, *args, **kwargs): scheduler = controller.get_scheduler() # name = get_value(data, 'name', None, exception=True) resp = scheduler.remove_entry(oid) return resp, 204
class ManagerActiveQueues(TaskApiView): summary = 'Workers active queues' description = 'Workers active queues' definitions = { 'ManagerActiveQueuesResponseSchema': ManagerActiveQueuesResponseSchema, } responses = SwaggerApiView.setResponses({ 200: { 'description': 'success', 'schema': ManagerActiveQueuesResponseSchema } }) def get(self, controller, data, *args, **kwargs): task_manager = controller.get_task_manager() resp = task_manager.get_active_queues() return {'workers_queues': resp}
class RunJobTest(TaskApiView): definitions = { 'RunJobTestBodyParamRequestSchema': RunJobTestBodyParamRequestSchema, 'RunJobTestBodyRequestSchema': RunJobTestBodyRequestSchema } parameters = SwaggerHelper().get_parameters(RunJobTestBodyRequestSchema) parameters_schema = RunJobTestBodyParamRequestSchema responses = SwaggerApiView.setResponses( {201: { 'description': 'success', 'schema': CrudApiJobResponseSchema }}) def post(self, controller, data, *args, **kwargs): task_manager = controller.get_task_manager() job = task_manager.run_jobtest(data) return {'jobid': job.id}, 201
class ManagerPing(TaskApiView): definitions = { 'ManagerPingResponseSchema': ManagerPingResponseSchema, } responses = SwaggerApiView.setResponses( {200: { 'description': 'success', 'schema': ManagerPingResponseSchema }}) def get(self, controller, data, *args, **kwargs): """ Worker pings Ping all active workers """ task_manager = controller.get_task_manager() resp = task_manager.ping() return {'workers_ping': resp}
class GetTasksCount(TaskApiView): definitions = { 'ApiObjecCountResponseSchema': ApiObjecCountResponseSchema, } responses = SwaggerApiView.setResponses({ 200: { 'description': 'success', 'schema': ApiObjecCountResponseSchema } }) def get(self, controller, data, *args, **kwargs): """ Task count Get count of all tasks """ task_manager = controller.get_task_manager() resp = task_manager.count_all_tasks() return resp
class ManagerStats(TaskApiView): definitions = { 'ManagerStatsResponseSchema': ManagerStatsResponseSchema, } responses = SwaggerApiView.setResponses({ 200: { 'description': 'success', 'schema': ManagerStatsResponseSchema } }) def get(self, controller, data, *args, **kwargs): """ Worker statistics Get all active workers statistics """ task_manager = controller.get_task_manager() resp = task_manager.stats() return {'workers_stats': resp}
class GetCatalog(SwaggerApiView): summary = 'Get catalog' description = 'Get catalog' tags = ['directory'] definitions = { 'GetCatalogResponseSchema': GetCatalogResponseSchema, } parameters = SwaggerHelper().get_parameters(GetApiObjectRequestSchema) responses = SwaggerApiView.setResponses({ 200: { 'description': 'success', 'schema': GetCatalogResponseSchema } }) def get(self, controller, data, oid, *args, **kwargs): catalog = controller.get_catalog(oid) res = catalog.detail() resp = {'catalog':res} return resp
class ListCatalogs(SwaggerApiView): summary = 'List catalogs' description = 'List catalogs' tags = ['directory'] definitions = { 'ListCatalogsResponseSchema': ListCatalogsResponseSchema, } parameters = SwaggerHelper().get_parameters(ListCatalogsRequestSchema) parameters_schema = ListCatalogsRequestSchema responses = SwaggerApiView.setResponses({ 200: { 'description': 'success', 'schema': ListCatalogsResponseSchema } }) def get(self, controller, data, *args, **kwargs): catalogs, total = controller.get_catalogs(**data) res = [r.info() for r in catalogs] return self.format_paginated_response(res, 'catalogs', total, **data)
class CreateCatalog(SwaggerApiView): summary = 'Create catalog' description = 'Create catalog' tags = ['directory'] definitions = { 'CreateCatalogRequestSchema': CreateCatalogRequestSchema, 'CrudApiObjectResponseSchema':CrudApiObjectResponseSchema } parameters = SwaggerHelper().get_parameters(CreateCatalogBodyRequestSchema) parameters_schema = CreateCatalogRequestSchema responses = SwaggerApiView.setResponses({ 201: { 'description': 'success', 'schema': CrudApiObjectResponseSchema } }) def post(self, controller, data, *args, **kwargs): resp = controller.add_catalog(**data.get('catalog')) return {'uuid': resp}, 201
class RunTestTask(TaskApiView): summary = 'Run test task' description = 'Run test task' definitions = { 'RunTestTaskBodyParamRequestSchema': RunTestTaskBodyParamRequestSchema, 'RunTestTaskBodyRequestSchema': RunTestTaskBodyRequestSchema } parameters = SwaggerHelper().get_parameters(RunTestTaskBodyRequestSchema) parameters_schema = RunTestTaskBodyParamRequestSchema responses = SwaggerApiView.setResponses({ 201: { 'description': 'success', 'schema': CrudApiJobResponseSchema } }) def post(self, controller, data, *args, **kwargs): task_manager = controller.get_task_manager() task = task_manager.run_test_task(data) return {'taskid': task.id}, 201
class GetTasksDefinition(TaskApiView): definitions = { 'GetTasksDefinitionResponseSchema': GetTasksDefinitionResponseSchema, } responses = SwaggerApiView.setResponses({ 200: { 'description': 'success', 'schema': GetTasksDefinitionResponseSchema } }) def get(self, controller, data, *args, **kwargs): """ Get task definitions List all task definitions """ task_manager = controller.get_task_manager() res = task_manager.get_registered_tasks() resp = {'task_definitions': res, 'count': len(res)} return resp
class UpdateEndpoint(SwaggerApiView): summary = 'Update catalog endpoint' description = 'Update catalog endpoint' tags = ['directory'] definitions = { 'UpdateEndpointRequestSchema': UpdateEndpointRequestSchema, 'CrudApiObjectResponseSchema': CrudApiObjectResponseSchema } parameters = SwaggerHelper().get_parameters(UpdateEndpointBodyRequestSchema) parameters_schema = UpdateEndpointRequestSchema responses = SwaggerApiView.setResponses({ 200: { 'description': 'success', 'schema': CrudApiObjectResponseSchema } }) def put(self, controller, data, oid, *args, **kwargs): endpoint = controller.get_endpoint(oid) resp = endpoint.update(**data.get('endpoint')) return {'uuid': resp}
class GetTasks(TaskApiView): summary = 'List task instances' description = 'List task instances' definitions = { 'GetTasksResponseSchema': GetTasksResponseSchema, 'GetTasksRequestSchema': GetTasksRequestSchema } parameters = SwaggerHelper().get_parameters(GetTasksRequestSchema) parameters_schema = GetTasksRequestSchema responses = SwaggerApiView.setResponses({ 200: { 'description': 'success', 'schema': GetTasksResponseSchema } }) def get(self, controller, data, *args, **kwargs): objs, total = controller.get_task_manager().get_tasks(**data) res = [r.info() for r in objs] return self.format_paginated_response(res, 'task_instances', total, **data)
class GetSchedulerEntries(TaskApiView): definitions = { 'GetSchedulerEntriesResponseSchema': GetSchedulerEntriesResponseSchema, } responses = SwaggerApiView.setResponses({ 200: { 'description': 'success', 'schema': GetSchedulerEntriesResponseSchema } }) def get(self, controller, data, *args, **kwargs): """ List scheduler entries Call this api to list all the scheduler entries """ scheduler = controller.get_scheduler() data = scheduler.get_entries() res = [i.info() for i in data] resp = {'schedules': res, 'count': len(res)} return resp
class GetCatalogPerms(SwaggerApiView): summary = 'Get catalog permissions' description = 'Get catalog permissions' tags = ['directory'] definitions = { 'ApiObjectPermsRequestSchema': ApiObjectPermsRequestSchema, 'ApiObjectPermsResponseSchema': ApiObjectPermsResponseSchema, } parameters = SwaggerHelper().get_parameters(ApiObjectPermsRequestSchema) parameters_schema = PaginatedRequestQuerySchema responses = SwaggerApiView.setResponses({ 200: { 'description': 'success', 'schema': ApiObjectPermsResponseSchema } }) def get(self, controller, data, oid, *args, **kwargs): catalog = controller.get_catalog(oid) res, total = catalog.authorization(**data) return self.format_paginated_response(res, 'perms', total, **data)
class SimpleHttpLogin(SwaggerApiView): summary = 'Login user with simple http authentication' description = 'Login user with simple http authentication' tags = ['authorization'] definitions = { 'SimpleHttpLoginRequestSchema': SimpleHttpLoginRequestSchema, 'SimpleHttpLoginResponseSchema': SimpleHttpLoginResponseSchema } parameters = SwaggerHelper().get_parameters(SimpleHttpLoginBodyRequestSchema) parameters_schema = SimpleHttpLoginRequestSchema responses = SwaggerApiView.setResponses({ 200: { 'description': 'success', 'schema': SimpleHttpLoginResponseSchema } }) def post(self, controller, data, *args, **kwargs): user = get_value(data, 'user', None, exception=True) password = get_value(data, 'password', None, exception=True) login_ip = get_value(data, 'login-ip', None, exception=True) try: name_domain = user.split('@') name = name_domain[0] try: domain = name_domain[1] except: domain = 'local' except: ApiManagerError('User must be <user>@<domain>') innerperms = [ (1, 1, 'auth', 'objects', 'ObjectContainer', '*', 1, '*'), (1, 1, 'auth', 'role', 'RoleContainer', '*', 1, '*'), (1, 1, 'auth', 'user', 'UserContainer', '*', 1, '*')] operation.perms = innerperms resp = controller.simple_http_login(name, domain, password, login_ip) return resp
class QueryTask(TaskApiView): definitions = { 'QueryTaskResponseSchema': QueryTaskResponseSchema, 'QueryTaskRequestSchema': QueryTaskRequestSchema, } parameters = SwaggerHelper().get_parameters(QueryTaskRequestSchema) parameters_schema = QueryTaskRequestSchema responses = SwaggerApiView.setResponses( {200: { 'description': 'success', 'schema': QueryTaskResponseSchema }}) def get(self, controller, data, oid, *args, **kwargs): """ Get task info Query single task by id and return description fields """ task_manager = controller.get_task_manager() res = task_manager.query_task(oid, chain=data.get('chain')) resp = {'task_instance': res} return resp
class GetTrace(TaskApiView): summary = 'Get task instance trace' description = 'Get task instance trace' definitions = { 'GetTraceResponseSchema': GetTraceResponseSchema, 'GetTaskRequestSchema': GetTaskRequestSchema, } parameters = SwaggerHelper().get_parameters(GetTaskRequestSchema) parameters_schema = GetTaskRequestSchema responses = SwaggerApiView.setResponses({ 200: { 'description': 'success', 'schema': GetTraceResponseSchema } }) def get(self, controller, data, oid, *args, **kwargs): task_manager = controller.get_task_manager() entity_class_name = data.get('entity_class') res = task_manager.get_task(oid, entity_class_name=entity_class_name) resp = {'task_trace': res.get_trace()} return resp
class GetAllTasks(TaskApiView): definitions = { 'GetAllTasksResponseSchema': GetAllTasksResponseSchema, 'GetAllTasksRequestSchema': GetAllTasksRequestSchema } parameters = SwaggerHelper().get_parameters(GetAllTasksRequestSchema) parameters_schema = GetAllTasksRequestSchema responses = SwaggerApiView.setResponses( {200: { 'description': 'success', 'schema': GetAllTasksResponseSchema }}) def get(self, controller, data, *args, **kwargs): """ List task instances Call this api to list all the task instances """ task_manager = controller.get_task_manager() res = task_manager.get_all_tasks(details=True, **data) resp = {'task_instances': res, 'count': len(res)} return resp
class GetTaskGraph(TaskApiView): definitions = { 'GetTaskGraphResponseSchema': GetTaskGraphResponseSchema, 'GetApiObjectRequestSchema': GetApiObjectRequestSchema, } parameters = SwaggerHelper().get_parameters(GetApiObjectRequestSchema) responses = SwaggerApiView.setResponses({ 200: { 'description': 'success', 'schema': GetTaskGraphResponseSchema } }) def get(self, controller, data, oid, *args, **kwargs): """ Get task graph Get list of nodes and link that represents the task childs graph """ task_manager = controller.get_task_manager() res = task_manager.get_task_graph(oid) resp = {'task_instance_graph': res} return resp
class CreateEndpoint(SwaggerApiView): summary = 'Create catalog endpoint' description = 'Create catalog endpoint' tags = ['directory'] definitions = { 'CreateEndpointRequestSchema': CreateEndpointRequestSchema, 'CrudApiObjectResponseSchema': CrudApiObjectResponseSchema } parameters = SwaggerHelper().get_parameters(CreateEndpointBodyRequestSchema) parameters_schema = CreateEndpointRequestSchema responses = SwaggerApiView.setResponses({ 201: { 'description': 'success', 'schema': CrudApiObjectResponseSchema } }) def post(self, controller, data, *args, **kwargs): data = data.get('endpoint') endpoint = data.pop('catalog') endpoint_obj = controller.get_catalog(endpoint) resp = endpoint_obj.add_endpoint(**data) return ({'uuid':resp}, 201)