2021-03-05 18:47:23 +00:00
|
|
|
package fetcher
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/hetznercloud/hcloud-go/hcloud"
|
|
|
|
)
|
|
|
|
|
|
|
|
var _ Fetcher = &snapshot{}
|
|
|
|
|
2021-03-05 18:53:37 +00:00
|
|
|
// NewSnapshot creates a new fetcher that will collect pricing information on server snapshots.
|
2023-01-25 19:24:33 +00:00
|
|
|
func NewSnapshot(pricing *PriceProvider, additionalLabels ...string) Fetcher {
|
|
|
|
return &snapshot{newBase(pricing, "snapshot", nil, additionalLabels...)}
|
2021-03-05 18:47:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type snapshot struct {
|
|
|
|
*baseFetcher
|
|
|
|
}
|
|
|
|
|
|
|
|
func (snapshot snapshot) Run(client *hcloud.Client) error {
|
|
|
|
images, _, err := client.Image.List(ctx, hcloud.ImageListOpts{})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, i := range images {
|
|
|
|
if i.Type == "snapshot" {
|
2021-03-06 23:40:07 +00:00
|
|
|
monthlyPrice := float64(i.ImageSize) * snapshot.pricing.Image()
|
2021-03-05 18:47:23 +00:00
|
|
|
hourlyPrice := pricingPerHour(monthlyPrice)
|
|
|
|
|
2023-01-25 19:24:33 +00:00
|
|
|
labels := append([]string{
|
|
|
|
i.Name,
|
|
|
|
},
|
|
|
|
parseAdditionalLabels(snapshot.additionalLabels, i.Labels)...,
|
|
|
|
)
|
|
|
|
|
|
|
|
snapshot.hourly.WithLabelValues(labels...).Set(hourlyPrice)
|
|
|
|
snapshot.monthly.WithLabelValues(labels...).Set(monthlyPrice)
|
2021-03-05 18:47:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|