func ToggleVmss()

in src/go/cmd/createvmss/main.go [354:411]


func ToggleVmss(ctx context.Context, azureClients *AzureClients) error {
	vmssName := "cwvmss"
	vmssExists, err := VmssExists(ctx, azureClients, vmssName)
	if err != nil {
		return err
	}
	if !vmssExists {

		localVMSubnetId, err := GetSubnetId(ctx, azureClients)
		if err != nil {
			fmt.Fprintf(os.Stderr, "ERROR: failed to initialize Azure Clients: %s", err)
			os.Exit(1)
		}
		renderClientsSubnet := SwapResourceName(localVMSubnetId, "render_clients1")

		cacheWarmerCloudInit := InitializeCloutInit(
			"10.0.1.11", // bootstrapAddress string,
			"/nfs1data", // exportPath string,
			"/bootstrap/bootstrap.cachewarmer-worker.sh", // bootstrapScriptPath string,
			"10.0.1.11", // jobMountAddress string,
			"/nfs1data", // jobExportPath string,
			"/",         //jobBasePath string
		)

		customData, err := cacheWarmerCloudInit.GetCacheWarmerCloudInit()
		if err != nil {
			fmt.Fprintf(os.Stderr, "BUG BUG: customData retrieval hits the following error: %v", err)
			os.Exit(1)
		}
		log.Info.Printf("customData: '%s'", customData)

		cacheWarmerVmss := createCacheWarmerVmssModel(
			vmssName,                            // vmssName string,
			azureClients.LocalMetadata.Location, // location string,
			"Standard_D2s_v3",                   // vmssSKU string,
			1,                                   // nodeCount int64,
			"azureuser",                         // userName string,
			"TestPassword$",                     // password string,
			"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC8fhkh3jpHUQsrUIezFB5k4Rq9giJM8G1Cr0u2IRMiqG++nat5hbOr3gODpTA0h11q9bzb6nJtK7NtDzIHx+w3YNIVpcTGLiUEsfUbY53IHg7Nl/p3/gkST3g0R6BSL7Hg45SfyvpH7kwY30MoVHG/6P3go4SKlYoHXlgaaNr3fMwUTIeE9ofvyS3fcr6xxlsoB6luKuEs50h0NGsE4QEnbfSY4Yd/C1ucc3mEw+QFXBIsENHfHfZYrLNHm2L8MXYVmAH8k//5sFs4Migln9GiUgEQUT6uOjowsZyXBbXwfT11og+syPkAq4eqjiC76r0w6faVihdBYVoc/UcyupgH azureuser@linuxvm", // sshKeyData string,
			"Canonical",         // publisher string,
			"UbuntuServer",      // offer string,
			"18.04-LTS",         // sku string,
			compute.Spot,        // priority compute.VirtualMachinePriorityTypes,
			compute.Delete,      // evictionPolicy compute.VirtualMachineEvictionPolicyTypes
			renderClientsSubnet, // subnetId string
			customData,
		)

		if _, err := CreateVmss(ctx, azureClients, cacheWarmerVmss); err != nil {
			return err
		}
	} else {
		if err := DeleteVmss(ctx, azureClients, vmssName); err != nil {
			return err
		}
	}
	return nil
}