client

package
v0.0.0-...-84310d3 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2020 License: Apache-2.0 Imports: 17 Imported by: 4

Documentation

Overview

Package client is the Go runtime for Watermelon modules.

A module is an executable that connects to the Watermelon GRPC server and accepts commands from the server. The commands are usually requests to execute a function. To execute these functions, the module must publish them before connecting the server. This is done in the module main:

package main

import (
  "os"
  "github.com/bserdar/watermelon/client"
)

func main() {
  f := client.Functions{}
  f.Add("db.Bootstrap", dbBootstrap)
  f.Add("db.Config", dbConfig)

  f.Add("controller.Bootstrap", controllerBootstrap)

  client.Run(os.Args[1:], f, nil)
}

The above main declares three functions, assigns them to Go functions and calls the client runtime with program arguments. The program arguments will contain the Watermelon server address, and optional `--log loglevel` argument. The client runtime connect the server, accepts function call requests and dispatches them. The runtime also deals with requests made from within this module, such as calling other modules, or calling the server to get inventory/host information, or to run a command on a remote host.

In addition to registering functions as above, this runtime allows publishing functions as part of a GRPC server as well. You can implement the module as a GRPC server, and publish the server as follows:

package main

import (
	"os"

  grpc "google.golang.org/grpc"

  "github.com/bserdar/watermelon/client"
  "github.com/bserdar/watermelon/modules/pkg/yum"
)

func main() {
  yumServer := yum.Server{}
  client.Run(os.Args[1:], nil, func(server *grpc.Server, rt *client.Runtime) {
    // Notify the runtime that there is a GRPC server for "yum"
    rt.RegisterGRPCServer(&yumServer, "yum")
    // Register the server
    yum.RegisterYumServer(server, yumServer)
  })
}

The published functions are called with a client session, and arguments. The arguments is a JSON document containing the arguments to the function. When completed, the function returns a JSON document containing the response, and an optional error. The function should either return a non-nil response, or a non-nil error, or both nils.

func dbBootstrap(session *client.Session, args[]byte) (output []byte,error) {
}

The Go client runtime has a function wrapper for convenience, so you can declare functions also as follows:

// Does not get any arguments, does not return an output or error
func dbBootstrap(session *client.Session) {
}

// Accepts arguments in a InStruct, and returns the output in OutStruct. The
// wrapper unmarshals input arguments into InStruct, and marshals the output
// to OutStruct
func dbBootstrap(session *client.Session,in InStruct) OutStruct {
}

// No input/output, but may return error
func dbBootstrap(client *client.Session) error {
}

If the service is registered as a GRPC service, the functions are regular GRPC functions that return ModuleResponse:

// Yum update GRPC function
func (s Server) Update(ctx context.Context, req *PackageParams) (*module.Response, error) {
}

If a module publishes GRPC functions, those functions can be called from other modules via GRPC, or by calling session.Call. If the module published functions without GRPC, then only session.Call can be used to call them.

Index

Constants

View Source
const LocalhostID = "localhost"

LocalhostID is the localhost

Variables

View Source
var AllHosts = "all"

AllHosts of the inventory

Functions

func Export

func Export(name string, function interface{}) int

Export can be used to register a function as an anonymous variable

var _ = client.Export("myFunc",myFunc)

func myFunc() {
}

func Flags

func Flags() *flag.FlagSet

Flags returns the flagset

func Run

func Run(args []string, funcs Functions, registerGRPCServers func(*grpc.Server, *Runtime))

Run creates a runtime and runs it

func Wrap

func Wrap(in interface{}) func(*Session, []byte) ([]byte, error)

Wrap wraps a function and translates json input/output for the wrapped function. The input function must be of the form:

in func(*Session,InStruct) (OutStruct,error)
in func(*Session,InStruct) error
in func(*Session,InStruct)
in func(*Session)

