Skip to content

Commit

Permalink
commit init db.sql and fix tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
YoLoveLife committed Jul 16, 2018
1 parent e8a55e7 commit f2f161a
Show file tree
Hide file tree
Showing 9 changed files with 228 additions and 62 deletions.
34 changes: 17 additions & 17 deletions apps/authority/api/permission.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# -*- coding:utf-8 -*-
from .. import models,serializers
from rest_framework import generics
from rest_framework.permissions import IsAuthenticated
from django.contrib.auth.models import Permission
from authority.permission import permission as PermissionPermission

__all__ = [
"PermissionListAPI"
]


class PermissionListAPI(generics.ListAPIView):
module = Permission
serializer_class = serializers.PermissionSerializer
queryset = Permission.objects.filter(codename__istartswith="yo_")
permission_classes = [PermissionPermission.PermissionListRequiredMixin,IsAuthenticated]
# -*- coding:utf-8 -*-
from .. import models,serializers
from rest_framework import generics
from rest_framework.permissions import IsAuthenticated
from django.contrib.auth.models import Permission
from authority.permission import permission as PermissionPermission

__all__ = [
"PermissionListAPI"
]


class PermissionListAPI(generics.ListAPIView):
module = Permission
serializer_class = serializers.PermissionSerializer
queryset = Permission.objects.filter(codename__istartswith="yo_")
permission_classes = [PermissionPermission.PermissionListRequiredMixin,IsAuthenticated]
8 changes: 4 additions & 4 deletions apps/dashboard/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def expired_aliyun_ecs():
from deveops.tools.aliyun import ecs
API = ecs.AliyunECSTool()
for page in range(1,API.pagecount+1):
results = API.get_instances(page)
results = API.request_get_instances(page)
for result in results:
dict_models = API.get_aliyun_expired_models(result)
if settings.ALIYUN_OVERDUETIME < dict_models.get('expired')< settings.ALIYUN_EXPIREDTIME:
Expand All @@ -32,7 +32,7 @@ def expired_aliyun_rds():
from deveops.tools.aliyun import rds
API = rds.AliyunRDSTool()
for page in range(1,API.pagecount+1):
results = API.get_instances(page)
results = API.request_get_instances(page)
for result in results:
if not API.is_readonly(result):
dict_models = API.get_aliyun_expired_models(result)
Expand All @@ -46,7 +46,7 @@ def expired_aliyun_kvstore():
from deveops.tools.aliyun import kvstore
API = kvstore.AliyunKVStoreTool()
for page in range(1,API.pagecount+1):
results = API.get_instances(page)
results = API.request_get_instances(page)
for result in results:
dict_models = API.get_aliyun_expired_models(result)
if settings.ALIYUN_OVERDUETIME < dict_models.get('expired')< settings.ALIYUN_EXPIREDTIME:
Expand All @@ -59,7 +59,7 @@ def expired_aliyun_mongodb():
from deveops.tools.aliyun import mongodb
API = mongodb.AliyunMongoDBTool()
for page in range(1,API.pagecount+1):
results = API.get_instances(page)
results = API.request_get_instances(page)
for result in results:
dict_models = API.get_aliyun_expired_models(result )
if settings.ALIYUN_OVERDUETIME < dict_models.get('expired')< settings.ALIYUN_EXPIREDTIME:
Expand Down
2 changes: 1 addition & 1 deletion apps/manager/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class Host(models.Model):

# 用户端口
sshport = models.IntegerField(default='22')
detail = models.ForeignKey(HostDetail, related_name='host', on_delete=models.SET_NULL, null=True)
detail = models.ForeignKey(HostDetail, related_name='host', on_delete=models.CASCADE, null=True)
_passwd = models.CharField(max_length=1000, default='', null=True, blank=True)

# 服务器状态
Expand Down
18 changes: 10 additions & 8 deletions apps/manager/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def aliyun2cmdb():
from deveops.tools.aliyun import ecs
API = ecs.AliyunECSTool()
for page in range(1,API.pagecount+1):
results = API.get_instances(page)
results = API.request_get_instances(page)
for result in results:
dict_models = API.get_aliyun_models(result)
host_query = Host.objects.filter(detail__aliyun_id=dict_models['detail']['aliyun_id'], connect_ip=dict_models['connect_ip'])
Expand All @@ -73,15 +73,17 @@ def cmdb2aliyun():
API = ecs.AliyunECSTool()
queryset = Host.objects.filter(~Q(detail__aliyun_id=''))
for host in queryset:
results = API.get_instance_status(host.detail.aliyun_id)
status = API.get_aliyun_instance_status(results)
if status is None:
# TODO: 提供一个逾期时间来延缓主机过期
status_results = API.request_get_instance_status(host.detail.aliyun_id)
status = API.get_aliyun_instance_status(status_results)
if status == 'delete':
host.delete()
elif host.status == settings.STATUS_HOST_PAUSE:
continue
else:
host.status = status
expired_results = API.request_get_instance(host.detail.aliyun_id)
expired = API.get_aliyun_expired_models(expired_results)
if expired.get('expired') < settings.ALIYUN_OVERDUETIME:
host.delete()
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
Loading

0 comments on commit f2f161a

Please sign in to comment.