clockworks

package
v1.9.2 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2024 License: MIT Imports: 24 Imported by: 1

Documentation

Overview

Package clockworks interacts with the Clockworks API service:

https://clockworks.oit.duke.edu/help/api_v1

Index

Constants

View Source
const AnyPatchWindow int = -1

AnyPatchWindow picks any available out of hours window

Variables

This section is empty.

Functions

func BindCreateVMCompletions added in v1.8.0

func BindCreateVMCompletions(cmd *cobra.Command, c *Client) error

BindCreateVMCompletions adds auto completion to the Create VM command

func BindDeleteVMCobra added in v1.7.0

func BindDeleteVMCobra(cmd *cobra.Command) error

BindDeleteVMCobra creates the required arguments for a delete VM request

func BindEditVMCobra added in v1.6.1

func BindEditVMCobra(cmd *cobra.Command) error

BindEditVMCobra creates the required arguments for a modify VM request

func BindNewVMCobra added in v1.6.0

func BindNewVMCobra(cmd *cobra.Command, client *Client) error

BindNewVMCobra creates the required arguments for a new VM to the given cobra.Command

func DoRequest

func DoRequest(ctx context.Context, req *http.Request) (*http.Response, error)

DoRequest executes a request with the default http client Do we really need this one? - DS

func DoRequestWithClient

func DoRequestWithClient(ctx context.Context, client *http.Client, req *http.Request) (*http.Response, error)

DoRequestWithClient submits an HTTP request using the specified client.

func NewVMCreateOpts added in v1.5.0

func NewVMCreateOpts[T VMCreateOpts](opts ...Option[T]) *T

NewVMCreateOpts uses functional options to return a new VMCreateOpts item

func NewVMDeleteOpts added in v1.5.0

func NewVMDeleteOpts[T VMDeleteOpts](opts ...Option[T]) *T

NewVMDeleteOpts creates a new VMDeleteOpts using functional options

func NewVMEditOpts added in v1.5.0

func NewVMEditOpts[T VMEditOpts](opts ...Option[T]) *T

NewVMEditOpts uses functional options to return a new VMEditOpts item

func NewVMListOpts added in v1.4.2

func NewVMListOpts[T VMListOpts](opts ...Option[T]) *T

NewVMListOpts generates a new VMListOpts object

func ProductionLevelCompletion added in v1.6.1

func ProductionLevelCompletion(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective)

ProductionLevelCompletion returns shell completion for the sysadmin options

func StorageTypeCompletion added in v1.6.0

func StorageTypeCompletion(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective)

StorageTypeCompletion returns shell completion for the storage options

func SysadminOptionCompletion added in v1.6.0

func SysadminOptionCompletion(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective)

SysadminOptionCompletion returns shell completion for the sysadmin options

func ValidatePatchWindowWithSysadminOption added in v1.5.0

func ValidatePatchWindowWithSysadminOption(p int, s SysadminOption) error

ValidatePatchWindowWithSysadminOption ensures these work together as expected

func WithEnv added in v1.5.0

func WithEnv() func(*Client)

WithEnv gets Username, Token and URL from environment variables

func WithErrWriter added in v1.5.0

func WithErrWriter(w io.Writer) func(*Client)

WithErrWriter sets the error writer to something custom

func WithLogger added in v1.9.1

func WithLogger(l *slog.Logger) func(*Client)

WithLogger sets the Logger on a new Client.

func WithReqWaitTimes added in v1.5.0

func WithReqWaitTimes(ts map[string]time.Duration) func(*Client)

WithReqWaitTimes overrides the default timing when waiting for a request to complete

func WithToken added in v1.5.0

func WithToken(t string) func(*Client)

WithToken passes the token in to a new client

func WithURL added in v1.5.0

func WithURL(u string) func(*Client)

WithURL passes the base url in to a new client

func WithUser added in v1.5.0

func WithUser(u string) func(*Client)

WithUser passes the username in to a new client

func WithViper added in v1.8.0

func WithViper(v *viper.Viper) func(*Client)

WithViper gets Username, Token and URL from Viper

Types

type AllowedBackups added in v1.6.0

type AllowedBackups int

AllowedBackups represents a range of backup types that a Location can have

const (
	// NoBackups is...no backups!
	NoBackups AllowedBackups = iota
	// Backups is on-site VM backups
	Backups
	// BackupsAndDR is on-site and offsite
	BackupsAndDR
)

func (*AllowedBackups) UnmarshalJSON added in v1.6.0

func (a *AllowedBackups) UnmarshalJSON(data []byte) error

UnmarshalJSON turns the int in to an actual AllowedBackups type

type CPU added in v1.5.0

type CPU int

CPU is the CPU count for a host

func (CPU) Validate added in v1.5.0

func (c CPU) Validate() error

Validate ensures this is set to something > 0

type Client

type Client struct {

	// Base URL for API requests.
	BaseURL *url.URL
	// baseURLString string
	Username string
	Token    string

	// User agent for client
	UserAgent string

	Location    LocationService
	PatchWindow PatchWindowService
	Container   ContainerService
	OS          OSService
	Network     NetworkService
	VMRequest   VMRequestService
	VM          VMService
	Logger      *slog.Logger
	// contains filtered or unexported fields
}

Client is the holder for all the services and methods for interacting with the API

func New added in v1.5.0

func New(opts ...func(*Client)) *Client

New uses functional options to create a new client

