X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/29e7c39df5bbe3eae5007b0e56eb93aace7728bd..HEAD:/lib/cloud/azure/azure.go diff --git a/lib/cloud/azure/azure.go b/lib/cloud/azure/azure.go index ba8a836dd0..71f2a23dc9 100644 --- a/lib/cloud/azure/azure.go +++ b/lib/cloud/azure/azure.go @@ -28,6 +28,7 @@ import ( "github.com/Azure/go-autorest/autorest/azure/auth" "github.com/Azure/go-autorest/autorest/to" "github.com/jmcvetta/randutil" + "github.com/prometheus/client_golang/prometheus" "github.com/sirupsen/logrus" "golang.org/x/crypto/ssh" ) @@ -238,7 +239,7 @@ type azureInstanceSet struct { logger logrus.FieldLogger } -func newAzureInstanceSet(config json.RawMessage, dispatcherID cloud.InstanceSetID, _ cloud.SharedResourceTags, logger logrus.FieldLogger) (prv cloud.InstanceSet, err error) { +func newAzureInstanceSet(config json.RawMessage, dispatcherID cloud.InstanceSetID, _ cloud.SharedResourceTags, logger logrus.FieldLogger, reg *prometheus.Registry) (prv cloud.InstanceSet, err error) { azcfg := azureInstanceSetConfig{} err = json.Unmarshal(config, &azcfg) if err != nil { @@ -419,7 +420,7 @@ func (az *azureInstanceSet) Create( Tags: tags, InterfacePropertiesFormat: &network.InterfacePropertiesFormat{ IPConfigurations: &[]network.InterfaceIPConfiguration{ - network.InterfaceIPConfiguration{ + { Name: to.StringPtr("ip1"), InterfaceIPConfigurationPropertiesFormat: &network.InterfaceIPConfigurationPropertiesFormat{ Subnet: &network.Subnet{ @@ -501,7 +502,7 @@ func (az *azureInstanceSet) Create( StorageProfile: storageProfile, NetworkProfile: &compute.NetworkProfile{ NetworkInterfaces: &[]compute.NetworkInterfaceReference{ - compute.NetworkInterfaceReference{ + { ID: nic.ID, NetworkInterfaceReferenceProperties: &compute.NetworkInterfaceReferenceProperties{ Primary: to.BoolPtr(true), @@ -514,20 +515,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 @@ -774,6 +789,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 }