api

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var UserAgent = "crowdy/conoha-cli/dev"

UserAgent is the User-Agent header value sent with all requests.

Functions

func EnsureToken

func EnsureToken(profile string, cfg *config.Config, creds *config.CredentialsStore, tokens *config.TokenStore) (string, error)

EnsureToken returns a valid token, refreshing if necessary. Priority: env var > cached token > re-authenticate.

func SetDebugLevel added in v0.1.3

func SetDebugLevel(level DebugLevel)

SetDebugLevel sets the debug level. Only increases (never decreases).

Types

type AuthResponse

type AuthResponse struct {
	Token struct {
		ExpiresAt string `json:"expires_at"`
	} `json:"token"`
}

AuthResponse represents the token response from the Identity API.

type Client

type Client struct {
	HTTP     *http.Client
	Region   string
	Token    string
	TenantID string
}

Client is the base HTTP client for ConoHa API.

func NewClient

func NewClient(region, token, tenantID string) *Client

NewClient creates a new API client.

func (*Client) BaseURL

func (c *Client) BaseURL(service string) string

BaseURL returns the service endpoint URL. If CONOHA_ENDPOINT is set, it overrides the default URL. If CONOHA_ENDPOINT_MODE=int, the service name is appended as a path segment (with remapping for services that differ between ext and int APIs).

func (*Client) Delete

func (c *Client) Delete(url string) error

Delete performs a DELETE request.

func (*Client) Do

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

Do executes an HTTP request with auth headers and error handling. Note: retries only work for requests without a body (GET/DELETE). POST/PUT with a body are not retried because the body is consumed on first attempt.

func (*Client) Get

func (c *Client) Get(url string, result any) error

Get performs a GET request and decodes the response into result.

func (*Client) Post

func (c *Client) Post(url string, body, result any) (*http.Response, error)

Post performs a POST request and decodes the response into result.

func (*Client) Put

func (c *Client) Put(url string, body, result any) error

Put performs a PUT request.

func (*Client) Request

func (c *Client) Request(method, url string, body any) (*http.Response, error)

Request creates and executes a request, returning the response.

type ComputeAPI

type ComputeAPI struct {
	Client *Client
}

ComputeAPI handles compute (server) operations.

func NewComputeAPI

func NewComputeAPI(c *Client) *ComputeAPI

func (*ComputeAPI) AddSecurityGroup added in v0.5.0

func (a *ComputeAPI) AddSecurityGroup(id, name string) error

AddSecurityGroup adds a security group to a server.

func (*ComputeAPI) AttachVolume

func (a *ComputeAPI) AttachVolume(serverID, volumeID string) error

AttachVolume attaches a volume to a server.

func (*ComputeAPI) CreateKeypair

func (a *ComputeAPI) CreateKeypair(req *model.KeypairCreateRequest) (*model.Keypair, error)

CreateKeypair creates a new keypair.

func (*ComputeAPI) CreateServer

func (a *ComputeAPI) CreateServer(req *model.ServerCreateRequest) (*model.Server, error)

CreateServer creates a new server.

func (*ComputeAPI) DeleteKeypair

func (a *ComputeAPI) DeleteKeypair(name string) error

DeleteKeypair deletes a keypair.

func (*ComputeAPI) DeleteServer

func (a *ComputeAPI) DeleteServer(id string) error

DeleteServer deletes a server.

func (*ComputeAPI) DetachVolume

func (a *ComputeAPI) DetachVolume(serverID, volumeID string) error

DetachVolume detaches a volume from a server.

func (*ComputeAPI) FindServer added in v0.1.2

func (a *ComputeAPI) FindServer(idOrName string) (*model.Server, error)

FindServer finds a server by ID, name, or nametag. If idOrName looks like a UUID, it tries GetServer first. Otherwise, it lists all servers and matches by name, then by nametag.

func (*ComputeAPI) GetConsole

func (a *ComputeAPI) GetConsole(id string) (*model.RemoteConsoleResponse, error)

GetConsole gets the VNC console URL via remote-consoles endpoint (Nova 2.6+).

func (*ComputeAPI) GetFlavor

func (a *ComputeAPI) GetFlavor(id string) (*model.Flavor, error)

