merge filed, update files...

pull/26/head
yumaojun 2015-11-13 12:50:21 +08:00
parent 4bfe326868
commit 9ec2b9ff1d
7 changed files with 9 additions and 81 deletions

View File

@ -59,13 +59,13 @@ class AssetGroup(models.Model):
class Asset(models.Model):
ip = models.IPAddressField(unique=True)
port = models.IntegerField(max_length=6, blank=True, null=True)
ip = models.GenericIPAddressField(unique=True)
port = models.IntegerField(blank=True, null=True)
group = models.ManyToManyField(AssetGroup)
username = models.CharField(max_length=20, blank=True, null=True)
password = models.CharField(max_length=80, blank=True, null=True)
use_default = models.BooleanField(default=True)
date_added = models.DateTimeField(auto_now=True, default=datetime.datetime.now(), null=True)
date_added = models.DateTimeField(auto_now=True)
is_active = models.BooleanField(default=True)
comment = models.CharField(max_length=100, blank=True, null=True)

View File

@ -96,7 +96,7 @@ def asset_add(request):
username = request.POST.get('username')
password = request.POST.get('password')
port = request.POST.get('port')
password_encode = CRYPTOR.encrypt(password)
password_encode = password
else:
username = None
port = None

View File

@ -8,7 +8,7 @@ class Log(models.Model):
dept_name = models.CharField(max_length=20)
log_path = models.CharField(max_length=100)
start_time = models.DateTimeField(null=True)
pid = models.IntegerField(max_length=10)
pid = models.IntegerField()
is_finished = models.BooleanField(default=False)
handle_finished = models.BooleanField(default=False)
end_time = models.DateTimeField(null=True)

View File

@ -132,10 +132,7 @@ class Command(MyInventory):
forks=forks
)
self.results = hoc.run()
<<<<<<< HEAD
=======
>>>>>>> 1c3d642be250026193bbdd9e2fe798e0197f5696
if self.stdout:
return {"ok": self.stdout}
else:
@ -446,10 +443,7 @@ class App(MyPlaybook):
if __name__ == "__main__":
pass
<<<<<<< HEAD
=======
>>>>>>> 1c3d642be250026193bbdd9e2fe798e0197f5696
# resource = {
# "group1": {
# "hosts": [{"hostname": "127.0.0.1", "port": "22", "username": "root", "password": "xxx"},],
@ -459,15 +453,9 @@ if __name__ == "__main__":
# command = Command(resource)
# print command.run("who", group="group1")
<<<<<<< HEAD
# resource = [{"hostname": "192.168.10.148", "port": "22", "username": "root", "password": "xxx"}]
# task = Tasks(resource)
# print task.get_host_info()
=======
# resource = [{"hostname": "127.0.1.1", "port": "22", "username": "root", "password": "xxx"}]
# command = Command(resource)
# print command.run("who")
>>>>>>> 1c3d642be250026193bbdd9e2fe798e0197f5696
# playbook = MyPlaybook(resource)
# playbook.run('test.yml')

View File

@ -9,15 +9,9 @@ from jperm.models import SysUser
from juser.user_api import gen_ssh_key
<<<<<<< HEAD
from juser.models import User, UserGroup
from jasset.models import Asset, AssetGroup
from jperm.models import PermRole, PermRule
=======
from juser.models import User, UserGroup
from jasset.models import Asset, AssetGroup
from jperm.models import PermRole, PermRule
>>>>>>> 1c3d642be250026193bbdd9e2fe798e0197f5696
from jperm.utils import updates_dict
from jperm.ansible_api import Tasks
@ -156,7 +150,6 @@ def perm_rule_add(request):
else:
return HttpResponse("add rule failed")
<<<<<<< HEAD
@require_role('admin')
def perm_rule_list(request):
"""
@ -176,59 +169,6 @@ def perm_rule_list(request):
=======
user_id = request.GET.get('id', '')
user = get_object(User, id=user_id)
if request.method == 'GET' and user:
# 获取所有 用户,用户组,资产,资产组,用户角色, 用于添加授权规则
users = User.objects.all()
user_groups = UserGroup.objects.all()
assets = Asset.objects.all()
asset_groups = AssetGroup.objects.all()
roles = PermRole.objects.all()
data_content = {"users": users, "user_groups": user_groups,
"assets": assets, "asset_groups": asset_groups,
"roles": roles}
render_data = updates_dict(data_nav, data_content)
return my_render('jperm/rule_add.html', render_data, request)
elif request.method == 'POST' and user:
# 获取用户选择的 用户,用户组,资产,资产组,用户角色
users_select = request.POST.getlist('user', [])
user_groups_select = request.POST.getlist('usergroup', [])
assets_select = request.POST.getlist('asset', [])
asset_groups_select = request.POST.getlist('assetgroup', [])
roles_select = request.POST.getlist('role', [])
# 获取需要授权的主机列表
assets_obj = [Asset.objects.get(ip=asset) for asset in assets_select]
asset_groups_obj = [AssetGroup.objects.get(name=group) for group in asset_groups_select]
group_assets_obj = [ asset for assets in [group.user_set.all() for group in asset_groups_obj]]
# 获取需要授权的用户列表
users_obj = [User.objects.get(name=user) for user in users_select]
user_groups_obj = [UserGroup.objects.get(name=group) for group in user_groups_select]
group_users_obj = [user for user in [group.user_set.all() for group in user_groups_obj]]
# 获取授予的角色列表
roles_obj = [User.objects.get(name=role) for role in roles_select]
# 调用Ansible API 执行授权
# 授权成功,写回数据库
print request.POST
return HttpResponse(request.POST)
>>>>>>> 1c3d642be250026193bbdd9e2fe798e0197f5696
@require_role('admin')

View File

@ -1,12 +1,12 @@
#coding: utf8
[base]
url = http://192.168.10.148
url = http://127.0.0.1
key = 88aaaf7ffe3c6c04
log = debug
[db]
host = 192.168.10.148
host = 127.0.0.1
port = 3306
user = jumpserver
password =mysql1234
@ -20,7 +20,7 @@ root_dn = cn=admin,dc=jumpserver,dc=org
root_pw = secret234
[websocket]
web_socket_host = 192.168.10.148:3000
web_socket_host = 1127.0.0.1:3000
[mail]
mail_enable = 1

View File

@ -6,7 +6,7 @@ from django.db import models
class Setting(models.Model):
name = models.CharField(max_length=100)
default_user = models.CharField(max_length=100, null=True, blank=True)
default_port = models.IntegerField(max_length=10, null=True, blank=True)
default_port = models.IntegerField(null=True, blank=True)
default_pri_key_path = models.CharField(max_length=100, null=True, blank=True)
class Meta: