choria_registryclient

package
v0.28.0 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package choria_registryclient is an API client to the Choria Choria_registry agent Version 0.28.0.

Actions:

  • Names - List of all known DDLs for a specific plugin type
  • Ddl - Retrieve the DDL for a specific plugin

Index

Constants

View Source
const (
	// DisplayDDL shows results based on the configuration in the DDL file
	DisplayDDL = DisplayMode(iota)
	// DisplayOK shows only passing results
	DisplayOK
	// DisplayFailed shows only failed results
	DisplayFailed
	// DisplayAll shows all results
	DisplayAll
	// DisplayNone shows no results
	DisplayNone
)
View Source
const (
	// OK is the reply status when all worked
	OK = StatusCode(iota)

	// Aborted is status for when the action could not run, most failures in an action should set this
	Aborted

	// UnknownAction is the status for unknown actions requested
	UnknownAction

	// MissingData is the status for missing input data
	MissingData

	// InvalidData is the status for invalid input data
	InvalidData

	// UnknownError is the status general failures in agents should set when things go bad
	UnknownError
)

Variables

This section is empty.

Functions

func DDL

func DDL() (*agent.DDL, error)

DDL is a parsed and loaded DDL for the agent

func DDLBytes

func DDLBytes() ([]byte, error)

DDLBytes is the raw JSON encoded DDL file for the agent

Types

type BroadcastNS

type BroadcastNS struct {
	sync.Mutex
	// contains filtered or unexported fields
}

BroadcastNS is a NodeSource that uses the Choria network broadcast method to discover nodes

func (*BroadcastNS) Discover

func (b *BroadcastNS) Discover(ctx context.Context, fw inter.Framework, filters []FilterFunc) ([]string, error)

Discover performs the discovery of nodes against the Choria Network

func (*BroadcastNS) Reset

func (b *BroadcastNS) Reset()

Reset resets the internal node cache

type ChoriaRegistryClient

type ChoriaRegistryClient struct {
	sync.Mutex
	// contains filtered or unexported fields
}

ChoriaRegistryClient to the choria_registry agent

func Must

func Must(fw inter.Framework, opts ...InitializationOption) (client *ChoriaRegistryClient)

Must create a new client and panics on error

func New

func New(fw inter.Framework, opts ...InitializationOption) (client *ChoriaRegistryClient, err error)

New creates a new client to the choria_registry agent

func (*ChoriaRegistryClient) AgentMetadata

func (p *ChoriaRegistryClient) AgentMetadata() *Metadata

AgentMetadata is the agent metadata this client supports

func (*ChoriaRegistryClient) Ddl

func (p *ChoriaRegistryClient) Ddl(inputName string, inputPluginType string) *DdlRequester

Ddl performs the ddl action

Description: Retrieve the DDL for a specific plugin

Required Inputs:

  • name (string) - The name of the plugin
  • plugin_type (string) - The type of plugin

Optional Inputs:

  • format (string) - The result format the plugin should be retrieved in

func (*ChoriaRegistryClient) DiscoverNodes

func (p *ChoriaRegistryClient) DiscoverNodes(ctx context.Context) (nodes []string, err error)

DiscoverNodes performs a discovery using the configured filter and node source

func (*ChoriaRegistryClient) Names added in v0.25.0

func (p *ChoriaRegistryClient) Names(inputPluginType string) *NamesRequester

Names performs the names action

Description: List of all known DDLs for a specific plugin type

Required Inputs:

  • plugin_type (string) - The type of plugin

func (*ChoriaRegistryClient) OptionAgentFilter

func (p *ChoriaRegistryClient) OptionAgentFilter(a ...string) *ChoriaRegistryClient

OptionAgentFilter adds an agent filter

func (*ChoriaRegistryClient) OptionClassFilter

func (p *ChoriaRegistryClient) OptionClassFilter(f ...string) *ChoriaRegistryClient

OptionClassFilter adds a class filter

func (*ChoriaRegistryClient) OptionCollective

func (p *ChoriaRegistryClient) OptionCollective(c string) *ChoriaRegistryClient

OptionCollective sets the collective to target

func (*ChoriaRegistryClient) OptionCombinedFilter

func (p *ChoriaRegistryClient) OptionCombinedFilter(f ...string) *ChoriaRegistryClient

