images-go

module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2026 License: Apache-2.0

README

images-go: Go SDK for the Selectel Images API

Go.dev reference Go Report Card Build Status

Package images-go provides Go SDK to work with the Selectel Images API, which is an OpenStack Glance v2 API.

Documentation

The Go library documentation is available at go.dev.

What this library is capable of

You can use this library to work with the following objects of the Selectel Images API:

Getting started

Installation

You can install needed images-go packages via go get command:

go get github.com/selectel/images-go/pkg/v1/image github.com/selectel/images-go/pkg/v1/member
Authentication

To work with the Selectel Images API you first need to:

Endpoints

The Images API endpoint is region-specific. Retrieve the endpoint of the image service type for the required region from the Identity catalog.

Usage example
package main

import (
	"context"
	"fmt"
	"log"
	"os"

	v1 "github.com/selectel/images-go/pkg/v1"
	"github.com/selectel/images-go/pkg/v1/image"
	"github.com/selectel/images-go/pkg/v1/member"
)

func main() {
	ctx := context.Background()

	// Token of the project and endpoint of the Images API in the required region.
	token := "gAAAAABeVNzu-..."
	endpoint := "<image-endpoint-from-the-identity-catalog>"

	// Initialize the Images API client.
	client, err := v1.NewClient(v1.Config{
		Endpoint:  endpoint,
		Token:     token,
		UserAgent: "my-application/v1.0.0",
	})
	if err != nil {
		log.Fatal(err)
	}

	// Create an image.
	newImage, _, err := image.Create(ctx, client, image.CreateOpts{
		Name:            "test-image",
		ContainerFormat: "bare",
		DiskFormat:      "qcow2",
	})
	if err != nil {
		log.Fatal(err)
	}

	// Upload the image data.
	file, err := os.Open("test-image.qcow2")
	if err != nil {
		log.Fatal(err)
	}
	defer file.Close()

	info, err := file.Stat()
	if err != nil {
		log.Fatal(err)
	}

	if _, err := image.Upload(ctx, client, newImage.ID, file, info.Size()); err != nil {
		log.Fatal(err)
	}

	// Print the image fields.
	uploaded, _, err := image.Get(ctx, client, newImage.ID)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Printf("Image: %+v\n", uploaded)

	// Share the image with another project.
	if _, _, err := member.Create(ctx, client, newImage.ID, "9c5cd8d6d4bb4f4a91e3d5e6f7a8b9c0"); err != nil {
		log.Fatal(err)
	}
}

Directories

Path Synopsis
pkg
v1
Package v1 provides the client and common types for the Selectel Images SDK.
Package v1 provides the client and common types for the Selectel Images SDK.
v1/image
Package image provides typed operations on Glance v2 images: creating, reading, listing, updating and deleting an image, uploading its data, importing it from a URL and reading its tasks.
Package image provides typed operations on Glance v2 images: creating, reading, listing, updating and deleting an image, uploading its data, importing it from a URL and reading its tasks.
v1/member
Package member provides typed operations on the members of a shared Glance v2 image: the projects that were granted access to it and the status of that access.
Package member provides typed operations on the members of a shared Glance v2 image: the projects that were granted access to it and the status of that access.

Jump to

Keyboard shortcuts

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