images

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2020 License: Apache-2.0 Imports: 10 Imported by: 230

Documentation

Overview

Package images enables management and retrieval of images from the OpenStack Image Service.

Example to List Images

images.ListOpts{
	Owner: "a7509e1ae65945fda83f3e52c6296017",
}

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

allImages, err := images.ExtractImages(allPages)
if err != nil {
	panic(err)
}

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

Example to Create an Image

createOpts := images.CreateOpts{
	Name:       "image_name",
	Visibility: images.ImageVisibilityPrivate,
}

image, err := images.Create(imageClient, createOpts)
if err != nil {
	panic(err)
}

Example to Update an Image

imageID := "1bea47ed-f6a9-463b-b423-14b9cca9ad27"

updateOpts := images.UpdateOpts{
	images.ReplaceImageName{
		NewName: "new_name",
	},
}

image, err := images.Update(imageClient, imageID, updateOpts).Extract()
if err != nil {
	panic(err)
}

Example to Delete an Image

imageID := "1bea47ed-f6a9-463b-b423-14b9cca9ad27"
err := images.Delete(imageClient, imageID).ExtractErr()
if err != nil {
	panic(err)
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func List

List implements image list request.

Types

type CreateOpts

type CreateOpts struct {
	// Name is the name of the new image.
	Name string `json:"name" required:"true"`

	// Id is the the image ID.
	ID string `json:"id,omitempty"`

	// Visibility defines who can see/use the image.
	Visibility *ImageVisibility `json:"visibility,omitempty"`

	// Tags is a set of image tags.
	Tags []string `json:"tags,omitempty"`

	// ContainerFormat is the format of the
	// container. Valid values are ami, ari, aki, bare, and ovf.
	ContainerFormat string `json:"container_format,omitempty"`

	// DiskFormat is the format of the disk. If set,
	// valid values are ami, ari, aki, vhd, vmdk, raw, qcow2, vdi,
	// and iso.
	DiskFormat string `json:"disk_format,omitempty"`

	// MinDisk is the amount of disk space in
	// GB that is required to boot the image.
	MinDisk int `json:"min_disk,omitempty"`

	// MinRAM is the amount of RAM in MB that
	// is required to boot the image.
	MinRAM int `json:"min_ram,omitempty"`

	// protected is whether the image is not deletable.
	Protected *bool `json:"protected,omitempty"`

	// properties is a set of properties, if any, that
	// are associated with the image.
	Properties map[string]string `json:"-"`
}

CreateOpts represents options used to create an image.

func (CreateOpts) ToImageCreateMap

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

ToImageCreateMap assembles a request body based on the contents of a CreateOpts.

type CreateOptsBuilder

type CreateOptsBuilder interface {
	// Returns value that can be passed to json.Marshal
	ToImageCreateMap() (map[string]interface{}, error)
}

CreateOptsBuilder allows extensions to add parameters to the Create request.

type CreateResult

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

CreateResult represents the result of a Create operation. Call its Extract method to interpret it as an Image.

func Create

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

Create implements create image request.

func (CreateResult) Extract

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

Extract interprets any commonResult as an Image.

type DeleteResult

type DeleteResult struct {
	gophercloud.ErrResult
}

DeleteResult represents the result of a Delete operation. Call its ExtractErr method to interpret it as an Image.

func Delete

func Delete(client *gophercloud.ServiceClient, id string) (r DeleteResult)

Delete implements image delete request.

type GetResult

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

GetResult represents the result of a Get operation. Call its Extract method to interpret it as an Image.

func Get

func Get(client *gophercloud.ServiceClient, id string) (r GetResult)

Get implements image get request.

func (GetResult) Extract

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

Extract interprets any commonResult as an Image.

type Image

type Image struct {
	// ID is the image UUID.
	ID string `json:"id"`

	// Name is the human-readable display name for the image.
	Name string `json:"name"`

	// Status is the image status. It can be "queued" or "active"
	// See imageservice/v2/images/type.go
	Status ImageStatus `json:"status"`

	// Tags is a list of image tags. Tags are arbitrarily defined strings
	// attached to an image.
	Tags []string `json:"tags"`

	// ContainerFormat is the format of the container.
	// Valid values are ami, ari, aki, bare, and ovf.
	ContainerFormat string `json:"container_format"`

	// DiskFormat is the format of the disk.
	// If set, valid values are ami, ari, aki, vhd, vmdk, raw, qcow2, vdi,
	// and iso.
	DiskFormat string `json:"disk_format"`

	// MinDiskGigabytes is the amount of disk space in GB that is required to
	// boot the image.
	MinDiskGigabytes int `json:"min_disk"`

	// MinRAMMegabytes [optional] is the amount of RAM in MB that is required to
	// boot the image.
	MinRAMMegabytes int `json:"min_ram"`

	// Owner is the tenant ID the image belongs to.
	Owner string `json:"owner"`

	// Protected is whether the image is deletable or not.
	Protected bool `json:"protected"`

	// Visibility defines who can see/use the image.
	Visibility ImageVisibility `json:"visibility"`

	// Checksum is the checksum of the data that's associated with the image.
	Checksum string `json:"checksum"`

	// SizeBytes is the size of the data that's associated with the image.
	SizeBytes int64 `json:"-"`

	// Metadata is a set of metadata associated with the image.
	// Image metadata allow for meaningfully define the image properties
	// and tags.
	// See http://docs.openstack.org/developer/glance/metadefs-concepts.html.
	Metadata map[string]string `json:"metadata"`

	// Properties is a set of key-value pairs, if any, that are associated with
	// the image.
	Properties map[string]interface{}

	// CreatedAt is the date when the image has been created.
	CreatedAt time.Time `json:"created_at"`

	// UpdatedAt is the date when the last change has been made to the image or
	// it's properties.
	UpdatedAt time.Time `json:"updated_at"`

	// File is the trailing path after the glance endpoint that represent the
	// location of the image or the path to retrieve it.
	File string `json:"file"`

	// Schema is the path to the JSON-schema that represent the image or image
	// entity.
	Schema string `json:"schema"`

	// VirtualSize is the virtual size of the image
	VirtualSize int64 `json:"virtual_size"`

	// OpenStackImageImportMethods is a slice listing the types of import
	// methods available in the cloud.
	OpenStackImageImportMethods []string `json:"-"`
	// OpenStackImageStoreIDs is a slice listing the store IDs available in
	// the cloud.
	OpenStackImageStoreIDs []string `json:"-"`
}

Image represents an image found in the OpenStack Image service.

func ExtractImages

func ExtractImages(r pagination.Page) ([]Image, error)

ExtractImages interprets the results of a single page from a List() call, producing a slice of Image entities.

func (*Image) UnmarshalJSON

func (r *Image) UnmarshalJSON(b []byte) error

type ImageDateFilter

type ImageDateFilter string

ImageDateFilter represents a valid filter to use for filtering images by their date during a List.

const (
	FilterGT  ImageDateFilter = "gt"
	FilterGTE ImageDateFilter = "gte"
	FilterLT  ImageDateFilter = "lt"
	FilterLTE ImageDateFilter = "lte"
	FilterNEQ ImageDateFilter = "neq"
	FilterEQ  ImageDateFilter = "eq"
)

type ImageDateQuery

type ImageDateQuery struct {
	Date   time.Time
	Filter ImageDateFilter
}

ImageDateQuery represents a date field to be used for listing images. If no filter is specified, the query will act as though FilterEQ was set.

type ImageMemberStatus

type ImageMemberStatus string

MemberStatus is a status for adding a new member (tenant) to an image member list.

const (
	// ImageMemberStatusAccepted is the status for an accepted image member.
	ImageMemberStatusAccepted ImageMemberStatus = "accepted"

	// ImageMemberStatusPending shows that the member addition is pending
	ImageMemberStatusPending ImageMemberStatus = "pending"

	// ImageMemberStatusAccepted is the status for a rejected image member
	ImageMemberStatusRejected ImageMemberStatus = "rejected"

	// ImageMemberStatusAll
	ImageMemberStatusAll ImageMemberStatus = "all"
)

type ImagePage

type ImagePage struct {
	pagination.LinkedPageBase
	// contains filtered or unexported fields
}

ImagePage represents the results of a List request.

func (ImagePage) IsEmpty

func (r ImagePage) IsEmpty() (bool, error)

IsEmpty returns true if an ImagePage contains no Images results.

func (ImagePage) NextPageURL

func (r ImagePage) NextPageURL() (string, error)

NextPageURL uses the response's embedded link reference to navigate to the next page of results.

type ImageStatus

type ImageStatus string

ImageStatus image statuses http://docs.openstack.org/developer/glance/statuses.html

const (
	// ImageStatusQueued is a status for an image which identifier has
	// been reserved for an image in the image registry.
	ImageStatusQueued ImageStatus = "queued"

	// ImageStatusSaving denotes that an image’s raw data is currently being
	// uploaded to Glance
	ImageStatusSaving ImageStatus = "saving"

	// ImageStatusActive denotes an image that is fully available in Glance.
	ImageStatusActive ImageStatus = "active"

	// ImageStatusKilled denotes that an error occurred during the uploading
	// of an image’s data, and that the image is not readable.
	ImageStatusKilled ImageStatus = "killed"

	// ImageStatusDeleted is used for an image that is no longer available to use.
	// The image information is retained in the image registry.
	ImageStatusDeleted ImageStatus = "deleted"

	// ImageStatusPendingDelete is similar to Delete, but the image is not yet
	// deleted.
	ImageStatusPendingDelete ImageStatus = "pending_delete"

	// ImageStatusDeactivated denotes that access to image data is not allowed to
	// any non-admin user.
	ImageStatusDeactivated ImageStatus = "deactivated"

	// ImageStatusImporting denotes that an import call has been made but that
	// the image is not yet ready for use.
	ImageStatusImporting ImageStatus = "importing"
)

type ImageVisibility

type ImageVisibility string

ImageVisibility denotes an image that is fully available in Glance. This occurs when the image data is uploaded, or the image size is explicitly set to zero on creation. According to design https://wiki.openstack.org/wiki/Glance-v2-community-image-visibility-design

const (
	// ImageVisibilityPublic all users
	ImageVisibilityPublic ImageVisibility = "public"

	// ImageVisibilityPrivate users with tenantId == tenantId(owner)
	ImageVisibilityPrivate ImageVisibility = "private"

	// ImageVisibilityShared images are visible to:
	// - users with tenantId == tenantId(owner)
	// - users with tenantId in the member-list of the image
	// - users with tenantId in the member-list with member_status == 'accepted'
	ImageVisibilityShared ImageVisibility = "shared"

	// ImageVisibilityCommunity images:
	// - all users can see and boot it
	// - users with tenantId in the member-list of the image with
	//	 member_status == 'accepted' have this image in their default image-list.
	ImageVisibilityCommunity ImageVisibility = "community"
)

type ListOpts

type ListOpts struct {
	// ID is the ID of the image.
	// Multiple IDs can be specified by constructing a string
	// such as "in:uuid1,uuid2,uuid3".
	ID string `q:"id"`

	// Integer value for the limit of values to return.
	Limit int `q:"limit"`

	// UUID of the server at which you want to set a marker.
	Marker string `q:"marker"`

	// Name filters on the name of the image.
	// Multiple names can be specified by constructing a string
	// such as "in:name1,name2,name3".
	Name string `q:"name"`

	// Visibility filters on the visibility of the image.
	Visibility ImageVisibility `q:"visibility"`

	// MemberStatus filters on the member status of the image.
	MemberStatus ImageMemberStatus `q:"member_status"`

	// Owner filters on the project ID of the image.
	Owner string `q:"owner"`

	// Status filters on the status of the image.
	// Multiple statuses can be specified by constructing a string
	// such as "in:saving,queued".
	Status ImageStatus `q:"status"`

	// SizeMin filters on the size_min image property.
	SizeMin int64 `q:"size_min"`

	// SizeMax filters on the size_max image property.
	SizeMax int64 `q:"size_max"`

	// Sort sorts the results using the new style of sorting. See the OpenStack
	// Image API reference for the exact syntax.
	//
	// Sort cannot be used with the classic sort options (sort_key and sort_dir).
	Sort string `q:"sort"`

	// SortKey will sort the results based on a specified image property.
	SortKey string `q:"sort_key"`

	// SortDir will sort the list results either ascending or decending.
	SortDir string `q:"sort_dir"`

	// Tags filters on specific image tags.
	Tags []string `q:"tag"`

	// CreatedAtQuery filters images based on their creation date.
	CreatedAtQuery *ImageDateQuery

	// UpdatedAtQuery filters images based on their updated date.
	UpdatedAtQuery *ImageDateQuery

	// ContainerFormat filters images based on the container_format.
	// Multiple container formats can be specified by constructing a
	// string such as "in:bare,ami".
	ContainerFormat string `q:"container_format"`

	// DiskFormat filters images based on the disk_format.
	// Multiple disk formats can be specified by constructing a string
	// such as "in:qcow2,iso".
	DiskFormat string `q:"disk_format"`
}

ListOpts allows the filtering and sorting of paginated collections through the API. Filtering is achieved by passing in struct field values that map to the server attributes you want to see returned. Marker and Limit are used for pagination.

http://developer.openstack.org/api-ref-image-v2.html

func (ListOpts) ToImageListQuery

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

ToImageListQuery formats a ListOpts into a query string.

type ListOptsBuilder

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

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

type Patch

type Patch interface {
	ToImagePatchMap() map[string]interface{}
}

Patch represents a single update to an existing image. Multiple updates to an image can be submitted at the same time.

type ReplaceImageChecksum

type ReplaceImageChecksum struct {
	Checksum string
}

ReplaceImageChecksum represents an updated checksum property request.

func (ReplaceImageChecksum) ToImagePatchMap

func (r ReplaceImageChecksum) ToImagePatchMap() map[string]interface{}

ReplaceImageChecksum assembles a request body based on ReplaceImageChecksum.

type ReplaceImageMinDisk

type ReplaceImageMinDisk struct {
	NewMinDisk int
}

ReplaceImageMinDisk represents an updated min_disk property request.

func (ReplaceImageMinDisk) ToImagePatchMap

func (r ReplaceImageMinDisk) ToImagePatchMap() map[string]interface{}

ToImagePatchMap assembles a request body based on ReplaceImageTags.

type ReplaceImageMinRam added in v0.9.0

type ReplaceImageMinRam struct {
	NewMinRam int
}

ReplaceImageMinRam represents an updated min_ram property request.

func (ReplaceImageMinRam) ToImagePatchMap added in v0.9.0

func (r ReplaceImageMinRam) ToImagePatchMap() map[string]interface{}

ToImagePatchMap assembles a request body based on ReplaceImageTags.

type ReplaceImageName

type ReplaceImageName struct {
	NewName string
}

ReplaceImageName represents an updated image_name property request.

func (ReplaceImageName) ToImagePatchMap

func (r ReplaceImageName) ToImagePatchMap() map[string]interface{}

ToImagePatchMap assembles a request body based on ReplaceImageName.

type ReplaceImageTags

type ReplaceImageTags struct {
	NewTags []string
}

ReplaceImageTags represents an updated tags property request.

func (ReplaceImageTags) ToImagePatchMap

func (r ReplaceImageTags) ToImagePatchMap() map[string]interface{}

ToImagePatchMap assembles a request body based on ReplaceImageTags.

type UpdateImageProperty

type UpdateImageProperty struct {
	Op    UpdateOp
	Name  string
	Value string
}

UpdateImageProperty represents an update property request.

func (UpdateImageProperty) ToImagePatchMap

func (r UpdateImageProperty) ToImagePatchMap() map[string]interface{}

ToImagePatchMap assembles a request body based on UpdateImageProperty.

type UpdateOp

type UpdateOp string

UpdateOp represents a valid update operation.

const (
	AddOp     UpdateOp = "add"
	ReplaceOp UpdateOp = "replace"
	RemoveOp  UpdateOp = "remove"
)

type UpdateOpts

type UpdateOpts []Patch

UpdateOpts implements UpdateOpts

func (UpdateOpts) ToImageUpdateMap

func (opts UpdateOpts) ToImageUpdateMap() ([]interface{}, error)

ToImageUpdateMap assembles a request body based on the contents of UpdateOpts.

type UpdateOptsBuilder

type UpdateOptsBuilder interface {
	// returns value implementing json.Marshaler which when marshaled matches
	// the patch schema:
	// http://specs.openstack.org/openstack/glance-specs/specs/api/v2/http-patch-image-api-v2.html
	ToImageUpdateMap() ([]interface{}, error)
}

UpdateOptsBuilder allows extensions to add additional parameters to the Update request.

type UpdateResult

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

UpdateResult represents the result of an Update operation. Call its Extract method to interpret it as an Image.

func Update

func Update(client *gophercloud.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult)

Update implements image updated request.

func (UpdateResult) Extract

func (r UpdateResult) Extract() (*Image, error)

Extract interprets any commonResult as an Image.

type UpdateVisibility

type UpdateVisibility struct {
	Visibility ImageVisibility
}

UpdateVisibility represents an updated visibility property request.

func (UpdateVisibility) ToImagePatchMap

func (r UpdateVisibility) ToImagePatchMap() map[string]interface{}

ToImagePatchMap assembles a request body based on UpdateVisibility.

Directories

Path Synopsis
images unit tests
images unit tests

Jump to

Keyboard shortcuts

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