client

package module
Version: v0.0.0-...-c17bdd9 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2015 License: MIT Imports: 13 Imported by: 0

README

fleet-client-go

Godoc

Currently that client requires a fleetctl binary available to execute. Thus there is no ssh connection used, the possible commands are submit, start, stop, destroy, list-units, list-machines. The client supports a dump version of Status, that uses list-units and just parses whether a service is running or not.

A new way to use fleets http api has been implemented.

install

import fleetClientPkg "github.com/DimShadoWWW/fleet-client-go"

usage

// Create new fleet client based on a given binary.
fleetClient := fleetClientPkg.NewClientCLI()

// Create new fleet client based on the http api.
fleetClient := fleetClientPkg.NewClientAPI()

// Interface methods.
type FleetClient interface {
  // A Unit is a submitted job known by fleet, but not started yet. Submitting
  // a job creates a unit. Unit() returns such an object. Further a Unit has
  // different properties than a ScheduledUnit.
	Unit(name string) (*job.Unit, error)

  // A ScheduledUnit is a submitted job known by fleet in a specific state.
  // ScheduledUnit() does not fetch a ScheduledUnit if a Unit is not started
  // yet, but only submitted. Further a ScheduledUnit has different properties
  // than a Unit.
	ScheduledUnit(name string) (*job.ScheduledUnit, error)

	Submit(name, filePath string) error
	Start(name string) error
	Stop(name string) error
	Load(name string) error
	Destroy(name string) error
	Status(name string) (*Status, error) // Deprecated, use StatusUnit()
	StatusUnit(name string) (UnitStatus, error)
}

Documentation

Index

Constants

View Source
const (
	STATE_LAUNCHED = "launched"
	STATE_LOADED   = "loaded"
	STATE_INACTIVE = "inactive"

	LOAD_UNKNOWN = "-"
	LOAD_LOADED  = "loaded" // See https://github.com/coreos/fleet/blob/master/job/job.go

	ACTIVE_UNKNOWN    = "-"
	ACTIVE_ACTIVE     = "active"
	ACTIVE_ACTIVATING = "activating"
	ACTIVE_FAILED     = "failed"

	SUB_UNKNOWN   = "-"
	SUB_DEAD      = "dead"
	SUB_LAUNCHED  = "launched"
	SUB_START     = "start"
	SUB_START_PRE = "start-pre"
	SUB_RUNNING   = "running"
	SUB_EXITED    = "exited"
	SUB_FAILED    = "failed"
)
View Source
const (
	FLEETCTL        = "fleetctl"
	ENDPOINT_OPTION = "--endpoint"
	ENDPOINT_VALUE  = "http://172.17.42.1:4001"
)
View Source
const (
	ERROR_TYPE_NOT_FOUND = 10000 + iota
)
View Source
const (
	FLEET_SOCK = "/var/run/fleet.sock"
)

Variables

This section is empty.

Functions

func GetMachineIP

func GetMachineIP(unitMachine string) string

GetMachineIP parses the unitMachine in format "uuid/ip" and returns only the IP part. Can be used with the {UnitStatus.Machine} field. Returns an empty string, if no ip was found.

func IsNotFoundError

func IsNotFoundError(err error) bool

Types

type ClientAPI

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

func (*ClientAPI) Destroy

func (this *ClientAPI) Destroy(name string) error

func (*ClientAPI) JournalF

func (this *ClientAPI) JournalF(name string) (chan string, error)

func (*ClientAPI) Load

func (this *ClientAPI) Load(name string) error

func (*ClientAPI) MachineAll

func (this *ClientAPI) MachineAll() ([]MachineStatus, error)

func (*ClientAPI) Start

func (this *ClientAPI) Start(name string) error

func (*ClientAPI) Status

func (this *ClientAPI) Status(name string) (*Status, error)

func (*ClientAPI) StatusAll

func (this *ClientAPI) StatusAll() ([]UnitStatus, error)

func (*ClientAPI) StatusUnit

func (this *ClientAPI) StatusUnit(name string) (UnitStatus, error)

