fluenceapi

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 24, 2025 License: MIT Imports: 7 Imported by: 0

README

Fluence Golang API Client

A Go client package that provides connections to the Fluence API.

Using this module, the Fluence provider establishes a new client and sends HTTP(s) requests to the Fluence API to perform CRUD operations. It also handles data mapping from user's inputs to models.go. The Fluence URL defaults to https://api.fluence.dev/, and is set in the client.go file.

Usage

Using the client requires a valid Fluence API key. Keys can be created in the API keys page in the Fluence console.

Once you have an API key, set the FLUENCE_API_KEY environment variable: export FLUENCE_API_KEY=<your key>

Finally, you can run go run test/test.go to validate your authentication, which should return any SSH keys you've uploaded, and any running VMs in your account.

Documentation

Index

Constants

View Source
const HostURL string = "https://api.fluence.dev"

HostURL - Default Fluence API URL

Variables

This section is empty.

Functions

This section is empty.

Types

type AddSshKey

type AddSshKey struct {
	Name      string `json:"name"`
	PublicKey string `json:"publicKey"`
}

AddSshKey represents the request body for adding an SSH key

type AdditionalResources

type AdditionalResources struct {
	Storage []AdditionalStorage `json:"storage,omitempty"`
}

AdditionalResources represents additional resources (currently only storage)

type AdditionalStorage

type AdditionalStorage struct {
	Supply uint64 `json:"supply"`
	Units  string `json:"units"`
	Type   string `json:"type"`
}

AdditionalStorage represents additional storage resources

type AdditionalSupply

type AdditionalSupply struct {
	Resource
	Supply
	PerVmLimit *uint64 `json:"perVmLimit,omitempty"`
}

AdditionalSupply represents additional supply for a resource

type AvailableHardware

type AvailableHardware struct {
	Cpu     []CpuHardware     `json:"cpu"`
	Memory  []MemoryHardware  `json:"memory"`
	Storage []StorageHardware `json:"storage"`
}

AvailableHardware represents the response for available hardware.

type Client

type Client struct {
	HostURL    string
	HTTPClient *http.Client
	ApiKey     string
}

Client -

func NewClient

func NewClient(host *string, apikey *string) (*Client, error)

NewClient -

func (*Client) CreateSshKey

func (c *Client) CreateSshKey(key AddSshKey) (*SshKey, error)

CreateSshKey creates a new SSH key.

func (*Client) CreateVmV3

func (c *Client) CreateVmV3(reqBody CreateVmV3) ([]CreatedVm, error)

CreateVmV3 creates new VM(s) with the given configuration and constraints.

func (*Client) EstimateDeposit

func (c *Client) EstimateDeposit(reqBody EstimateDepositRequestV3) (*EstimatedDepositV3DTO, error)

EstimateDeposit estimates the deposit required for a VM configuration.

func (*Client) GetAvailableCountries

func (c *Client) GetAvailableCountries() ([]string, error)

GetAvailableCountries fetches a list of available countries on the marketplace.

func (*Client) GetAvailableHardware

func (c *Client) GetAvailableHardware() (*AvailableHardware, error)

GetAvailableHardware fetches a list of available hardware on the marketplace.

func (*Client) GetBasicConfigurations

func (c *Client) GetBasicConfigurations() ([]string, error)

GetBasicConfigurations fetches a list of basic configurations from the marketplace.

func (*Client) GetMarketplaceOffers

func (c *Client) GetMarketplaceOffers(constraints *OfferConstraints) ([]MarketOffering, error)

GetMarketplaceOffers fetches a list of offers that match the given constraints.

func (*Client) ListSshKeys

func (c *Client) ListSshKeys() ([]SshKey, error)

ListSshKeys fetches all SSH keys.

func (*Client) ListVmsV3

func (c *Client) ListVmsV3() ([]RunningInstanceV3, error)

ListVmsV3 fetches all running VM instances (v3).

func (*Client) RemoveSshKey

func (c *Client) RemoveSshKey(fingerprint string) error

RemoveSshKey removes an SSH key by fingerprint.

func (*Client) RemoveVms

func (c *Client) RemoveVms(vmIds []string) (*VmsRemoved, error)

