github.com/rogpeppe/juju@v0.0.0-20140613142852-6337964b789e/provider/local/instance.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  	"github.com/juju/errors"
    10  
    11  	"github.com/juju/juju/instance"
    12  	"github.com/juju/juju/network"
    13  )
    14  
    15  type localInstance struct {
    16  	id  instance.Id
    17  	env *localEnviron
    18  }
    19  
    20  var _ instance.Instance = (*localInstance)(nil)
    21  
    22  // Id implements instance.Instance.Id.
    23  func (inst *localInstance) Id() instance.Id {
    24  	return inst.id
    25  }
    26  
    27  // Status implements instance.Instance.Status.
    28  func (inst *localInstance) Status() string {
    29  	return ""
    30  }
    31  
    32  func (*localInstance) Refresh() error {
    33  	return nil
    34  }
    35  
    36  func (inst *localInstance) Addresses() ([]network.Address, error) {
    37  	if inst.id == bootstrapInstanceId {
    38  		addrs := []network.Address{{
    39  			Scope: network.ScopePublic,
    40  			Type:  network.HostName,
    41  			Value: "localhost",
    42  		}, {
    43  			Scope: network.ScopeCloudLocal,
    44  			Type:  network.IPv4Address,
    45  			Value: inst.env.bridgeAddress,
    46  		}}
    47  		return addrs, nil
    48  	}
    49  	return nil, errors.NotImplementedf("localInstance.Addresses")
    50  }
    51  
    52  // OpenPorts implements instance.Instance.OpenPorts.
    53  func (inst *localInstance) OpenPorts(machineId string, ports []network.Port) error {
    54  	logger.Infof("OpenPorts called for %s:%v", machineId, ports)
    55  	return nil
    56  }
    57  
    58  // ClosePorts implements instance.Instance.ClosePorts.
    59  func (inst *localInstance) ClosePorts(machineId string, ports []network.Port) error {
    60  	logger.Infof("ClosePorts called for %s:%v", machineId, ports)
    61  	return nil
    62  }
    63  
    64  // Ports implements instance.Instance.Ports.
    65  func (inst *localInstance) Ports(machineId string) ([]network.Port, error) {
    66  	return nil, nil
    67  }
    68  
    69  // Add a string representation of the id.
    70  func (inst *localInstance) String() string {
    71  	return fmt.Sprintf("inst:%v", inst.id)
    72  }