github.com/mhilton/juju-juju@v0.0.0-20150901100907-a94dd2c73455/apiserver/common/networking.go (about)

     1  // Copyright 2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package common
     5  
     6  import (
     7  	"github.com/juju/juju/apiserver/params"
     8  	"github.com/juju/juju/environs/config"
     9  	"github.com/juju/juju/network"
    10  	providercommon "github.com/juju/juju/provider/common"
    11  )
    12  
    13  // BackingSubnet defines the methods supported by a Subnet entity
    14  // stored persistently.
    15  //
    16  // TODO(dimitern): Once the state backing is implemented, remove this
    17  // and just use *state.Subnet.
    18  type BackingSubnet interface {
    19  	CIDR() string
    20  	VLANTag() int
    21  	ProviderId() string
    22  	AvailabilityZones() []string
    23  	Status() string
    24  	SpaceName() string
    25  	Life() params.Life
    26  }
    27  
    28  // BackingSubnetInfo describes a single subnet to be added in the
    29  // backing store.
    30  //
    31  // TODO(dimitern): Replace state.SubnetInfo with this and remove
    32  // BackingSubnetInfo, once the rest of state backing methods and the
    33  // following pre-reqs are done:
    34  // * subnetDoc.AvailabilityZone becomes subnetDoc.AvailabilityZones,
    35  //   adding an upgrade step to migrate existing non empty zones on
    36  //   subnet docs. Also change state.Subnet.AvailabilityZone to
    37  // * add subnetDoc.SpaceName - no upgrade step needed, as it will only
    38  //   be used for new space-aware subnets.
    39  // * Subnets need a reference count to calculate Status.
    40  // * ensure EC2 and MAAS providers accept empty IDs as Subnets() args
    41  //   and return all subnets, including the AvailabilityZones (for EC2;
    42  //   empty for MAAS as zones are orthogonal to networks).
    43  type BackingSubnetInfo struct {
    44  	// ProviderId is a provider-specific network id. This may be empty.
    45  	ProviderId string
    46  
    47  	// CIDR of the network, in 123.45.67.89/24 format.
    48  	CIDR string
    49  
    50  	// VLANTag needs to be between 1 and 4094 for VLANs and 0 for normal
    51  	// networks. It's defined by IEEE 802.1Q standard.
    52  	VLANTag int
    53  
    54  	// AllocatableIPHigh and Low describe the allocatable portion of the
    55  	// subnet. The remainder, if any, is reserved by the provider.
    56  	// Either both of these must be set or neither, if they're empty it
    57  	// means that none of the subnet is allocatable. If present they must
    58  	// be valid IP addresses within the subnet CIDR.
    59  	AllocatableIPHigh string
    60  	AllocatableIPLow  string
    61  
    62  	// AvailabilityZones describes which availability zone(s) this
    63  	// subnet is in. It can be empty if the provider does not support
    64  	// availability zones.
    65  	AvailabilityZones []string
    66  
    67  	// SpaceName holds the juju network space this subnet is
    68  	// associated with. Can be empty if not supported.
    69  	SpaceName string
    70  
    71  	// Status holds the status of the subnet. Normally this will be
    72  	// calculated from the reference count and Life of a subnet.
    73  	Status string
    74  
    75  	// Live holds the life of the subnet
    76  	Life params.Life
    77  }
    78  
    79  // BackingSpace defines the methods supported by a Space entity stored
    80  // persistently.
    81  type BackingSpace interface {
    82  	// Name returns the space name.
    83  	Name() string
    84  
    85  	// Subnets returns the subnets in the space
    86  	Subnets() ([]BackingSubnet, error)
    87  
    88  	// ProviderId returns the network ID of the provider
    89  	ProviderId() network.Id
    90  
    91  	// Zones returns a list of availability zone(s) that this
    92  	// space is in. It can be empty if the provider does not support
    93  	// availability zones.
    94  	Zones() []string
    95  
    96  	// Life returns the lifecycle state of the space
    97  	Life() params.Life
    98  }
    99  
   100  // Backing defines the methods needed by the API facade to store and
   101  // retrieve information from the underlying persistency layer (state
   102  // DB).
   103  type NetworkBacking interface {
   104  	// EnvironConfig returns the current environment config.
   105  	EnvironConfig() (*config.Config, error)
   106  
   107  	// AvailabilityZones returns all cached availability zones (i.e.
   108  	// not from the provider, but in state).
   109  	AvailabilityZones() ([]providercommon.AvailabilityZone, error)
   110  
   111  	// SetAvailabilityZones replaces the cached list of availability
   112  	// zones with the given zones.
   113  	SetAvailabilityZones([]providercommon.AvailabilityZone) error
   114  
   115  	// AddSpace creates a space
   116  	AddSpace(Name string, Subnets []string, Public bool) error
   117  
   118  	// AllSpaces returns all known Juju network spaces.
   119  	AllSpaces() ([]BackingSpace, error)
   120  
   121  	// AddSubnet creates a backing subnet for an existing subnet.
   122  	AddSubnet(BackingSubnetInfo) (BackingSubnet, error)
   123  
   124  	// AllSubnets returns all backing subnets.
   125  	AllSubnets() ([]BackingSubnet, error)
   126  }