~rogpeppe/juju-core/azure

« back to all changes in this revision

Viewing changes to environs/local/instance.go

[r=thumper] Add the initial bootstrap implementation.

This isn't all that is needed to bootstrap, but it is the start.
In particular, this adds the mongo upstart service. This branch
also adds a very simple instance implementation for the local
instances.

https://codereview.appspot.com/11325043/

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2013 Canonical Ltd.
 
2
// Licensed under the AGPLv3, see LICENCE file for details.
 
3
 
 
4
package local
 
5
 
 
6
import (
 
7
        "fmt"
 
8
 
 
9
        "launchpad.net/juju-core/environs"
 
10
        "launchpad.net/juju-core/instance"
 
11
)
 
12
 
 
13
type localInstance struct {
 
14
        id  instance.Id
 
15
        env *localEnviron
 
16
}
 
17
 
 
18
var _ instance.Instance = (*localInstance)(nil)
 
19
 
 
20
// Id implements instance.Instance.Id.
 
21
func (inst *localInstance) Id() instance.Id {
 
22
        return inst.id
 
23
}
 
24
 
 
25
// DNSName implements instance.Instance.DNSName.
 
26
func (inst *localInstance) DNSName() (string, error) {
 
27
        if string(inst.id) == "localhost" {
 
28
                // get the bridge address from the environment
 
29
                addr, err := inst.env.findBridgeAddress()
 
30
                if err != nil {
 
31
                        logger.Errorf("failed to get bridge address: %v", err)
 
32
                        return "", instance.ErrNoDNSName
 
33
                }
 
34
                return addr, nil
 
35
        }
 
36
        return "", instance.ErrNoDNSName
 
37
}
 
38
 
 
39
// WaitDNSName implements instance.Instance.WaitDNSName.
 
40
func (inst *localInstance) WaitDNSName() (string, error) {
 
41
        return environs.WaitDNSName(inst)
 
42
}
 
43
 
 
44
// OpenPorts implements instance.Instance.OpenPorts.
 
45
func (inst *localInstance) OpenPorts(machineId string, ports []instance.Port) error {
 
46
        logger.Infof("OpenPorts called for %s:%v", machineId, ports)
 
47
        return nil
 
48
}
 
49
 
 
50
// ClosePorts implements instance.Instance.ClosePorts.
 
51
func (inst *localInstance) ClosePorts(machineId string, ports []instance.Port) error {
 
52
        logger.Infof("ClosePorts called for %s:%v", machineId, ports)
 
53
        return nil
 
54
}
 
55
 
 
56
// Ports implements instance.Instance.Ports.
 
57
func (inst *localInstance) Ports(machineId string) ([]instance.Port, error) {
 
58
        return nil, fmt.Errorf("not implemented")
 
59
}
 
60
 
 
61
// Add a string representation of the id.
 
62
func (inst *localInstance) String() string {
 
63
        return fmt.Sprintf("inst:%v", inst.id)
 
64
}