monolith/commands/provision.py

61 lines
2.6 KiB
Python
Raw Normal View History

import main
from modules import provision
class ProvisionCommand:
def __init__(self, *args):
self.provision(*args)
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 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:
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
if 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)