github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/provider/vsphere/environ_network.go (about) 1 // Copyright 2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 // +build !gccgo 5 6 package vsphere 7 8 import ( 9 "github.com/juju/errors" 10 11 "github.com/juju/juju/instance" 12 "github.com/juju/juju/network" 13 ) 14 15 // AllocateAddress implements environs.Environ. 16 func (env *environ) AllocateAddress(instID instance.Id, subnetID network.Id, addr *network.Address, _, _ string) error { 17 return env.changeAddress(instID, subnetID, *addr, true) 18 } 19 20 // ReleaseAddress implements environs.Environ. 21 func (env *environ) ReleaseAddress(instID instance.Id, netID network.Id, addr network.Address, _, _ string) error { 22 return env.changeAddress(instID, netID, addr, false) 23 } 24 25 func (env *environ) changeAddress(instID instance.Id, netID network.Id, addr network.Address, add bool) error { 26 instances, err := env.Instances([]instance.Id{instID}) 27 if err != nil { 28 return errors.Trace(err) 29 } 30 inst := instances[0].(*environInstance) 31 _, client, err := inst.getInstanceConfigurator() 32 if err != nil { 33 return errors.Trace(err) 34 } 35 interfaceName := "eth0" 36 if string(netID) == env.ecfg.externalNetwork() { 37 interfaceName = "eth1" 38 } 39 if add { 40 err = client.AddIpAddress(interfaceName, addr.Value) 41 } else { 42 err = client.ReleaseIpAddress(addr.Value) 43 } 44 45 return errors.Trace(err) 46 } 47 48 // SupportsSpaces is specified on environs.Networking. 49 func (env *environ) SupportsSpaces() (bool, error) { 50 return false, errors.NotSupportedf("spaces") 51 } 52 53 // SupportsAddressAllocation is specified on environs.Networking. 54 func (env *environ) SupportsAddressAllocation(_ network.Id) (bool, error) { 55 return false, errors.NotSupportedf("address allocation") 56 } 57 58 // Subnets implements environs.Environ. 59 func (env *environ) Subnets(inst instance.Id, ids []network.Id) ([]network.SubnetInfo, error) { 60 return env.client.Subnets(inst, ids) 61 } 62 63 // NetworkInterfaces implements environs.Environ. 64 func (env *environ) NetworkInterfaces(inst instance.Id) ([]network.InterfaceInfo, error) { 65 return env.client.GetNetworkInterfaces(inst, env.ecfg) 66 } 67 68 // OpenPorts opens the given port ranges for the whole environment. 69 // Must only be used if the environment was setup with the 70 // FwGlobal firewall mode. 71 func (env *environ) OpenPorts(ports []network.PortRange) error { 72 return errors.Trace(errors.NotSupportedf("ClosePorts")) 73 } 74 75 // ClosePorts closes the given port ranges for the whole environment. 76 // Must only be used if the environment was setup with the 77 // FwGlobal firewall mode. 78 func (env *environ) ClosePorts(ports []network.PortRange) error { 79 return errors.Trace(errors.NotSupportedf("ClosePorts")) 80 } 81 82 // Ports returns the port ranges opened for the whole environment. 83 // Must only be used if the environment was setup with the 84 // FwGlobal firewall mode. 85 func (env *environ) Ports() ([]network.PortRange, error) { 86 return nil, errors.Trace(errors.NotSupportedf("Ports")) 87 } 88 89 func (e *environ) AllocateContainerAddresses(hostInstanceID instance.Id, preparedInfo []network.InterfaceInfo) ([]network.InterfaceInfo, error) { 90 return nil, errors.NotSupportedf("container address allocation") 91 }