tasks

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2019 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package tasks enables management and retrieval of tasks from the OpenStack Imageservice.

Example to List Tasks

listOpts := tasks.ListOpts{
  Owner: "424e7cf0243c468ca61732ba45973b3e",
}

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

allTasks, err := tasks.ExtractTasks(allPages)
if err != nil {
  panic(err)
}

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

Example to Get a Task

task, err := tasks.Get(imagesClient, "1252f636-1246-4319-bfba-c47cde0efbe0").Extract()
if err != nil {
  panic(err)
}

fmt.Printf("%+v\n", task)

Example to Create a Task

createOpts := tasks.CreateOpts{
  Type: "import",
  Input: map[string]interface{}{
    "image_properties": map[string]interface{}{
      "container_format": "bare",
      "disk_format":      "raw",
    },
    "import_from_format": "raw",
    "import_from":        "https://cloud-images.ubuntu.com/bionic/current/bionic-server-cloudimg-amd64.img",
  },
}

task, err := tasks.Create(imagesClient, createOpts).Extract()
if err != nil {
  panic(err)
}

fmt.Printf("%+v\n", task)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func List

List returns a Pager which allows you to iterate over a collection of the tasks.

Types

type CreateOpts

type CreateOpts struct {
	Type  string                 `json:"type" required:"true"`
	Input map[string]interface{} `json:"input"`
}

CreateOpts specifies parameters of a new Imageservice task.

func (CreateOpts) ToTaskCreateMap

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

ToTaskCreateMap constructs a request body from CreateOpts.

type CreateOptsBuilder

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

CreateOptsBuilder allows to add additional 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 a Task.

func Create

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

Create requests the creation of a new Imageservice task on the server.

func (CreateResult) Extract

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

Extract interprets any commonResult as a Task.

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 a Task.

func Get

func Get(c *gophercloud.ServiceClient, taskID string) (r GetResult)

Get retrieves a specific Imageservice task based on its ID.

func (GetResult) Extract

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

Extract interprets any commonResult as a Task.

type ListOpts

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

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

	// SortDir allows to select sort direction.
	// It can be "asc" or "desc" (default).
	SortDir string `q:"sort_dir"`

	// SortKey allows to sort by one of the following tTask attributes:
	//  - created_at
	//  - expires_at
	//  - status
	//  - type
	//  - updated_at
	// Default is created_at.
	SortKey string `q:"sort_key"`

	// ID filters on the identifier of the task.
	ID string `json:"id"`

	// Type filters on the type of the task.
	Type string `json:"type"`

	// Status filters on the status of the task.
	Status TaskStatus `q:"status"`
}

ListOpts allows the filtering and sorting of paginated collections through the OpenStack Imageservice tasks API.

func (ListOpts) ToTaskListQuery

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

ToTaskListQuery formats a ListOpts into a query string.

type ListOptsBuilder

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

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

type Task

type Task struct {
	// ID is a unique identifier of the task.
	ID string `json:"id"`

	// Type represents the type of the task.
	Type string `json:"type"`

	// Status represents current status of the task.
	// You can use the TaskStatus custom type to unmarshal raw JSON response into
	// the pre-defined valid task status.
	Status string `json:"status"`

	// Input represents different parameters for the task.
	Input map[string]interface{} `json:"input"`

	// Result represents task result details.
	Result map[string]interface{} `json:"result"`

	// Owner is a unique identifier of the task owner.
	Owner string `json:"owner"`

	// Message represents human-readable message that is usually populated
	// on task failure.
	Message string `json:"message"`

	// ExpiresAt contains the timestamp of when the task will become a subject of
	// removal.
	ExpiresAt time.Time `json:"expires_at"`

	// CreatedAt contains the task creation timestamp.
	CreatedAt time.Time `json:"created_at"`

	// UpdatedAt contains the latest timestamp of when the task was updated.
	UpdatedAt time.Time `json:"updated_at"`

	// Self contains URI for the task.
	Self string `json:"self"`

	// Schema the path to the JSON-schema that represent the task.
	Schema string `json:"schema"`
}

Task represents a single task of the OpenStack Image service.

func ExtractTasks

func ExtractTasks(r pagination.Page) ([]Task, error)

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

type TaskPage

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

TaskPage represents the results of a List request.

func (TaskPage) IsEmpty

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

IsEmpty returns true if a TaskPage contains no Tasks results.

func (TaskPage) NextPageURL

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

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

type TaskStatus

type TaskStatus string

TaskStatus represents valid task status. You can use this type to compare the actual status of a task to a one of the pre-defined statuses.

const (
	// TaskStatusPending represents status of the pending task.
	TaskStatusPending TaskStatus = "pending"

	// TaskStatusProcessing represents status of the processing task.
	TaskStatusProcessing TaskStatus = "processing"

	// TaskStatusSuccess represents status of the success task.
	TaskStatusSuccess TaskStatus = "success"

	// TaskStatusFailure represents status of the failure task.
	TaskStatusFailure TaskStatus = "failure"
)

Directories

Path Synopsis
tasks unit tests
tasks unit tests

Jump to

Keyboard shortcuts

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