Skip to content

Commit

Permalink
切换到adminlte
Browse files Browse the repository at this point in the history
  • Loading branch information
guohongze committed Feb 10, 2017
1 parent 4d854e3 commit 1e03a25
Show file tree
Hide file tree
Showing 2,139 changed files with 218,539 additions and 233,518 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.svn/
.idea/
16 changes: 15 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

987 changes: 615 additions & 372 deletions .idea/workspace.xml

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions .idea/woss2.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file added ansible/__init__.py
Empty file.
Binary file added ansible/__init__.pyc
Binary file not shown.
Binary file added ansible/__pycache__/__init__.cpython-35.pyc
Binary file not shown.
Binary file added ansible/__pycache__/admin.cpython-35.pyc
Binary file not shown.
Binary file added ansible/__pycache__/models.cpython-35.pyc
Binary file not shown.
1 change: 1 addition & 0 deletions ansible/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from django.contrib import admin
Binary file added ansible/admin.pyc
Binary file not shown.
7 changes: 7 additions & 0 deletions ansible/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from __future__ import unicode_literals

from django.apps import AppConfig


class AnsibleConfig(AppConfig):
name = 'ansible'
Empty file added ansible/migrations/__init__.py
Empty file.
Binary file added ansible/migrations/__init__.pyc
Binary file not shown.
5 changes: 5 additions & 0 deletions ansible/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from __future__ import unicode_literals

from django.db import models

# Create your models here.
Binary file added ansible/models.pyc
Binary file not shown.
3 changes: 3 additions & 0 deletions ansible/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
10 changes: 10 additions & 0 deletions ansible/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#! /usr/bin/env python
# -*- coding: utf-8 -*-
from django.conf.urls import url, include
from . import views

app_name = 'cmdb'
urlpatterns = [
url(r'^$', views.ansible, name='ansible'),
url(r'^exec', views.ansiblexe, name='exec'),
]
Binary file added ansible/urls.pyc
Binary file not shown.
64 changes: 64 additions & 0 deletions ansible/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
from subprocess import Popen, PIPE
from cmdb.models import Host, HostGroup
from django.shortcuts import render_to_response, redirect
from django.http import HttpResponse


def ansible(request):
host_list = Host.objects.all()
hostgroup = HostGroup.objects.all()
return render_to_response('ansible.html',locals())


def ansiblexe(request):
if request.method == 'POST':
host1 = request.POST.getlist('mserver', [])
group = request.POST.getlist('mgroup', [])
playbook = request.POST.getlist('mplaybook', [])
command = request.POST.getlist('mcommand', [])
for h in host1:
print h
print type(group)
print type(playbook)
print type(command)
return HttpResponse("ok")
# if host:
# if playbook:
# for h in host:
# print h
# f = open('svn_install.yml', 'r+')
# flist = f.readlines()
# flist[0] = '- hosts: '+h+'\n'
# f = open('svn_install.yml', 'w+')
# f.writelines(flist)
# f.close()
# cmd = "ansible-playbook"+" "+playbook
# p = Popen(cmd, stdout=PIPE, shell=True)
# data = p.communicate()
# return data
# else:
# for h in host:
# cmd = "ansible" + " " + h + "-a" + command
# p = Popen(cmd, stdout=PIPE, shell=True)
# data = p.communicate()
# return data
# else:
# if group:
# for g in group:
# f = open('svn_install.yml', 'r+')
# flist = f.readlines()
# flist[0] = '- hosts: '+g+'\n'
# f = open('svn_install.yml', 'w+')
# f.writelines(flist)
# f.close
# cmd = "ansible-playbook"+" "+playbook
# p = Popen(cmd, stdout=PIPE, shell=True)
# data = p.communicate()
# return data
# else:
# for g in group:
# cmd = "ansible" + " " + h + "-a" + command
# p = Popen(cmd, stdout=PIPE, shell=True)
# data = p.communicate()
# return data

