Categorygithub.com/QumulusTechnology/gophercloud
modulepackage
0.24.3
Repository: https://github.com/qumulustechnology/gophercloud.git
Documentation: pkg.go.dev

# README

Gophercloud: an OpenStack SDK for Go

Build Status Coverage Status

Gophercloud is an OpenStack Go SDK.

Useful links

How to install

Reference a Gophercloud package in your code:

import "github.com/gophercloud/gophercloud"

Then update your go.mod:

go mod tidy

Getting started

Credentials

Because you'll be hitting an API, you will need to retrieve your OpenStack credentials and either store them as environment variables or in your local Go files. The first method is recommended because it decouples credential information from source code, allowing you to push the latter to your version control system without any security risk.

You will need to retrieve the following:

  • username
  • password
  • a valid Keystone identity URL

For users that have the OpenStack dashboard installed, there's a shortcut. If you visit the project/access_and_security path in Horizon and click on the "Download OpenStack RC File" button at the top right hand corner, you will download a bash file that exports all of your access details to environment variables. To execute the file, run source admin-openrc.sh and you will be prompted for your password.

Authentication

NOTE: It is now recommended to use the clientconfig package found at https://github.com/gophercloud/utils/tree/master/openstack/clientconfig for all authentication purposes.

The below documentation is still relevant. clientconfig simply implements the below and presents it in an easier and more flexible way.

Once you have access to your credentials, you can begin plugging them into Gophercloud. The next step is authentication, and this is handled by a base "Provider" struct. To get one, you can either pass in your credentials explicitly, or tell Gophercloud to use environment variables:

import (
  "github.com/gophercloud/gophercloud"
  "github.com/gophercloud/gophercloud/openstack"
  "github.com/gophercloud/gophercloud/openstack/utils"
)

// Option 1: Pass in the values yourself
opts := gophercloud.AuthOptions{
  IdentityEndpoint: "https://openstack.example.com:5000/v2.0",
  Username: "{username}",
  Password: "{password}",
}

// Option 2: Use a utility function to retrieve all your environment variables
opts, err := openstack.AuthOptionsFromEnv()

Once you have the opts variable, you can pass it in and get back a ProviderClient struct:

provider, err := openstack.AuthenticatedClient(opts)

The ProviderClient is the top-level client that all of your OpenStack services derive from. The provider contains all of the authentication details that allow your Go code to access the API - such as the base URL and token ID.

Provision a server

Once we have a base Provider, we inject it as a dependency into each OpenStack service. In order to work with the Compute API, we need a Compute service client; which can be created like so:

client, err := openstack.NewComputeV2(provider, gophercloud.EndpointOpts{
  Region: os.Getenv("OS_REGION_NAME"),
})

We then use this client for any Compute API operation we want. In our case, we want to provision a new server - so we invoke the Create method and pass in the flavor ID (hardware specification) and image ID (operating system) we're interested in:

import "github.com/gophercloud/gophercloud/openstack/compute/v2/servers"

server, err := servers.Create(client, servers.CreateOpts{
  Name:      "My new server!",
  FlavorRef: "flavor_id",
  ImageRef:  "image_id",
}).Extract()

The above code sample creates a new server with the parameters, and embodies the new resource in the server variable (a servers.Server struct).

Advanced Usage

Have a look at the FAQ for some tips on customizing the way Gophercloud works.

Backwards-Compatibility Guarantees

None. Vendor it and write tests covering the parts you use.

Contributing

See the contributing guide.

Help and feedback

If you're struggling with something or have spotted a potential bug, feel free to submit an issue to our bug tracker.

Thank You

We'd like to extend special thanks and appreciation to the following:

OpenLab

OpenLab is providing a full CI environment to test each PR and merge for a variety of OpenStack releases.

VEXXHOST

VEXXHOST is providing their services to assist with the development and testing of Gophercloud.

# Packages

No description provided by the author
Package openstack contains resources for the individual OpenStack projects supported in Gophercloud.
Package pagination contains utilities and convenience structs that implement common pagination idioms within OpenStack APIs.
Package testhelper container methods that are useful for writing unit tests.
gophercloud.

# Functions

BuildHeaders is an internal function to be used by request methods in individual resource packages.
BuildQueryString is an internal function to be used by request methods in individual resource packages.
BuildRequestBody builds a map[string]interface from the given `struct`.
ExtractNextURL is an internal function useful for packages of collection resources that are paginated in a certain way.
IDSliceToQueryString takes a slice of elements and converts them into a query string.
IntToPointer is a function for converting integers into integer pointers.
IntWithinRange returns TRUE if an integer falls within a defined range, and FALSE if not.
MaybeInt is an internal function to be used by request methods in individual resource packages.
MaybeString is an internal function to be used by request methods in individual resource packages.
NormalizePathURL is used to convert rawPath to a fqdn, using basePath as a reference in the filesystem, if necessary.
NormalizeURL is an internal function to be used by provider clients.
ParseResponse is a helper function to parse http.Response to constituents.
RemainingKeys will inspect a struct and compare it to a map.
WaitFor polls a predicate function, once per second, up to a timeout limit.

# Constants

AvailabilityAdmin indicates that an endpoint is only available to administrators.
AvailabilityInternal indicates that an endpoint is only available within the cluster's internal network.
AvailabilityPublic indicates that an endpoint is available to everyone on the internet.
DefaultUserAgent is the default User-Agent string set in the request header.
DefaultUserAgent is the default User-Agent string set in the request header.
IPv4 is used for IP version 4 addresses.
IPv6 is used for IP version 6 addresses.
RFC3339Milli describes a common time format used by some API responses.
No description provided by the author
RFC3339NoZ is the time format used in Heat (Orchestration).
RFC3339ZNoT is the time format used in Zun (Containers Service).
RFC3339ZNoTNoZ is another time format used in Zun (Containers Service).

