vcdusage

package module
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2025 License: BSD-3-Clause-Clear Imports: 11 Imported by: 0

README

stellar

go-vcdusage

Go Reference GitHub Tag

Testing Environment Variables

The following environment variables must be set (and valid) for tests to run.

Key Description
VCD_URL vCloud URL
VCD_USERNAME vCloud Username
VCD_PASSWORD vCloud Password
VCD_ORG_ID vCloud Org ID to test against
VCD_CORES Number of allocated cores in vCloud Org
VCD_MEMORY Amount of allocated memory in vCloud Org
VCD_STORAGE Amount allocated storage in vCloud Org
VCD_VM_COUNT Number of VMs in vCloud Org

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCfgNoPassword = errors.New("password required")

ErrCfgNoPassword indicates an authentication password was not provided.

View Source
var ErrCfgNoURL = errors.New("URL required")

ErrCfgNoURL indicates a URL was not provided.

View Source
var ErrCfgNoUsername = errors.New("username required")

ErrCfgNoUsername indicates an authentication username was not provided.

Functions

func ParseURL

func ParseURL(u string) (*url.URL, error)

ParseURL parses a vCloud URL from a string to a *url.URL, sets the appropriate URI schema, and sets the correct path.

Types

type Client

type Client struct {
	VCD *govcd.VCDClient
}

func New

func New(options ...Option) (*Client, error)

Create a new VCD Usage client.

func (*Client) Org

func (client *Client) Org(orgID string) (*govcd.AdminOrg, error)

Org retrieves a vCloud Organization object.

func (*Client) VDC

func (client *Client) VDC(orgID string, id string) (*VDC, error)

VDC retrieves a single VDC associated with an organization by its ID and provides a wrapper for utilization functions for each VDC.

func (*Client) VDCs

func (client *Client) VDCs(orgID string) (VDCs, error)

VDCs retrieves all VDCs associated with an organization and provides a wrapper for utilization functions for each VDC.

type DataStorage

type DataStorage float64

DataStorage is a representation of a data storage amount in bytes.

func (DataStorage) Float64

func (d DataStorage) Float64() float64

Float64 converts the DataStorage value to float64.

func (DataStorage) GB

func (d DataStorage) GB() float64

GB converts the DataStorage value to GB as float64 with 0 decimal points.

func (DataStorage) Int64

func (d DataStorage) Int64() int64

Int64 converts the DataStorage value to int64.

func (DataStorage) KB

func (d DataStorage) KB() float64

KB converts the DataStorage value to KB as float64 with 0 decimal points.

func (DataStorage) MB

func (d DataStorage) MB() float64

MB converts the DataStorage value to MB as float64 with 0 decimal points.

func (DataStorage) String

func (d DataStorage) String() string

String converts the DataStorage value to string.

func (DataStorage) TB

func (d DataStorage) TB() float64

TB converts the DataStorage value to TB as float64 with a maximum of 2 decimal points.

func (DataStorage) Uint64

func (d DataStorage) Uint64() uint64

Uint64 converts the DataStorage value to uint64.

type Option

type Option func(*Options)

func Insecure

func Insecure() Option

Insecure disables SSL certificate validation when communicating with vCloud.

func Org

func Org(org string) Option

Org sets the organization name used when authenticating with vCloud. If not set, 'system' will be used.

func Password

func Password(p string) Option

Password sets the authentication password. This option is required.

func URL

func URL(u *url.URL) Option

URL sets the vCloud base URL. This option is required. See ParseURL helper.

func Username

func Username(u string) Option

Username sets the authentication username. This option is required.

type Options

type Options struct {
	Insecure bool
	Org      string
	Username string
	Password string
	URL      *url.URL
}

func (*Options) Validate

func (opts *Options) Validate() error

Validate ensures required parameters are set.

type VDC

type VDC struct {
	Obj      *govcd.Vdc
	AdminOrg *govcd.AdminOrg
	Client   *Client
}

VDC is a wrapper around a govcd.Vdc object with references to the corresponding Admin Org and vcdusage.Client.

