Last active
June 9, 2016 21:33
-
-
Save alunux/d6f55a15e4471ab51bb7da21009c6ca8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from json import loads | |
from xmlrpc.client import ServerProxy | |
from os import system | |
from sys import argv | |
def ping_server(server_addr): | |
print("Checking the server status...") | |
status = system("ping -c 1 -w 5 " + server_addr + " > /dev/null 2>&1") | |
if status == 0: | |
return ("Up", server_addr) | |
else: | |
return ("Down", server_addr) | |
def print_info_disk(info, data_disk): | |
for i in info: | |
print("%s\t\t\t: %.2f kB\t\t%.2f MB\t%.2f GB" \ | |
% (i, data_disk[i]['kB'], data_disk[i]['MB'], data_disk[i]['GB'])) | |
def main(server_addr): | |
server = ServerProxy("http://" + server_addr + ":13000/", allow_none=True) | |
(status_server, addr) = ping_server(server_addr) | |
print("%s status\t: %s" % (addr, status_server)) | |
if status_server == "Up": | |
try: | |
data_disk = loads(server.server_disk_usage()) | |
print_info_disk(["Total", "Used", "Free"], data_disk) | |
except ConnectionRefusedError: | |
print("Can't connect to lovorus-server.py on the server") | |
if __name__ == '__main__': | |
if len(argv) == 2: | |
main(argv[1]) | |
else: | |
print("Need an IP address") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment