mirror of https://github.com/kubernetes/kops.git
Merge pull request #9790 from olemarkus/openstack-newer-nova
Remove compute floating ip extension
This commit is contained in:
commit
165933852d
|
|
@ -57,20 +57,24 @@ func (os *clusterDiscoveryOS) listL3FloatingIPs(routerID string) ([]*resources.R
|
|||
|
||||
func (os *clusterDiscoveryOS) listFloatingIPs(instanceID string) ([]*resources.Resource, error) {
|
||||
var resourceTrackers []*resources.Resource
|
||||
floatingIPs, err := os.osCloud.ListFloatingIPs()
|
||||
instance, err := os.osCloud.GetInstance(instanceID)
|
||||
if err != nil {
|
||||
return resourceTrackers, err
|
||||
}
|
||||
floatingIPs, err := os.osCloud.ListL3FloatingIPs(l3floatingip.ListOpts{
|
||||
Description: "fip-" + instance.Name,
|
||||
})
|
||||
if err != nil {
|
||||
return resourceTrackers, err
|
||||
}
|
||||
for _, floatingIP := range floatingIPs {
|
||||
if floatingIP.InstanceID == instanceID {
|
||||
resourceTracker := &resources.Resource{
|
||||
Name: floatingIP.IP,
|
||||
ID: floatingIP.ID,
|
||||
Type: typeFloatingIP,
|
||||
Deleter: DeleteFloatingIP,
|
||||
}
|
||||
resourceTrackers = append(resourceTrackers, resourceTracker)
|
||||
resourceTracker := &resources.Resource{
|
||||
Name: floatingIP.Description,
|
||||
ID: floatingIP.ID,
|
||||
Type: typeFloatingIP,
|
||||
Deleter: DeleteFloatingIP,
|
||||
}
|
||||
resourceTrackers = append(resourceTrackers, resourceTracker)
|
||||
}
|
||||
return resourceTrackers, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,7 +44,6 @@ go_library(
|
|||
"//vendor/github.com/gophercloud/gophercloud/openstack:go_default_library",
|
||||
"//vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v3/volumes:go_default_library",
|
||||
"//vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/availabilityzones:go_default_library",
|
||||
"//vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/floatingips:go_default_library",
|
||||
"//vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/keypairs:go_default_library",
|
||||
"//vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/servergroups:go_default_library",
|
||||
"//vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/volumeattach:go_default_library",
|
||||
|
|
@ -81,7 +80,6 @@ go_test(
|
|||
deps = [
|
||||
"//pkg/apis/kops:go_default_library",
|
||||
"//vendor/github.com/gophercloud/gophercloud:go_default_library",
|
||||
"//vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/floatingips:go_default_library",
|
||||
"//vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/servers:go_default_library",
|
||||
"//vendor/github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/loadbalancers:go_default_library",
|
||||
"//vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/floatingips:go_default_library",
|
||||
|
|
|
|||
|
|
@ -29,7 +29,6 @@ import (
|
|||
os "github.com/gophercloud/gophercloud/openstack"
|
||||
cinder "github.com/gophercloud/gophercloud/openstack/blockstorage/v3/volumes"
|
||||
az "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/availabilityzones"
|
||||
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/floatingips"
|
||||
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/keypairs"
|
||||
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/servergroups"
|
||||
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/volumeattach"
|
||||
|
|
@ -289,17 +288,14 @@ type OpenstackCloud interface {
|
|||
|
||||
GetStorageAZFromCompute(azName string) (*az.AvailabilityZone, error)
|
||||
|
||||
GetFloatingIP(id string) (fip *floatingips.FloatingIP, err error)
|
||||
GetL3FloatingIP(id string) (fip *l3floatingip.FloatingIP, err error)
|
||||
|
||||
GetImage(name string) (i *images.Image, err error)
|
||||
|
||||
GetFlavor(name string) (f *flavors.Flavor, err error)
|
||||
|
||||
AssociateFloatingIPToInstance(serverID string, opts floatingips.AssociateOpts) (err error)
|
||||
|
||||
ListServerFloatingIPs(id string) ([]*string, error)
|
||||
|
||||
ListFloatingIPs() (fips []floatingips.FloatingIP, err error)
|
||||
ListL3FloatingIPs(opts l3floatingip.ListOpts) (fips []l3floatingip.FloatingIP, err error)
|
||||
CreateL3FloatingIP(opts l3floatingip.CreateOpts) (fip *l3floatingip.FloatingIP, err error)
|
||||
DeleteFloatingIP(id string) error
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/gophercloud/gophercloud"
|
||||
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/floatingips"
|
||||
"github.com/gophercloud/gophercloud/openstack/compute/v2/servers"
|
||||
"github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/loadbalancers"
|
||||
l3floatingips "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/floatingips"
|
||||
|
|
@ -39,7 +38,6 @@ func Test_OpenstackCloud_GetApiIngressStatus(t *testing.T) {
|
|||
desc string
|
||||
cluster *kops.Cluster
|
||||
loadbalancers []loadbalancers.LoadBalancer
|
||||
floatingIPs []floatingips.FloatingIP
|
||||
l3FloatingIPs []l3floatingips.FloatingIP
|
||||
instances serverList
|
||||
cloudFloatingEnabled bool
|
||||
|
|
@ -325,19 +323,6 @@ func Test_OpenstackCloud_GetApiIngressStatus(t *testing.T) {
|
|||
))),
|
||||
http.StatusOK,
|
||||
)
|
||||
fixture(
|
||||
mux,
|
||||
"/os-floating-ips",
|
||||
http.MethodGet,
|
||||
string(mustJSONMarshal(json.Marshal(
|
||||
struct {
|
||||
FloatingIPs []floatingips.FloatingIP `json:"floating_ips"`
|
||||
}{
|
||||
FloatingIPs: testCase.floatingIPs,
|
||||
},
|
||||
))),
|
||||
http.StatusOK,
|
||||
)
|
||||
mux.HandleFunc("/floatingips", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
|
|
|
|||
|
|
@ -19,20 +19,19 @@ package openstack
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/floatingips"
|
||||
l3floatingip "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/floatingips"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
"k8s.io/kops/util/pkg/vfs"
|
||||
)
|
||||
|
||||
func (c *openstackCloud) GetFloatingIP(id string) (fip *floatingips.FloatingIP, err error) {
|
||||
return getFloatingIP(c, id)
|
||||
func (c *openstackCloud) GetL3FloatingIP(id string) (fip *l3floatingip.FloatingIP, err error) {
|
||||
return getL3FloatingIP(c, id)
|
||||
}
|
||||
|
||||
func getFloatingIP(c OpenstackCloud, id string) (fip *floatingips.FloatingIP, err error) {
|
||||
func getL3FloatingIP(c OpenstackCloud, id string) (fip *l3floatingip.FloatingIP, err error) {
|
||||
done, err := vfs.RetryWithBackoff(readBackoff, func() (bool, error) {
|
||||
|
||||
fip, err = floatingips.Get(c.ComputeClient(), id).Extract()
|
||||
fip, err = l3floatingip.Get(c.NetworkingClient(), id).Extract()
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("GetFloatingIP: fetching floating IP (%s) failed: %v", id, err)
|
||||
}
|
||||
|
|
@ -47,47 +46,6 @@ func getFloatingIP(c OpenstackCloud, id string) (fip *floatingips.FloatingIP, er
|
|||
return fip, nil
|
||||
}
|
||||
|
||||
func (c *openstackCloud) CreateFloatingIP(opts floatingips.CreateOpts) (fip *floatingips.FloatingIP, err error) {
|
||||
return createFloatingIP(c, opts)
|
||||
}
|
||||
|
||||
func createFloatingIP(c OpenstackCloud, opts floatingips.CreateOpts) (fip *floatingips.FloatingIP, err error) {
|
||||
done, err := vfs.RetryWithBackoff(writeBackoff, func() (bool, error) {
|
||||
|
||||
fip, err = floatingips.Create(c.ComputeClient(), opts).Extract()
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("CreateFloatingIP: create floating IP failed: %v", err)
|
||||
}
|
||||
return true, nil
|
||||
})
|
||||
if !done {
|
||||
if err == nil {
|
||||
err = wait.ErrWaitTimeout
|
||||
}
|
||||
return fip, err
|
||||
}
|
||||
return fip, nil
|
||||
}
|
||||
|
||||
func (c *openstackCloud) AssociateFloatingIPToInstance(serverID string, opts floatingips.AssociateOpts) (err error) {
|
||||
return associateFloatingIPToInstance(c, serverID, opts)
|
||||
}
|
||||
|
||||
func associateFloatingIPToInstance(c OpenstackCloud, serverID string, opts floatingips.AssociateOpts) (err error) {
|
||||
done, err := vfs.RetryWithBackoff(writeBackoff, func() (bool, error) {
|
||||
err = floatingips.AssociateInstance(c.ComputeClient(), serverID, opts).ExtractErr()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return true, nil
|
||||
})
|
||||
|
||||
if !done && err == nil {
|
||||
err = wait.ErrWaitTimeout
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *openstackCloud) CreateL3FloatingIP(opts l3floatingip.CreateOpts) (fip *l3floatingip.FloatingIP, err error) {
|
||||
return createL3FloatingIP(c, opts)
|
||||
}
|
||||
|
|
@ -110,32 +68,6 @@ func createL3FloatingIP(c OpenstackCloud, opts l3floatingip.CreateOpts) (fip *l3
|
|||
return fip, nil
|
||||
}
|
||||
|
||||
func (c *openstackCloud) ListFloatingIPs() (fips []floatingips.FloatingIP, err error) {
|
||||
return listFloatingIPs(c)
|
||||
}
|
||||
|
||||
func listFloatingIPs(c OpenstackCloud) (fips []floatingips.FloatingIP, err error) {
|
||||
|
||||
done, err := vfs.RetryWithBackoff(readBackoff, func() (bool, error) {
|
||||
pages, err := floatingips.List(c.ComputeClient()).AllPages()
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("failed to list floating ip: %v", err)
|
||||
}
|
||||
fips, err = floatingips.ExtractFloatingIPs(pages)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("failed to extract floating ip: %v", err)
|
||||
}
|
||||
return true, nil
|
||||
})
|
||||
if !done {
|
||||
if err == nil {
|
||||
err = wait.ErrWaitTimeout
|
||||
}
|
||||
return fips, err
|
||||
}
|
||||
return fips, nil
|
||||
}
|
||||
|
||||
func (c *openstackCloud) ListL3FloatingIPs(opts l3floatingip.ListOpts) (fips []l3floatingip.FloatingIP, err error) {
|
||||
return listL3FloatingIPs(c, opts)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ import (
|
|||
"github.com/gophercloud/gophercloud"
|
||||
cinder "github.com/gophercloud/gophercloud/openstack/blockstorage/v3/volumes"
|
||||
az "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/availabilityzones"
|
||||
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/floatingips"
|
||||
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/keypairs"
|
||||
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/servergroups"
|
||||
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/volumeattach"
|
||||
|
|
@ -162,10 +161,6 @@ func (c *MockCloud) AppendTag(resource string, id string, tag string) error {
|
|||
return appendTag(c, resource, id, tag)
|
||||
}
|
||||
|
||||
func (c *MockCloud) AssociateFloatingIPToInstance(serverID string, opts floatingips.AssociateOpts) (err error) {
|
||||
return associateFloatingIPToInstance(c, serverID, opts)
|
||||
}
|
||||
|
||||
func (c *MockCloud) AssociateToPool(server *servers.Server, poolID string, opts v2pools.CreateMemberOpts) (association *v2pools.Member, err error) {
|
||||
return associateToPool(c, server, poolID, opts)
|
||||
}
|
||||
|
|
@ -174,10 +169,6 @@ func (c *MockCloud) AttachVolume(serverID string, opts volumeattach.CreateOpts)
|
|||
return attachVolume(c, serverID, opts)
|
||||
}
|
||||
|
||||
func (c *MockCloud) CreateFloatingIP(opts floatingips.CreateOpts) (fip *floatingips.FloatingIP, err error) {
|
||||
return createFloatingIP(c, opts)
|
||||
}
|
||||
|
||||
func (c *MockCloud) CreateInstance(opt servers.CreateOptsBuilder) (*servers.Server, error) {
|
||||
return createInstance(c, opt)
|
||||
}
|
||||
|
|
@ -325,8 +316,8 @@ func (c *MockCloud) GetExternalSubnet() (subnet *subnets.Subnet, err error) {
|
|||
return getExternalSubnet(c, c.extSubnetName)
|
||||
}
|
||||
|
||||
func (c *MockCloud) GetFloatingIP(id string) (fip *floatingips.FloatingIP, err error) {
|
||||
return getFloatingIP(c, id)
|
||||
func (c *MockCloud) GetL3FloatingIP(id string) (fip *l3floatingip.FloatingIP, err error) {
|
||||
return getL3FloatingIP(c, id)
|
||||
}
|
||||
|
||||
func (c *MockCloud) GetImage(name string) (*images.Image, error) {
|
||||
|
|
@ -381,9 +372,6 @@ func (c *MockCloud) ListDNSZones(opt zones.ListOptsBuilder) ([]zones.Zone, error
|
|||
func (c *MockCloud) ListDNSRecordsets(zoneID string, opt recordsets.ListOptsBuilder) ([]recordsets.RecordSet, error) {
|
||||
return listDNSRecordsets(c, zoneID, opt)
|
||||
}
|
||||
func (c *MockCloud) ListFloatingIPs() (fips []floatingips.FloatingIP, err error) {
|
||||
return listFloatingIPs(c)
|
||||
}
|
||||
|
||||
func (c *MockCloud) ListInstances(opt servers.ListOptsBuilder) ([]servers.Server, error) {
|
||||
return listInstances(c, opt)
|
||||
|
|
|
|||
|
|
@ -45,7 +45,6 @@ go_library(
|
|||
"//vendor/github.com/gophercloud/gophercloud:go_default_library",
|
||||
"//vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v3/volumes:go_default_library",
|
||||
"//vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/bootfromvolume:go_default_library",
|
||||
"//vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/floatingips:go_default_library",
|
||||
"//vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/keypairs:go_default_library",
|
||||
"//vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/schedulerhints:go_default_library",
|
||||
"//vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/servergroups:go_default_library",
|
||||
|
|
|
|||
|
|
@ -96,11 +96,11 @@ func (e *FloatingIP) FindIPAddress(context *fi.Context) (*string, error) {
|
|||
return nil, fmt.Errorf("Could not find port floatingips port=%s", fi.StringValue(e.LB.PortID))
|
||||
}
|
||||
|
||||
fip, err := cloud.GetFloatingIP(fi.StringValue(e.ID))
|
||||
fip, err := cloud.GetL3FloatingIP(fi.StringValue(e.ID))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &fip.IP, nil
|
||||
return &fip.FloatingIP, nil
|
||||
}
|
||||
|
||||
// GetDependencies returns the dependencies of the Instance task
|
||||
|
|
|
|||
|
|
@ -20,8 +20,9 @@ import (
|
|||
"fmt"
|
||||
"strconv"
|
||||
|
||||
l3floatingip "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/floatingips"
|
||||
|
||||
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/bootfromvolume"
|
||||
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/floatingips"
|
||||
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/keypairs"
|
||||
"github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/schedulerhints"
|
||||
"github.com/gophercloud/gophercloud/openstack/compute/v2/servers"
|
||||
|
|
@ -253,10 +254,12 @@ func (_ *Instance) RenderOpenstack(t *openstack.OpenstackAPITarget, a, e, change
|
|||
|
||||
func associateFloatingIP(t *openstack.OpenstackAPITarget, e *Instance) error {
|
||||
cloud := t.Cloud.(openstack.OpenstackCloud)
|
||||
client := cloud.NetworkingClient()
|
||||
|
||||
_, err := l3floatingip.Update(client, fi.StringValue(e.FloatingIP.ID), l3floatingip.UpdateOpts{
|
||||
PortID: e.Port.ID,
|
||||
}).Extract()
|
||||
|
||||
err := cloud.AssociateFloatingIPToInstance(fi.StringValue(e.ID), floatingips.AssociateOpts{
|
||||
FloatingIP: fi.StringValue(e.FloatingIP.IP),
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to associated floating IP to instance %s: %v", *e.Name, err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,10 +19,9 @@ package openstacktasks
|
|||
import (
|
||||
"fmt"
|
||||
|
||||
"k8s.io/klog/v2"
|
||||
// "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/floatingips"
|
||||
"github.com/gophercloud/gophercloud/openstack/loadbalancer/v2/listeners"
|
||||
openstackutil "k8s.io/cloud-provider-openstack/pkg/util/openstack"
|
||||
"k8s.io/klog/v2"
|
||||
"k8s.io/kops/upup/pkg/fi"
|
||||
"k8s.io/kops/upup/pkg/fi/cloudup/openstack"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,18 +0,0 @@
|
|||
load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [
|
||||
"doc.go",
|
||||
"requests.go",
|
||||
"results.go",
|
||||
"urls.go",
|
||||
],
|
||||
importmap = "k8s.io/kops/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/floatingips",
|
||||
importpath = "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/floatingips",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//vendor/github.com/gophercloud/gophercloud:go_default_library",
|
||||
"//vendor/github.com/gophercloud/gophercloud/pagination:go_default_library",
|
||||
],
|
||||
)
|
||||
|
|
@ -1,68 +0,0 @@
|
|||
/*
|
||||
Package floatingips provides the ability to manage floating ips through the
|
||||
Nova API.
|
||||
|
||||
This API has been deprecated and will be removed from a future release of the
|
||||
Nova API service.
|
||||
|
||||
For environements that support this extension, this package can be used
|
||||
regardless of if either Neutron or nova-network is used as the cloud's network
|
||||
service.
|
||||
|
||||
Example to List Floating IPs
|
||||
|
||||
allPages, err := floatingips.List(computeClient).AllPages()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
allFloatingIPs, err := floatingips.ExtractFloatingIPs(allPages)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
for _, fip := range allFloatingIPs {
|
||||
fmt.Printf("%+v\n", fip)
|
||||
}
|
||||
|
||||
Example to Create a Floating IP
|
||||
|
||||
createOpts := floatingips.CreateOpts{
|
||||
Pool: "nova",
|
||||
}
|
||||
|
||||
fip, err := floatingips.Create(computeClient, createOpts).Extract()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
Example to Delete a Floating IP
|
||||
|
||||
err := floatingips.Delete(computeClient, "floatingip-id").ExtractErr()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
Example to Associate a Floating IP With a Server
|
||||
|
||||
associateOpts := floatingips.AssociateOpts{
|
||||
FloatingIP: "10.10.10.2",
|
||||
}
|
||||
|
||||
err := floatingips.AssociateInstance(computeClient, "server-id", associateOpts).ExtractErr()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
Example to Disassociate a Floating IP From a Server
|
||||
|
||||
disassociateOpts := floatingips.DisassociateOpts{
|
||||
FloatingIP: "10.10.10.2",
|
||||
}
|
||||
|
||||
err := floatingips.DisassociateInstance(computeClient, "server-id", disassociateOpts).ExtractErr()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
*/
|
||||
package floatingips
|
||||
|
|
@ -1,119 +0,0 @@
|
|||
package floatingips
|
||||
|
||||
import (
|
||||
"github.com/gophercloud/gophercloud"
|
||||
"github.com/gophercloud/gophercloud/pagination"
|
||||
)
|
||||
|
||||
// List returns a Pager that allows you to iterate over a collection of FloatingIPs.
|
||||
func List(client *gophercloud.ServiceClient) pagination.Pager {
|
||||
return pagination.NewPager(client, listURL(client), func(r pagination.PageResult) pagination.Page {
|
||||
return FloatingIPPage{pagination.SinglePageBase(r)}
|
||||
})
|
||||
}
|
||||
|
||||
// CreateOptsBuilder allows extensions to add additional parameters to the
|
||||
// Create request.
|
||||
type CreateOptsBuilder interface {
|
||||
ToFloatingIPCreateMap() (map[string]interface{}, error)
|
||||
}
|
||||
|
||||
// CreateOpts specifies a Floating IP allocation request.
|
||||
type CreateOpts struct {
|
||||
// Pool is the pool of Floating IPs to allocate one from.
|
||||
Pool string `json:"pool" required:"true"`
|
||||
}
|
||||
|
||||
// ToFloatingIPCreateMap constructs a request body from CreateOpts.
|
||||
func (opts CreateOpts) ToFloatingIPCreateMap() (map[string]interface{}, error) {
|
||||
return gophercloud.BuildRequestBody(opts, "")
|
||||
}
|
||||
|
||||
// Create requests the creation of a new Floating IP.
|
||||
func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) {
|
||||
b, err := opts.ToFloatingIPCreateMap()
|
||||
if err != nil {
|
||||
r.Err = err
|
||||
return
|
||||
}
|
||||
resp, err := client.Post(createURL(client), b, &r.Body, &gophercloud.RequestOpts{
|
||||
OkCodes: []int{200},
|
||||
})
|
||||
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
|
||||
return
|
||||
}
|
||||
|
||||
// Get returns data about a previously created Floating IP.
|
||||
func Get(client *gophercloud.ServiceClient, id string) (r GetResult) {
|
||||
resp, err := client.Get(getURL(client, id), &r.Body, nil)
|
||||
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
|
||||
return
|
||||
}
|
||||
|
||||
// Delete requests the deletion of a previous allocated Floating IP.
|
||||
func Delete(client *gophercloud.ServiceClient, id string) (r DeleteResult) {
|
||||
resp, err := client.Delete(deleteURL(client, id), nil)
|
||||
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
|
||||
return
|
||||
}
|
||||
|
||||
// AssociateOptsBuilder allows extensions to add additional parameters to the
|
||||
// Associate request.
|
||||
type AssociateOptsBuilder interface {
|
||||
ToFloatingIPAssociateMap() (map[string]interface{}, error)
|
||||
}
|
||||
|
||||
// AssociateOpts specifies the required information to associate a Floating IP with an instance
|
||||
type AssociateOpts struct {
|
||||
// FloatingIP is the Floating IP to associate with an instance.
|
||||
FloatingIP string `json:"address" required:"true"`
|
||||
|
||||
// FixedIP is an optional fixed IP address of the server.
|
||||
FixedIP string `json:"fixed_address,omitempty"`
|
||||
}
|
||||
|
||||
// ToFloatingIPAssociateMap constructs a request body from AssociateOpts.
|
||||
func (opts AssociateOpts) ToFloatingIPAssociateMap() (map[string]interface{}, error) {
|
||||
return gophercloud.BuildRequestBody(opts, "addFloatingIp")
|
||||
}
|
||||
|
||||
// AssociateInstance pairs an allocated Floating IP with a server.
|
||||
func AssociateInstance(client *gophercloud.ServiceClient, serverID string, opts AssociateOptsBuilder) (r AssociateResult) {
|
||||
b, err := opts.ToFloatingIPAssociateMap()
|
||||
if err != nil {
|
||||
r.Err = err
|
||||
return
|
||||
}
|
||||
resp, err := client.Post(associateURL(client, serverID), b, nil, nil)
|
||||
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
|
||||
return
|
||||
}
|
||||
|
||||
// DisassociateOptsBuilder allows extensions to add additional parameters to
|
||||
// the Disassociate request.
|
||||
type DisassociateOptsBuilder interface {
|
||||
ToFloatingIPDisassociateMap() (map[string]interface{}, error)
|
||||
}
|
||||
|
||||
// DisassociateOpts specifies the required information to disassociate a
|
||||
// Floating IP with a server.
|
||||
type DisassociateOpts struct {
|
||||
FloatingIP string `json:"address" required:"true"`
|
||||
}
|
||||
|
||||
// ToFloatingIPDisassociateMap constructs a request body from DisassociateOpts.
|
||||
func (opts DisassociateOpts) ToFloatingIPDisassociateMap() (map[string]interface{}, error) {
|
||||
return gophercloud.BuildRequestBody(opts, "removeFloatingIp")
|
||||
}
|
||||
|
||||
// DisassociateInstance decouples an allocated Floating IP from an instance
|
||||
func DisassociateInstance(client *gophercloud.ServiceClient, serverID string, opts DisassociateOptsBuilder) (r DisassociateResult) {
|
||||
b, err := opts.ToFloatingIPDisassociateMap()
|
||||
if err != nil {
|
||||
r.Err = err
|
||||
return
|
||||
}
|
||||
resp, err := client.Post(disassociateURL(client, serverID), b, nil, nil)
|
||||
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
|
||||
return
|
||||
}
|
||||
|
|
@ -1,115 +0,0 @@
|
|||
package floatingips
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strconv"
|
||||
|
||||
"github.com/gophercloud/gophercloud"
|
||||
"github.com/gophercloud/gophercloud/pagination"
|
||||
)
|
||||
|
||||
// A FloatingIP is an IP that can be associated with a server.
|
||||
type FloatingIP struct {
|
||||
// ID is a unique ID of the Floating IP
|
||||
ID string `json:"-"`
|
||||
|
||||
// FixedIP is a specific IP on the server to pair the Floating IP with.
|
||||
FixedIP string `json:"fixed_ip,omitempty"`
|
||||
|
||||
// InstanceID is the ID of the server that is using the Floating IP.
|
||||
InstanceID string `json:"instance_id"`
|
||||
|
||||
// IP is the actual Floating IP.
|
||||
IP string `json:"ip"`
|
||||
|
||||
// Pool is the pool of Floating IPs that this Floating IP belongs to.
|
||||
Pool string `json:"pool"`
|
||||
}
|
||||
|
||||
func (r *FloatingIP) UnmarshalJSON(b []byte) error {
|
||||
type tmp FloatingIP
|
||||
var s struct {
|
||||
tmp
|
||||
ID interface{} `json:"id"`
|
||||
}
|
||||
err := json.Unmarshal(b, &s)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*r = FloatingIP(s.tmp)
|
||||
|
||||
switch t := s.ID.(type) {
|
||||
case float64:
|
||||
r.ID = strconv.FormatFloat(t, 'f', -1, 64)
|
||||
case string:
|
||||
r.ID = t
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// FloatingIPPage stores a single page of FloatingIPs from a List call.
|
||||
type FloatingIPPage struct {
|
||||
pagination.SinglePageBase
|
||||
}
|
||||
|
||||
// IsEmpty determines whether or not a FloatingIPsPage is empty.
|
||||
func (page FloatingIPPage) IsEmpty() (bool, error) {
|
||||
va, err := ExtractFloatingIPs(page)
|
||||
return len(va) == 0, err
|
||||
}
|
||||
|
||||
// ExtractFloatingIPs interprets a page of results as a slice of FloatingIPs.
|
||||
func ExtractFloatingIPs(r pagination.Page) ([]FloatingIP, error) {
|
||||
var s struct {
|
||||
FloatingIPs []FloatingIP `json:"floating_ips"`
|
||||
}
|
||||
err := (r.(FloatingIPPage)).ExtractInto(&s)
|
||||
return s.FloatingIPs, err
|
||||
}
|
||||
|
||||
// FloatingIPResult is the raw result from a FloatingIP request.
|
||||
type FloatingIPResult struct {
|
||||
gophercloud.Result
|
||||
}
|
||||
|
||||
// Extract is a method that attempts to interpret any FloatingIP resource
|
||||
// response as a FloatingIP struct.
|
||||
func (r FloatingIPResult) Extract() (*FloatingIP, error) {
|
||||
var s struct {
|
||||
FloatingIP *FloatingIP `json:"floating_ip"`
|
||||
}
|
||||
err := r.ExtractInto(&s)
|
||||
return s.FloatingIP, err
|
||||
}
|
||||
|
||||
// CreateResult is the response from a Create operation. Call its Extract method
|
||||
// to interpret it as a FloatingIP.
|
||||
type CreateResult struct {
|
||||
FloatingIPResult
|
||||
}
|
||||
|
||||
// GetResult is the response from a Get operation. Call its Extract method to
|
||||
// interpret it as a FloatingIP.
|
||||
type GetResult struct {
|
||||
FloatingIPResult
|
||||
}
|
||||
|
||||
// DeleteResult is the response from a Delete operation. Call its ExtractErr
|
||||
// method to determine if the call succeeded or failed.
|
||||
type DeleteResult struct {
|
||||
gophercloud.ErrResult
|
||||
}
|
||||
|
||||
// AssociateResult is the response from a Delete operation. Call its ExtractErr
|
||||
// method to determine if the call succeeded or failed.
|
||||
type AssociateResult struct {
|
||||
gophercloud.ErrResult
|
||||
}
|
||||
|
||||
// DisassociateResult is the response from a Delete operation. Call its
|
||||
// ExtractErr method to determine if the call succeeded or failed.
|
||||
type DisassociateResult struct {
|
||||
gophercloud.ErrResult
|
||||
}
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
package floatingips
|
||||
|
||||
import "github.com/gophercloud/gophercloud"
|
||||
|
||||
const resourcePath = "os-floating-ips"
|
||||
|
||||
func resourceURL(c *gophercloud.ServiceClient) string {
|
||||
return c.ServiceURL(resourcePath)
|
||||
}
|
||||
|
||||
func listURL(c *gophercloud.ServiceClient) string {
|
||||
return resourceURL(c)
|
||||
}
|
||||
|
||||
func createURL(c *gophercloud.ServiceClient) string {
|
||||
return resourceURL(c)
|
||||
}
|
||||
|
||||
func getURL(c *gophercloud.ServiceClient, id string) string {
|
||||
return c.ServiceURL(resourcePath, id)
|
||||
}
|
||||
|
||||
func deleteURL(c *gophercloud.ServiceClient, id string) string {
|
||||
return getURL(c, id)
|
||||
}
|
||||
|
||||
func serverURL(c *gophercloud.ServiceClient, serverID string) string {
|
||||
return c.ServiceURL("servers/" + serverID + "/action")
|
||||
}
|
||||
|
||||
func associateURL(c *gophercloud.ServiceClient, serverID string) string {
|
||||
return serverURL(c, serverID)
|
||||
}
|
||||
|
||||
func disassociateURL(c *gophercloud.ServiceClient, serverID string) string {
|
||||
return serverURL(c, serverID)
|
||||
}
|
||||
|
|
@ -305,7 +305,6 @@ github.com/gophercloud/gophercloud/openstack
|
|||
github.com/gophercloud/gophercloud/openstack/blockstorage/v3/volumes
|
||||
github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/availabilityzones
|
||||
github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/bootfromvolume
|
||||
github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/floatingips
|
||||
github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/keypairs
|
||||
github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/schedulerhints
|
||||
github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/servergroups
|
||||
|
|
|
|||
Loading…
Reference in New Issue