orch

package
v1.11.0 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2024 License: Apache-2.0 Imports: 9 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ProcessError

func ProcessError(r *resty.Response, err error, errorString string) error

ProcessError will process the response for RESTY and thow an error accordingly

Types

type Client

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

Client for the Orchestrator API

func NewClient

func NewClient(hostURL string, token string, tlsConfig *tls.Config) *Client

NewClient access the orchestrator API via TLS

func (*Client) CommandDeploy

func (c *Client) CommandDeploy(deployRequest *DeployRequest) (*JobID, error)

CommandDeploy runs the orchestrator across all nodes in an environment (POST /command/deploy)

func (*Client) CommandPlanRun

func (c *Client) CommandPlanRun(planRunRequest *PlanRunRequest) (*PlanRunJobID, error)

CommandPlanRun runs a plan via the plan executor (POST /command/plan_run)

func (*Client) CommandScheduleTask

func (c *Client) CommandScheduleTask(scheduleTaskRequest *ScheduleTaskRequest) (*ScheduledJobID, error)

CommandScheduleTask schedules a task to run at a future date and time (POST /command/schedule_task)

func (*Client) CommandStop

func (c *Client) CommandStop(stopRequest *StopRequest) (*StopJobID, error)

CommandStop stops a orchestrator job that is currently in progress (POST /command/stop)

func (*Client) CommandTask

func (c *Client) CommandTask(taskRequest *TaskRequest) (*JobID, error)

CommandTask runs a permitted task job across a set of nodes (POST /command/task)

func (*Client) CommandTaskTarget

func (c *Client) CommandTaskTarget(taskTargetRequest *TaskTargetRequest) (*TaskTargetJobID, error)

CommandTaskTarget creates a new task-target (POST /command/task_target)

func (*Client) Inventory

func (c *Client) Inventory() ([]InventoryNode, error)

Inventory lists all nodes that are connected to the PCP broker (GET /inventory)

func (*Client) InventoryCheck

func (c *Client) InventoryCheck(nodes []string) ([]InventoryNode, error)

InventoryCheck checks if the given list of nodes is connected to the PCP broker (POST /inventory)

func (*Client) InventoryNode

func (c *Client) InventoryNode(node string) (*InventoryNode, error)

InventoryNode returns information about whether the requested node is connected to the PCP broker (GET /inventory/:node)

func (*Client) Job

func (c *Client) Job(jobID string) (*Job, error)

Job lists all details of a given job (GET /jobs/:job-id)

func (*Client) JobNodes

func (c *Client) JobNodes(jobID string) (*JobNodes, error)

JobNodes lists all of the nodes associated with a given job (GET /jobs/:job-id/nodes)

func (*Client) JobReport

func (c *Client) JobReport(jobID string) (*JobReport, error)

JobReport returns the report for a given job (GET /jobs/:job-id/report)

func (*Client) Jobs

func (c *Client) Jobs() (*Jobs, error)

Jobs lists all of the jobs known to the orchestrator (GET /jobs)

func (*Client) Plan

func (c *Client) Plan(environment, module, planname string) (*Plan, error)

Plan returns data about the specified plan, including metadata (GET /plans/:module/:planname)

func (*Client) PlanByID

func (c *Client) PlanByID(environment, planID string) (*Plan, error)

PlanByID extracts the module and planname from the supplied ID and calls Plan(...)

func (*Client) Plans

func (c *Client) Plans(environment string) (*Plans, error)

Plans lists all known plans in a given environment (GET /plans)

func (*Client) Task

func (c *Client) Task(environment, module, taskname string) (*Task, error)

Task returns data about a specified task, including metadata and file information. For the default task in a module, taskname is init. (GET /tasks/:module/:taskname)

func (*Client) TaskByID

func (c *Client) TaskByID(environment, taskID string) (*Task, error)

TaskByID extracts the module and taskname from the supplied ID and calls Task(...)

func (*Client) Tasks

func (c *Client) Tasks(environment string) (*Tasks, error)

Tasks lists all tasks in a given environment (GET /tasks)

type DeployRequest

