platform.go

79 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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
package platform

// Platform provides cloud infrastructure operations.
// Use providers to create: mock.New(), digitalocean.New(), aws.New(), gcp.New()
type Platform struct {
	Backend
}

// Backend is the interface that providers implement.
type Backend interface {
	// Servers
	CreateServer(opts ServerOptions) (*Server, error)
	GetServer(name string) (*Server, error)
	DeleteServer(id string) error

	// Volumes
	CreateVolume(name string, sizeGB int, region Region) (*Volume, error)
	GetVolume(name string) (*Volume, error)
	AttachVolume(volumeID, serverID string) error
	DetachVolume(volumeID string) error
}

// ServerOptions configures server creation.
type ServerOptions struct {
	Name    string
	Size    Size
	Region  Region
	Image   string // Provider-specific image ID/slug
	SSHKey  string // SSH key fingerprint (use GetSSHKeyFingerprint to get)
	Tags    []string
	Backups bool   // Enable provider-managed backups
	VpcID   string // VPC ID for private networking (optional)
}

// SSHKeyProvider is an optional interface for SSH key management.
type SSHKeyProvider interface {
	// GetSSHKeyFingerprint finds or registers an SSH key, returns fingerprint.
	GetSSHKeyFingerprint(publicKey string) (string, error)
}

// VPCProvider is an optional interface for VPC management.
type VPCProvider interface {
	// CreateVPC creates a VPC network, returning its ID.
	CreateVPC(name, region, description string) (string, error)
	// GetVPC looks up a VPC by name and returns its ID.
	GetVPC(name string) (string, error)
}

// LoadBalancer represents a cloud load balancer.
type LoadBalancer struct {
	ID     string
	Name   string
	IP     string // Public IP address
	Status string // "new", "active", "errored"
}

// LoadBalancerConfig configures load balancer creation.
type LoadBalancerConfig struct {
	Name       string
	Region     Region
	VpcID      string   // VPC to attach to
	ServerIDs  []int    // Backend server IDs
	Tags       []string // Tags to target servers (alternative to ServerIDs)
	Port       int      // Frontend port (default 443)
	TargetPort int      // Backend port (default 80)
	HealthPath string   // Health check path (default "/health")
}

// LoadBalancerProvider is an optional interface for load balancer management.
type LoadBalancerProvider interface {
	CreateLoadBalancer(cfg LoadBalancerConfig) (*LoadBalancer, error)
	GetLoadBalancer(name string) (*LoadBalancer, error)
	DeleteLoadBalancer(id string) error
}

// TagProvider is an optional interface for tagging servers with provider-specific tags.
type TagProvider interface {
	TagServer(serverID string, tag string) error
}