InStruct and OutStruct are public structs. Wrap translates the input to InStruct, calls the function, and then translates the OutStruct to byte array. If either in or outstruct are []byte, they are untranslated. If the function returns only error, or nothing, those are passed as nil

Types

type Args

type Args map[string]interface{}

Args can be used to pass values to a function

type CmdResponse

type CmdResponse struct {
	Stdout   []byte
	Stderr   []byte
	ExitCode int
}

CmdResponse is a command response

func (CmdResponse) AllOut

func (c CmdResponse) AllOut() string

AllOut returns the stdout + stderr

func (CmdResponse) Err

func (c CmdResponse) Err() string

Err returns the stderr

func (CmdResponse) Out

func (c CmdResponse) Out() string

Out returns the stdout

type CommandError

type CommandError struct {
	Host string
	Msg  string
}

CommandError is an error message from a host

func (CommandError) Error

func (c CommandError) Error() string

Error returns host: msg

type CommonFileInfo

type CommonFileInfo struct {
	FileName    string
	FileSize    int64
	FileMode    os.FileMode
	FileModTime time.Time
	FileIsDir   bool
}

CommonFileInfo is an os.FileInfo

func (CommonFileInfo) IsDir

func (c CommonFileInfo) IsDir() bool

IsDir returns true if this is a directory

func (CommonFileInfo) ModTime

func (c CommonFileInfo) ModTime() time.Time

ModTime returns the file modification time

func (CommonFileInfo) Mode

func (c CommonFileInfo) Mode() os.FileMode

Mode returns the file mode

func (CommonFileInfo) Name

func (c CommonFileInfo) Name() string

Name returns the file name

func (CommonFileInfo) Size

func (c CommonFileInfo) Size() int64

Size returns the file size

func (CommonFileInfo) Sys

func (c CommonFileInfo) Sys() interface{}

Sys returns nil

type Ensure

type Ensure struct {
	Mode  *int
	UID   string
	GID   string
	User  string
	Group string
	Dir   *bool
}

Ensure describes the attributes of a file/directory

func (Ensure) EnsureDir

func (e Ensure) EnsureDir() Ensure

EnsureDir returns a copy of e with dir flag set

func (Ensure) EnsureMode

func (e Ensure) EnsureMode(mode int) Ensure

EnsureMode returns a copy of e with mode set

type FileOwner

type FileOwner struct {
	OwnerName string
	OwnerID   string
	GroupName string
	GroupID   string
}

FileOwner contains owner information

type Functions

type Functions map[string]func(*Session, []byte) ([]byte, error)

Functions are used to keep track of the registered functions

func (Functions) Add

func (f Functions) Add(name string, function interface{})

Add adds a new function to the functions list

type GRPCServer

type GRPCServer struct {
	RT *Runtime
}

GRPCServer has the dispatch function that helps implement expose functions as GRPC functions. Embed GRPCServer to implement a custom GRPC server for a module.

type MyServer struct {
   client.GRPCServer
}

func (s MyServer) Function(req *Request) (*Response,errror) {
   var out Response
   err:=s.Dispatch(req.SessionID,function,*req,&out)
   if err!=nil {
      return nil,err
   }
   return &out, nil
}

func (GRPCServer) Dispatch

func (s GRPCServer) Dispatch(sessionID string, f, input, output interface{}) error

Dispatch calls f

func (*GRPCServer) GetSession

func (s *GRPCServer) GetSession(ID string) *Session

GetSession returns a session with the given ID

func (GRPCServer) SessionFromContext

func (s GRPCServer) SessionFromContext(ctx context.Context) *Session

SessionFromContext retrieves the session from the GRPC context on the receiving end of a GRPC call

type HasAllLabels

type HasAllLabels struct {
	Labels []string
}

HasAllLabels is a selector that selects hosts containing all the labels

func Has

func Has(label string) HasAllLabels

Has returns a selector that selects hosts containing label

func HasAllOf

func HasAllOf(label ...string) HasAllLabels

HasAllOf returns a selector that selects hosts containing all of the labels

