/
instance.go
45 lines (35 loc) · 989 Bytes
/
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
// Copyright 2013 Joyent Inc.
// Licensed under the AGPLv3, see LICENCE file for details.
package joyent
import (
"github.com/joyent/gosdc/cloudapi"
"github.com/juju/juju/instance"
"github.com/juju/juju/network"
)
type joyentInstance struct {
machine *cloudapi.Machine
env *joyentEnviron
}
var _ instance.Instance = (*joyentInstance)(nil)
func (inst *joyentInstance) Id() instance.Id {
return instance.Id(inst.machine.Id)
}
func (inst *joyentInstance) Status() string {
return inst.machine.State
}
func (inst *joyentInstance) Refresh() error {
return nil
}
func (inst *joyentInstance) Addresses() ([]network.Address, error) {
addresses := make([]network.Address, 0, len(inst.machine.IPs))
for _, ip := range inst.machine.IPs {
address := network.NewAddress(ip)
if ip == inst.machine.PrimaryIP {
address.Scope = network.ScopePublic
} else {
address.Scope = network.ScopeCloudLocal
}
addresses = append(addresses, address)
}
return addresses, nil
}