Skip to content

Commit

Permalink
1.优化密钥认证
Browse files Browse the repository at this point in the history
2.更新requirements.txt
  • Loading branch information
welliamcao committed Jan 23, 2018
1 parent a72ae53 commit 273d7c1
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions OpsManage/tasks/ansible.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def AnsibleScripts(**kw):
server_assets = Server_Assets.objects.get(ip=sip)
except Exception, ex:
continue
if server_assets.keyfile == 1:resource.append({"hostname": server_assets.ip, "port": int(server_assets.port)})
if server_assets.keyfile == 1:resource.append({"hostname": server_assets.ip, "port": int(server_assets.port),"username": server_assets.username})
else:resource.append({"hostname": server_assets.ip, "port": int(server_assets.port),"username": server_assets.username,"password": server_assets.passwd})
ANS = ANSRunner(resource,redisKey=None,logId=logId)
ANS.run_model(host_list=sList,module_name='script',module_args=filePath)
Expand Down Expand Up @@ -74,7 +74,7 @@ def AnsiblePlayBook(**kw):
server_assets = Server_Assets.objects.get(ip=sip)
except Exception, ex:
continue
if server_assets.keyfile == 1:resource.append({"hostname": server_assets.ip, "port": int(server_assets.port)})
if server_assets.keyfile == 1:resource.append({"hostname": server_assets.ip, "port": int(server_assets.port),"username": server_assets.username})
else:resource.append({"hostname": server_assets.ip, "port": int(server_assets.port),"username": server_assets.username,"password": server_assets.passwd})
ANS = ANSRunner(resource,redisKey=None,logId=logId)
ANS.run_playbook(host_list=sList, playbook_path=filePath)
Expand Down
2 changes: 1 addition & 1 deletion OpsManage/tasks/sched.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def updateAssets():
print ex
continue
sList.append(server_assets.ip)
if server_assets.keyfile == 1:resource.append({"hostname": server_assets.ip, "port": int(server_assets.port)})
if server_assets.keyfile == 1:resource.append({"hostname": server_assets.ip, "port": int(server_assets.port),"username": server_assets.username})
else:resource.append({"hostname": server_assets.ip, "port": server_assets.port,"username": server_assets.username, "password": server_assets.passwd})
ANS = ANSRunner(resource)
ANS.run_model(host_list=sList,module_name='setup',module_args="")
Expand Down
20 changes: 10 additions & 10 deletions OpsManage/views/ansible.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,19 @@ def apps_model(request):
for server in serverList:
server_assets = Server_Assets.objects.get(id=server)
sList.append(server_assets.ip)
if server_assets.keyfile == 1:resource.append({"hostname": server_assets.ip, "port": int(server_assets.port)})
if server_assets.keyfile == 1:resource.append({"hostname": server_assets.ip, "port": int(server_assets.port),"username": server_assets.username})
else:resource.append({"hostname": server_assets.ip, "port": int(server_assets.port),"username": server_assets.username,"password": server_assets.passwd})
elif request.POST.get('server_model') == 'group':
serverList = Assets.objects.filter(group=request.POST.get('ansible_group'))
for server in serverList:
sList.append(server.server_assets.ip)
if server.server_assets.keyfile == 1:resource.append({"hostname": server.server_assets.ip, "port": int(server.server_assets.port)})
if server.server_assets.keyfile == 1:resource.append({"hostname": server.server_assets.ip, "port": int(server.server_assets.port),"username": server.server_assets.username})
else:resource.append({"hostname": server.server_assets.ip, "port": int(server.server_assets.port),"username": server.server_assets.username,"password": server.server_assets.passwd})
elif request.POST.get('server_model') == 'service':
serverList = Assets.objects.filter(business=request.POST.get('ansible_service'))
for server in serverList:
sList.append(server.server_assets.ip)
if server.server_assets.keyfile == 1:resource.append({"hostname": server.server_assets.ip, "port": int(server.server_assets.port)})
if server.server_assets.keyfile == 1:resource.append({"hostname": server.server_assets.ip, "port": int(server.server_assets.port),"username": server.server_assets.username})
else:resource.append({"hostname": server.server_assets.ip, "port": int(server.server_assets.port),"username": server.server_assets.username,"password": server.server_assets.passwd})
if len(request.POST.get('custom_model')) > 0:model_name = request.POST.get('custom_model')
else:model_name = request.POST.get('ansible_model',None)
Expand Down Expand Up @@ -258,7 +258,7 @@ def apps_playbook_run(request,pid):
for server in serverList:
server_assets = Server_Assets.objects.get(ip=server)
sList.append(server_assets.ip)
if server_assets.keyfile == 1:resource.append({"hostname": server_assets.ip, "port": int(server_assets.port)})
if server_assets.keyfile == 1:resource.append({"hostname": server_assets.ip, "port": int(server_assets.port),"username": server_assets.username})
else:resource.append({"hostname": server_assets.ip, "port": int(server_assets.port),"username": server_assets.username,"password": server_assets.passwd})
if playbook.playbook_vars:playbook_vars = playbook.playbook_vars
else:playbook_vars = request.POST.get('playbook_vars')
Expand Down Expand Up @@ -518,7 +518,7 @@ def saveScript(content,filePath):
for server in serverList:
server_assets = Server_Assets.objects.get(id=server)
sList.append(server_assets.ip)
if server_assets.keyfile == 1:resource.append({"hostname": server_assets.ip, "port": int(server_assets.port)})
if server_assets.keyfile == 1:resource.append({"hostname": server_assets.ip, "port": int(server_assets.port),"username": server_assets.username})
else:resource.append({"hostname": server_assets.ip, "port": int(server_assets.port),"username": server_assets.username,"password": server_assets.passwd})
elif request.POST.get('server_model') == 'group':
serverList = Assets.objects.filter(group=request.POST.get('ansible_group'))
Expand All @@ -528,7 +528,7 @@ def saveScript(content,filePath):
except Exception, ex:
print ex
continue
if server.server_assets.keyfile == 1:resource.append({"hostname": server.server_assets.ip, "port": int(server.server_assets.port)})
if server.server_assets.keyfile == 1:resource.append({"hostname": server.server_assets.ip, "port": int(server.server_assets.port),"username": server.server_assets.username})
else:resource.append({"hostname": server.server_assets.ip, "port": int(server.server_assets.port),"username": server.server_assets.username,"password": server.server_assets.passwd})
elif request.POST.get('server_model') == 'service':
serverList = Assets.objects.filter(business=request.POST.get('ansible_service'))
Expand All @@ -538,7 +538,7 @@ def saveScript(content,filePath):
except Exception, ex:
print ex
continue
if server.server_assets.keyfile == 1:resource.append({"hostname": server.server_assets.ip, "port": int(server.server_assets.port)})
if server.server_assets.keyfile == 1:resource.append({"hostname": server.server_assets.ip, "port": int(server.server_assets.port),"username": server.server_assets.username})
else:resource.append({"hostname": server.server_assets.ip, "port": int(server.server_assets.port),"username": server.server_assets.username,"password": server.server_assets.passwd})

