from django.shortcuts import render,HttpResponse
import json
# Create your views here.
from repository import models
from aip.plugins import Plugins def server(request):
server_dict=json.loads(request.body.decode('utf-8'))
if not server_dict['basic']['status']:
return HttpResponse('iiiiiiiii') # hostname=server_dict['basic']['data']['hostname']
# server_obj=models.Server.objects.filter(hostname=hostname).first() cls=Plugins()
response=cls.process(server_dict)
print(response)
print(type(response))
return HttpResponse(json.dumps(response))

Views

from django.shortcuts import render,HttpResponse
from django.conf import settings
from repository import models
import importlib
from .basic import Basic
class Plugins(object):
def __init__(self):
self.settings=settings.PLUGIN_ITEMS
self.basic_key='basic'
self.board_key='board'
print(self.basic_key) def process(self,server_dict):
hostname = server_dict['basic']['data']['hostname']
server_obj = models.Server.objects.filter(hostname=hostname).first() ret={'code':1,'msg':None}
if not server_obj:
ret['code']=4
return ret
#直接传入参数
obj = Basic(server_obj, server_dict[self.basic_key], server_dict[self.board_key])
obj.exec()
# return HttpResponse('请求错误')
# else:
#使用内存。网卡等走的流程
for i,v in self.settings.items():
try:
class_obj,class_name=v.rsplit('.',maxsplit=1)
module=importlib.import_module(class_obj)
ret=getattr(module,class_name)
print(ret,'=======')
obj=ret(server_obj,server_dict[i])
print(obj,'//[[[[[[')
obj.exec()
print('////',obj.exec())
except Exception as e:
ret['code']=4
return ret

plugins init

