~nskaggs/+junk/xenial-test

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/apiserver/client/backend.go

  • Committer: Nicholas Skaggs
  • Date: 2016-10-24 20:56:05 UTC
  • Revision ID: nicholas.skaggs@canonical.com-20161024205605-z8lta0uvuhtxwzwl
Initi with beta15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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/core/description"
 
13
        "github.com/juju/juju/environs/config"
 
14
        "github.com/juju/juju/instance"
 
15
        "github.com/juju/juju/network"
 
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
        FindEntity(names.Tag) (state.Entity, error)
 
36
        Unit(string) (Unit, error)
 
37
        Application(string) (*state.Application, error)
 
38
        Machine(string) (*state.Machine, error)
 
39
        AllMachines() ([]*state.Machine, error)
 
40
        AllApplications() ([]*state.Application, error)
 
41
        AllRelations() ([]*state.Relation, error)
 
42
        AddOneMachine(state.MachineTemplate) (*state.Machine, error)
 
43
        AddMachineInsideMachine(state.MachineTemplate, string, instance.ContainerType) (*state.Machine, error)
 
44
        AddMachineInsideNewMachine(template, parentTemplate state.MachineTemplate, containerType instance.ContainerType) (*state.Machine, error)
 
45
        ModelConstraints() (constraints.Value, error)
 
46
        ModelConfig() (*config.Config, error)
 
47
        ModelConfigValues() (config.ConfigValues, error)
 
48
        UpdateModelConfig(map[string]interface{}, []string, state.ValidateConfigFunc) error
 
49
        SetModelConstraints(constraints.Value) error
 
50
        ModelUUID() string
 
51
        ModelTag() names.ModelTag
 
52
        Model() (*state.Model, error)
 
53
        ForModel(tag names.ModelTag) (*state.State, error)
 
54
        SetModelAgentVersion(version.Number) error
 
55
        SetAnnotations(state.GlobalEntity, map[string]string) error
 
56
        Annotations(state.GlobalEntity) (map[string]string, error)
 
57
        InferEndpoints(...string) ([]state.Endpoint, error)
 
58
        EndpointsRelation(...state.Endpoint) (*state.Relation, error)
 
59
        Charm(*charm.URL) (*state.Charm, error)
 
60
        LatestPlaceholderCharm(*charm.URL) (*state.Charm, error)
 
61
        AddRelation(...state.Endpoint) (*state.Relation, error)
 
62
        AddModelUser(state.UserAccessSpec) (description.UserAccess, error)
 
63
        AddControllerUser(state.UserAccessSpec) (description.UserAccess, error)
 
64
        RemoveUserAccess(names.UserTag, names.Tag) error
 
65
        Watch() *state.Multiwatcher
 
66
        AbortCurrentUpgrade() error
 
67
        APIHostPorts() ([][]network.HostPort, error)
 
68
        LatestModelMigration() (state.ModelMigration, error)
 
69
}
 
70
 
 
71
func NewStateBackend(st *state.State) Backend {
 
72
        return stateShim{st}
 
73
}
 
74
 
 
75
type stateShim struct {
 
76
        *state.State
 
77
}
 
78
 
 
79
func (s stateShim) Unit(name string) (Unit, error) {
 
80
        u, err := s.State.Unit(name)
 
81
        if err != nil {
 
82
                return nil, err
 
83
        }
 
84
        return u, nil
 
85
}