2019-08-25 20:29:11 +00:00
|
|
|
import main
|
|
|
|
from modules import provision
|
|
|
|
|
2022-07-21 12:39:41 +00:00
|
|
|
|
2019-08-25 20:29:11 +00:00
|
|
|
class AutoCommand:
|
|
|
|
def __init__(self, *args):
|
|
|
|
self.auto(*args)
|
|
|
|
|
2022-09-05 06:20:30 +00:00
|
|
|
def auto(
|
|
|
|
self, addr, authed, data, obj, spl, success, failure, info, incUsage, length
|
|
|
|
):
|
2019-08-25 20:29:11 +00:00
|
|
|
if authed:
|
2019-10-13 11:37:01 +00:00
|
|
|
if length == 1:
|
|
|
|
for i in main.network.keys():
|
|
|
|
if 1 in main.network[i].relays.keys():
|
|
|
|
info("Skipping %s - first relay exists" % i)
|
|
|
|
else:
|
|
|
|
num, alias = main.network[i].add_relay(1)
|
2022-09-05 06:20:30 +00:00
|
|
|
success(
|
|
|
|
"Successfully created first relay on network %s with alias %s"
|
|
|
|
% (i, alias)
|
|
|
|
)
|
2019-10-13 11:37:01 +00:00
|
|
|
provision.provisionRelay(num, i)
|
2022-09-05 06:20:30 +00:00
|
|
|
success(
|
|
|
|
"Started provisioning network %s on first relay for alias %s"
|
|
|
|
% (i, alias)
|
|
|
|
)
|
2019-08-25 20:29:11 +00:00
|
|
|
main.saveConf("network")
|
|
|
|
return
|
2019-09-29 13:57:36 +00:00
|
|
|
elif length == 2:
|
|
|
|
if not spl[1] in main.network.keys():
|
|
|
|
failure("No such network: %s" % spl[1])
|
|
|
|
return
|
2019-10-13 11:37:01 +00:00
|
|
|
if 1 in main.network[spl[1]].relays.keys():
|
|
|
|
failure("First relay exists on %s" % spl[1])
|
|
|
|
return
|
|
|
|
num, alias = main.network[spl[1]].add_relay(1)
|
2022-09-05 06:20:30 +00:00
|
|
|
success(
|
|
|
|
"Successfully created relay %i on network %s with alias %s"
|
|
|
|
% (num, spl[1], alias)
|
|
|
|
)
|
2019-10-13 11:37:01 +00:00
|
|
|
provision.provisionRelay(num, spl[1])
|
2022-09-05 06:20:30 +00:00
|
|
|
success(
|
|
|
|
"Started provisioning network %s on relay %s for alias %s"
|
|
|
|
% (spl[1], num, alias)
|
|
|
|
)
|
2019-09-29 13:57:36 +00:00
|
|
|
main.saveConf("network")
|
|
|
|
return
|
2019-08-25 20:29:11 +00:00
|
|
|
else:
|
|
|
|
incUsage("auto")
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
incUsage(None)
|