func (*VDC) CoreCount

func (vdc *VDC) CoreCount() uint64

CoreCount retrieves the used CPU MHz for a VDC and calculates the number of cores used by the VDC by dividing the total used CPU MHz by the CPU speed.

For example, if the speed is 3.1 GHz and the used amount is 49.6, the core count is 16.

func (*VDC) Memory

func (vdc *VDC) Memory() DataStorage

Memory retrieves the amount of used memory to an oVDC, represented as a DataStorage type.

func (*VDC) PoweredOnVMCount

func (vdc *VDC) PoweredOnVMCount() uint64

PoweredOnVMCount retrieves the number of powered-on VMs deployed in the VDC.

func (*VDC) Speed

func (vdc *VDC) Speed() uint64

Speed retrieves the CPU speed of a VDC in MHz. This is required for calculating core count.

func (*VDC) Storage

func (vdc *VDC) Storage() DataStorage

Storage retrieves the total amount of 'requested' storage for an oVDC using the oVDC default storage policy.

func (*VDC) StorageAll

func (vdc *VDC) StorageAll() DataStorage

StorageAll retrieves the total amount of used storage for an oVDC, totaling the 'requested' storage for all storage policies.

func (*VDC) VMCount

func (vdc *VDC) VMCount() uint64

VMCount retrieves the number of VMs deployed in the VDC.

func (*VDC) VMCountWithQuery

func (vdc *VDC) VMCountWithQuery(queries ...VMQuerySetter) uint64

VMCountWithQuery retrieves the number of VMs matching all of the provided queries. If PoweredOn is false (default), VMs that are both powered on or off will be included.

type VDCs

type VDCs []VDC

VDCs is a slice of vcdusage.VDC wrappers.

func (VDCs) CoreCount

func (vdcs VDCs) CoreCount() uint64

CoreCount retrieves the used CPU MHz for a VDC and calculates the number of cores used by all VDCs by dividing the total used CPU MHz by the CPU speed.

For example, if the speed is 3.1 GHz and the used amount is 49.6, the core count is 16.

func (VDCs) Memory

func (vdcs VDCs) Memory() DataStorage

Memory retrieves the amount of used memory to all VDCs, represented as a DataStorage type.

func (VDCs) PoweredOnVMCount

func (vdcs VDCs) PoweredOnVMCount() uint64

PoweredOnVMCount retrieves the number of powered on VMs deployed in all VDCs.

func (VDCs) Speed

func (vdcs VDCs) Speed() uint64

Speed retrieves the max CPU speed of all VDCs in MHz. This is required for calculating core count.

func (VDCs) Storage

func (vdcs VDCs) Storage() DataStorage

Memory retrieves the amount of used storage to all VDCs, represented as a DataStorage type.

func (VDCs) VMCount

func (vdcs VDCs) VMCount() uint64

VMCount retrieves the number of VMs deployed in all VDCs.

func (VDCs) VMCountWithQuery

func (vdcs VDCs) VMCountWithQuery(queries ...VMQuerySetter) uint64

VMCountWithQuery retrieves the number of VMs matching all of the provided queries in all VDCs. If PoweredOn is false (default), VMs that are both powered on or off will be included.

type VMQuery

type VMQuery struct {
	Name      *regexp.Regexp
	GuestOS   *regexp.Regexp
	PoweredOn bool
}

type VMQuerySetter

type VMQuerySetter func(*VMQuery)

func VMPoweredOn

func VMPoweredOn() VMQuerySetter

func VMWithGuestOSContaining

func VMWithGuestOSContaining(contains string) VMQuerySetter

func VMWithGuestOSMatching

func VMWithGuestOSMatching(pattern *regexp.Regexp) VMQuerySetter

func VMWithNameContaining

func VMWithNameContaining(contains string) VMQuerySetter

func VMWithNameMatching

func VMWithNameMatching(pattern *regexp.Regexp) VMQuerySetter

Jump to

Keyboard shortcuts

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