GetFlavor returns a flavor by ID.

func (*ComputeAPI) GetKeypair added in v0.4.2

func (a *ComputeAPI) GetKeypair(name string) (*model.Keypair, error)

GetKeypair returns a single keypair by name.

func (*ComputeAPI) GetServer

func (a *ComputeAPI) GetServer(id string) (*model.Server, error)

GetServer returns a server by ID.

func (*ComputeAPI) GetServerMetadata

func (a *ComputeAPI) GetServerMetadata(id string) (map[string]string, error)

GetServerMetadata returns server metadata.

func (*ComputeAPI) ListFlavors

func (a *ComputeAPI) ListFlavors() ([]model.Flavor, error)

ListFlavors returns all flavors.

func (*ComputeAPI) ListKeypairs

func (a *ComputeAPI) ListKeypairs() ([]model.Keypair, error)

ListKeypairs returns all keypairs.

func (*ComputeAPI) ListServers

func (a *ComputeAPI) ListServers() ([]model.Server, error)

ListServers returns all servers.

func (*ComputeAPI) ListVolumeAttachments added in v0.3.3

func (a *ComputeAPI) ListVolumeAttachments(serverID string) ([]model.VolumeAttachment, error)

ListVolumeAttachments returns volumes attached to a server.

func (*ComputeAPI) RebootServer

func (a *ComputeAPI) RebootServer(id string, hard bool) error

RebootServer reboots a server.

func (*ComputeAPI) RebuildServer

func (a *ComputeAPI) RebuildServer(id, imageID string) error

RebuildServer rebuilds a server with a new image.

func (*ComputeAPI) RemoveSecurityGroup added in v0.5.0

func (a *ComputeAPI) RemoveSecurityGroup(id, name string) error

RemoveSecurityGroup removes a security group from a server.

func (*ComputeAPI) ResizeServer

func (a *ComputeAPI) ResizeServer(id, flavorID string) error

ResizeServer resizes a server to a new flavor.

func (*ComputeAPI) ServerAction

func (a *ComputeAPI) ServerAction(id string, action map[string]any) error

ServerAction performs an action on a server (start, stop, reboot, etc.).

func (*ComputeAPI) StartServer

func (a *ComputeAPI) StartServer(id string) error

StartServer starts a stopped server.

func (*ComputeAPI) StopServer

func (a *ComputeAPI) StopServer(id string) error

StopServer stops a running server.

func (*ComputeAPI) UpdateServerMetadata added in v0.4.2

func (a *ComputeAPI) UpdateServerMetadata(id string, meta map[string]string) (map[string]string, error)

UpdateServerMetadata merges metadata into a server's existing metadata.

type DNSAPI

type DNSAPI struct {
	Client *Client
}

func NewDNSAPI

func NewDNSAPI(c *Client) *DNSAPI

func (*DNSAPI) CreateDomain

func (a *DNSAPI) CreateDomain(name, email string, ttl int) (*model.Domain, error)

func (*DNSAPI) CreateRecord

func (a *DNSAPI) CreateRecord(domainID, name, recordType, data string, ttl int, priority *int) (*model.Record, error)

func (*DNSAPI) DeleteDomain

func (a *DNSAPI) DeleteDomain(id string) error

func (*DNSAPI) DeleteRecord

func (a *DNSAPI) DeleteRecord(domainID, recordID string) error

func (*DNSAPI) GetDomain

func (a *DNSAPI) GetDomain(id string) (*model.Domain, error)

func (*DNSAPI) ListDomains

func (a *DNSAPI) ListDomains() ([]model.Domain, error)

func (*DNSAPI) ListRecords

func (a *DNSAPI) ListRecords(domainID string) ([]model.Record, error)

func (*DNSAPI) UpdateDomain

func (a *DNSAPI) UpdateDomain(id string, body map[string]any) error

func (*DNSAPI) UpdateRecord

func (a *DNSAPI) UpdateRecord(domainID, recordID string, body map[string]any) error

type DebugLevel added in v0.1.3

type DebugLevel int

DebugLevel controls the verbosity of debug output.

const (
	DebugOff     DebugLevel = 0
	DebugVerbose DebugLevel = 1 // method, URL, status, duration
	DebugAPI     DebugLevel = 2 // + headers, bodies
)

