mirror of
https://github.com/jangraefen/hcloud-pricing-exporter
synced 2024-11-10 05:54:15 +00:00
Merge branch 'main' of github.com:jangraefen/hcloud-pricing-exporter
This commit is contained in:
commit
f11439b7ba
2 changed files with 10 additions and 5 deletions
|
@ -36,21 +36,26 @@ func (provider *PriceProvider) FloatingIP(ipType hcloud.FloatingIPType, location
|
|||
}
|
||||
|
||||
// PrimaryIP returns the current price for a primary IP per hour and month.
|
||||
func (provider *PriceProvider) PrimaryIP(ipType hcloud.PrimaryIPType, datacenter string) (hourly, monthly float64, err error) {
|
||||
func (provider *PriceProvider) PrimaryIP(ipType hcloud.PrimaryIPType, location string) (hourly, monthly float64, err error) {
|
||||
provider.pricingLock.RLock()
|
||||
defer provider.pricingLock.RUnlock()
|
||||
|
||||
// v6 pricing is not defined by the API
|
||||
if string(ipType) == "ipv6" {
|
||||
return 0, 0, nil
|
||||
}
|
||||
|
||||
for _, byType := range provider.getPricing().PrimaryIPs {
|
||||
if byType.Type == string(ipType) {
|
||||
for _, pricing := range byType.Pricings {
|
||||
if pricing.Datacenter == datacenter {
|
||||
if pricing.Location == location {
|
||||
return parsePrice(pricing.Hourly.Gross), parsePrice(pricing.Monthly.Gross), nil
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0, 0, fmt.Errorf("no primary IP pricing found for datacenter %s", datacenter)
|
||||
return 0, 0, fmt.Errorf("no primary IP pricing found for location %s", location)
|
||||
}
|
||||
|
||||
// Image returns the current price for an image per GB per month.
|
||||
|
|
|
@ -8,7 +8,7 @@ var _ Fetcher = &floatingIP{}
|
|||
|
||||
// NewPrimaryIP creates a new fetcher that will collect pricing information on primary IPs.
|
||||
func NewPrimaryIP(pricing *PriceProvider) Fetcher {
|
||||
return &primaryIP{newBase(pricing, "primaryip", "datacenter")}
|
||||
return &primaryIP{newBase(pricing, "primaryip", "location")}
|
||||
}
|
||||
|
||||
type primaryIP struct {
|
||||
|
@ -24,7 +24,7 @@ func (primaryIP primaryIP) Run(client *hcloud.Client) error {
|
|||
for _, p := range primaryIPs {
|
||||
datacenter := p.Datacenter
|
||||
|
||||
hourlyPrice, monthlyPrice, err := primaryIP.pricing.PrimaryIP(p.Type, datacenter.Name)
|
||||
hourlyPrice, monthlyPrice, err := primaryIP.pricing.PrimaryIP(p.Type, datacenter.Location.Name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue