github.com/cloudbase/juju-core@v0.0.0-20140504232958-a7271ac7912f/provider/local/instance_linux.go (about) 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/errors" 10 "launchpad.net/juju-core/instance" 11 "launchpad.net/juju-core/provider/common" 12 ) 13 14 type localInstance struct { 15 id instance.Id 16 env *localEnviron 17 } 18 19 var _ instance.Instance = (*localInstance)(nil) 20 21 // Id implements instance.Instance.Id. 22 func (inst *localInstance) Id() instance.Id { 23 return inst.id 24 } 25 26 // Status implements instance.Instance.Status. 27 func (inst *localInstance) Status() string { 28 return "" 29 } 30 31 func (*localInstance) Refresh() error { 32 return nil 33 } 34 35 func (inst *localInstance) Addresses() ([]instance.Address, error) { 36 if inst.id == bootstrapInstanceId { 37 addrs := []instance.Address{{ 38 NetworkScope: instance.NetworkPublic, 39 Type: instance.HostName, 40 Value: "localhost", 41 }, { 42 NetworkScope: instance.NetworkCloudLocal, 43 Type: instance.Ipv4Address, 44 Value: inst.env.bridgeAddress, 45 }} 46 return addrs, nil 47 } 48 return nil, errors.NewNotImplementedError("localInstance.Addresses") 49 } 50 51 // DNSName implements instance.Instance.DNSName. 52 func (inst *localInstance) DNSName() (string, error) { 53 if inst.id == bootstrapInstanceId { 54 return inst.env.bridgeAddress, nil 55 } 56 // Get the IPv4 address from eth0 57 return getAddressForInterface("eth0") 58 } 59 60 // WaitDNSName implements instance.Instance.WaitDNSName. 61 func (inst *localInstance) WaitDNSName() (string, error) { 62 return common.WaitDNSName(inst) 63 } 64 65 // OpenPorts implements instance.Instance.OpenPorts. 66 func (inst *localInstance) OpenPorts(machineId string, ports []instance.Port) error { 67 logger.Infof("OpenPorts called for %s:%v", machineId, ports) 68 return nil 69 } 70 71 // ClosePorts implements instance.Instance.ClosePorts. 72 func (inst *localInstance) ClosePorts(machineId string, ports []instance.Port) error { 73 logger.Infof("ClosePorts called for %s:%v", machineId, ports) 74 return nil 75 } 76 77 // Ports implements instance.Instance.Ports. 78 func (inst *localInstance) Ports(machineId string) ([]instance.Port, error) { 79 return nil, nil 80 } 81 82 // Add a string representation of the id. 83 func (inst *localInstance) String() string { 84 return fmt.Sprintf("inst:%v", inst.id) 85 }