后端
前端
data_info = {'id':1,'ip':'192.168.56.1','hostname':'test'}
OpServerM.objects.get_or_create(**data_info)
update_data = {'id':1,'ip':'192.168.56.101','hostname':'test01'}
server = OpServerM.objects.filter(pk=update_data['id'])
server.update(**update_data)
response = HttpResponse()
response['Content-Type'] = "text/javascript"
hostsFile = request.FILES.getlist('uploadhosts')
for i in hostsFile:
filename = os.path.join(MEDIA_ROOT,i.name)
file = open(filename, 'wb')
for chrunk in i.chunks():
file.write(chrunk)
file.close()
def imp_hosts(filename,sheet_name,model_name):
fileds = model_name._meta.get_fields(include_parents=False)
flist = []
for filed in fileds:
flist.append(str(filed).split('.')[-1])
wb = load_workbook(filename)
##读取excel表sheet名称为sheet_name的数据
ws = wb[sheet_name]
List=[]
for row in list(ws.rows)[1:]:
cols = []
for col in row:
cols.append(col.value)
tab_dic = dict(map(lambda x, y: [x, y], flist, cols))
List.append(model_name(**tab_dic))
model_name.objects.bulk_create(List)
log-monitor:
file.managed:
- name: /data/shell/log-monitor.sh
- source: salt://init/centos/files/log-monitor.sh
- template: jinja
参考资料
Saltstack API
salt '192.168.56.101' cmd.run 'free -m'
参考资料
Saltstack任务编排stats.sls
vim {django_root}/project/settings.py
MEDIA_URL='/media/'
MEDIA_ROOT='media'
salt '192.168.56.101' cp.get_url http://{django-server:port}/media/upload.file /tmp/upload.file
salt '192.168.56.101' cp.push /tmp/download.file
salt 'django-server' cp.get_file salt://192.168.56.101/tmp/download.file /{DJANGO_ROOT}/media/download.file
wget http://{django-server:port}/media/download.file
参考资料
Django2集成celery4执行异步任务、定时任务
celery -A celery_tasks worker -l info
官方文档
Celery管理和监控工具-Flower
Flower API
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。