Added first setting command
This commit is contained in:
parent
eee83add5d
commit
9591616b66
5
PKGBUILD
5
PKGBUILD
@ -2,10 +2,11 @@ pkgname=saturn-discover
|
||||
pkgver=1.0
|
||||
pkgrel=1
|
||||
arch=('any')
|
||||
source=('saturnDiscoverDeamon.py' 'saturnDiscover.service')
|
||||
md5sums=('SKIP' 'SKIP')
|
||||
source=('saturnDiscoverDeamon.py' 'saturnDiscover.service' 'saturnDiscover')
|
||||
md5sums=('SKIP' 'SKIP' 'SKIP')
|
||||
|
||||
package() {
|
||||
install -D -t "${pkgdir}/usr/bin" "$srcdir/saturnDiscover"
|
||||
install -D -t "${pkgdir}/usr/bin" "$srcdir/saturnDiscoverDeamon.py"
|
||||
install -m755 -d ${pkgdir}/usr/lib/systemd/system
|
||||
install -m644 $startdir/saturnDiscover.service ${pkgdir}/usr/lib/systemd/system
|
||||
|
145
saturnDiscover
Executable file
145
saturnDiscover
Executable file
@ -0,0 +1,145 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import os
|
||||
import sys
|
||||
import json
|
||||
|
||||
def tryReadFile(fname, defval):
|
||||
with open(fname, 'r') as file:
|
||||
return file.read().replace('\n', '')
|
||||
|
||||
return defval
|
||||
|
||||
def restartService():
|
||||
os.system("systemctl restart saturnDiscover")
|
||||
|
||||
def loadHosts():
|
||||
HOSTS = {}
|
||||
|
||||
try:
|
||||
with open('/etc/slurm-llnl/hosts.json', 'r') as file:
|
||||
HOSTS = json.load(file)
|
||||
except:
|
||||
HOSTS = {}
|
||||
|
||||
return HOSTS
|
||||
|
||||
def updateFile(filename, value):
|
||||
with open(filename, "w") as outfile:
|
||||
outfile.write(value)
|
||||
|
||||
def help():
|
||||
print("Saturn discover setting tool")
|
||||
print()
|
||||
print("Using: saturnDiscover <command> [ops]")
|
||||
print("supported commands:")
|
||||
print(" add Add value (to list)")
|
||||
print(" set Set value")
|
||||
print(" list List values (from list)")
|
||||
print(" get Get value")
|
||||
print(" reload Reload cluster config")
|
||||
print("")
|
||||
print("Every command have sub help, when you write help in ops")
|
||||
|
||||
def helpAdd():
|
||||
print("Saturn discover setting tool")
|
||||
print("command ADD - add value to list")
|
||||
print()
|
||||
print("Using: saturnDiscover add <target> <value>")
|
||||
print("supported tragets:")
|
||||
print(" res Node resources list")
|
||||
|
||||
def helpSet():
|
||||
print("Saturn discover setting tool")
|
||||
print("command SET - set value")
|
||||
print()
|
||||
print("Using: saturnDiscover set <target> <value>")
|
||||
print("supported tragets:")
|
||||
print(" mac Node mac address")
|
||||
|
||||
def helpList():
|
||||
print("Saturn discover setting tool")
|
||||
print("command LIST - print values in list")
|
||||
print()
|
||||
print("Using: saturnDiscover list <target>")
|
||||
print("supported tragets:")
|
||||
print(" res Node resources list")
|
||||
print(" nodes Discovered nodes list")
|
||||
|
||||
def helpGet():
|
||||
print("Saturn discover setting tool")
|
||||
print("command GET - get value")
|
||||
print()
|
||||
print("Using: saturnDiscover get <target>")
|
||||
print("supported tragets:")
|
||||
print(" mac Node mac address")
|
||||
|
||||
def helpReload():
|
||||
print("Saturn discover setting tool")
|
||||
print("command RELOAD - reload cluster configuration on all nodes")
|
||||
print()
|
||||
print("Using: saturnDiscover reload")
|
||||
|
||||
argc = len(sys.argv)
|
||||
|
||||
if (argc <= 1):
|
||||
help()
|
||||
exit(0)
|
||||
|
||||
## prase command
|
||||
if (sys.argv[1] == "add"):
|
||||
if (argc != 4):
|
||||
helpAdd()
|
||||
exit(1)
|
||||
|
||||
if (sys.argv[2] == "res"):
|
||||
res = json.loads(tryReadFile("/etc/slurm-llnl/localRes", "[]"))
|
||||
res.append(sys.argv[3])
|
||||
updateFile("/etc/slurm-llnl/localRes", json.dumps(res))
|
||||
|
||||
restartService()
|
||||
|
||||
elif (sys.argv[1] == "set"):
|
||||
if (argc != 4):
|
||||
helpSet()
|
||||
exit(1)
|
||||
|
||||
if (sys.argv[2] == "mac"):
|
||||
updateFile("/etc/slurm-llnl/localMac", sys.argv[3])
|
||||
|
||||
restartService()
|
||||
|
||||
elif (sys.argv[1] == "list"):
|
||||
if (argc != 3):
|
||||
helpList()
|
||||
exit(1)
|
||||
|
||||
if (sys.argv[2] == "res"):
|
||||
res = json.loads(tryReadFile("/etc/slurm-llnl/localRes", "[]"))
|
||||
print(res)
|
||||
|
||||
if (sys.argv[2] == "nodes"):
|
||||
nodes = loadHosts()
|
||||
print(nodes)
|
||||
|
||||
elif (sys.argv[1] == "get"):
|
||||
if (argc != 3):
|
||||
helpGet()
|
||||
exit(1)
|
||||
|
||||
if (sys.argv[2] == "mac"):
|
||||
print(tryReadFile("/etc/slurm-llnl/localMac", "00:00:00:00:00:00"))
|
||||
|
||||
elif (sys.argv[1] == "reaload"):
|
||||
if (argc != 2):
|
||||
helpReload()
|
||||
exit(1)
|
||||
|
||||
ver = int(tryReadFile("/etc/slurm-llnl/confVer", 0))
|
||||
updateFile("/etc/slurm-llnl/confVer", str(ver + 1))
|
||||
|
||||
restartService()
|
||||
|
||||
else:
|
||||
help()
|
||||
exit(1)
|
@ -58,6 +58,7 @@ def selfInfo():
|
||||
"cpus": os.cpu_count(),
|
||||
"rams": os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES'),
|
||||
"res": json.loads(tryReadFile("/etc/slurm-llnl/localRes", "[]")),
|
||||
"mac": tryReadFile("/etc/slurm-llnl/localMac", "00:00:00:00:00:00"),
|
||||
"version": int(tryReadFile("/etc/slurm-llnl/confVer", 0))
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user