1
// Copyright 2015 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
7
"github.com/altoros/gosigma"
8
"github.com/juju/errors"
10
"github.com/juju/juju/instance"
11
"github.com/juju/juju/network"
12
"github.com/juju/juju/status"
15
var _ instance.Instance = (*sigmaInstance)(nil)
17
type sigmaInstance struct {
21
var ErrNoDNSName = errors.New("IPv4 address not found")
23
// Id returns a provider-generated identifier for the Instance.
24
func (i sigmaInstance) Id() instance.Id {
25
id := instance.Id(i.server.UUID())
26
logger.Tracef("sigmaInstance.Id: %s", id)
30
// Status returns the provider-specific status for the instance.
31
func (i sigmaInstance) Status() instance.InstanceStatus {
32
entityStatus := i.server.Status()
33
logger.Tracef("sigmaInstance.Status: %s", entityStatus)
34
jujuStatus := status.StatusPending
36
case gosigma.ServerStarting:
37
jujuStatus = status.StatusAllocating
38
case gosigma.ServerRunning:
39
jujuStatus = status.StatusRunning
40
case gosigma.ServerStopping, gosigma.ServerStopped:
41
jujuStatus = status.StatusEmpty
42
case gosigma.ServerUnavailable:
43
// I am not sure about this one.
44
jujuStatus = status.StatusPending
46
jujuStatus = status.StatusPending
49
return instance.InstanceStatus{
51
Message: entityStatus,
56
// Addresses returns a list of hostnames or ip addresses
57
// associated with the instance. This will supercede DNSName
58
// which can be implemented by selecting a preferred address.
59
func (i sigmaInstance) Addresses() ([]network.Address, error) {
63
addr := network.Address{
65
Type: network.IPv4Address,
66
Scope: network.ScopePublic,
69
logger.Tracef("sigmaInstance.Addresses: %v", addr)
71
return []network.Address{addr}, nil
73
return []network.Address{}, nil
76
// OpenPorts opens the given ports on the instance, which
77
// should have been started with the given machine id.
78
func (i sigmaInstance) OpenPorts(machineID string, ports []network.PortRange) error {
79
return errors.NotImplementedf("OpenPorts")
82
// ClosePorts closes the given ports on the instance, which
83
// should have been started with the given machine id.
84
func (i sigmaInstance) ClosePorts(machineID string, ports []network.PortRange) error {
85
return errors.NotImplementedf("ClosePorts")
88
// Ports returns the set of ports open on the instance, which
89
// should have been started with the given machine id.
90
// The ports are returned as sorted by SortPorts.
91
func (i sigmaInstance) Ports(machineID string) ([]network.PortRange, error) {
92
return nil, errors.NotImplementedf("Ports")
95
func (i sigmaInstance) findIPv4() string {
96
addrs := i.server.IPv4()
103
func (i *sigmaInstance) hardware(arch string, driveSize uint64) (*instance.HardwareCharacteristics, error) {
104
memory := i.server.Mem() / gosigma.Megabyte
105
cores := uint64(i.server.SMP())
106
cpu := i.server.CPU()
107
hw := instance.HardwareCharacteristics{
114
diskSpace := driveSize / gosigma.Megabyte
116
hw.RootDisk = &diskSpace