flymachines

package
v1.11.0 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2025 License: CC0-1.0 Imports: 9 Imported by: 0

Documentation

Overview

Package flymachines is an API client for Fly's machines API.

This package is loosely based on the Swagger spec for the Fly Machines API1, but with only the important bits implemented.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewError

func NewError(resp *http.Response) error

func Ptr

func Ptr[T any](t T) *T

Types

type App

type App struct {
	ID   string `json:"id"`   // The unique ID of the app
	Name string `json:"name"` // The name of the app (also unique but human readable)
}

App is a Fly app. Apps are collections of resources such as machines, volumes, and IP addresses.

type CheckStatus

type CheckStatus struct {
	Name      string    `json:"name"`
	Status    string    `json:"status"`
	Output    string    `json:"output"`
	UpdatedAt time.Time `json:"updated_at"`
}

type Client

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

func New

func New(token string, cli *http.Client) *Client

New returns a new client for the Fly machines API with the given API token.

This will automatically detect if you have access to the internal API either by a WireGuard tunnel or by being on the Fly network.

func NewClient

func NewClient(token, apiURL string, cli *http.Client) *Client

NewClient returns a new client for the Fly machines API with the given API token and URL.

This is a fairly low-level operation for if you know what URL you need, you probably want to use New instead.

func (*Client) CordonAppMachine

func (c *Client) CordonAppMachine(ctx context.Context, appID, machineID string) error

func (*Client) CreateApp

func (c *Client) CreateApp(ctx context.Context, caa CreateAppArgs) (*CreateAppResponse, error)

CreateApp creates a single application in the given organization and on the given network.

func (*Client) CreateMachine

func (c *Client) CreateMachine(ctx context.Context, appID string, cm CreateMachine) (*Machine, error)

func (*Client) CreateVolume

func (c *Client) CreateVolume(ctx context.Context, appName string, cv CreateVolume) (*Volume, error)

func (*Client) DeleteApp

func (c *Client) DeleteApp(ctx context.Context, appName string) error

func (*Client) DeleteAppMachine

func (c *Client) DeleteAppMachine(ctx context.Context, appID, machineID string) error

func (*Client) DeleteVolume

func (c *Client) DeleteVolume(ctx context.Context, appName, volumeID string) error

func (*Client) DestroyAppMachine

func (c *Client) DestroyAppMachine(ctx context.Context, appID, machineID string) error

func (*Client) Do

func (c *Client) Do(req *http.Request) (*http.Response, error)

Do performs a HTTP request with the appropriate authentication and user agent headers.

func (*Client) ExtendVolume

func (c *Client) ExtendVolume(ctx context.Context, appName, voluleID string, sizeGB int) (*ExtendVolumeResponse, error)

func (*Client) GetApp

func (c *Client) GetApp(ctx context.Context, appName string) (*SingleApp, error)

GetApp fetches information about one app in particular.

func (*Client) GetAppMachine

func (c *Client) GetAppMachine(ctx context.Context, appID, machineID string) (*Machine, error)

func (*Client) GetAppMachineEvents

func (c *Client) GetAppMachineEvents(ctx context.Context, appID, machineID string) ([]MachineEvent, error)

func (*Client) GetAppMachineMetadata

func (c *Client) GetAppMachineMetadata(ctx context.Context, appID, machineID string) (map[string]string, error)

func (*Client) GetAppMachines

func (c *Client) GetAppMachines(ctx context.Context, appName string) ([]Machine, error)

func (*Client) GetApps

func (c *Client) GetApps(ctx context.Context, orgSlug string) ([]ListApp, error)

GetApps gets all of the applications in an organization.

func (*Client) GetVolume

func (c *Client) GetVolume(ctx context.Context, appName, volumeID string) (*Volume, error)

func (*Client) GetVolumes

func (c *Client) GetVolumes(ctx context.Context, appName string) ([]Volume, error)

func (*Client) ListVolumeSnapshots

func (c *Client) ListVolumeSnapshots(ctx context.Context, appName, volumeID string) ([]Snapshot, error)

func (*Client) RestartAppMachine

func (c *Client) RestartAppMachine(ctx context.Context, appID, machineID string) error

func (*Client) StartAppMachine

func (c *Client) StartAppMachine(ctx context.Context, appID, machineID string) error

func (*Client) StopAppMachine

func (c *Client) StopAppMachine(ctx context.Context, appID, machineID string) error

func (*Client) UncordonAppMachine

func (c *Client) UncordonAppMachine(ctx context.Context, appID, machineID string) error

type CreateAppArgs

type CreateAppArgs struct {
	AppName string `json:"app_name"`
	Network string `json:"network"`
	OrgSlug string `json:"org_slug"`
}

CreateAppArgs are the arguments to the CreateApp call.

