def main()

in playbooks/roles/cyclecloud/files/configure.py [0:0]


def main():

    parser = argparse.ArgumentParser(description="usage: %prog [options]")

    parser.add_argument("--tenantId",
                        dest="tenantId",
                        help="Tenant ID of the Azure subscription")

    parser.add_argument("--applicationId",
                        dest="applicationId",
                        help="Application ID of the Service Principal")

    parser.add_argument("--applicationSecret",
                        dest="applicationSecret",
                        help="Application Secret of the Service Principal")

    parser.add_argument("--username",
                        dest="username",
                        help="The local admin user for the CycleCloud VM")

    parser.add_argument("--hostname",
                        dest="hostname",
                        help="The short public hostname assigned to this VM (or public IP), used for LetsEncrypt")

    parser.add_argument("--acceptTerms",
                        dest="acceptTerms",
                        action="store_true",
                        help="Accept Cyclecloud terms and do a silent install")

    parser.add_argument("--useLetsEncrypt",
                        dest="useLetsEncrypt",
                        action="store_true",
                        help="Automatically fetch certificate from Let's Encrypt. "
                             "(Only suitable for installations with public IP.)")

    parser.add_argument("--useManagedIdentity",
                        dest="useManagedIdentity",
                        action="store_true",
                        help="Use the first assigned Managed Identity rather than a Service Principal "
                             "for the default account")

    parser.add_argument("--password",
                        dest="password",
                        help="The password for the CycleCloud UI user")

    parser.add_argument("--publickey",
                        dest="publickey",
                        help="The public ssh key for the CycleCloud UI user")

    parser.add_argument("--storageAccount",
                        dest="storageAccount",
                        help="The storage account to use as a CycleCloud locker")

    parser.add_argument("--resourceGroup",
                        dest="resourceGroup",
                        help="The resource group for CycleCloud cluster resources. "
                             "Resource Group must already exist. (Default: same RG as CycleCloud)")

    args = parser.parse_args()

    print("Debugging arguments: %s" % args)

    vm_metadata = get_vm_metadata()

    if args.resourceGroup:
        print("CycleCloud created in resource group: %s" % vm_metadata["compute"]["resourceGroupName"])
        print("Cluster resources will be created in resource group: %s" %  args.resourceGroup)
        vm_metadata["compute"]["resourceGroupName"] = args.resourceGroup

    # Retry await_startup in case it takes much longer than expected 
    # (this is common in local testing with limited compute resources)
    max_tries = 5
    started = False
    while not started:
        try:
            max_tries -= 1
            _catch_sys_error([cs_cmd, "await_startup"])
            started = True
        except:
            if max_tries >  0:
                # Wait 30s seconds before retrying
                _catch_sys_error([sleep, "30"])
                print("Retrying...")
            else:
                print("CycleServer is not started")
                raise 

    azEnvironment = vm_metadata["compute"]["azEnvironment"]
    azEnvironment = azEnvironment.lower()
    print("azEnvironment=%s" % azEnvironment)

    if azEnvironment == 'azurepubliccloud':
        azureSovereignCloud = 'public'
    elif azEnvironment == 'azureusgovernmentcloud':
        azureSovereignCloud = 'usgov'
    elif azEnvironment == 'azurechinacloud':
        azureSovereignCloud = 'china'
    elif azEnvironment == 'azuregermancloud':
        azureSovereignCloud = 'germany'
    else:
        azureSovereignCloud = 'public'

    cyclecloud_account_setup(vm_metadata, args.useManagedIdentity, args.tenantId, args.applicationId,
                             args.applicationSecret, args.username, azureSovereignCloud,
                             args.acceptTerms, args.password, args.storageAccount)

    #  Create user requires root privileges
    create_user_credential(args.username, args.publickey)

    clean_up()