def download_log(request): sys_mgr = sysinfo.sys_mgr() # get sys manager sys_mgr.rm_sys_log() # rm the exist tar log file log_tar_file = sys_mgr.tar_sys_log() response = FileResponse(log_tar_file, request=request, content_type='application/force-download') response.headers['Content-Disposition'] = 'attachment; filename=%s' % (os.path.basename(log_tar_file)) return response
def download_log(request): sys_mgr = sysinfo.sys_mgr() # get sys manager sys_mgr.rm_sys_log() # rm the exist tar log file log_tar_file = sys_mgr.tar_sys_log() response = FileResponse(log_tar_file, request=request, content_type='application/force-download') response.headers['Content-Disposition'] = 'attachment; filename=%s' % ( os.path.basename(log_tar_file)) return response
def system_cpu_list_get(request): sys_mgr = sysinfo.sys_mgr() # get sys manager cpus = sys_mgr.get_cpu_list() cpu_list_dict = [] for cpu in cpus: cpu_info = {'processor': int(cpu["processor"]), 'model_name': cpu["model name"], 'cpu_MHz': float(cpu["cpu MHz"]), 'cache_size': cpu["cache size"]} cpu_list_dict.append(cpu_info) return cpu_list_dict
def system_cpu_list_get(request): sys_mgr = sysinfo.sys_mgr() # get sys manager cpus = sys_mgr.get_cpu_list() cpu_list_dict = [] for cpu in cpus: cpu_info = { 'processor': int(cpu["processor"]), 'model_name': cpu["model name"], 'cpu_MHz': float(cpu["cpu MHz"]), 'cache_size': cpu["cache size"] } cpu_list_dict.append(cpu_info) return cpu_list_dict
def get_system_localhost(request): sys_mgr = sysinfo.sys_mgr() sys_uname = platform.uname() hostname = sys_mgr.get_hostname() dist_name, dist_version, dist_id = sys_mgr.get_dist_info() uptime = datetime.now() - datetime.fromtimestamp(psutil.BOOT_TIME) av1, av2, av3 = os.getloadavg() info = { 'hostname': hostname, 'system': sys_uname[0], 'release': sys_uname[2], 'version': sys_uname[3], 'machine': sys_uname[4], 'processor': sys_uname[5], 'dist_name': dist_name, 'dist_version': dist_version, 'dist_id': dist_id, "uptime": str(uptime).split('.')[0], "loadavg":[av1, av2, av3] } return info
def get_system_localhost(request): sys_mgr = sysinfo.sys_mgr() sys_uname = platform.uname() hostname = sys_mgr.get_hostname() dist_name, dist_version, dist_id = sys_mgr.get_dist_info() uptime = datetime.now() - datetime.fromtimestamp(psutil.BOOT_TIME) av1, av2, av3 = os.getloadavg() info = { 'hostname': hostname, 'system': sys_uname[0], 'release': sys_uname[2], 'version': sys_uname[3], 'machine': sys_uname[4], 'processor': sys_uname[5], 'dist_name': dist_name, 'dist_version': dist_version, 'dist_id': dist_id, "uptime": str(uptime).split('.')[0], "loadavg": [av1, av2, av3] } return info
def set_datetime(request): params = get_params_from_request(request) sys_mgr = sysinfo.sys_mgr() # get sys manager sys_mgr.set_datetime(params['datetime'], user=request.client_addr) return Response(status=200)
def get_datetime(request): sys_mgr = sysinfo.sys_mgr() # get sys manager datetime_str = sys_mgr.get_datetime() return {'datetime': datetime_str}
def sys_reboot(request): sys_mgr = sysinfo.sys_mgr() # get sys manager sys_mgr.reboot(user=request.client_addr) return Response(status=200)
def sys_poweroff(request): sys_mgr = sysinfo.sys_mgr() # get sys manager sys_mgr.poweroff(user=request.client_addr) return Response(status=200)
def flush_page_cache_post(request): sys_mgr = sysinfo.sys_mgr() # get sys manager sys_mgr.flush_page_cache() return Response(status=200)
def put_selinux_state(request): params = get_params_from_request(request, selinux_mod_schema) sys_mgr = sysinfo.sys_mgr() # get sys manager sys_mgr.set_selinux_state(params['state'], user=request.client_addr) return "System should be reboot when selinux state is changed"
def get_host_list(request): sys_mgr = sysinfo.sys_mgr() host_list = sys_mgr.get_host_list() return host_list
def get_selinux_state(request): sys_mgr = sysinfo.sys_mgr() # get sys manager return {"state": sys_mgr.get_selinux_state()}
def get_timestamp(request): sys_mgr = sysinfo.sys_mgr() # get sys manager timestamp = sys_mgr.get_timestamp() return {'timestamp': timestamp}
def put_system_localhost(request): sys_mgr = sysinfo.sys_mgr() # get sys manager params = get_params_from_request(request, local_host_schema) if "hostname" in params: sys_mgr.set_hostname(params["hostname"], user=request.client_addr) return Response(status=200)
def put_host_list(request): params = get_params_from_request(request, host_list_schema) sys_mgr = sysinfo.sys_mgr() sys_mgr.set_host_list(params, request.client_addr) return Response(status=200)