package providers import ( "context" "time" ) // VMOptions contains options for creating a new VM type VMOptions struct { Name string Zone string // e.g., "ch-gva-2", "lpg1", "fsn1" Flavor string // Instance type/size Image string // OS image name or ID SSHPublicKey string // Ephemeral public key content UserData string // Cloud-init script DiskSizeGB int64 // Root disk size Tags map[string]string // Optional tags/labels } // VM represents a created virtual machine type VM struct { ID string Name string PublicIP string PrivateIP string Status string Provider string Zone string CreatedAt time.Time } // Flavor represents an instance type/size type Flavor struct { ID string Name string CPUs int Memory int // MB Disk int // GB (if applicable) } // Image represents an OS image type Image struct { ID string Name string } // CloudProvider defines the interface for cloud providers type CloudProvider interface { // Name returns the provider name Name() string // CreateVM creates a new virtual machine CreateVM(ctx context.Context, opts VMOptions) (*VM, error) // DeleteVM deletes a virtual machine by ID DeleteVM(ctx context.Context, vmID string) error // GetVM gets VM details by ID GetVM(ctx context.Context, vmID string) (*VM, error) // WaitForSSH waits until SSH is available on the VM WaitForSSH(ctx context.Context, ip string, port int, timeout time.Duration) error // ListFlavors lists available instance types ListFlavors(ctx context.Context) ([]Flavor, error) // ListImages lists available OS images ListImages(ctx context.Context, filter string) ([]Image, error) // ListZones lists available zones/regions ListZones(ctx context.Context) ([]string, error) } // GenerateCloudInit creates a cloud-init user-data script func GenerateCloudInit(ephemeralPubKey string) string { return `#cloud-config ssh_pwauth: false users: - name: root ssh_authorized_keys: - "` + ephemeralPubKey + `" package_update: true packages: - rsync - docker.io - docker-compose - wireguard-tools write_files: - path: /var/tmp/recovery-ready content: "ready" permissions: '0644' runcmd: - systemctl enable docker - systemctl start docker ` }