type IdentityAPI

type IdentityAPI struct {
	Client *Client
}

func NewIdentityAPI

func NewIdentityAPI(c *Client) *IdentityAPI

func (*IdentityAPI) CreateCredential

func (a *IdentityAPI) CreateCredential(credType, blob, userID string) (*model.Credential, error)

func (*IdentityAPI) CreateSubUser

func (a *IdentityAPI) CreateSubUser(name, password string) (*model.SubUser, error)

func (*IdentityAPI) DeleteCredential

func (a *IdentityAPI) DeleteCredential(id string) error

func (*IdentityAPI) DeleteSubUser

func (a *IdentityAPI) DeleteSubUser(id string) error

func (*IdentityAPI) GetCredential

func (a *IdentityAPI) GetCredential(id string) (*model.Credential, error)

func (*IdentityAPI) ListCredentials

func (a *IdentityAPI) ListCredentials() ([]model.Credential, error)

func (*IdentityAPI) ListRoles

func (a *IdentityAPI) ListRoles() ([]model.Role, error)

func (*IdentityAPI) ListSubUsers

func (a *IdentityAPI) ListSubUsers() ([]model.SubUser, error)

func (*IdentityAPI) UpdateSubUser

func (a *IdentityAPI) UpdateSubUser(id string, body map[string]any) error

type ImageAPI

type ImageAPI struct {
	Client *Client
}

func NewImageAPI

func NewImageAPI(c *Client) *ImageAPI

func (*ImageAPI) CreateImage added in v0.3.3

func (a *ImageAPI) CreateImage(name, diskFormat, containerFormat string) (*model.Image, error)

func (*ImageAPI) DeleteImage

func (a *ImageAPI) DeleteImage(id string) error

func (*ImageAPI) GetImage

func (a *ImageAPI) GetImage(id string) (*model.Image, error)

func (*ImageAPI) ListImages

func (a *ImageAPI) ListImages() ([]model.Image, error)

func (*ImageAPI) UploadImageFile added in v0.3.3

func (a *ImageAPI) UploadImageFile(id string, reader io.Reader, size int64) error

type LoadBalancerAPI

type LoadBalancerAPI struct {
	Client *Client
}

func NewLoadBalancerAPI

func NewLoadBalancerAPI(c *Client) *LoadBalancerAPI

func (*LoadBalancerAPI) CreateHealthMonitor

func (a *LoadBalancerAPI) CreateHealthMonitor(poolID, name, monitorType string, delay, timeout, maxRetries int, urlPath, expectedCodes string) (*model.HealthMonitor, error)

func (*LoadBalancerAPI) CreateListener

func (a *LoadBalancerAPI) CreateListener(name, protocol string, port int, lbID string) (*model.Listener, error)

func (*LoadBalancerAPI) CreateLoadBalancer

func (a *LoadBalancerAPI) CreateLoadBalancer(name, subnetID string) (*model.LoadBalancer, error)

func (*LoadBalancerAPI) CreateMember

func (a *LoadBalancerAPI) CreateMember(poolID, name, address string, port int, weight *int) (*model.Member, error)

func (*LoadBalancerAPI) CreatePool

func (a *LoadBalancerAPI) CreatePool(name, protocol, lbAlgorithm, listenerID string) (*model.Pool, error)

func (*LoadBalancerAPI) DeleteHealthMonitor

func (a *LoadBalancerAPI) DeleteHealthMonitor(id string) error

func (*LoadBalancerAPI) DeleteListener

func (a *LoadBalancerAPI) DeleteListener(id string) error

func (*LoadBalancerAPI) DeleteLoadBalancer

func (a *LoadBalancerAPI) DeleteLoadBalancer(id string) error

func (*LoadBalancerAPI) DeleteMember

func (a *LoadBalancerAPI) DeleteMember(poolID, memberID string) error

func (*LoadBalancerAPI) DeletePool

func (a *LoadBalancerAPI) DeletePool(id string) error

func (*LoadBalancerAPI) GetHealthMonitor added in v0.3.3

func (a *LoadBalancerAPI) GetHealthMonitor(id string) (*model.HealthMonitor, error)

func (*LoadBalancerAPI) GetListener added in v0.3.3

