github.com/wallyworld/juju@v0.0.0-20161013125918-6cf1bc9d917a/core/description/interfaces.go (about)

     1  // Copyright 2016 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package description
     5  
     6  import (
     7  	"time"
     8  
     9  	"github.com/juju/version"
    10  	"gopkg.in/juju/names.v2"
    11  )
    12  
    13  // HasAnnotations defines the common methods for setting and
    14  // getting annotations for the various entities.
    15  type HasAnnotations interface {
    16  	Annotations() map[string]string
    17  	SetAnnotations(map[string]string)
    18  }
    19  
    20  // HasConstraints defines the common methods for setting and
    21  // getting constraints for the various entities.
    22  type HasConstraints interface {
    23  	Constraints() Constraints
    24  	SetConstraints(ConstraintsArgs)
    25  }
    26  
    27  // HasStatus defines the common methods for setting and getting status
    28  // entries for the various entities.
    29  type HasStatus interface {
    30  	Status() Status
    31  	SetStatus(StatusArgs)
    32  }
    33  
    34  // HasStatusHistory defines the common methods for setting and
    35  // getting historical status entries for the various entities.
    36  type HasStatusHistory interface {
    37  	StatusHistory() []Status
    38  	SetStatusHistory([]StatusArgs)
    39  }
    40  
    41  // Model is a database agnostic representation of an existing model.
    42  type Model interface {
    43  	HasAnnotations
    44  	HasConstraints
    45  
    46  	Cloud() string
    47  	CloudRegion() string
    48  	CloudCredential() string
    49  	Tag() names.ModelTag
    50  	Owner() names.UserTag
    51  	Config() map[string]interface{}
    52  	LatestToolsVersion() version.Number
    53  
    54  	// UpdateConfig overwrites existing config values with those specified.
    55  	UpdateConfig(map[string]interface{})
    56  
    57  	// Blocks returns a map of block type to the message associated with that
    58  	// block.
    59  	Blocks() map[string]string
    60  
    61  	Users() []User
    62  	AddUser(UserArgs)
    63  
    64  	Machines() []Machine
    65  	AddMachine(MachineArgs) Machine
    66  
    67  	Applications() []Application
    68  	AddApplication(ApplicationArgs) Application
    69  
    70  	Relations() []Relation
    71  	AddRelation(RelationArgs) Relation
    72  
    73  	Spaces() []Space
    74  	AddSpace(SpaceArgs) Space
    75  
    76  	LinkLayerDevices() []LinkLayerDevice
    77  	AddLinkLayerDevice(LinkLayerDeviceArgs) LinkLayerDevice
    78  
    79  	Subnets() []Subnet
    80  	AddSubnet(SubnetArgs) Subnet
    81  
    82  	IPAddresses() []IPAddress
    83  	AddIPAddress(IPAddressArgs) IPAddress
    84  
    85  	SSHHostKeys() []SSHHostKey
    86  	AddSSHHostKey(SSHHostKeyArgs) SSHHostKey
    87  
    88  	CloudImageMetadata() []CloudImageMetadata
    89  	AddCloudImageMetadata(CloudImageMetadataArgs) CloudImageMetadata
    90  
    91  	Actions() []Action
    92  	AddAction(ActionArgs) Action
    93  
    94  	Sequences() map[string]int
    95  	SetSequence(name string, value int)
    96  
    97  	Volumes() []Volume
    98  	AddVolume(VolumeArgs) Volume
    99  
   100  	Filesystems() []Filesystem
   101  	AddFilesystem(FilesystemArgs) Filesystem
   102  
   103  	Storages() []Storage
   104  	AddStorage(StorageArgs) Storage
   105  
   106  	StoragePools() []StoragePool
   107  	AddStoragePool(StoragePoolArgs) StoragePool
   108  
   109  	Validate() error
   110  }
   111  
   112  // User represents a user of the model. Users are able to connect to, and
   113  // depending on the read only flag, modify the model.
   114  type User interface {
   115  	Name() names.UserTag
   116  	DisplayName() string
   117  	CreatedBy() names.UserTag
   118  	DateCreated() time.Time
   119  	LastConnection() time.Time
   120  	Access() string
   121  }
   122  
   123  // Address represents an IP Address of some form.
   124  type Address interface {
   125  	Value() string
   126  	Type() string
   127  	Scope() string
   128  	Origin() string
   129  }
   130  
   131  // AgentTools represent the version and related binary file
   132  // that the machine and unit agents are using.
   133  type AgentTools interface {
   134  	Version() version.Binary
   135  	URL() string
   136  	SHA256() string
   137  	Size() int64
   138  }
   139  
   140  // Machine represents an existing live machine or container running in the
   141  // model.
   142  type Machine interface {
   143  	HasAnnotations
   144  	HasConstraints
   145  	HasStatus
   146  	HasStatusHistory
   147  
   148  	Id() string
   149  	Tag() names.MachineTag
   150  	Nonce() string
   151  	PasswordHash() string
   152  	Placement() string
   153  	Series() string
   154  	ContainerType() string
   155  	Jobs() []string
   156  	SupportedContainers() ([]string, bool)
   157  
   158  	Instance() CloudInstance
   159  	SetInstance(CloudInstanceArgs)
   160  
   161  	// Life() string -- only transmit alive things?
   162  	ProviderAddresses() []Address
   163  	MachineAddresses() []Address
   164  	SetAddresses(machine []AddressArgs, provider []AddressArgs)
   165  
   166  	PreferredPublicAddress() Address
   167  	PreferredPrivateAddress() Address
   168  	SetPreferredAddresses(public AddressArgs, private AddressArgs)
   169  
   170  	Tools() AgentTools
   171  	SetTools(AgentToolsArgs)
   172  
   173  	Containers() []Machine
   174  	AddContainer(MachineArgs) Machine
   175  
   176  	BlockDevices() []BlockDevice
   177  	AddBlockDevice(BlockDeviceArgs) BlockDevice
   178  
   179  	OpenedPorts() []OpenedPorts
   180  	AddOpenedPorts(OpenedPortsArgs) OpenedPorts
   181  
   182  	// THINKING: Validate() error to make sure the machine has
   183  	// enough stuff set, like tools, and addresses etc.
   184  	Validate() error
   185  
   186  	// port docs
   187  }
   188  
   189  // OpenedPorts represents a collection of port ranges that are open on a
   190  // particular subnet. OpenedPorts are always associated with a Machine.
   191  type OpenedPorts interface {
   192  	SubnetID() string
   193  	OpenPorts() []PortRange
   194  }
   195  
   196  // PortRange represents one or more contiguous ports opened by a particular
   197  // Unit.
   198  type PortRange interface {
   199  	UnitName() string
   200  	FromPort() int
   201  	ToPort() int
   202  	Protocol() string
   203  }
   204  
   205  // CloudInstance holds information particular to a machine
   206  // instance in a cloud.
   207  type CloudInstance interface {
   208  	InstanceId() string
   209  	Status() string
   210  	Architecture() string
   211  	Memory() uint64
   212  	RootDisk() uint64
   213  	CpuCores() uint64
   214  	CpuPower() uint64
   215  	Tags() []string
   216  	AvailabilityZone() string
   217  }
   218  
   219  // Constraints holds information about particular deployment
   220  // constraints for entities.
   221  type Constraints interface {
   222  	Architecture() string
   223  	Container() string
   224  	CpuCores() uint64
   225  	CpuPower() uint64
   226  	InstanceType() string
   227  	Memory() uint64
   228  	RootDisk() uint64
   229  
   230  	Spaces() []string
   231  	Tags() []string
   232  
   233  	VirtType() string
   234  }
   235  
   236  // Status represents an agent, application, or workload status.
   237  type Status interface {
   238  	Value() string
   239  	Message() string
   240  	Data() map[string]interface{}
   241  	Updated() time.Time
   242  }
   243  
   244  // Application represents a deployed charm in a model.
   245  type Application interface {
   246  	HasAnnotations
   247  	HasConstraints
   248  	HasStatus
   249  	HasStatusHistory
   250  
   251  	Tag() names.ApplicationTag
   252  	Name() string
   253  	Series() string
   254  	Subordinate() bool
   255  	CharmURL() string
   256  	Channel() string
   257  	CharmModifiedVersion() int
   258  	ForceCharm() bool
   259  	Exposed() bool
   260  	MinUnits() int
   261  
   262  	Settings() map[string]interface{}
   263  
   264  	Leader() string
   265  	LeadershipSettings() map[string]interface{}
   266  
   267  	MetricsCredentials() []byte
   268  	StorageConstraints() map[string]StorageConstraint
   269  
   270  	Units() []Unit
   271  	AddUnit(UnitArgs) Unit
   272  
   273  	Validate() error
   274  }
   275  
   276  // Unit represents an instance of an application in a model.
   277  type Unit interface {
   278  	HasAnnotations
   279  	HasConstraints
   280  
   281  	Tag() names.UnitTag
   282  	Name() string
   283  	Machine() names.MachineTag
   284  
   285  	PasswordHash() string
   286  
   287  	Principal() names.UnitTag
   288  	Subordinates() []names.UnitTag
   289  
   290  	MeterStatusCode() string
   291  	MeterStatusInfo() string
   292  
   293  	Tools() AgentTools
   294  	SetTools(AgentToolsArgs)
   295  
   296  	WorkloadStatus() Status
   297  	SetWorkloadStatus(StatusArgs)
   298  
   299  	WorkloadStatusHistory() []Status
   300  	SetWorkloadStatusHistory([]StatusArgs)
   301  
   302  	WorkloadVersion() string
   303  
   304  	WorkloadVersionHistory() []Status
   305  	SetWorkloadVersionHistory([]StatusArgs)
   306  
   307  	AgentStatus() Status
   308  	SetAgentStatus(StatusArgs)
   309  
   310  	AgentStatusHistory() []Status
   311  	SetAgentStatusHistory([]StatusArgs)
   312  
   313  	AddPayload(PayloadArgs) Payload
   314  	Payloads() []Payload
   315  
   316  	Validate() error
   317  }
   318  
   319  // Relation represents a relationship between two applications,
   320  // or a peer relation between different instances of an application.
   321  type Relation interface {
   322  	Id() int
   323  	Key() string
   324  
   325  	Endpoints() []Endpoint
   326  	AddEndpoint(EndpointArgs) Endpoint
   327  }
   328  
   329  // Endpoint represents one end of a relation. A named endpoint provided
   330  // by the charm that is deployed for the application.
   331  type Endpoint interface {
   332  	ApplicationName() string
   333  	Name() string
   334  	// Role, Interface, Optional, Limit, and Scope should all be available
   335  	// through the Charm associated with the Application. There is no real need
   336  	// for this information to be denormalised like this. However, for now,
   337  	// since the import may well take place before the charms have been loaded
   338  	// into the model, we'll send this information over.
   339  	Role() string
   340  	Interface() string
   341  	Optional() bool
   342  	Limit() int
   343  	Scope() string
   344  
   345  	// UnitCount returns the number of units the endpoint has settings for.
   346  	UnitCount() int
   347  
   348  	Settings(unitName string) map[string]interface{}
   349  	SetUnitSettings(unitName string, settings map[string]interface{})
   350  }
   351  
   352  // Space represents a network space, which is a named collection of subnets.
   353  type Space interface {
   354  	Name() string
   355  	Public() bool
   356  	ProviderID() string
   357  }
   358  
   359  // LinkLayerDevice represents a link layer device.
   360  type LinkLayerDevice interface {
   361  	Name() string
   362  	MTU() uint
   363  	ProviderID() string
   364  	MachineID() string
   365  	Type() string
   366  	MACAddress() string
   367  	IsAutoStart() bool
   368  	IsUp() bool
   369  	ParentName() string
   370  }
   371  
   372  // Subnet represents a network subnet.
   373  type Subnet interface {
   374  	ProviderId() string
   375  	CIDR() string
   376  	VLANTag() int
   377  	AvailabilityZone() string
   378  	SpaceName() string
   379  	AllocatableIPHigh() string
   380  	AllocatableIPLow() string
   381  }
   382  
   383  // IPAddress represents an IP address.
   384  type IPAddress interface {
   385  	ProviderID() string
   386  	DeviceName() string
   387  	MachineID() string
   388  	SubnetCIDR() string
   389  	ConfigMethod() string
   390  	Value() string
   391  	DNSServers() []string
   392  	DNSSearchDomains() []string
   393  	GatewayAddress() string
   394  }
   395  
   396  // SSHHostKey represents an ssh host key.
   397  type SSHHostKey interface {
   398  	MachineID() string
   399  	Keys() []string
   400  }
   401  
   402  // CloudImageMetadata represents an IP cloudimagemetadata.
   403  type CloudImageMetadata interface {
   404  	Stream() string
   405  	Region() string
   406  	Version() string
   407  	Series() string
   408  	Arch() string
   409  	VirtType() string
   410  	RootStorageType() string
   411  	RootStorageSize() (uint64, bool)
   412  	DateCreated() int64
   413  	Source() string
   414  	Priority() int
   415  	ImageId() string
   416  }
   417  
   418  // Action represents an IP action.
   419  type Action interface {
   420  	Id() string
   421  	Receiver() string
   422  	Name() string
   423  	Parameters() map[string]interface{}
   424  	Enqueued() time.Time
   425  	Started() time.Time
   426  	Completed() time.Time
   427  	Results() map[string]interface{}
   428  	Status() string
   429  	Message() string
   430  }
   431  
   432  // Volume represents a volume (disk, logical volume, etc.) in the model.
   433  type Volume interface {
   434  	HasStatus
   435  	HasStatusHistory
   436  
   437  	Tag() names.VolumeTag
   438  	Storage() names.StorageTag
   439  
   440  	Binding() (names.Tag, error)
   441  
   442  	Provisioned() bool
   443  
   444  	Size() uint64
   445  	Pool() string
   446  
   447  	HardwareID() string
   448  	VolumeID() string
   449  	Persistent() bool
   450  
   451  	Attachments() []VolumeAttachment
   452  	AddAttachment(VolumeAttachmentArgs) VolumeAttachment
   453  }
   454  
   455  // VolumeAttachment represents a volume attached to a machine.
   456  type VolumeAttachment interface {
   457  	Machine() names.MachineTag
   458  	Provisioned() bool
   459  	ReadOnly() bool
   460  	DeviceName() string
   461  	DeviceLink() string
   462  	BusAddress() string
   463  }
   464  
   465  // Filesystem represents a filesystem in the model.
   466  type Filesystem interface {
   467  	HasStatus
   468  	HasStatusHistory
   469  
   470  	Tag() names.FilesystemTag
   471  	Volume() names.VolumeTag
   472  	Storage() names.StorageTag
   473  	Binding() (names.Tag, error)
   474  
   475  	Provisioned() bool
   476  
   477  	Size() uint64
   478  	Pool() string
   479  
   480  	FilesystemID() string
   481  
   482  	Attachments() []FilesystemAttachment
   483  	AddAttachment(FilesystemAttachmentArgs) FilesystemAttachment
   484  }
   485  
   486  // FilesystemAttachment represents a filesystem attached to a machine.
   487  type FilesystemAttachment interface {
   488  	Machine() names.MachineTag
   489  	Provisioned() bool
   490  	MountPoint() string
   491  	ReadOnly() bool
   492  }
   493  
   494  // Storage represents the state of a unit or application-wide storage instance
   495  // in the model.
   496  type Storage interface {
   497  	Tag() names.StorageTag
   498  	Kind() string
   499  	// Owner returns the tag of the application or unit that owns this storage
   500  	// instance.
   501  	Owner() (names.Tag, error)
   502  	Name() string
   503  
   504  	Attachments() []names.UnitTag
   505  
   506  	Validate() error
   507  }
   508  
   509  // StoragePool represents a named storage pool and its settings.
   510  type StoragePool interface {
   511  	Name() string
   512  	Provider() string
   513  	Attributes() map[string]interface{}
   514  }
   515  
   516  // StorageConstraint repressents the user-specified constraints for
   517  // provisioning storage instances for an application unit.
   518  type StorageConstraint interface {
   519  	// Pool is the name of the storage pool from which to provision the
   520  	// storage instances.
   521  	Pool() string
   522  	// Size is the required size of the storage instances, in MiB.
   523  	Size() uint64
   524  	// Count is the required number of storage instances.
   525  	Count() uint64
   526  }