vppagenthelper

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2020 License: Apache-2.0 Imports: 9 Imported by: 0

README

vpp-agent provides a convenient GRPC API for vpp.

vppagenthelper is a simple tool to make it easy to run a (vpp-agent,vpp) pair from your go code.

import (
   "github.com/edwarnicke/vppagenthelper"
   "go.ligato.io/vpp-agent/v3/proto/ligato/configurator"
)

ctx,cancel := context.WithCancel(context.Background())

// Runs an instance of vpp and vpp-agent, returning a grpc.ClientConnInterface (cc) connected to the started vpp-agent
// and an errCh that will receive any errors.
cc, errCh := vppagenthelper.StartAndDialContext(ctx)

// An error may already be in channel on launch, otherwise errCh
// will be closed when vpp and vpp-agent have both exited
select {
case err := <-errCh:
    logrus.Fatal(err)
default:
}

client := configurator.NewConfiguratorServiceClient(cc)

// Stop vpp and vpp-agent
cancel()
// Block till they have exited
<-errCh

Options

Both vpp and vpp-agent have default notions of where various config files and socket files should live. If you wish to start more than one instance of vpp-agent, you will need to place them under an alternate rootDir. This can be done with vppagenthelper.Options

import (
    "github.com/phayes/freeport"
    "github.com/edwarnicke/vppagenthelper"
)

rootDir, err = ioutil.TempDir("", "vppagent-")
grpcPort, err := freeport.GetFreePort()
httpPort, err := freeport.GetFreePort()
f.Require().NoError(err)
cc, errCh = vppagenthelper.StartAndDialContext(
    f.ctx,
    vppagenthelper.WithRootDir(rootDir),
    vppagenthelper.WithGrpcPort(grpcPort),
    vppagenthelper.WithHTTPPort(httpPort),
)

Using vppctl with an alternate rootDir

To use vppctl when using an alternate rootDir run:

vppctl -s ${ROOTDIR}/var/run/vpp/cli.sock ${normal cmds}

Using agentctl with an alternate rootDir

To use agentctl when using an alternate rootDir run:

agentctl --http-port ${HTTP_PORT}

Documentation

Overview

Package vppagenthelper provides a simple StartAndDialContext function that will start up a local vppagent, dial it, and return the grpc.ClientConnInterface

Index

Constants

View Source
const (
	// DefaultRootDir - Default value for RootDir
	DefaultRootDir = ""
	// DefaultGrpcPort - Default value for GRPC port
	DefaultGrpcPort = 9111
	// DefaultHTTPPort - Default value for HTTP port
	DefaultHTTPPort = 9191
)

Variables

This section is empty.

Functions

func StartAndDialContext

func StartAndDialContext(ctx context.Context, opts ...Option) (vppagentCC grpc.ClientConnInterface, errCh chan error)

StartAndDialContext - starts vppagent (and vpp), dials them using any provided options and returns the resulting grpc.ClientConnInterface, and an error chan that will receive the error from the lifecycle of the vppagent and vpp and be closed when both have exited. Stdout and Stderr for the vppagent and vpp are set to be log.Entry(ctx).Writer().

Types

type Option

type Option func(opt *option)

Option - Option for use with vppagent.Start(...)

func WithGrpcPort

func WithGrpcPort(grpcPort int) Option

WithGrpcPort - set the grpc port for vppagent to listen on

func WithHTTPPort

func WithHTTPPort(httpPort int) Option

WithHTTPPort - set the http port for vppagent to listen on

func WithRootDir

func WithRootDir(rootDir string) Option

WithRootDir - set a root dir (usually a tmpDir) for all conf files.

Jump to

Keyboard shortcuts

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