func (a *LoadBalancerAPI) GetListener(id string) (*model.Listener, error)

func (*LoadBalancerAPI) GetLoadBalancer

func (a *LoadBalancerAPI) GetLoadBalancer(id string) (*model.LoadBalancer, error)

func (*LoadBalancerAPI) GetMember added in v0.3.3

func (a *LoadBalancerAPI) GetMember(poolID, memberID string) (*model.Member, error)

func (*LoadBalancerAPI) GetPool added in v0.3.3

func (a *LoadBalancerAPI) GetPool(id string) (*model.Pool, error)

func (*LoadBalancerAPI) ListHealthMonitors

func (a *LoadBalancerAPI) ListHealthMonitors() ([]model.HealthMonitor, error)

func (*LoadBalancerAPI) ListListeners

func (a *LoadBalancerAPI) ListListeners() ([]model.Listener, error)

func (*LoadBalancerAPI) ListLoadBalancers

func (a *LoadBalancerAPI) ListLoadBalancers() ([]model.LoadBalancer, error)

func (*LoadBalancerAPI) ListMembers

func (a *LoadBalancerAPI) ListMembers(poolID string) ([]model.Member, error)

func (*LoadBalancerAPI) ListPools

func (a *LoadBalancerAPI) ListPools() ([]model.Pool, error)

func (*LoadBalancerAPI) UpdateLoadBalancer

func (a *LoadBalancerAPI) UpdateLoadBalancer(id string, body map[string]any) error

type NetworkAPI

type NetworkAPI struct {
	Client *Client
}

func NewNetworkAPI

func NewNetworkAPI(c *Client) *NetworkAPI

func (*NetworkAPI) AttachPort

func (a *NetworkAPI) AttachPort(computeClient *Client, serverID, portID string) error

AttachPort attaches a port to a server (uses compute API).

func (*NetworkAPI) CreateNetwork

func (a *NetworkAPI) CreateNetwork(name string) (*model.Network, error)

func (*NetworkAPI) CreatePort

func (a *NetworkAPI) CreatePort(networkID, name string) (*model.Port, error)

func (*NetworkAPI) CreateSecurityGroup

func (a *NetworkAPI) CreateSecurityGroup(name, description string) (*model.SecurityGroup, error)

func (*NetworkAPI) CreateSecurityGroupRule

func (a *NetworkAPI) CreateSecurityGroupRule(sgID, direction, protocol, ethertype string, portMin, portMax *int, remoteIP string) (*model.SecurityGroupRule, error)

func (*NetworkAPI) CreateSubnet

func (a *NetworkAPI) CreateSubnet(networkID, cidr, name string, ipVersion int) (*model.Subnet, error)

func (*NetworkAPI) DeleteNetwork

func (a *NetworkAPI) DeleteNetwork(id string) error

func (*NetworkAPI) DeletePort

func (a *NetworkAPI) DeletePort(id string) error

func (*NetworkAPI) DeleteSecurityGroup

func (a *NetworkAPI) DeleteSecurityGroup(id string) error

func (*NetworkAPI) DeleteSecurityGroupRule

func (a *NetworkAPI) DeleteSecurityGroupRule(id string) error

func (*NetworkAPI) DeleteSubnet

func (a *NetworkAPI) DeleteSubnet(id string) error

func (*NetworkAPI) DetachPort

func (a *NetworkAPI) DetachPort(computeClient *Client, serverID, portID string) error

DetachPort detaches a port from a server (uses compute API).

func (*NetworkAPI) GetSecurityGroup

func (a *NetworkAPI) GetSecurityGroup(id string) (*model.SecurityGroup, error)

func (*NetworkAPI) ListNetworks

func (a *NetworkAPI) ListNetworks() ([]model.Network, error)

func (*NetworkAPI) ListPorts

func (a *NetworkAPI) ListPorts() ([]model.Port, error)

func (*NetworkAPI) ListPortsByDevice added in v0.3.3

func (a *NetworkAPI) ListPortsByDevice(deviceID string) ([]model.Port, error)

ListPortsByDevice returns ports associated with a device (server).

func (*NetworkAPI) ListQoSPolicies

func (a *NetworkAPI) ListQoSPolicies() ([]model.QoSPolicy, error)