type DeployRequest struct {
	Environment        string `json:"environment"`
	Scope              Scope  `json:"scope,omitempty"`
	Description        string `json:"description,omitempty"`
	Noop               bool   `json:"noop,omitempty"`
	NoNoop             bool   `json:"no_noop,omitempty"`
	Concurrency        int    `json:"concurrency,omitempty"`
	EnforceEnvironment bool   `json:"enforce_environment"`
	Debug              bool   `json:"debug,omitempty"`
	Trace              bool   `json:"trace,omitempty"`
	Evaltrace          bool   `json:"evaltrace,omitempty"`
	Target             string `json:"target,omitempty"`
}

DeployRequest describes a deploy request

type Environment

type Environment struct {
	Name string `json:"name"`
}

Environment in the current job

type Events

type Events struct {
	ID string `json:"id"`
}

Events in the current job

type HTTPError

type HTTPError struct {
	Msg        string
	StatusCode int
}

HTTPError represents an error with the HTTP response code

func (*HTTPError) Error

func (he *HTTPError) Error() string

func (*HTTPError) GetStatusCode

func (he *HTTPError) GetStatusCode() int

GetStatusCode will return the HTTP status code.

type Interval

type Interval struct {
	Units string `json:"units"`
	Value int    `json:"value"`
}

Interval represents the time Interval for a task to run

type InventoryNode

type InventoryNode struct {
	Name      string `json:"name,omitempty"`
	Connected bool   `json:"connected,omitempty"`
	Broker    string `json:"broker,omitempty"`
	Timestamp string `json:"timestamp,omitempty"`
}

InventoryNode contains data about a single node

type Job

type Job struct {
	ID          string                 `json:"id"`
	Name        string                 `json:"name"`
	State       string                 `json:"state"`
	Type        string                 `json:"type"`
	Command     string                 `json:"command"`
	Options     map[string]interface{} `json:"options"`
	NodeCount   int                    `json:"node_count"`
	NodeStates  NodeStates             `json:"node_states"`
	Owner       map[string]interface{} `json:"owner"`
	Description string                 `json:"description"`
	Timestamp   string                 `json:"timestamp"`
	Environment Environment            `json:"environment"`
	Status      []Status               `json:"status"`
	Nodes       Nodes                  `json:"nodes"`
	Events      Events                 `json:"events"`
	Report      Report                 `json:"report"`
}

Job contains data about a single job

type JobEvent

type JobEvent struct {
	ID        string `json:"id"`
	Type      string `json:"type"`
	Timestamp string `json:"timestamp"`
	Details   struct {
		Node   string `json:"node"`
		Detail struct {
			Noop bool `json:"noop"`
		} `json:"detail"`
	} `json:"details"`
	Message string `json:"message"`
}

JobEvent contains a single event from a job

type JobID

type JobID struct {
	Job struct {
		ID   string `json:"id"`
		Name string `json:"name"`
	} `json:"job"`
}

JobID identifies a single Orchestrator job

type JobNode

type JobNode struct {
	Transport       string                 `json:"transport"`
	FinishTimestamp string                 `json:"finish_timestamp"`
	TransactionUUID string                 `json:"transaction_uuid"`
	StartTimestamp  string                 `json:"start_timestamp"`
	Name            string                 `json:"name"`
	Duration        float64                `json:"duration"`
	State           string                 `json:"state"`
	Details         map[string]interface{} `json:"details"`
	Result          map[string]interface{} `json:"result"`
	LatestEventID   int                    `json:"latest-event-id"`
	Timestamp       string                 `json:"timestamp"`
}

JobNode is a single node associated with a given job

type JobNodes

type JobNodes struct {
	Items      []JobNode  `json:"items"`
	NextEvents NextEvents `json:"next-events"`
}

JobNodes is a list of all nodes associated with a given job

type JobReport

type JobReport struct {
	Items []struct {
		Node      string     `json:"node"`
		State     string     `json:"state"`
		Timestamp string     `json:"timestamp"`
		Events    []JobEvent `json:"events"`
	} `json:"items"`
}

JobReport contains the report for a single job

type Jobs

type Jobs struct {
	Items      []Job      `json:"items"`
	Pagination Pagination `json:"pagination"`
}

Jobs contains data about all jobs

type NextEvents

type NextEvents struct {
	ID    string `json:"id"`
	Event string `json:"event"`
}

