1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
20 "git.arvados.org/arvados.git/lib/cloud"
21 "git.arvados.org/arvados.git/sdk/go/arvados"
22 "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute"
23 "github.com/Azure/azure-sdk-for-go/services/network/mgmt/2018-06-01/network"
24 storageacct "github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2018-02-01/storage"
25 "github.com/Azure/azure-sdk-for-go/storage"
26 "github.com/Azure/go-autorest/autorest"
27 "github.com/Azure/go-autorest/autorest/azure"
28 "github.com/Azure/go-autorest/autorest/azure/auth"
29 "github.com/Azure/go-autorest/autorest/to"
30 "github.com/jmcvetta/randutil"
31 "github.com/sirupsen/logrus"
32 "golang.org/x/crypto/ssh"
35 // Driver is the azure implementation of the cloud.Driver interface.
36 var Driver = cloud.DriverFunc(newAzureInstanceSet)
38 type azureInstanceSetConfig struct {
43 CloudEnvironment string
45 ImageResourceGroup string
48 NetworkResourceGroup string
52 SharedImageGalleryName string
53 SharedImageGalleryImageVersion string
54 DeleteDanglingResourcesAfter arvados.Duration
58 type containerWrapper interface {
59 GetBlobReference(name string) *storage.Blob
60 ListBlobs(params storage.ListBlobsParameters) (storage.BlobListResponse, error)
63 type virtualMachinesClientWrapper interface {
64 createOrUpdate(ctx context.Context,
65 resourceGroupName string,
67 parameters compute.VirtualMachine) (result compute.VirtualMachine, err error)
68 delete(ctx context.Context, resourceGroupName string, VMName string) (result *http.Response, err error)
69 listComplete(ctx context.Context, resourceGroupName string) (result compute.VirtualMachineListResultIterator, err error)
72 type virtualMachinesClientImpl struct {
73 inner compute.VirtualMachinesClient
76 func (cl *virtualMachinesClientImpl) createOrUpdate(ctx context.Context,
77 resourceGroupName string,
79 parameters compute.VirtualMachine) (result compute.VirtualMachine, err error) {
81 future, err := cl.inner.CreateOrUpdate(ctx, resourceGroupName, VMName, parameters)
83 return compute.VirtualMachine{}, wrapAzureError(err)
85 future.WaitForCompletionRef(ctx, cl.inner.Client)
86 r, err := future.Result(cl.inner)
87 return r, wrapAzureError(err)
90 func (cl *virtualMachinesClientImpl) delete(ctx context.Context, resourceGroupName string, VMName string) (result *http.Response, err error) {
91 future, err := cl.inner.Delete(ctx, resourceGroupName, VMName)
93 return nil, wrapAzureError(err)
95 err = future.WaitForCompletionRef(ctx, cl.inner.Client)
96 return future.Response(), wrapAzureError(err)
99 func (cl *virtualMachinesClientImpl) listComplete(ctx context.Context, resourceGroupName string) (result compute.VirtualMachineListResultIterator, err error) {
100 r, err := cl.inner.ListComplete(ctx, resourceGroupName)
101 return r, wrapAzureError(err)
104 type interfacesClientWrapper interface {
105 createOrUpdate(ctx context.Context,
106 resourceGroupName string,
107 networkInterfaceName string,
108 parameters network.Interface) (result network.Interface, err error)
109 delete(ctx context.Context, resourceGroupName string, networkInterfaceName string) (result *http.Response, err error)
110 listComplete(ctx context.Context, resourceGroupName string) (result network.InterfaceListResultIterator, err error)
113 type interfacesClientImpl struct {
114 inner network.InterfacesClient
117 func (cl *interfacesClientImpl) delete(ctx context.Context, resourceGroupName string, VMName string) (result *http.Response, err error) {
118 future, err := cl.inner.Delete(ctx, resourceGroupName, VMName)
120 return nil, wrapAzureError(err)
122 err = future.WaitForCompletionRef(ctx, cl.inner.Client)
123 return future.Response(), wrapAzureError(err)
126 func (cl *interfacesClientImpl) createOrUpdate(ctx context.Context,
127 resourceGroupName string,
128 networkInterfaceName string,
129 parameters network.Interface) (result network.Interface, err error) {
131 future, err := cl.inner.CreateOrUpdate(ctx, resourceGroupName, networkInterfaceName, parameters)
133 return network.Interface{}, wrapAzureError(err)
135 future.WaitForCompletionRef(ctx, cl.inner.Client)
136 r, err := future.Result(cl.inner)
137 return r, wrapAzureError(err)
140 func (cl *interfacesClientImpl) listComplete(ctx context.Context, resourceGroupName string) (result network.InterfaceListResultIterator, err error) {
141 r, err := cl.inner.ListComplete(ctx, resourceGroupName)
142 return r, wrapAzureError(err)
145 type disksClientWrapper interface {
146 listByResourceGroup(ctx context.Context, resourceGroupName string) (result compute.DiskListPage, err error)
147 delete(ctx context.Context, resourceGroupName string, diskName string) (result compute.DisksDeleteFuture, err error)
150 type disksClientImpl struct {
151 inner compute.DisksClient
154 func (cl *disksClientImpl) listByResourceGroup(ctx context.Context, resourceGroupName string) (result compute.DiskListPage, err error) {
155 r, err := cl.inner.ListByResourceGroup(ctx, resourceGroupName)
156 return r, wrapAzureError(err)
159 func (cl *disksClientImpl) delete(ctx context.Context, resourceGroupName string, diskName string) (result compute.DisksDeleteFuture, err error) {
160 r, err := cl.inner.Delete(ctx, resourceGroupName, diskName)
161 return r, wrapAzureError(err)
164 var quotaRe = regexp.MustCompile(`(?i:exceed|quota|limit)`)
166 type azureRateLimitError struct {
171 func (ar *azureRateLimitError) EarliestRetry() time.Time {
175 type azureQuotaError struct {
179 func (ar *azureQuotaError) IsQuotaError() bool {
183 func wrapAzureError(err error) error {
184 de, ok := err.(autorest.DetailedError)
188 rq, ok := de.Original.(*azure.RequestError)
192 if rq.Response == nil {
195 if rq.Response.StatusCode == 429 || len(rq.Response.Header["Retry-After"]) >= 1 {
197 ra := rq.Response.Header["Retry-After"][0]
198 earliestRetry, parseErr := http.ParseTime(ra)
200 // Could not parse as a timestamp, must be number of seconds
201 dur, parseErr := strconv.ParseInt(ra, 10, 64)
203 earliestRetry = time.Now().Add(time.Duration(dur) * time.Second)
205 // Couldn't make sense of retry-after,
206 // so set retry to 20 seconds
207 earliestRetry = time.Now().Add(20 * time.Second)
210 return &azureRateLimitError{*rq, earliestRetry}
212 if rq.ServiceError == nil {
215 if quotaRe.FindString(rq.ServiceError.Code) != "" || quotaRe.FindString(rq.ServiceError.Message) != "" {
216 return &azureQuotaError{*rq}
221 type azureInstanceSet struct {
222 azconfig azureInstanceSetConfig
223 vmClient virtualMachinesClientWrapper
224 netClient interfacesClientWrapper
225 disksClient disksClientWrapper
226 imageResourceGroup string
227 blobcont containerWrapper
228 azureEnv azure.Environment
229 interfaces map[string]network.Interface
233 stopFunc context.CancelFunc
234 stopWg sync.WaitGroup
235 deleteNIC chan string
236 deleteBlob chan storage.Blob
237 deleteDisk chan compute.Disk
238 logger logrus.FieldLogger
241 func newAzureInstanceSet(config json.RawMessage, dispatcherID cloud.InstanceSetID, _ cloud.SharedResourceTags, logger logrus.FieldLogger) (prv cloud.InstanceSet, err error) {
242 azcfg := azureInstanceSetConfig{}
243 err = json.Unmarshal(config, &azcfg)
248 az := azureInstanceSet{logger: logger}
249 az.ctx, az.stopFunc = context.WithCancel(context.Background())
250 err = az.setup(azcfg, string(dispatcherID))
258 func (az *azureInstanceSet) setup(azcfg azureInstanceSetConfig, dispatcherID string) (err error) {
260 vmClient := compute.NewVirtualMachinesClient(az.azconfig.SubscriptionID)
261 netClient := network.NewInterfacesClient(az.azconfig.SubscriptionID)
262 disksClient := compute.NewDisksClient(az.azconfig.SubscriptionID)
263 storageAcctClient := storageacct.NewAccountsClient(az.azconfig.SubscriptionID)
265 az.azureEnv, err = azure.EnvironmentFromName(az.azconfig.CloudEnvironment)
270 authorizer, err := auth.ClientCredentialsConfig{
271 ClientID: az.azconfig.ClientID,
272 ClientSecret: az.azconfig.ClientSecret,
273 TenantID: az.azconfig.TenantID,
274 Resource: az.azureEnv.ResourceManagerEndpoint,
275 AADEndpoint: az.azureEnv.ActiveDirectoryEndpoint,
281 vmClient.Authorizer = authorizer
282 netClient.Authorizer = authorizer
283 disksClient.Authorizer = authorizer
284 storageAcctClient.Authorizer = authorizer
286 az.vmClient = &virtualMachinesClientImpl{vmClient}
287 az.netClient = &interfacesClientImpl{netClient}
288 az.disksClient = &disksClientImpl{disksClient}
290 az.imageResourceGroup = az.azconfig.ImageResourceGroup
291 if az.imageResourceGroup == "" {
292 az.imageResourceGroup = az.azconfig.ResourceGroup
295 var client storage.Client
296 if az.azconfig.StorageAccount != "" && az.azconfig.BlobContainer != "" {
297 result, err := storageAcctClient.ListKeys(az.ctx, az.azconfig.ResourceGroup, az.azconfig.StorageAccount)
299 az.logger.WithError(err).Warn("Couldn't get account keys")
303 key1 := *(*result.Keys)[0].Value
304 client, err = storage.NewBasicClientOnSovereignCloud(az.azconfig.StorageAccount, key1, az.azureEnv)
306 az.logger.WithError(err).Warn("Couldn't make client")
310 blobsvc := client.GetBlobService()
311 az.blobcont = blobsvc.GetContainerReference(az.azconfig.BlobContainer)
312 } else if az.azconfig.StorageAccount != "" || az.azconfig.BlobContainer != "" {
313 az.logger.Error("Invalid configuration: StorageAccount and BlobContainer must both be empty or both be set")
316 az.dispatcherID = dispatcherID
317 az.namePrefix = fmt.Sprintf("compute-%s-", az.dispatcherID)
321 defer az.stopWg.Done()
323 tk := time.NewTicker(5 * time.Minute)
326 case <-az.ctx.Done():
330 if az.blobcont != nil {
338 az.deleteNIC = make(chan string)
339 az.deleteBlob = make(chan storage.Blob)
340 az.deleteDisk = make(chan compute.Disk)
342 for i := 0; i < 4; i++ {
344 for nicname := range az.deleteNIC {
345 _, delerr := az.netClient.delete(context.Background(), az.azconfig.ResourceGroup, nicname)
347 az.logger.WithError(delerr).Warnf("Error deleting %v", nicname)
349 az.logger.Printf("Deleted NIC %v", nicname)
354 for blob := range az.deleteBlob {
355 err := blob.Delete(nil)
357 az.logger.WithError(err).Warnf("Error deleting %v", blob.Name)
359 az.logger.Printf("Deleted blob %v", blob.Name)
364 for disk := range az.deleteDisk {
365 _, err := az.disksClient.delete(az.ctx, az.imageResourceGroup, *disk.Name)
367 az.logger.WithError(err).Warnf("Error deleting disk %+v", *disk.Name)
369 az.logger.Printf("Deleted disk %v", *disk.Name)
378 func (az *azureInstanceSet) cleanupNic(nic network.Interface) {
379 _, delerr := az.netClient.delete(context.Background(), az.azconfig.ResourceGroup, *nic.Name)
381 az.logger.WithError(delerr).Warnf("Error cleaning up NIC after failed create")
385 func (az *azureInstanceSet) Create(
386 instanceType arvados.InstanceType,
387 imageID cloud.ImageID,
388 newTags cloud.InstanceTags,
389 initCommand cloud.InitCommand,
390 publicKey ssh.PublicKey) (cloud.Instance, error) {
393 defer az.stopWg.Done()
395 if instanceType.AddedScratch > 0 {
396 return nil, fmt.Errorf("cannot create instance type %q: driver does not implement non-zero AddedScratch (%d)", instanceType.Name, instanceType.AddedScratch)
399 name, err := randutil.String(15, "abcdefghijklmnopqrstuvwxyz0123456789")
404 name = az.namePrefix + name
406 tags := map[string]*string{}
407 for k, v := range newTags {
408 tags[k] = to.StringPtr(v)
410 tags["created-at"] = to.StringPtr(time.Now().Format(time.RFC3339Nano))
412 networkResourceGroup := az.azconfig.NetworkResourceGroup
413 if networkResourceGroup == "" {
414 networkResourceGroup = az.azconfig.ResourceGroup
417 nicParameters := network.Interface{
418 Location: &az.azconfig.Location,
420 InterfacePropertiesFormat: &network.InterfacePropertiesFormat{
421 IPConfigurations: &[]network.InterfaceIPConfiguration{
423 Name: to.StringPtr("ip1"),
424 InterfaceIPConfigurationPropertiesFormat: &network.InterfaceIPConfigurationPropertiesFormat{
425 Subnet: &network.Subnet{
426 ID: to.StringPtr(fmt.Sprintf("/subscriptions/%s/resourceGroups/%s/providers"+
427 "/Microsoft.Network/virtualnetworks/%s/subnets/%s",
428 az.azconfig.SubscriptionID,
429 networkResourceGroup,
431 az.azconfig.Subnet)),
433 PrivateIPAllocationMethod: network.Dynamic,
439 nic, err := az.netClient.createOrUpdate(az.ctx, az.azconfig.ResourceGroup, name+"-nic", nicParameters)
441 return nil, wrapAzureError(err)
445 customData := base64.StdEncoding.EncodeToString([]byte("#!/bin/sh\n" + initCommand + "\n"))
446 var storageProfile *compute.StorageProfile
448 re := regexp.MustCompile(`^http(s?)://`)
449 if re.MatchString(string(imageID)) {
450 if az.blobcont == nil {
452 return nil, wrapAzureError(errors.New("Invalid configuration: can't configure unmanaged image URL without StorageAccount and BlobContainer"))
454 blobname = fmt.Sprintf("%s-os.vhd", name)
455 instanceVhd := fmt.Sprintf("https://%s.blob.%s/%s/%s",
456 az.azconfig.StorageAccount,
457 az.azureEnv.StorageEndpointSuffix,
458 az.azconfig.BlobContainer,
460 az.logger.Warn("using deprecated unmanaged image, see https://doc.arvados.org/ to migrate to managed disks")
461 storageProfile = &compute.StorageProfile{
462 OsDisk: &compute.OSDisk{
463 OsType: compute.Linux,
464 Name: to.StringPtr(name + "-os"),
465 CreateOption: compute.DiskCreateOptionTypesFromImage,
466 Image: &compute.VirtualHardDisk{
467 URI: to.StringPtr(string(imageID)),
469 Vhd: &compute.VirtualHardDisk{
475 id := to.StringPtr("/subscriptions/" + az.azconfig.SubscriptionID + "/resourceGroups/" + az.imageResourceGroup + "/providers/Microsoft.Compute/images/" + string(imageID))
476 if az.azconfig.SharedImageGalleryName != "" && az.azconfig.SharedImageGalleryImageVersion != "" {
477 id = to.StringPtr("/subscriptions/" + az.azconfig.SubscriptionID + "/resourceGroups/" + az.imageResourceGroup + "/providers/Microsoft.Compute/galleries/" + az.azconfig.SharedImageGalleryName + "/images/" + string(imageID) + "/versions/" + az.azconfig.SharedImageGalleryImageVersion)
478 } else if az.azconfig.SharedImageGalleryName != "" || az.azconfig.SharedImageGalleryImageVersion != "" {
480 return nil, wrapAzureError(errors.New("Invalid configuration: SharedImageGalleryName and SharedImageGalleryImageVersion must both be set or both be empty"))
482 storageProfile = &compute.StorageProfile{
483 ImageReference: &compute.ImageReference{
486 OsDisk: &compute.OSDisk{
487 OsType: compute.Linux,
488 Name: to.StringPtr(name + "-os"),
489 CreateOption: compute.DiskCreateOptionTypesFromImage,
494 vmParameters := compute.VirtualMachine{
495 Location: &az.azconfig.Location,
497 VirtualMachineProperties: &compute.VirtualMachineProperties{
498 HardwareProfile: &compute.HardwareProfile{
499 VMSize: compute.VirtualMachineSizeTypes(instanceType.ProviderType),
501 StorageProfile: storageProfile,
502 NetworkProfile: &compute.NetworkProfile{
503 NetworkInterfaces: &[]compute.NetworkInterfaceReference{
506 NetworkInterfaceReferenceProperties: &compute.NetworkInterfaceReferenceProperties{
507 Primary: to.BoolPtr(true),
512 OsProfile: &compute.OSProfile{
514 AdminUsername: to.StringPtr(az.azconfig.AdminUsername),
515 LinuxConfiguration: &compute.LinuxConfiguration{
516 DisablePasswordAuthentication: to.BoolPtr(true),
517 SSH: &compute.SSHConfiguration{
518 PublicKeys: &[]compute.SSHPublicKey{
520 Path: to.StringPtr("/home/" + az.azconfig.AdminUsername + "/.ssh/authorized_keys"),
521 KeyData: to.StringPtr(string(ssh.MarshalAuthorizedKey(publicKey))),
526 CustomData: &customData,
531 if instanceType.Preemptible {
532 // Setting maxPrice to -1 is the equivalent of paying spot price, up to the
533 // normal price. This means the node will not be pre-empted for price
534 // reasons. It may still be pre-empted for capacity reasons though. And
535 // Azure offers *no* SLA on spot instances.
536 var maxPrice float64 = -1
537 vmParameters.VirtualMachineProperties.Priority = compute.Spot
538 vmParameters.VirtualMachineProperties.EvictionPolicy = compute.Delete
539 vmParameters.VirtualMachineProperties.BillingProfile = &compute.BillingProfile{MaxPrice: &maxPrice}
542 vm, err := az.vmClient.createOrUpdate(az.ctx, az.azconfig.ResourceGroup, name, vmParameters)
544 // Do some cleanup. Otherwise, an unbounded number of new unused nics and
545 // blobs can pile up during times when VMs can't be created and the
546 // dispatcher keeps retrying, because the garbage collection in manageBlobs
547 // and manageNics is only triggered periodically. This is most important
548 // for nics, because those are subject to a quota.
552 _, delerr := az.blobcont.GetBlobReference(blobname).DeleteIfExists(nil)
554 az.logger.WithError(delerr).Warnf("Error cleaning up vhd blob after failed create")
558 // Leave cleaning up of managed disks to the garbage collection in manageDisks()
560 return nil, wrapAzureError(err)
563 return &azureInstance{
570 func (az *azureInstanceSet) Instances(cloud.InstanceTags) ([]cloud.Instance, error) {
572 defer az.stopWg.Done()
574 interfaces, err := az.manageNics()
579 result, err := az.vmClient.listComplete(az.ctx, az.azconfig.ResourceGroup)
581 return nil, wrapAzureError(err)
584 var instances []cloud.Instance
585 for ; result.NotDone(); err = result.Next() {
587 return nil, wrapAzureError(err)
589 instances = append(instances, &azureInstance{
592 nic: interfaces[*(*result.Value().NetworkProfile.NetworkInterfaces)[0].ID],
595 return instances, nil
598 // manageNics returns a list of Azure network interface resources.
599 // Also performs garbage collection of NICs which have "namePrefix",
600 // are not associated with a virtual machine and have a "created-at"
601 // time more than DeleteDanglingResourcesAfter (to prevent racing and
602 // deleting newly created NICs) in the past are deleted.
603 func (az *azureInstanceSet) manageNics() (map[string]network.Interface, error) {
605 defer az.stopWg.Done()
607 result, err := az.netClient.listComplete(az.ctx, az.azconfig.ResourceGroup)
609 return nil, wrapAzureError(err)
612 interfaces := make(map[string]network.Interface)
614 timestamp := time.Now()
615 for ; result.NotDone(); err = result.Next() {
617 az.logger.WithError(err).Warnf("Error listing nics")
618 return interfaces, nil
620 if strings.HasPrefix(*result.Value().Name, az.namePrefix) {
621 if result.Value().VirtualMachine != nil {
622 interfaces[*result.Value().ID] = result.Value()
624 if result.Value().Tags["created-at"] != nil {
625 createdAt, err := time.Parse(time.RFC3339Nano, *result.Value().Tags["created-at"])
627 if timestamp.Sub(createdAt) > az.azconfig.DeleteDanglingResourcesAfter.Duration() {
628 az.logger.Printf("Will delete %v because it is older than %s", *result.Value().Name, az.azconfig.DeleteDanglingResourcesAfter)
629 az.deleteNIC <- *result.Value().Name
636 return interfaces, nil
639 // manageBlobs garbage collects blobs (VM disk images) in the
640 // configured storage account container. It will delete blobs which
641 // have "namePrefix", are "available" (which means they are not
642 // leased to a VM) and haven't been modified for
643 // DeleteDanglingResourcesAfter seconds.
644 func (az *azureInstanceSet) manageBlobs() {
646 page := storage.ListBlobsParameters{Prefix: az.namePrefix}
647 timestamp := time.Now()
650 response, err := az.blobcont.ListBlobs(page)
652 az.logger.WithError(err).Warn("Error listing blobs")
655 for _, b := range response.Blobs {
656 age := timestamp.Sub(time.Time(b.Properties.LastModified))
657 if b.Properties.BlobType == storage.BlobTypePage &&
658 b.Properties.LeaseState == "available" &&
659 b.Properties.LeaseStatus == "unlocked" &&
660 age.Seconds() > az.azconfig.DeleteDanglingResourcesAfter.Duration().Seconds() {
662 az.logger.Printf("Blob %v is unlocked and not modified for %v seconds, will delete", b.Name, age.Seconds())
666 if response.NextMarker != "" {
667 page.Marker = response.NextMarker
674 // manageDisks garbage collects managed compute disks (VM disk images) in the
675 // configured resource group. It will delete disks which have "namePrefix",
676 // are "unattached" (which means they are not leased to a VM) and were created
677 // more than DeleteDanglingResourcesAfter seconds ago. (Azure provides no
678 // modification timestamp on managed disks, there is only a creation timestamp)
679 func (az *azureInstanceSet) manageDisks() {
681 re := regexp.MustCompile(`^` + regexp.QuoteMeta(az.namePrefix) + `.*-os$`)
682 threshold := time.Now().Add(-az.azconfig.DeleteDanglingResourcesAfter.Duration())
684 response, err := az.disksClient.listByResourceGroup(az.ctx, az.imageResourceGroup)
686 az.logger.WithError(err).Warn("Error listing disks")
690 for ; response.NotDone(); err = response.Next() {
692 az.logger.WithError(err).Warn("Error getting next page of disks")
695 for _, d := range response.Values() {
696 if d.DiskProperties.DiskState == compute.Unattached &&
697 d.Name != nil && re.MatchString(*d.Name) &&
698 d.DiskProperties.TimeCreated.ToTime().Before(threshold) {
700 az.logger.Printf("Disk %v is unlocked and was created at %+v, will delete", *d.Name, d.DiskProperties.TimeCreated.ToTime())
707 func (az *azureInstanceSet) Stop() {
715 type azureInstance struct {
716 provider *azureInstanceSet
717 nic network.Interface
718 vm compute.VirtualMachine
721 func (ai *azureInstance) ID() cloud.InstanceID {
722 return cloud.InstanceID(*ai.vm.ID)
725 func (ai *azureInstance) String() string {
729 func (ai *azureInstance) ProviderType() string {
730 return string(ai.vm.VirtualMachineProperties.HardwareProfile.VMSize)
733 func (ai *azureInstance) SetTags(newTags cloud.InstanceTags) error {
734 ai.provider.stopWg.Add(1)
735 defer ai.provider.stopWg.Done()
737 tags := map[string]*string{}
738 for k, v := range ai.vm.Tags {
741 for k, v := range newTags {
742 tags[k] = to.StringPtr(v)
745 vmParameters := compute.VirtualMachine{
746 Location: &ai.provider.azconfig.Location,
749 vm, err := ai.provider.vmClient.createOrUpdate(ai.provider.ctx, ai.provider.azconfig.ResourceGroup, *ai.vm.Name, vmParameters)
751 return wrapAzureError(err)
758 func (ai *azureInstance) Tags() cloud.InstanceTags {
759 tags := cloud.InstanceTags{}
760 for k, v := range ai.vm.Tags {
766 func (ai *azureInstance) Destroy() error {
767 ai.provider.stopWg.Add(1)
768 defer ai.provider.stopWg.Done()
770 _, err := ai.provider.vmClient.delete(ai.provider.ctx, ai.provider.azconfig.ResourceGroup, *ai.vm.Name)
771 return wrapAzureError(err)
774 func (ai *azureInstance) Address() string {
775 if iprops := ai.nic.InterfacePropertiesFormat; iprops == nil {
777 } else if ipconfs := iprops.IPConfigurations; ipconfs == nil || len(*ipconfs) == 0 {
779 } else if ipconfprops := (*ipconfs)[0].InterfaceIPConfigurationPropertiesFormat; ipconfprops == nil {
781 } else if addr := ipconfprops.PrivateIPAddress; addr == nil {
788 func (ai *azureInstance) RemoteUser() string {
789 return ai.provider.azconfig.AdminUsername
792 func (ai *azureInstance) VerifyHostKey(ssh.PublicKey, *ssh.Client) error {
793 return cloud.ErrNotImplemented