go_weave_api

package module
v0.0.0-...-9d0a089 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2022 License: Apache-2.0 Imports: 20 Imported by: 0

README

go-weave-api

go-weave-api is a simple weave client that helps users deploy weave nodes locally or remotely. Most of the code is written based on weave scripts. More detail can be found in this repository.

requirement

go-weave-api requires go-1.18 or later. This api is writing based on weave-2.8.1, there is no verification that the previous version of weave can be used.

how-to-use

Start with local machine:

func main() {
    w, err := NewWeaveNode("127.0.0.1",WithProxy(), WithPlugin())
	if err != nil {
		panic(err)
	}
	defer w.Close()
	
	if err = w.Launch(); err != nil {
		panic(err)
	}

	status, err := w.Status()
	if err != nil {
		panic(err)
	}
	fmt.Println(status.Overview)

	w.Stop()
}

Start with remote docker node:

func main() {
    w, err := NewWeaveNode("192.168.0.111", WithDockerPort(2375),
		WithTLS("./cacert.pem", "./cert.pem", "./key.pem"),
		WithProxy(), WithPlugin())
    if err != nil {
        panic(err)
    }
    defer w.Close()
    
    if err = w.Launch(); err != nil {
        panic(err)
    }
    
    status, err := w.Status()
    if err != nil {
        panic(err)
    }
    fmt.Println(status.Overview)
    
    w.Stop()
}

License

This repository is distributed under the Apache License Version 2.0 found in the LICENSE file.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CNIBuilder

type CNIBuilder struct {
	// contains filtered or unexported fields
}

func NewCNIBuilder

func NewCNIBuilder(cli *docker.Client, version string) *CNIBuilder

type Connection

type Connection struct {
	Outbound bool
	Address  string
	State    string
	NodeId   string
}

type ConnectionStatus

type ConnectionStatus struct {
	Outbound bool
	Address  string
	State    string
	Info     string
	Attrs    map[string]any
}

type DNSServer

type DNSServer struct {
	Address  string
	Search   string
	Disabled bool
	// contains filtered or unexported fields
}

func NewDNSServer

func NewDNSServer(address, search string, disabled bool) *DNSServer

type DNSStatus

type DNSStatus struct {
	Hostname    string
	Address     string
	ContainerId string
	Origin      string
}

type IPAMStatus

type IPAMStatus struct {
	IPAM string
}

type Option

type Option func(*Weave)

func NoDNS

func NoDNS() Option

func NoDiscovery

func NoDiscovery() Option

func NoFastdp

func NoFastdp() Option

func NoMulticastRoute

func NoMulticastRoute() Option

func NoRestart

func NoRestart() Option

func WithDNSAddress

func WithDNSAddress(address string) Option

func WithDockerPort

func WithDockerPort(port int) Option

func WithHost

func WithHost(host string) Option

func WithHostnameFromLabel

func WithHostnameFromLabel(labelKey string) Option

func WithHostnameMatch

func WithHostnameMatch(match string) Option

func WithHostnameReplacement

func WithHostnameReplacement(replacement string) Option

func WithHttpPort

func WithHttpPort(port int) Option

func WithIPRange

func WithIPRange(ipRange string) Option

func WithIpAllocDefaultSubnet

func WithIpAllocDefaultSubnet(ipRange string) Option

func WithLogLevel

func WithLogLevel(level string) Option

func WithName

func WithName(name string) Option

func WithNickname

func WithNickname(nickname string) Option

func WithPassword

func WithPassword(password string) Option

func WithPeers

func WithPeers(peers ...string) Option

func WithPlugin

func WithPlugin() Option

func WithPort

func WithPort(port int) Option

func WithProxy

func WithProxy() Option

func WithResume

func WithResume() Option

func WithStatusPort

func WithStatusPort(port int) Option

func WithTLS

func WithTLS(cacertPath, certPath, keyPath string) Option

func WithToken

func WithToken(token string) Option

func WithTrustedSubnets

func WithTrustedSubnets(cidrs string) Option

func WithVersion

func WithVersion(version string) Option

func WithWeaveMtu

func WithWeaveMtu(mtu int) Option

func WithoutDNS

func WithoutDNS() Option

type Overview

type Overview struct {
	Version string
	Router  struct {
		Protocol       string
		Name           string
		Encryption     string
		PeerDiscovery  string
		Targets        string
		Connections    string
		Peers          string
		TrustedSubnets string
	}
	IPAM struct {
		Status        string
		Range         string
		DefaultSubnet string
	}
	DNS struct {
		Domain   string
		Upstream string
		TTL      string
		Entries  string
	}
	Proxy struct {
		Address string
	}
	Plugin struct {
		DriverName string
	}
}

type PeerStatus

type PeerStatus struct {
	NodeId      string
	Connections []Connection
}

type Status

type Status struct {
	Overview    *Overview
	DNS         []DNSStatus
	Peers       []PeerStatus
	Connections []ConnectionStatus
	Targets     TargetStatus
	IPAM        IPAMStatus
}

type TargetStatus

type TargetStatus struct {
	// contains filtered or unexported fields
}

type Weave

type Weave struct {
	// contains filtered or unexported fields
}

func NewWeaveNode

func NewWeaveNode(address string, opts ...Option) (*Weave, error)

func (*Weave) AddContainerDNS

func (w *Weave) AddContainerDNS(containerId, fqdn string) error

func (*Weave) AddExternalDNS

func (w *Weave) AddExternalDNS(ip, fqdn string) error

func (*Weave) Attach

func (w *Weave) Attach(containerId string, withoutDNS, rewriteHost, noMulticastRoute bool, hosts []string, addr ...string) error

func (*Weave) Close

func (w *Weave) Close() error

func (*Weave) Connect

func (w *Weave) Connect(replace bool, peer ...string) error

func (*Weave) Detach

func (w *Weave) Detach(containerId string, addr ...string) error

func (*Weave) Expose

func (w *Weave) Expose(fqdn string, withoutMasquerade bool, addr ...string) ([]string, error)

func (*Weave) Forget

func (w *Weave) Forget(peer ...string) error

func (*Weave) Hide

func (w *Weave) Hide(addr ...string) ([]string, error)

func (*Weave) Launch

func (w *Weave) Launch() error

func (*Weave) LookupDNS

func (w *Weave) LookupDNS(hostname string) ([]string, error)

func (*Weave) Prime

func (w *Weave) Prime() error

func (*Weave) RemoveContainerDNS

func (w *Weave) RemoveContainerDNS(containerId string, fqdn ...string) error

func (*Weave) RemoveExternalDNS

func (w *Weave) RemoveExternalDNS(ip, fqdn string) error

func (*Weave) RemovePeer

func (w *Weave) RemovePeer(peers ...string) error

func (*Weave) Setup

func (w *Weave) Setup() error

func (*Weave) SetupCNI

func (w *Weave) SetupCNI() error

func (*Weave) Status

func (w *Weave) Status(subArgs ...string) (*Status, error)

func (*Weave) Stop

func (w *Weave) Stop() error

Jump to

Keyboard shortcuts

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