func initializeApplicationVariables()

in src/go/cmd/vmscaler/main.go [51:173]


func initializeApplicationVariables(ctx context.Context) (*vmscaler.VMScaler, error) {
	var vnetResourceGroup = flag.String("vnetResourceGroup", "", "the virtual network resource group")
	var vnetName = flag.String("vnetName", "", "the virtual network name")
	var subnetName = flag.String("subnetName", "", "the subnet name")

	var location = flag.String("location", "westus2", "the location of the VMSS instances")

	var resourceGroup = flag.String("resourceGroup", "", "the resource group name that contains the VMSS instances")
	var vmSku = flag.String("vmSku", vmscaler.DEFAULT_SKU, "the virtual machine SKU")
	var imageId = flag.String("imageId", "", "the custom image id to use for the VMSS")
	var username = flag.String("username", "", "the username to use for VMSS virtual machines")
	var password = flag.String("password", "", "the password to use for VMSS virtual machines")
	var vmsPerVMSS = flag.Int("vmsPerVMSS", vmscaler.DEFAULT_VMS_PER_VMSS, "the number of VMs per VMSS")
	var singlePlacementGroup = flag.Bool("singlePlacementGroup", vmscaler.DEFAULT_VMSS_SINGLEPLACEMENTGROUP, "configure VMSS to span multiple tenants")
	var overProvision = flag.Bool("overProvision", vmscaler.DEFAULT_VMSS_OVERPROVISION, "configure VMSS to use overprovisioning")
	var priority = flag.String("priority", string(compute.Low), "the priority of the VMSS nodes")

	var debug = flag.Bool("debug", false, "enable debug output")

	flag.Parse()

	if *debug {
		log.EnableDebugging()
	}

	if envVarsAvailable := verifyEnvVars(); !envVarsAvailable {
		usage()
		os.Exit(1)
	}

	if len(*vnetResourceGroup) == 0 {
		fmt.Fprintf(os.Stderr, "ERROR: vnetResourceGroup is not specified\n")
		usage()
		os.Exit(1)
	}

	if len(*vnetName) == 0 {
		fmt.Fprintf(os.Stderr, "ERROR: vnetName is not specified\n")
		usage()
		os.Exit(1)
	}

	if len(*subnetName) == 0 {
		fmt.Fprintf(os.Stderr, "ERROR: subnetName is not specified\n")
		usage()
		os.Exit(1)
	}

	if len(*resourceGroup) == 0 {
		fmt.Fprintf(os.Stderr, "ERROR: resourceGroup is not specified\n")
		usage()
		os.Exit(1)
	}

	if len(*imageId) == 0 {
		fmt.Fprintf(os.Stderr, "ERROR: imageId is not specified\n")
		usage()
		os.Exit(1)
	}

	if len(*username) == 0 {
		fmt.Fprintf(os.Stderr, "ERROR: username is not specified\n")
		usage()
		os.Exit(1)
	}

	if len(*password) == 0 {
		fmt.Fprintf(os.Stderr, "ERROR: password is not specified\n")
		usage()
		os.Exit(1)
	}

	if *vmsPerVMSS < vmscaler.MINIMUM_VMS_PER_VMSS || *vmsPerVMSS > vmscaler.MAXIMUM_VMS_PER_VMSS {
		fmt.Fprintf(os.Stderr, "ERROR: vmsPerVMSS must be in the range [%d, %d]\n", vmscaler.MINIMUM_VMS_PER_VMSS, vmscaler.MAXIMUM_VMS_PER_VMSS)
		usage()
		os.Exit(1)
	}

	authorizer, err := auth.NewAuthorizerFromEnvironment()
	if err != nil {
		fmt.Fprintf(os.Stderr, "ERROR: authorizer from environment failed: %s", err)
		os.Exit(1)
	}

	var computePriority compute.VirtualMachinePriorityTypes
	if strings.EqualFold(string(compute.Low), *priority) {
		computePriority = compute.Low
	} else {
		computePriority = compute.Regular
	}

	queueName := buildQueueName(vmscaler.DEFAULT_QUEUE_PREFIX, cli.GetEnv(azure.AZURE_SUBSCRIPTION_ID), *resourceGroup)
	azure.FatalValidateQueueName(queueName)

	return &vmscaler.VMScaler{
		Context:                 ctx,
		AzureTenantId:           cli.GetEnv(azure.AZURE_TENANT_ID),
		AzureClientId:           cli.GetEnv(azure.AZURE_CLIENT_ID),
		AzureClientSecret:       cli.GetEnv(azure.AZURE_CLIENT_SECRET),
		AzureSubscriptionId:     cli.GetEnv(azure.AZURE_SUBSCRIPTION_ID),
		StorageAccountName:      cli.GetEnv(azure.AZURE_STORAGE_ACCOUNT),
		StorageAccountKey:       cli.GetEnv(azure.AZURE_STORAGE_ACCOUNT_KEY),
		StorageAccountQueueName: queueName,
		Authorizer:              authorizer,

		VNETResourceGroup: *vnetResourceGroup,
		VNETName:          *vnetName,
		SubnetName:        *subnetName,

		// VMSS configuration values
		ResourceGroup:        *resourceGroup,
		Location:             *location,
		SKU:                  *vmSku,
		ImageID:              *imageId,
		Username:             *username,
		Password:             *password,
		VMsPerVMSS:           int64(*vmsPerVMSS),
		SinglePlacementGroup: *singlePlacementGroup,
		OverProvision:        *overProvision,
		Priority:             computePriority,
		EvictionPolicy:       compute.Delete,
	}, nil
}