예제 #1
0
def list_vps():
         data = []
         vps_dir = item.get_setting('vserver_dir')
         pref = item.get_setting('vserver_prefix')
         conf_dir = pref+'/etc/vservers/'
         
         vps = os.listdir(vps_dir)
         vps.remove('.pkg')
         
         for a in vps:
	   
	     life = os.popen("sudo "+pref+"/sbin/vserver-stat | grep "+a+"").read()
	     if life != '':
		button = "<input class=\"btnred\" type=\"button\" id=\"\" value=\"Matikan\">"
		f = open(""+conf_dir+""+a+"/context")
		fd = f.read()
		f.close()
	     
		m = open(""+conf_dir+""+a+"/rlimits/rss.hard")
		mu = os.popen("sudo "+pref+"/sbin/vserver-stat | grep "+a+" | awk '{ print $4 }'|cut -d'.' -f1").read()
		mr = m.read()
		ma = (int(mr)/250)-(int(mu))
		mn = int(mr)/250
		m.close()
	       
	     else :
		button = "<input class=\"btn\" type=\"button\" id=\"\" value=\"Hidupkan\">"
		m = open(""+conf_dir+""+a+"/rlimits/rss.hard")
		mr = m.read()
		mn = int(mr)/250
		ma = 0
		f = open(""+conf_dir+""+a+"/context")
		fd = f.read()
		f.close()
	    
	     
	     ip = open(""+conf_dir+""+a+"/interfaces/0/ip")
	     ipn = ip.read()
	     ip.close()
	     
	     
	     
	     
	     data += [{'nama_vps' : a.title(),'id' : fd ,'memori' : str(mn) , 'freemem': str(ma) ,'ip' : ipn, 'button' : button },]
         return data
예제 #2
0
def info_vserver():
    data = {}
    vprefix = item.get_setting("vserver_prefix").strip()
    vd = item.get_setting("vserver_dir").strip()
    conf = os.popen(
        "" + vprefix + "/sbin/vserver-info . SYSINFO | grep -m 1 cfg | cut -d':' -f2 | cut -d '}' -f 2"
    ).read()

    vdevice = os.popen("stat " + vd + " | grep Device | awk '{ print $2}' | cut -d'/' -f1").read()
    mj = vdevice[0:2]
    mn = vdevice[2]
    rd = ""
    if mj == "80":
        rd = "/dev/sda"
    elif mj == "30":
        rd = "/dev/hda"

    vf = os.popen("df | grep " + rd + mn + " | awk '{ print $4}'").read()
    vt = os.popen("df | grep " + rd + mn + " | awk '{ print $2}'").read()

    byte = 1000000
    suf = ""
    suft = ""

    if int(vt) / byte == 0:
        suft = " Megabyte"
        hasilt = int(vt) / 1000
    elif int(vt) / byte > 0:
        suft = " Gigabyte"
        hasilt = int(vt) / byte

    if int(vf) / byte == 0:
        suf = "Megabyte"
        hasil = int(vf) / 1000
    elif int(vf) / byte > 0:
        suf = " Gigabyte"
        hasil = int(vf) / byte

    persenmount = hasil * 100 / hasilt
    if persenmount <= 30:
        mountbar = "highbar"
        pesan = (
            "<br><br>Liat deh bar nya , udah rada merah kan. Tolong demi kenyamanan sistem , rada di bersihkan dulu ini harddisk "
            + rd
            + mn
            + " nya !!"
        )
        style = "red"
    elif persenmount > 30 and persenmount <= 70:
        mountbar = "midbar"
        pesan = "<br><br> Masih agak lega sih ruangan peyimpanan nya. Harus hati-hati, jangan sampe kepenuhan ya !"
        style = "blue"
    elif persenmount > 70:
        mountbar = "lowbar"
        pesan = "<br><br>Asik, Lega banget nih Harddisk, rada nyantai ahh "
        style = "green"

    data = {
        "rootdir": vd,
        "prefix": vprefix,
        "confdir": vprefix + conf,
        "mount": rd + mn,
        "totalmount": str(hasilt) + suft,
        "persenmount": str(persenmount),
        "mountbar": mountbar,
        "mountsize": str(hasil) + " " + suf + pesan,
        "style": style,
    }
    return data