Merge branch '20541-less-fetching-mounts'
[arvados.git] / lib / cloud / azure / azure.go
index ad1f8c532d6a1a8a1630c1c83d35a67aaa8a6d0d..494db854ed3c857fbf47f714f46b5c605120e30e 100644 (file)
@@ -491,21 +491,6 @@ func (az *azureInstanceSet) Create(
                }
        }
 
-       priority := compute.Regular
-       evictionPolicy := compute.Deallocate
-       var billingProfile compute.BillingProfile
-       var maxPrice float64
-       if instanceType.Preemptible {
-               priority = compute.Spot
-               evictionPolicy = compute.Delete
-               // Setting maxPrice to -1 is the equivalent of paying spot price, up to the
-               // normal price. This means the node will not be pre-empted for price
-               // reasons. It may still be pre-empted for capacity reasons though. And
-               // Azure offers *no* SLA on spot instances.
-               maxPrice = -1
-               billingProfile = compute.BillingProfile{MaxPrice: &maxPrice}
-       }
-
        vmParameters := compute.VirtualMachine{
                Location: &az.azconfig.Location,
                Tags:     tags,
@@ -514,9 +499,6 @@ func (az *azureInstanceSet) Create(
                                VMSize: compute.VirtualMachineSizeTypes(instanceType.ProviderType),
                        },
                        StorageProfile: storageProfile,
-                       Priority:       priority,
-                       EvictionPolicy: evictionPolicy,
-                       BillingProfile: &billingProfile,
                        NetworkProfile: &compute.NetworkProfile{
                                NetworkInterfaces: &[]compute.NetworkInterfaceReference{
                                        {
@@ -532,20 +514,34 @@ func (az *azureInstanceSet) Create(
                                AdminUsername: to.StringPtr(az.azconfig.AdminUsername),
                                LinuxConfiguration: &compute.LinuxConfiguration{
                                        DisablePasswordAuthentication: to.BoolPtr(true),
-                                       SSH: &compute.SSHConfiguration{
-                                               PublicKeys: &[]compute.SSHPublicKey{
-                                                       {
-                                                               Path:    to.StringPtr("/home/" + az.azconfig.AdminUsername + "/.ssh/authorized_keys"),
-                                                               KeyData: to.StringPtr(string(ssh.MarshalAuthorizedKey(publicKey))),
-                                                       },
-                                               },
-                                       },
                                },
                                CustomData: &customData,
                        },
                },
        }
 
+       if publicKey != nil {
+               vmParameters.VirtualMachineProperties.OsProfile.LinuxConfiguration.SSH = &compute.SSHConfiguration{
+                       PublicKeys: &[]compute.SSHPublicKey{
+                               {
+                                       Path:    to.StringPtr("/home/" + az.azconfig.AdminUsername + "/.ssh/authorized_keys"),
+                                       KeyData: to.StringPtr(string(ssh.MarshalAuthorizedKey(publicKey))),
+                               },
+                       },
+               }
+       }
+
+       if instanceType.Preemptible {
+               // Setting maxPrice to -1 is the equivalent of paying spot price, up to the
+               // normal price. This means the node will not be pre-empted for price
+               // reasons. It may still be pre-empted for capacity reasons though. And
+               // Azure offers *no* SLA on spot instances.
+               var maxPrice float64 = -1
+               vmParameters.VirtualMachineProperties.Priority = compute.Spot
+               vmParameters.VirtualMachineProperties.EvictionPolicy = compute.Delete
+               vmParameters.VirtualMachineProperties.BillingProfile = &compute.BillingProfile{MaxPrice: &maxPrice}
+       }
+
        vm, err := az.vmClient.createOrUpdate(az.ctx, az.azconfig.ResourceGroup, name, vmParameters)
        if err != nil {
                // Do some cleanup. Otherwise, an unbounded number of new unused nics and
@@ -792,6 +788,10 @@ func (ai *azureInstance) Address() string {
        }
 }
 
+func (ai *azureInstance) PriceHistory(arvados.InstanceType) []cloud.InstancePrice {
+       return nil
+}
+
 func (ai *azureInstance) RemoteUser() string {
        return ai.provider.azconfig.AdminUsername
 }