func NewFromEnvironment

func NewFromEnvironment() (c *Client, err error)

NewFromEnvironment is just a shortcut for New(WithEnv()) Keeping it around for backwards compatibility (for now...) Deprecated: Use New(WithEnv()) instead going forward

func (*Client) CheckResponse added in v1.9.0

func (c *Client) CheckResponse(r *http.Response) error

CheckResponse examines an http.Response and returns an error if it's not cool 😎

func (*Client) Do

func (c *Client) Do(ctx context.Context, req *http.Request, v interface{}) (*Response, error)

Do executes the http request

func (*Client) GuessPrimaryNetworkWithFQDN added in v1.4.14

func (c *Client) GuessPrimaryNetworkWithFQDN(ctx context.Context, fqdn string) (*Network, error)

GuessPrimaryNetworkWithFQDN attempts to find the primary network based off of the FQDN

func (*Client) GuessPrimaryNetworkWithVMId added in v1.4.15

func (c *Client) GuessPrimaryNetworkWithVMId(ctx context.Context, id int) (*Network, error)

GuessPrimaryNetworkWithVMId returns a network that is guessed using the VM ID

func (*Client) VMCreateOptsWithCmd added in v1.6.0

func (c *Client) VMCreateOptsWithCmd(cmd *cobra.Command, args []string) (*VMCreateOpts, error)

VMCreateOptsWithCmd creates a new VMCreatOpts with the cobra.Command info given

func (*Client) VMDeleteOptsWithCmd added in v1.7.0

func (c *Client) VMDeleteOptsWithCmd(cmd *cobra.Command, args []string) (*VMDeleteOpts, error)

VMDeleteOptsWithCmd returns a delete option with the given options

func (*Client) VMEditOptsWithCmd added in v1.6.1

func (c *Client) VMEditOptsWithCmd(cmd *cobra.Command, args []string) (*VMEditOpts, error)

VMEditOptsWithCmd returns an edit option with the given options

func (*Client) Validate added in v1.5.0

func (c *Client) Validate() error

Validate ensures that enough pieces of the client are set to use (Username and Token)

type CloudInitUserData added in v1.5.0

type CloudInitUserData string

CloudInitUserData is a non empty string

func (CloudInitUserData) Validate added in v1.5.0

func (r CloudInitUserData) Validate() error

Validate ensures this is set to a non empty string

type Container

type Container struct {
	Name string `json:"name,omitempty"`
}

Container is the clockworks 'container'

func NewContainer added in v1.5.0

func NewContainer(n string) *Container

NewContainer returns a new Container instance with the provided name

func (Container) ValidateWithSysadminOption added in v1.5.0

func (c Container) ValidateWithSysadminOption(s SysadminOption) error

ValidateWithSysadminOption returns an error if it's invalid

type ContainerService

type ContainerService interface {
	List(context.Context) ([]Container, *Response, error)
	ListNames(context.Context) ([]string, *Response, error)
	Get(context.Context, string) (*Container, *Response, error)
}

ContainerService holds on the methods for interacting with containers

type ContainerServiceOp

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

ContainerServiceOp is the operator for the ContainerService interface

func (*ContainerServiceOp) Get

Get returns a specific container object using it's name string

func (*ContainerServiceOp) List

List returns the container objects

func (*ContainerServiceOp) ListNames

func (s *ContainerServiceOp) ListNames(ctx context.Context) ([]string, *Response, error)

ListNames returns a list of the containers as strings

type DiskSet added in v1.5.0

type DiskSet []VMDisk

DiskSet describes a slice of VMDisks

func NewDiskSet added in v1.5.0

func NewDiskSet(sizes []int) DiskSet

NewDiskSet creates a new DiskSet with the given sizes in GB

func NewDiskSetPTR added in v1.5.0

func NewDiskSetPTR(sizes []int) *DiskSet

NewDiskSetPTR returns a pointer to a new disk set

func (DiskSet) Validate added in v1.5.0

func (ds DiskSet) Validate() error

Validate ensures that we have a good DiskSet

type ErrorResponse

type ErrorResponse struct {
	// HTTP response that caused this error
	Response *http.Response

	// Error message
	Message string   `json:"message"`
	Errors  []string `json:"errors"`
}

ErrorResponse holds the http response, and any additional metadata when an error is returned

func (*ErrorResponse) Error

func (r *ErrorResponse) Error() string

Error turns the response in to an Error

type FundCode added in v1.5.0

type FundCode string

FundCode is a the financial piece of a VM

func (FundCode) Validate added in v1.5.0

func (r FundCode) Validate() error

Validate ensures this is set to a non empty string

type Hostname added in v1.5.0

type Hostname string

Hostname represents a valid hostname for a Clockworks interaction

func (Hostname) Validate added in v1.5.0

func (h Hostname) Validate() error

Validate returns an error when the hostname is invalid

type Location

type Location struct {
	ID                int            `json:"id"`
	ParentLocation    int            `json:"parent_location,omitempty"`
	MemGBCapacity     int            `json:"mem_gb_capacity,omitempty"`
	MemGBUsed         int            `json:"mem_gb_used,omitempty"`
	CPUUsed           int            `json:"cpu_used,omitempty"`
	MinAllowedBackups AllowedBackups `json:"min_allowed_backups,omitempty"`
	MaxAllowedBackups AllowedBackups `json:"max_allowed_backups,omitempty"`
	IsCluster         bool           `json:"is_cluster,omitempty"`
	Type              string         `json:"type,omitempty"`
	VCenterFQDN       string         `json:"vcenter_fqdn,omitempty"`
	DisplayName       string         `json:"display_name,omitempty"`
	ClusterName       string         `json:"cluster_name,omitempty"`
	ChildLocations    []interface{}  `json:"child_locations,omitempty"`
	Datastores        []string       `json:"datastores,omitempty"`
	Tags              []string       `json:"tags,omitempty"`
}

