13
14
"launchpad.net/juju-core/tools"
16
const provisioner = "Provisioner"
18
17
// State provides access to the Machiner API facade.
19
18
type State struct {
20
19
*common.EnvironWatcher
25
const provisionerFacade = "Provisioner"
25
27
// NewState creates a new client-side Machiner facade.
26
28
func NewState(caller base.Caller) *State {
28
EnvironWatcher: common.NewEnvironWatcher(provisioner, caller),
30
EnvironWatcher: common.NewEnvironWatcher(provisionerFacade, caller),
31
APIAddresser: common.NewAPIAddresser(provisionerFacade, caller),
35
func (st *State) call(method string, params, result interface{}) error {
36
return st.caller.Call(provisionerFacade, "", method, params, result)
33
39
// machineLife requests the lifecycle of the given machine from the server.
34
40
func (st *State) machineLife(tag string) (params.Life, error) {
35
return common.Life(st.caller, provisioner, tag)
41
return common.Life(st.caller, provisionerFacade, tag)
38
44
// Machine provides access to methods of a state.Machine through the facade.
53
59
// the current environment.
54
60
func (st *State) WatchEnvironMachines() (watcher.StringsWatcher, error) {
55
61
var result params.StringsWatchResult
56
err := st.caller.Call(provisioner, "", "WatchEnvironMachines", nil, &result)
62
err := st.call("WatchEnvironMachines", nil, &result)
73
func (st *State) WatchMachineErrorRetry() (watcher.NotifyWatcher, error) {
74
var result params.NotifyWatchResult
75
err := st.call("WatchMachineErrorRetry", nil, &result)
79
if err := result.Error; err != nil {
80
return nil, result.Error
82
w := watcher.NewNotifyWatcher(st.caller, result)
67
86
// StateAddresses returns the list of addresses used to connect to the state.
68
87
func (st *State) StateAddresses() ([]string, error) {
69
88
var result params.StringsResult
70
err := st.caller.Call(provisioner, "", "StateAddresses", nil, &result)
74
return result.Result, nil
77
// APIAddresses returns the list of addresses used to connect to the API.
78
func (st *State) APIAddresses() ([]string, error) {
79
var result params.StringsResult
80
err := st.caller.Call(provisioner, "", "APIAddresses", nil, &result)
84
return result.Result, nil
87
// CACert returns the certificate used to validate the state connection.
88
func (st *State) CACert() ([]byte, error) {
89
var result params.BytesResult
90
err := st.caller.Call(provisioner, "", "CACert", nil, &result)
89
err := st.call("StateAddresses", nil, &result)
100
99
args := params.Entities{
101
100
Entities: []params.Entity{{Tag: tag}},
103
err := st.caller.Call(provisioner, "", "Tools", args, &results)
102
err := st.call("Tools", args, &results)
105
104
// TODO: Not directly tested
119
118
// ContainerConfig returns information from the environment config that are
120
119
// needed for container cloud-init.
121
120
func (st *State) ContainerConfig() (result params.ContainerConfig, err error) {
122
err = st.caller.Call(provisioner, "", "ContainerConfig", nil, &result)
121
err = st.call("ContainerConfig", nil, &result)
123
122
return result, err
125
// MachinesWithTransientErrors returns a slice of machines and corresponding status information
126
// for those machines which have transient provisioning errors.
127
func (st *State) MachinesWithTransientErrors() ([]*Machine, []params.StatusResult, error) {
128
var results params.StatusResults
129
err := st.call("MachinesWithTransientErrors", nil, &results)
133
machines := make([]*Machine, len(results.Results))
134
for i, status := range results.Results {
135
if status.Error != nil {
138
machines[i] = &Machine{
139
tag: names.MachineTag(status.Id),
144
return machines, results.Results, nil