if len(sList) > 0 and request.POST.get('type') == 'run' and request.POST.get('script_file'):
Expand Down Expand Up @@ -655,13 +655,13 @@ def saveScript(content,filePath):
for server in serverList:
server_assets = Server_Assets.objects.get(id=server)
sList.append(server_assets.ip)
if server_assets.keyfile == 1:resource.append({"hostname": server_assets.ip, "port": int(server_assets.port)})
if server_assets.keyfile == 1:resource.append({"hostname": server_assets.ip, "port": int(server_assets.port),"username": server_assets.username})
else:resource.append({"hostname": server_assets.ip, "port": int(server_assets.port),"username": server_assets.username,"password": server_assets.passwd})
elif request.POST.get('server_model') == 'group':
serverList = Assets.objects.filter(group=request.POST.get('ansible_group'))
for server in serverList:
sList.append(server.server_assets.ip)
if server.server_assets.keyfile == 1:resource.append({"hostname": server.server_assets.ip, "port": int(server.server_assets.port)})
if server.server_assets.keyfile == 1:resource.append({"hostname": server.server_assets.ip, "port": int(server.server_assets.port),"username": server.server_assets.username})
else:resource.append({"hostname": server.server_assets.ip, "port": int(server.server_assets.port),"username": server.server_assets.username,"password": server.server_assets.passwd})
elif request.POST.get('server_model') == 'service':
serverList = Assets.objects.filter(business=request.POST.get('ansible_service'))
Expand All @@ -671,7 +671,7 @@ def saveScript(content,filePath):
except Exception, ex:
print ex
continue
if server.server_assets.keyfile == 1:resource.append({"hostname": server.server_assets.ip, "port": int(server.server_assets.port)})
if server.server_assets.keyfile == 1:resource.append({"hostname": server.server_assets.ip, "port": int(server.server_assets.port),"username": server.server_assets.username})
else:resource.append({"hostname": server.server_assets.ip, "port": int(server.server_assets.port),"username": server.server_assets.username,"password": server.server_assets.passwd})
if request.POST.get('type') == 'save' and request.POST.get('script_file'):
filePath = os.getcwd() + '/' + str(script.script_file)
Expand Down
2 changes: 1 addition & 1 deletion OpsManage/views/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ def assets_batch(request):
fList.append(assets.management_ip)
continue
serList.append(server_assets.ip)
if server_assets.keyfile == 1:resource.append({"hostname": server_assets.ip, "port": int(server_assets.port)})
if server_assets.keyfile == 1:resource.append({"hostname": server_assets.ip, "port": int(server_assets.port),"username": server_assets.username})
else:resource.append({"hostname": server_assets.ip, "port": server_assets.port,"username": server_assets.username, "password": server_assets.passwd})
ANS = ANSRunner(resource)
ANS.run_model(host_list=serList,module_name='setup',module_args="")
Expand Down
2 changes: 0 additions & 2 deletions OpsManage/views/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ def task_model(request):
#获取注册的任务
regTaskList = []
for task in list(keys(cTasks)):
print task
if task.startswith('OpsManage.tasks.ansible') or task.startswith('OpsManage.tasks.sched'):
regTaskList.append(task)
try:
Expand Down Expand Up @@ -110,7 +109,6 @@ def task_model(request):
def task_view(request):
if request.method == "GET":
try:

workList = WorkerState.objects.all()
regTaskList = []
for task in list(keys(cTasks)):
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ djangorestframework==3.5.3
paramiko
ansible==2.2.2
supervisor
mysql-replication
pymysql
redis
MySQL-python
DBUtils
Expand Down

0 comments on commit 273d7c1

Please sign in to comment.