from django.shortcuts import render,HttpResponse
from django.conf import settings
from repository import models
import importlib
from .basic import Basic
class Plugins(object):
def __init__(self):
self.settings=settings.PLUGIN_ITEMS
self.basic_key='basic'
self.board_key='board'
print(self.basic_key) def process(self,server_dict):
ret = {'code': 1, 'msg': None}
hostname = server_dict['basic']['data']['hostname']
server_obj = models.Server.objects.filter(hostname=hostname).first()
print('=====================',server_obj) if not server_obj:
ret['code']=4
return ret
#直接传入参数 obj = Basic(server_obj, server_dict[self.basic_key], server_dict[self.board_key])
obj.exec() # return HttpResponse('请求错误')
# else:
#使用内存。网卡等走的流程
for i,v in self.settings.items(): try:
class_obj,class_name=v.rsplit('.',maxsplit=1) module=importlib.import_module(class_obj)
print(module)
rets=getattr(module,class_name)
print(rets) obj=rets(server_obj,server_dict[i]) obj.exec()
print(obj.exec()) except Exception as e:
ret['code']=4
return ret
from repository import models
class Basic(object):
def __init__(self,server_obj,basic_key,board_key):
self.server_obj=server_obj
self.basic_key=basic_key
self.boaed_key=board_key def exec(self): temp = {} # 获取新的主机详细信息
basic_obj = self.basic_key['data']
board_obj = self.boaed_key['data']
temp.update(basic_obj)
temp.update(board_obj)
# 数据库更改主机的详细信息
server_obj = models.Server.objects.filter(hostname=self.server_obj.hostname).first()
temps = []
for i, new_values in temp.items():
old_values = getattr(server_obj, i)
if new_values != old_values:
conent = "[%s]的[%s]由[%s]更改为[%s]" % (self.server_obj.hostname, i, old_values, new_values)
temps.append(conent)
setattr(server_obj, i, new_values)
server_obj.save()
if temps:
models.ServerRecord.objects.create(server_obj=server_obj, content=';'.join(temps),

basic

from repository import models

class Disk(object):
def __init__(self,server_obj,server_dict):
self.server_obj=server_obj
self.server_dict=server_dict
self.temps=[] def exec(self):
# 配置disk详细信息
disk_obj = self.server_dict['data']
new_disk_keys = set(disk_obj.keys())
disk_list = models.Disk.objects.all()
old_disk_keys = {item.slot for item in disk_list}
# print(old_disk_keys)
app_disk = new_disk_keys - old_disk_keys
del_disk = old_disk_keys - new_disk_keys
same_disk = new_disk_keys & old_disk_keys
if app_disk:
self.add_disk_exec(app_disk, disk_obj) if del_disk:
self.del_disk_exec(del_disk,disk_obj)
if same_disk:
self.same_disk_exec(same_disk, disk_obj) if self.temps:
models.ServerRecord.objects.create(server_obj=self.server_obj, content=';'.join(self.temps),)
# 增加硬盘信息 def add_disk_exec(self,app_disk,disk_obj):
for i in app_disk:
obj = disk_obj[i]
obj['server_obj'] = self.server_obj
models.Disk.objects.create(**obj)
conent = "Disk增加信息[%s]" % obj
self.temps.append(conent)
# print(temps)
# if temps:
# models.ServerRecord.objects.create(server_obj=self.server_obj, content=';'.join(temps),
# creator_id=request.user) # 删除硬盘信息
def del_disk_exec(self,del_disk,disk_obj):
for i in del_disk:
conent = "Disk删除硬盘信息[%s]" % (disk_obj[i])
models.Disk.objects.filter(slot__in=i).delete()
self.temps.append(conent)
print(conent)
# if temps:
# models.ServerRecord.objects.create(server_obj=server_obj, content=';'.join(temps),
# creator_id=request.user) # 共同相同:same_disk
def same_disk_exec(self,same_disk,disk_obj):
for i in same_disk:
new_values = disk_obj[i]
disk_f = models.Disk.objects.filter(slot=i).first()
for i, new_values_new in new_values.items():
old_values = getattr(disk_f, i)
if new_values_new != old_values:
setattr(disk_f, i, new_values_new)
conent = "[%s]的[%s]由[%s]更改为[%s]" % (i, i, old_values, new_values_new)
self.temps.append(conent)
disk_f.save()

disk

from repository import models
class Memory(object):
def __init__(self,server_obj,server_dict):
self.server_obj=server_obj
self.server_dict=server_dict
self.temps=[] def exec(self):
# 更新memory信息
memory_obj = self.server_dict['data']
new_memory_keys = set(memory_obj.keys())
memory_list = models.Memory.objects.all()
old_memory_keys = {item.slot for item in memory_list}
# print(old_disk_keys)
app_memory = new_memory_keys - old_memory_keys
del_memory = old_memory_keys - new_memory_keys
same_memory = new_memory_keys & old_memory_keys
# 增加硬盘信息
if app_memory:
self.add_memory_key( memory_obj, app_memory) if del_memory:
self.del_memory_key(del_memory, memory_obj)
if same_memory:
self.same_memory_key(same_memory, memory_obj)
if self.temps:
models.ServerRecord.objects.create(server_obj=self.server_obj, content=';'.join(self.temps)) def add_memory_key(self,memory_obj,app_memory):
for i in app_memory:
obj = memory_obj[i]
obj['server_obj'] = self.server_obj
models.Memory.objects.create(**obj)
conent = "memory增加信息[%s]" % obj
self.temps.append(conent)
# print(temps)
# if temps:
# models.ServerRecord.objects.create(server_obj=server_obj, content=';'.join(temps),
# ) # 删除硬盘信息
def del_memory_key(self,del_memory,memory_obj):
for i in del_memory:
conent = "Disk删除硬盘信息[%s]" % (memory_obj[i])
models.Memory.objects.filter(slot__in=i).delete()
self.temps.append(conent)
# print(conent)
# if temps:
# models.ServerRecord.objects.create(server_obj=server_obj, content=';'.join(temps),
# ) # 共同相同:same_disk
def same_memory_key(self,same_memory,memory_obj):
for i in same_memory:
new_values = memory_obj[i]
memory_f = models.Memory.objects.filter(slot=i).first()
for i, new_values_new in new_values.items():
old_values = getattr(memory_f, i)
if new_values_new != old_values:
setattr(memory_f, i, new_values_new)
conent = "[%s]的[%s]由[%s]更改为[%s]" % (i, i, old_values, new_values_new)
self.temps.append(conent)
memory_f.save()
# if temp:

memory

from repository import models
class NIC(object):
def __init__(self,server_obj,server_dict):
self.server_obj=server_obj
self.nic_dict=server_dict
self.temps=[] def exec(self):
# 配置nic信息
nic_obj =self.nic_dict['data']
nic_list = self.server_obj.nic.values('name')
new_nic_obj = set(self.nic_dict['data'].keys())
old_nic_obj = {nic['name'] for nic in nic_list}
# print(new_nic_obj)
# print(old_nic_obj)
app_nic = new_nic_obj - old_nic_obj
del_nic = old_nic_obj - new_nic_obj
same_nic = new_nic_obj & old_nic_obj
if app_nic:
self.add_nic(app_nic,nic_obj) if del_nic:
self.del_nic(del_nic) if same_nic:
self.same_nic_key(same_nic,nic_obj) if self.temps:
models.ServerRecord.objects.create(server_obj=self.server_obj, content=';'.join(self.temps))
# 增加nic信息
def add_nic(self,app_nic,nic_obj):
for item in app_nic:
values = nic_obj[item]
values['server_obj'] = self.server_obj
models.NIC.objects.create(**values)
conent = "nic增加信息[%s]" % item
self.temps.append(conent)
# print(temps)
# if temps:
# models.ServerRecord.objects.create(server_obj=server_obj, content=';'.join(temps)) # 删除硬盘信息
def del_nic(self,del_nic):
for item in del_nic:
conent = "nic删除信息[%s]" % item
models.NIC.objects.filter(server_obj=self.server_obj, name__in=item).delete()
self.temps.append(conent)
# if temps:
# models.ServerRecord.objects.create(server_obj=server_obj, content=';'.join(temps))
def same_nic_key(self,same_nic,nic_obj):
for name in same_nic:
value = nic_obj[name]
obj = models.NIC.objects.filter(server_obj=self.server_obj, name=name).first()
for k, new_val in value.items():
old_val = getattr(obj, k)
if old_val != new_val:
conent = "名称%s的网卡的%s由%s变更为%s" % (name, k, old_val, new_val)
self.temps.append(conent)
setattr(obj, k, new_val)
obj.save()
# if temps:

nic

服务系统 server端的更多相关文章

  1. Eureka系列(二) 服务注册Server端具体实现

    服务注册 Server端流程   我们先看下面这张图片,这张图片简单描述了下我们EurekaClient 在调用EurekaServer 提供的服务注册Http接口,Server端实现接口执行的大致流 ...

  2. Eureka系列(七) 服务下线Server端具体实现

    服务下线的大致流程图   下面这张图很简单地描述了Server端服务下线的大致流程: 服务下线Server端实现源码分析   Eureka服务实现是通过Server端InstanceResource ...

  3. zabbix配置文件详解--服务(server)端、客户(agent)端、代理(proxy)端

    在zabbix服务(server)端.客户(agent)端.代理(proxy)端分别对应着一个配置文件,即:zabbix_server.conf,zabbix_agentd.conf,zabbix_p ...

  4. 微服务学习三:springboot与springcloud集成之Eurake的使用(server端,client端)

    这个多亏了网站上的一个大神的博客: http://blog.csdn.net/forezp/article/details/70148833 强烈推荐学习: 1.springcloud是什么,这个大家 ...

  5. Eureka系列(四) 获取服务Server端具体实现

    获取服务 Server端流程   我们先看下面这张图片,这张图片简单描述了下我们EurekaClient在调用EurekaServer 提供的获取服务Http接口,Server端实现接口执行的大致流程 ...

  6. 详解zabbix安装部署(Server端篇)

    原文:http://blog.chinaunix.net/uid-25266990-id-3380929.html Linux下常用的系统监控软件有Nagios.Cacti.Zabbix.Monit等 ...

  7. Unity3d Web Player 与server端联网配置

    针对Unity3d Web Player 的server端联网配置写一随笔咯.  以SmartFoxServer2X官方的Unity3d Example ”tris“为例,部署好服务器之后,在Unit ...

  8. Python的XMLRPC机制:实现跨进程间、client/server端通信

    SimpleXMLRPCServer模块式python语言的一个基于 xml 格式的进程间通信的基础框架. SimpleXMLRPCServer是一个单线程的服务器,这意味着,如果几个客户端同时发出多 ...

  9. 图解server端网络架构

    这篇是计算机类的优质首发推荐>>>><图解server端网络架构> 467张图表讲透构建高可用高性能server实战 写给网络架构师 serverproject师的 ...

随机推荐

  1. 关于http ,那些你必须知道的事

    一,HTTP简介 1,HTTP协议是Hyper Text Transfer Protocol(超文本传输协议)的缩写,是用于从万维网(WWW:World Wide Web )服务器传输超文本到本地浏览 ...

  2. spring-common.xml

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  3. flutter 修改

    原来用的是tabviewer来写的,但是有点问题. 点到某一个tab,会导致加载前一个tab的数据,看到别人的文章keep tab的做法,写了 tabbar的控件. 我想了一把,直接换成了pagerv ...

  4. RMAN 总括 组成 配置 检测

    RMAN 组件: 1. RMAN 执行程序, 也就是RMAN 命令. 2. Server session : 服务器上的进程, 是真正用来干活的. 3. Target database: 你想要进行备 ...

  5. java 教程

    1.视频教程 http://blog.csdn.net/zhangdaiscott/article/details/18220411 2.书籍教程: 3.学习课程

  6. Easyui Datagrid的Rownumber行号显示问题

    Datagrid中当你的行数据超过9999时,第一列的行号rownumber将会因为表格内容过长而导致无法显示全部数字, 这一点Easyui无法做到自适应 所以需要进行修改,这里扩展一个方法就行了. ...

  7. edmx-新建表

  8. 第二百二十八节,jQuery EasyUI,TreeGrid(树形表格)组件

    jQuery EasyUI,TreeGrid(树形表格)组件 学习要点: 1.加载方式 2.属性列表 3.事件列表 4.方法列表 本节课重点了解 EasyUI 中 TreeGrid(树形表格)组件的使 ...

  9. MFC多国语言——资源DLL

    此随笔中主要内容来自http://blog.csdn.net/china_hxx/article/details/10066655,原出处不详. 以下内容基于VC 6.0.要实现界面多语言化,必须要先 ...

  10. 利用jsonrpc技术包装uiautomator

    昨天一天在网上搜索解决上一篇文章中的exception: monkeyrunner内置uiautomator出错的原因 尽管没找到解决办法.可是让我无意中发现了一个好工具,比sl4a更好用的工具.直接 ...