metal.go

55 lines
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
package metal

import (
	"congo.gg/pkg/platform"
)

// Compile-time check that backend implements platform.Backend.
var _ platform.Backend = (*backend)(nil)

type backend struct {
	servers map[string]*platform.Server
}

// New creates a bare-metal platform from pre-configured servers.
// Servers are declared in infra.json with their IPs — no cloud API creates them.
func New(servers []platform.Server) *platform.Platform {
	m := make(map[string]*platform.Server, len(servers))
	for i := range servers {
		m[servers[i].Name] = &servers[i]
	}
	return &platform.Platform{
		Backend: &backend{servers: m},
	}
}

func (b *backend) CreateServer(opts platform.ServerOptions) (*platform.Server, error) {
	return nil, platform.ErrUnsupported
}

func (b *backend) GetServer(name string) (*platform.Server, error) {
	if s, ok := b.servers[name]; ok {
		return s, nil
	}
	return nil, platform.ErrNotFound
}

func (b *backend) DeleteServer(id string) error {
	return platform.ErrUnsupported
}

func (b *backend) CreateVolume(name string, sizeGB int, region platform.Region) (*platform.Volume, error) {
	return nil, platform.ErrUnsupported
}

func (b *backend) GetVolume(name string) (*platform.Volume, error) {
	return nil, platform.ErrUnsupported
}

func (b *backend) AttachVolume(volumeID, serverID string) error {
	return platform.ErrUnsupported
}

func (b *backend) DetachVolume(volumeID string) error {
	return platform.ErrUnsupported
}