api-shell格式

shell格式API

vim urls.py

url(r'^hostinfo/gettxt/$', 'hostinfo.views.gettxt'),

vim view.py

         ​

def gettxt(req):
res = ''
hg = HostGroup.objects.all()
for g in hg:
groupname = g.groupname
for h in g.members.all():
hostname = h.hostname
ip = h.ip
res += groupname+' '+hostname+' '+ip+'\n'
return HttpResponse(res)

 

# curl -s http://192.168.17.139:8000/hostinfo/gettxt/
web web1.james.top CentOS release 6.5 (Final)
web web1.james.top CentOS release 6.5 (Final)
db db1.james.top CentOS release 6.5 (Final)

 

posted on 2018-01-10 19:51  linux-paul  阅读(139)  评论(0编辑  收藏  举报

导航