gogobosh

package module
v0.0.0-...-d50e93b Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2023 License: MIT Imports: 13 Imported by: 12

README

Go Go BOSH - BOSH client API for golang applications

This project is a golang library for applications wanting to talk to a BOSH/MicroBOSH or bosh-lite.

Build workflow GoDoc

API

The following client functions are available, as a subset of the full BOSH Director API.

  • client.GetInfo()
  • client.GetStemcells()
  • client.GetReleases()
  • client.GetDeployments()
  • client.GetDeployment("cf-warden")
  • client.GetDeploymentVMs("cf-warden")
  • client.GetTasks()
  • client.GetTask(123)
  • client.GetTaskResult(123)
  • client.Start("deployment", "job", "instance-id")
  • client.Stop("deployment", "job", "instance-id")
  • client.Restart("deployment", "job", "instance-id")

Install

go get github.com/cloudfoundry-community/gogobosh

Documentation

The documentation is published to https://godoc.org/github.com/cloudfoundry-community/gogobosh. Also, view the documentation locally with:

$ godoc

Usage

As a short getting started guide:

package main

import (
  "github.com/cloudfoundry-community/gogobosh"
  "fmt"
)

func main() {
  c, _ := gogobosh.NewClient(gogobosh.DefaultConfig())
  info, _ := c.GetInfo()

  fmt.Println("Director")
  fmt.Printf("  Name       %s\n", info.Name)
  fmt.Printf("  Version    %s\n", info.Version)
  fmt.Printf("  User       %s\n", info.User)
  fmt.Printf("  UUID       %s\n", info.UUID)
  fmt.Printf("  CPI        %s\n", info.CPI)
}

##Development

Some test are unit tests and run completely in memory without bosh while the integration tests require a local bosh-lite installation. Ideally you would run this before submitting a PR. All the unit and integration tests can be run using:

$ make test-all

Unit tests are fast in-memory tests and do not run against bosh-lite. All the unit tests can be run using:

$ make test

Integration tests in integration_test.go run against bosh-lite and can be run using:

$ BOSH_CLIENT_SECRET='myadminsecret' make test-integration

Before submitting a PR make sure all the tests pass, the code is properly formatted and linted:

$ make

Contributing

Contributions from the community are welcomed. This is a rough outline of what a contributor's workflow looks like:

  • Create a topic branch from where you want to base your work
  • Make commits of logical units
  • Make sure your commit messages are in the proper format (see below)
  • Push your changes to a topic branch in your fork of the repository
  • Submit a pull request

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CPU

type CPU struct {
	Sys  string `json:"sys"`
	User string `json:"user"`
	Wait string `json:"wait"`
}

CPU struct

type Cfg

type Cfg struct {
	ID        string `json:"id"`
	Name      string `json:"name"`
	Type      string `json:"type"`
	Content   string `json:"content"`
	CreatedAt int    `json:"int"`
	Deleted   bool   `json:"deleted"`
}

Cfg struct

type Client

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

Client used to communicate with BOSH

func NewClient

func NewClient(config *Config) (*Client, error)

NewClient returns a new client

func (*Client) Cleanup

func (c *Client) Cleanup(removeAll bool) (Task, error)

Cleanup will post to the cleanup endpoint of bosh, passing along the removeAll flag passed in as a bool

func (*Client) CreateDeployment

func (c *Client) CreateDeployment(manifest string) (Task, error)

CreateDeployment deploys the given deployment manifest

func (*Client) DeleteDeployment

func (c *Client) DeleteDeployment(name string) (Task, error)

DeleteDeployment from given BOSH

func (*Client) DoRequest

func (c *Client) DoRequest(r *request) (*http.Response, error)

DoRequest runs a request with our client

func (*Client) DoRequestAndUnmarshal

func (c *Client) DoRequestAndUnmarshal(r *request, objPtr interface{}) error

func (*Client) GetCloudConfig

func (c *Client) GetCloudConfig(latest bool) ([]Cfg, error)

GetCloudConfig from given BOSH

func (*Client) GetDeployment

func (c *Client) GetDeployment(name string) (Manifest, error)

GetDeployment returns a specific deployment by name from the given BOSH

func (*Client) GetDeploymentVMs

func (c *Client) GetDeploymentVMs(name string) ([]VM, error)

GetDeploymentVMs returns all the VMs that make up the specified deployment

func (*Client) GetDeployments

func (c *Client) GetDeployments() ([]Deployment, error)

GetDeployments returns all deployments from the given BOSH

