github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/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/names" 10 "github.com/juju/version" 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 // HasStatusHistory defines the common methods for setting and 28 // getting historical status entries for the various entities. 29 type HasStatusHistory interface { 30 StatusHistory() []Status 31 SetStatusHistory([]StatusArgs) 32 } 33 34 // Model is a database agnostic representation of an existing model. 35 type Model interface { 36 HasAnnotations 37 HasConstraints 38 39 Tag() names.ModelTag 40 Owner() names.UserTag 41 Config() map[string]interface{} 42 LatestToolsVersion() version.Number 43 44 // UpdateConfig overwrites existing config values with those specified. 45 UpdateConfig(map[string]interface{}) 46 47 // Blocks returns a map of block type to the message associated with that 48 // block. 49 Blocks() map[string]string 50 51 Users() []User 52 AddUser(UserArgs) 53 54 Machines() []Machine 55 AddMachine(MachineArgs) Machine 56 57 Services() []Service 58 AddService(ServiceArgs) Service 59 60 Relations() []Relation 61 AddRelation(RelationArgs) Relation 62 63 Sequences() map[string]int 64 SetSequence(name string, value int) 65 66 Validate() error 67 } 68 69 // User represents a user of the model. Users are able to connect to, and 70 // depending on the read only flag, modify the model. 71 type User interface { 72 Name() names.UserTag 73 DisplayName() string 74 CreatedBy() names.UserTag 75 DateCreated() time.Time 76 LastConnection() time.Time 77 ReadOnly() bool 78 } 79 80 // Address represents an IP Address of some form. 81 type Address interface { 82 Value() string 83 Type() string 84 Scope() string 85 Origin() string 86 } 87 88 // AgentTools represent the version and related binary file 89 // that the machine and unit agents are using. 90 type AgentTools interface { 91 Version() version.Binary 92 URL() string 93 SHA256() string 94 Size() int64 95 } 96 97 // Machine represents an existing live machine or container running in the 98 // model. 99 type Machine interface { 100 HasAnnotations 101 HasConstraints 102 HasStatusHistory 103 104 Id() string 105 Tag() names.MachineTag 106 Nonce() string 107 PasswordHash() string 108 Placement() string 109 Series() string 110 ContainerType() string 111 Jobs() []string 112 SupportedContainers() ([]string, bool) 113 114 Instance() CloudInstance 115 SetInstance(CloudInstanceArgs) 116 117 // Life() string -- only transmit alive things? 118 ProviderAddresses() []Address 119 MachineAddresses() []Address 120 SetAddresses(machine []AddressArgs, provider []AddressArgs) 121 122 PreferredPublicAddress() Address 123 PreferredPrivateAddress() Address 124 SetPreferredAddresses(public AddressArgs, private AddressArgs) 125 126 Tools() AgentTools 127 SetTools(AgentToolsArgs) 128 129 Containers() []Machine 130 AddContainer(MachineArgs) Machine 131 132 Status() Status 133 SetStatus(StatusArgs) 134 135 // TODO: 136 // Storage 137 138 OpenedPorts() []OpenedPorts 139 AddOpenedPorts(OpenedPortsArgs) OpenedPorts 140 141 // THINKING: Validate() error to make sure the machine has 142 // enough stuff set, like tools, and addresses etc. 143 Validate() error 144 145 // reboot doc 146 // block devices 147 // port docs 148 // machine filesystems 149 } 150 151 // OpenedPorts represents a collection of port ranges that are open on a 152 // particular subnet. OpenedPorts are always associated with a Machine. 153 type OpenedPorts interface { 154 SubnetID() string 155 OpenPorts() []PortRange 156 } 157 158 // PortRange represents one or more contiguous ports opened by a particular 159 // Unit. 160 type PortRange interface { 161 UnitName() string 162 FromPort() int 163 ToPort() int 164 Protocol() string 165 } 166 167 // CloudInstance holds information particular to a machine 168 // instance in a cloud. 169 type CloudInstance interface { 170 InstanceId() string 171 Status() string 172 Architecture() string 173 Memory() uint64 174 RootDisk() uint64 175 CpuCores() uint64 176 CpuPower() uint64 177 Tags() []string 178 AvailabilityZone() string 179 } 180 181 // Constraints holds information about particular deployment 182 // constraints for entities. 183 type Constraints interface { 184 Architecture() string 185 Container() string 186 CpuCores() uint64 187 CpuPower() uint64 188 InstanceType() string 189 Memory() uint64 190 RootDisk() uint64 191 192 Spaces() []string 193 Tags() []string 194 } 195 196 // Status represents an agent, service, or workload status. 197 type Status interface { 198 Value() string 199 Message() string 200 Data() map[string]interface{} 201 Updated() time.Time 202 } 203 204 // Service represents a deployed charm in a model. 205 type Service interface { 206 HasAnnotations 207 HasConstraints 208 HasStatusHistory 209 210 Tag() names.ServiceTag 211 Name() string 212 Series() string 213 Subordinate() bool 214 CharmURL() string 215 Channel() string 216 CharmModifiedVersion() int 217 ForceCharm() bool 218 Exposed() bool 219 MinUnits() int 220 221 Settings() map[string]interface{} 222 SettingsRefCount() int 223 224 Leader() string 225 LeadershipSettings() map[string]interface{} 226 227 MetricsCredentials() []byte 228 229 Status() Status 230 SetStatus(StatusArgs) 231 232 Units() []Unit 233 AddUnit(UnitArgs) Unit 234 235 Validate() error 236 } 237 238 // Unit represents an instance of a service in a model. 239 type Unit interface { 240 HasAnnotations 241 HasConstraints 242 243 Tag() names.UnitTag 244 Name() string 245 Machine() names.MachineTag 246 247 PasswordHash() string 248 249 Principal() names.UnitTag 250 Subordinates() []names.UnitTag 251 252 MeterStatusCode() string 253 MeterStatusInfo() string 254 255 // TODO: storage 256 257 Tools() AgentTools 258 SetTools(AgentToolsArgs) 259 260 WorkloadStatus() Status 261 SetWorkloadStatus(StatusArgs) 262 263 WorkloadStatusHistory() []Status 264 SetWorkloadStatusHistory([]StatusArgs) 265 266 AgentStatus() Status 267 SetAgentStatus(StatusArgs) 268 269 AgentStatusHistory() []Status 270 SetAgentStatusHistory([]StatusArgs) 271 272 Validate() error 273 } 274 275 // Relation represents a relationship between two services, 276 // or a peer relation between different instances of a service. 277 type Relation interface { 278 Id() int 279 Key() string 280 281 Endpoints() []Endpoint 282 AddEndpoint(EndpointArgs) Endpoint 283 } 284 285 // Endpoint represents one end of a relation. A named endpoint provided 286 // by the charm that is deployed for the service. 287 type Endpoint interface { 288 ServiceName() string 289 Name() string 290 // Role, Interface, Optional, Limit, and Scope should all be available 291 // through the Charm associated with the Service. There is no real need 292 // for this information to be denormalised like this. However, for now, 293 // since the import may well take place before the charms have been loaded 294 // into the model, we'll send this information over. 295 Role() string 296 Interface() string 297 Optional() bool 298 Limit() int 299 Scope() string 300 301 // UnitCount returns the number of units the endpoint has settings for. 302 UnitCount() int 303 304 Settings(unitName string) map[string]interface{} 305 SetUnitSettings(unitName string, settings map[string]interface{}) 306 }