From ba463062ca363bc6626dff80172782a43abe033f Mon Sep 17 00:00:00 2001 From: FengyunPan Date: Tue, 8 Aug 2017 23:29:37 +0800 Subject: [PATCH 1/2] Update gophercloud to support list interfaces of OpenStack instance --- Godeps/Godeps.json | 65 +++--- Godeps/LICENSES | 199 ++++++++++++++++++ pkg/cloudprovider/providers/openstack/BUILD | 1 + .../providers/openstack/openstack.go | 21 ++ .../src/k8s.io/apiserver/Godeps/Godeps.json | 14 +- .../src/k8s.io/client-go/Godeps/Godeps.json | 14 +- .../gophercloud/gophercloud/openstack/BUILD | 1 + .../v2/extensions/attachinterfaces/BUILD | 36 ++++ .../v2/extensions/attachinterfaces/doc.go | 3 + .../extensions/attachinterfaces/requests.go | 13 ++ .../v2/extensions/attachinterfaces/results.go | 43 ++++ .../v2/extensions/attachinterfaces/urls.go | 7 + .../openstack/compute/v2/servers/requests.go | 3 + .../openstack/identity/v2/tenants/requests.go | 78 +++++++ .../openstack/identity/v2/tenants/results.go | 33 +++ .../openstack/identity/v2/tenants/urls.go | 16 ++ .../openstack/identity/v3/tokens/requests.go | 2 +- .../openstack/identity/v3/tokens/results.go | 55 ++++- .../extensions/layer3/floatingips/requests.go | 1 + .../gophercloud/gophercloud/results.go | 47 +++++ 20 files changed, 606 insertions(+), 46 deletions(-) create mode 100644 vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/attachinterfaces/BUILD create mode 100644 vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/attachinterfaces/doc.go create mode 100644 vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/attachinterfaces/requests.go create mode 100644 vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/attachinterfaces/results.go create mode 100644 vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/attachinterfaces/urls.go diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 271f154f560..5ab01233189 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -1577,123 +1577,127 @@ }, { "ImportPath": "github.com/gophercloud/gophercloud", - "Rev": "ed590d9afe113c6107cd60717b196155e6579e78" + "Rev": "c0406a133c4a74a838baf0ddff3c2fab21155fba" }, { "ImportPath": "github.com/gophercloud/gophercloud/openstack", - "Rev": "ed590d9afe113c6107cd60717b196155e6579e78" + "Rev": "c0406a133c4a74a838baf0ddff3c2fab21155fba" }, { "ImportPath": "github.com/gophercloud/gophercloud/openstack/blockstorage/v1/apiversions", - "Rev": "ed590d9afe113c6107cd60717b196155e6579e78" + "Rev": "c0406a133c4a74a838baf0ddff3c2fab21155fba" }, { "ImportPath": "github.com/gophercloud/gophercloud/openstack/blockstorage/v1/volumes", - "Rev": "ed590d9afe113c6107cd60717b196155e6579e78" + "Rev": "c0406a133c4a74a838baf0ddff3c2fab21155fba" }, { "ImportPath": "github.com/gophercloud/gophercloud/openstack/blockstorage/v2/volumes", - "Rev": "ed590d9afe113c6107cd60717b196155e6579e78" + "Rev": "c0406a133c4a74a838baf0ddff3c2fab21155fba" }, { "ImportPath": "github.com/gophercloud/gophercloud/openstack/common/extensions", - "Rev": "ed590d9afe113c6107cd60717b196155e6579e78" + "Rev": "c0406a133c4a74a838baf0ddff3c2fab21155fba" + }, + { + "ImportPath": "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/attachinterfaces", + "Rev": "c0406a133c4a74a838baf0ddff3c2fab21155fba" }, { "ImportPath": "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/volumeattach", - "Rev": "ed590d9afe113c6107cd60717b196155e6579e78" + "Rev": "c0406a133c4a74a838baf0ddff3c2fab21155fba" }, { "ImportPath": "github.com/gophercloud/gophercloud/openstack/compute/v2/flavors", - "Rev": "ed590d9afe113c6107cd60717b196155e6579e78" + "Rev": "c0406a133c4a74a838baf0ddff3c2fab21155fba" }, { "ImportPath": "github.com/gophercloud/gophercloud/openstack/compute/v2/images", - "Rev": "ed590d9afe113c6107cd60717b196155e6579e78" + "Rev": "c0406a133c4a74a838baf0ddff3c2fab21155fba" }, { "ImportPath": "github.com/gophercloud/gophercloud/openstack/compute/v2/servers", - "Rev": "ed590d9afe113c6107cd60717b196155e6579e78" + "Rev": "c0406a133c4a74a838baf0ddff3c2fab21155fba" }, { "ImportPath": "github.com/gophercloud/gophercloud/openstack/identity/v2/tenants", - "Rev": "ed590d9afe113c6107cd60717b196155e6579e78" + "Rev": "c0406a133c4a74a838baf0ddff3c2fab21155fba" }, { "ImportPath": "github.com/gophercloud/gophercloud/openstack/identity/v2/tokens", - "Rev": "ed590d9afe113c6107cd60717b196155e6579e78" + "Rev": "c0406a133c4a74a838baf0ddff3c2fab21155fba" }, { "ImportPath": "github.com/gophercloud/gophercloud/openstack/identity/v3/extensions/trusts", - "Rev": "ed590d9afe113c6107cd60717b196155e6579e78" + "Rev": "c0406a133c4a74a838baf0ddff3c2fab21155fba" }, { "ImportPath": "github.com/gophercloud/gophercloud/openstack/identity/v3/tokens", - "Rev": "ed590d9afe113c6107cd60717b196155e6579e78" + "Rev": "c0406a133c4a74a838baf0ddff3c2fab21155fba" }, { "ImportPath": "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions", - "Rev": "ed590d9afe113c6107cd60717b196155e6579e78" + "Rev": "c0406a133c4a74a838baf0ddff3c2fab21155fba" }, { "ImportPath": "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/floatingips", - "Rev": "ed590d9afe113c6107cd60717b196155e6579e78" + "Rev": "c0406a133c4a74a838baf0ddff3c2fab21155fba" }, { "ImportPath": "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/routers", - "Rev": "ed590d9afe113c6107cd60717b196155e6579e78" + "Rev": "c0406a133c4a74a838baf0ddff3c2fab21155fba" }, { "ImportPath": "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas/members", - "Rev": "ed590d9afe113c6107cd60717b196155e6579e78" + "Rev": "c0406a133c4a74a838baf0ddff3c2fab21155fba" }, { "ImportPath": "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas/monitors", - "Rev": "ed590d9afe113c6107cd60717b196155e6579e78" + "Rev": "c0406a133c4a74a838baf0ddff3c2fab21155fba" }, { "ImportPath": "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas/pools", - "Rev": "ed590d9afe113c6107cd60717b196155e6579e78" + "Rev": "c0406a133c4a74a838baf0ddff3c2fab21155fba" }, { "ImportPath": "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas/vips", - "Rev": "ed590d9afe113c6107cd60717b196155e6579e78" + "Rev": "c0406a133c4a74a838baf0ddff3c2fab21155fba" }, { "ImportPath": "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/listeners", - "Rev": "ed590d9afe113c6107cd60717b196155e6579e78" + "Rev": "c0406a133c4a74a838baf0ddff3c2fab21155fba" }, { "ImportPath": "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/loadbalancers", - "Rev": "ed590d9afe113c6107cd60717b196155e6579e78" + "Rev": "c0406a133c4a74a838baf0ddff3c2fab21155fba" }, { "ImportPath": "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/monitors", - "Rev": "ed590d9afe113c6107cd60717b196155e6579e78" + "Rev": "c0406a133c4a74a838baf0ddff3c2fab21155fba" }, { "ImportPath": "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/lbaas_v2/pools", - "Rev": "ed590d9afe113c6107cd60717b196155e6579e78" + "Rev": "c0406a133c4a74a838baf0ddff3c2fab21155fba" }, { "ImportPath": "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/groups", - "Rev": "ed590d9afe113c6107cd60717b196155e6579e78" + "Rev": "c0406a133c4a74a838baf0ddff3c2fab21155fba" }, { "ImportPath": "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/rules", - "Rev": "ed590d9afe113c6107cd60717b196155e6579e78" + "Rev": "c0406a133c4a74a838baf0ddff3c2fab21155fba" }, { "ImportPath": "github.com/gophercloud/gophercloud/openstack/networking/v2/ports", - "Rev": "ed590d9afe113c6107cd60717b196155e6579e78" + "Rev": "c0406a133c4a74a838baf0ddff3c2fab21155fba" }, { "ImportPath": "github.com/gophercloud/gophercloud/openstack/utils", - "Rev": "ed590d9afe113c6107cd60717b196155e6579e78" + "Rev": "c0406a133c4a74a838baf0ddff3c2fab21155fba" }, { "ImportPath": "github.com/gophercloud/gophercloud/pagination", - "Rev": "ed590d9afe113c6107cd60717b196155e6579e78" + "Rev": "c0406a133c4a74a838baf0ddff3c2fab21155fba" }, { "ImportPath": "github.com/gorilla/context", @@ -1802,6 +1806,7 @@ }, { "ImportPath": "github.com/inconshreveable/mousetrap", + "Comment": "v1.0", "Rev": "76626ae9c91c4f2a10f34cad8ce83ea42c93bb75" }, { diff --git a/Godeps/LICENSES b/Godeps/LICENSES index 5911292ad9c..b5c59d6a434 100644 --- a/Godeps/LICENSES +++ b/Godeps/LICENSES @@ -54565,6 +54565,205 @@ specific language governing permissions and limitations under the License. ================================================================================ +================================================================================ += vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/attachinterfaces licensed under: = + +Copyright 2012-2013 Rackspace, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); you may not use +this file except in compliance with the License. You may obtain a copy of the +License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software distributed +under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR +CONDITIONS OF ANY KIND, either express or implied. See the License for the +specific language governing permissions and limitations under the License. + +------ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + += vendor/github.com/gophercloud/gophercloud/LICENSE dd19699707373c2ca31531a659130416 - +================================================================================ + + ================================================================================ = vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/volumeattach licensed under: = diff --git a/pkg/cloudprovider/providers/openstack/BUILD b/pkg/cloudprovider/providers/openstack/BUILD index a3eff15c99c..147620a9c9c 100644 --- a/pkg/cloudprovider/providers/openstack/BUILD +++ b/pkg/cloudprovider/providers/openstack/BUILD @@ -34,6 +34,7 @@ go_library( "//vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v1/apiversions:go_default_library", "//vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v1/volumes:go_default_library", "//vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v2/volumes:go_default_library", + "//vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/attachinterfaces:go_default_library", "//vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/volumeattach:go_default_library", "//vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/servers:go_default_library", "//vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/extensions/trusts:go_default_library", diff --git a/pkg/cloudprovider/providers/openstack/openstack.go b/pkg/cloudprovider/providers/openstack/openstack.go index 15993f6f910..9510dbd9520 100644 --- a/pkg/cloudprovider/providers/openstack/openstack.go +++ b/pkg/cloudprovider/providers/openstack/openstack.go @@ -31,6 +31,7 @@ import ( "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack" apiversions_v1 "github.com/gophercloud/gophercloud/openstack/blockstorage/v1/apiversions" + "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/attachinterfaces" "github.com/gophercloud/gophercloud/openstack/compute/v2/servers" "github.com/gophercloud/gophercloud/openstack/identity/v3/extensions/trusts" tokens3 "github.com/gophercloud/gophercloud/openstack/identity/v3/tokens" @@ -444,6 +445,26 @@ func getAddressByName(client *gophercloud.ServiceClient, name types.NodeName) (s return addrs[0].Address, nil } +// getAttachedInterfacesByID returns the node interfaces of the specified instance. +func getAttachedInterfacesByID(client *gophercloud.ServiceClient, serviceID string) ([]attachinterfaces.Interface, error) { + var interfaces []attachinterfaces.Interface + + pager := attachinterfaces.List(client, serviceID) + err := pager.EachPage(func(page pagination.Page) (bool, error) { + s, err := attachinterfaces.ExtractInterfaces(page) + if err != nil { + return false, err + } + interfaces = append(interfaces, s...) + return true, nil + }) + if err != nil { + return interfaces, err + } + + return interfaces, nil +} + func (os *OpenStack) Clusters() (cloudprovider.Clusters, bool) { return nil, false } diff --git a/staging/src/k8s.io/apiserver/Godeps/Godeps.json b/staging/src/k8s.io/apiserver/Godeps/Godeps.json index a526d8d83dc..123f5c9918e 100644 --- a/staging/src/k8s.io/apiserver/Godeps/Godeps.json +++ b/staging/src/k8s.io/apiserver/Godeps/Godeps.json @@ -404,31 +404,31 @@ }, { "ImportPath": "github.com/gophercloud/gophercloud", - "Rev": "ed590d9afe113c6107cd60717b196155e6579e78" + "Rev": "c0406a133c4a74a838baf0ddff3c2fab21155fba" }, { "ImportPath": "github.com/gophercloud/gophercloud/openstack", - "Rev": "ed590d9afe113c6107cd60717b196155e6579e78" + "Rev": "c0406a133c4a74a838baf0ddff3c2fab21155fba" }, { "ImportPath": "github.com/gophercloud/gophercloud/openstack/identity/v2/tenants", - "Rev": "ed590d9afe113c6107cd60717b196155e6579e78" + "Rev": "c0406a133c4a74a838baf0ddff3c2fab21155fba" }, { "ImportPath": "github.com/gophercloud/gophercloud/openstack/identity/v2/tokens", - "Rev": "ed590d9afe113c6107cd60717b196155e6579e78" + "Rev": "c0406a133c4a74a838baf0ddff3c2fab21155fba" }, { "ImportPath": "github.com/gophercloud/gophercloud/openstack/identity/v3/tokens", - "Rev": "ed590d9afe113c6107cd60717b196155e6579e78" + "Rev": "c0406a133c4a74a838baf0ddff3c2fab21155fba" }, { "ImportPath": "github.com/gophercloud/gophercloud/openstack/utils", - "Rev": "ed590d9afe113c6107cd60717b196155e6579e78" + "Rev": "c0406a133c4a74a838baf0ddff3c2fab21155fba" }, { "ImportPath": "github.com/gophercloud/gophercloud/pagination", - "Rev": "ed590d9afe113c6107cd60717b196155e6579e78" + "Rev": "c0406a133c4a74a838baf0ddff3c2fab21155fba" }, { "ImportPath": "github.com/grpc-ecosystem/go-grpc-prometheus", diff --git a/staging/src/k8s.io/client-go/Godeps/Godeps.json b/staging/src/k8s.io/client-go/Godeps/Godeps.json index c72a9d07672..5e68697cc6c 100644 --- a/staging/src/k8s.io/client-go/Godeps/Godeps.json +++ b/staging/src/k8s.io/client-go/Godeps/Godeps.json @@ -172,31 +172,31 @@ }, { "ImportPath": "github.com/gophercloud/gophercloud", - "Rev": "ed590d9afe113c6107cd60717b196155e6579e78" + "Rev": "c0406a133c4a74a838baf0ddff3c2fab21155fba" }, { "ImportPath": "github.com/gophercloud/gophercloud/openstack", - "Rev": "ed590d9afe113c6107cd60717b196155e6579e78" + "Rev": "c0406a133c4a74a838baf0ddff3c2fab21155fba" }, { "ImportPath": "github.com/gophercloud/gophercloud/openstack/identity/v2/tenants", - "Rev": "ed590d9afe113c6107cd60717b196155e6579e78" + "Rev": "c0406a133c4a74a838baf0ddff3c2fab21155fba" }, { "ImportPath": "github.com/gophercloud/gophercloud/openstack/identity/v2/tokens", - "Rev": "ed590d9afe113c6107cd60717b196155e6579e78" + "Rev": "c0406a133c4a74a838baf0ddff3c2fab21155fba" }, { "ImportPath": "github.com/gophercloud/gophercloud/openstack/identity/v3/tokens", - "Rev": "ed590d9afe113c6107cd60717b196155e6579e78" + "Rev": "c0406a133c4a74a838baf0ddff3c2fab21155fba" }, { "ImportPath": "github.com/gophercloud/gophercloud/openstack/utils", - "Rev": "ed590d9afe113c6107cd60717b196155e6579e78" + "Rev": "c0406a133c4a74a838baf0ddff3c2fab21155fba" }, { "ImportPath": "github.com/gophercloud/gophercloud/pagination", - "Rev": "ed590d9afe113c6107cd60717b196155e6579e78" + "Rev": "c0406a133c4a74a838baf0ddff3c2fab21155fba" }, { "ImportPath": "github.com/hashicorp/golang-lru", diff --git a/vendor/github.com/gophercloud/gophercloud/openstack/BUILD b/vendor/github.com/gophercloud/gophercloud/openstack/BUILD index 9b80a679a6e..6203609ba6b 100644 --- a/vendor/github.com/gophercloud/gophercloud/openstack/BUILD +++ b/vendor/github.com/gophercloud/gophercloud/openstack/BUILD @@ -39,6 +39,7 @@ filegroup( "//vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v1/volumes:all-srcs", "//vendor/github.com/gophercloud/gophercloud/openstack/blockstorage/v2/volumes:all-srcs", "//vendor/github.com/gophercloud/gophercloud/openstack/common/extensions:all-srcs", + "//vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/attachinterfaces:all-srcs", "//vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/volumeattach:all-srcs", "//vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/flavors:all-srcs", "//vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/images:all-srcs", diff --git a/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/attachinterfaces/BUILD b/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/attachinterfaces/BUILD new file mode 100644 index 00000000000..bb8bf4e650d --- /dev/null +++ b/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/attachinterfaces/BUILD @@ -0,0 +1,36 @@ +package(default_visibility = ["//visibility:public"]) + +licenses(["notice"]) + +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", + ], + tags = ["automanaged"], + deps = [ + "//vendor/github.com/gophercloud/gophercloud:go_default_library", + "//vendor/github.com/gophercloud/gophercloud/pagination:go_default_library", + ], +) + +filegroup( + name = "package-srcs", + srcs = glob(["**"]), + tags = ["automanaged"], + visibility = ["//visibility:private"], +) + +filegroup( + name = "all-srcs", + srcs = [":package-srcs"], + tags = ["automanaged"], +) diff --git a/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/attachinterfaces/doc.go b/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/attachinterfaces/doc.go new file mode 100644 index 00000000000..2ef30db869e --- /dev/null +++ b/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/attachinterfaces/doc.go @@ -0,0 +1,3 @@ +// Package attachinterfaces provides the ability to manage network interfaces through +// nova-network +package attachinterfaces diff --git a/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/attachinterfaces/requests.go b/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/attachinterfaces/requests.go new file mode 100644 index 00000000000..76cc879630d --- /dev/null +++ b/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/attachinterfaces/requests.go @@ -0,0 +1,13 @@ +package attachinterfaces + +import ( + "github.com/gophercloud/gophercloud" + "github.com/gophercloud/gophercloud/pagination" +) + +// List makes a request against the nova API to list the servers interfaces. +func List(client *gophercloud.ServiceClient, serverID string) pagination.Pager { + return pagination.NewPager(client, listInterfaceURL(client, serverID), func(r pagination.PageResult) pagination.Page { + return InterfacePage{pagination.SinglePageBase(r)} + }) +} diff --git a/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/attachinterfaces/results.go b/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/attachinterfaces/results.go new file mode 100644 index 00000000000..776ad8305b8 --- /dev/null +++ b/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/attachinterfaces/results.go @@ -0,0 +1,43 @@ +package attachinterfaces + +import ( + "github.com/gophercloud/gophercloud/pagination" +) + +// FixedIP represents a Fixed IP Address. +type FixedIP struct { + SubnetID string `json:"subnet_id"` + IPAddress string `json:"ip_address"` +} + +// Interface represents a network interface on an instance. +type Interface struct { + PortState string `json:"port_state"` + FixedIPs []FixedIP `json:"fixed_ips"` + PortID string `json:"port_id"` + NetID string `json:"net_id"` + MACAddr string `json:"mac_addr"` +} + +// InterfacePage abstracts the raw results of making a List() request against the API. +// As OpenStack extensions may freely alter the response bodies of structures returned +// to the client, you may only safely access the data provided through the ExtractInterfaces call. +type InterfacePage struct { + pagination.SinglePageBase +} + +// IsEmpty returns true if an InterfacePage contains no interfaces. +func (r InterfacePage) IsEmpty() (bool, error) { + interfaces, err := ExtractInterfaces(r) + return len(interfaces) == 0, err +} + +// ExtractInterfaces interprets the results of a single page from a List() call, +// producing a map of interfaces. +func ExtractInterfaces(r pagination.Page) ([]Interface, error) { + var s struct { + Interfaces []Interface `json:"interfaceAttachments"` + } + err := (r.(InterfacePage)).ExtractInto(&s) + return s.Interfaces, err +} diff --git a/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/attachinterfaces/urls.go b/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/attachinterfaces/urls.go new file mode 100644 index 00000000000..7d376f99bb5 --- /dev/null +++ b/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/attachinterfaces/urls.go @@ -0,0 +1,7 @@ +package attachinterfaces + +import "github.com/gophercloud/gophercloud" + +func listInterfaceURL(client *gophercloud.ServiceClient, serverID string) string { + return client.ServiceURL("servers", serverID, "os-interface") +} diff --git a/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/servers/requests.go b/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/servers/requests.go index 96186373176..1a7b3ec77ed 100644 --- a/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/servers/requests.go +++ b/vendor/github.com/gophercloud/gophercloud/openstack/compute/v2/servers/requests.go @@ -50,6 +50,9 @@ type ListOpts struct { // Bool to show all tenants AllTenants bool `q:"all_tenants"` + + // List servers for a particular tenant. Setting "AllTenants = true" is required. + TenantID string `q:"tenant_id"` } // ToServerListQuery formats a ListOpts into a query string. diff --git a/vendor/github.com/gophercloud/gophercloud/openstack/identity/v2/tenants/requests.go b/vendor/github.com/gophercloud/gophercloud/openstack/identity/v2/tenants/requests.go index b9d7de65fac..b6550ce60d2 100644 --- a/vendor/github.com/gophercloud/gophercloud/openstack/identity/v2/tenants/requests.go +++ b/vendor/github.com/gophercloud/gophercloud/openstack/identity/v2/tenants/requests.go @@ -27,3 +27,81 @@ func List(client *gophercloud.ServiceClient, opts *ListOpts) pagination.Pager { return TenantPage{pagination.LinkedPageBase{PageResult: r}} }) } + +// CreateOpts represents the options needed when creating new tenant. +type CreateOpts struct { + // Name is the name of the tenant. + Name string `json:"name" required:"true"` + // Description is the description of the tenant. + Description string `json:"description,omitempty"` + // Enabled sets the tenant status to enabled or disabled. + Enabled *bool `json:"enabled,omitempty"` +} + +// CreateOptsBuilder describes struct types that can be accepted by the Create call. +type CreateOptsBuilder interface { + ToTenantCreateMap() (map[string]interface{}, error) +} + +// ToTenantCreateMap assembles a request body based on the contents of a CreateOpts. +func (opts CreateOpts) ToTenantCreateMap() (map[string]interface{}, error) { + return gophercloud.BuildRequestBody(opts, "tenant") +} + +// Create is the operation responsible for creating new tenant. +func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) { + b, err := opts.ToTenantCreateMap() + if err != nil { + r.Err = err + return + } + _, r.Err = client.Post(createURL(client), b, &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{200, 201}, + }) + return +} + +// Get requests details on a single tenant by ID. +func Get(client *gophercloud.ServiceClient, id string) (r GetResult) { + _, r.Err = client.Get(getURL(client, id), &r.Body, nil) + return +} + +// UpdateOptsBuilder allows extensions to add additional attributes to the Update request. +type UpdateOptsBuilder interface { + ToTenantUpdateMap() (map[string]interface{}, error) +} + +// UpdateOpts specifies the base attributes that may be updated on an existing server. +type UpdateOpts struct { + // Name is the name of the tenant. + Name string `json:"name,omitempty"` + // Description is the description of the tenant. + Description string `json:"description,omitempty"` + // Enabled sets the tenant status to enabled or disabled. + Enabled *bool `json:"enabled,omitempty"` +} + +// ToTenantUpdateMap formats an UpdateOpts structure into a request body. +func (opts UpdateOpts) ToTenantUpdateMap() (map[string]interface{}, error) { + return gophercloud.BuildRequestBody(opts, "tenant") +} + +// Update is the operation responsible for updating exist tenants by their TenantID. +func Update(client *gophercloud.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) { + b, err := opts.ToTenantUpdateMap() + if err != nil { + r.Err = err + return + } + _, r.Err = client.Put(updateURL(client, id), &b, &r.Body, &gophercloud.RequestOpts{ + OkCodes: []int{200}, + }) + return +} + +// Delete is the operation responsible for permanently deleting an API tenant. +func Delete(client *gophercloud.ServiceClient, id string) (r DeleteResult) { + _, r.Err = client.Delete(deleteURL(client, id), nil) + return +} diff --git a/vendor/github.com/gophercloud/gophercloud/openstack/identity/v2/tenants/results.go b/vendor/github.com/gophercloud/gophercloud/openstack/identity/v2/tenants/results.go index 3ce1e677367..5a319de5cbe 100644 --- a/vendor/github.com/gophercloud/gophercloud/openstack/identity/v2/tenants/results.go +++ b/vendor/github.com/gophercloud/gophercloud/openstack/identity/v2/tenants/results.go @@ -51,3 +51,36 @@ func ExtractTenants(r pagination.Page) ([]Tenant, error) { err := (r.(TenantPage)).ExtractInto(&s) return s.Tenants, err } + +type tenantResult struct { + gophercloud.Result +} + +// Extract interprets any tenantResults as a tenant. +func (r tenantResult) Extract() (*Tenant, error) { + var s struct { + Tenant *Tenant `json:"tenant"` + } + err := r.ExtractInto(&s) + return s.Tenant, err +} + +// GetResult temporarily contains the response from the Get call. +type GetResult struct { + tenantResult +} + +// CreateResult temporarily contains the reponse from the Create call. +type CreateResult struct { + tenantResult +} + +// DeleteResult temporarily contains the response from the Delete call. +type DeleteResult struct { + gophercloud.ErrResult +} + +// UpdateResult temporarily contains the response from the Update call. +type UpdateResult struct { + tenantResult +} diff --git a/vendor/github.com/gophercloud/gophercloud/openstack/identity/v2/tenants/urls.go b/vendor/github.com/gophercloud/gophercloud/openstack/identity/v2/tenants/urls.go index 101599bc94b..0f026690790 100644 --- a/vendor/github.com/gophercloud/gophercloud/openstack/identity/v2/tenants/urls.go +++ b/vendor/github.com/gophercloud/gophercloud/openstack/identity/v2/tenants/urls.go @@ -5,3 +5,19 @@ import "github.com/gophercloud/gophercloud" func listURL(client *gophercloud.ServiceClient) string { return client.ServiceURL("tenants") } + +func getURL(client *gophercloud.ServiceClient, tenantID string) string { + return client.ServiceURL("tenants", tenantID) +} + +func createURL(client *gophercloud.ServiceClient) string { + return client.ServiceURL("tenants") +} + +func deleteURL(client *gophercloud.ServiceClient, tenantID string) string { + return client.ServiceURL("tenants", tenantID) +} + +func updateURL(client *gophercloud.ServiceClient, tenantID string) string { + return client.ServiceURL("tenants", tenantID) +} diff --git a/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/tokens/requests.go b/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/tokens/requests.go index 95cef43cbb7..39c19aee3cd 100644 --- a/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/tokens/requests.go +++ b/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/tokens/requests.go @@ -182,7 +182,7 @@ func Get(c *gophercloud.ServiceClient, token string) (r GetResult) { func Validate(c *gophercloud.ServiceClient, token string) (bool, error) { resp, err := c.Request("HEAD", tokenURL(c), &gophercloud.RequestOpts{ MoreHeaders: subjectTokenHeaders(c, token), - OkCodes: []int{200, 204, 400, 401, 403, 404}, + OkCodes: []int{200, 204, 404}, }) if err != nil { return false, err diff --git a/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/tokens/results.go b/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/tokens/results.go index 0f1e8c2ba76..7c306e83feb 100644 --- a/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/tokens/results.go +++ b/vendor/github.com/gophercloud/gophercloud/openstack/identity/v3/tokens/results.go @@ -41,6 +41,32 @@ type ServiceCatalog struct { Entries []CatalogEntry `json:"catalog"` } +// Domain provides information about the domain to which this token grants access. +type Domain struct { + ID string `json:"id"` + Name string `json:"name"` +} + +// User represents a user resource that exists on the API. +type User struct { + Domain Domain `json:"domain"` + ID string `json:"id"` + Name string `json:"name"` +} + +// Role provides information about roles to which User is authorized. +type Role struct { + ID string `json:"id"` + Name string `json:"name"` +} + +// Project provides information about project to which User is authorized. +type Project struct { + Domain Domain `json:"domain"` + ID string `json:"id"` + Name string `json:"name"` +} + // commonResult is the deferred result of a Create or a Get call. type commonResult struct { gophercloud.Result @@ -67,12 +93,39 @@ func (r commonResult) ExtractToken() (*Token, error) { } // ExtractServiceCatalog returns the ServiceCatalog that was generated along with the user's Token. -func (r CreateResult) ExtractServiceCatalog() (*ServiceCatalog, error) { +func (r commonResult) ExtractServiceCatalog() (*ServiceCatalog, error) { var s ServiceCatalog err := r.ExtractInto(&s) return &s, err } +// ExtractUser returns the User that is the owner of the Token. +func (r commonResult) ExtractUser() (*User, error) { + var s struct { + User *User `json:"user"` + } + err := r.ExtractInto(&s) + return s.User, err +} + +// ExtractRoles returns Roles to which User is authorized. +func (r commonResult) ExtractRoles() ([]Role, error) { + var s struct { + Roles []Role `json:"roles"` + } + err := r.ExtractInto(&s) + return s.Roles, err +} + +// ExtractProject returns Project to which User is authorized. +func (r commonResult) ExtractProject() (*Project, error) { + var s struct { + Project *Project `json:"project"` + } + err := r.ExtractInto(&s) + return s.Project, err +} + // CreateResult defers the interpretation of a created token. // Use ExtractToken() to interpret it as a Token, or ExtractServiceCatalog() to interpret it as a service catalog. type CreateResult struct { diff --git a/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/floatingips/requests.go b/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/floatingips/requests.go index 83930874c5d..0c628426c0f 100644 --- a/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/floatingips/requests.go +++ b/vendor/github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/floatingips/requests.go @@ -22,6 +22,7 @@ type ListOpts struct { SortKey string `q:"sort_key"` SortDir string `q:"sort_dir"` RouterID string `q:"router_id"` + Status string `q:"status"` } // List returns a Pager which allows you to iterate over a collection of diff --git a/vendor/github.com/gophercloud/gophercloud/results.go b/vendor/github.com/gophercloud/gophercloud/results.go index 76c16ef8ff6..6a5b0baaa67 100644 --- a/vendor/github.com/gophercloud/gophercloud/results.go +++ b/vendor/github.com/gophercloud/gophercloud/results.go @@ -78,6 +78,53 @@ func (r Result) extractIntoPtr(to interface{}, label string) error { return err } + toValue := reflect.ValueOf(to) + if toValue.Kind() == reflect.Ptr { + toValue = toValue.Elem() + } + + switch toValue.Kind() { + case reflect.Slice: + typeOfV := toValue.Type().Elem() + if typeOfV.Kind() == reflect.Struct { + if typeOfV.NumField() > 0 && typeOfV.Field(0).Anonymous { + newSlice := reflect.MakeSlice(reflect.SliceOf(typeOfV), 0, 0) + newType := reflect.New(typeOfV).Elem() + + for _, v := range m[label].([]interface{}) { + b, err := json.Marshal(v) + if err != nil { + return err + } + + for i := 0; i < newType.NumField(); i++ { + s := newType.Field(i).Addr().Interface() + err = json.NewDecoder(bytes.NewReader(b)).Decode(s) + if err != nil { + return err + } + } + newSlice = reflect.Append(newSlice, newType) + } + toValue.Set(newSlice) + } + } + case reflect.Struct: + typeOfV := toValue.Type() + if typeOfV.NumField() > 0 && typeOfV.Field(0).Anonymous { + for i := 0; i < toValue.NumField(); i++ { + toField := toValue.Field(i) + if toField.Kind() == reflect.Struct { + s := toField.Addr().Interface() + err = json.NewDecoder(bytes.NewReader(b)).Decode(s) + if err != nil { + return err + } + } + } + } + } + err = json.Unmarshal(b, &to) return err } From 6aa7c47480525383d31bcef1d0498fe479972e2e Mon Sep 17 00:00:00 2001 From: FengyunPan Date: Tue, 8 Aug 2017 23:32:59 +0800 Subject: [PATCH 2/2] Fix conflict about getPortByIp Currently getPortByIp() get port of instance only based on IP. If there are two instances in diffent network and the CIDR of their subnet are same, getPortByIp() will be conflict. My PR gets port based on IP and Name of instance. --- .../openstack/openstack_loadbalancer.go | 28 ---------- .../providers/openstack/openstack_routes.go | 53 +++++++++++++++++-- 2 files changed, 49 insertions(+), 32 deletions(-) diff --git a/pkg/cloudprovider/providers/openstack/openstack_loadbalancer.go b/pkg/cloudprovider/providers/openstack/openstack_loadbalancer.go index ca085890009..50948bb9809 100644 --- a/pkg/cloudprovider/providers/openstack/openstack_loadbalancer.go +++ b/pkg/cloudprovider/providers/openstack/openstack_loadbalancer.go @@ -100,34 +100,6 @@ func networkExtensions(client *gophercloud.ServiceClient) (map[string]bool, erro return seen, err } -func getPortByIP(client *gophercloud.ServiceClient, ipAddress string) (neutronports.Port, error) { - var targetPort neutronports.Port - var portFound = false - - err := neutronports.List(client, neutronports.ListOpts{}).EachPage(func(page pagination.Page) (bool, error) { - portList, err := neutronports.ExtractPorts(page) - if err != nil { - return false, err - } - - for _, port := range portList { - for _, ip := range port.FixedIPs { - if ip.IPAddress == ipAddress { - targetPort = port - portFound = true - return false, nil - } - } - } - - return true, nil - }) - if err == nil && !portFound { - err = ErrNotFound - } - return targetPort, err -} - func getFloatingIPByPortID(client *gophercloud.ServiceClient, portID string) (*floatingips.FloatingIP, error) { opts := floatingips.ListOpts{ PortID: portID, diff --git a/pkg/cloudprovider/providers/openstack/openstack_routes.go b/pkg/cloudprovider/providers/openstack/openstack_routes.go index 2cb0cd95ff0..e999f5eb5ae 100644 --- a/pkg/cloudprovider/providers/openstack/openstack_routes.go +++ b/pkg/cloudprovider/providers/openstack/openstack_routes.go @@ -177,7 +177,12 @@ func (r *Routes) CreateRoute(clusterName string, nameHint string, route *cloudpr } defer onFailure.Call(unwind) - port, err := getPortByIP(r.network, addr) + // get the port of addr on target node. + portID, err := getPortIDByIP(r.compute, route.TargetNode, addr) + if err != nil { + return err + } + port, err := getPortByID(r.network, portID) if err != nil { return err } @@ -195,7 +200,7 @@ func (r *Routes) CreateRoute(clusterName string, nameHint string, route *cloudpr newPairs := append(port.AllowedAddressPairs, neutronports.AddressPair{ IPAddress: route.DestinationCIDR, }) - unwind, err := updateAllowedAddressPairs(r.network, &port, newPairs) + unwind, err := updateAllowedAddressPairs(r.network, port, newPairs) if err != nil { return err } @@ -246,7 +251,12 @@ func (r *Routes) DeleteRoute(clusterName string, route *cloudprovider.Route) err } defer onFailure.Call(unwind) - port, err := getPortByIP(r.network, addr) + // get the port of addr on target node. + portID, err := getPortIDByIP(r.compute, route.TargetNode, addr) + if err != nil { + return err + } + port, err := getPortByID(r.network, portID) if err != nil { return err } @@ -265,7 +275,7 @@ func (r *Routes) DeleteRoute(clusterName string, route *cloudprovider.Route) err addr_pairs[index] = addr_pairs[len(addr_pairs)-1] addr_pairs = addr_pairs[:len(addr_pairs)-1] - unwind, err := updateAllowedAddressPairs(r.network, &port, addr_pairs) + unwind, err := updateAllowedAddressPairs(r.network, port, addr_pairs) if err != nil { return err } @@ -276,3 +286,38 @@ func (r *Routes) DeleteRoute(clusterName string, route *cloudprovider.Route) err onFailure.Disarm() return nil } + +func getPortIDByIP(compute *gophercloud.ServiceClient, targetNode types.NodeName, ipAddress string) (string, error) { + srv, err := getServerByName(compute, targetNode) + if err != nil { + return "", err + } + + interfaces, err := getAttachedInterfacesByID(compute, srv.ID) + if err != nil { + return "", err + } + + for _, intf := range interfaces { + for _, fixedIP := range intf.FixedIPs { + if fixedIP.IPAddress == ipAddress { + return intf.PortID, nil + } + } + } + + return "", ErrNotFound +} + +func getPortByID(client *gophercloud.ServiceClient, portID string) (*neutronports.Port, error) { + targetPort, err := neutronports.Get(client, portID).Extract() + if err != nil { + return nil, err + } + + if targetPort == nil { + return nil, ErrNotFound + } + + return targetPort, nil +}