type CreateAppResponse

type CreateAppResponse struct {
	ID        string    `json:"id"`
	CreatedAt MilliTime `json:"created_at"`
}

CreateAppResponse is the response from the CreateApp call.

type CreateMachine

type CreateMachine struct {
	Config                  MachineConfig `json:"config"`
	LeaseTTL                int           `json:"lease_ttl"`
	LSVD                    bool          `json:"lsvd"` // should be true?
	Name                    string        `json:"name"`
	Region                  string        `json:"region"`
	SkipLaunch              *bool         `json:"skip_launch,omitempty"`
	SkipServiceRegistration *bool         `json:"skip_service_registration,omitempty"`
}

type CreateVolume

type CreateVolume struct {
	Compute           *MachineGuest `json:"compute,omitempty"`
	Encrypted         bool          `json:"encrypted,omitempty"`
	FSType            string        `json:"fs_type,omitempty"`
	MachinesOnly      bool          `json:"machines_only,omitempty"`
	Name              string        `json:"name,omitempty"`
	Region            string        `json:"region,omitempty"`
	RequireUniqueZone bool          `json:"require_unique_zone"`
	SizeGB            int           `json:"size_gb,omitempty"`
	SnapshotID        string        `json:"snapshot_id,omitempty"`
	SnapshotRetention int           `json:"snapshot_retention"`
	SourceVolumeID    string        `json:"source_volume_id,omitempty"`
}

func (CreateVolume) Fork

func (cv CreateVolume) Fork(vol *Volume) CreateVolume

type Error

type Error struct {
	ErrorString string `json:"error"`
	StatusCode  int    `json:"status_code"`
	ReqID       string `json:"req_id"`
	Method      string `json:"method"`
	URL         string `json:"url"`
}

func (*Error) Error

func (e *Error) Error() string

func (*Error) LogValue

func (e *Error) LogValue() slog.Value

type ExtendVolumeResponse

type ExtendVolumeResponse struct {
	NeedsRestart bool   `json:"needs_restart"`
	Volume       Volume `json:"volume"`
}

type ImageRef

type ImageRef struct {
	Registry   string          `json:"registry"`
	Repository string          `json:"repository"`
	Tag        string          `json:"tag"`
	Digest     string          `json:"digest"`
	Labels     json.RawMessage `json:"labels"` // TODO(Xe): figure out what this is
}

type ListApp

type ListApp struct {
	App
	MachineCount int    `json:"machine_count"` // The number of machines associated with this app
	Network      string `json:"network"`       // The network this app is on
}

ListApp is a Fly app with extra information that is only shown when you're listing apps with GetApps.

type Machine

type Machine struct {
	ID         string         `json:"id"`
	Name       string         `json:"name"`
	State      string         `json:"state"`
	Region     string         `json:"region"`
	InstanceID string         `json:"instance_id"`
	PrivateIP  string         `json:"private_ip"`
	Config     MachineConfig  `json:"config"`
	ImageRef   ImageRef       `json:"image_ref"`
	CreatedAt  time.Time      `json:"created_at"`
	UpdatedAt  *time.Time     `json:"updated_at"`
	Events     []MachineEvent `json:"events"`
	Checks     []CheckStatus  `json:"checks"`
}

type MachineCheck

type MachineCheck struct {
	Type          string              `json:"type"`
	Interval      time.Duration       `json:"interval"`
	Timeout       time.Duration       `json:"timeout"`
	GracePeriod   time.Duration       `json:"grace_period"`
	Path          string              `json:"path"`
	TLSServerName *string             `json:"tls_server_name,omitempty"`
	TLSSkipVerify *bool               `json:"tls_skip_verify,omitempty"`
	Headers       []MachineHTTPHeader `json:"headers,omitempty"`
}

type MachineConfig

type MachineConfig struct {
	Env        map[string]string `json:"env"`
	Metadata   map[string]string `json:"metadata"`
	Mounts     []MachineMount    `json:"mounts,omitempty"`
	Image      string            `json:"image"`
	Restart    MachineRestart    `json:"restart"`
	Guest      MachineGuest      `json:"guest"`
	StopConfig MachineStopConfig `json:"stop_config"`
	Processes  []MachineProcess  `json:"processes,omitempty"`
}

type MachineEvent

type MachineEvent struct {
	ID        string          `json:"id"`
	Type      string          `json:"type"`
	Status    string          `json:"status"`
	Source    string          `json:"source"`
	Timestamp MilliTime       `json:"timestamp"`
	Request   json.RawMessage `json:"request"` // Request can be anything, so we just store it as a raw message
}

type MachineGuest