type HasAnyLabel

type HasAnyLabel struct {
	Labels []string
}

HasAnyLabel is a selector that selects hosts containing any of the labels

func HasAnyOf

func HasAnyOf(label ...string) HasAnyLabel

HasAnyOf returns a selector that selects hosts containing any of the labels

type HasNoneLabels

type HasNoneLabels struct {
	Labels []string
}

HasNoneLabels is a selector that selects hosts containing none of the labels

func HasNoneOf

func HasNoneOf(label ...string) HasNoneLabels

HasNoneOf returns a selector that selects hosts containing none of the labels

type Host

type Host struct {
	S  *Session
	ID string
}

Host encapsulates a single host

func (Host) Chmod

func (h Host) Chmod(path string, mode int) error

Chmod runs chmod on host. Returns OS error msg

func (Host) Chown

func (h Host) Chown(path string, user, group string) error

Chown runs chown on host. Returns OS error msg

func (Host) Command

func (h Host) Command(cmd string) CmdResponse

Command executes a command on the host

func (Host) CommandMayFail

func (h Host) CommandMayFail(cmd string) (CmdResponse, error)

CommandMayFail returns error if command fails, instead of panicking

func (Host) Commandf

func (h Host) Commandf(format string, args ...interface{}) CmdResponse

Commandf executes a command on the host

func (Host) CopyFromLocal

func (h Host) CopyFromLocal(fromPath, toPath string) error

CopyFromLocal copies a file from local to host

func (Host) CopyFromLocalIfDifferent

func (h Host) CopyFromLocalIfDifferent(fromPath, toPath string) (bool, error)

CopyFromLocalIfDifferent copies a file from local to h if different

func (Host) Ensure

func (h Host) Ensure(path string, req Ensure) bool

Ensure a file has certain attributes. Returns true if things changed

func (Host) Exists

func (h Host) Exists(path string) bool

Exists returns true if path exists

func (Host) GetCfg

func (h Host) GetCfg(path string, out interface{})

GetCfg retrieves a configuration ite pointed to by path, a JSON pointer, and unmarshals the JSON to out

func (Host) GetCfgJSON

func (h Host) GetCfgJSON(path string) []byte

GetCfgJSON retrieves a configuration item pointed to by path, a JSON pointer, and returns the JSON for it. It looks at host first, and if item is not found there, it looks at global configuration

func (Host) GetFileInfo

func (h Host) GetFileInfo(path string) (os.FileInfo, FileOwner)

GetFileInfo retrieves file information

func (Host) GetInfo

func (h Host) GetInfo() pb.HostInfo

GetInfo returns host info. Panics on invalid host

func (Host) HasLabel

func (h Host) HasLabel(label string) bool

HasLabel returns if the host has the label

func (Host) Logf

func (h Host) Logf(format string, args ...interface{})

Logf logs a message

func (Host) MarshalJSON

func (h Host) MarshalJSON() ([]byte, error)

MarshalJSON writes out the ID

func (Host) Mkdir

func (h Host) Mkdir(path string) error

Mkdir creates a dir. Returns OS error msg

func (Host) ReadFile

func (h Host) ReadFile(file string) (os.FileInfo, []byte)

ReadFile reads from a remote file

func (Host) String

func (h Host) String() string

func (Host) WaitHost

func (h Host) WaitHost(timeout time.Duration) error

WaitHost waits until host becomes available

func (Host) WriteFile

func (h Host) WriteFile(file string, perms os.FileMode, data []byte) error

WriteFile writes a file to a remote host

func (Host) WriteFileFromTemplate

func (h Host) WriteFileFromTemplate(file string, perms os.FileMode, template string, templateData interface{}) (bool, error)

WriteFileFromTemplate writes a file to a remote host based on a template. TemplateData is marshaled in JSON

func (Host) WriteFileFromTemplateFile

func (h Host) WriteFileFromTemplateFile(file string, perms os.FileMode, templateFile string, templateData interface{}) (bool, error)

