github.com/emc-advanced-dev/unik@v0.0.0-20190717152701-a58d3e8e33b7/pkg/providers/interface.go (about)

     1  package providers
     2  
     3  import (
     4  	"github.com/emc-advanced-dev/pkg/errors"
     5  	"github.com/solo-io/unik/pkg/types"
     6  )
     7  
     8  type Provider interface {
     9  	GetConfig() ProviderConfig
    10  	//Images
    11  	Stage(params types.StageImageParams) (*types.Image, error)
    12  	ListImages() ([]*types.Image, error)
    13  	GetImage(nameOrIdPrefix string) (*types.Image, error)
    14  	DeleteImage(id string, force bool) error
    15  	//Instances
    16  	RunInstance(params types.RunInstanceParams) (*types.Instance, error)
    17  	ListInstances() ([]*types.Instance, error)
    18  	GetInstance(nameOrIdPrefix string) (*types.Instance, error)
    19  	DeleteInstance(id string, force bool) error
    20  	StartInstance(id string) error
    21  	StopInstance(id string) error
    22  	GetInstanceLogs(id string) (string, error)
    23  	//Volumes
    24  	CreateVolume(params types.CreateVolumeParams) (*types.Volume, error)
    25  	ListVolumes() ([]*types.Volume, error)
    26  	GetVolume(nameOrIdPrefix string) (*types.Volume, error)
    27  	DeleteVolume(id string, force bool) error
    28  	AttachVolume(id, instanceId, mntPoint string) error
    29  	DetachVolume(id string) error
    30  	//Hub
    31  	PullImage(params types.PullImagePararms) error
    32  	PushImage(params types.PushImagePararms) error
    33  	RemoteDeleteImage(params types.RemoteDeleteImagePararms) error
    34  }
    35  
    36  type ProviderConfig struct {
    37  	UsePartitionTables bool
    38  }
    39  
    40  type Providers map[string]Provider
    41  
    42  func (providers Providers) Keys() []string {
    43  	keys := []string{}
    44  	for providerType := range providers {
    45  		keys = append(keys, providerType)
    46  	}
    47  	return keys
    48  }
    49  
    50  func (providers Providers) ProviderForImage(imageId string) (Provider, error) {
    51  	for _, provider := range providers {
    52  		_, err := provider.GetImage(imageId)
    53  		if err == nil {
    54  			return provider, nil
    55  		}
    56  	}
    57  	return nil, errors.New("image "+imageId+" not found", nil)
    58  }
    59  
    60  func (providers Providers) ProviderForInstance(instanceId string) (Provider, error) {
    61  	for _, provider := range providers {
    62  		_, err := provider.GetInstance(instanceId)
    63  		if err == nil {
    64  			return provider, nil
    65  		}
    66  	}
    67  	return nil, errors.New("instance "+instanceId+" not found", nil)
    68  }
    69  
    70  func (providers Providers) ProviderForVolume(volumeId string) (Provider, error) {
    71  	for _, provider := range providers {
    72  		_, err := provider.GetVolume(volumeId)
    73  		if err == nil {
    74  			return provider, nil
    75  		}
    76  	}
    77  	return nil, errors.New("volume "+volumeId+" not found", nil)
    78  }