func (*Client) GetInfo

func (c *Client) GetInfo() (Info, error)

GetInfo returns BOSH Info

func (*Client) GetReleases

func (c *Client) GetReleases() ([]Release, error)

GetReleases from the given BOSH

func (*Client) GetStemcells

func (c *Client) GetStemcells() ([]Stemcell, error)

GetStemcells from given BOSH

func (*Client) GetTask

func (c *Client) GetTask(id int) (Task, error)

GetTask returns the specified task from BOSH

func (*Client) GetTaskEvents

func (c *Client) GetTaskEvents(id int) ([]TaskEvent, error)

GetTaskEvents retrieves the events for the specified task

func (*Client) GetTaskOutput

func (c *Client) GetTaskOutput(id int, typ string) ([]string, error)

GetTaskOutput returns the completed tasks output

func (*Client) GetTaskResult

func (c *Client) GetTaskResult(id int) ([]string, error)

GetTaskResult returns the tasks result

func (*Client) GetTasks

func (c *Client) GetTasks() ([]Task, error)

GetTasks returns all BOSH tasks

func (*Client) GetTasksByQuery

func (c *Client) GetTasksByQuery(query url.Values) ([]Task, error)

GetTasksByQuery from given BOSH

func (*Client) GetToken

func (c *Client) GetToken() (string, error)

GetToken - returns the current token bearer

func (*Client) GetUUID

func (c *Client) GetUUID() (string, error)

GetUUID returns the BOSH UUID

func (*Client) NewRequest

func (c *Client) NewRequest(method, path string) *request

NewRequest is used to create a new request

func (*Client) Restart

func (c *Client) Restart(deployment, jobName, instanceID string) (Task, error)

func (*Client) RestartNoConverge

func (c *Client) RestartNoConverge(deployment, jobName, instanceID string) (Task, error)

func (*Client) Start

func (c *Client) Start(deployment, jobName, instanceID string) (Task, error)

func (*Client) StartNoConverge

func (c *Client) StartNoConverge(deployment, jobName, instanceID string) (Task, error)

func (*Client) Stop

func (c *Client) Stop(deployment, jobName, instanceID string) (Task, error)

func (*Client) StopNoConverge

func (c *Client) StopNoConverge(deployment, jobName, instanceID string) (Task, error)

func (*Client) UUID

func (c *Client) UUID() string

UUID returns the BOSH uuid Deprecated: Use GetUUID and check for errors

func (*Client) UpdateCloudConfig

func (c *Client) UpdateCloudConfig(config string) error

UpdateCloudConfig updates the cloud config with the specified config

func (*Client) UploadRelease

func (c *Client) UploadRelease(url, sha1 string) (Task, error)

UploadRelease to the given BOSH

func (*Client) UploadStemcell

func (c *Client) UploadStemcell(url, sha1 string) (Task, error)

UploadStemcell to the given BOSH

func (*Client) WaitUntilDone

func (c *Client) WaitUntilDone(task Task, timeout time.Duration) (Task, error)

type Config

type Config struct {
	BOSHAddress       string
	Username          string
	Password          string
	ClientID          string
	ClientSecret      string
	UAAAuth           bool
	HttpClient        *http.Client
	SkipSslValidation bool
	TokenSource       oauth2.TokenSource
	Endpoint          *Endpoint
}

Config is used to configure the creation of a client

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig configuration for client

type Deployment

type Deployment struct {
	Name        string     `json:"name"`
	CloudConfig string     `json:"cloud_config"`
	Releases    []Resource `json:"releases"`
	Stemcells   []Resource `json:"stemcells"`
}

Deployment struct

func (*Deployment) HasRelease

func (d *Deployment) HasRelease(name string) bool

HasRelease if deployment has release

type Disk

type Disk struct {
	Ephemeral  DiskStats `json:"ephemeral"`
	System     DiskStats `json:"system"`
	Persistent DiskStats `json:"persistent"`
}

Disk struct

type DiskStats

type DiskStats struct {
	Percent      string `json:"percent"`
	InodePercent string `json:"inode_percent"`
}

DiskStats struct

type Endpoint

type Endpoint struct {
	URL string `json:"doppler_logging_endpoint"`
}

func DefaultEndpoint

func DefaultEndpoint() *Endpoint

type Event