Location represents a Location item in Clockworks

func (*Location) CanBackup added in v1.6.0

func (l *Location) CanBackup() bool

CanBackup returns a boolean representing if normal backups can be performed on VMSs in this location

func (*Location) CanDR added in v1.6.0

func (l *Location) CanDR() bool

CanDR returns a boolean representing if disaster recovery can be performed on VMS in this location

func (*Location) InferredBackup added in v1.6.0

func (l *Location) InferredBackup() bool

InferredBackup returns true if the location has a >= min_allowed_backups of 1

func (*Location) InferredDR added in v1.6.0

func (l *Location) InferredDR() bool

InferredDR returns true if the location has a >= min_allowed_backups of 2

type LocationID added in v1.5.0

type LocationID int

LocationID is the ID of the location for a VM

func (LocationID) Validate added in v1.5.0

func (l LocationID) Validate() error

Validate ensures this is set to something > 0

type LocationListVMOpt

type LocationListVMOpt struct {
	ShowDeleted  bool `url:"show_deleted"`
	ShowArchived bool `url:"show_archived"`
	ShowLive     bool `url:"show_live"`
}

LocationListVMOpt are the options that can be passed to the LocationList service

type LocationService

type LocationService interface {
	List(context.Context) ([]Location, *Response, error)
	ListIds(context.Context) ([]int, *Response, error)
	ListWithNetwork(context.Context, string) ([]Location, *Response, error)
	ListDisplayNames(context.Context) ([]string, *Response, error)
	Get(context.Context, int) (*Location, *Response, error)
	GetWithName(context.Context, string) (*Location, *Response, error)
	DisplayNameMap(context.Context) (map[string]int, *Response, error)
	ShellComplete(context.Context, string) []string
}

LocationService holds on the methods for interacting with the Location endpoint in Clockworks

type LocationServiceOp

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

LocationServiceOp is the operator for the LocationServic

func (*LocationServiceOp) DisplayNameMap

func (s *LocationServiceOp) DisplayNameMap(ctx context.Context) (map[string]int, *Response, error)

DisplayNameMap returns a map of the locations, using the DisplayName as the key and the ID as the value

func (*LocationServiceOp) Get

func (s *LocationServiceOp) Get(ctx context.Context, id int) (*Location, *Response, error)

Get returns a single Location using it's ID

func (*LocationServiceOp) GetWithName added in v1.6.0

func (s *LocationServiceOp) GetWithName(ctx context.Context, name string) (*Location, *Response, error)

GetWithName returns a single location using it's Name

func (*LocationServiceOp) List

List returns a list of all locations

func (*LocationServiceOp) ListDisplayNames

func (s *LocationServiceOp) ListDisplayNames(ctx context.Context) ([]string, *Response, error)

ListDisplayNames returns a list of the display names for a location

func (*LocationServiceOp) ListIds

func (s *LocationServiceOp) ListIds(ctx context.Context) ([]int, *Response, error)

ListIds returns just the ids for the locations

func (*LocationServiceOp) ListWithNetwork

func (s *LocationServiceOp) ListWithNetwork(ctx context.Context, name string) ([]Location, *Response, error)

ListWithNetwork returns the Locations for a given network

func (*LocationServiceOp) ShellComplete added in v1.6.1

func (s *LocationServiceOp) ShellComplete(ctx context.Context, filter string) []string

ShellComplete provides shell complete functionality for Locations

type Network

type Network struct {
	ID     int    `json:"id"`
	Subnet string `json:"subnet,omitempty"`
	Name   string `json:"name,omitempty"`
	Type   string `json:"type,omitempty"`
	VRF    string `json:"vrf,omitempty"`
}

Network is the object that represents a Clockworks Network

type NetworkService

type NetworkService interface {
	List(context.Context) ([]Network, *Response, error)
	ListCIDRs(context.Context) ([]string, *Response, error)
	ListWithLocation(context.Context, int) ([]Network, *Response, error)
	Get(context.Context, string) (*Network, *Response, error)
	ShellComplete(context.Context, string) []string
}

NetworkService holds on the methods for interacting with the Network endpoint

type NetworkServiceOp

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

NetworkServiceOp is the operator for the NetworkService

func (*NetworkServiceOp) Get

func (s *NetworkServiceOp) Get(ctx context.Context, name string) (*Network, *Response, error)

Get returns a single Network object given a name

func (*NetworkServiceOp) List

func (s *NetworkServiceOp) List(ctx context.Context) ([]Network, *Response, error)

List returns a slice of all Network objects

func (*NetworkServiceOp) ListCIDRs

func (s *NetworkServiceOp) ListCIDRs(ctx context.Context) ([]string, *Response, error)

ListCIDRs returns a list of CIDRS

func (*NetworkServiceOp) ListWithLocation

func (s *NetworkServiceOp) ListWithLocation(ctx context.Context, id int) ([]Network, *Response, error)

