github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/apiserver/client/state.go (about)

     1  // Copyright 2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package client
     5  
     6  import (
     7  	"github.com/juju/names"
     8  	"github.com/juju/version"
     9  	"gopkg.in/juju/charm.v6-unstable"
    10  
    11  	"github.com/juju/juju/constraints"
    12  	"github.com/juju/juju/environs/config"
    13  	"github.com/juju/juju/instance"
    14  	"github.com/juju/juju/network"
    15  	"github.com/juju/juju/state"
    16  	"github.com/juju/juju/status"
    17  )
    18  
    19  // Unit represents a state.Unit.
    20  type Unit interface {
    21  	status.StatusHistoryGetter
    22  	Life() state.Life
    23  	Destroy() (err error)
    24  	IsPrincipal() bool
    25  	PublicAddress() (network.Address, error)
    26  	PrivateAddress() (network.Address, error)
    27  	Resolve(retryHooks bool) error
    28  	AgentHistory() status.StatusHistoryGetter
    29  }
    30  
    31  // stateInterface contains the state.State methods used in this package,
    32  // allowing stubs to be created for testing.
    33  type stateInterface interface {
    34  	FindEntity(names.Tag) (state.Entity, error)
    35  	Unit(string) (Unit, error)
    36  	Service(string) (*state.Service, error)
    37  	Machine(string) (*state.Machine, error)
    38  	AllMachines() ([]*state.Machine, error)
    39  	AllServices() ([]*state.Service, error)
    40  	AllRelations() ([]*state.Relation, error)
    41  	AddOneMachine(state.MachineTemplate) (*state.Machine, error)
    42  	AddMachineInsideMachine(state.MachineTemplate, string, instance.ContainerType) (*state.Machine, error)
    43  	AddMachineInsideNewMachine(template, parentTemplate state.MachineTemplate, containerType instance.ContainerType) (*state.Machine, error)
    44  	ModelConstraints() (constraints.Value, error)
    45  	ModelConfig() (*config.Config, error)
    46  	UpdateModelConfig(map[string]interface{}, []string, state.ValidateConfigFunc) error
    47  	SetModelConstraints(constraints.Value) error
    48  	ModelUUID() string
    49  	ModelTag() names.ModelTag
    50  	Model() (*state.Model, error)
    51  	ForModel(tag names.ModelTag) (*state.State, error)
    52  	SetModelAgentVersion(version.Number) error
    53  	SetAnnotations(state.GlobalEntity, map[string]string) error
    54  	Annotations(state.GlobalEntity) (map[string]string, error)
    55  	InferEndpoints(...string) ([]state.Endpoint, error)
    56  	EndpointsRelation(...state.Endpoint) (*state.Relation, error)
    57  	Charm(*charm.URL) (*state.Charm, error)
    58  	LatestPlaceholderCharm(*charm.URL) (*state.Charm, error)
    59  	AddRelation(...state.Endpoint) (*state.Relation, error)
    60  	AddModelUser(state.ModelUserSpec) (*state.ModelUser, error)
    61  	RemoveModelUser(names.UserTag) error
    62  	Watch() *state.Multiwatcher
    63  	AbortCurrentUpgrade() error
    64  	APIHostPorts() ([][]network.HostPort, error)
    65  }
    66  
    67  type stateShim struct {
    68  	*state.State
    69  }
    70  
    71  func (s *stateShim) Unit(name string) (Unit, error) {
    72  	u, err := s.State.Unit(name)
    73  	if err != nil {
    74  		return nil, err
    75  	}
    76  	return u, nil
    77  }