cherrypy

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2020 License: MIT Imports: 14 Imported by: 2

Documentation

Overview

Package cherrypy provides a client to integrate with Salt NetAPI's rest_cherrypy module https://docs.saltstack.com/en/latest/ref/netapi/all/salt.netapi.rest_cherrypy.html

Index

Constants

View Source
const (
	// LocalClient sends commands to Minions. Equivalent to the salt CLI command.
	LocalClient CommandClient = "local"

	// RunnerClient invokes runner modules on the Master.
	// Equivalent to the salt-run CLI command.
	RunnerClient = "runner"

	// WheelClient invokes wheel modules on the Master.
	// Wheel modules do not have a direct CLI equivalent
	WheelClient = "wheel"
)
View Source
const (
	// Glob Bash glob completion
	Glob TargetType = "glob"
	// PCRE Perl style regular expression
	PCRE = "pcre"
	// List Python list of hosts
	List = "list"
	// Grain Match based on a grain comparison
	Grain = "grain"
	// GrainPCRE Grain comparison with a regex
	GrainPCRE = "grain_pcre"
	// Pillar data comparison
	Pillar = "pillar"
	// PillarPCRE pillar data comparison with a regex
	PillarPCRE = "pillar_pcre"
	// NodeGroup Match on nodegroup
	NodeGroup = "nodegroup"
	// Range Use a Range server for matching
	Range = "range"
	// Compound a compound match string
	Compound = "compound"
	// IPCIDR match based on Subnet (CIDR notation) or IPv4 address.
	IPCIDR = "ipcidr"
)

Variables

View Source
var (
	// ErrorInvalidCredentials indicates authentication failed with 401 error.
	// Username, password or backend might be invalid.
	ErrorInvalidCredentials = errors.New("invalid credentials or authentication backend: %s")

	// ErrorNotAuthenticated indicates Logout() was called before authenticating with Salt
	ErrorNotAuthenticated = errors.New("not authenticated")
)
View Source
var (
	// ErrorMinionKeyNotFound indicates requested minion key does not exist on the master
	ErrorMinionKeyNotFound = errors.New("minion key was not found")

	// ErrorKeyPairNotReceived indicates master did not create a new key-pair.
	// This occurs if a key was already accepted by master for that particular minion
	// and the force argument was set to false
	ErrorKeyPairNotReceived = errors.New("public or private key was not received")

	// ErrorKeyPairBroken indicates the key-pair file received was broken
	ErrorKeyPairBroken = errors.New("cannot extract keypair from archive")
)
View Source
var (
	// ErrorJobNotFound indicates requested job was not found
	ErrorJobNotFound = errors.New("job was not found")
)
View Source
var (
	// ErrorMinionNotFound indicates that minion was not found on Salt Master
	ErrorMinionNotFound = errors.New("minion not found")
)

Functions

This section is empty.

Types

type AsyncMinionJobResult

type AsyncMinionJobResult struct {
	ID      string   `json:"jid"`
	Minions []string `json:"minions"`
}

AsyncMinionJobResult contains results of an async run with local client.

type Client

type Client struct {
	Address string
	Token   string
	// contains filtered or unexported fields
}