ListWithLocation returns a list of networks given a location ID

func (*NetworkServiceOp) ShellComplete added in v1.6.1

func (s *NetworkServiceOp) ShellComplete(ctx context.Context, filter string) []string

ShellComplete provides shell completion for VM stuff

type NetworkType added in v1.5.0

type NetworkType int

NetworkType is the base type for a Network configuration option in Clockworks

const (
	// NullNetwork is the empty NetworkType
	NullNetwork NetworkType = iota
	// PublicNetwork will use any available public network
	PublicNetwork
	// PrivateNetwork will use any available private network
	PrivateNetwork
	// CustomNetwork will use a given network
	CustomNetwork
)

func NetworkTypeWithString added in v1.5.1

func NetworkTypeWithString(s string) NetworkType

NetworkTypeWithString returns a NetworkType using the given string

func (*NetworkType) MarshalJSON added in v1.5.0

func (n *NetworkType) MarshalJSON() ([]byte, error)

MarshalJSON ensures that json conversions use the string value here, not the int value

func (NetworkType) String added in v1.5.0

func (n NetworkType) String() string

func (NetworkType) ValidateWithSubnet added in v1.5.0

func (n NetworkType) ValidateWithSubnet(s string) error

ValidateWithSubnet ensures that a subnet is valid for a given NetworkType

type OS

type OS struct {
	APIOnly          bool   `json:"api_only,omitempty"`
	Family           string `json:"family,omitempty"`
	FullName         string `json:"full_name,omitempty"`
	ID               int    `json:"id,omitempty"`
	InitScript       string `json:"init_script,omitempty"`
	Movement         string `json:"movement,omitempty"`
	OSId             string `json:"os_id,omitempty"`
	SCCMCollectionID string `json:"sccm_collection_id,omitempty"`
	SSIManaged       bool   `json:"ssi_managed,omitempty"`
	SSIOnly          bool   `json:"ssi_only,omitempty"`
	Template         string `json:"template,omitempty"`
}

OS Represents an Operating Systems from Clockworks

type OSID added in v1.5.0

type OSID string

OSID is the ID of a Operating System for a new VM

func (OSID) Validate added in v1.5.0

func (o OSID) Validate() error

Validate ensures this is set to a non empty string

type OSService

type OSService interface {
	List(context.Context) ([]OS, *Response, error)
	ListIds(context.Context) ([]string, *Response, error)
	Get(context.Context, string) (*OS, *Response, error)
	ShellComplete(context.Context, string) []string
}

OSService holds all of the OS related methods

type OSServiceOp

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

OSServiceOp is the operator for the OSService

func (*OSServiceOp) Get

func (s *OSServiceOp) Get(ctx context.Context, name string) (*OS, *Response, error)

Get returns a specific OS based on the given name

func (*OSServiceOp) List

func (s *OSServiceOp) List(ctx context.Context) ([]OS, *Response, error)

List returns all the OSes

func (*OSServiceOp) ListIds

func (s *OSServiceOp) ListIds(ctx context.Context) ([]string, *Response, error)

ListIds returns a list of IDs for the OSes

func (*OSServiceOp) ShellComplete added in v1.6.1

func (s *OSServiceOp) ShellComplete(ctx context.Context, filter string) []string

ShellComplete provides shell complete functionality for Locations

type Option added in v1.5.0

type Option[T VMCreateOpts | VMEditOpts | VMListOpts | VMDeleteOpts] func(*T)

Option is a generic that we can pass in to things like VM create/edit/etc

func WithApplication added in v1.6.0

func WithApplication[T VMCreateOpts](f string) Option[T]

WithApplication sets the application for a new request

func WithArchiveDeleteTime added in v1.5.0

func WithArchiveDeleteTime[T VMDeleteOpts](n time.Time) Option[T]

WithArchiveDeleteTime sets the archive_delete_time for a delete request

func WithArchived added in v1.5.0

func WithArchived[T VMListOpts]() Option[T]

WithArchived sets the show_archived to true for a filter option

func WithBackups added in v1.6.0

func WithBackups[T VMCreateOpts]() Option[T]

WithBackups sets the backups value to 'true'

func WithCPU added in v1.5.0

func WithCPU[T VMCreateOpts | VMEditOpts](c int) Option[T]

WithCPU sets the CPU in a request

func WithCloudInitUserData added in v1.5.0

func WithCloudInitUserData[T VMCreateOpts](c string) Option[T]

WithCloudInitUserData sets the cloud_init_user_data in a new request

func WithContainer added in v1.6.0

func WithContainer[T VMCreateOpts](f string) Option[T]

WithContainer sets the VMware container for the given VM

func WithDeleteArchiveAfter added in v1.7.0

func WithDeleteArchiveAfter(n time.Duration) Option[VMDeleteOpts]

WithDeleteArchiveAfter waits the given duration after a VM is deleted, before starting the archive deletion

func WithDeleted added in v1.5.0

func WithDeleted[T VMListOpts]() Option[T]

WithDeleted sets the show_deleted to true for a filter option

func WithDetails added in v1.5.0

func WithDetails[T VMListOpts]() Option[T]

WithDetails sets hide_details to false in a VM listing

func WithDisasterRecovery added in v1.6.0

func WithDisasterRecovery[T VMCreateOpts]() Option[T]

WithDisasterRecovery sets the disaster_recovery value to 'true'

func WithDisks added in v1.5.0

