-
Notifications
You must be signed in to change notification settings - Fork 0
/
selfnetctl
79 lines (60 loc) · 2.61 KB
/
selfnetctl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/python3
# -*- coding: utf-8; tab-width: 4; indent-tabs-mode: t -*-
import sys
import argparse
sys.path.append('/usr/lib/selfnetd')
from sn_param import SnParam
from sn_subcmd import SnSubCmdMain
def parseArgs():
argParser = argparse.ArgumentParser()
subParsers = argParser.add_subparsers()
apGenCaCert = subParsers.add_parser("generate-ca-cert")
apGenCaCert.set_defaults(subcmd="gen_ca_cert")
apGenMyCert = subParsers.add_parser("generate-my-cert")
apGenMyCert.set_defaults(subcmd="gen_my_cert")
apGenCert = subParsers.add_parser("generate-cert")
apGenCert.set_defaults(subcmd="gen_cert")
apGenCert.add_argument("--hostname", required=True)
apGenCert.add_argument("--outdir")
apListPeer = subParsers.add_parser("list-peers")
apListPeer.set_defaults(subcmd="list_peers")
apOpPowerOn = subParsers.add_parser("poweron")
apOpPowerOn.set_defaults(subcmd="poweron")
apOpPowerOn.add_argument("peerName")
apOpPowerOff = subParsers.add_parser("poweroff")
apOpPowerOff.set_defaults(subcmd="poweroff")
apOpPowerOff.add_argument("peerName")
apOpReboot = subParsers.add_parser("reboot")
apOpReboot.set_defaults(subcmd="reboot")
apOpReboot.add_argument("peerName")
apOpSuspend = subParsers.add_parser("suspend")
apOpSuspend.set_defaults(subcmd="suspend")
apOpSuspend.add_argument("peerName")
apOpHibernate = subParsers.add_parser("hibernate")
apOpHibernate.set_defaults(subcmd="hibernate")
apOpHibernate.add_argument("peerName")
apOpHybridSleep = subParsers.add_parser("hybrid-sleep")
apOpHybridSleep.set_defaults(subcmd="hybrid-sleep")
apOpHybridSleep.add_argument("peerName")
apListModule = subParsers.add_parser("list-modules")
apListModule.set_defaults(subcmd="list_modules")
return argParser.parse_args()
################################################################################
param = SnParam()
parseResult = parseArgs()
# some assistant sub command
if parseResult.subcmd == "gen_ca_cert":
SnSubCmdMain(param).generateCaCert()
elif parseResult.subcmd == "gen_my_cert":
SnSubCmdMain(param).generateMyCert()
elif parseResult.subcmd == "gen_cert":
SnSubCmdMain(param).generateCert(parseResult.hostname, parseResult.outdir)
elif parseResult.subcmd == "list_peers":
SnSubCmdMain(param).listPeers()
elif parseResult.subcmd in ["poweron", "poweroff", "reboot", "suspend", "hibernate", "hybrid-sleep"]:
SnSubCmdMain(param).peerPowerOperation(parseResult.peerName, parseResult.subcmd)
elif parseResult.subcmd == "list_modules":
SnSubCmdMain(param).listModules()
else:
assert False
sys.exit(0)