github.com/axw/juju@v0.0.0-20161005053422-4bd6544d08d4/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"
     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. "12.04".
    22  	Version string
    23  
    24  	// Series is OS series, for e.g. "trusty".
    25  	Series string
    26  
    27  	// Arch is the architecture for this cloud image, for e.g. "amd64"
    28  	Arch string
    29  
    30  	// VirtType contains virtualisation type of the cloud image, for e.g. "pv", "hvm". "kvm".
    31  	VirtType string
    32  
    33  	// RootStorageType contains type of root storage, for e.g. "ebs", "instance".
    34  	RootStorageType string
    35  
    36  	// RootStorageSize contains size of root storage in gigabytes (GB).
    37  	RootStorageSize *uint64
    38  
    39  	// Source describes where this image is coming from: is it public? custom?
    40  	Source string
    41  }
    42  
    43  // Metadata describes a cloud image metadata.
    44  type Metadata struct {
    45  	MetadataAttributes
    46  
    47  	// Priority is an importance factor for image metadata.
    48  	// Higher number means higher priority.
    49  	// This will allow to sort metadata by importance.
    50  	Priority int
    51  
    52  	// ImageId contains image identifier.
    53  	ImageId string
    54  
    55  	// DateCreated contains the time and date the image was created. This
    56  	// is populated when the Metadata is saved.
    57  	DateCreated int64
    58  }
    59  
    60  // Storage provides methods for storing and retrieving cloud image metadata.
    61  type Storage interface {
    62  	// SaveMetadata adds cloud images metadata into state if it's new or
    63  	// updates metadata if it already exists.
    64  	SaveMetadata([]Metadata) error
    65  
    66  	// DeleteMetadata deletes cloud image metadata from state.
    67  	DeleteMetadata(imageId string) error
    68  
    69  	// FindMetadata returns all Metadata that match specified
    70  	// criteria or a "not found" error if none match.
    71  	// Empty criteria will return all cloud image metadata.
    72  	// Returned result is grouped by source type and ordered by date created.
    73  	FindMetadata(criteria MetadataFilter) (map[string][]Metadata, error)
    74  
    75  	// SupportedArchitectures returns collection of unique architectures
    76  	// that stored metadata contains.
    77  	SupportedArchitectures(criteria MetadataFilter) ([]string, error)
    78  
    79  	// AllCloudImageMetadata returns all the cloud image metadata in the
    80  	// model.
    81  	AllCloudImageMetadata() ([]Metadata, error)
    82  }
    83  
    84  // DataStore exposes data store operations for use by the cloud image metadata package.
    85  type DataStore interface {
    86  
    87  	// RunTransaction runs desired transactions against this data source..
    88  	RunTransaction(jujutxn.TransactionSource) error
    89  
    90  	// GetCollection retrieves desired collection from this data source.
    91  	GetCollection(name string) (collection mongo.Collection, closer func())
    92  }