func (*ClientAPI) Stop

func (this *ClientAPI) Stop(name string) error

func (*ClientAPI) Submit

func (this *ClientAPI) Submit(name, filePath string) error

func (*ClientAPI) Unit

func (this *ClientAPI) Unit(name string) (*schema.Unit, error)

type ClientCLI

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

func (*ClientCLI) Destroy

func (this *ClientCLI) Destroy(name string) error

func (*ClientCLI) JournalF

func (this *ClientCLI) JournalF(name string) (chan string, error)

func (*ClientCLI) Load

func (this *ClientCLI) Load(name string) error

func (*ClientCLI) MachineAll

func (this *ClientCLI) MachineAll() ([]MachineStatus, error)

func (*ClientCLI) Start

func (this *ClientCLI) Start(name string) error

func (*ClientCLI) Status

func (this *ClientCLI) Status(name string) (*Status, error)

func (*ClientCLI) StatusAll

func (this *ClientCLI) StatusAll() ([]UnitStatus, error)

StatusAll executes "fleetctl status" and parses the output table. Thus, certain fields can be mangled or shortened, e.g. the machine column.

func (*ClientCLI) StatusUnit

func (this *ClientCLI) StatusUnit(name string) (UnitStatus, error)

StatusUnit returns the UnitStatus for the given unitfile. If the unit is not found or could not be retrieved, an error will be returned.

Internally it executes `fleetctl status` and looks for the matching unit file. Its {UnitStatus} will be returned.

func (*ClientCLI) Stop

func (this *ClientCLI) Stop(name string) error

func (*ClientCLI) Submit

func (this *ClientCLI) Submit(name, filePath string) error

func (*ClientCLI) Unit

func (this *ClientCLI) Unit(name string) (*schema.Unit, error)

type FleetClient

type FleetClient interface {
	// A Unit is a submitted job known by fleet, but not started yet. Submitting
	// a job creates a unit. Unit() returns such an object. Further a Unit has
	// different properties than a ScheduledUnit.
	Unit(name string) (*schema.Unit, error)

	Submit(name, filePath string) error
	Start(name string) error
	Stop(name string) error
	Load(name string) error
	Destroy(name string) error
	Status(name string) (*Status, error) // Deprecated, use StatusUnit()
	StatusUnit(name string) (UnitStatus, error)
	StatusAll() ([]UnitStatus, error)
	JournalF(name string) (chan string, error)
	MachineAll() ([]MachineStatus, error)
}

func NewClient

func NewClient() FleetClient

func NewClientAPI

func NewClientAPI() FleetClient

func NewClientAPIWithSocket

func NewClientAPIWithSocket(socket string) FleetClient

func NewClientCLI

func NewClientCLI() FleetClient

func NewClientCLIWithPeer

func NewClientCLIWithPeer(etcdPeer string) FleetClient

type FleetClientError

type FleetClientError struct {
	StatusCode int
	StatusText string
}

func NewFleetClientError

func NewFleetClientError(code int, text string) FleetClientError

func (FleetClientError) Error

func (this FleetClientError) Error() string

type MachineStatus

type MachineStatus struct {
	Machine   string
	IPAddress string
	Metadata  string
}

type Status

type Status struct {
	Running     bool
	ContainerIP string
}

type UnitStatus

type UnitStatus struct {
	// Unit Name with file extension
	Unit string

	State string

	// "-", "loaded"
	Load string

	// "-", "active", "failed"
	Active string

	// The state of the unit, e.g. "-", "running" or "failed". See the SUB_* constants.
	Sub string

	// The machine that is used to execute the unit.
	// Is "-", when no machine is assigned.
	// Otherwise is in the format of "uuid/ip", where uuid is shortened version of the host uuid
	// and IP is the IP assigned to that machine.
	Machine string
}

func (UnitStatus) MachineIP

func (status UnitStatus) MachineIP() string

MachineIP returns the IP of the used machine, if available, an empty string otherwise. Alias for `return GetMachineIp(status.Machine)`.

Directories

Path Synopsis
examples
cli

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL