/
state.go
94 lines (76 loc) · 2.2 KB
/
state.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Copyright 2015 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package instancepoller
import (
"github.com/juju/juju/apiserver/common/networkingcommon"
"github.com/juju/juju/core/instance"
"github.com/juju/juju/core/network"
"github.com/juju/juju/core/status"
"github.com/juju/juju/state"
)
// StateMachine represents a machine from state package.
type StateMachine interface {
state.Entity
networkingcommon.LinkLayerMachine
InstanceId() (instance.Id, error)
ProviderAddresses() network.SpaceAddresses
SetProviderAddresses(...network.SpaceAddress) error
InstanceStatus() (status.StatusInfo, error)
SetInstanceStatus(status.StatusInfo) error
SetStatus(status.StatusInfo) error
String() string
Refresh() error
Life() state.Life
Status() (status.StatusInfo, error)
IsManual() (bool, error)
}
type StateInterface interface {
state.ModelAccessor
state.ModelMachinesWatcher
state.EntityFinder
network.SpaceLookup
Machine(id string) (StateMachine, error)
// ApplyOperation applies a given ModelOperation to the model.
ApplyOperation(state.ModelOperation) error
}
type machineShim struct {
*state.Machine
}
func (s machineShim) AllLinkLayerDevices() ([]networkingcommon.LinkLayerDevice, error) {
devList, err := s.Machine.AllLinkLayerDevices()
if err != nil {
return nil, err
}
out := make([]networkingcommon.LinkLayerDevice, len(devList))
for i, dev := range devList {
out[i] = dev
}
return out, nil
}
func (s machineShim) AllDeviceAddresses() ([]networkingcommon.LinkLayerAddress, error) {
addrList, err := s.Machine.AllDeviceAddresses()
if err != nil {
return nil, err
}
out := make([]networkingcommon.LinkLayerAddress, len(addrList))
for i, addr := range addrList {
out[i] = addr
}
return out, nil
}
// TODO - CAAS(ericclaudejones): This should contain state alone, model will be
// removed once all relevant methods are moved from state to model.
type stateShim struct {
*state.State
*state.Model
}
func (s stateShim) Machine(id string) (StateMachine, error) {
m, err := s.State.Machine(id)
if err != nil {
return nil, err
}
return machineShim{m}, nil
}
var getState = func(st *state.State, m *state.Model) StateInterface {
return stateShim{st, m}
}