def del_asset(id): ''' 删除单台服务器信息,移除至回收表,更改状态,并且停监控 ''' if request.method == 'DELETE': host = abort_if_id_doesnt_exist(Asset,host_id=id) if host: #将data新增到回收表中 data = {'idrac_user': host.idrac_user , 'logical_cpu_cores': host.logical_cpu_cores , 'idrac_userpass': host.idrac_userpass , 'system_version': host.system_version , 'idc_un': host.idc_un , 'father_ip': host.father_ip , 'models': host.models , 'system_note': host.system_note , 'device_model': host.device_model , 'hard_disk': host.hard_disk , 'create_time': host.create_time , 'father_id': host.father_id , 'device_type': host.device_type , 'ethernet_interface': host.ethernet_interface , 'physical_memory': host.physical_memory , 'metadata': host.metadata , 'idc_cabinet': host.idc_cabinet , 'system_network_card': host.system_network_card , 'system_hostname': host.system_hostname , 'system_status': host.system_status , 'memory_slots_number': host.memory_slots_number , 'system_userpass': host.system_userpass , 'device_sn': host.device_sn , 'physical_cpu_cores': host.physical_cpu_cores , 'physical_cpu_model': host.physical_cpu_model , 'system_mac': host.system_mac , 'system_ip': host.system_ip , 'group_id': host.group_id , 'system_user': host.system_user , 'system_kernel': host.system_kernel , 'idrac_ip': host.idrac_ip , 'idc_id': host.idc_id , 'system_swap': host.system_swap , 'guarantee_date': host.guarantee_date , 'offline_time': datetime.now() , "app_name": [i.app_name for i in host.cmdb_application.all()] if host.models == 'app' else host.models } #montior_stop(host.System_Ip) dbdel(Asset,host_id=id) db.session.add(Asset_offline(**data)) db.session.commit() #for i in dir(host): # data[i] = i #eval('host.%s' % i) #print(data) return task.json_message_200('Sucess'), 200 else: return task.json_message_404(),404
def delete(self, permid): ''' Delete Perms ''' permobj = abort_if_id_doesnt_exist(Perm, id=permid) if not permobj: return my_response( dict(result=False, message='ID is not exist', code=410)) dbdel(Perm, id=permid) log(level='info', message='Delete Perm: id=%s' % permid) return my_response(dict(result=True, message='Perm Delete Success'))
def delete(self, userid): ''' Delete User ''' userobj = abort_if_id_doesnt_exist(User, id=userid) if not userobj: return my_response( dict(result=False, message='ID is not exist', code=410)) dbdel(User, id=userid) log(level='info', message='Delete User: userid=%s' % userid) return my_response(dict(result=True, message='User Delete Success'))
def delete(self): ''' ''' args = self.reqparse.parse_args(strict=True) hostid = args.get('Host_Id') idcobj = abort_if_id_doesnt_exist(Asset, Host_Id=hostid) if not idcobj: return my_response( dict(result=False, message='ID is not exist', code=410)) dbdel(Asset, Host_Id=hostid) #log(level='info', message='Delete User: userid=%s' % userid) return my_response( dict(result=True, message='Hard_Disk Delete Success'))
def delete(self): ''' ''' parser = reqparse.RequestParser() parser.add_argument('id', type=str, required=True, location='json') args = parser.parse_args() vcid = args.get('id') idcobj = abort_if_id_doesnt_exist(vCenter, id=vcid) if not idcobj: return my_response( dict(result=False, message='ID is not exist', code=410)) dbdel(vCenter, id=vcid) #log(level='info', message='Delete User: userid=%s' % userid) return my_response(dict(result=True, message='vcenter Delete Success'))
def Init(id): p = vCenter.query.filter_by(id=id).first() try: pysphere = pp_pysphere(HOST=p.host, USER=p.user, PASSWORD=p.password) props = pysphere.get_properties() errors = {} for k, v in props.items(): if 'host' in k: Host_Id = p.area + '-' + k Host_Id_List = [i.Host_Id for i in Esxi_Server.query.all()] if Host_Id not in Host_Id_List: try: esxi = Esxi_Server( Host_Id=Host_Id, Mac_Address=v.get('Mac_Address', 'Null'), Net_Dev_Name=v.get('Net_Dev_Name', 'Null'), Physical_Cpu_Mhz=v.get('Physical_Cpu_Mhz', 'Null'), Physical_Cpu_Model=v.get('Physical_Cpu_Model', 'Null'), Physical_Memory=v.get('Physical_Memory', 'Null'), Physical_Cpu_Cores=v.get('Physical_Cpu_Cores', 'Null'), Physical_Cpu_Pkgs=v.get('Physical_Cpu_Pkgs', 'Null'), Logical_Cpu_Cores=v.get('Logical_Cpu_Cores', 'Null'), Device_UUID=v.get('Device_UUID', 'Null'), Device_Type=v.get('Device_Type', 'Null'), Device_Status=v.get('Device_Status', 'Null'), System_Ip=v.get('ipAddress', 'Null'), Device_Model=v.get('Device_Model', 'Null'), Datastore_Space=v.get('Datastore_Space', 'Null'), Datastore_Name=v.get('Datastore_Name', 'Null'), Datastore_Type=v.get('Datastore_Type', 'Null'), Datastore_Free_Space=v.get('DatastoreFreespace', 'Null'), ) dbadd(esxi) except Exception, e: #runlog(e, level='error') errors[k] = e else: dbdel(Esxi_Server, Host_Id=Host_Id) try: esxi = Esxi_Server( Host_Id=Host_Id, Mac_Address=v.get('Mac_Address', 'Null'), Net_Dev_Name=v.get('Net_Dev_Name', 'Null'), Physical_Cpu_Mhz=v.get('Physical_Cpu_Mhz', 'Null'), Physical_Cpu_Model=v.get('Physical_Cpu_Model', 'Null'), Physical_Memory=v.get('Physical_Memory', 'Null'), Physical_Cpu_Cores=v.get('Physical_Cpu_Cores', 'Null'), Physical_Cpu_Pkgs=v.get('Physical_Cpu_Pkgs', 'Null'), Logical_Cpu_Cores=v.get('Logical_Cpu_Cores', 'Null'), Device_UUID=v.get('Device_UUID', 'Null'), Device_Type=v.get('Device_Type', 'Null'), Device_Status=v.get('Device_Status', 'Null'), System_Ip=v.get('ipAddress', 'Null'), Device_Model=v.get('Device_Model', 'Null'), Datastore_Space=v.get('Datastore_Space', 'Null'), Datastore_Name=v.get('Datastore_Name', 'Null'), Datastore_Type=v.get('Datastore_Type', 'Null'), Datastore_Free_Space=v.get('DatastoreFreespace', 'Null'), ) dbadd(esxi) except Exception, e: #runlog(e, level='error') errors[k] = e elif 'vm' in k: Host_Id = p.area + '-' + k Father_Id = p.area + '-' + v['summary.runtime.host'] System_Ip = v.get('guest.ipAddress', 'Null') Hard_Disk = str( v.get('summary.storage.committed', 0) / 1073741824) + 'G' Physical_Memory = str( v.get('config.hardware.memoryMB', 0) / 1024) + 'G' if System_Ip != 'Null': if not ip_check(System_Ip): System_Ip = 'Null' Host_Id_List = [i.Host_Id for i in Esxi_Vmware.query.all()] if Host_Id not in Host_Id_List: try: vmw = Esxi_Vmware( Host_Id=Host_Id, Father_Id=Father_Id, Physical_Cpu_Cores=v.get('config.hardware.numCPU', 'Null'), Hard_Disk=Hard_Disk, System_Hostname=v.get('guest.hostName', 'Null'), System_Uptime=v.get( 'summary.quickStats.uptimeSeconds', 'Null'), System_Ip=System_Ip, Ethernet_Cards=v.get( 'summary.config.numEthernetCards', 'Null'), Physical_Memory=Physical_Memory, Power_Status=v.get('summary.runtime.powerState', 'Null'), Guest_Status=v.get('guest.guestState', 'Null'), HeartBeatStatus=v.get('guestHeartbeatStatus', 'Null'), Show_Name=v.get('name', 'Null'), Virtual_Disk_Nums=v.get( 'summary.config.numVirtualDisks', 'Null'), Tool_Status=v.get('guest.toolsStatus', 'Null'), ) dbadd(vmw) except Exception, e: #runlog(e, level='error') errors[k] = e
'Null'), Guest_Status=v.get('guest.guestState', 'Null'), HeartBeatStatus=v.get('guestHeartbeatStatus', 'Null'), Show_Name=v.get('name', 'Null'), Virtual_Disk_Nums=v.get( 'summary.config.numVirtualDisks', 'Null'), Tool_Status=v.get('guest.toolsStatus', 'Null'), ) dbadd(vmw) except Exception, e: #runlog(e, level='error') errors[k] = e else: dbdel(Esxi_Vmware, Host_Id=Host_Id) try: vmw = Esxi_Vmware( Host_Id=Host_Id, Father_Id=Father_Id, Physical_Cpu_Cores=v.get('config.hardware.numCPU', 'Null'), Hard_Disk=Hard_Disk, System_Hostname=v.get('guest.hostName', 'Null'), System_Uptime=v.get( 'summary.quickStats.uptimeSeconds', 'Null'), System_Ip=System_Ip, Ethernet_Cards=v.get( 'summary.config.numEthernetCards', 'Null'), Physical_Memory=Physical_Memory, Power_Status=v.get('summary.runtime.powerState',