Skip to content

Commit

Permalink
fix(814) Add instance disks resource to linode
Browse files Browse the repository at this point in the history
  • Loading branch information
titanventura committed Aug 14, 2023
1 parent 92208f1 commit 228ade5
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions providers/linode/compute/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type LinodeInstance struct {
Instance *linodego.Instance
}

func Linodes(ctx context.Context, client providers.ProviderClient, linodeInstances []LinodeInstance) ([]Resource, error) {
func LinodesAndDisks(ctx context.Context, client providers.ProviderClient, linodeInstances []LinodeInstance) ([]Resource, error) {
resources := make([]Resource, 0)

for _, linodeInstance := range linodeInstances {
Expand Down Expand Up @@ -53,12 +53,32 @@ func Linodes(ctx context.Context, client providers.ProviderClient, linodeInstanc
Tags: tags,
Link: fmt.Sprintf("https://cloud.linode.com/linodes/%d", instance.ID),
})

instanceDisks, err := client.LinodeClient.ListInstanceDisks(ctx, instance.ID, &linodego.ListOptions{})
if err != nil {
return resources, err
}

for _, disk := range instanceDisks {
resources = append(resources, models.Resource{
Provider: "Linode",
Account: client.Name,
Service: "Instance Disk",
Region: instance.Region,
ResourceId: fmt.Sprintf("%d", disk.ID),
Cost: 0,
Name: disk.Label,
FetchedAt: time.Now(),
CreatedAt: *disk.Created,
Link: fmt.Sprintf("https://cloud.linode.com/linodes/%d/storage", instance.ID),
})
}
}

log.WithFields(log.Fields{
"provider": "Linode",
"account": client.Name,
"service": "Linode",
"service": "Linode and Instance Disk",
"resources": len(resources),
}).Info("Fetched resources")
return resources, nil
Expand Down

0 comments on commit 228ade5

Please sign in to comment.