WriteFileFromTemplateFile writes a file to a remote host based on a template file on localhost. TemplateData is marshaled in JSON

func (Host) WriteFileIfDifferent

func (h Host) WriteFileIfDifferent(file string, perms os.FileMode, data []byte) (bool, error)

WriteFileIfDifferent writes a file to a remote host if writing changes the file

type Inventory

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

Inventory is the inventory runtime implementation for clients

func (Inventory) Add

func (inv Inventory) Add(session string, to string, hosts []string) (string, error)

Add adds new hosts to the given inventory, and returns the new inventory ID

func (Inventory) GetHostIDs

func (inv Inventory) GetHostIDs(session string, invID string) ([]string, error)

GetHostIDs returns the host IDs included in the inventory

func (Inventory) GetHostInfo

func (inv Inventory) GetHostInfo(session string, IDs []string) ([]*pb.HostInfo, error)

GetHostInfo returns the host information for the given hosts

func (Inventory) GetHosts

func (inv Inventory) GetHosts(session string, invID string) ([]*pb.HostInfo, error)

GetHosts returns hosts in an inventory

func (Inventory) Make

func (inv Inventory) Make(session string, from []string) (string, error)

Make creates a new inventory from the given host IDs

func (Inventory) Release

func (inv Inventory) Release(session string, id string)

Release notifies the server that the inventory is no longer needed, and can be freed

func (Inventory) Select

func (inv Inventory) Select(session string, from string, what ...Selector) (string, error)

Select a subset of an inventory based on the given criteria, and returns a new inventory id representing the subset

func (Inventory) Union

func (inv Inventory) Union(session string, what []string) (string, error)

Union combines inventories to build a new host set containing all the hosts in the sources

type KeyAndValues

type KeyAndValues struct {
	Key    string
	Values []string
}

KeyAndValues contains a property key, and a set of values one of which should match

type Remote

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

Remote is the remote runtime implementation for clients

func (Remote) Chmod

func (r Remote) Chmod(session string, hostID string, path string, mode int) (*pb.CommandError, error)

Chmod runs chmod on host

func (Remote) Chown

func (r Remote) Chown(session string, hostID string, path string, user, group string) (*pb.CommandError, error)

Chown runs chown on host

func (Remote) Command

func (r Remote) Command(session string, hostID string, cmd string) (CmdResponse, error)

Command executes a command on a host

func (Remote) Commandf

func (r Remote) Commandf(session string, hostID string, format string, args ...interface{}) (CmdResponse, error)

Commandf executes a command on a host

func (Remote) CopyFile

func (r Remote) CopyFile(session string, from string, fromPath string, to string, toPath string, onlyIfDifferent bool) (bool, error)

CopyFile copies a file

func (Remote) Ensure

func (r Remote) Ensure(session string, hostID string, path string, req Ensure) (bool, error)

Ensure a file has certain attributes

func (Remote) GetFileInfo

func (r Remote) GetFileInfo(session string, hostID string, path string) (os.FileInfo, FileOwner, error)

GetFileInfo retrieves file information

func (Remote) Mkdir

func (r Remote) Mkdir(session string, hostID string, path string) (*pb.CommandError, error)

Mkdir creates a dir

func (Remote) ReadFile

func (r Remote) ReadFile(session string, hostID string, file string) (os.FileInfo, []byte, error)

ReadFile reads from a remote file

func (Remote) WaitHost

func (r Remote) WaitHost(session string, hostID string, timeout time.Duration) error

WaitHost waits until host becomes available

func (Remote) WriteFile

func (r Remote) WriteFile(session string, hostID string, file string, perms os.FileMode, data []byte, onlyIfDifferent bool) (bool, *pb.CommandError, error)

WriteFile writes a file to a remote host

func (Remote) WriteFileFromTemplate

func (r Remote) WriteFileFromTemplate(session string, hostID string, file string, perms os.FileMode, template string, templateData interface{}, onlyIfDifferent bool) (bool, *pb.CommandError, error)

