def process(server_obj, server_info, user_obj): response = BaseResponse() try: disk_info = server_info['disk'] if not disk_info['status']: response.status = False models.ErrorLog.objects.create(asset_obj=server_obj.asset, title='disk-agent', content=disk_info['error']) return response client_disk_dict = disk_info['data'] disk_obj_list = models.Disk.objects.filter(server_obj=server_obj) disk_slots = map(lambda x: x, (item.slot for item in disk_obj_list)) update_list = agorithm.get_intersection(set(client_disk_dict.keys()), set(disk_slots)) add_list = agorithm.get_exclude(client_disk_dict.keys(), update_list) del_list = agorithm.get_exclude(disk_slots, update_list) HandleDisk._add_disk(add_list, client_disk_dict, server_obj, user_obj) HandleDisk._update_disk(update_list, disk_obj_list, client_disk_dict, server_obj, user_obj) HandleDisk._del_disk(del_list, disk_obj_list, server_obj, user_obj) except Exception as e: response.status = False models.ErrorLog.objects.create(asset_obj=server_obj.asset, title='disk-run', content=traceback.format_exc()) return response
def process(server_obj, server_info, user_obj): response = BaseResponse() try: mem_info = server_info['memory'] if not mem_info['status']: models.ErrorLog.objects.create(asset_obj=server_obj.asset, title='memory-agent', content=mem_info['error']) response.status = False return response client_mem_dict = mem_info['data'] mem_obj_list = models.Memory.objects.filter(server_obj=server_obj) mem_slots = map(lambda x: x, (item.slot for item in mem_obj_list)) update_list = agorithm.get_intersection(set(client_mem_dict.keys()), set(mem_slots)) add_list = agorithm.get_exclude(client_mem_dict.keys(), update_list) del_list = agorithm.get_exclude(mem_slots, update_list) HandleMemory._add_memory(add_list, client_mem_dict, server_obj, user_obj) HandleMemory._update_memory(update_list, mem_obj_list, client_mem_dict, server_obj, user_obj) HandleMemory._del_memory(del_list, mem_obj_list, server_obj, user_obj) except Exception as e: response.status = False models.ErrorLog.objects.create(asset_obj=server_obj.asset, title='memory-run', content=traceback.format_exc()) return response
def process(server_obj,server_info,user_obj): response = BaseResponse() try: # 获取数据库中所有网卡信息 # server_info 服务器最新汇报的数据 nic_info = server_info['nic'] if not nic_info['status']: response.status = False models.ErrorLog.objects.create(asset_obj=server_obj.asset,title='nic-agent',content=nic_info['error']) return response client_nic_dict = nic_info['data'] nic_obj_list = models.NIC.objects.filter(server_obj=server_obj) nic_name_list = map(lambda x:x,(item.name for item in nic_obj_list)) update_list = agorithm.get_intersection(set(client_nic_dict.keys()),set(nic_name_list)) add_list = agorithm.get_exclude(client_nic_dict.keys(),update_list) del_list = agorithm.get_exclude(nic_name_list,update_list) # 删除 更新 添加操作 HandleNic._add_nic(add_list, client_nic_dict, server_obj, user_obj) HandleNic._update_nic(update_list, nic_obj_list, client_nic_dict, server_obj, user_obj) HandleNic._del_nic(del_list, nic_obj_list, server_obj, user_obj) except Exception as e: response.status = False response.error = str(e) models.ErrorLog.objects.create(asset_obj=server_obj.asset,title='nic-run',content=traceback.format_exc()) return response
def process(server_obj, server_info, user_obj): response = BaseResponse() try: disk_info = server_info['disk'] if not disk_info['status']: response.status = False models.ErrorLog.objects.create(asset_obj=server_obj.asset, title='disk-agent', content=disk_info['error']) return response client_disk_dict = disk_info['data'] disk_obj_list = models.Disk.objects.filter(server_obj=server_obj) disk_slots = map(lambda x: x, (item.slot for item in disk_obj_list)) update_list = agorithm.get_intersection( set(client_disk_dict.keys()), set(disk_slots)) add_list = agorithm.get_exclude(client_disk_dict.keys(), update_list) del_list = agorithm.get_exclude(disk_slots, update_list) HandleDisk._add_disk(add_list, client_disk_dict, server_obj, user_obj) HandleDisk._update_disk(update_list, disk_obj_list, client_disk_dict, server_obj, user_obj) HandleDisk._del_disk(del_list, disk_obj_list, server_obj, user_obj) except Exception as e: response.status = False models.ErrorLog.objects.create(asset_obj=server_obj.asset, title='disk-run', content=traceback.format_exc()) return response
def process(server_obj, server_info, user_obj): response = BaseResponse() try: mem_info = server_info['memory'] if not mem_info['status']: models.ErrorLog.objects.create(asset_obj=server_obj.asset, title='memory-agent', content=mem_info['error']) response.status = False return response client_mem_dict = mem_info['data'] mem_obj_list = models.Memory.objects.filter(server_obj=server_obj) mem_slots = map(lambda x: x, (item.slot for item in mem_obj_list)) update_list = agorithm.get_intersection( set(client_mem_dict.keys()), set(mem_slots)) add_list = agorithm.get_exclude(client_mem_dict.keys(), update_list) del_list = agorithm.get_exclude(mem_slots, update_list) HandleMemory._add_memory(add_list, client_mem_dict, server_obj, user_obj) HandleMemory._update_memory(update_list, mem_obj_list, client_mem_dict, server_obj, user_obj) HandleMemory._del_memory(del_list, mem_obj_list, server_obj, user_obj) except Exception as e: response.status = False models.ErrorLog.objects.create(asset_obj=server_obj.asset, title='memory-run', content=traceback.format_exc()) return response
def process(server_obj, server_info, user_obj): response = BaseResponse() try: nic_info = server_info['nic'] if not nic_info['status']: response.status = False models.ErrorLog.objects.create(asset_obj=server_obj.asset, title='nic-agent', content=nic_info['error']) return response client_nic_dict = nic_info['data'] nic_obj_list = models.NIC.objects.filter(server_obj=server_obj) nic_name_list = map(lambda x: x, (item.name for item in nic_obj_list)) update_list = agorithm.get_intersection( set(client_nic_dict.keys()), set(nic_name_list)) add_list = agorithm.get_exclude(client_nic_dict.keys(), update_list) del_list = agorithm.get_exclude(nic_name_list, update_list) HandleInstance._add_nic(add_list, client_nic_dict, server_obj, user_obj) HandleInstance._update_nic(update_list, nic_obj_list, client_nic_dict, server_obj, user_obj) HandleInstance._del_nic(del_list, nic_obj_list, server_obj, user_obj) except Exception as e: response.status = False models.ErrorLog.objects.create(asset_obj=server_obj.hostname, title='nic-run', content=traceback.format_exc()) return response