awx

package module
v0.0.0-...-191529c Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

README

AWX Go Client

This is a Go client for interacting with the AWX API. AWX is an open-source project that provides a web-based user interface, REST API, and task engine built on top of Ansible.

Installation

To install the AWX Go client, use go get:

go get github.com/sapcc/go-awx

Usage

Here is a basic example of how to use the AWX Go client:

package main

import (
    "fmt"
    "log"
    awx "github.com/sapcc/go-awx"
)

func main() {
    client, err := awx.NewClient(awx.Options{
        Endpoint: "https://your-awx.cloud/api/v2",
        Username: "username",
		Password: "password",
		Token:    "token",
    })
    if err != nil {
        log.Fatalf("Failed to create AWX client: %v", err)
    }
    input := ListJobsInput{ID: "1"}
	jobs := JobList{}
    err = client.List(context.Background(), awx.ObjectKey{Resource: "jobs"}, &jobs, nil)
    if err != nil {
        log.Fatalf("Failed to list inventories: %v", err)
    }

    for _, job := range jobs.Results {
        fmt.Printf("job: %s\n", job.Name)
    }
}

Features

  • List inventories
  • Create, update, and delete inventories
  • List job templates
  • Launch job templates
  • And more...

Contributing

Contributions are welcome! Please open an issue or submit a pull request on GitHub.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Acknowledgements

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CanCancelJob

type CanCancelJob struct {
	CanCancel bool `json:"can_cancel"`
}

CanCancelJob represents the output of the GetCancelJob method.

type Client

type Client interface {
	Ping(ctx context.Context) (output GetPingOutput, err error)
	Reader
	Writer
}

Client represents the client for the AWX API.

func NewClient

func NewClient(options ClientOptions) (c Client, err error)

NewClient creates a new client for the AWX API.

type ClientOptions

type ClientOptions struct {
	Endpoint           string
	HTTPClient         HTTPClient
	InsecureSkipVerify bool
	Username           string
	Password           string
	Token              string
	Agent              string
	Version            string
}

ClientOptions represents the options for the client.

type CreateJobTemplatesSchedule

type CreateJobTemplatesSchedule struct {
	Name               string `json:"name"`
	RRULE              string `json:"rrule"`
	UnifiedJobTemplate int    `json:"unified_job_template"`
	ExtraData          string `json:"extra_data"`
	Inventory          string `json:"inventory"`
	Limit              string `json:"limit"`
}

CreateJobTemplatesSchedule represents the input of the PostJobTemplateSchedule method.

type Error

type Error struct {
	StatusCode int
	Msg        []string
}

Error represents the output of the Error method.

func NewError

func NewError(statusCode int, msg []string) *Error

NewError creates a new error.

func (*Error) Error

func (e *Error) Error() string

Error returns the error message.

type ErrorResponse

type ErrorResponse struct {
	All []string `json:"__all__"`
}

ErrorResponse represents the awx error response.

type GetAuthTokenInput

type GetAuthTokenInput struct {
	Username string `json:"username,omitempty"`
	Password string `json:"password,omitempty"`
}

GetAuthTokenInput represents the input of the GetAuthToken method.

type GetAuthTokenOutput

type GetAuthTokenOutput struct {
	Token   string    `json:"token,omitempty"`
	Expires time.Time `json:"expires,omitempty"`
}

GetAuthTokenOutput represents the output of the GetAuthToken method.

type GetOption

type GetOption interface {
}

GetOption represents an option for get operation.

type GetPingOutput

type GetPingOutput struct {
	Version     string `json:"version"`
	ActiveNode  string `json:"active_node"`
	InstallUUID string `json:"install_uuid"`
}

GetPingOutput represents the output of the Ping method.

type HTTPClient

type HTTPClient interface {
	Do(*http.Request) (*http.Response, error)
}

HTTPClient provides the interface for a client making HTTP requests with the API.

type Inventory

type Inventory struct {
	ID                int    `json:"id"`
	Name              string `json:"name"`
	URL               string `json:"url"`
	Type              string `json:"type"`
	Modified          string `json:"modified"`
	Created           string `json:"created"`
	HasActiveFailures bool   `json:"has_active_failures"`
	TotalHosts        int    `json:"total_hosts"`
	PendingDeletion   bool   `json:"pending_deletion"`
}

Inventory represents the output of the GetInventories method.

type InventoryList

type InventoryList struct {
	ListGetResponse
	Results []*Inventory `json:"results,omitempty"`
}

InventoryList represents the output of the ListInventories method.

type InventoryListInput

type InventoryListInput struct {
	Query string `schema:"-,omitempty"`
	Name  string `schema:"name,omitempty"`
}

InventoryListInput represents the input of the ListInventories method.