OptionCombinedFilter adds a combined filter

func (*ChoriaRegistryClient) OptionCompoundFilter

func (p *ChoriaRegistryClient) OptionCompoundFilter(f ...string) *ChoriaRegistryClient

OptionCompoundFilter adds a compound filter

func (*ChoriaRegistryClient) OptionDiscoveryTimeout

func (p *ChoriaRegistryClient) OptionDiscoveryTimeout(t time.Duration) *ChoriaRegistryClient

OptionDiscoveryTimeout configures the request discovery timeout, defaults to configured discovery timeout

func (*ChoriaRegistryClient) OptionExprFilter

func (p *ChoriaRegistryClient) OptionExprFilter(f string) *ChoriaRegistryClient

OptionExprFilter sets a filter expression that will remove results from the result set

func (*ChoriaRegistryClient) OptionFactFilter

func (p *ChoriaRegistryClient) OptionFactFilter(f ...string) *ChoriaRegistryClient

OptionFactFilter adds a fact filter

func (*ChoriaRegistryClient) OptionIdentityFilter

func (p *ChoriaRegistryClient) OptionIdentityFilter(f ...string) *ChoriaRegistryClient

OptionIdentityFilter adds an identity filter

func (*ChoriaRegistryClient) OptionInBatches

func (p *ChoriaRegistryClient) OptionInBatches(size int, sleep int) *ChoriaRegistryClient

OptionInBatches performs requests in batches

func (*ChoriaRegistryClient) OptionLimitMethod

func (p *ChoriaRegistryClient) OptionLimitMethod(m string) *ChoriaRegistryClient

OptionLimitMethod configures the method to use when limiting targets - "random" or "first"

func (*ChoriaRegistryClient) OptionLimitSeed

func (p *ChoriaRegistryClient) OptionLimitSeed(s int64) *ChoriaRegistryClient

OptionLimitSeed sets the random seed used to select targets when limiting and limit method is "random"

func (*ChoriaRegistryClient) OptionLimitSize

func (p *ChoriaRegistryClient) OptionLimitSize(s string) *ChoriaRegistryClient

OptionLimitSize sets limits on the targets, either a number of a percentage like "10%"

func (*ChoriaRegistryClient) OptionReplyTo

func (p *ChoriaRegistryClient) OptionReplyTo(t string) *ChoriaRegistryClient

OptionReplyTo sets a custom reply target

func (*ChoriaRegistryClient) OptionReset

func (p *ChoriaRegistryClient) OptionReset() *ChoriaRegistryClient

OptionReset resets the client options to use across requests to an empty list

func (*ChoriaRegistryClient) OptionTargets

func (p *ChoriaRegistryClient) OptionTargets(t []string) *ChoriaRegistryClient

OptionTargets sets specific node targets which would avoid discovery for all action calls until reset

func (*ChoriaRegistryClient) OptionWorkers

func (p *ChoriaRegistryClient) OptionWorkers(w int) *ChoriaRegistryClient

OptionWorkers sets how many worker connections should be started to the broker

type DdlOutput

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

DdlOutput is the output from the ddl action

func (*DdlOutput) Ddl

func (d *DdlOutput) Ddl() string

Ddl is the value of the ddl output

Description: The plugin DDL in the requested format

func (*DdlOutput) HashMap

func (d *DdlOutput) HashMap() map[string]any

HashMap is the raw output data

func (*DdlOutput) JSON

func (d *DdlOutput) JSON() ([]byte, error)

JSON is the JSON representation of the output data

func (*DdlOutput) Name

func (d *DdlOutput) Name() string

Name is the value of the name output

Description: The name of the plugin

func (*DdlOutput) ParseDdlOutput

func (d *DdlOutput) ParseDdlOutput(target any) error

ParseDdlOutput parses the result value from the Ddl action into target

func (*DdlOutput) PluginType

func (d *DdlOutput) PluginType() string

PluginType is the value of the plugin_type output

Description: The type of plugin

func (*DdlOutput) ResultDetails

func (d *DdlOutput) ResultDetails() *ResultDetails

ResultDetails is the details about the request

func (*DdlOutput) Version

func (d *DdlOutput) Version() string

Version is the value of the version output

Description: The version of the plugin

type DdlRequester

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