func (*NetworkAPI) ListSecurityGroupRules

func (a *NetworkAPI) ListSecurityGroupRules() ([]model.SecurityGroupRule, error)

func (*NetworkAPI) ListSecurityGroups

func (a *NetworkAPI) ListSecurityGroups() ([]model.SecurityGroup, error)

func (*NetworkAPI) ListSubnets

func (a *NetworkAPI) ListSubnets() ([]model.Subnet, error)

func (*NetworkAPI) UpdatePort

func (a *NetworkAPI) UpdatePort(id string, body map[string]any) error

func (*NetworkAPI) UpdateSecurityGroup

func (a *NetworkAPI) UpdateSecurityGroup(id string, body map[string]any) error

type ObjectStorageAPI

type ObjectStorageAPI struct {
	Client *Client
}

func NewObjectStorageAPI

func NewObjectStorageAPI(c *Client) *ObjectStorageAPI

func (*ObjectStorageAPI) CreateContainer

func (a *ObjectStorageAPI) CreateContainer(name string) error

func (*ObjectStorageAPI) DeleteContainer

func (a *ObjectStorageAPI) DeleteContainer(name string) error

func (*ObjectStorageAPI) DeleteObject

func (a *ObjectStorageAPI) DeleteObject(container, objectName string) error

func (*ObjectStorageAPI) DownloadObject

func (a *ObjectStorageAPI) DownloadObject(container, objectName, localPath string) error

func (*ObjectStorageAPI) GetAccountInfo

func (a *ObjectStorageAPI) GetAccountInfo() (*model.AccountInfo, error)

func (*ObjectStorageAPI) ListContainers

func (a *ObjectStorageAPI) ListContainers() ([]model.Container, error)

func (*ObjectStorageAPI) ListObjects

func (a *ObjectStorageAPI) ListObjects(container string) ([]model.StorageObject, error)

func (*ObjectStorageAPI) ListObjectsWithPrefix added in v0.3.3

func (a *ObjectStorageAPI) ListObjectsWithPrefix(container, prefix string) ([]model.StorageObject, error)

ListObjectsWithPrefix returns objects in a container filtered by prefix.

func (*ObjectStorageAPI) PublishContainer

func (a *ObjectStorageAPI) PublishContainer(name string) error

func (*ObjectStorageAPI) UnpublishContainer

func (a *ObjectStorageAPI) UnpublishContainer(name string) error

func (*ObjectStorageAPI) UploadObject

func (a *ObjectStorageAPI) UploadObject(container, objectName, localPath string) error

type TokenResult

type TokenResult struct {
	Token     string
	ExpiresAt time.Time
}

TokenResult contains the token string and expiration.

func Authenticate

func Authenticate(region, tenantID, username, password string) (*TokenResult, error)

Authenticate obtains a new token from the Identity API.

type VolumeAPI

type VolumeAPI struct {
	Client *Client
}

func NewVolumeAPI

func NewVolumeAPI(c *Client) *VolumeAPI

func (*VolumeAPI) CreateVolume

func (a *VolumeAPI) CreateVolume(req *model.VolumeCreateRequest) (*model.Volume, error)

func (*VolumeAPI) DeleteVolume

func (a *VolumeAPI) DeleteVolume(id string) error

func (*VolumeAPI) GetBackup

func (a *VolumeAPI) GetBackup(id string) (*model.Backup, error)

func (*VolumeAPI) GetVolume

func (a *VolumeAPI) GetVolume(id string) (*model.Volume, error)

func (*VolumeAPI) ListBackups

func (a *VolumeAPI) ListBackups() ([]model.Backup, error)

func (*VolumeAPI) ListVolumeTypes

func (a *VolumeAPI) ListVolumeTypes() ([]model.VolumeType, error)

func (*VolumeAPI) ListVolumes

func (a *VolumeAPI) ListVolumes() ([]model.Volume, error)

func (*VolumeAPI) RestoreBackup

func (a *VolumeAPI) RestoreBackup(backupID, volumeID string) error

func (*VolumeAPI) UpdateVolume

func (a *VolumeAPI) UpdateVolume(id string, body map[string]any) error

Jump to

Keyboard shortcuts

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