RemoveVms removes VMs by their IDs.

func (*Client) UpdateVms

func (c *Client) UpdateVms(updates []UpdateVm) error

UpdateVms updates one or more VMs (patch).

type ConfigurationPrice

type ConfigurationPrice struct {
	Slug  string `json:"slug"`
	Price string `json:"price"`
}

ConfigurationPrice represents a configuration and its price

type CpuHardware

type CpuHardware struct {
	Architecture string `json:"architecture"`
	Manufacturer string `json:"manufacturer"`
}

CpuHardware represents CPU hardware constraints

type CreateVmV3

type CreateVmV3 struct {
	Constraints     *OfferConstraints `json:"constraints,omitempty"`
	Instances       int               `json:"instances"`
	VmConfiguration VmConfiguration   `json:"vmConfiguration"`
}

CreateVmV3 represents the request body for creating VMs

type CreatedVm

type CreatedVm struct {
	VmId   string `json:"vmId"`
	VmName string `json:"vmName"`
}

CreatedVm represents a created VM response

type Datacenter

type Datacenter struct {
	CountryCode    string   `json:"countryCode"`
	CityCode       string   `json:"cityCode"`
	CityIndex      uint32   `json:"cityIndex"`
	Tier           uint32   `json:"tier"`
	Certifications []string `json:"certifications"`
}

Datacenter represents a datacenter object

type DatacenterConstraint

type DatacenterConstraint struct {
	Countries []string `json:"countries"`
}

DatacenterConstraint represents a constraint on datacenter countries

type DefaultImageDTO

type DefaultImageDTO struct {
	Id           string `json:"id"`
	Name         string `json:"name"`
	Distribution string `json:"distribution"`
	Slug         string `json:"slug"`
	DownloadUrl  string `json:"downloadUrl"`
	Username     string `json:"username"`
	CreatedAt    string `json:"createdAt"`
	UpdatedAt    string `json:"updatedAt"`
}

DefaultImageDTO represents a default OS image

type ErrorBody

type ErrorBody struct {
	Error string `json:"error"`
}

ErrorBody represents the error response format

type EstimateDepositRequestV3

type EstimateDepositRequestV3 struct {
	Constraints *OfferConstraints `json:"constraints,omitempty"`
	Instances   int               `json:"instances"`
}

EstimateDepositRequestV3 represents the request for deposit estimation

type EstimatedDepositV3DTO

type EstimatedDepositV3DTO struct {
	DepositAmountUsdc  string `json:"depositAmountUsdc"`
	DepositEpochs      uint64 `json:"depositEpochs"`
	TotalPricePerEpoch string `json:"totalPricePerEpoch"`
	MaxPricePerEpoch   string `json:"maxPricePerEpoch"`
	Instances          int    `json:"instances"`
}

EstimatedDepositV3DTO represents the estimated deposit response

type HardwareConstraints

type HardwareConstraints struct {
	Cpu     []CpuHardware     `json:"cpu,omitempty"`
	Memory  []MemoryHardware  `json:"memory,omitempty"`
	Storage []StorageHardware `json:"storage,omitempty"`
}

HardwareConstraints represents hardware constraints for offers

type MarketOffering

type MarketOffering struct {
	Configuration       ConfigurationPrice `json:"configuration"`
	Resources           []Resource         `json:"resources"`
	Datacenter          Datacenter         `json:"datacenter"`
	Servers             []ServerOffering   `json:"servers"`
	MaxAdditionalSupply []AdditionalSupply `json:"maxAdditionalSupply"`
}

MarketOffering represents a market offering

type MemoryHardware

type MemoryHardware struct {
	Type       string `json:"type"`
	Generation string `json:"generation"`
}

MemoryHardware represents memory hardware constraints

type OfferConstraints

type OfferConstraints struct {
	AdditionalResources      *AdditionalResources  `json:"additionalResources,omitempty"`
	BasicConfiguration       *string               `json:"basicConfiguration,omitempty"`
	Datacenter               *DatacenterConstraint `json:"datacenter,omitempty"`
	Hardware                 *HardwareConstraints  `json:"hardware,omitempty"`
	MaxTotalPricePerEpochUsd *string               `json:"maxTotalPricePerEpochUsd,omitempty"`
}