DdlRequester performs a RPC request to choria_registry#ddl

func (*DdlRequester) Do

func (d *DdlRequester) Do(ctx context.Context) (*DdlResult, error)

Do performs the request

func (*DdlRequester) Format

func (d *DdlRequester) Format(v string) *DdlRequester

Format is an optional input to the ddl action

Description: The result format the plugin should be retrieved in

type DdlResult

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

DdlResult is the result from a ddl action

func (*DdlResult) AllOutputs added in v0.26.0

func (d *DdlResult) AllOutputs() []*DdlOutput

AllOutputs provide access to all outputs

func (*DdlResult) EachOutput

func (d *DdlResult) EachOutput(h func(r *DdlOutput))

EachOutput iterates over all results received

func (*DdlResult) RenderResults

func (d *DdlResult) RenderResults(w io.Writer, format RenderFormat, displayMode DisplayMode, verbose bool, silent bool, colorize bool, log Log) error

func (*DdlResult) Stats

func (d *DdlResult) Stats() Stats

Stats is the rpc request stats

type DisplayMode

type DisplayMode uint8

DisplayMode overrides the DDL display hints

type ExternalNS

type ExternalNS struct {
	sync.Mutex
	// contains filtered or unexported fields
}

ExternalNS is a NodeSource that calls an external command for discovery

func (*ExternalNS) Discover

func (p *ExternalNS) Discover(ctx context.Context, fw inter.Framework, filters []FilterFunc) ([]string, error)

func (*ExternalNS) Reset

func (p *ExternalNS) Reset()

Reset resets the internal node cache

type FilterFunc

type FilterFunc func(f *protocol.Filter) error

FilterFunc can generate a Choria filter

type InitializationOption

type InitializationOption func(opts *initOptions)

InitializationOption is an optional setting used to initialize the client

func Discovery

func Discovery(ns NodeSource) InitializationOption

Discovery sets the NodeSource to use when finding nodes to manage

func DiscoveryMethod

func DiscoveryMethod(m string) InitializationOption

DiscoveryMethod accepts a discovery method name as supplied from the CLI and configures the correct NodeSource reverts to broadcast method if an unsupported method is supplied, custom node sources can be set using Discovery()

func DiscoveryTimeout

func DiscoveryTimeout(t time.Duration) InitializationOption

DiscoveryTimeout sets a timeout for discovery for those methods that support it

func Logger

Logger sets the logger to use else one is made via the Choria framework

func Progress

func Progress() InitializationOption

Progress enables displaying a progress bar

type Log

type Log interface {
	Debugf(format string, args ...any)
	Infof(format string, args ...any)
	Warnf(format string, args ...any)
	Errorf(format string, args ...any)
	Fatalf(format string, args ...any)
	Panicf(format string, args ...any)
}

type MetaNS

type MetaNS struct {
	// Options is the CLI options to discover based on
	Options *discovery.StandardOptions

	// Agent should be the agent the request is targeted at
	Agent string

	// DisablePipedDiscovery prevents the STDIN being used as a discovery source
	DisablePipedDiscovery bool

	sync.Mutex
	// contains filtered or unexported fields
}

MetaNS is a NodeSource that assists CLI tools in creating Choria standard command line based discovery.

func NewMetaNS

func NewMetaNS(opts *discovery.StandardOptions, enablePipeMode bool) *MetaNS

NewMetaNS creates a new meta discovery node source

func (*MetaNS) Discover

func (p *MetaNS) Discover(ctx context.Context, fw inter.Framework, _ []FilterFunc) ([]string, error)

Discover performs the discovery of nodes against the Choria Network.

func (*MetaNS) Reset

func (p *MetaNS) Reset()

Reset resets the internal node cache

type Metadata

type Metadata struct {
	License     string `json:"license"`
	Author      string `json:"author"`
	Timeout     int    `json:"timeout"`
	Name        string `json:"name"`
	Version     string `json:"version"`
	URL         string `json:"url"`
	Description string `json:"description"`
}

Metadata is the agent metadata

type NamesOutput added in v0.25.0

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

NamesOutput is the output from the names action

func (*NamesOutput) HashMap added in v0.25.0

func (d *NamesOutput) HashMap() map[string]any

HashMap is the raw output data

func (*NamesOutput) JSON added in v0.25.0

