~themue/juju-core/053-env-more-script-friendly

« back to all changes in this revision

Viewing changes to environs/maas/instance.go

Merge trunk and resolve conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package maas
 
2
 
 
3
import (
 
4
        "launchpad.net/gomaasapi"
 
5
        "launchpad.net/juju-core/environs"
 
6
        "launchpad.net/juju-core/log"
 
7
        "launchpad.net/juju-core/state"
 
8
        "launchpad.net/juju-core/state/api/params"
 
9
)
 
10
 
 
11
type maasInstance struct {
 
12
        maasObject *gomaasapi.MAASObject
 
13
        environ    *maasEnviron
 
14
}
 
15
 
 
16
var _ environs.Instance = (*maasInstance)(nil)
 
17
 
 
18
func (instance *maasInstance) Id() state.InstanceId {
 
19
        // Use the node's 'resource_uri' value.
 
20
        return state.InstanceId((*instance.maasObject).URI().String())
 
21
}
 
22
 
 
23
// refreshInstance refreshes the instance with the most up-to-date information
 
24
// from the MAAS server.
 
25
func (instance *maasInstance) refreshInstance() error {
 
26
        insts, err := instance.environ.Instances([]state.InstanceId{instance.Id()})
 
27
        if err != nil {
 
28
                return err
 
29
        }
 
30
        newMaasObject := insts[0].(*maasInstance).maasObject
 
31
        instance.maasObject = newMaasObject
 
32
        return nil
 
33
}
 
34
 
 
35
func (instance *maasInstance) DNSName() (string, error) {
 
36
        hostname, err := (*instance.maasObject).GetField("hostname")
 
37
        if err != nil {
 
38
                return "", err
 
39
        }
 
40
        return hostname, nil
 
41
}
 
42
 
 
43
func (instance *maasInstance) WaitDNSName() (string, error) {
 
44
        // A MAAS nodes gets his DNS name when it's created.  WaitDNSName,
 
45
        // (same as DNSName) just returns the hostname of the node.
 
46
        return instance.DNSName()
 
47
}
 
48
 
 
49
// MAAS does not do firewalling so these port methods do nothing.
 
50
func (instance *maasInstance) OpenPorts(machineId string, ports []params.Port) error {
 
51
        log.Debugf("environs/maas: unimplemented OpenPorts() called")
 
52
        return nil
 
53
}
 
54
 
 
55
func (instance *maasInstance) ClosePorts(machineId string, ports []params.Port) error {
 
56
        log.Debugf("environs/maas: unimplemented ClosePorts() called")
 
57
        return nil
 
58
}
 
59
 
 
60
func (instance *maasInstance) Ports(machineId string) ([]params.Port, error) {
 
61
        log.Debugf("environs/maas: unimplemented Ports() called")
 
62
        return []params.Port{}, nil
 
63
}