github.com/altoros/juju-vmware@v0.0.0-20150312064031-f19ae857ccca/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/juju/instance" 8 "github.com/juju/juju/network" 9 ) 10 11 // Networking interface defines methods that environments 12 // with networking capabilities must implement. 13 type Networking interface { 14 // AllocateAddress requests a specific address to be allocated for the 15 // given instance on the given subnet. 16 AllocateAddress(instId instance.Id, subnetId network.Id, addr network.Address) error 17 18 // ReleaseAddress releases a specific address previously allocated with 19 // AllocateAddress. 20 ReleaseAddress(instId instance.Id, subnetId network.Id, addr network.Address) error 21 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) 25 26 // NetworkInterfaces requests information about the network 27 // interfaces on the given instance. 28 NetworkInterfaces(instId instance.Id) ([]network.InterfaceInfo, error) 29 30 // SupportsAddressAllocation returns whether the given subnetId 31 // supports static IP address allocation using AllocateAddress 32 // and ReleaseAddress. 33 SupportsAddressAllocation(subnetId network.Id) (bool, error) 34 } 35 36 // NetworkingEnviron combines the standard Environ interface with the 37 // functionality for networking. 38 type NetworkingEnviron interface { 39 // Environ represents a juju environment. 40 Environ 41 42 // Networking defines the methods of networking capable environments. 43 Networking 44 } 45 46 // SupportsNetworking is a convenience helper to check if an environment 47 // supports networking. It returns an interface containing Environ and 48 // Networking in this case. 49 func SupportsNetworking(environ Environ) (NetworkingEnviron, bool) { 50 ne, ok := environ.(NetworkingEnviron) 51 return ne, ok 52 }