func WithDisks[T VMCreateOpts | VMEditOpts](disks DiskSet) Option[T]

WithDisks sets the initial disk sizes for a new VM request

func WithFundCode added in v1.5.0

func WithFundCode[T VMCreateOpts | VMEditOpts](f string) Option[T]

WithFundCode sets the fund_code for a new request

func WithHostname added in v1.5.0

func WithHostname[T VMCreateOpts](h string) Option[T]

WithHostname sets a hostname in the VMCreateOpts

func WithIPAddress added in v1.5.0

func WithIPAddress[T VMListOpts](n string) Option[T]

WithIPAddress sets the ipaddress for a filter option

func WithLocation added in v1.6.0

func WithLocation[T VMCreateOpts | VMListOpts](l Location) Option[T]

WithLocation specifies the location of a new VM. This will also set the backup and disasaster_recovery flags based off of the locations capabilities

func WithName added in v1.5.0

func WithName[T VMListOpts](n string) Option[T]

WithName sets the name for a filter option

func WithNetworkType added in v1.5.0

func WithNetworkType[T VMCreateOpts](n NetworkType) Option[T]

WithNetworkType specifies the network_type for a new request

func WithOSID added in v1.5.0

func WithOSID[T VMCreateOpts](h string) Option[T]

WithOSID sets a os_id in the VMCreateOpts

func WithOnBehalfOf added in v1.6.0

func WithOnBehalfOf[T VMCreateOpts](f string) Option[T]

WithOnBehalfOf sets the on_behalf_of for a new request

func WithPatchWindowID added in v1.5.0

func WithPatchWindowID[T VMCreateOpts](p int) Option[T]

WithPatchWindowID sets the patch_window_id in a new request

func WithPoweroffAllowed added in v1.5.0

func WithPoweroffAllowed[T VMEditOpts]() Option[T]

WithPoweroffAllowed will set poweroff_allowed to true in a VM request

func WithProductionLevel added in v1.6.0

func WithProductionLevel[T VMCreateOpts](f ProductionLevel) Option[T]

WithProductionLevel sets the application for a new request

func WithRAM added in v1.5.0

func WithRAM[T VMCreateOpts | VMEditOpts](r int) Option[T]

WithRAM sets the ram in a request

func WithSecureProjectID added in v1.6.0

func WithSecureProjectID[T VMCreateOpts](c int) Option[T]

WithSecureProjectID sets the secure_project_id in a request

func WithSkipFinalize added in v1.5.0

func WithSkipFinalize[T VMCreateOpts]() Option[T]

WithSkipFinalize sets the skip_finalize value to 'true'

func WithStartTime added in v1.7.0

func WithStartTime[T VMEditOpts | VMCreateOpts | VMDeleteOpts, V time.Time | string](n V) Option[T]

WithStartTime sets the start_time for a request

func WithStorageType added in v1.5.0

func WithStorageType[T VMCreateOpts | VMEditOpts](s StorageType) Option[T]

WithStorageType sets the storage_type in a new request

func WithSubnet added in v1.6.0

func WithSubnet[T VMCreateOpts](f string) Option[T]

WithSubnet sets the subnet for the given VM

func WithSysadminOption added in v1.5.0

func WithSysadminOption[T VMCreateOpts | VMEditOpts](s SysadminOption) Option[T]

WithSysadminOption sets the sysadmin_option_id in a new request

func WithSysadminnedBy added in v1.5.0

func WithSysadminnedBy[T VMListOpts](n string) Option[T]

WithSysadminnedBy sets the sysadminned_by for a filter option

func WithoutLive added in v1.5.0

func WithoutLive[T VMListOpts]() Option[T]

WithoutLive sets the show_live to false for a filter option

func WithoutValidate added in v1.6.0

func WithoutValidate[T VMCreateOpts]() Option[T]

WithoutValidate skips any attempt to validate the request before it is sent on to Clockworks. Useful for less wordy testing, or if the validation logic breaks before we can ship a fix

type PatchWindow

type PatchWindow struct {
	ID   float64 `json:"id,omitempty"`
	Name string  `json:"name,omitempty"`
}

PatchWindow represents a Patchmonkey Window from Clockworks

type PatchWindowService

type PatchWindowService interface {
	List(context.Context) ([]PatchWindow, *Response, error)
	ListIds(context.Context) ([]int, *Response, error)
	ShellComplete(context.Context, string) []string
}

PatchWindowService contains all the PatchWindow methods

type PatchWindowServiceOp

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

PatchWindowServiceOp is the operator for the PatchWindowService

func (*PatchWindowServiceOp) List

List returns all PatchWindows

func (*PatchWindowServiceOp) ListIds

func (s *PatchWindowServiceOp) ListIds(ctx context.Context) ([]int, *Response, error)

ListIds returns a list of all PatchWindow IDs

func (*PatchWindowServiceOp) ShellComplete added in v1.6.1

func (s *PatchWindowServiceOp) ShellComplete(ctx context.Context, filter string) []string

ShellComplete provides shell completion for VM stuff

type ProductionLevel added in v1.5.0

type ProductionLevel int

ProductionLevel represents the production level status of a VM

const (
	// NullProductionLevel is the unset value for this type
	NullProductionLevel ProductionLevel = iota
	// Production is...prime time production my folks!
	Production
	// Testing is for testing changes before pushing to production
	Testing
	// Development is for breaking changes
	Development
)