OfferConstraints represents constraints for marketplace offers

type OpenPorts

type OpenPorts struct {
	Port     uint16 `json:"port"`
	Protocol string `json:"protocol"`
}

OpenPorts represents an open port specification

type PortSpec

type PortSpec struct {
	Port     uint16 `json:"port"`
	Protocol string `json:"protocol"`
}

PortSpec represents a port specification for a running instance

type RemoveSshKey

type RemoveSshKey struct {
	Fingerprint string `json:"fingerprint"`
}

RemoveSshKey represents the request body for removing an SSH key

type RemoveVms

type RemoveVms struct {
	VmIds []string `json:"vmIds"`
}

RemoveVms represents the request body for removing VMs

type Resource

type Resource struct {
	Type     string           `json:"type"`
	Metadata ResourceMetadata `json:"metadata"`
	Price    string           `json:"price"`
}

Resource represents a resource object

type ResourceMetadata

type ResourceMetadata map[string]interface{}

ResourceMetadata is a generic map for metadata (use interface{} for flexibility)

type RunningInstanceV3

type RunningInstanceV3 struct {
	Id              string       `json:"id"`
	Status          string       `json:"status"`
	PricePerEpoch   string       `json:"pricePerEpoch"`
	Resources       []VmResource `json:"resources"`
	CreatedAt       string       `json:"createdAt"`
	NextBillingAt   string       `json:"nextBillingAt"`
	ReservedBalance string       `json:"reservedBalance"`
	TotalSpent      string       `json:"totalSpent"`
	Datacenter      *Datacenter  `json:"datacenter,omitempty"`
	OsImage         *string      `json:"osImage,omitempty"`
	Ports           *[]PortSpec  `json:"ports,omitempty"`
	PublicIp        *string      `json:"publicIp,omitempty"`
	VmName          *string      `json:"vmName,omitempty"`
}

RunningInstanceV3 represents a running VM instance

type ServerOffering

type ServerOffering struct {
	AvailableBasicInstances uint64             `json:"availableBasicInstances"`
	AdditionalResources     []AdditionalSupply `json:"additionalResources"`
}

ServerOffering represents a server offering

type SshKey

type SshKey struct {
	Name        string `json:"name"`
	Fingerprint string `json:"fingerprint"`
	Algorithm   string `json:"algorithm"`
	Comment     string `json:"comment"`
	PublicKey   string `json:"publicKey"`
	Active      bool   `json:"active"`
	CreatedAt   string `json:"createdAt"`
}

SshKey represents an SSH key object

type StorageHardware

type StorageHardware struct {
	Type string `json:"type"`
}

StorageHardware represents storage hardware constraints

type String

type String string

String is a type alias for string, used for OpenAPI compatibility

type Supply

type Supply struct {
	Supply uint64 `json:"supply"`
	Units  string `json:"units"`
}

Supply represents a supply object

type UpdateVm

type UpdateVm struct {
	Id        string       `json:"id"`
	OpenPorts *[]OpenPorts `json:"openPorts,omitempty"`
	VmName    *string      `json:"vmName,omitempty"`
}

UpdateVm represents a patch update for a VM

type UpdateVms

type UpdateVms struct {
	Updates []UpdateVm `json:"updates"`
}

UpdateVms represents a patch update for multiple VMs

type VmConfiguration

type VmConfiguration struct {
	Hostname  *string     `json:"hostname,omitempty"`
	Name      string      `json:"name"`
	OpenPorts []OpenPorts `json:"openPorts"`
	OsImage   string      `json:"osImage"`
	SshKeys   []string    `json:"sshKeys"`
}

VmConfiguration represents a VM configuration

type VmResource

type VmResource struct {
	Supply
	Type     string           `json:"type"`
	Details  interface{}      `json:"details"`
	Metadata ResourceMetadata `json:"metadata"`
}

VmResource represents a VM resource

type VmsRemoved

type VmsRemoved struct {
	Transactions []string `json:"transactions"`
}

VmsRemoved represents the response for removed VMs

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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