Skip to content

Commit

Permalink
主机可以根据IP修改
Browse files Browse the repository at this point in the history
  • Loading branch information
YoLoveLife committed May 22, 2018
1 parent 4863ecb commit f2af38b
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,20 @@
from rest_framework.views import Response, status
from deveops.api import WebTokenAuthentication
import redis
import json
from deveops.conf import REDIS_PORT,REDIS_SPACE

__all__ = [
"DashboardAPI",
"DashboardManagerAPI",
]


class DashboardAPI(WebTokenAuthentication,generics.ListAPIView):
class DashboardManagerAPI(WebTokenAuthentication,generics.ListAPIView):
permission_classes = [AllowAny,]
# def get(self, request, *args, **kwargs):

def get(self, request, *args, **kwargs):
con = redis.StrictRedis(port=REDIS_PORT,db=REDIS_SPACE)
print(con.hgetall('MANAGER_STATUS'))
return Response(con.hgetall('MANAGER_STATUS'),status.HTTP_200_OK)
status_json = con.get('MANAGER_STATUS')
manager_status = json.loads(str(status_json, encoding='utf-8'))
return Response(manager_status,status.HTTP_200_OK)
31 changes: 21 additions & 10 deletions apps/dashboard/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from deveops.conf import ALIYUN_PAGESIZE,REDIS_PORT,REDIS_SPACE,EXPIREDTIME
import redis
import datetime
import json
from deveops.utils import aliyun
from deveops.utils import resolver

Expand Down Expand Up @@ -53,24 +54,34 @@ def aliyunRDSInfoCatch():
@periodic_task(run_every=crontab(minute='*'))
def managerStatusCatch():
connect.delete('MANAGER_STATUS')

status = {}
# 資產計數
from manager import models as Manager
host_count = Manager.Host.objects.count()
group_count = Manager.Group.objects.count()
status = {
'host_count':host_count,
'group_count':group_count,
}
status['host_count'] = Manager.Host.objects.count()
status['group_count'] = Manager.Group.objects.count()

# 類型統計
systypes = Manager.System_Type.objects.all()
sys_list = []
for sys in systypes:
status[sys.name] = sys.hosts_detail.count()
sys_list.append({'name': sys.name,'value': sys.hosts_detail.count()})
status['systemtype'] = sys_list
# 不同系统类型所涉及的主机个数

positions = Manager.Position.objects.all()
pos_list = []
for pos in positions:
status['pos'+str(pos.id)] = pos.hosts_detail.count()
pos_list.append({'name': pos.name,'value': pos.hosts_detail.count()})
status['position'] = pos_list
# 不同位置所涉及的主机个数

groups = Manager.Group.objects.all()
group_list = []
for group in groups:
status[group.uuid] = group.hosts.count()
group_list.append({'name': group.name,'value': group.hosts.count()})
status['groups'] = group_list

connect.hmset('MANAGER_STATUS', status)
status_json = json.dumps(status)
connect.set('MANAGER_STATUS',status_json)

4 changes: 2 additions & 2 deletions apps/dashboard/urls/api_urls.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from django.urls import path
from ..api import dashboard as DashboardAPI
from ..api import manager as ManagerAPI
from ..api import expired as ExpiredAPI

urlpatterns=[
# Resource dashboard api
path(r'v1/manager/', DashboardAPI.DashboardAPI.as_view()),
path(r'v1/manager/', ManagerAPI.DashboardManagerAPI.as_view()),
#
# Resource expire api
path(r'v1/expired/ecs/bypage/', ExpiredAPI.DashboardExpiredECSAPI.as_view()),
Expand Down
9 changes: 8 additions & 1 deletion apps/manager/api/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,14 @@ class ManagerHostListByPageAPI(WebTokenAuthentication, generics.ListAPIView):
# permission_classes = [HostPermission.HostListRequiredMixin,IsAuthenticated]
permission_classes = [AllowAny,]
pagination_class = HostPagination
filter_fields = '__all__'
filter_fields = ('groups',)

def get_queryset(self):
query = self.request.query_params.get('connect_ip', None)
if query is not None:
return self.queryset.filter(connect_ip__icontains=query)
else:
return self.queryset


class ManagerHostCreateAPI(WebTokenAuthentication,generics.CreateAPIView):
Expand Down
6 changes: 4 additions & 2 deletions apps/manager/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,10 @@ class Host(models.Model):
storages = models.ManyToManyField(Storage, blank=True, related_name='hosts', verbose_name=_('Host'))

# 相关信息
connect_ip = models.GenericIPAddressField(default='', null=False)
service_ip = models.GenericIPAddressField(default='0.0.0.0', null=True)
# connect_ip = models.GenericIPAddressField(default='', null=False)
connect_ip = models.CharField(max_length=15, default='', null=False)
service_ip = models.CharField(max_length=15, default='0.0.0.0', null=True)
# service_ip = models.GenericIPAddressField(default='0.0.0.0', null=True)

# 主机名称
hostname = models.CharField(max_length=50, default='localhost.localdomain', null=True, blank=True)
Expand Down
5 changes: 0 additions & 5 deletions apps/manager/urls/api_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from ..api import systype as SystypeAPI
from ..api import position as PositionAPI
from ..api import host as HostAPI
from ..api import dashboard as DashboardAPI
urlpatterns=[
# Resource group api
path(r'v1/group/', GroupAPI.ManagerGroupListAPI.as_view()),
Expand Down Expand Up @@ -41,8 +40,4 @@
# # Resource storage api
# path(r'v1/storage/', api.ManagerStorageListAPI.as_view()),
# path(r'v1/storage/(?P<pk>[0-9]+)/remove/', api.ManagerStorageRemoveAPI.as_view()),
#
# Resource dashboard api
path(r'v1/dashboard/', DashboardAPI.ManagerDashboardAPI.as_view()),
#
]

0 comments on commit f2af38b

Please sign in to comment.