Refactor providers data
This commit is contained in:
21
internal/providers/common.go
Normal file
21
internal/providers/common.go
Normal file
@ -0,0 +1,21 @@
|
||||
package providers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
proto "git.badhouseplants.net/softplayer/softplayer-go-proto/pkg/environments"
|
||||
)
|
||||
|
||||
type Providers interface {
|
||||
GetServerType(proto.ServerType) (string, error)
|
||||
GetServerLocation(string) (string, error)
|
||||
}
|
||||
|
||||
func GetProvider(provider proto.Provider) (Providers, error) {
|
||||
switch provider {
|
||||
case proto.Provider_PROVIDER_HETZNER:
|
||||
return &Hetzner{}, nil
|
||||
default:
|
||||
return nil, fmt.Errorf("unknown provider: %s", provider.String())
|
||||
}
|
||||
}
|
@ -1,9 +1,47 @@
|
||||
package providers
|
||||
|
||||
// Hetzner supported regions
|
||||
const (
|
||||
HETZNER_REG_FINLAND = "fn"
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
proto "git.badhouseplants.net/softplayer/softplayer-go-proto/pkg/environments"
|
||||
)
|
||||
|
||||
type Hetzner struct {
|
||||
type Hetzner struct{}
|
||||
|
||||
// GetServerLocation implements Providers.
|
||||
func (h *Hetzner) GetServerLocation(location string) (string, error) {
|
||||
switch location {
|
||||
case proto.HetznerLocation_HETZNER_LOCATION_ASHBURN.String():
|
||||
return "ash", nil
|
||||
case proto.HetznerLocation_HETZNER_LOCATION_HILLSBORO.String():
|
||||
return "hil", nil
|
||||
case proto.HetznerLocation_HETZNER_LOCATION_FALKENSTEIN.String():
|
||||
return "fsn1", nil
|
||||
case proto.HetznerLocation_HETZNER_LOCATION_NUREMBERG.String():
|
||||
return "nbg1", nil
|
||||
case proto.HetznerLocation_HETZNER_LOCATION_HELSINKI.String():
|
||||
return "hel1", nil
|
||||
default:
|
||||
return "", fmt.Errorf("unknown location: %s", location)
|
||||
}
|
||||
}
|
||||
|
||||
func (h *Hetzner) GetServerType(kind proto.ServerType) (serverType string, err error) {
|
||||
switch kind {
|
||||
case proto.ServerType_SERVER_TYPE_STARTER:
|
||||
serverType = "cpx21"
|
||||
return
|
||||
case proto.ServerType_SERVER_TYPE_REGULAR:
|
||||
serverType = "cpx31"
|
||||
return
|
||||
case proto.ServerType_SERVER_TYPE_PLUS:
|
||||
serverType = "cpx41"
|
||||
return
|
||||
case proto.ServerType_SERVER_TYPE_PRO:
|
||||
serverType = "cpx51"
|
||||
return
|
||||
default:
|
||||
err = fmt.Errorf("unknown server type: %s", kind.String())
|
||||
return
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user