1
// Copyright 2015 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
7
"gopkg.in/juju/names.v2"
9
"github.com/juju/errors"
10
"github.com/juju/juju/instance"
11
"github.com/juju/juju/network"
14
// SupportsNetworking is a convenience helper to check if an environment
15
// supports networking. It returns an interface containing Environ and
16
// Networking in this case.
17
var SupportsNetworking = supportsNetworking
19
// Networking interface defines methods that environments
20
// with networking capabilities must implement.
21
type Networking interface {
22
// Subnets returns basic information about subnets known
23
// by the provider for the environment.
24
Subnets(inst instance.Id, subnetIds []network.Id) ([]network.SubnetInfo, error)
26
// NetworkInterfaces requests information about the network
27
// interfaces on the given instance.
28
NetworkInterfaces(instId instance.Id) ([]network.InterfaceInfo, error)
30
// SupportsSpaces returns whether the current environment supports
31
// spaces. The returned error satisfies errors.IsNotSupported(),
32
// unless a general API failure occurs.
33
SupportsSpaces() (bool, error)
35
// SupportsSpaceDiscovery returns whether the current environment
36
// supports discovering spaces from the provider. The returned error
37
// satisfies errors.IsNotSupported(), unless a general API failure occurs.
38
SupportsSpaceDiscovery() (bool, error)
40
// Spaces returns a slice of network.SpaceInfo with info, including
41
// details of all associated subnets, about all spaces known to the
42
// provider that have subnets available.
43
Spaces() ([]network.SpaceInfo, error)
45
// AllocateContainerAddresses allocates a static address for each of the
46
// container NICs in preparedInfo, hosted by the hostInstanceID. Returns the
47
// network config including all allocated addresses on success.
48
AllocateContainerAddresses(hostInstanceID instance.Id, containerTag names.MachineTag, preparedInfo []network.InterfaceInfo) ([]network.InterfaceInfo, error)
50
// ReleaseContainerAddresses releases the previously allocated
51
// addresses matching the interface infos passed in.
52
ReleaseContainerAddresses(interfaces []network.InterfaceInfo) error
55
// NetworkingEnviron combines the standard Environ interface with the
56
// functionality for networking.
57
type NetworkingEnviron interface {
58
// Environ represents a juju environment.
61
// Networking defines the methods of networking capable environments.
65
func supportsNetworking(environ Environ) (NetworkingEnviron, bool) {
66
ne, ok := environ.(NetworkingEnviron)
70
// SupportsSpaces checks if the environment implements NetworkingEnviron
71
// and also if it supports spaces.
72
func SupportsSpaces(env Environ) bool {
73
netEnv, ok := supportsNetworking(env)
77
ok, err := netEnv.SupportsSpaces()
79
if !errors.IsNotSupported(err) {
80
logger.Errorf("checking model spaces support failed with: %v", err)