Client handles communication with NetAPI rest_cherrypy module (https://docs.saltstack.com/en/latest/ref/netapi/all/salt.netapi.rest_cherrypy.html)

Example usage:

client := cherrypy.NewClient("http://master:8000", "admin", "password", "pam")
if err := client.Login(); err != nil {
	return err
}
defer client.Logout()

minion := client.Minion("minion1")

func NewClient

func NewClient(address string, username string, password string, backend string, skipVerify bool) *Client

NewClient creates a new instance of client

address: URL of the cherrypy instance on a master (e.g.: https://salt-master:8000)
backend: External authentication (eauth) backend (https://docs.saltstack.com/en/latest/topics/eauth/index.html)

func (*Client) GenerateKeyPair

func (c *Client) GenerateKeyPair(ctx context.Context, id string, keySize int, force bool) (*MinionKeyPair, error)

GenerateKeyPair generates and auto-accepts minion keypair on the master.

If force argument is false and if the master already has keys for the minion; ErrorKeyPairNotReceived error will be returned.

If force argument is true; existing keys will be overwriten and new keys will be generated.

https://docs.saltstack.com/en/latest/ref/netapi/all/salt.netapi.rest_cherrypy.html#salt.netapi.rest_cherrypy.app.Keys.POST

func (*Client) Hook

func (c *Client) Hook(ctx context.Context, id string, data interface{}) error

Hook fires an event on Salt's event bus

All events are prefixed with salt/netapi/hook. Therefore if the id is set to "test"; Salt Reactor will receive "salt/netapi/hook/test" event.

https://docs.saltstack.com/en/latest/ref/netapi/all/salt.netapi.rest_cherrypy.html#salt.netapi.rest_cherrypy.app.Webhook.POST

func (*Client) Job

func (c *Client) Job(ctx context.Context, id string) (*JobDetails, error)

Job retrieves details of a single job

If the job was not found; ErrorJobNotFound will be returned.

https://docs.saltstack.com/en/latest/ref/netapi/all/salt.netapi.rest_cherrypy.html#get--jobs-(jid)

func (*Client) Jobs

func (c *Client) Jobs(ctx context.Context) ([]Job, error)

Jobs retrieves status of all jobs from Salt Master.

https://docs.saltstack.com/en/latest/ref/netapi/all/salt.netapi.rest_cherrypy.html#get--jobs-(jid)

func (*Client) Key

func (c *Client) Key(ctx context.Context, id string) (string, error)

Key returns public key of a single minion from master

If the minion is not found on the master ErrorMinionKeyNotFound error is returned.

https://docs.saltstack.com/en/latest/ref/netapi/all/salt.netapi.rest_cherrypy.html#salt.netapi.rest_cherrypy.app.Keys.GET

func (*Client) Login

func (c *Client) Login(ctx context.Context) error

Login establishes a session with rest_cherrypy and retrieves the token

https://docs.saltstack.com/en/latest/ref/netapi/all/salt.netapi.rest_cherrypy.html#login

func (*Client) Logout

func (c *Client) Logout(ctx context.Context) error

Logout terminates the session with rest_cherrypy and clears the token

Calls to logout will fail with ErrorNotAuthenticated if Login() was not called prior.

https://docs.saltstack.com/en/latest/ref/netapi/all/salt.netapi.rest_cherrypy.html#logout

func (*Client) Minion

func (c *Client) Minion(ctx context.Context, id string) (*Minion, error)

Minion retrieves grains of a single minion from Salt Master

If the minion is offline; grains will be empty. If the requested minion is not known by the master; ErrorMinionNotFound error will be thrown.

https://docs.saltstack.com/en/latest/ref/netapi/all/salt.netapi.rest_cherrypy.html#get--minions-(mid)

func (*Client) Minions

func (c *Client) Minions(ctx context.Context) ([]Minion, error)

Minions retrieves grains of all minions on a Salt Master

Grains will be empty for offline minions.

https://docs.saltstack.com/en/latest/ref/netapi/all/salt.netapi.rest_cherrypy.html#get--minions-(mid)

func (*Client) RunCommand

func (c *Client) RunCommand(ctx context.Context, cmd Command) (interface{}, error)

RunCommand runs a command on master using Run endpoint

https://docs.saltstack.com/en/latest/ref/netapi/all/salt.netapi.rest_cherrypy.html#salt.netapi.rest_cherrypy.app.Run

func (*Client) RunCommands

func (c *Client) RunCommands(ctx context.Context, cmds []Command) ([]interface{}, error)

RunCommands runs multiple commands on master using Run endpoint

https://docs.saltstack.com/en/latest/ref/netapi/all/salt.netapi.rest_cherrypy.html#salt.netapi.rest_cherrypy.app.Run

func (*Client) Stats

func (c *Client) Stats(ctx context.Context) (map[string]interface{}, error)

Stats retrieves CherryPy stats

https://docs.saltstack.com/en/latest/ref/netapi/all/salt.netapi.rest_cherrypy.html#stats

func (*Client) SubmitJob

func (c *Client) SubmitJob(ctx context.Context, job MinionJob) (*AsyncMinionJobResult, error)

SubmitJob submits a single job to be executed on minions asynchronously

https://docs.saltstack.com/en/latest/ref/netapi/all/salt.netapi.rest_cherrypy.html#salt.netapi.rest_cherrypy.app.Minions.POST

func (*Client) SubmitJobs

func (c *Client) SubmitJobs(ctx context.Context, jobs []MinionJob) ([]AsyncMinionJobResult, error)

SubmitJobs submits multiple jobs to be executed on minions asynchronously

https://docs.saltstack.com/en/latest/ref/netapi/all/salt.netapi.rest_cherrypy.html#salt.netapi.rest_cherrypy.app.Minions.POST

type Command

type Command struct {
	Client    CommandClient
	Target    Target
	Function  string
	Arguments map[string]interface{}
}

Command to send to Run endpont

type CommandClient

type CommandClient string

CommandClient indicates Salt API which client to use

https://docs.saltstack.com/en/latest/ref/netapi/all/salt.netapi.rest_cherrypy.html#usage

See the constants available in this file for possible values.

type ExpressionTarget

type ExpressionTarget struct {
	Expression string
	Type       TargetType
}

ExpressionTarget is used for almost all target types of SaltStack

func (ExpressionTarget) GetTarget

func (t ExpressionTarget) GetTarget() interface{}

GetTarget returns targets

func (ExpressionTarget) GetType

func (t ExpressionTarget) GetType() TargetType

GetType returns target type

type Job

type Job struct {
	ID          string
	Function    string
	Target      Target
	Arguments   []interface{}
	KWArguments map[string]interface{}
	StartTime   time.Time
	User        string
}

Job contains summary of a job returned by Jobs()

type JobDetails

type JobDetails struct {
	Job
	Minions []string
	Returns map[string]interface{}
}

JobDetails contain job summary and returns per minion

type KeyResult

type KeyResult struct {
	Local           []string `json:"local"`
	MinionsRejected []string `json:"minions_rejected"`
	MinionsDenied   []string `json:"minions_denied"`
	MinionsPre      []string `json:"minions_pre"`
	Minions         []string `json:"minions"`
}

KeyResult contains list of available keys on the master

type ListTarget

type ListTarget struct {
	// Targets contain list of minion ids
	Targets []string
}

ListTarget is for list target type of SaltStack

func (ListTarget) GetTarget

func (t ListTarget) GetTarget() interface{}

GetTarget returns targets

func (ListTarget) GetType

func (t ListTarget) GetType() TargetType

GetType returns target type

type Minion

type Minion struct {
	ID     string
	Grains map[string]interface{}
}

Minion information

type MinionJob

type MinionJob struct {
	Target      Target
	Function    string
	Arguments   []interface{}
	KWArguments map[string]interface{}
}

MinionJob contains job information to be sent to the minion

type MinionKeyPair

type MinionKeyPair struct {
	ID      string
	Public  string
	Private string
}

MinionKeyPair contains key-pair for a minion

type RequestError

type RequestError struct {
	StatusCode int
	Status     string
	Body       []byte
}

func (*RequestError) Error

func (e *RequestError) Error() string

type Target

type Target interface {
	GetTarget() interface{}
	GetType() TargetType
}

Target is an interface used in Command and MinionJob to target minions

type TargetType

type TargetType string

TargetType indicates Salt API which targing mode to use.

https://docs.saltstack.com/en/latest/ref/clients/index.html#salt.client.LocalClient.cmd https://docs.saltstack.com/en/latest/topics/targeting/index.html#advanced-targeting-methods

See the constants available in this file for possible values.

Jump to

Keyboard shortcuts

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