github.com/Pankov404/juju@v0.0.0-20150703034450-be266991dceb/environs/networking.go (about)

     1  // Copyright 2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package environs
     5  
     6  import (
     7  	"github.com/juju/utils/featureflag"
     8  
     9  	"github.com/juju/juju/feature"
    10  	"github.com/juju/juju/instance"
    11  	"github.com/juju/juju/network"
    12  )
    13  
    14  // Networking interface defines methods that environments
    15  // with networking capabilities must implement.
    16  type Networking interface {
    17  	// AllocateAddress requests a specific address to be allocated for the
    18  	// given instance on the given subnet.
    19  	AllocateAddress(instId instance.Id, subnetId network.Id, addr network.Address) error
    20  
    21  	// ReleaseAddress releases a specific address previously allocated with
    22  	// AllocateAddress.
    23  	ReleaseAddress(instId instance.Id, subnetId network.Id, addr network.Address) error
    24  
    25  	// Subnets returns basic information about subnets known
    26  	// by the provider for the environment.
    27  	Subnets(inst instance.Id, subnetIds []network.Id) ([]network.SubnetInfo, error)
    28  
    29  	// NetworkInterfaces requests information about the network
    30  	// interfaces on the given instance.
    31  	NetworkInterfaces(instId instance.Id) ([]network.InterfaceInfo, error)
    32  
    33  	// SupportsAddressAllocation returns whether the given subnetId
    34  	// supports static IP address allocation using AllocateAddress and
    35  	// ReleaseAddress. If subnetId is network.AnySubnet, the provider
    36  	// can decide whether it can return true or a false and an error
    37  	// (e.g. "subnetId must be set").
    38  	SupportsAddressAllocation(subnetId network.Id) (bool, error)
    39  }
    40  
    41  // NetworkingEnviron combines the standard Environ interface with the
    42  // functionality for networking.
    43  type NetworkingEnviron interface {
    44  	// Environ represents a juju environment.
    45  	Environ
    46  
    47  	// Networking defines the methods of networking capable environments.
    48  	Networking
    49  }
    50  
    51  // SupportsNetworking is a convenience helper to check if an environment
    52  // supports networking. It returns an interface containing Environ and
    53  // Networking in this case.
    54  func SupportsNetworking(environ Environ) (NetworkingEnviron, bool) {
    55  	ne, ok := environ.(NetworkingEnviron)
    56  	return ne, ok
    57  }
    58  
    59  // AddressAllocationEnabled is a shortcut for checking if the
    60  // AddressAllocation feature flag is enabled.
    61  func AddressAllocationEnabled() bool {
    62  	return featureflag.Enabled(feature.AddressAllocation)
    63  }