github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/container/kvm/instance.go (about)

     1  // Copyright 2013 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package kvm
     5  
     6  import (
     7  	"fmt"
     8  
     9  	"github.com/juju/juju/core/instance"
    10  	corenetwork "github.com/juju/juju/core/network"
    11  	"github.com/juju/juju/core/network/firewall"
    12  	"github.com/juju/juju/core/status"
    13  	"github.com/juju/juju/environs/context"
    14  	"github.com/juju/juju/environs/instances"
    15  )
    16  
    17  type kvmInstance struct {
    18  	container Container
    19  	id        string
    20  }
    21  
    22  var _ instances.Instance = (*kvmInstance)(nil)
    23  
    24  // Id implements instances.instance.Id.
    25  func (kvm *kvmInstance) Id() instance.Id {
    26  	return instance.Id(kvm.id)
    27  }
    28  
    29  // Status implements instances.Instance.Status.
    30  func (kvm *kvmInstance) Status(ctx context.ProviderCallContext) instance.Status {
    31  	if kvm.container.IsRunning() {
    32  		return instance.Status{
    33  			Status:  status.Running,
    34  			Message: "running",
    35  		}
    36  	}
    37  	return instance.Status{
    38  		Status:  status.Stopped,
    39  		Message: "stopped",
    40  	}
    41  }
    42  
    43  func (*kvmInstance) Refresh() error {
    44  	return nil
    45  }
    46  
    47  func (kvm *kvmInstance) Addresses(ctx context.ProviderCallContext) (corenetwork.ProviderAddresses, error) {
    48  	logger.Errorf("kvmInstance.Addresses not implemented")
    49  	return nil, nil
    50  }
    51  
    52  // OpenPorts implements instances.Instance.OpenPorts.
    53  func (kvm *kvmInstance) OpenPorts(ctx context.ProviderCallContext, machineId string, rules firewall.IngressRules) error {
    54  	return fmt.Errorf("not implemented")
    55  }
    56  
    57  // ClosePorts implements instances.Instance.ClosePorts.
    58  func (kvm *kvmInstance) ClosePorts(ctx context.ProviderCallContext, machineId string, rules firewall.IngressRules) error {
    59  	return fmt.Errorf("not implemented")
    60  }
    61  
    62  // IngressRules implements instances.Instance.IngressRules.
    63  func (kvm *kvmInstance) IngressRules(ctx context.ProviderCallContext, machineId string) (firewall.IngressRules, error) {
    64  	return nil, fmt.Errorf("not implemented")
    65  }
    66  
    67  // Add a string representation of the id.
    68  func (kvm *kvmInstance) String() string {
    69  	return fmt.Sprintf("kvm:%s", kvm.id)
    70  }