type Job

type Job struct {
	ID                 int       `json:"id"`
	Name               string    `json:"name"`
	URL                string    `json:"url"`
	Type               string    `json:"type"`
	Modified           string    `json:"modified"`
	Created            string    `json:"created"`
	UnifiedJobTemplate int       `json:"unified_job_template"`
	Status             string    `json:"status"`
	Failed             bool      `json:"failed"`
	Started            time.Time `json:"started"`
	Finished           time.Time `json:"finished"`
}

Job represents the output of the GetJobs method.

type JobList

type JobList struct {
	ListGetResponse
	Results []*Job `json:"results,omitempty"`
}

JobList represents the output of the ListJobs method.

type JobTemplate

type JobTemplate struct {
	ID       int    `json:"id"`
	Name     string `json:"name"`
	URL      string `json:"url"`
	Type     string `json:"type"`
	Modified string `json:"modified"`
	Created  string `json:"created"`
	Status   string `json:"status"`
}

JobTemplate represents the output of the GetJobTemplates method.

type JobTemplateList

type JobTemplateList struct {
	ListGetResponse
	Results []*JobTemplate `json:"results,omitempty"`
}

JobTemplateList represents the output of the ListJobTemplates method.

type ListGetResponse

type ListGetResponse struct {
	Count    int    `json:"count,omitempty"`
	Next     string `json:"next,omitempty"`
	Previous string `json:"previous,omitempty"`
}

ListGetResponse represents the output of the ListGet method.

type ListJobTemplateInput

type ListJobTemplateInput struct {
	ID    string `schema:"id,omitempty"`
	Name  string `schema:"name,omitempty"`
	Query string `schema:"-,omitempty"`
}

ListJobTemplateInput represents the input of the ListJobTemplates method.

type ListJobsInput

type ListJobsInput struct {
	ID         string `schema:"id,omitempty"`
	LaunchType string `schema:"launch_type,omitempty"`
	ScheduleID int    `schema:"schedule__id,omitempty"`
	Query      string `schema:"query,omitempty"`
}

ListJobsInput represents the input of the ListJobs method.

type ListOption

type ListOption interface {
}

ListOption represents an option for list operation.

type ListSchedulesInput

type ListSchedulesInput struct {
	ID   string `schema:"id,omitempty"`
	Name string `schema:"name,omitempty"`
}

ListSchedulesInput represents the input of the ListSchedules method.

type Object

type Object interface {
}

Object represents an object in AWX.

type ObjectKey

type ObjectKey struct {
	Resource   string
	ResourceID string
	Action     string
}

ObjectKey represents the key of an object.

func (ObjectKey) String

func (k ObjectKey) String() string

type ObjectList

type ObjectList interface {
}

ObjectList represents a list of objects in AWX.

type Reader

type Reader interface {
	// Get retrieves an obj for the given object key from AWX.
	// obj must be a struct pointer so that obj can be updated with the response
	// returned by the Server.
	Get(ctx context.Context, key ObjectKey, obj Object, httpStatus []int) error

	// List retrieves list of objects for a given resource and list options. On a
	// successful call, Items field in the list will be populated with the
	// result returned from the server.
	List(ctx context.Context, key ObjectKey, list ObjectList, opts ListOption, httpStatus []int) error
}

Reader knows how to read and list AWX objects.

type Schedule

type Schedule struct {
	ID                 int    `json:"id"`
	RRULE              string `json:"rrule"`
	Type               string `json:"type"`
	URL                string `json:"url"`
	Created            string `json:"created"`
	Modified           string `json:"modified"`
	ExtraData          string `json:"extra_data"`
	Name               string `json:"name"`
	Description        string `json:"description"`
	UnifiedJobTemplate int    `json:"unified_job_template"`
	Inventory          int    `json:"inventory"`
}

Schedule represents the output of the GetSchedule method.

type ScheduleList

type ScheduleList struct {
	ListGetResponse
	Results []*Schedule `json:"results,omitempty"`
}

ScheduleList represents the output of the ListSchedule method.

type Writer

type Writer interface {
	// Create saves the object obj in AWX. obj must be a
	// struct pointer so that obj can be updated with the content returned by the Server.
	Create(ctx context.Context, key ObjectKey, obj Object, httpStatus []int) error

	// Delete deletes the given obj from AWXAWX.
	Delete(ctx context.Context, key ObjectKey, httpStatus []int) error

	// Update updates the given obj in the AWX. obj must be a
	// struct pointer so that obj can be updated with the content returned by the Server.
	Update(ctx context.Context, key ObjectKey, obj Object, httpStatus []int) error
}

Writer knows how to create, delete, and update Kubernetes objects.

Jump to

Keyboard shortcuts

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