Implement more automated provisioning of aliases and relays, and remove networks cleanly
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import main
|
||||
from yaml import dump
|
||||
from modules import alias
|
||||
|
||||
class AliasCommand:
|
||||
def __init__(self, *args):
|
||||
@@ -7,6 +8,49 @@ class AliasCommand:
|
||||
|
||||
def alias(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
||||
if authed:
|
||||
info(dump(main.alias))
|
||||
if length == 1:
|
||||
info(dump(main.alias))
|
||||
return
|
||||
elif length == 2:
|
||||
if spl[1] == "add":
|
||||
nextNum = max(main.alias.keys())+1
|
||||
main.alias[nextNum] = alias.generate_alias()
|
||||
success("Generated new alias: %i" % nextNum)
|
||||
main.saveConf("alias")
|
||||
return
|
||||
else:
|
||||
incUsage("alias")
|
||||
return
|
||||
elif length == 3:
|
||||
if spl[1] == "add":
|
||||
if not spl[2].isdigit():
|
||||
failure("Must be a number, not %s" % spl[2])
|
||||
return
|
||||
num = int(spl[2])
|
||||
for i in range(num):
|
||||
nextNum = max(main.alias.keys())+1
|
||||
main.alias[nextNum] = alias.generate_alias()
|
||||
success("Generated new alias: %i" % nextNum)
|
||||
main.saveConf("alias")
|
||||
return
|
||||
elif spl[1] == "del":
|
||||
if not spl[2].isdigit():
|
||||
failure("Must be a number, not %s" % spl[2])
|
||||
return
|
||||
num = int(spl[2])
|
||||
failed = False
|
||||
for i in main.network.keys():
|
||||
if num in main.network[i].aliases.keys():
|
||||
failure("Alias in use by %s" % i)
|
||||
failed = True
|
||||
if failed:
|
||||
return
|
||||
del main.alias[num]
|
||||
success("Removed alias: %i" % num)
|
||||
main.saveConf("alias")
|
||||
return
|
||||
else:
|
||||
incUsage("alias")
|
||||
return
|
||||
else:
|
||||
incUsage(None)
|
||||
|
||||
@@ -25,13 +25,23 @@ class AutoCommand:
|
||||
if not spl[1] in main.network.keys():
|
||||
failure("No such network: %s" % spl[1])
|
||||
return
|
||||
num, alias = main.network[spl[1]].add_relay()
|
||||
success("Successfully created relay %i on network %s with alias %s" % (num, spl[1], alias))
|
||||
for i in main.alias.keys():
|
||||
print("num", i)
|
||||
num, alias = main.network[spl[1]].add_relay(i)
|
||||
success("Successfully created relay %i on network %s with alias %s" % (num, spl[1], alias))
|
||||
rtrn = provision.provisionRelay(num, spl[1])
|
||||
success("Started provisioning network %s on relay %s for alias %s" % (spl[1], num, rtrn))
|
||||
main.saveConf("network")
|
||||
return
|
||||
elif length == 1:
|
||||
for i in main.network.keys():
|
||||
for x in main.alias.keys():
|
||||
num, alias = main.network[i].add_relay(x)
|
||||
success("Successfully created relay %i on network %s with alias %s" % (num, i, alias))
|
||||
rtrn = provision.provisionRelay(num, i)
|
||||
success("Started provisioning network %s on relay %s for alias %s" % (i, num, rtrn))
|
||||
main.saveConf("network")
|
||||
rtrn = provision.provisionRelay(num, spl[1])
|
||||
success("Started provisioning network %s on relay %s for alias %s" % (spl[1], num, rtrn))
|
||||
return
|
||||
|
||||
else:
|
||||
incUsage("auto")
|
||||
return
|
||||
|
||||
@@ -32,7 +32,7 @@ class DisableCommand:
|
||||
if name in main.FactoryPool.keys():
|
||||
main.FactoryPool[name].stopTrying()
|
||||
main.ReactorPool[name].disconnect()
|
||||
if spl[1] in main.IRCPool.keys():
|
||||
if name in main.IRCPool.keys():
|
||||
del main.IRCPool[name]
|
||||
del main.ReactorPool[name]
|
||||
del main.FactoryPool[name]
|
||||
|
||||
@@ -38,6 +38,7 @@ class NetworkCommand:
|
||||
elif length == 3:
|
||||
if spl[1] == "del":
|
||||
if spl[2] in main.network.keys():
|
||||
main.network[spl[2]].seppuku() # ;(
|
||||
del main.network[spl[2]]
|
||||
success("Successfully removed network: %s" % spl[2])
|
||||
main.saveConf("network")
|
||||
|
||||
Reference in New Issue
Block a user