func (*ProductionLevel) MarshalJSON added in v1.6.2

func (p *ProductionLevel) MarshalJSON() ([]byte, error)

MarshalJSON ensures that json conversions use the string value here, not the int value

func (*ProductionLevel) Set added in v1.6.1

func (p *ProductionLevel) Set(v string) error

Set helps fulfill the pflag.Value interface

func (ProductionLevel) String added in v1.5.0

func (p ProductionLevel) String() string

func (ProductionLevel) Type added in v1.6.1

func (p ProductionLevel) Type() string

Type satisfies part of the pflags.Value interface

type RAM added in v1.5.0

type RAM int

RAM is the amount of RAM for a machine

func (RAM) Validate added in v1.5.0

func (r RAM) Validate() error

Validate ensures this is set to something > 0

type Response

type Response struct {
	*http.Response
}

Response is just a holder for the response and any metadata we wanna keep

type StorageType added in v1.5.0

type StorageType int

StorageType represents one of the storage classes in Clockworks

const (
	// NullStorageType is the unset Storage Type
	NullStorageType StorageType = iota
	// PlatinumStorage is the all flash array
	PlatinumStorage
	// SilverStorage is the 'fast' array
	SilverStorage
	// BronzeStorage is 'slow', but actually still pretty fast
	BronzeStorage
)

func StorageTypeWithString added in v1.5.1

func StorageTypeWithString(s string) StorageType

StorageTypeWithString returns a storage type using the given string.

func (*StorageType) MarshalJSON added in v1.5.0

func (s *StorageType) MarshalJSON() ([]byte, error)

MarshalJSON ensures that json conversions use the string value here, not the int value

func (*StorageType) Set added in v1.6.0

func (s *StorageType) Set(v string) error

Set helps fulfill the pflag.Value interface

func (StorageType) String added in v1.5.0

func (s StorageType) String() string

func (*StorageType) Type added in v1.6.0

func (s *StorageType) Type() string

Type is used in the help for pflag.Value

func (StorageType) Validate added in v1.5.0

func (s StorageType) Validate() error

Validate returns an error if empty

type SysadminOption added in v1.5.0

type SysadminOption int

SysadminOption is the type of support for a given VM

[1 == self-admin, 2 == 8/5, 3 == 24/7, 4 == 8/5 web, 5 == 24/7 web]
const (
	// NullSupport is the unset value
	NullSupport SysadminOption = iota
	// SelfAdminSupport is user supported, no ssi
	SelfAdminSupport
	// WorkHoursGeneralSupport is general 8-5 support
	WorkHoursGeneralSupport
	// FullGeneralSupport is 24/7 general support
	FullGeneralSupport
	// WorkHoursWebSupport is web supported 8-5
	WorkHoursWebSupport
	// FullWebSupport is 24/7 web support
	FullWebSupport
)

func (*SysadminOption) Set added in v1.6.0

func (s *SysadminOption) Set(v string) error

Set helps fulfill the pflag.Value interface

func (SysadminOption) String added in v1.6.0

func (s SysadminOption) String() string

String returns the string representing a given SupportOption

func (*SysadminOption) Type added in v1.6.0

func (s *SysadminOption) Type() string

Type is used in the help for pflag.Value

func (SysadminOption) Validate added in v1.5.0

func (s SysadminOption) Validate() error

Validate ensures this is set

type VM

type VM struct {
	ID                int      `json:"id"`
	Name              string   `json:"name,omitempty"`
	GuestFqdn         string   `json:"guest_fqdn,omitempty"`
	MemGB             float64  `json:"mem_gb,omitempty"` // MemGB looks like an int in test, but is in fact a float
	MemMB             int      `json:"mem_mb,omitempty"`
	LocationID        int      `json:"location_id,omitempty"`
	CPU               int      `json:"cpu,omitempty"`
	PatchWindowID     int      `json:"patch_window_id,omitempty"`
	SysadminOptionID  int      `json:"sysadmin_option_id,omitempty"`
	SelfAdmin         bool     `json:"self_admin,omitempty"`
	Folder            string   `json:"folder,omitempty"`
	FundCode          string   `json:"fund_code,omitempty"`
	UUID              string   `json:"uuid,omitempty"`
	SerialNumber      string   `json:"serial_number,omitempty"`
	Type              string   `json:"type,omitempty"`
	MoRef             string   `json:"mo_ref,omitempty"`
	MobURL            string   `json:"mob_url,omitempty"`
	WebURL            string   `json:"web_url,omitempty"`
	APIURL            string   `json:"api_url,omitempty"`
	ServiceLevel      string   `json:"service_level,omitempty"`
	StorageType       string   `json:"storage_type,omitempty"`
	ProductionLevel   string   `json:"production_level,omitempty"`
	ToolsStatus       string   `json:"tools_status,omitempty"`
	OSId              string   `json:"os_id,omitempty"`
	OsOptionID        string   `json:"os_option_id,omitempty"`
	CloudInitUserData string   `json:"cloud_init_user_data,omitempty"`
	Disks             []VMDisk `json:"disks,omitempty"`
	SysadminNetids    []string `json:"sysadmin_netids,omitempty"`
	AppAdminNetids    []string `json:"app_admin_netids,omitempty"`
	MacAddresses      []string `json:"mac_addresses,omitempty"`
	IPAddresses       []string `json:"ip_addresses,omitempty"`
}

