def commandRun(request): client = request.GET.get("client") command = Command.objects.get(id=request.GET.get("commandId")) targetType = request.GET.get("targetType") target = request.GET.get("target") arguments = request.GET.get("arguments") cmd = request.GET.get("cmd") arg = [] kwarg = {} if arguments: arr = arguments.split('|') for param in arr: kw = param.split('=') if len(kw) > 1: kwarg[kw[0]] = kw[1] else: arg.append(param) api = SaltAPI() if client == "runner" or client == "runner_async" or client == "wheel": rsp = api.run(client, command.fun, arg, kwarg) else: rsp = api.cmd(client, command.fun, targetType, target, arg, kwarg) if client == "local_async" or client == "runner_async": data = rsp['return'][0]["jid"] record = CommandRecord(cmd=cmd, jid=data, result="") record.save() else: data = rsp['return'][0] record = CommandRecord(cmd=cmd, jid="", result=json.dumps(data)) record.save() return JsonResponse({'errno': 0, 'error': '', 'data': data})
def moduleFunListSync(request): errno = 0 try: api = SaltAPI() moduleTypes = [Module.execution, Module.runner, Module.wheel] for moduleType in moduleTypes: rsp = api.run(client='runner', fun="doc." + moduleType) docs = rsp['return'][0] for fun in docs: arr = fun.split('.') module, created = Module.objects.get_or_create(type=moduleType, name=arr[0]) command, created = Command.objects.get_or_create(module=module, fun=fun) if not command.doc: command.doc = docs[fun] command.save() except Exception: errno = 1 return JsonResponse({'errno': errno, 'error': '', 'data': ''})