github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/provider/openstack/legacy_networking.go (about) 1 // Copyright 2012-2016 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package openstack 5 6 import ( 7 "github.com/juju/errors" 8 "github.com/juju/utils" 9 "gopkg.in/goose.v2/nova" 10 11 "github.com/juju/juju/core/instance" 12 "github.com/juju/juju/network" 13 ) 14 15 // LegacyNovaNetworking is an implementation of Networking that uses the legacy 16 // Nova network APIs. 17 // 18 // NOTE(axw) this is provided on a best-effort basis, primarily for CI testing 19 // of Juju until we are no longer dependent on an old OpenStack installation. 20 // This should not be relied on in production, and should be removed as soon as 21 // possible. 22 type LegacyNovaNetworking struct { 23 networkingBase 24 } 25 26 // AllocatePublicIP is part of the Networking interface. 27 func (n *LegacyNovaNetworking) AllocatePublicIP(instId instance.Id) (*string, error) { 28 fips, err := n.env.nova().ListFloatingIPs() 29 if err != nil { 30 return nil, err 31 } 32 var newfip *nova.FloatingIP 33 for _, fip := range fips { 34 newfip = &fip 35 if fip.InstanceId != nil && *fip.InstanceId != "" { 36 // unavailable, skip 37 newfip = nil 38 continue 39 } else { 40 logger.Debugf("found unassigned public ip: %v", newfip.IP) 41 // unassigned, we can use it 42 return &newfip.IP, nil 43 } 44 } 45 if newfip == nil { 46 // allocate a new IP and use it 47 newfip, err = n.env.nova().AllocateFloatingIP() 48 if err != nil { 49 return nil, err 50 } 51 logger.Debugf("allocated new public IP: %v", newfip.IP) 52 } 53 return &newfip.IP, nil 54 } 55 56 // DefaultNetworks is part of the Networking interface. 57 func (*LegacyNovaNetworking) DefaultNetworks() ([]nova.ServerNetworks, error) { 58 return []nova.ServerNetworks{}, nil 59 } 60 61 // ResolveNetwork is part of the Networking interface. 62 func (n *LegacyNovaNetworking) ResolveNetwork(name string, external bool) (string, error) { 63 // Ignore external, it's a Neutron concept. 64 if utils.IsValidUUIDString(name) { 65 return name, nil 66 } 67 var networkIds []string 68 networks, err := n.env.nova().ListNetworks() 69 if err != nil { 70 return "", err 71 } 72 for _, network := range networks { 73 // Assuming a positive match on "" makes this behave the same as the 74 // server-side filtering in Neutron networking. 75 if name == "" || network.Label == name { 76 networkIds = append(networkIds, network.Id) 77 } 78 } 79 return processResolveNetworkIds(name, networkIds) 80 } 81 82 // Subnets is part of the Networking interface. 83 func (n *LegacyNovaNetworking) Subnets(instId instance.Id, subnetIds []network.Id) ([]network.SubnetInfo, error) { 84 return nil, errors.NotSupportedf("nova subnet") 85 } 86 87 // NetworkInterfaces is part of the Networking interface. 88 func (n *LegacyNovaNetworking) NetworkInterfaces(instId instance.Id) ([]network.InterfaceInfo, error) { 89 return nil, errors.NotSupportedf("nova network interfaces") 90 }