WriteFileFromTemplate writes a file to a remote host based on a template. TemplateData is marshaled in JSON

type Runtime

type Runtime struct {
	Port       int
	Worker     WorkServer
	Inv        Inventory
	Rmt        Remote
	ClientConn *grpc.ClientConn
	LCClient   pb.LifecycleClient
}

Runtime is the client runtime to be used by module implementations.

func NewRuntime

func NewRuntime(server string, listener net.Listener, funcs Functions, registerGRPCServers func(*grpc.Server, *Runtime)) (*Runtime, error)

NewRuntime creates a new runtime with the given server connection. It creates a server on the client side using localhost:myport. The server must be of the form host:port

func (*Runtime) Call

func (rt *Runtime) Call(session, module, function string, data interface{}) (*pb.Response, error)

Call calls another module

func (*Runtime) ConnectModule

func (rt *Runtime) ConnectModule(module string) (*grpc.ClientConn, error)

ConnectModule loads a module and returns a client connection to it

func (*Runtime) GetArgs

func (rt *Runtime) GetArgs(session string) []string

func (*Runtime) GetCfg

func (rt *Runtime) GetCfg(session, path string, out interface{}) error

GetCfg retrieves a configuration ite pointed to by path, a JSON pointer, and unmarshals the JSON to out

func (*Runtime) GetCfgJSON

func (rt *Runtime) GetCfgJSON(session, path string) ([]byte, error)

GetCfgJSON retrieves a configuration item pointed to by path, a JSON pointer, and returns the JSON for it.

func (*Runtime) GetHostCfg

func (rt *Runtime) GetHostCfg(session, host, path string, out interface{}) error

GetHostCfg retrieves a configuration ite pointed to by path, a JSON pointer, and unmarshals the JSON to out. It looks at host specific configuration first, and then the global configuration

func (*Runtime) GetHostCfgJSON

func (rt *Runtime) GetHostCfgJSON(session, host, path string) ([]byte, error)

GetHostCfgJSON retrieves a host-specific configuration item pointed to by path, a JSON pointer, and returns the JSON for it. If the host does not have the configuration item, this looks at the global configuration

func (*Runtime) LoadModule

func (rt *Runtime) LoadModule(name string) (string, error)

LoadModule loads a module and returns its GRPC address

func (*Runtime) Logf

func (rt *Runtime) Logf(session string, hostID string, format string, args ...interface{})

Logf writes a log message for the host

func (*Runtime) Printf

func (rt *Runtime) Printf(session string, format string, args ...interface{})

Printf prints a message

func (*Runtime) RegisterGRPCServer

func (rt *Runtime) RegisterGRPCServer(server grpcServer, funcNamePrefix string)

RegisterGRPCServer registers a GRPC server with the runtime so its methods can be exposed as funcNamePrefix.MethodName

func (*Runtime) Session

func (rt *Runtime) Session(id string) *Session

Session returns a new session

func (*Runtime) Start

func (rt *Runtime) Start() error

Start the runtime lifecycle and all the servers associated with it. This does not return until the lifecycle ends

type SelectByAllProperty

type SelectByAllProperty struct {
	All []KeyAndValues
}

SelectByAllProperty is a selector that selects hosts having all the given properties

func WithAllProperty

func WithAllProperty(kv ...KeyAndValues) SelectByAllProperty

WithAllProperty returns a selector that selects hosts containing all given properties

type SelectByAnyProperty

type SelectByAnyProperty struct {
	Any []KeyAndValues
}

SelectByAnyProperty is a selector that selects hosts having any of the given properties

func WithAnyProperty

func WithAnyProperty(kv ...KeyAndValues) SelectByAnyProperty

WithAnyProperty returns a selector that selects hosts containing any of the given properties

type SelectByID

type SelectByID struct {
	IDs []string
}

SelectByID is a selector that selects hosts by ID

func WithIds

func WithIds(id ...string) SelectByID