VM represents a VM inside of Clockworks

type VMCreateOpts

type VMCreateOpts struct {
	CPU               CPU               `json:"cpu,omitempty"`
	LocationID        LocationID        `json:"location_id,omitempty"`
	PatchWindowID     int               `json:"patch_window_id,omitempty"`
	RAM               RAM               `json:"ram,omitempty"`
	SecureProjectID   int               `json:"secure_project_id,omitempty"`
	SysadminOptionID  SysadminOption    `json:"sysadmin_option_id,omitempty"`
	Backups           bool              `json:"backups,omitempty"`
	DisasterRecovery  bool              `json:"disaster_recovery,omitempty"`
	SkipFinalize      bool              `json:"skip_finalize,omitempty"`
	OSID              OSID              `json:"os_id,omitempty"`
	Hostname          Hostname          `json:"hostname,omitempty"`
	FundCode          FundCode          `json:"fund_code,omitempty"`
	NetworkType       NetworkType       `json:"network_type,omitempty"`
	Subnet            string            `json:"subnet,omitempty"`
	ContainerName     string            `json:"container_name,omitempty"`
	CloudInitUserData CloudInitUserData `json:"cloud_init_user_data,omitempty"`
	ProductionLevel   ProductionLevel   `json:"production_level,omitempty"`
	StorageType       StorageType       `json:"storage_type,omitempty"`
	ApplicationName   string            `json:"application_name,omitempty"`
	Disks             DiskSet           `json:"disks,omitempty"`
	OnBehalfOf        string            `json:"on_behalf_of,omitempty"`
	StartTime         *time.Time        `json:"start_time,omitempty"`
	// contains filtered or unexported fields
}

VMCreateOpts specifies options for creating a new VM

func (VMCreateOpts) Validate added in v1.5.0

func (opt VMCreateOpts) Validate() error

Validate Loops through various validators and makes sure a VMCreate request is ok Wondering if we should move this to the VMCreateOpts object instead of having a public method for this - DS

type VMDeleteOpts

type VMDeleteOpts struct {
	ArchiveDeleteTime *time.Time `json:"archive_delete_time,omitempty"`
	StartTime         *time.Time `json:"start_time,omitempty"`
}

VMDeleteOpts defines options for deleting a VM

type VMDisk

type VMDisk struct {
	DiskID int `json:"disk_id,omitempty"`
	SizeGB int `json:"size_gb,omitempty"`
}

VMDisk contains the information needed for interacting with disks on a VM inside of Clockworks

func NewDisk added in v1.5.0

func NewDisk(s int) VMDisk

NewDisk creates a new VMDisk object, with a given size in GB

func NewDiskWithID added in v1.8.0

func NewDiskWithID(s int, id int) VMDisk

NewDiskWithID creates a new VMDisk object with the given size and id

type VMEditOpts

type VMEditOpts struct {
	FundCode         FundCode       `json:"fund_code,omitempty"`
	RAM              RAM            `json:"ram,omitempty"`
	CPU              CPU            `json:"cpu,omitempty"`
	Disks            *DiskSet       `json:"disks,omitempty"`
	StorageType      StorageType    `json:"storage_type,omitempty"`
	SysadminOptionID SysadminOption `json:"sysadmin_option_id,omitempty"`
	PoweroffAllowed  bool           `json:"poweroff_allowed"`
	StartTime        *time.Time     `json:"start_time,omitempty"`
}

VMEditOpts defines options for editing a VM

func (*VMEditOpts) Validate

func (v *VMEditOpts) Validate() error

Validate makes sure we aren't just passing an empty one in here with no changes

type VMListOpts

type VMListOpts struct {
	Name          string     `url:"name,omitempty"`
	SysadminnedBy string     `url:"sysadminned_by,omitempty"`
	HideDetails   bool       `url:"hide_details"`
	ShowDeleted   bool       `url:"show_deleted"`
	ShowArchived  bool       `url:"show_archived"`
	ShowLive      bool       `url:"show_live"`
	LocationID    LocationID `url:"location_id,omitempty"`
	IPAddress     string     `url:"ip_address,omitempty"`
}

VMListOpts are the options for listing VMs

type VMRequest

type VMRequest struct {
	APIUserNetid       string `json:"api_user_netid,omitempty"`
	ApproverID         string `json:"approver_id,omitempty"`
	ApproverNetid      string `json:"approver_netid,omitempty"`
	Comments           string `json:"comments,omitempty"`
	CreatedAt          string `json:"created_at,omitempty"`
	DateRequested      string `json:"date_requested,omitempty"`
	DateStarted        string `json:"date_started,omitempty"`
	Hostname           string `json:"hostname,omitempty"`
	ID                 int    `json:"id,omitempty"`
	OldVMRequestInfoID int    `json:"old_vm_request_info_id,omitempty"`
	ScheduledStart     string `json:"scheduled_start,omitempty"`
	SensitiveData      bool   `json:"sensitive_data,omitempty"`
	SkipFinalize       bool   `json:"skip_finalize,omitempty"`
	SnRequestID        string `json:"sn_request_id,omitempty"`
	Status             string `json:"status,omitempty"`
	StepID             int    `json:"step_id,omitempty"`
	Type               string `json:"type,omitempty"`
	UpdatedAt          string `json:"updated_at,omitempty"`
	UserID             int    `json:"user_id,omitempty"`
	UserNetid          string `json:"user_netid,omitempty"`
	VMID               int    `json:"vm_id,omitempty"`
	VMRequestInfoID    int    `json:"vm_request_info_id,omitempty"`
}

