Skip to content

Commit

Permalink
ddr
Browse files Browse the repository at this point in the history
  • Loading branch information
YoLoveLife committed Jul 18, 2018
1 parent db149fc commit 9277000
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 48 deletions.
5 changes: 5 additions & 0 deletions apps/authority/api/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import pyotp
import os
from qrcode import QRCode,constants
from urllib import parse
__all__ = [
"UserLoginAPI", "UserInfoAPI", "UserListAPI",
"UserOpsListAPI", "UserUpdateAPI", "UserDeleteAPI",
Expand Down Expand Up @@ -103,10 +104,14 @@ class UserDeleteAPI(WebTokenAuthentication,generics.DestroyAPIView):


def get_qrcode(user):
if not user.qrcode: # ''
user.qrcode = pyotp.random_base32(16)
user.save()
file_name = str(aes.encrypt(user.qrcode),encoding='utf-8')
file = settings.QCODE_ROOT+'/'+file_name+'.png'
if not os.path.exists(file):
data = pyotp.totp.TOTP(user.qrcode).provisioning_uri(user.username, issuer_name="devEops")
print('data',data)
qr = QRCode(
version=1,
error_correction=constants.ERROR_CORRECT_L,
Expand Down
4 changes: 2 additions & 2 deletions apps/authority/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class ExtendUser(AbstractUser):
img = models.CharField(max_length=10, default='user.jpg')
phone = models.CharField(max_length=11, default='None',)
full_name = models.CharField(max_length=11, default='未获取')
qrcode = models.CharField(max_length=29,default=pyotp.random_base32(29),editable=False)
qrcode = models.CharField(max_length=29, default='')
have_qrcode = models.BooleanField(default=False)
groups = models.ManyToManyField(
Group,
Expand Down Expand Up @@ -135,7 +135,7 @@ def get_group_name(self):
elif self.groups.count() == 0:
return "无权限"
else:
str = "|"
str = "-"
list = []
groups = self.groups.all()
for group in groups:
Expand Down
13 changes: 7 additions & 6 deletions apps/authority/tests.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.test import TestCase

# Create your tests here.
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.test import TestCase

# Create your tests here.
# DDR
19 changes: 17 additions & 2 deletions apps/manager/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,15 @@ def host_maker(dict_models):

def host_updater(obj, dict_models):
dict_models.pop('detail')
dict_models['_status'] = dict_models.pop('status')
status = dict_models.pop('status')
if obj.get().status == settings.STATUS_HOST_PAUSE:
if status == settings.STATUS_HOST_CAN_BE_USE:
pass
else:
dict_models['_status'] = settings.STATUS_HOST_CLOSE
else:
dict_models['_status'] = status

obj.update(**dict_models)


Expand Down Expand Up @@ -83,7 +91,14 @@ def cmdb2aliyun():
if expired.get('expired') < settings.ALIYUN_OVERDUETIME:
host.delete()
else:
host.status = status
if host.status == settings.STATUS_HOST_PAUSE:
if status == settings.STATUS_HOST_CAN_BE_USE:
pass
else:
host.status = settings.STATUS_HOST_CLOSE
else:
host.status = status



connect = redis.StrictRedis(host=settings.REDIS_HOST,port=settings.REDIS_PORT,db=settings.REDIS_SPACE,password=settings.REDIS_PASSWD)
Expand Down
10 changes: 7 additions & 3 deletions apps/ops/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Meta:


class MetaSerializer(serializers.ModelSerializer):
hosts = serializers.PrimaryKeyRelatedField(many=True, queryset=models.Host.objects.all())
hosts = serializers.PrimaryKeyRelatedField(required=False,many=True, queryset=models.Host.objects.all(),allow_null=True)
need_files = serializers.ListField(source="file_list", read_only=True)
contents = MetaContentSerializer(required=True, many=True, allow_null=True)
group = serializers.PrimaryKeyRelatedField(queryset=models.Group.objects.all())
Expand All @@ -40,16 +40,20 @@ def create(self, validated_data):
contents = validated_data.pop('contents')
validated_data.pop('qrcode')
id_list = []
hosts = None
for content in contents:
content_instance = models.META_CONTENT.objects.create(**content)
id_list.append(content_instance.id)
hosts = validated_data.pop('hosts')

if 'hosts' in validated_data.keys():
hosts = validated_data.pop('hosts')

contests_list = models.META_CONTENT.objects.filter(id__in=id_list)

obj = models.META.objects.create(**validated_data)
obj.contents.add(*contests_list)
obj.hosts.set(hosts)
if hosts is not None:
obj.hosts.set(hosts)
obj.save()

return obj
Expand Down
66 changes: 33 additions & 33 deletions apps/variable/models.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.conf import settings
from manager.models import Group
import uuid
__all__ = [
"Variable", "Var2Group",
]


class Variable(models.Model):
id = models.AutoField(primary_key=True)
uuid = models.UUIDField(auto_created=True, default=uuid.uuid4, editable=False)
key = models.CharField(default='', max_length=30)
value = models.CharField(default='', max_length=30)

class Meta:
ordering = ['id',]
abstract = True


class Var2Group(Variable):
group = models.ForeignKey(Group, related_name='vars', null=True, on_delete=models.SET_NULL)

class Meta:
permissions = (
('yo_list_group_var', u'罗列组参数'),
('yo_change_group_var', u'新增组参数'),
('yo_delete_group_var', u'删除组参数'),
)

# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.conf import settings
from manager.models import Group
import uuid
__all__ = [
"Variable", "Var2Group",
]


class Variable(models.Model):
id = models.AutoField(primary_key=True)
uuid = models.UUIDField(auto_created=True, default=uuid.uuid4, editable=False)
key = models.CharField(default='', max_length=100)
value = models.CharField(default='', max_length=200)

class Meta:
ordering = ['id',]
abstract = True


class Var2Group(Variable):
group = models.ForeignKey(Group, related_name='vars', null=True, on_delete=models.SET_NULL)

class Meta:
permissions = (
('yo_list_group_var', u'罗列组参数'),
('yo_change_group_var', u'新增组参数'),
('yo_delete_group_var', u'删除组参数'),
)
3 changes: 1 addition & 2 deletions apps/yodns/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# Time 17-10-25
# Author Yo
# Email [email protected]

from __future__ import absolute_import, unicode_literals
from celery.task import periodic_task
from celery.schedules import crontab
Expand Down Expand Up @@ -37,4 +36,4 @@ def dns_flush():
for dns in DNS.objects.all().exclude(Q(father__isnull=True)|Q(father__father__isnull=True)):
dns.inner_dig = reflush(dns,settings.INNER_DNS)
dns.dig = reflush(dns,settings.OUTER_DNS)
dns.save()
dns.save()
1 change: 1 addition & 0 deletions deveops/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@
"description": "description",
"first_name":"sn",
"phone":"mobile",
"groups": "",
}
AUTH_LDAP_ALWAYS_UPDATE_USER = True
# AUTH_LDAP_MIRROR_GROUPS = True
Expand Down
2 changes: 2 additions & 0 deletions deveops/tools/aliyun/cms.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ def get_line_opts(results, title):
time = []
minimum = []
maximum = []
if not results:
return {}
for result in json.loads(results):
d = datetime.datetime.fromtimestamp(result['timestamp']/1000)
str1 = d.strftime("%Y/%m/%d %H:%M:%S") #"%Y/%m/%d %H:%M:%S"
Expand Down

0 comments on commit 9277000

Please sign in to comment.