backend

package
v0.0.0-...-7bbcb7b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 16, 2026 License: AGPL-3.0 Imports: 25 Imported by: 0

Documentation

Overview

Package backend ...

Example (LeaseWGIP)
package main

import (
	"database/sql"
	"log"

	_ "github.com/lib/pq"
)

var (
	wgIPRangeStart = "10.0.0.1"

	db *sql.DB
)

func leaseWGIP(lesseeType string, lesseeID int64) (string, error) {
	query := `
	INSERT INTO wireguard_ip_leases (
		SELECT $1, $2, min(t.ip)
		FROM (
			SELECT $3 ip
			UNION
			SELECT ip + 1
			FROM wireguard_ip_leases
		) t
		LEFT JOIN wireguard_ip_leases
		ON (t.ip = wireguard_ip_leases.ip)
		WHERE wireguard_ip_leases.ip IS NULL
	)
	RETURNING ip;`

	tx, err := db.Begin()
	if err != nil {
		return "", err
	}
	var ip sql.NullString
	if err := tx.QueryRow(query, lesseeType, lesseeID, wgIPRangeStart).Scan(&ip); err != nil {
		if err := tx.Rollback(); err != nil {
			return "", err
		}
		return "", err
	}
	if err := tx.Commit(); err != nil {
		return "", err
	}

	return ip.String, nil
}

func releaseWGIPLease(lesseeType string, lesseeID int64) error {
	// delete from wireguard_ip_leases...
	return nil
}

func main() {
	nodeIP, err := leaseWGIP("node", 1234)
	log.Println(nodeIP, err)

	peerIP, err := leaseWGIP("external_peer", 1234)
	log.Println(peerIP, err)
}

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComputeCost

func ComputeCost(sku *node.SKU, timeOnline time.Duration) float64

Types

type Backend

type Backend struct {
	NodeDrivers map[string]node.Driver
	// contains filtered or unexported fields
}

Backend ...

func New

func New(cfg Config) (*Backend, error)

New ...

func (*Backend) ActiveNodeCount

func (b *Backend) ActiveNodeCount(ctx context.Context) (int64, error)

func (*Backend) ActiveNodes

func (b *Backend) ActiveNodes(ctx context.Context) ([]*node.Node, error)

func (*Backend) AddStaticPeer

func (b *Backend) AddStaticPeer(ctx context.Context, name, address string, port int) (*wgutil.InterfaceConfig, error)

func (*Backend) CreateNode

func (b *Backend) CreateNode(
	ctx context.Context,
	driver node.Driver,
	name, region, sku, user, ipv4 string,
	billingType node.BillingType,
	nodeType node.NodeType,
	spot bool,
	w io.Writer,
) error

func (*Backend) DestroyNode

func (b *Backend) DestroyNode(ctx context.Context, name string) error

func (*Backend) GetConfigForPeer

func (b *Backend) GetConfigForPeer(ctx context.Context, name string) (*wgutil.InterfaceConfig, error)

func (*Backend) InactiveNodes

func (b *Backend) InactiveNodes(ctx context.Context) ([]*node.Node, error)

func (*Backend) RemoveStaticPeer

func (b *Backend) RemoveStaticPeer(ctx context.Context, name string) error

func (*Backend) RunOnController

func (b *Backend) RunOnController(ctx context.Context, cmd string) (string, error)

func (*Backend) SSHIdentityFile

func (b *Backend) SSHIdentityFile() string

SSHIdentityFile ...

func (*Backend) SSHPublicKey

func (b *Backend) SSHPublicKey() string

SSHPublicKey ...

type Config

type Config struct {
	LogLevel int
	DB       struct {
		Name string
		User string
		Pass string
		Host string
		Port int
	}
	Providers       map[string]DriverConfig
	SSHIdentityFile string
	ScriptDirectory string
	CertificateKey  string
	Lockfile        string
}

Config ...

func (*Config) DecoderConfigOptions

func (c *Config) DecoderConfigOptions(config *mapstructure.DecoderConfig)

DecoderConfigOptions ...

type DigitalOceanConfig

type DigitalOceanConfig struct {
	Token string
}

DigitalOceanConfig ...

type DreamHostConfig

type DreamHostConfig struct {
	TenantID   string
	TenantName string
	Username   string
	Password   string
}

DreamHostConfig ...

type DriverConfig

type DriverConfig interface {
	// contains filtered or unexported methods
}

DriverConfig ...

type GCPConfig

type GCPConfig struct {
	Config string
}

type HeficedConfig

type HeficedConfig struct {
	ClientID     string
	ClientSecret string
	TenantID     string
}

HeficedConfig ...

type HetznerConfig

type HetznerConfig struct {
	Token string
}

HetznerConfig ...

type OVHConfig

type OVHConfig struct {
	AppKey      string
	AppSecret   string
	ConsumerKey string
	ProjectID   string
	Subsidiary  string
}

OVHConfig ...

type ScalewayConfig

type ScalewayConfig struct {
	OrganizationID string
	AccessKey      string
	SecretKey      string
}

ScalewayConfig ...

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址