def get_server_asset_info(tgt,url,user,passwd,device): ''' Salt API得到资产信息,进行格式化输出 ''' cf = ConfigParser.ConfigParser() cf.read("config.ini") global asset_info info = [] sapi = SaltAPI(url=url,username=user,password=passwd) ret = sapi.remote_noarg_execution(tgt,'grains.items') manufacturer = ret['manufacturer'] info.append(manufacturer) productname = ret['productname'] info.append(productname) serialnumber = ret['serialnumber'] info.append(serialnumber) cpu_model = ret['cpu_model'] info.append(cpu_model) num_cpus = int(ret['num_cpus']) info.append(num_cpus) num_gpus = int(ret['num_gpus']) info.append(num_gpus) mem_total = ret['mem'] info.append(mem_total) disk = ret['disk'] info.append(disk) id = ret['id'] info.append(id) lan_ip = ret['ip4_interfaces'][device] info.append(lan_ip) sys_ver = ret['os'] + ret['osrelease'] + '-' + ret['osarch'] info.append(sys_ver) asset_info.append(info) return asset_info
def salt_deploy(request): print request.POST cmd = { 'aliyum': 'aliyum.aliyum', 'jdk': 'Jdk_Tomcat.jdk_install', 'tomcat1.8': 'Jdk_Tomcat.tomcat8_install', 'nginx': 'nginx.nginx_install', 'nginx.conf': 'nginx.nginx_conf' } fun = 'state.sls' result = [] error = "" Accepted_Keys = SaltAPI().list_all_key()[0] if request.method == 'POST': select_app = request.POST.get('select_app') match = request.POST.getlist('match[]') ssh_id = request.POST.get('ssh_id') if select_app == '' and ssh_id != '': ssh_id = request.POST.get('ssh_id').split(',') ##判断match和ssh_id都为'' # if match ==''and ssh_id=='': error = '请选择执行主机或者输入salt_id' for i in match: result.append(SaltAPI().salt_remote_execution(client='local_async', tgt=str(i), fun=fun, arg=cmd[select_app])) return HttpResponse(json.dumps(result)) return render(request, 'SaltStack/salt_deploy.html', {'Accepted_Keys': Accepted_Keys})
def get(self): minion_id = self.get_argument('minion_id') saltapi = SaltAPI( url=settings.SALT_API['url'], username=settings.SALT_API['user'], password=settings.SALT_API['password']) minions, minions_pre, minions_rej,minions_den = saltapi.allMinionKeys() result = {} if minion_id.find(','): minion_id_list = minion_id.split(',') if set(minion_id_list).issubset(set(minions)): for id in minion_id_list: result['result'] = saltapi.deleteKeys(id) self.write(json.dumps(result)) else: result['result'] = False self.write(json.dumps(result)) elif minion_id in minions: result['result'] = saltapi.deleteKeys(minion_id) print result self.write(json.dumps(result)) else: result['result'] = False print result self.write(json.dumps(result))
def get(self): minion_id = self.get_argument('minion_id') saltapi = SaltAPI( url=settings.SALT_API['url'], username=settings.SALT_API['user'], password=settings.SALT_API['password']) minions, minions_pre, minions_rej,minions_den = saltapi.allMinionKeys() result = {} if minion_id.find(','): minion_id_list = minion_id.split(',') if set(minion_id_list).issubset(set(minions_pre)): for id in minion_id_list: result['result'] = saltapi.acceptKeys(id) self.write(json.dumps(result)) self.redirect("/salt/unacceptkeys") else: result['result'] = False self.write(json.dumps(result)) # for id in minion_id_list: # print 'Error, %s is not in minions_pre ' % id self.redirect("/salt/unacceptkeys") elif minion_id in minions_pre: result['result'] = saltapi.acceptKeys(minion_id) print result self.write(json.dumps(result)) else: result['result'] = False print result self.write(json.dumps(result)) return
def get_server_asset_info(tgt, url, user, passwd, device): ''' Salt API得到资产信息,进行格式化输出 ''' asset_info = [] cf = ConfigParser.ConfigParser() cf.read("config.ini") info = [] sapi = SaltAPI(url=url, username=user, password=passwd) ret = sapi.remote_noarg_execution(tgt, 'grains.items') ret2 = sapi.remote_noarg_execution(tgt, 'status.diskusage') disk = (ret2['/']['total'] / (1000 * 1000)) / 1000.0 manufacturer = ret['manufacturer'] info.append(manufacturer) productname = ret['productname'] info.append(productname) serialnumber = ret['serialnumber'] info.append(serialnumber) cpu_model = ret['cpu_model'] info.append(cpu_model) num_cpus = int(ret['num_cpus']) info.append(num_cpus) num_gpus = int(ret['num_gpus']) info.append(num_gpus) mem_total = ret['mem_total'] info.append(mem_total) info.append(disk) id = ret['id'] info.append(id) lan_ip = ret['ip4_interfaces'][device] info.append(lan_ip) sys_ver = ret['os'] + ret['osrelease'] + '-' + ret['osarch'] info.append(sys_ver) asset_info.append(info) return asset_info
def remote_execution(request): """ remote command execution """ ret = '' tgtcheck = '' danger = ('rm', 'reboot', 'init ', 'shutdown', 'll') user = request.user if request.method == 'POST': action = request.get_full_path().split('=')[1] if action == 'exec': tgt = request.POST.get('tgt') arg = request.POST.get('arg') tgtcheck = HostList.objects.filter(hostname=tgt) argcheck = arg not in danger if tgtcheck and argcheck: sapi = SaltAPI(url=settings.SALT_API['url'], username=settings.SALT_API['user'], password=settings.SALT_API['password']) ret = sapi.remote_execution(tgt, 'cmd.run', arg) elif not tgtcheck: ret = '亲,目标主机不正确,请重新输入' elif not argcheck: ret = '亲,命令很危险, 你这样子老大会不开森' Message.objects.create(type='salt', action='execution', action_ip=tgt, content='saltstack execution command: %s ' % (arg)) return render(request, 'salt_remote_execution.html', {'ret': ret})
def salt_transfer_file(task_id, host_obj, task_content, task_type, user_id, user_name): bind_host = host_obj saltapi = SaltAPI(url=settings.Salt_API['url'], username=settings.Salt_API['user'], password=settings.Salt_API['password']) try: task_dic = json.loads(task_content) if task_type == "file_send": upload_files = task_dic["upload_files"] remote_files = [] for file_path in upload_files: salt_file_relative_path = "%s/%s" % ( settings.Salt_File_Transfer_Upload, file_path) remote_filename = file_path.split("/")[-1] remote_files.append(remote_filename) remote_file_abs_path = "%s/%s" % ( task_dic['remote_path'].rstrip("/"), remote_filename) result = saltapi.saltRun(tgt=bind_host.host.ip_addr, func='cp.get_file', arg1=salt_file_relative_path, arg2=remote_file_abs_path) cmd_result = "successfully send files %s to remote path [%s]" % ( remote_files, task_dic['remote_path']) stdout = result['return'][0][bind_host.host.ip_addr] result = "success" elif task_type == "file_get": download_files = task_dic["download_files"] successful_download_files = [] datetime_prefix = datetime.datetime.now().strftime("%Y-%m-%d") master_ip = settings.Salt_API['url'].split('/')[-2].split(':')[0] local_file_path = "%s/%s/%s/%s" % ( settings.Salt_File_Transfer_Download, user_name, datetime_prefix, bind_host.host.ip_addr) #print "download_files-->", download_files,type(download_files) for download_file in download_files: result = saltapi.saltRun(tgt=bind_host.host.ip_addr, func='cp.push', arg1=download_file) # for windows type eg. C:\temp\xxx.ini if "\\" in download_file: download_file = download_file.replace("\\", "/") download_file = "/" + download_file download_To_local = settings.Salt_File_Transfer_Download_Abs_Path + bind_host.host.ip_addr + "/files" + download_file handle_result = utils.salt_handle_download_file( user_name, master_ip, download_To_local, bind_host.host.ip_addr) if handle_result: successful_download_files.append(download_file) if successful_download_files: cmd_result = "successfully download files from %s to [%s]" % ( successful_download_files, local_file_path) result = "success" else: cmd_result = "Failed to download files" result = "failed" except Exception, e: print e cmd_result = e result = "failed"
def get(self): saltapi = SaltAPI( url=settings.SALT_API['url'], username=settings.SALT_API['user'], password=settings.SALT_API['password'] ) minions, minions_pre, minions_rej,minions_den = saltapi.allMinionKeys() return self.render( 'base-rejected.html', minions_rej= minions_rej)
def get(self): minion_id_list = self.get_argument('rejectkeys') minion_id_strings = ','.join(minion_id_list) saltapi = SaltAPI( url=settings.SALT_API['url'], username=settings.SALT_API['user'], password=settings.SALT_API['password']) ret = saltapi.deleteKeys(minion_id_strings) self.redirect("/salt/rejectedkeys")
def Delete_Host(request): note_name = request.POST['note_name'] salt_api = SaltAPI() result = salt_api.Delete_Key(note_name) if result: result = 'success' else: result = 'fail' return HttpResponse(json.dumps(result))
def module_deploy(request): """ deploy (nginx/php/mysql..etc) module """ ret = [] jid = [] user = request.user if request.method == 'POST': action = request.get_full_path().split('=')[1] if action == 'deploy': tgt = request.POST.get('tgt') arg = request.POST.getlist('module') tgtcheck = HostList.objects.filter(hostname=tgt) if tgtcheck: Message.objects.create(type='salt', action='deploy', action_ip=tgt, content='saltstack %s module depoy' % (arg)) sapi = SaltAPI(url=settings.SALT_API['url'], username=settings.SALT_API['user'], password=settings.SALT_API['password']) db = db_operate() if 'sysinit' in arg: obj = sapi.async_deploy( tgt, arg[-1]) # 先执行初始化模块,其他任意 sysinit 在最后的模块 sql = "insert INTO salt_returns VALUES(%s) " % obj print sql jid.append(obj) arg.remove('sysinit') if arg: for i in arg: obj = sapi.async_deploy(tgt, i) jid.append(obj) else: for i in arg: obj = sapi.async_deploy(tgt, i) sql = "insert INTO salt_returns VALUES(%s) " % obj db.mysql_command(settings.OMS_MYSQL, sql) jid.append(obj) msg = '%s deploy %s module success,jid is %s' % (tgt, i, obj) ret.append(msg) # db = db_operate() # for i in jid: # # time.sleep(10) # sql = 'select returns from salt_returns where returns=%s' # result=db.select_table(settings.OMS_MYSQL,sql,str(i)) #通过jid获取执行结果 # print result # ret.extend(result) # sapi.async_deploy('test-01','zabbix.api') #调用zabbix.api执行模块监控 else: ret = '亲,目标主机不对,请重新输入' return render(request, 'salt_module_deploy.html', {'ret': ret})
def Add_Host(request): note_name = request.POST['note_name'] print note_name salt_api = SaltAPI() result = salt_api.Accept_Key(note_name) if result: result = 'success' else: result = 'fail' return HttpResponse(json.dumps(result))
def salt_key_list(request): """ list all key """ user = request.user sapi = SaltAPI(url=settings.SALT_API['url'], username=settings.SALT_API['user'], password=settings.SALT_API['password']) minions, minions_pre = sapi.list_all_key() return render(request, 'salt_key_list.html', {'all_minions': minions, 'all_minions_pre': minions_pre})
def get(self): saltapi = SaltAPI( url=settings.SALT_API['url'], username=settings.SALT_API['user'], password=settings.SALT_API['password'] ) minions, minions_pre, minions_rej,minions_den = saltapi.allMinionKeys() res = {"data":minions_den} print res #self.write(json.dumps(res)) return self.render( 'base-denied.html',minions_den=minions_den)
def salt_delete_key(request): """ delete salt minions key """ node_name = request.GET.get('node_name') sapi = SaltAPI(url=settings.SALT_API['url'], username=settings.SALT_API['user'], password=settings.SALT_API['password']) ret = sapi.delete_key(node_name) Message.objects.create(type='salt', action='key', action_ip=node_name, content='saltstack delete node key') return HttpResponseRedirect(reverse('key_list'))
def salt_delete_key(request): """ delete salt minions key :param request: :return: """ node_name = request.GET.get('node_name') sapi = SaltAPI(url=settings.SALT_API['url'], username=settings.SALT_API['user'], password=settings.SALT_API['password']) ret = sapi.delete_key(node_name) Message.objects.create(type='salt', action='key', action_ip=node_name, content='saltstack delete node key') return HttpResponseRedirect(reverse('key_list'))
def get(self): minion_id = self.get_argument('deniedkeys') saltapi = SaltAPI( url=settings.SALT_API['url'], username=settings.SALT_API['user'], password=settings.SALT_API['password']) result = {} result['result'] = saltapi.deleteKeys(minion_id) print result self.write(json.dumps(result)) self.redirect("/salt/deniedkeys")
def Remote_Execution(request,): print request.POST if request.method == "POST": print request.POST tgt = request.POST['tgt'] fun = request.POST['fun'] arg = request.POST['args'] salt_api = SaltAPI() result = salt_api.Remote_Server_Info(tgt,fun,arg) result = result['return'][0] print result return HttpResponse(json.dumps(result)) return render(request,'html/remote_exe.html')
def salt_key_list(request): """ List all key :param request: :return: """ user = request.user sapi = SaltAPI(url=settings.SALT_API['url'], username=settings.SALT_API['user'], password=settings.SALT_API['password']) minions, minions_pre = sapi.list_all_key() return render(request, 'salt_key_list.html', {'all_minions': minions, 'all_minions_pre': minions_pre})
def get_server_status_info(tgt): ''' Salt API得到资产信息,进行格式化输出 ''' info = {} sapi = SaltAPI() ret = sapi.remote_noarg_execution(tgt,'status.all_status') cpu_status=ret['cpustats] disk_status=ret['diskstats'] mem_status=ret['meminfo'] vm_status=ret['vmstats'] return info
def module_deploy(request): """ deploy (nginx/php/mysql..etc) module """ ret = [] jid = [] user = request.user if request.method == 'POST': action = request.get_full_path().split('=')[1] if action == 'deploy': tgt = request.POST.get('tgt') arg = request.POST.getlist('module') tgtcheck = HostList.objects.filter(hostname=tgt) if tgtcheck: Message.objects.create(type='salt', action='deploy', action_ip=tgt, content='saltstack %s module depoy' % (arg)) sapi = SaltAPI(url=settings.SALT_API['url'], username=settings.SALT_API['user'], password=settings.SALT_API['password']) db = db_operate() if 'sysinit' in arg: obj = sapi.async_deploy(tgt, arg[-1]) # 先执行初始化模块,其他任意 sysinit 在最后的模块 sql = "insert INTO salt_returns VALUES(%s) " % obj print sql jid.append(obj) arg.remove('sysinit') if arg: for i in arg: obj = sapi.async_deploy(tgt, i) jid.append(obj) else: for i in arg: obj = sapi.async_deploy(tgt, i) sql = "insert INTO salt_returns VALUES(%s) " % obj db.mysql_command(settings.OMS_MYSQL, sql) jid.append(obj) msg = '%s deploy %s module success,jid is %s' % (tgt, i, obj) ret.append(msg) # db = db_operate() # for i in jid: # # time.sleep(10) # sql = 'select returns from salt_returns where returns=%s' # result=db.select_table(settings.OMS_MYSQL,sql,str(i)) #通过jid获取执行结果 # print result # ret.extend(result) # sapi.async_deploy('test-01','zabbix.api') #调用zabbix.api执行模块监控 else: ret = '亲,目标主机不对,请重新输入' return render(request, 'salt_module_deploy.html', {'ret': ret})
def salt_many_cmd(request): Accepted_Keys = SaltAPI().list_all_key()[0] result = [] if request.method == 'POST': cmd_args = request.POST.get('cmd_args') match = request.POST.getlist('match[]') for i in match: result.append(SaltAPI().salt_remote_execution(client='local_async', tgt=str(i), fun='cmd.run', arg=cmd_args)) return HttpResponse(json.dumps(result)) return render(request, 'SaltStack/salt_many_cmd.html', {'Accepted_Keys': Accepted_Keys})
def module_deploy(request): """ deploy (nginx/php/mysql..etc) module :param request: :return: """ ret = [] jid = [] user = request.user if request.method == 'POST': action = request.get_full_path().split('=')[1] if action == 'deploy': tgt = request.POST.get('tgt') arg = request.POST.getlist('module') tgtcheck = HostList.objects.filter(hostname=tgt) if tgtcheck: Message.objects.create(type='salt', action='deploy', action_ip=tgt, content='saltstack %s module deploy' % (arg)) sapi = SaltAPI(url=settings.SALT_API['url'], username=settings.SALT_API['user'], password=settings.SALT_API['password']) db = db_operate() if 'sysinit' in arg: obj = sapi.async_deploy(tgt, arg[-1]) sql = "instert INTO salt_returns VALUES(%s) " % obj print sql jid.append(obj) arg.remove('sysinit') if arg: for i in arg: obj = sapi.async_deploy(tgt, i) jid.append(obj) else: for i in arg: obj = sapi.async_deploy(tgt, i) sql = "insert INTO salt_returns VALUES(%s) " % obj db.mysql_command(settings.OMS_MYSQL, sql) jid.append(obj) msg = '%s deploy %s module success,jid is %s' % (tgt, i, obj) ret.append(msg) else: ret = '目标主机不对,请重新输入' return render(request, 'salt_module_deploy.html', {'ret': ret})
def salt_test(request): result = [] result_show = [] node_name = request.POST.getlist('Select_Host[]') if len(node_name) > 1: for i in node_name: result.append(SaltAPI().salt_remote_execution(tgt=str(i), fun='test.ping')) return HttpResponse(json.dumps(str(result)), content_type='application/json') else: result.append(SaltAPI().salt_remote_execution(tgt=str(node_name[0]), fun='test.ping')) return HttpResponse(json.dumps(str(result[0])), content_type='application/json')
def get_server_asset_info(tgt): ''' Salt API得到资产信息,进行格式化输出 ''' print global asset_info info = [] sapi = SaltAPI() ret = sapi.remote_noarg_execution(tgt, 'grains.items') manufacturer = ret['manufacturer'] info.append(manufacturer) productname = ret['productname'] info.append(productname) serialnumber = ret['serialnumber'] info.append(serialnumber) cpu_model = ret['cpu_model'] info.append(cpu_model) num_cpus = int(ret['num_cpus']) info.append(num_cpus) num_gpus = int(ret['num_gpus']) info.append(num_gpus) mem_total = str(round(int(ret['mem_total']) / 1000.0, ))[:-2] + 'G' info.append(mem_total) disk = sapi.remote_noarg_execution(tgt, 'disk.usage') disk_size = str(int(disk['/']['1K-blocks']) / 1048576) + 'G' info.append(disk_size) try: raidlevel = ret['raidlevel'] except Exception as e: raidlevel = "" info.append(raidlevel) id = ret['id'] info.append(id) try: lan_ip = ret['lan_ip'][0] except Exception as e: lan_ip = "" info.append(lan_ip) try: lan_mac = ret['hwaddr_interfaces']['eth0'] except Exception, e: lan_mac = ""
def get_server_asset_info(tgt): ''' Salt API得到资产信息,进行格式化输出 ''' global asset_info info = [] sapi = SaltAPI(url=settings.SALT_API['url'], username=settings.SALT_API['user'], password=settings.SALT_API['password']) ret = sapi.remote_noarg_execution(tgt, 'grains.items') manufacturer = ret['manufacturer'] info.append(manufacturer) productname = ret['productname'] info.append(productname) serialnumber = ret['serialnumber'] info.append(serialnumber) cpu_model = ret['cpu_model'] info.append(cpu_model) num_cpus = int(ret['num_cpus']) info.append(num_cpus) num_gpus = int(ret['num_gpus']) info.append(num_gpus) mem_total = str(round(int(ret['mem_total']) / 1000.0, ))[:-2] + 'G' info.append(mem_total) disk_size = ret['disk_size'] info.append(disk_size) raidlevel = ret['raidlevel'] info.append(raidlevel) id = ret['id'] info.append(id) lan_ip = ret['lan_ip'][0] info.append(lan_ip) lan_mac = ret['hwaddr_interfaces']['eth0'] info.append(lan_mac) sys_ver = ret['os'] + ret['osrelease'] + '-' + ret['osarch'] info.append(sys_ver) virtual = ret['virtual'] info.append(virtual) idc_name = ret['idc_name'] info.append(idc_name) asset_info.append(info)
def get_server_asset_info(tgt, url, user, passwd, device): ''' Salt API得到资产信息,进行格式化输出 ''' cf = ConfigParser.ConfigParser() cf.read("config.ini") global asset_info info = [] sapi = SaltAPI(url=url, username=user, password=passwd) ret = sapi.remote_noarg_execution(tgt, 'grains.items') # manufacturer = ret['manufacturer'] # info.append(manufacturer) info.append('111') # productname = ret['productname'] # info.append(productname) info.append('222') # serialnumber = ret['serialnumber'] # info.append(serialnumber) # info.append('333') serialnumber = ret['server_id'] info.append(serialnumber) cpu_model = ret['cpu_model'] info.append(cpu_model) num_cpus = int(ret['num_cpus']) info.append(num_cpus) num_gpus = int(ret['num_gpus']) info.append(num_gpus) mem_total = ret['mem'] info.append(mem_total) disk = ret['disk'] info.append(disk) id = ret['id'] info.append(id) lan_ip = ret['ip4_interfaces'][device] info.append(lan_ip) sys_ver = ret['os'] + ret['osrelease'] + '-' + ret['osarch'] info.append(sys_ver) asset_info = [] asset_info.append(info) return asset_info
def get_server_asset_info(tgt): ''' Salt API得到资产信息,进行格式化输出 ''' global asset_info info = [] sapi = SaltAPI(url=settings.SALT_API['url'],username=settings.SALT_API['user'],password=settings.SALT_API['password']) ret = sapi.remote_noarg_execution(tgt,'grains.items') manufacturer = ret['manufacturer'] info.append(manufacturer) productname = ret['productname'] info.append(productname) serialnumber = ret['serialnumber'] info.append(serialnumber) cpu_model = ret['cpu_model'] info.append(cpu_model) num_cpus = int(ret['num_cpus']) info.append(num_cpus) num_gpus = int(ret['num_gpus']) info.append(num_gpus) mem_total = str(round(int(ret['mem_total'])/1000.0,))[:-2] + 'G' info.append(mem_total) disk_size = ret['disk_size'] info.append(disk_size) raidlevel = ret['raidlevel'] info.append(raidlevel) id = ret['id'] info.append(id) lan_ip = ret['lan_ip'][0] info.append(lan_ip) lan_mac = ret['hwaddr_interfaces']['eth0'] info.append(lan_mac) sys_ver = ret['os'] + ret['osrelease'] + '-' + ret['osarch'] info.append(sys_ver) virtual = ret['virtual'] info.append(virtual) idc_name = ret['idc_name'] info.append(idc_name) asset_info.append(info)
def List_Host(request): salt_api = SaltAPI() minions, minions_pre = salt_api.List_All_Key() host_list = minions+minions_pre ip = salt_api.Remote_Server_Info('*','cmd.run',"ifconfig | grep 'inet addr:' |grep -v 127.0.0.1|cut -d'B' -f 1|cut -d':' -f 2")['return'][0].values() os = salt_api.Remote_Server_Info('*','cmd.run','cat /etc/issue')['return'][0].values() is_alive = salt_api.Is_Salt_Alive('*').values() data=zip(host_list,ip,os,is_alive) return render(request,'html/list_host.html',{'data':data})
def salt_run_script(task_id, host_obj, script_type, script_path, script_param, user_name): print "going to run--->", host_obj, script_type, script_param, script_path bind_host = host_obj saltapi = SaltAPI(url=settings.Salt_API['url'], username=settings.Salt_API['user'], password=settings.Salt_API['password']) try: if script_param: if script_type == "powershell": result = saltapi.saltRun(tgt=bind_host.host.ip_addr, func='cmd.script', arg1=script_path, arg2=script_param, arg3='shell=powershell') else: result = saltapi.saltRun(tgt=bind_host.host.ip_addr, func='cmd.script', arg1=script_path, arg2=script_param) else: if script_type == "powershell": result = saltapi.saltRun(tgt=bind_host.host.ip_addr, func='cmd.script', arg1=script_path, arg2='shell=powershell') else: result = saltapi.saltRun(tgt=bind_host.host.ip_addr, func='cmd.script', arg1=script_path) stderr = result['return'][0][bind_host.host.ip_addr]["stderr"] stdout = result['return'][0][bind_host.host.ip_addr]["stdout"] result = stdout, stderr cmd_result_flag = filter(lambda x: len(x) > 0, result) if cmd_result_flag: cmd_result = filter(lambda x: len(x) > 0, result)[0] else: cmd_result = 'no result return' result = "success" except Exception, e: print("\033[31;1m%s\033[0m" % e) cmd_result = e result = 'failed'
def salt_api(request): Accepted_Keys = SaltAPI().list_all_key()[0] Unaccepted_Keys = SaltAPI().list_all_key()[1] return render(request, 'SaltStack/salt-api.html', locals())
def delete_key(request): node_name = request.POST.get('Accepted_Key[]') result = SaltAPI().delete_key(node_name=str(node_name)) return HttpResponse(json.dumps(result))