github.com/altoros/juju-vmware@v0.0.0-20150312064031-f19ae857ccca/provider/vmware/instance.go (about)

     1  // Copyright 2014 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package vmware
     5  
     6  import (
     7  	"github.com/juju/errors"
     8  	"github.com/vmware/govmomi/vim25/mo"
     9  
    10  	"github.com/juju/juju/instance"
    11  	"github.com/juju/juju/network"
    12  )
    13  
    14  type environInstance struct {
    15  	base *mo.VirtualMachine
    16  	env  *environ
    17  }
    18  
    19  var _ instance.Instance = (*environInstance)(nil)
    20  
    21  func newInstance(base *mo.VirtualMachine, env *environ) *environInstance {
    22  	return &environInstance{
    23  		base: base,
    24  		env:  env,
    25  	}
    26  }
    27  
    28  // Id implements instance.Instance.
    29  func (inst *environInstance) Id() instance.Id {
    30  	return instance.Id(inst.base.Name)
    31  }
    32  
    33  // Status implements instance.Instance.
    34  func (inst *environInstance) Status() string {
    35  	//return inst.base.Status()
    36  	return ""
    37  }
    38  
    39  // Refresh implements instance.Instance.
    40  func (inst *environInstance) Refresh() error {
    41  	env := inst.env.getSnapshot()
    42  	err := env.client.Refresh(inst.base)
    43  	return errors.Trace(err)
    44  }
    45  
    46  // Addresses implements instance.Instance.
    47  func (inst *environInstance) Addresses() ([]network.Address, error) {
    48  	if inst.base.Guest == nil || inst.base.Guest.IpAddress == "" {
    49  		return nil, nil
    50  	}
    51  	return network.NewAddresses(inst.base.Guest.IpAddress), nil
    52  }
    53  
    54  func findInst(id instance.Id, instances []instance.Instance) instance.Instance {
    55  	for _, inst := range instances {
    56  		if id == inst.Id() {
    57  			return inst
    58  		}
    59  	}
    60  	return nil
    61  }
    62  
    63  // firewall stuff
    64  
    65  // OpenPorts opens the given ports on the instance, which
    66  // should have been started with the given machine id.
    67  func (inst *environInstance) OpenPorts(machineID string, ports []network.PortRange) error {
    68  	return errors.Trace(errors.NotImplementedf(""))
    69  }
    70  
    71  // ClosePorts closes the given ports on the instance, which
    72  // should have been started with the given machine id.
    73  func (inst *environInstance) ClosePorts(machineID string, ports []network.PortRange) error {
    74  	return errors.Trace(errors.NotImplementedf(""))
    75  }
    76  
    77  // Ports returns the set of ports open on the instance, which
    78  // should have been started with the given machine id.
    79  // The ports are returned as sorted by SortPorts.
    80  func (inst *environInstance) Ports(machineID string) ([]network.PortRange, error) {
    81  	return nil, errors.Trace(errors.NotImplementedf(""))
    82  }