WithIds returns a selector that selects hosts by ID

type SelectByName

type SelectByName struct {
	Names []string
}

SelectByName is a selector that selects hosts by name

func WithNames

func WithNames(name ...string) SelectByName

WithNames returns a selector that selects hosts by name

type Selector

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

type Session

type Session struct {
	Rt       *Runtime
	ID       string
	Modified bool
}

Session represents a client session. All session functions will panic if there is an error

func (Session) Add

func (s Session) Add(to string, hosts []string) string

Add adds new hosts to the given inventory, and returns the new inventory ID

func (*Session) Call

func (s *Session) Call(module, function string, data interface{}) *pb.Response

Call calls another module

func (*Session) Chmod

func (s *Session) Chmod(hostID string, path string, mode int) error

Chmod runs chmod on host. Returns OS error msg

func (*Session) Chown

func (s *Session) Chown(hostID string, path string, user, group string) error

Chown runs chown on host. Returns OS error msg

func (Session) Command

func (s Session) Command(hostID string, cmd string) CmdResponse

Command executes a command on a host

func (Session) CommandMayFail

func (s Session) CommandMayFail(hostID string, cmd string) (CmdResponse, error)

CommandMayFail returns error if command fails, instead of panicking

func (Session) Commandf

func (s Session) Commandf(hostID string, format string, args ...interface{}) CmdResponse

Commandf executes a command on a host

func (*Session) ConnectModule

func (s *Session) ConnectModule(module string) (*grpc.ClientConn, error)

ConnectModule loads a module and returns a client connection to it

func (*Session) Context

func (s *Session) Context() context.Context

Context returns a context to be used in GRPC calls. The returned contex contains the session ID as metadata

func (*Session) CopyFile

func (s *Session) CopyFile(from string, fromPath string, to string, toPath string) error

CopyFile copies a file

func (*Session) CopyFromLocal

func (s *Session) CopyFromLocal(fromPath string, to string, toPath string) error

CopyFromLocal copies a file from localhost

func (*Session) CopyFromLocalIfDifferent

func (s *Session) CopyFromLocalIfDifferent(fromPath string, to string, toPath string) (bool, error)

CopyFromLocalIfDifferent copies a file from localhost if different

func (*Session) CopyIfDifferent

func (s *Session) CopyIfDifferent(from string, fromPath string, to string, toPath string) (bool, error)

CopyIfDifferent copies a file if it is different in destination

func (*Session) Ensure

func (s *Session) Ensure(hostID string, path string, req Ensure) bool

Ensure a file has certain attributes. Returns true if things changed

func (*Session) Exists

func (s *Session) Exists(hostID string, path string) bool

Exists returns true if path is a file or dir

func (*Session) ForAll

func (s *Session) ForAll(inv string, f func(Host) error) bool

ForAll runs f for all hosts in inv. Returns true if everything is fine.

func (*Session) ForAllSelected

func (s *Session) ForAllSelected(sel Selector, f func(Host) error) bool

ForAllSelected selects hosts mathcing the selector from all hosts, and call f for each

func (*Session) ForAllSerial

func (s *Session) ForAllSerial(inv string, f func(Host) error) bool

ForAllSerial runs f for all hosts in inv one by one. Returns true if everything is fine.

func (Session) GetArgs

func (s Session) GetArgs() []string

GetArgs returns args to the main program

func (Session) GetCfg

func (s Session) GetCfg(path string, out interface{})

GetCfg retrieves a configuration ite pointed to by path, a JSON pointer, and unmarshals the JSON to out

func (Session) GetCfgJSON

func (s Session) GetCfgJSON(path string) []byte

GetCfgJSON retrieves a configuration item pointed to by path, a JSON pointer, and returns the JSON for it.

func (*Session) GetFileInfo

func (s *Session) GetFileInfo(hostID string, path string) (os.FileInfo, FileOwner)

GetFileInfo retrieves file information

func (Session) GetHostCfg

