keypairs

package
v1.1.7 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package keypairs provides the ability to manage key pairs as well as create servers with a specified key pair.

Example to List Key Pairs

allPages, err := keypairs.List(computeClient, nil).AllPages()
if err != nil {
	panic(err)
}

allKeyPairs, err := keypairs.ExtractKeyPairs(allPages)
if err != nil {
	panic(err)
}

for _, kp := range allKeyPairs {
	fmt.Printf("%+v\n", kp)
}

Example to List Key Pairs using microversion 2.10 or greater

client.Microversion = "2.10"

listOpts := keypairs.ListOpts{
	UserID: "user-id",
}

allPages, err := keypairs.List(computeClient, listOpts).AllPages()
if err != nil {
	panic(err)
}

allKeyPairs, err := keypairs.ExtractKeyPairs(allPages)
if err != nil {
	panic(err)
}

for _, kp := range allKeyPairs {
	fmt.Printf("%+v\n", kp)
}

Example to Create a Key Pair

createOpts := keypairs.CreateOpts{
	Name: "keypair-name",
}

keypair, err := keypairs.Create(computeClient, createOpts).Extract()
if err != nil {
	panic(err)
}

fmt.Printf("%+v", keypair)

Example to Import a Key Pair

createOpts := keypairs.CreateOpts{
	Name:      "keypair-name",
	PublicKey: "public-key",
}

keypair, err := keypairs.Create(computeClient, createOpts).Extract()
if err != nil {
	panic(err)
}

Example to Delete a Key Pair

err := keypairs.Delete(computeClient, "keypair-name", nil).ExtractErr()
if err != nil {
	panic(err)
}

Example to Delete a Key Pair owned by a certain user using microversion 2.10 or greater

client.Microversion = "2.10"

deleteOpts := keypairs.DeleteOpts{
	UserID: "user-id",
}

err := keypairs.Delete(client, "keypair-name", deleteOpts).ExtractErr()
if err != nil {
	panic(err)
}

Example to Create a Server With a Key Pair

serverCreateOpts := servers.CreateOpts{
	Name:      "server_name",
	ImageRef:  "image-uuid",
	FlavorRef: "flavor-uuid",
}

createOpts := keypairs.CreateOptsExt{
	CreateOptsBuilder: serverCreateOpts,
	KeyName:           "keypair-name",
}

server, err := servers.Create(computeClient, createOpts).Extract()
if err != nil {
	panic(err)
}

Example to Get a Key Pair owned by a certain user using microversion 2.10 or greater

client.Microversion = "2.10"

getOpts := keypairs.GetOpts{
	UserID: "user-id",
}

keypair, err := keypairs.Get(computeClient, "keypair-name", getOpts).Extract()
if err != nil {
	panic(err)
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func List

List returns a Pager that allows you to iterate over a collection of KeyPairs.

Types

type CreateOpts

type CreateOpts struct {
	// Name is a friendly name to refer to this KeyPair in other services.
	Name string `json:"name" required:"true"`

	// UserID [optional] is the user_id for a keypair.
	// This allows administrative users to upload keys for other users than themselves.
	// This requires microversion 2.10 or higher.
	UserID string `json:"user_id,omitempty"`

	// The type of the keypair. Allowed values are ssh or x509
	// This requires microversion 2.2 or higher.
	Type string `json:"type,omitempty"`

	// PublicKey [optional] is a pregenerated OpenSSH-formatted public key.
	// If provided, this key will be imported and no new key will be created.
	PublicKey string `json:"public_key,omitempty"`
}

CreateOpts specifies KeyPair creation or import parameters.

func (CreateOpts) ToKeyPairCreateMap

func (opts CreateOpts) ToKeyPairCreateMap() (map[string]interface{}, error)

ToKeyPairCreateMap constructs a request body from CreateOpts.

type CreateOptsBuilder

type CreateOptsBuilder interface {
	ToKeyPairCreateMap() (map[string]interface{}, error)
}

CreateOptsBuilder allows extensions to add additional parameters to the Create request.

type CreateOptsExt

type CreateOptsExt struct {
	servers.CreateOptsBuilder

	// KeyName is the name of the key pair.
	KeyName string `json:"key_name,omitempty"`
}

CreateOptsExt adds a KeyPair option to the base CreateOpts.

func (CreateOptsExt) ToServerCreateMap

func (opts CreateOptsExt) ToServerCreateMap() (map[string]interface{}, error)

ToServerCreateMap adds the key_name to the base server creation options.

type CreateResult

type CreateResult struct {
	// contains filtered or unexported fields
}

CreateResult is the response from a Create operation. Call its Extract method to interpret it as a KeyPair.

func Create

func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult)

