~james-page/ubuntu/wily/juju-core/mir-fixes

« back to all changes in this revision

Viewing changes to src/launchpad.net/juju-core/state/api/provisioner/provisioner.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-03-28 08:58:42 UTC
  • mfrom: (1.1.21)
  • Revision ID: package-import@ubuntu.com-20140328085842-cyzrgc120bdfxwj0
Tags: 1.17.7-0ubuntu1
* New upstream point release, including fixes for:
  - no debug log with all providers on Ubuntu 14.04 (LP: #1294776).
* d/control: Add cpu-checker dependency to juju-local (LP: #1297077).

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
import (
7
7
        "fmt"
8
8
 
 
9
        "launchpad.net/juju-core/names"
9
10
        "launchpad.net/juju-core/state/api/base"
10
11
        "launchpad.net/juju-core/state/api/common"
11
12
        "launchpad.net/juju-core/state/api/params"
13
14
        "launchpad.net/juju-core/tools"
14
15
)
15
16
 
16
 
const provisioner = "Provisioner"
17
 
 
18
17
// State provides access to the Machiner API facade.
19
18
type State struct {
20
19
        *common.EnvironWatcher
 
20
        *common.APIAddresser
21
21
 
22
22
        caller base.Caller
23
23
}
24
24
 
 
25
const provisionerFacade = "Provisioner"
 
26
 
25
27
// NewState creates a new client-side Machiner facade.
26
28
func NewState(caller base.Caller) *State {
27
29
        return &State{
28
 
                EnvironWatcher: common.NewEnvironWatcher(provisioner, caller),
 
30
                EnvironWatcher: common.NewEnvironWatcher(provisionerFacade, caller),
 
31
                APIAddresser:   common.NewAPIAddresser(provisionerFacade, caller),
 
32
                caller:         caller}
 
33
}
29
34
 
30
 
                caller: caller}
 
35
func (st *State) call(method string, params, result interface{}) error {
 
36
        return st.caller.Call(provisionerFacade, "", method, params, result)
31
37
}
32
38
 
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)
36
42
}
37
43
 
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)
57
63
        if err != nil {
58
64
                return nil, err
59
65
        }
64
70
        return w, nil
65
71
}
66
72
 
 
73
func (st *State) WatchMachineErrorRetry() (watcher.NotifyWatcher, error) {
 
74
        var result params.NotifyWatchResult
 
75
        err := st.call("WatchMachineErrorRetry", nil, &result)
 
76
        if err != nil {
 
77
                return nil, err
 
78
        }
 
79
        if err := result.Error; err != nil {
 
80
                return nil, result.Error
 
81
        }
 
82
        w := watcher.NewNotifyWatcher(st.caller, result)
 
83
        return w, nil
 
84
}
 
85
 
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)
71
 
        if err != nil {
72
 
                return nil, err
73
 
        }
74
 
        return result.Result, nil
75
 
}
76
 
 
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)
81
 
        if err != nil {
82
 
                return nil, err
83
 
        }
84
 
        return result.Result, nil
85
 
}
86
 
 
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)
91
90
        if err != nil {
92
91
                return nil, err
93
92
        }
100
99
        args := params.Entities{
101
100
                Entities: []params.Entity{{Tag: tag}},
102
101
        }
103
 
        err := st.caller.Call(provisioner, "", "Tools", args, &results)
 
102
        err := st.call("Tools", args, &results)
104
103
        if err != nil {
105
104
                // TODO: Not directly tested
106
105
                return nil, err
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
124
123
}
 
124
 
 
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)
 
130
        if err != nil {
 
131
                return nil, nil, err
 
132
        }
 
133
        machines := make([]*Machine, len(results.Results))
 
134
        for i, status := range results.Results {
 
135
                if status.Error != nil {
 
136
                        continue
 
137
                }
 
138
                machines[i] = &Machine{
 
139
                        tag:  names.MachineTag(status.Id),
 
140
                        life: status.Life,
 
141
                        st:   st,
 
142
                }
 
143
        }
 
144
        return machines, results.Results, nil
 
145
}