60 lines
2.6 KiB
Python
60 lines
2.6 KiB
Python
import main
|
|
from modules import provision
|
|
|
|
class Provision:
|
|
def __init__(self, register):
|
|
register("provision", self.provision)
|
|
|
|
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
|
|
|
|
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
|
|
|
|
rtrn = provision.provisionRelayForNetwork(spl[1], spl[2], spl[3])
|
|
if rtrn == "PROVISIONED":
|
|
failure("Relay %s already provisioned for network %s" % (spl[1], 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]))
|
|
elif rtrn:
|
|
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])
|
|
if rtrn == "PROVISIONED":
|
|
failure("Relay %s already provisioned for alias %s" % (spl[1], spl[2]))
|
|
return
|
|
elif rtrn:
|
|
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)
|