Create requests the creation of a new KeyPair on the server, or to import a pre-existing keypair.

func (CreateResult) Extract

func (r CreateResult) Extract() (*KeyPair, error)

Extract is a method that attempts to interpret any KeyPair resource response as a KeyPair struct.

type DeleteOpts

type DeleteOpts struct {
	// UserID is the user ID of the user that owns the key pair.
	// This requires microversion 2.10 or higher.
	UserID string `q:"user_id"`
}

DeleteOpts enables deleting KeyPairs based on specific attributes.

func (DeleteOpts) ToKeyPairDeleteQuery

func (opts DeleteOpts) ToKeyPairDeleteQuery() (string, error)

ToKeyPairDeleteQuery formats a DeleteOpts into a query string.

type DeleteOptsBuilder

type DeleteOptsBuilder interface {
	ToKeyPairDeleteQuery() (string, error)
}

DeleteOptsBuilder allows extensions to add additional parameters to the Delete request.

type DeleteResult

type DeleteResult struct {
	gophercloud.ErrResult
}

DeleteResult is the response from a Delete operation. Call its ExtractErr method to determine if the call succeeded or failed.

func Delete

func Delete(client *gophercloud.ServiceClient, name string, opts DeleteOptsBuilder) (r DeleteResult)

Delete requests the deletion of a previous stored KeyPair from the server.

type GetOpts

type GetOpts struct {
	// UserID is the user ID that owns the key pair.
	// This requires microversion 2.10 or higher.
	UserID string `q:"user_id"`
}

GetOpts enables retrieving KeyPairs based on specific attributes.

func (GetOpts) ToKeyPairGetQuery

func (opts GetOpts) ToKeyPairGetQuery() (string, error)

ToKeyPairGetQuery formats a GetOpts into a query string.

type GetOptsBuilder

type GetOptsBuilder interface {
	ToKeyPairGetQuery() (string, error)
}

GetOptsBuilder allows extensions to add additional parameters to the Get request.

type GetResult

type GetResult struct {
	// contains filtered or unexported fields
}

GetResult is the response from a Get operation. Call its Extract method to interpret it as a KeyPair.

func Get

func Get(client *gophercloud.ServiceClient, name string, opts GetOptsBuilder) (r GetResult)

Get returns public data about a previously uploaded KeyPair.

func (GetResult) Extract

func (r GetResult) Extract() (*KeyPair, error)

Extract is a method that attempts to interpret any KeyPair resource response as a KeyPair struct.

type KeyPair

type KeyPair struct {
	// Name is used to refer to this keypair from other services within this
	// region.
	Name string `json:"name"`

	// Fingerprint is a short sequence of bytes that can be used to authenticate
	// or validate a longer public key.
	Fingerprint string `json:"fingerprint"`

	// PublicKey is the public key from this pair, in OpenSSH format.
	// "ssh-rsa AAAAB3Nz..."
	PublicKey string `json:"public_key"`

	// The type of the keypair
	Type string `json:"type"`
}

KeyPair is an SSH key known to the OpenStack Cloud that is available to be injected into servers.

func ExtractKeyPairs

func ExtractKeyPairs(r pagination.Page) ([]KeyPair, error)

ExtractKeyPairs interprets a page of results as a slice of KeyPairs.

type KeyPairPage

type KeyPairPage struct {
	pagination.SinglePageBase
}

KeyPairPage stores a single page of all KeyPair results from a List call. Use the ExtractKeyPairs function to convert the results to a slice of KeyPairs.

func (KeyPairPage) IsEmpty

func (page KeyPairPage) IsEmpty() (bool, error)

IsEmpty determines whether or not a KeyPairPage is empty.

type ListOpts

type ListOpts struct {
	// UserID is the user ID that owns the key pair.
	// This requires microversion 2.10 or higher.
	UserID string `q:"user_id"`
}

ListOpts enables listing KeyPairs based on specific attributes.

func (ListOpts) ToKeyPairListQuery

func (opts ListOpts) ToKeyPairListQuery() (string, error)

ToKeyPairListQuery formats a ListOpts into a query string.

type ListOptsBuilder

type ListOptsBuilder interface {
	ToKeyPairListQuery() (string, error)
}

ListOptsBuilder allows extensions to add additional parameters to the List request.

Directories

Path Synopsis
keypairs unit tests
keypairs unit tests

Jump to

Keyboard shortcuts

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