/
deployer.go
75 lines (63 loc) · 1.89 KB
/
deployer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Copyright 2012, 2013 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package deployer
import (
"github.com/juju/names"
"github.com/juju/juju/api/base"
"github.com/juju/juju/api/common"
"github.com/juju/juju/apiserver/params"
)
const deployerFacade = "Deployer"
// State provides access to the deployer worker's idea of the state.
type State struct {
facade base.FacadeCaller
*common.APIAddresser
}
// NewState creates a new State instance that makes API calls
// through the given caller.
func NewState(caller base.APICaller) *State {
facadeCaller := base.NewFacadeCaller(caller, deployerFacade)
return &State{
facade: facadeCaller,
APIAddresser: common.NewAPIAddresser(facadeCaller),
}
}
// unitLife returns the lifecycle state of the given unit.
func (st *State) unitLife(tag names.UnitTag) (params.Life, error) {
return common.Life(st.facade, tag)
}
// Unit returns the unit with the given tag.
func (st *State) Unit(tag names.UnitTag) (*Unit, error) {
life, err := st.unitLife(tag)
if err != nil {
return nil, err
}
return &Unit{
tag: tag,
life: life,
st: st,
}, nil
}
// Machine returns the machine with the given tag.
func (st *State) Machine(tag names.MachineTag) (*Machine, error) {
// TODO(dfc) this cannot return an error any more
return &Machine{
tag: tag,
st: st,
}, nil
}
// StateAddresses returns the list of addresses used to connect to the state.
func (st *State) StateAddresses() ([]string, error) {
var result params.StringsResult
err := st.facade.FacadeCall("StateAddresses", nil, &result)
if err != nil {
return nil, err
}
return result.Result, nil
}
// ConnectionInfo returns all the address information that the deployer task
// needs in one call.
func (st *State) ConnectionInfo() (result params.DeployerConnectionValues, err error) {
err = st.facade.FacadeCall("ConnectionInfo", nil, &result)
return result, err
}