forked from juju/juju
-
Notifications
You must be signed in to change notification settings - Fork 0
/
instance.go
83 lines (68 loc) · 2.11 KB
/
instance.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
// Copyright 2015 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
// +build go1.3
package lxd
import (
"fmt"
"github.com/juju/errors"
"github.com/juju/juju/instance"
"github.com/juju/juju/network"
"github.com/juju/juju/status"
"github.com/juju/juju/tools/lxdclient"
)
type lxdInstance struct {
id string
client *lxdclient.Client
}
var _ instance.Instance = (*lxdInstance)(nil)
// Id implements instance.Instance.Id.
func (lxd *lxdInstance) Id() instance.Id {
return instance.Id(lxd.id)
}
func (*lxdInstance) Refresh() error {
return nil
}
func (lxd *lxdInstance) Addresses() ([]network.Address, error) {
return nil, errors.NotImplementedf("lxdInstance.Addresses")
}
// Status implements instance.Instance.Status.
func (lxd *lxdInstance) Status() instance.InstanceStatus {
jujuStatus := status.Pending
instStatus, err := lxd.client.Status(lxd.id)
if err != nil {
return instance.InstanceStatus{
Status: status.Empty,
Message: fmt.Sprintf("could not get status: %v", err),
}
}
switch instStatus {
case lxdclient.StatusStarting, lxdclient.StatusStarted:
jujuStatus = status.Allocating
case lxdclient.StatusRunning:
jujuStatus = status.Running
case lxdclient.StatusFreezing, lxdclient.StatusFrozen, lxdclient.StatusThawed, lxdclient.StatusStopping, lxdclient.StatusStopped:
jujuStatus = status.Empty
default:
jujuStatus = status.Empty
}
return instance.InstanceStatus{
Status: jujuStatus,
Message: instStatus,
}
}
// OpenPorts implements instance.Instance.OpenPorts.
func (lxd *lxdInstance) OpenPorts(machineId string, ports []network.PortRange) error {
return fmt.Errorf("not implemented")
}
// ClosePorts implements instance.Instance.ClosePorts.
func (lxd *lxdInstance) ClosePorts(machineId string, ports []network.PortRange) error {
return fmt.Errorf("not implemented")
}
// Ports implements instance.Instance.Ports.
func (lxd *lxdInstance) Ports(machineId string) ([]network.PortRange, error) {
return nil, fmt.Errorf("not implemented")
}
// Add a string representation of the id.
func (lxd *lxdInstance) String() string {
return fmt.Sprintf("lxd:%s", lxd.id)
}