NextEvents section of the response

type NodeStates

type NodeStates struct {
	Finished int `json:"finished"`
	Errored  int `json:"errored"`
	Failed   int `json:"failed"`
	Running  int `json:"running"`
}

NodeStates for the current job

type Nodes

type Nodes struct {
	ID string `json:"id"`
}

Nodes in the current job

type OrchestratorError

type OrchestratorError struct {
	Kind       string `json:"kind"`
	Msg        string `json:"Msg"`
	StatusCode int
}

OrchestratorError represents an error response from the Orchestrator API

func (*OrchestratorError) Error

func (oe *OrchestratorError) Error() string

func (*OrchestratorError) GetStatusCode

func (oe *OrchestratorError) GetStatusCode() int

GetStatusCode will return the status code.

type Owner

type Owner struct {
	ID    string `json:"id"`
	Login string `json:"login"`
}

Owner represents the owner of a job

type Pagination

type Pagination struct {
	Limit  int `json:"limit"`
	Offset int `json:"offset"`
	Total  int `json:"total"`
}

Pagination information about the current payload

type Plan

type Plan struct {
	ID          string `json:"id,omitempty"`
	Name        string `json:"name,omitempty"`
	Environment struct {
		Name   string `json:"name,omitempty"`
		CodeID string `json:"code_id,omitempty" structs:"-"`
	} `json:"environment,omitempty"`
	Metadata  TaskMetadata `json:"metadata,omitempty" structs:"-"`
	Permitted bool         `json:"permitted,omitempty"`
}

Plan contains information about a specific plan

type PlanRunJobID

type PlanRunJobID struct {
	Name string `json:"name"`
}

PlanRunJobID identifies a plan_run job

type PlanRunRequest

type PlanRunRequest struct {
	Name        string                 `json:"plan_name"`
	Params      map[string]interface{} `json:"params"`
	Environment string                 `json:"environment,omitempty"`
	Description string                 `json:"description,omitempty"`
}

PlanRunRequest describes a plan_run request

type Plans

type Plans struct {
	Environment struct {
		Name   string `json:"name,omitempty"`
		CodeID string `json:"code_id,omitempty" structs:"-"`
	} `json:"environment,omitempty"`
	Items []struct {
		ID        string `json:"id,omitempty"`
		Name      string `json:"name,omitempty"`
		Permitted bool   `json:"permitted,omitempty"`
	} `json:"items,omitempty"`
}

Plans lists the known plans in a single environment

type Report

type Report struct {
	ID string `json:"id"`
}

Report for the current job

type ScheduleOptions

type ScheduleOptions struct {
	Interval Interval `json:"interval"`
}

ScheduleOptions represents the schedule options for a task

func NewScheduleTaskOptions

func NewScheduleTaskOptions(interval time.Duration) *ScheduleOptions

NewScheduleTaskOptions will create task options based on time

type ScheduleTaskRequest

type ScheduleTaskRequest struct {
	Environment     string                 `json:"environment,omitempty"`
	Task            string                 `json:"task"`
	Params          map[string]interface{} `json:"params"`
	Scope           Scope                  `json:"scope"`
	ScheduledTime   string                 `json:"scheduled_time"`
	ScheduleOptions *ScheduleOptions       `json:"schedule_options,omitempty"`
}

ScheduleTaskRequest describes a scheduled task

type ScheduledJobID

type ScheduledJobID struct {
	ScheduledJob struct {
		ID   string `json:"id"`
		Name string `json:"name"`
	} `json:"scheduled_job"`
}

ScheduledJobID identifies a single scheduled job

type Scope

type Scope struct {
	Application string        `json:"application,omitempty"`
	Nodes       []string      `json:"nodes,omitempty"`
	Query       []interface{} `json:"query,omitempty"`
	NodeGroup   string        `json:"node_group,omitempty"`
}

Scope represents the scope of a job. Only a single field can be specified.

type Status

type Status struct {
	State     string `json:"state"`
	EnterTime string `json:"enter_time"`
	ExitTime  string `json:"exit_time"`
}

Status of the current job

type StopJobID

type StopJobID struct {
	Job struct {
		ID    string         `json:"id"`
		Name  string         `json:"name"`
		Nodes map[string]int `json:"nodes"`
	} `json:"job"`
}