type MachineGuest struct {
	CPUKind          string   `json:"cpu_kind"` // "shared" or "performance"
	CPUs             int      `json:"cpus"`
	MemoryMB         int      `json:"memory_mb"`
	GPUKind          string   `json:"gpu_kind,omitempty"`
	KernelArgs       []string `json:"kernel_args,omitempty"`
	HostDedicationID string   `json:"host_dedication_id,omitempty"`
}

type MachineHTTPHeader

type MachineHTTPHeader struct {
	Name   string   `json:"name"`
	Values []string `json:"values"`
}

type MachineMount

type MachineMount struct {
	Encrypted bool   `json:"encrypted"`
	Path      string `json:"path"`
	SizeGB    int    `json:"size_gb"`
	Volume    string `json:"volume"`
	Name      string `json:"name"`
}

type MachinePort

type MachinePort struct {
	Port       int      `json:"port"`
	Handlers   []string `json:"handlers"`
	ForceHTTPS *bool    `json:"force_https,omitempty"`
	StartPort  *int     `json:"start_port,omitempty"`
	EndPort    *int     `json:"end_port,omitempty"`
}

type MachineProcess

type MachineProcess struct {
	Cmd        []string          `json:"cmd,omitempty"`
	Entrypoint []string          `json:"entrypoint,omitempty"`
	Env        map[string]string `json:"env,omitempty"`
	Exec       []string          `json:"exec,omitempty"`
	User       string            `json:"user,omitempty"`
}

type MachineRestart

type MachineRestart struct {
	MaxRetries int                  `json:"max_retries"` // only relevant when Policy is "on-fail"
	Policy     MachineRestartPolicy `json:"policy"`
}

type MachineRestartPolicy

type MachineRestartPolicy string
const (
	MachineRestartPolicyNo        MachineRestartPolicy = "no"
	MachineRestartPolicyAlways    MachineRestartPolicy = "always"
	MachineRestartPolicyOnFailure MachineRestartPolicy = "on-failure"
)

type MachineService

type MachineService struct {
	Protocol                 string                    `json:"protocol"`
	InternalPort             int                       `json:"internal_port"`
	ForceInstanceDescription *string                   `json:"force_instance_description,omitempty"`
	ForceInstanceKey         *string                   `json:"force_instance_key,omitempty"`
	Ports                    []MachinePort             `json:"ports"`
	Checks                   []MachineCheck            `json:"checks"`
	MinMachinesRunning       int                       `json:"min_machines_running"`
	Concurrency              MachineServiceConcurrency `json:"concurrency"`
}

type MachineServiceConcurrency

type MachineServiceConcurrency struct {
	Type      string `json:"type"`
	HardLimit int    `json:"hard_limit"`
	SoftLimit int    `json:"soft_limit"`
}

type MachineStopConfig

type MachineStopConfig struct {
	Timeout string `json:"timeout"`
	Signal  string `json:"signal"`
}

type MilliTime

type MilliTime struct {
	time.Time
}

MilliTime is a time.Time that can be marshalled and unmarshalled from milliseconds since the Unix epoch.

func (MilliTime) MarshalJSON

func (mt MilliTime) MarshalJSON() ([]byte, error)

func (*MilliTime) UnmarshalJSON

func (mt *MilliTime) UnmarshalJSON(b []byte) error

type Org

type Org struct {
	Name string `json:"name"`
	Slug string `json:"slug"`
}

Org is a Fly organization. An organization is a collection of apps and users that are allowed to manage that collection.

type SingleApp

type SingleApp struct {
	App
	Organization Org    `json:"organization"` // The organization this app belongs to
	Status       string `json:"status"`       // The current status of the app
}

SingleApp is a Fly app with extra information that is only shown when you're getting a single app with GetApp.

type Snapshot

type Snapshot struct {
	CreatedAt time.Time `json:"created_at"`
	Digest    string    `json:"digest"`
	ID        string    `json:"id"`
	Size      int       `json:"size"`
}

type Volume

type Volume struct {
	ID                string    `json:"id"`
	Name              string    `json:"name"`
	State             string    `json:"state"`
	SizeGB            int       `json:"size_gb"`
	Region            string    `json:"region"`
	Zone              string    `json:"zone"`
	Encrypted         bool      `json:"encrypted"`
	AttachedAllocID   string    `json:"attached_alloc_id"`
	AttachedMachineID string    `json:"attached_machine_id"`
	CreatedAt         time.Time `json:"created_at"`
	Blocks            int       `json:"blocks"`
	BlockSize         int       `json:"block_size"`
	BlocksAvail       int       `json:"blocks_avail"`
	BlocksFree        int       `json:"blocks_free"`
	FSType            string    `json:"fs_type"`
	SnapshotRetention int       `json:"snapshot_retention"`
	HostDedicationKey string    `json:"host_dedication_key,omitempty"`
}

Jump to

Keyboard shortcuts

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