func (d *NamesOutput) JSON() ([]byte, error)

JSON is the JSON representation of the output data

func (*NamesOutput) Names added in v0.25.0

func (d *NamesOutput) Names() []any

Names is the value of the names output

Description: The names of all known DDL files

func (*NamesOutput) ParseNamesOutput added in v0.25.0

func (d *NamesOutput) ParseNamesOutput(target any) error

ParseNamesOutput parses the result value from the Names action into target

func (*NamesOutput) PluginType added in v0.25.0

func (d *NamesOutput) PluginType() string

PluginType is the value of the plugin_type output

Description: The type of plugin

func (*NamesOutput) ResultDetails added in v0.25.0

func (d *NamesOutput) ResultDetails() *ResultDetails

ResultDetails is the details about the request

type NamesRequester added in v0.25.0

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

NamesRequester performs a RPC request to choria_registry#names

func (*NamesRequester) Do added in v0.25.0

Do performs the request

type NamesResult added in v0.25.0

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

NamesResult is the result from a names action

func (*NamesResult) AllOutputs added in v0.26.0

func (d *NamesResult) AllOutputs() []*NamesOutput

AllOutputs provide access to all outputs

func (*NamesResult) EachOutput added in v0.25.0

func (d *NamesResult) EachOutput(h func(r *NamesOutput))

EachOutput iterates over all results received

func (*NamesResult) RenderResults added in v0.25.0

func (d *NamesResult) RenderResults(w io.Writer, format RenderFormat, displayMode DisplayMode, verbose bool, silent bool, colorize bool, log Log) error

func (*NamesResult) Stats added in v0.25.0

func (d *NamesResult) Stats() Stats

Stats is the rpc request stats

type NodeSource

type NodeSource interface {
	Reset()
	Discover(ctx context.Context, fw inter.Framework, filters []FilterFunc) ([]string, error)
}

NodeSource discovers nodes

type PuppetDBNS

type PuppetDBNS struct {
	sync.Mutex
	// contains filtered or unexported fields
}

PuppetDBNS is a NodeSource that uses the PuppetDB PQL Queries to discover nodes

func (*PuppetDBNS) Discover

func (p *PuppetDBNS) Discover(ctx context.Context, fw inter.Framework, filters []FilterFunc) ([]string, error)

Discover performs the discovery of nodes against the Choria Network

func (*PuppetDBNS) Reset

func (p *PuppetDBNS) Reset()

Reset resets the internal node cache

type RenderFormat

type RenderFormat int

RenderFormat is the format used by the RenderResults helper

const (
	// JSONFormat renders the results as a JSON document
	JSONFormat RenderFormat = iota

	// TextFormat renders the results as a Choria typical result set in line with choria req output
	TextFormat

	// TableFormat renders all successful responses in a table
	TableFormat

	// TXTFooter renders only the request summary statistics
	TXTFooter
)

type ResultDetails

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

ResultDetails is the details about a result

func (*ResultDetails) OK

func (d *ResultDetails) OK() bool

OK determines if the request was successful

func (*ResultDetails) Sender

func (d *ResultDetails) Sender() string

Sender is the identity of the remote that produced the message

func (*ResultDetails) StatusCode

func (d *ResultDetails) StatusCode() StatusCode

StatusCode is the status code produced by the remote

func (*ResultDetails) StatusMessage

func (d *ResultDetails) StatusMessage() string

StatusMessage is the status message produced by the remote

type Stats

type Stats interface {
	Agent() string
	Action() string
	All() bool
	NoResponseFrom() []string
	UnexpectedResponseFrom() []string
	DiscoveredCount() int
	DiscoveredNodes() *[]string
	FailCount() int
	OKCount() int
	ResponsesCount() int
	PublishDuration() (time.Duration, error)
	RequestDuration() (time.Duration, error)
	DiscoveryDuration() (time.Duration, error)
	OverrideDiscoveryTime(start time.Time, end time.Time)
	UniqueRequestID() string
}

Stats are the statistics for a request

type StatusCode

type StatusCode uint8

StatusCode is a reply status as defined by MCollective SimpleRPC - integers 0 to 5

See the constants OK, RPCAborted, UnknownRPCAction, MissingRPCData, InvalidRPCData and UnknownRPCError

Jump to

Keyboard shortcuts

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