-
Notifications
You must be signed in to change notification settings - Fork 492
/
machiner.go
48 lines (40 loc) · 1.21 KB
/
machiner.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
// Copyright 2012, 2013 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package machiner
import (
"github.com/juju/errors"
"github.com/juju/names/v5"
"github.com/juju/juju/api/base"
"github.com/juju/juju/api/common"
"github.com/juju/juju/core/life"
)
const machinerFacade = "Machiner"
// State provides access to the Machiner API facade.
type State struct {
facade base.FacadeCaller
*common.APIAddresser
}
// NewState creates a new client-side Machiner facade.
func NewState(caller base.APICaller) *State {
facadeCaller := base.NewFacadeCaller(caller, machinerFacade)
return &State{
facade: facadeCaller,
APIAddresser: common.NewAPIAddresser(facadeCaller),
}
}
// machineLife requests the lifecycle of the given machine from the server.
func (st *State) machineLife(tag names.MachineTag) (life.Value, error) {
return common.OneLife(st.facade, tag)
}
// Machine provides access to methods of a state.Machine through the facade.
func (st *State) Machine(tag names.MachineTag) (*Machine, error) {
life, err := st.machineLife(tag)
if err != nil {
return nil, errors.Annotate(err, "can't get life for machine")
}
return &Machine{
tag: tag,
life: life,
st: st,
}, nil
}