github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/state/cloudimagemetadata/interface.go (about)

     1  // Copyright 2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package cloudimagemetadata
     5  
     6  import (
     7  	jujutxn "github.com/juju/txn/v3"
     8  
     9  	"github.com/juju/juju/mongo"
    10  )
    11  
    12  // MetadataAttributes contains cloud image metadata attributes.
    13  type MetadataAttributes struct {
    14  	// Stream contains reference to a particular stream,
    15  	// for e.g. "daily" or "released"
    16  	Stream string
    17  
    18  	// Region is the name of cloud region associated with the image.
    19  	Region string
    20  
    21  	// Version is OS version, for e.g. "22.04".
    22  	Version string
    23  
    24  	// Arch is the architecture for this cloud image, for e.g. "amd64"
    25  	Arch string
    26  
    27  	// VirtType contains virtualisation type of the cloud image, for e.g. "pv", "hvm". "kvm".
    28  	VirtType string
    29  
    30  	// RootStorageType contains type of root storage, for e.g. "ebs", "instance".
    31  	RootStorageType string
    32  
    33  	// RootStorageSize contains size of root storage in gigabytes (GB).
    34  	RootStorageSize *uint64
    35  
    36  	// Source describes where this image is coming from: is it public? custom?
    37  	Source string
    38  }
    39  
    40  // Metadata describes a cloud image metadata.
    41  type Metadata struct {
    42  	MetadataAttributes
    43  
    44  	// Priority is an importance factor for image metadata.
    45  	// Higher number means higher priority.
    46  	// This will allow to sort metadata by importance.
    47  	Priority int
    48  
    49  	// ImageId contains image identifier.
    50  	ImageId string
    51  
    52  	// DateCreated contains the time and date the image was created. This
    53  	// is populated when the Metadata is saved.
    54  	DateCreated int64
    55  }
    56  
    57  // Storage provides methods for storing and retrieving cloud image metadata.
    58  type Storage interface {
    59  	// SaveMetadata adds cloud images metadata into state if it's new or
    60  	// updates metadata if it already exists.
    61  	// Non custom records will expire after a set time.
    62  	SaveMetadata([]Metadata) error
    63  
    64  	// DeleteMetadata deletes cloud image metadata from state.
    65  	DeleteMetadata(imageId string) error
    66  
    67  	// FindMetadata returns all Metadata that match specified
    68  	// criteria or a "not found" error if none match.
    69  	// Empty criteria will return all cloud image metadata.
    70  	// Returned result is grouped by source type and ordered by date created.
    71  	FindMetadata(criteria MetadataFilter) (map[string][]Metadata, error)
    72  
    73  	// SupportedArchitectures returns collection of unique architectures
    74  	// that stored metadata contains.
    75  	SupportedArchitectures(criteria MetadataFilter) ([]string, error)
    76  
    77  	// AllCloudImageMetadata returns all the cloud image metadata in the
    78  	// model.
    79  	AllCloudImageMetadata() ([]Metadata, error)
    80  }
    81  
    82  // DataStore exposes data store operations for use by the cloud image metadata package.
    83  type DataStore interface {
    84  
    85  	// RunTransaction runs desired transactions against this data source..
    86  	RunTransaction(jujutxn.TransactionSource) error
    87  
    88  	// GetCollection retrieves desired collection from this data source.
    89  	GetCollection(name string) (collection mongo.Collection, closer func())
    90  }