2019-01-26 01:57:24 +00:00
|
|
|
import main
|
|
|
|
from modules import provision
|
|
|
|
|
2019-08-09 22:06:34 +00:00
|
|
|
class ProvisionCommand:
|
2019-01-26 18:58:21 +00:00
|
|
|
def __init__(self, *args):
|
|
|
|
self.provision(*args)
|
2019-01-26 01:57:24 +00:00
|
|
|
|
|
|
|
def provision(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
|
|
|
|
if authed:
|
|
|
|
if length == 4 or length == 3:
|
|
|
|
if not spl[1] in main.relay.keys():
|
|
|
|
failure("No such relay: %s" % spl[1])
|
|
|
|
return
|
|
|
|
if not spl[2] in main.alias.keys():
|
|
|
|
failure("No such alias: %s" % spl[2])
|
|
|
|
return
|
|
|
|
if length == 4: # provision for relay, alias and network
|
|
|
|
if not spl[3] in main.network.keys():
|
|
|
|
failure("No such network: %s" % spl[3])
|
|
|
|
return
|
|
|
|
|
2019-08-12 20:03:47 +00:00
|
|
|
#if "users" in main.relay[spl[1]]:
|
|
|
|
# if not spl[2] in main.relay[spl[1]]["users"]:
|
|
|
|
# failure("Relay %s not provisioned for alias %s" % (spl[1], spl[2]))
|
|
|
|
# return
|
|
|
|
#else:
|
|
|
|
# failure("Relay %s not provisioned for alias %s" % (spl[1], spl[2]))
|
|
|
|
# return
|
2019-01-26 01:57:24 +00:00
|
|
|
|
|
|
|
rtrn = provision.provisionRelayForNetwork(spl[1], spl[2], spl[3])
|
2019-08-12 20:03:47 +00:00
|
|
|
#if rtrn == "PROVISIONED":
|
|
|
|
# failure("Relay %s already provisioned for alias %s on network %s" % (spl[1], spl[2], spl[3]))
|
|
|
|
# return
|
|
|
|
#elif rtrn == "DUPLICATE":
|
|
|
|
# failure("Instance with relay %s and alias %s already exists for network %s" % (spl[1], spl[2], spl[3]))
|
|
|
|
# return
|
|
|
|
if rtrn:
|
2019-01-26 01:57:24 +00:00
|
|
|
success("Started provisioning network %s on relay %s for alias %s" % (spl[3], spl[1], spl[2]))
|
|
|
|
info("Instance name is %s" % rtrn)
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
failure("Failure while provisioning relay %s" % spl[1])
|
|
|
|
return
|
|
|
|
if length == 3: # provision for relay and alias only
|
|
|
|
rtrn = provision.provisionRelayForAlias(spl[1], spl[2])
|
2019-08-12 20:03:47 +00:00
|
|
|
#if rtrn == "PROVISIONED":
|
|
|
|
# failure("Relay %s already provisioned for alias %s" % (spl[1], spl[2]))
|
|
|
|
# return
|
|
|
|
if rtrn:
|
2019-01-26 01:57:24 +00:00
|
|
|
success("Started provisioning relay %s for alias %s" % (spl[1], spl[2]))
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
failure("Failure while provisioning relay %s" % spl[1])
|
|
|
|
return
|
|
|
|
|
|
|
|
else:
|
|
|
|
incUsage("provision")
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
incUsage(None)
|