Documentation
¶
Overview ¶
Package openstack is a pure-Go (no cgo) Ruby-facing OpenStack client. It puts a clean, idiomatic surface on top of the reference Go OpenStack SDK github.com/gophercloud/gophercloud/v2 (Apache-2.0 licensed; imported, never vendored). gophercloud already implements everything that is OpenStack: the Keystone authentication dance, the service catalog, request signing, pagination and the per-service HTTP APIs. This package does not reimplement any of that; it wraps gophercloud and adds the thin conveniences a consumer such as go-embedded-ruby (rbgo) needs to expose an OpenStack client to Ruby:
- Connect performs Keystone v3 authentication (password, token or application-credential) and returns a Connection carrying the token and service catalog, mirroring OpenStack::Connection.new;
- per-service accessors (Connection.Compute, Connection.Network, Connection.BlockStorage, Connection.ObjectStorage, Connection.Image, Connection.Identity) each offering list / get / create / update / delete over the core resources, in the spirit of fog-openstack's collections (Fog::OpenStack::Compute#servers, .get, .create, .destroy);
- resources returned as Resource hashes (map[string]any keyed by the JSON attribute names), the natural shape for a Ruby Hash;
- a typed error tree (Error, NotFoundError, AuthError, ForbiddenError, ConflictError, BadRequestError) mapping gophercloud's HTTP status codes onto the Ruby exception hierarchy OpenStack::Error < StandardError;
- an injectable HTTP transport seam (Options.Transport / Options.HTTPClient) so tests and rbgo can supply a fake and no live cloud is ever required.
Scope: the core CRUD for the six main services (Nova, Neutron, Cinder, Swift, Glance, Keystone). The full OpenStack API is enormous; less-common services and advanced per-resource operations are intentionally not wrapped but remain reachable through gophercloud directly against the authenticated Connection. See the README for the exact coverage matrix.
The package has no dependency on any Ruby runtime: the surface is Go-typed, and a Ruby binding layer marshals Ruby values onto these Go types.
Index ¶
- func IsAuth(err error) bool
- func IsBadRequest(err error) bool
- func IsConflict(err error) bool
- func IsForbidden(err error) bool
- func IsNotFound(err error) bool
- type APIError
- type AuthError
- type BadRequestError
- type BlockStorage
- func (b *BlockStorage) CreateSnapshot(opts Resource) (Resource, error)
- func (b *BlockStorage) CreateVolume(opts Resource) (Resource, error)
- func (b *BlockStorage) CreateVolumeType(opts Resource) (Resource, error)
- func (b *BlockStorage) DeleteSnapshot(id string) error
- func (b *BlockStorage) DeleteVolume(id string) error
- func (b *BlockStorage) DeleteVolumeType(id string) error
- func (b *BlockStorage) GetSnapshot(id string) (Resource, error)
- func (b *BlockStorage) GetVolume(id string) (Resource, error)
- func (b *BlockStorage) GetVolumeType(id string) (Resource, error)
- func (b *BlockStorage) Snapshots() ([]Resource, error)
- func (b *BlockStorage) UpdateSnapshot(id string, opts Resource) (Resource, error)
- func (b *BlockStorage) UpdateVolume(id string, opts Resource) (Resource, error)
- func (b *BlockStorage) UpdateVolumeType(id string, opts Resource) (Resource, error)
- func (b *BlockStorage) VolumeTypes() ([]Resource, error)
- func (b *BlockStorage) Volumes() ([]Resource, error)
- type Compute
- func (c *Compute) AttachVolume(serverID string, opts Resource) (Resource, error)
- func (c *Compute) CreateKeypair(opts Resource) (Resource, error)
- func (c *Compute) CreateServer(opts Resource) (Resource, error)
- func (c *Compute) DeleteKeypair(name string) error
- func (c *Compute) DeleteServer(id string) error
- func (c *Compute) DetachVolume(serverID, volumeID string) error
- func (c *Compute) Flavor(id string) (Resource, error)
- func (c *Compute) Flavors() ([]Resource, error)
- func (c *Compute) Keypair(name string) (Resource, error)
- func (c *Compute) Keypairs() ([]Resource, error)
- func (c *Compute) RebootServer(id, method string) error
- func (c *Compute) Server(id string) (Resource, error)
- func (c *Compute) Servers() ([]Resource, error)
- func (c *Compute) StartServer(id string) error
- func (c *Compute) StopServer(id string) error
- func (c *Compute) UpdateServer(id string, opts Resource) (Resource, error)
- type ConflictError
- type Connection
- func (c *Connection) BlockStorage() (*BlockStorage, error)
- func (c *Connection) Compute() (*Compute, error)
- func (c *Connection) Identity() (*Identity, error)
- func (c *Connection) Image() (*Image, error)
- func (c *Connection) Network() (*Network, error)
- func (c *Connection) ObjectStorage() (*ObjectStorage, error)
- type Error
- type ForbiddenError
- type Identity
- func (i *Identity) CreateDomain(opts Resource) (Resource, error)
- func (i *Identity) CreateProject(opts Resource) (Resource, error)
- func (i *Identity) CreateRole(opts Resource) (Resource, error)
- func (i *Identity) CreateUser(opts Resource) (Resource, error)
- func (i *Identity) DeleteDomain(id string) error
- func (i *Identity) DeleteProject(id string) error
- func (i *Identity) DeleteRole(id string) error
- func (i *Identity) DeleteUser(id string) error
- func (i *Identity) Domains() ([]Resource, error)
- func (i *Identity) GetDomain(id string) (Resource, error)
- func (i *Identity) GetProject(id string) (Resource, error)
- func (i *Identity) GetRole(id string) (Resource, error)
- func (i *Identity) GetUser(id string) (Resource, error)
- func (i *Identity) Projects() ([]Resource, error)
- func (i *Identity) Roles() ([]Resource, error)
- func (i *Identity) UpdateDomain(id string, opts Resource) (Resource, error)
- func (i *Identity) UpdateProject(id string, opts Resource) (Resource, error)
- func (i *Identity) UpdateRole(id string, opts Resource) (Resource, error)
- func (i *Identity) UpdateUser(id string, opts Resource) (Resource, error)
- func (i *Identity) Users() ([]Resource, error)
- type Image
- func (i *Image) CreateImage(opts Resource) (Resource, error)
- func (i *Image) DeleteImage(id string) error
- func (i *Image) GetImage(id string) (Resource, error)
- func (i *Image) Images() ([]Resource, error)
- func (i *Image) UpdateImage(id string, opts images.UpdateOpts) (Resource, error)
- func (i *Image) UploadImage(id string, data io.Reader) error
- type Network
- func (n *Network) CreateFloatingIP(opts Resource) (Resource, error)
- func (n *Network) CreateNetwork(opts Resource) (Resource, error)
- func (n *Network) CreatePort(opts Resource) (Resource, error)
- func (n *Network) CreateRouter(opts Resource) (Resource, error)
- func (n *Network) CreateSecurityGroup(opts Resource) (Resource, error)
- func (n *Network) CreateSecurityGroupRule(opts Resource) (Resource, error)
- func (n *Network) CreateSubnet(opts Resource) (Resource, error)
- func (n *Network) DeleteFloatingIP(id string) error
- func (n *Network) DeleteNetwork(id string) error
- func (n *Network) DeletePort(id string) error
- func (n *Network) DeleteRouter(id string) error
- func (n *Network) DeleteSecurityGroup(id string) error
- func (n *Network) DeleteSecurityGroupRule(id string) error
- func (n *Network) DeleteSubnet(id string) error
- func (n *Network) FloatingIPs() ([]Resource, error)
- func (n *Network) GetFloatingIP(id string) (Resource, error)
- func (n *Network) GetNetwork(id string) (Resource, error)
- func (n *Network) GetPort(id string) (Resource, error)
- func (n *Network) GetRouter(id string) (Resource, error)
- func (n *Network) GetSecurityGroup(id string) (Resource, error)
- func (n *Network) GetSecurityGroupRule(id string) (Resource, error)
- func (n *Network) GetSubnet(id string) (Resource, error)
- func (n *Network) Networks() ([]Resource, error)
- func (n *Network) Ports() ([]Resource, error)
- func (n *Network) Routers() ([]Resource, error)
- func (n *Network) SecurityGroupRules() ([]Resource, error)
- func (n *Network) SecurityGroups() ([]Resource, error)
- func (n *Network) Subnets() ([]Resource, error)
- func (n *Network) UpdateFloatingIP(id string, opts Resource) (Resource, error)
- func (n *Network) UpdateNetwork(id string, opts Resource) (Resource, error)
- func (n *Network) UpdatePort(id string, opts Resource) (Resource, error)
- func (n *Network) UpdateRouter(id string, opts Resource) (Resource, error)
- func (n *Network) UpdateSecurityGroup(id string, opts Resource) (Resource, error)
- func (n *Network) UpdateSubnet(id string, opts Resource) (Resource, error)
- type NotFoundError
- type ObjectStorage
- func (o *ObjectStorage) Containers() ([]Resource, error)
- func (o *ObjectStorage) CreateContainer(name string) error
- func (o *ObjectStorage) DeleteContainer(name string) error
- func (o *ObjectStorage) DeleteObject(container, name string) error
- func (o *ObjectStorage) GetObject(container, name string) ([]byte, error)
- func (o *ObjectStorage) Objects(container string) ([]Resource, error)
- func (o *ObjectStorage) PutObject(container, name string, content io.Reader) error
- type Options
- type Resource
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsBadRequest ¶
IsBadRequest reports whether err is (or wraps) a BadRequestError.
func IsConflict ¶
IsConflict reports whether err is (or wraps) a ConflictError.
func IsForbidden ¶
IsForbidden reports whether err is (or wraps) a ForbiddenError.
func IsNotFound ¶
IsNotFound reports whether err is (or wraps) a NotFoundError.
Types ¶
type APIError ¶
type APIError interface {
error
// Status returns the HTTP status code carried by the underlying API
// response, or 0 when the error did not originate from one.
Status() int
// Unwrap exposes the wrapped gophercloud error for errors.Is/As.
Unwrap() error
}
APIError is implemented by every error this package returns. It mirrors the Ruby exception hierarchy that a binding layer exposes as
OpenStack::Error < StandardError OpenStack::NotFound < OpenStack::Error OpenStack::AuthError < OpenStack::Error OpenStack::Forbidden < OpenStack::Error OpenStack::Conflict < OpenStack::Error OpenStack::BadRequest < OpenStack::Error
Every concrete type below satisfies APIError, so a consumer can either type switch, use the Is* predicates, or (in Ruby) rescue the mapped class.
type AuthError ¶
type AuthError struct {
// contains filtered or unexported fields
}
AuthError maps gophercloud's 401 responses and authentication failures (OpenStack::AuthError).
type BadRequestError ¶
type BadRequestError struct {
// contains filtered or unexported fields
}
BadRequestError maps gophercloud's 400 responses (OpenStack::BadRequest).
func (*BadRequestError) Error ¶
func (e *BadRequestError) Error() string
Error implements the error interface.
type BlockStorage ¶
type BlockStorage struct {
// contains filtered or unexported fields
}
BlockStorage is the Cinder (v3) service accessor: volumes, snapshots and volume types.
func (*BlockStorage) CreateSnapshot ¶
func (b *BlockStorage) CreateSnapshot(opts Resource) (Resource, error)
CreateSnapshot creates a snapshot (volume_id, name, ...).
func (*BlockStorage) CreateVolume ¶
func (b *BlockStorage) CreateVolume(opts Resource) (Resource, error)
CreateVolume creates a volume (size, name, ...).
func (*BlockStorage) CreateVolumeType ¶
func (b *BlockStorage) CreateVolumeType(opts Resource) (Resource, error)
CreateVolumeType creates a volume type (name, description, ...).
func (*BlockStorage) DeleteSnapshot ¶
func (b *BlockStorage) DeleteSnapshot(id string) error
DeleteSnapshot deletes a snapshot by ID.
func (*BlockStorage) DeleteVolume ¶
func (b *BlockStorage) DeleteVolume(id string) error
DeleteVolume deletes a volume by ID.
func (*BlockStorage) DeleteVolumeType ¶
func (b *BlockStorage) DeleteVolumeType(id string) error
DeleteVolumeType deletes a volume type by ID.
func (*BlockStorage) GetSnapshot ¶
func (b *BlockStorage) GetSnapshot(id string) (Resource, error)
GetSnapshot fetches a snapshot by ID.
func (*BlockStorage) GetVolume ¶
func (b *BlockStorage) GetVolume(id string) (Resource, error)
GetVolume fetches a volume by ID.
func (*BlockStorage) GetVolumeType ¶
func (b *BlockStorage) GetVolumeType(id string) (Resource, error)
GetVolumeType fetches a volume type by ID.
func (*BlockStorage) Snapshots ¶
func (b *BlockStorage) Snapshots() ([]Resource, error)
Snapshots lists all volume snapshots (detailed).
func (*BlockStorage) UpdateSnapshot ¶
func (b *BlockStorage) UpdateSnapshot(id string, opts Resource) (Resource, error)
UpdateSnapshot updates a snapshot (name, description).
func (*BlockStorage) UpdateVolume ¶
func (b *BlockStorage) UpdateVolume(id string, opts Resource) (Resource, error)
UpdateVolume updates a volume (name, description, ...).
func (*BlockStorage) UpdateVolumeType ¶
func (b *BlockStorage) UpdateVolumeType(id string, opts Resource) (Resource, error)
UpdateVolumeType updates a volume type.
func (*BlockStorage) VolumeTypes ¶
func (b *BlockStorage) VolumeTypes() ([]Resource, error)
VolumeTypes lists all volume types.
func (*BlockStorage) Volumes ¶
func (b *BlockStorage) Volumes() ([]Resource, error)
Volumes lists all volumes (detailed).
type Compute ¶
type Compute struct {
// contains filtered or unexported fields
}
Compute is the Nova service accessor, exposing the core CRUD over servers, flavors and keypairs plus server power actions and volume attachment. The shape mirrors fog-openstack's Fog::OpenStack::Compute collections.
func (*Compute) AttachVolume ¶
AttachVolume attaches a volume to a server; opts carries at least {"volumeId" => "..."}.
func (*Compute) CreateKeypair ¶
CreateKeypair creates (or imports) a keypair from the option hash (name, public_key).
func (*Compute) CreateServer ¶
CreateServer boots a server from the supplied option hash (name, flavorRef, imageRef, networks, ...).
func (*Compute) DeleteKeypair ¶
DeleteKeypair deletes a keypair by name.
func (*Compute) DeleteServer ¶
DeleteServer deletes a server by ID.
func (*Compute) DetachVolume ¶
DetachVolume detaches a volume from a server.
func (*Compute) RebootServer ¶
RebootServer reboots a server. method is "SOFT" (default) or "HARD".
func (*Compute) StartServer ¶
StartServer powers on a stopped server.
func (*Compute) StopServer ¶
StopServer powers off a running server.
type ConflictError ¶
type ConflictError struct {
// contains filtered or unexported fields
}
ConflictError maps gophercloud's 409 responses (OpenStack::Conflict).
func (*ConflictError) Error ¶
func (e *ConflictError) Error() string
Error implements the error interface.
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
Connection is an authenticated OpenStack session. It owns a gophercloud ProviderClient (carrying the token and service catalog) and hands out the per-service accessors below.
func Connect ¶
func Connect(ctx context.Context, opts Options) (*Connection, error)
Connect authenticates against Keystone v3 and returns a ready Connection. A missing AuthURL, or any authentication failure, yields an *AuthError.
func (*Connection) BlockStorage ¶
func (c *Connection) BlockStorage() (*BlockStorage, error)
BlockStorage returns the Cinder (block storage v3) service accessor.
func (*Connection) Compute ¶
func (c *Connection) Compute() (*Compute, error)
Compute returns the Nova (compute) service accessor.
func (*Connection) Identity ¶
func (c *Connection) Identity() (*Identity, error)
Identity returns the Keystone (identity v3) service accessor.
func (*Connection) Image ¶
func (c *Connection) Image() (*Image, error)
Image returns the Glance (image v2) service accessor.
func (*Connection) Network ¶
func (c *Connection) Network() (*Network, error)
Network returns the Neutron (network) service accessor.
func (*Connection) ObjectStorage ¶
func (c *Connection) ObjectStorage() (*ObjectStorage, error)
ObjectStorage returns the Swift (object storage) service accessor.
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error is the generic error returned when no more specific type applies (for example a transport failure or a 5xx response). It is the base of the tree.
type ForbiddenError ¶
type ForbiddenError struct {
// contains filtered or unexported fields
}
ForbiddenError maps gophercloud's 403 responses (OpenStack::Forbidden).
func (*ForbiddenError) Error ¶
func (e *ForbiddenError) Error() string
Error implements the error interface.
type Identity ¶
type Identity struct {
// contains filtered or unexported fields
}
Identity is the Keystone (v3) service accessor: projects, users, roles and domains.
func (*Identity) CreateDomain ¶
CreateDomain creates a domain (name, description, enabled).
func (*Identity) CreateProject ¶
CreateProject creates a project (name, domain_id, description, ...).
func (*Identity) CreateRole ¶
CreateRole creates a role (name, domain_id, ...).
func (*Identity) CreateUser ¶
CreateUser creates a user (name, domain_id, password, ...).
func (*Identity) DeleteDomain ¶
DeleteDomain deletes a domain by ID.
func (*Identity) DeleteProject ¶
DeleteProject deletes a project by ID.
func (*Identity) DeleteRole ¶
DeleteRole deletes a role by ID.
func (*Identity) DeleteUser ¶
DeleteUser deletes a user by ID.
func (*Identity) GetProject ¶
GetProject fetches a project by ID.
func (*Identity) UpdateDomain ¶
UpdateDomain updates a domain.
func (*Identity) UpdateProject ¶
UpdateProject updates a project.
func (*Identity) UpdateRole ¶
UpdateRole updates a role.
func (*Identity) UpdateUser ¶
UpdateUser updates a user.
type Image ¶
type Image struct {
// contains filtered or unexported fields
}
Image is the Glance (v2) service accessor: image records and their data. Glance returns image objects unwrapped, so single results carry no envelope.
func (*Image) CreateImage ¶
CreateImage creates an image record (name, disk_format, container_format, ...). Upload the binary payload separately with UploadImage.
func (*Image) DeleteImage ¶
DeleteImage deletes an image by ID.
func (*Image) UpdateImage ¶
UpdateImage updates an image record's mutable attributes. Glance uses a JSON patch document, so callers pass a typed images.UpdateOpts (a list of Add/Replace/Remove operations).
type Network ¶
type Network struct {
// contains filtered or unexported fields
}
Network is the Neutron service accessor: networks, subnets, ports, routers, security groups and their rules, and floating IPs.
func (*Network) CreateFloatingIP ¶
CreateFloatingIP allocates a floating IP (floating_network_id, ...).
func (*Network) CreateNetwork ¶
CreateNetwork creates a network from the option hash (name, admin_state_up, ...).
func (*Network) CreatePort ¶
CreatePort creates a port (network_id, ...).
func (*Network) CreateRouter ¶
CreateRouter creates a router (name, admin_state_up, external_gateway_info, ...).
func (*Network) CreateSecurityGroup ¶
CreateSecurityGroup creates a security group (name, description).
func (*Network) CreateSecurityGroupRule ¶
CreateSecurityGroupRule creates a rule (security_group_id, direction, protocol, port_range_min, ...).
func (*Network) CreateSubnet ¶
CreateSubnet creates a subnet (network_id, cidr, ip_version, ...).
func (*Network) DeleteFloatingIP ¶
DeleteFloatingIP releases a floating IP by ID.
func (*Network) DeleteNetwork ¶
DeleteNetwork deletes a network by ID.
func (*Network) DeletePort ¶
DeletePort deletes a port by ID.
func (*Network) DeleteRouter ¶
DeleteRouter deletes a router by ID.
func (*Network) DeleteSecurityGroup ¶
DeleteSecurityGroup deletes a security group by ID.
func (*Network) DeleteSecurityGroupRule ¶
DeleteSecurityGroupRule deletes a rule by ID.
func (*Network) DeleteSubnet ¶
DeleteSubnet deletes a subnet by ID.
func (*Network) FloatingIPs ¶
FloatingIPs lists all floating IPs.
func (*Network) GetFloatingIP ¶
GetFloatingIP fetches a floating IP by ID.
func (*Network) GetNetwork ¶
GetNetwork fetches a network by ID.
func (*Network) GetSecurityGroup ¶
GetSecurityGroup fetches a security group by ID.
func (*Network) GetSecurityGroupRule ¶
GetSecurityGroupRule fetches a security group rule by ID.
func (*Network) SecurityGroupRules ¶
SecurityGroupRules lists all security group rules.
func (*Network) SecurityGroups ¶
SecurityGroups lists all security groups.
func (*Network) UpdateFloatingIP ¶
UpdateFloatingIP associates/disassociates a floating IP (port_id).
func (*Network) UpdateNetwork ¶
UpdateNetwork updates a network.
func (*Network) UpdatePort ¶
UpdatePort updates a port.
func (*Network) UpdateRouter ¶
UpdateRouter updates a router.
func (*Network) UpdateSecurityGroup ¶
UpdateSecurityGroup updates a security group.
type NotFoundError ¶
type NotFoundError struct {
// contains filtered or unexported fields
}
NotFoundError maps gophercloud's 404 responses (OpenStack::NotFound).
func (*NotFoundError) Error ¶
func (e *NotFoundError) Error() string
Error implements the error interface.
type ObjectStorage ¶
type ObjectStorage struct {
// contains filtered or unexported fields
}
ObjectStorage is the Swift service accessor: containers and objects. Swift list responses are bare JSON arrays, so the items come back without an envelope key.
func (*ObjectStorage) Containers ¶
func (o *ObjectStorage) Containers() ([]Resource, error)
Containers lists all containers (with metadata).
func (*ObjectStorage) CreateContainer ¶
func (o *ObjectStorage) CreateContainer(name string) error
CreateContainer creates (or updates) a container by name.
func (*ObjectStorage) DeleteContainer ¶
func (o *ObjectStorage) DeleteContainer(name string) error
DeleteContainer deletes an empty container by name.
func (*ObjectStorage) DeleteObject ¶
func (o *ObjectStorage) DeleteObject(container, name string) error
DeleteObject deletes an object from a container.
func (*ObjectStorage) GetObject ¶
func (o *ObjectStorage) GetObject(container, name string) ([]byte, error)
GetObject downloads an object's content from a container.
type Options ¶
type Options struct {
// AuthURL is the Keystone v3 identity endpoint ("OS_AUTH_URL"), e.g.
// https://keystone.example.com/v3. Required.
AuthURL string
// Username / UserID + Password select password authentication.
Username string
UserID string
Password string
// Token authenticates with an existing Keystone token ID.
Token string
// Application-credential authentication.
ApplicationCredentialID string
ApplicationCredentialName string
ApplicationCredentialSecret string
// ProjectName / ProjectID and DomainName / DomainID scope the token.
ProjectName string
ProjectID string
DomainName string
DomainID string
// Region selects which catalog endpoint to use for every service. Leave
// empty when the cloud publishes a single region.
Region string
// AllowReauth lets gophercloud transparently re-authenticate when the token
// expires.
AllowReauth bool
// Transport is the injectable HTTP transport seam. When non-nil it becomes
// the RoundTripper of the underlying gophercloud client, letting tests and
// rbgo supply a fake so no live cloud is needed. Mutually exclusive with
// HTTPClient (HTTPClient wins when both are set).
Transport http.RoundTripper
// HTTPClient, when non-nil, is used verbatim as the gophercloud HTTP client.
HTTPClient *http.Client
}
Options carries the Keystone v3 authentication parameters plus the pluggable HTTP transport. It mirrors the keyword arguments a Ruby caller passes to OpenStack::Connection.new(auth_url:, username:, password:, project_name:, domain_name:, region:, ...). Three authentication styles are supported:
- password: Username (or UserID) + Password + a domain;
- token: Token (an existing Keystone token, scoped by the project fields);
- application credential: ApplicationCredentialID/Name + Secret.
type Resource ¶
Resource is a Ruby-style hash describing a single OpenStack resource. Keys are the resource's JSON attribute names exactly as the OpenStack API returns them (id, name, status, admin_state_up, ...) and values are the decoded JSON scalars, arrays and nested hashes. This is the natural shape for a Ruby binding: it maps directly onto a Ruby Hash.
Conversions read the raw API response rather than re-marshalling gophercloud's typed structs, so the keys are always the wire (snake_case) names even for the few gophercloud structs that omit output JSON tags.