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
- Variables
- type AsyncMinionJobResult
- type Client
- func (c *Client) GenerateKeyPair(ctx context.Context, id string, keySize int, force bool) (*MinionKeyPair, error)
- func (c *Client) Hook(ctx context.Context, id string, data interface{}) error
- func (c *Client) Job(ctx context.Context, id string) (*JobDetails, error)
- func (c *Client) Jobs(ctx context.Context) ([]Job, error)
- func (c *Client) Key(ctx context.Context, id string) (string, error)
- func (c *Client) Keys(ctx context.Context) (*KeyResult, error)
- func (c *Client) Login(ctx context.Context) error
- func (c *Client) Logout(ctx context.Context) error
- func (c *Client) Minion(ctx context.Context, id string) (*Minion, error)
- func (c *Client) Minions(ctx context.Context) ([]Minion, error)
- func (c *Client) RunCommand(ctx context.Context, cmd Command) (interface{}, error)
- func (c *Client) RunCommands(ctx context.Context, cmds []Command) ([]interface{}, error)
- func (c *Client) Stats(ctx context.Context) (map[string]interface{}, error)
- func (c *Client) SubmitJob(ctx context.Context, job MinionJob) (*AsyncMinionJobResult, error)
- func (c *Client) SubmitJobs(ctx context.Context, jobs []MinionJob) ([]AsyncMinionJobResult, error)
- type Command
- type CommandClient
- type ExpressionTarget
- type Job
- type JobDetails
- type KeyResult
- type ListTarget
- type Minion
- type MinionJob
- type MinionKeyPair
- type RequestError
- type Target
- type TargetType
Constants ¶
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" )
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 ¶
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") )
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") )
var ( // ErrorJobNotFound indicates requested job was not found ErrorJobNotFound = errors.New("job was not found") )
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 ¶
AsyncMinionJobResult contains results of an async run with local client.
type Client ¶
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.
func (*Client) Hook ¶
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.
func (*Client) Job ¶
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 ¶
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 ¶
Key returns public key of a single minion from master
If the minion is not found on the master ErrorMinionKeyNotFound error is returned.
func (*Client) Login ¶
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 ¶
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 ¶
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.
func (*Client) Minions ¶
Minions retrieves grains of all minions on a Salt Master
Grains will be empty for offline minions.
func (*Client) RunCommand ¶
RunCommand runs a command on master using Run endpoint
func (*Client) RunCommands ¶
RunCommands runs multiple commands on master using Run endpoint
func (*Client) Stats ¶
Stats retrieves CherryPy stats
https://docs.saltstack.com/en/latest/ref/netapi/all/salt.netapi.rest_cherrypy.html#stats
func (*Client) SubmitJobs ¶
SubmitJobs submits multiple jobs to be executed on minions asynchronously
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 ¶
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
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 ¶
MinionKeyPair contains key-pair for a minion
type RequestError ¶
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.