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)
}
Output:
Index ¶
- func ComputeCost(sku *node.SKU, timeOnline time.Duration) float64
- type Backend
- func (b *Backend) ActiveNodeCount(ctx context.Context) (int64, error)
- func (b *Backend) ActiveNodes(ctx context.Context) ([]*node.Node, error)
- func (b *Backend) AddStaticPeer(ctx context.Context, name, address string, port int) (*wgutil.InterfaceConfig, error)
- func (b *Backend) CreateNode(ctx context.Context, driver node.Driver, name, region, sku, user, ipv4 string, ...) error
- func (b *Backend) DestroyNode(ctx context.Context, name string) error
- func (b *Backend) GetConfigForPeer(ctx context.Context, name string) (*wgutil.InterfaceConfig, error)
- func (b *Backend) InactiveNodes(ctx context.Context) ([]*node.Node, error)
- func (b *Backend) RemoveStaticPeer(ctx context.Context, name string) error
- func (b *Backend) RunOnController(ctx context.Context, cmd string) (string, error)
- func (b *Backend) SSHIdentityFile() string
- func (b *Backend) SSHPublicKey() string
- type Config
- type DigitalOceanConfig
- type DreamHostConfig
- type DriverConfig
- type GCPConfig
- type HeficedConfig
- type HetznerConfig
- type OVHConfig
- type ScalewayConfig
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Backend ¶
type Backend struct {
NodeDrivers map[string]node.Driver
// contains filtered or unexported fields
}
Backend ...
func (*Backend) ActiveNodeCount ¶
func (*Backend) ActiveNodes ¶
func (*Backend) AddStaticPeer ¶
func (*Backend) CreateNode ¶
func (*Backend) GetConfigForPeer ¶
func (*Backend) InactiveNodes ¶
func (*Backend) RemoveStaticPeer ¶
func (*Backend) RunOnController ¶
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 DreamHostConfig ¶
DreamHostConfig ...
type DriverConfig ¶
type DriverConfig interface {
// contains filtered or unexported methods
}
DriverConfig ...
type HeficedConfig ¶
HeficedConfig ...
type OVHConfig ¶
type OVHConfig struct {
AppKey string
AppSecret string
ConsumerKey string
ProjectID string
Subsidiary string
}
OVHConfig ...
type ScalewayConfig ¶
ScalewayConfig ...
Click to show internal directories.
Click to hide internal directories.