type Event struct {
	ID         string                 `json:"id"`
	ParentID   string                 `json:"parent_id"`
	Timestamp  int                    `json:"timestamp"`
	User       string                 `json:"user"`
	Action     string                 `json:"action"`
	ObjectType string                 `json:"object_type"`
	ObjectName string                 `json:"object_name"`
	Task       string                 `json:"task"`
	Deployment string                 `json:"deployment"`
	Error      string                 `json:"error"`
	Context    map[string]interface{} `json:"context"`
}

Event struct

type Info

type Info struct {
	Name               string             `json:"name"`
	UUID               string             `json:"uuid"`
	Version            string             `json:"version"`
	User               string             `json:"user"`
	CPI                string             `json:"cpi"`
	UserAuthentication UserAuthentication `json:"user_authentication"`
}

Info struct

type Manifest

type Manifest struct {
	Manifest string `json:"manifest"`
}

Manifest struct

type Memory

type Memory struct {
	Percent string `json:"percent"`
	KB      string `json:"KB"`
}

Memory struct

type Process

type Process struct {
	Name   string        `json:"name"`
	State  string        `json:"state"`
	Uptime Uptime        `json:"uptime"`
	Mem    ProcessMemory `json:"mem"`
	CPU    ProcessCPU    `json:"cpu"`
}

Process running on a VM

type ProcessCPU

type ProcessCPU struct {
	Total float64 `json:"total"`
}

ProcessCPU struct

type ProcessMemory

type ProcessMemory struct {
	Percent float64 `json:"percent"`
	KB      int     `json:"KB"`
}

ProcessMemory struct

type Release

type Release struct {
	Name            string           `json:"name"`
	ReleaseVersions []ReleaseVersion `json:"release_versions"`
}

Release struct

type ReleaseVersion

type ReleaseVersion struct {
	Version            string   `json:"version"`
	CommitHash         string   `json:"commit_hash"`
	UncommittedChanges bool     `json:"uncommitted_changes"`
	CurrentlyDeployed  bool     `json:"currently_deployed"`
	JobNames           []string `json:"job_names"`
}

ReleaseVersion struct

type Resource

type Resource struct {
	Name    string `json:"name"`
	Version string `json:"version"`
}

Resource struct

type Stemcell

type Stemcell struct {
	Name            string `json:"name"`
	OperatingSystem string `json:"operating_system"`
	Version         string `json:"version"`
	CID             string `json:"cid"`
	CPI             string `json:"cpi"`
	Deployments     []struct {
		Name string `json:"name"`
	} `json:"deployments"`
}

Stemcell struct

type Task

type Task struct {
	ID          int    `json:"id"`
	State       string `json:"state"`
	Description string `json:"description"`
	Timestamp   int    `json:"timestamp"`
	Result      string `json:"result"`
	User        string `json:"user"`
}

Task struct

type TaskEvent

type TaskEvent struct {
	Time     int      `json:"time"`
	Stage    string   `json:"stage"`
	Tags     []string `json:"tags"`
	Total    int      `json:"total"`
	Task     string   `json:"task"`
	Index    int      `json:"index"`
	State    string   `json:"state"`
	Progress int      `json:"progress"`

	Error struct {
		Code    int    `json:"code"`
		Message string `json:"message"`
	} `json:"error"`
}

TaskEvent struct

type Uptime

type Uptime struct {
	Secs int `json:"secs"`
}

Uptime struct

type UserAuthentication

type UserAuthentication struct {
	Type    string `json:"type"`
	Options struct {
		URL string `json:"url"`
	} `json:"options"`
}

UserAuthentication struct

type VM

type VM struct {
	VMCID              string    `json:"vm_cid"`
	IPs                []string  `json:"ips"`
	DNS                []string  `json:"dns"`
	AgentID            string    `json:"agent_id"`
	JobName            string    `json:"job_name"`
	Index              int       `json:"index"`
	JobState           string    `json:"job_state"`
	State              string    `json:"state"`
	ResourcePool       string    `json:"resource_pool"`
	VMType             string    `json:"vm_type"`
	Vitals             Vitals    `json:"vitals"`
	Processes          []Process `json:"processes"`
	ResurrectionPaused bool      `json:"resurrection_paused"`
	AZ                 string    `json:"az"`
	ID                 string    `json:"id"`
	Bootstrap          bool      `json:"bootstrap"`
	Ignore             bool      `json:"ignore"`
}

VM struct

type Vitals

type Vitals struct {
	Disk Disk     `json:"disk"`
	Load []string `json:"load"`
	Mem  Memory   `json:"mem"`
	Swap Memory   `json:"swap"`
	CPU  CPU      `json:"cpu"`
}

Vitals for a VM

Jump to

Keyboard shortcuts

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