StopJobID describes jobs that were stopped successfully

type StopRequest

type StopRequest struct {
	Job string `json:"job"`
}

StopRequest describes a stop request

type Task

type Task struct {
	ID          string `json:"id,omitempty"`
	Name        string `json:"name,omitempty"`
	Environment struct {
		Name   string `json:"name,omitempty"`
		CodeID string `json:"code_id,omitempty"`
	} `json:"environment,omitempty"`
	Metadata TaskMetadata `json:"metadata,omitempty"`
	Files    []TaskFile   `json:"files,omitempty"`
}

Task contains data about a specified task, including metadata and file information

type TaskFile

type TaskFile struct {
	Filename string `json:"filename,omitempty"`
	URI      struct {
		Path   string `json:"path,omitempty"`
		Params struct {
			Environment string `json:"environment,omitempty"`
		} `json:"params,omitempty"`
	} `json:"uri,omitempty"`
	Sha256    string `json:"sha256,omitempty"`
	SizeBytes int    `json:"size_bytes,omitempty"`
}

TaskFile ...

type TaskImplementation

type TaskImplementation struct {
	Name         string   `json:"name"`
	Requirements []string `json:"requirements"`
	InputMethod  string   `json:"input_method"`
}

TaskImplementation in the task metadata

type TaskMetadata

type TaskMetadata struct {
	Description     string                 `json:"description,omitempty"`
	Private         bool                   `json:"private,omitempty"`
	SupportsNoop    bool                   `json:"supports_noop,omitempty"`
	InputMethod     string                 `json:"input_method,omitempty"`
	Parameters      map[string]TaskParam   `json:"parameters,omitempty"`
	Extensions      map[string]interface{} `json:"extensions,omitempty"`
	Implementations []TaskImplementation   `json:"implementations"`
}

TaskMetadata ...

type TaskParam

type TaskParam struct {
	Description string `json:"description,omitempty"`
	Type        string `json:"type,omitempty"`
}

TaskParam in the task metadata

type TaskRequest

type TaskRequest struct {
	Environment string                 `json:"environment,omitempty"`
	Task        string                 `json:"task"`
	Params      map[string]interface{} `json:"params"`
	Scope       Scope                  `json:"scope"`
	Description string                 `json:"description"`
	Noop        bool                   `json:"noop"`
}

TaskRequest describes a task to be run Environment(string): The environment to load the task from. The default is production. Scope The PuppetDB query, list of nodes, or a node group ID. Application scopes are not allowed for task jobs. This key is required. Description A description of the job. Noop Whether to run the job in no-op mode. The default is false. Task The task to run on the targets. This key is required. Params The parameters to pass to the task. This key is required, but can be an empty object. Targets A collection of target objects used for running the task on nodes through SSH or WinRM via Bolt server. Userdata An object of arbitrary key/value data supplied to the job. REF: https://puppet.com/docs/pe/2019.8/orchestrator_api_commands_endpoint.html#orchestrator_api_post_command_task

type TaskTargetJobID

type TaskTargetJobID struct {
	TaskTargetJob struct {
		ID   string `json:"id"`
		Name string `json:"name"`
	} `json:"task_target"`
}

TaskTargetJobID identifies a task_target job

type TaskTargetRequest

type TaskTargetRequest struct {
	DisplayName string   `json:"display_name"`
	Tasks       []string `json:"tasks,omitempty"`
	AllTasks    bool     `json:"all_tasks,omitempty"`
	Nodes       []string `json:"nodes"`
	NodeGroups  []string `json:"node_groups"`
	PQLQuery    string   `json:"pql_query,omitempty"`
}

TaskTargetRequest is a collection of tasks, nodes and node groups that define a permission group

type Tasks

type Tasks struct {
	Environment struct {
		Name   string `json:"name,omitempty"`
		CodeID string `json:"code_id,omitempty"`
	} `json:"environment,omitempty"`
	Items []struct {
		ID   string `json:"id,omitempty"`
		Name string `json:"name,omitempty"`
	} `json:"items,omitempty"`
}

Tasks is a list all tasks in a single environment

Jump to

Keyboard shortcuts

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