func (s Session) GetHostCfg(host, path string, out interface{})

GetHostCfg retrieves a configuration ite pointed to by path, a JSON pointer, and unmarshals the JSON to out. It looks at the host configuration first, and if it is not found there, it looks at the global configuration

func (Session) GetHostCfgJSON

func (s Session) GetHostCfgJSON(host, path string) []byte

GetHostCfgJSON retrieves a configuration item pointed to by path, a JSON pointer, and returns the JSON for it. It looks at the host configuration first, and if not found there, looks at the global configuration

func (Session) GetHostIDs

func (s Session) GetHostIDs(invID string) []string

GetHostIDs returns the host IDs included in the inventory

func (Session) GetHostInfo

func (s Session) GetHostInfo(IDs []string) []*pb.HostInfo

GetHostInfo returns the host information for the given hosts

func (Session) GetHosts

func (s Session) GetHosts(invID string) []*pb.HostInfo

GetHosts returns hosts in an inventory

func (*Session) Host

func (s *Session) Host(h string) Host

Host returns a host object tied to this session

func (*Session) LoadModule

func (s *Session) LoadModule(module string) (string, error)

LoadModule loads a module and returns its GRPC location

func (Session) Logf

func (s Session) Logf(hostID string, format string, args ...interface{})

Logf logs a message

func (Session) Make

func (s Session) Make(from []string) string

Make creates a new inventory from the given host IDs

func (*Session) Mkdir

func (s *Session) Mkdir(hostID string, path string) error

Mkdir creates a dir. Returns OS error msg

func (Session) Printf

func (s Session) Printf(format string, args ...interface{})

Printf prints a message

func (Session) ReadFile

func (s Session) ReadFile(hostID string, file string) (os.FileInfo, []byte)

ReadFile reads from a remote file

func (Session) Release

func (s Session) Release(id string)

Release notifies the server that the inventory is no longer needed, and can be freed

func (Session) Select

func (s Session) Select(from string, what ...Selector) string

Select a subset of an inventory based on the given criteria, and returns a new inventory id representing the subset

func (Session) Union

func (s Session) Union(what []string) string

Union combines inventories to build a new host set containing all the hosts in the sources

func (*Session) WaitHost

func (s *Session) WaitHost(hostID string, timeout time.Duration) error

WaitHost waits until host becomes available

func (*Session) WriteFile

func (s *Session) WriteFile(hostID string, file string, perms os.FileMode, data []byte) error

WriteFile writes a file to a remote host

func (*Session) WriteFileFromTemplate

func (s *Session) WriteFileFromTemplate(hostID string, file string, perms os.FileMode, template string, templateData interface{}) (bool, error)

WriteFileFromTemplate writes a file to a remote host based on a template. TemplateData is marshaled in JSON

func (*Session) WriteFileFromTemplateFile

func (s *Session) WriteFileFromTemplateFile(hostID string, file string, perms os.FileMode, templateFile string, templateData interface{}) (bool, error)

WriteFileFromTemplateFile writes a file to a remote host based on a template file loaded from localhost. TemplateData is marshaled in JSON

func (*Session) WriteFileIfDifferent

func (s *Session) WriteFileIfDifferent(hostID string, file string, perms os.FileMode, data []byte) (bool, error)

WriteFileIfDifferent writes a file to a remote host if writing changes the file

type WorkServer

type WorkServer struct {
	Functions Functions
	Server    *grpc.Server
	Listener  net.Listener
	// contains filtered or unexported fields
}

WorkServer contains the functions defined in this module

func (*WorkServer) Process

func (w *WorkServer) Process(ctx context.Context, req *pb.Request) (returnResponse *pb.Response, e error)

Process calls the function

func (*WorkServer) Start

func (w *WorkServer) Start() error

Start starts the work server. It doesn't return until the listener is closed

func (*WorkServer) Stop

func (w *WorkServer) Stop()

Stop the listener

Jump to

Keyboard shortcuts

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