# Variables

Convenience vars for EnabledState values.
Convenience vars for EnabledState values.

# Structs

AuthOptions stores information needed to authenticate to an OpenStack Cloud.
AuthScope allows a created token to be limited to a specific domain or project.
BaseError is an error type that all other error types embed.
EndpointOpts specifies search criteria used by queries against an OpenStack service catalog.
ErrAPIKeyProvided indicates that an APIKey was provided but can't be used.
ErrAppCredMissingSecret indicates that no Application Credential Secret was provided with Application Credential ID or Name.
ErrDefault400 is the default error type returned on a 400 HTTP response code.
ErrDefault401 is the default error type returned on a 401 HTTP response code.
ErrDefault403 is the default error type returned on a 403 HTTP response code.
ErrDefault404 is the default error type returned on a 404 HTTP response code.
ErrDefault405 is the default error type returned on a 405 HTTP response code.
ErrDefault408 is the default error type returned on a 408 HTTP response code.
ErrDefault409 is the default error type returned on a 409 HTTP response code.
ErrDefault429 is the default error type returned on a 429 HTTP response code.
ErrDefault500 is the default error type returned on a 500 HTTP response code.
ErrDefault503 is the default error type returned on a 503 HTTP response code.
ErrDomainIDOrDomainName indicates that a username was provided, but no domain to scope it.
ErrDomainIDWithToken indicates that a DomainID was provided, but token authentication is being used instead.
ErrDomainIDWithUserID indicates that a DomainID was provided, but unnecessary because a UserID is being used.
ErrDomainNameWithToken indicates that a DomainName was provided, but token authentication is being used instead.s.
ErrDomainNameWithUserID indicates that a DomainName was provided, but unnecessary because a UserID is being used.
ErrEndpointNotFound is returned when no available endpoints match the provided EndpointOpts.
ErrErrorAfterReauthentication is the error type returned when reauthentication succeeds, but an error occurs afterword (usually an HTTP error).
ErrInvalidInput is an error type used for most non-HTTP Gophercloud errors.
ErrMissingAnyoneOfEnvironmentVariables is the error when anyone of the environment variables is required in a particular situation but not provided by the user.
ErrMissingEnvironmentVariable is the error when environment variable is required in a particular situation but not provided by the user.
ErrMissingInput is the error when input is required in a particular situation but not provided by the user.
ErrMissingPassword indicates that no password was provided and no token is available.
ErrMultipleResourcesFound is the error when trying to retrieve a resource's ID by name and multiple resources have the user-provided name.
ErrResourceNotFound is the error when trying to retrieve a resource's ID by name and the resource doesn't exist.
ErrResult is an internal type to be used by individual resource packages, but its methods will be available on a wide variety of user-facing embedding types.
ErrScopeDomainIDOrDomainName indicates that a domain ID or Name was required in a Scope, but not present.
ErrScopeEmpty indicates that no credentials were provided in a Scope.
ErrScopeProjectIDAlone indicates that a ProjectID was provided with other constraints in a Scope.
ErrScopeProjectIDOrProjectName indicates that both a ProjectID and a ProjectName were provided in a Scope.
ErrServiceNotFound is returned when no service in a service catalog matches the provided EndpointOpts.
ErrTenantIDProvided indicates that a TenantID was provided but can't be used.
ErrTenantNameProvided indicates that a TenantName was provided but can't be used.
ErrTimeOut is the error type returned when an operations times out.
ErrUnableToReauthenticate is the error type returned when reauthentication fails.
ErrUnexpectedResponseCode is returned by the Request method when a response code other than those listed in OkCodes is encountered.
ErrUnexpectedType is the error when an unexpected type is encountered.
ErrUserIDWithToken indicates that a UserID was provided, but token authentication is being used instead.
ErrUsernameOrUserID indicates that neither username nor userID are specified, or both are at once.
ErrUsernameWithToken indicates that a Username was provided, but token authentication is being used instead.
HeaderResult is an internal type to be used by individual resource packages, but its methods will be available on a wide variety of user-facing embedding types.
Link is an internal type to be used in packages of collection resources that are paginated in a certain way.
ProviderClient stores details that are required to interact with any services within a specific provider's API.
RequestOpts customizes the behavior of the provider.Request() method.
Result is an internal type to be used by individual resource packages, but its methods will be available on a wide variety of user-facing embedding types.
ServiceClient stores details required to interact with a specific service API implemented by a provider.
UserAgent represents a User-Agent header.

# Interfaces

AuthResult is the result from the request that was used to obtain a provider client's Keystone token.
Err400er is the interface resource error types implement to override the error message from a 400 error.
Err401er is the interface resource error types implement to override the error message from a 401 error.
Err403er is the interface resource error types implement to override the error message from a 403 error.
Err404er is the interface resource error types implement to override the error message from a 404 error.
Err405er is the interface resource error types implement to override the error message from a 405 error.
Err408er is the interface resource error types implement to override the error message from a 408 error.
Err409er is the interface resource error types implement to override the error message from a 409 error.
Err429er is the interface resource error types implement to override the error message from a 429 error.
Err500er is the interface resource error types implement to override the error message from a 500 error.
Err503er is the interface resource error types implement to override the error message from a 503 error.
StatusCodeError is a convenience interface to easily allow access to the status code field of the various ErrDefault* types.

# Type aliases

Availability indicates to whom a specific service endpoint is accessible: the internet at large, internal networks only, or only to administrators.
EndpointLocator is an internal function to be used by provider implementations.
IPVersion is a type for the possible IP address versions.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
RetryFunc is a catch-all function for retrying failed API requests.