2021-03-05 18:47:23 +00:00
|
|
|
package fetcher
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/hetznercloud/hcloud-go/hcloud"
|
|
|
|
)
|
|
|
|
|
|
|
|
var _ Fetcher = &floatingIP{}
|
|
|
|
|
2021-03-05 18:53:37 +00:00
|
|
|
// NewFloatingIP creates a new fetcher that will collect pricing information on floating IPs.
|
2021-03-05 19:28:17 +00:00
|
|
|
func NewFloatingIP(pricing *PriceProvider) Fetcher {
|
|
|
|
return &floatingIP{newBase(pricing, "floatingip", "location")}
|
2021-03-05 18:47:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type floatingIP struct {
|
|
|
|
*baseFetcher
|
|
|
|
}
|
|
|
|
|
|
|
|
func (floatingIP floatingIP) Run(client *hcloud.Client) error {
|
|
|
|
floatingIPs, _, err := client.FloatingIP.List(ctx, hcloud.FloatingIPListOpts{})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, f := range floatingIPs {
|
|
|
|
location := f.HomeLocation
|
|
|
|
|
2021-03-05 19:28:17 +00:00
|
|
|
monthlyPrice := floatingIP.pricing.FloatingIP()
|
2021-03-05 18:47:23 +00:00
|
|
|
hourlyPrice := pricingPerHour(monthlyPrice)
|
|
|
|
|
|
|
|
floatingIP.hourly.WithLabelValues(f.Name, location.Name).Set(hourlyPrice)
|
|
|
|
floatingIP.monthly.WithLabelValues(f.Name, location.Name).Set(monthlyPrice)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|