[项目] server.scripts.os_sub.py(LOAMAW v1.0)

import subprocess

def script_os_distributor(os_distributor_server):
    distributor_out = subprocess.check_output('ansible -m shell -a \'lsb_release -a\' %s | grep \'Distributor ID:\' | awk -F\':\' \'{print $2}\''%os_distributor_server, shell=True)
    return distributor_out

def script_os_release(os_release_server):
    release_out = subprocess.check_output('ansible -m shell -a \'lsb_release -a\' %s | grep \'Release:\' | awk -F\':\' \'{print $2}\''%os_release_server, shell=True)
    return release_out

def script_os_kernel(os_kernel_server):
    kernel_out = subprocess.check_output('ansible -m shell -a \'uname -r\' %s | grep \-'%os_kernel_server, shell=True)
    return kernel_out

def script_os_uptime(os_uptime_server):
    uptime_out = subprocess.check_output('ansible -m shell -a \'uptime\' %s | grep \, | awk \'{print $3,$4}\' | awk -F\',\' \'{print $1}\''%os_uptime_server, shell=True)
    return uptime_out

[项目] server.scripts.nc_sub.py(LOAMAW v1.0)

import subprocess

def script_nc_name(space_nc_name):
    nc_name_out = subprocess.check_output('ansible -m shell -a \'ifconfig\' %s | ifconfig | egrep flags= | awk \'{print $1}\' | awk -F\':\' \'{print $1}\''%space_nc_name, shell=True)
    return nc_name_out

def script_nc_ip(space_nc_name):
    nc_ip_out = subprocess.check_output('ansible -m shell -a \'ifconfig\' %s | egrep \"[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\" | awk \'{print $2}\''%space_nc_name, shell=True)
    return nc_ip_out

[项目] server.scripts.mem_sub.py(LOAMAW v1.0)

import subprocess

def script_mem_size(sname):
    mem_size_out = subprocess.check_output('ansible -m shell -a \'free\' %s | grep -i mem | awk \'{print $2}\''%sname, shell=True)
    return(mem_size_out)

def script_mem_usage(sname):
    mem_usage_out = subprocess.check_output('ansible -m shell -a \'free\' %s | grep -i mem | awk \'{print $3}\''%sname, shell=True)
    return(mem_usage_out)

def script_mem_idleness(sname):
    mem_idleness_out = subprocess.check_output('ansible -m shell -a \'free\' %s | grep -i mem | awk \'{print $4}\''%sname, shell=True)
    return(mem_idleness_out)

[项目] server.scripts.cpu_sub.py(LOAMAW v1.0)

import subprocess

def script_cpu_core(cpu_server_name):
    cpu_core_out = subprocess.check_output('ansible -m shell -a \'cat /proc/cpuinfo | egrep "core id|physical id" | tr -d "\n" | sed s/physical/\\nphysical/g | grep -v ^$ | sort | uniq | wc -l\' %s | tail -1'%cpu_server_name, shell=True)
    return(cpu_core_out)

def script_cpu_qty(qty_server_name):
    cpu_qty_out = subprocess.check_output('ansible -m shell -a \'cat /proc/cpuinfo | grep "physical id" | sort | uniq | wc -l\' %s | tail -1'%qty_server_name, shell=True)
    return(cpu_qty_out)

def script_cpu_usage(cpu_usage_server_name):
    cpu_usage_out = subprocess.check_output('ansible -m shell -a \'top -bn 1\' %s | grep \'Cpu\' | awk -F\',\' \'{print $1 }\' | awk \'{print $2}\''%cpu_usage_server_name, shell=True)
    return(cpu_usage_out)

def script_cpu_idleness(cpu_idleness_server_name):
    cpu_idleness_out = subprocess.check_output('ansible -m shell -a \'top -bn 1\' %s | grep \'Cpu\' | awk -F\',\' \'{print $4 }\' | awk \'{print $1}\''%cpu_idleness_server_name, shell=True)
    return(cpu_idleness_out)