def main()

in src/terraform/modules/hammerspace/anvil-run-once-configure/configure-anvil.py [0:0]


def main():
    logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.DEBUG)

    # parse the options
    usage = "usage: %prog [options] ANVIL_ADDRESS ANVIL_PASSWORD DSX_COUNT"
    parser = optparse.OptionParser(usage)
    parser.add_option("-s", "--share-name", dest="sharename", help="print the sharename", default="")
    parser.add_option("-a", "--ad-name", dest="activeDirectoryName", help="the active directory to join", default="")
    parser.add_option("-u", "--ad-user", dest="activeDirectoryUser", help="the active directory user", default="")
    parser.add_option("-p", "--ad-password", dest="activeDirectoryPassword", help="the active directory password", default="")
    parser.add_option("-n", "--name", dest="name", help="the visible name of the site", default="")
    parser.add_option("--azure-account", dest="azureAccount", help="the azure storage account name", default="")
    parser.add_option("--azure-account-key", dest="azureAccountKey", help="the azure storage account key", default="")
    parser.add_option("--azure-account-container", dest="azureAccountContainer", help="the azure storage account container", default="")
    (options, args) = parser.parse_args()

    if len(args) < 3:
        parser.error("incorrect number of arguments")
        sys.exit(1)

    anvilAddress = args[0]
    anvilPassword = args[1]
    dsxCount = int(args[2])

    sharePath = options.sharename
    adName = options.activeDirectoryName
    adUser = options.activeDirectoryUser
    adPassword = options.activeDirectoryPassword
    siteName = options.name
    azureAccount = options.azureAccount
    azureAccountKey = options.azureAccountKey
    azureAccountContainer = options.azureAccountContainer
    
    # configure the rest API
    anvilRest = AnvilRest(anvilAddress, anvilPassword)

    # wait for the port
    waitForRestPort(anvilRest)
    
    # wait for the storage to be added
    success = waitForDSXStorage(anvilRest, dsxCount)
    if not success:
        logging.error("ERROR: timed out waiting for DSX Storage")
        sys.exit(2)

    # wait for the volumes to be added
    success = waitForDSXVolumes(anvilRest, dsxCount)
    if not success:
        logging.error("ERROR: timed out waiting for DSX volumes")
        sys.exit(3)

    # create a share
    if sharePath != "":
        addStorageShare(anvilRest, sharePath)

    # domain join
    if adName != "" and adUser != "" and adPassword != "":
        joinDomain(anvilRest, adName, adUser, adPassword)

    if siteName != "":
        updateSiteDisplayName(anvilRest, siteName)

    if azureAccount != "" and azureAccountKey != "":
        addAzureStorage(anvilRest, azureAccount, azureAccountKey, azureAccountContainer)

    # configure default objectives
    addDefaultObjectives(anvilRest)

    logging.info("complete")