Binary file added ansible/views.pyc
Binary file not shown.
Binary file added cmdb/__pycache__/__init__.cpython-35.pyc
Binary file not shown.
Binary file added cmdb/__pycache__/admin.cpython-35.pyc
Binary file not shown.
Binary file added cmdb/__pycache__/apps.cpython-35.pyc
Binary file not shown.
Binary file added cmdb/__pycache__/models.cpython-35.pyc
Binary file not shown.
29 changes: 6 additions & 23 deletions cmdb/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ def collect(request):
host = Host.objects.get(hostname=hostname)
except:
host = Host()
identity = req.POST.get('identity')
try:
host = Host.objects.get(identity=identity)
except:
host = Host()
if req.POST.get('identity'):
identity = req.POST.get('identity')
try:
host = Host.objects.get(identity=identity)
except:
host = Host()
host.hostname = hostname
host.group = group
host.cpu_num = int(cpu_num)
Expand All @@ -48,24 +49,6 @@ def collect(request):
else:
return HttpResponse("no any post data!")

'''
def gethostsjson(req):
if req.GET:
d = []
hostgroups = HostGroup.objects.all()
for hg in hostgroups:
ret_hg = {'hostgroup': hg.name, 'members': []}
members = hg.members.all()
for h in members:
ret_h = {'hostname': h.hostname, 'ipaddr': h.ip}
ret_hg['members'].append(ret_h)
d.append(ret_hg)
ret = {'status': 1, 'data': d, 'message': 'OK'}
return HttpResponse(json.dumps(ret))
else:
return HttpResponse('Nothing of hosts to json.dumps!')
'''


def get_group(request):
if request.GET:
Expand Down
Binary file modified cmdb/api.pyc
Binary file not shown.
34 changes: 34 additions & 0 deletions cmdb/migrations/0010_auto_20170203_2211.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.8 on 2017-02-03 14:11
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('cmdb', '0009_auto_20170128_2350'),
]

operations = [
migrations.AlterModelOptions(
name='idc',
options={'verbose_name': '\u6570\u636e\u4e2d\u5fc3', 'verbose_name_plural': '\u6570\u636e\u4e2d\u5fc3'},
),
migrations.AlterField(
model_name='host',
name='cpu_model',
field=models.CharField(max_length=100, null=True),
),
migrations.AlterField(
model_name='host',
name='os',
field=models.CharField(max_length=50, null=True, verbose_name='\u64cd\u4f5c\u7cfb\u7edf'),
),
migrations.AlterField(
model_name='idc',
name='address',
field=models.CharField(max_length=100, null=True),
),
]
Binary file added cmdb/migrations/0010_auto_20170203_2211.pyc
Binary file not shown.
5 changes: 4 additions & 1 deletion cmdb/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@ class Idc(models.Model):

def __unicode__(self):
return self.name
class Meta:
verbose_name = u'数据中心'
verbose_name_plural = verbose_name


class Host(models.Model):
hostname = models.CharField(max_length=30, verbose_name=u"主机名")
os = models.CharField(max_length=50,null=True)
os = models.CharField(u"操作系统",max_length=50,null=True)
vendor = models.CharField(max_length=30,null=True)
group = models.CharField(max_length=30,null=True)
cpu_model = models.CharField(max_length=100,null=True)
Expand Down
Binary file modified cmdb/models.pyc
Binary file not shown.
9 changes: 4 additions & 5 deletions cmdb/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@

app_name = 'cmdb'
urlpatterns = [
url(r'^$', views.IndexView.as_view(), name='index'),
url(r'^cmdb', views.cmdb, name='cmdb'),
url(r'^ansible', views.ansible, name='ansible'),
url(r'^index3', views.index3, name='index3'),
#url(r'^$', views.IndexView.as_view(), name='index'),
url(r'^$', views.cmdb, name='cmdb'),
url(r'^excel', views.excel, name='excel'),
url(r'^login', views.login, name='login'),
url(r'^collect', api.collect, name='update api'),
url(r'^sync', views.hostsync, name='sync'),
url(r'^collect', api.collect, name='update_api'),
url(r'^api/host', api.get_host, name='get_host'),
url(r'^api/group', api.get_group, name='get_group'),
]
Binary file modified cmdb/urls.pyc
Binary file not shown.
38 changes: 18 additions & 20 deletions cmdb/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,6 @@ def cmdb(request):
return render_to_response('cmdb.html', locals())