VMRequest holds all the information needed for a VMRequest

type VMRequestListOpts

type VMRequestListOpts struct {
	Status string `url:"status,omitempty"`
}

VMRequestListOpts is the config for a VMRequestList

type VMRequestResponse

type VMRequestResponse struct {
	SNRequestID     string   `json:"sn_request_id,omitempty"`
	VMRequestAPIURL string   `json:"vm_request_api_url,omitempty"`
	VMRequestID     int      `json:"vm_request_id,omitempty"`
	VMRequestWebURL string   `json:"vm_request_web_url,omitempty"`
	Errors          []string `json:"errors,omitempty"`
}

VMRequestResponse is the response to a VMRequest

type VMRequestService

type VMRequestService interface {
	List(context.Context, *VMRequestListOpts) ([]VMRequest, *Response, error)
	ListWithVMId(context.Context, int, *VMRequestListOpts) ([]VMRequest, *Response, error)
	Get(context.Context, int) (*VMRequest, *Response, error)
	WaitForFinalStatusTUI(context.Context, int) error
	WaitForFinalStatus(context.Context, int) error
}

VMRequestService contains all of the methods for a VMRequest

type VMRequestServiceOp

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

VMRequestServiceOp is the operator for the VMRequestService

func (*VMRequestServiceOp) Get

func (s *VMRequestServiceOp) Get(ctx context.Context, name int) (*VMRequest, *Response, error)

Get returns a specific VMRequest, given the ID

func (*VMRequestServiceOp) List

List returns all VMRequests

func (*VMRequestServiceOp) ListWithVMId

func (s *VMRequestServiceOp) ListWithVMId(ctx context.Context, id int, opt *VMRequestListOpts) ([]VMRequest, *Response, error)

ListWithVMId returns a list of VMRequests with a given VM ID

func (*VMRequestServiceOp) WaitForFinalStatus

func (s *VMRequestServiceOp) WaitForFinalStatus(ctx context.Context, id int) error

WaitForFinalStatus just waits for a completed status

func (*VMRequestServiceOp) WaitForFinalStatusTUI

func (s *VMRequestServiceOp) WaitForFinalStatusTUI(ctx context.Context, id int) error

WaitForFinalStatusTUI - Blocks until a VMRequest is in a final status. Usually completed or errored in a TUI

type VMService

type VMService interface {
	// Read only Operations
	List(context.Context, *VMListOpts) ([]VM, *Response, error)
	ListWithLocation(context.Context, int, *LocationListVMOpt) ([]VM, *Response, error)
	Get(context.Context, int) (*VM, *Response, error)
	GetWithFQDN(context.Context, string) (*VM, *Response, error)
	GetIDWithFQDN(context.Context, string, *VMListOpts) (int, *Response, error)

	// Shell Helpers
	ShellComplete(context.Context, string) []string

	// Edit Operations
	Edit(context.Context, int, *VMEditOpts) (*VMRequestResponse, *Response, error)
	Delete(context.Context, int, *VMDeleteOpts) (*VMRequestResponse, *Response, error)
	Create(context.Context, *VMCreateOpts) (*VMRequestResponse, *Response, error)
}

VMService contains all the methods needed for interacting with the VM endpoint

type VMServiceOp

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

VMServiceOp is the operator for the VMService

func (*VMServiceOp) Create

Create will create a VM with the given VMCreateOpts

func (*VMServiceOp) Delete

func (s *VMServiceOp) Delete(ctx context.Context, vmid int, opt *VMDeleteOpts) (*VMRequestResponse, *Response, error)

Delete deletes a VM

func (*VMServiceOp) Edit

func (s *VMServiceOp) Edit(ctx context.Context, vmid int, opt *VMEditOpts) (*VMRequestResponse, *Response, error)

Edit allows modification to a VM given the ID and VMEditOpts

func (*VMServiceOp) Get

func (s *VMServiceOp) Get(ctx context.Context, name int) (*VM, *Response, error)

Get returns a single VM from the ID

func (*VMServiceOp) GetIDWithFQDN

func (s *VMServiceOp) GetIDWithFQDN(ctx context.Context, fqdn string, opt *VMListOpts) (int, *Response, error)

GetIDWithFQDN Given the FQDN of a host, return the clockworks ID.

func (*VMServiceOp) GetWithFQDN

func (s *VMServiceOp) GetWithFQDN(ctx context.Context, fqdn string) (*VM, *Response, error)

GetWithFQDN returns a VM after being given the FQDN

func (*VMServiceOp) List

func (s *VMServiceOp) List(ctx context.Context, opt *VMListOpts) ([]VM, *Response, error)

List will return all VMs matching the passed options

func (*VMServiceOp) ListWithLocation

func (s *VMServiceOp) ListWithLocation(ctx context.Context, id int, c *LocationListVMOpt) ([]VM, *Response, error)

ListWithLocation returns a list of VMs given the location id and list options

func (*VMServiceOp) ShellComplete added in v1.6.1

func (s *VMServiceOp) ShellComplete(ctx context.Context, filter string) []string

ShellComplete provides shell completion for VM stuff

type Validator added in v1.5.0

type Validator interface {
	Validate() error
}

Validator is an interface that describes a...Validator

Jump to

Keyboard shortcuts

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