github.com/axw/juju@v0.0.0-20161005053422-4bd6544d08d4/apiserver/client/backend.go (about) 1 // Copyright 2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package client 5 6 import ( 7 "github.com/juju/version" 8 "gopkg.in/juju/charm.v6-unstable" 9 "gopkg.in/juju/names.v2" 10 11 "github.com/juju/juju/constraints" 12 "github.com/juju/juju/environs/config" 13 "github.com/juju/juju/instance" 14 "github.com/juju/juju/network" 15 "github.com/juju/juju/permission" 16 "github.com/juju/juju/state" 17 "github.com/juju/juju/status" 18 ) 19 20 // Unit represents a state.Unit. 21 type Unit interface { 22 status.StatusHistoryGetter 23 Life() state.Life 24 Destroy() (err error) 25 IsPrincipal() bool 26 PublicAddress() (network.Address, error) 27 PrivateAddress() (network.Address, error) 28 Resolve(retryHooks bool) error 29 AgentHistory() status.StatusHistoryGetter 30 } 31 32 // Backend contains the state.State methods used in this package, 33 // allowing stubs to be created for testing. 34 type Backend interface { 35 AbortCurrentUpgrade() error 36 AddControllerUser(state.UserAccessSpec) (permission.UserAccess, error) 37 AddMachineInsideMachine(state.MachineTemplate, string, instance.ContainerType) (*state.Machine, error) 38 AddMachineInsideNewMachine(template, parentTemplate state.MachineTemplate, containerType instance.ContainerType) (*state.Machine, error) 39 AddModelUser(string, state.UserAccessSpec) (permission.UserAccess, error) 40 AddOneMachine(state.MachineTemplate) (*state.Machine, error) 41 AddRelation(...state.Endpoint) (*state.Relation, error) 42 AllApplications() ([]*state.Application, error) 43 AllMachines() ([]*state.Machine, error) 44 AllRelations() ([]*state.Relation, error) 45 Annotations(state.GlobalEntity) (map[string]string, error) 46 APIHostPorts() ([][]network.HostPort, error) 47 Application(string) (*state.Application, error) 48 ApplicationLeaders() (map[string]string, error) 49 Charm(*charm.URL) (*state.Charm, error) 50 EndpointsRelation(...state.Endpoint) (*state.Relation, error) 51 FindEntity(names.Tag) (state.Entity, error) 52 ForModel(tag names.ModelTag) (*state.State, error) 53 InferEndpoints(...string) ([]state.Endpoint, error) 54 LatestMigration() (state.ModelMigration, error) 55 LatestPlaceholderCharm(*charm.URL) (*state.Charm, error) 56 Machine(string) (*state.Machine, error) 57 Model() (*state.Model, error) 58 ModelConfig() (*config.Config, error) 59 ModelConfigValues() (config.ConfigValues, error) 60 ModelConstraints() (constraints.Value, error) 61 ModelTag() names.ModelTag 62 ModelUUID() string 63 RemoveUserAccess(names.UserTag, names.Tag) error 64 SetAnnotations(state.GlobalEntity, map[string]string) error 65 SetModelAgentVersion(version.Number) error 66 SetModelConstraints(constraints.Value) error 67 Unit(string) (Unit, error) 68 UpdateModelConfig(map[string]interface{}, []string, state.ValidateConfigFunc) error 69 Watch() *state.Multiwatcher 70 } 71 72 func NewStateBackend(st *state.State) Backend { 73 return stateShim{st} 74 } 75 76 type stateShim struct { 77 *state.State 78 } 79 80 func (s stateShim) Unit(name string) (Unit, error) { 81 u, err := s.State.Unit(name) 82 if err != nil { 83 return nil, err 84 } 85 return u, nil 86 }