def index3(request):
host_list = Host.objects.all()
return render_to_response('index.html',locals())

def ansible(request):
host_list = Host.objects.all()
hostgroup = HostGroup.objects.all()
return render_to_response('ansible.html',locals())

class IndexView(generic.ListView):
template_name = 'index.html'
context_object_name = 'host_list'

def get_queryset(self):
return Host.objects.order_by('hostname')


def excel(request):
host = Host.objects.all()
response = HttpResponse(content_type='text/csv')
Expand All @@ -43,7 +26,7 @@ def excel(request):
writer.writerow([h.hostname, h.ip, h.group, h.memory, h.disk, h.cpu_model, h.cpu_num, h.os, str(h.idc).encode('gb2312')])
return response

def __str__(self):
def __unicode__(self):
return self.name


Expand All @@ -57,6 +40,21 @@ def login(request):
return redirect('/cmdb')
else:
ret['status'] = 'user or password error'
return render_to_response('cmdb/login.html', locals())
return render_to_response('login2.html', locals())
else:
return render_to_response('cmdb/login.html', locals())
return render_to_response('login2.html', locals())


def hostsync(request):
group = HostGroup.objects.all()
ansible_file = open("/etc/ansible/hosts","wb")
for h in group:
group_name = "["+h.name+"]"+"\n"
ansible_file.write(group_name)
members = h.members.all()
for m in members:
#gitlab ansible_host=10.100.1.76 host_name=gitlab
host_item = m.hostname+" "+"ansible_host="+m.ip+" "+"host_name="+m.hostname+"\n"
ansible_file.write(host_item)
ansible_file.close()
return HttpResponse("ok")
Binary file modified cmdb/views.pyc
Binary file not shown.
Binary file modified db.sqlite3
Binary file not shown.
Empty file added navi/__init__.py
Empty file.
Binary file added navi/__init__.pyc
Binary file not shown.
Binary file added navi/__pycache__/__init__.cpython-35.pyc
Binary file not shown.
Binary file added navi/__pycache__/admin.cpython-35.pyc
Binary file not shown.
Binary file added navi/__pycache__/models.cpython-35.pyc
Binary file not shown.
12 changes: 12 additions & 0 deletions navi/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from django.contrib import admin
from .models import navi

class NaviAdmin(admin.ModelAdmin):
list_display = [
'name',
'url',
]


admin.site.register(navi, NaviAdmin)

Binary file added navi/admin.pyc
Binary file not shown.
7 changes: 7 additions & 0 deletions navi/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from __future__ import unicode_literals

from django.apps import AppConfig


class NaviConfig(AppConfig):
name = 'navi'
25 changes: 25 additions & 0 deletions navi/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.8 on 2017-02-03 14:11
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='navi',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=50, null=True)),
('img', models.CharField(max_length=50, null=True)),
('url', models.URLField()),
],
),
]
Binary file added navi/migrations/0001_initial.pyc
Binary file not shown.
20 changes: 20 additions & 0 deletions navi/migrations/0002_auto_20170210_0946.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.8 on 2017-02-10 01:46
from __future__ import unicode_literals

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('navi', '0001_initial'),
]

operations = [
migrations.RenameField(
model_name='navi',
old_name='img',
new_name='description',
),
]
Binary file added navi/migrations/0002_auto_20170210_0946.pyc
Binary file not shown.
Empty file added navi/migrations/__init__.py
Empty file.
Binary file added navi/migrations/__init__.pyc
Binary file not shown.
Loading

0 comments on commit 1e03a25

Please sign in to comment.