Skip to content

Commit 44e9945

Browse files
committed
implements #2027
1 parent 1ebd605 commit 44e9945

3 files changed

Lines changed: 15 additions & 3 deletions

File tree

CHANGES.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ Common
2828
Compute
2929
~~~~~~~
3030

31+
- [OpenStack] Optional node port ID to attach the floating IP in OpenStack
32+
ex_attach_floating_ip_to_node function.
33+
(#2028)
34+
[Miguel Caballer - @micafer]
35+
3136
- [OpenStack] Add metadata fields ``os_distro`` and ``os_version`` provided
3237
by OpenStack Image API (if set) to the ``extra`` field of the OpenStack NodeImage.
3338
(#1982)

libcloud/compute/drivers/openstack.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4298,7 +4298,7 @@ def ex_delete_floating_ip(self, ip):
42984298
resp = self.network_connection.request("/v2.0/floatingips/%s" % ip.id, method="DELETE")
42994299
return resp.status in (httplib.NO_CONTENT, httplib.ACCEPTED)
43004300

4301-
def ex_attach_floating_ip_to_node(self, node, ip):
4301+
def ex_attach_floating_ip_to_node(self, node, ip, port_id=None):
43024302
"""
43034303
Attach the floating IP to the node
43044304
@@ -4308,6 +4308,9 @@ def ex_attach_floating_ip_to_node(self, node, ip):
43084308
:param ip: floating IP to attach
43094309
:type ip: ``str`` or :class:`OpenStack_1_1_FloatingIpAddress`
43104310
4311+
:param port_id: Optional node port ID to attach the floating IP
4312+
:type ip: ``str``
4313+
43114314
:rtype: ``bool``
43124315
"""
43134316
ip_id = None
@@ -4320,13 +4323,15 @@ def ex_attach_floating_ip_to_node(self, node, ip):
43204323
ip_id = fip.id
43214324
if not ip_id:
43224325
return False
4323-
ports = self.ex_get_node_ports(node)
4326+
if not port_id:
4327+
ports = self.ex_get_node_ports(node)
4328+
port_id = ports[0].id
43244329
if ports:
43254330
# Set to the first node port
43264331
resp = self.network_connection.request(
43274332
"/v2.0/floatingips/%s" % ip_id,
43284333
method="PUT",
4329-
data={"floatingip": {"port_id": ports[0].id}},
4334+
data={"floatingip": {"port_id": port_id}},
43304335
)
43314336
return resp.status == httplib.OK
43324337
else:

libcloud/test/compute/test_openstack.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1677,8 +1677,10 @@ def test_ex_attach_floating_ip_to_node(self):
16771677
node = self.driver.create_node(name="racktest", image=image, size=size)
16781678
node.id = 4242
16791679
ip = "42.42.42.42"
1680+
port_id = 'ce531f90-199f-48c0-816c-13e38010b442'
16801681

16811682
self.assertTrue(self.driver.ex_attach_floating_ip_to_node(node, ip))
1683+
self.assertTrue(self.driver.ex_attach_floating_ip_to_node(node, ip, port_id))
16821684

16831685
def test_detach_floating_ip_from_node(self):
16841686
image = NodeImage(id=11, name="Ubuntu 8.10 (intrepid)", driver=self.driver)

0 commit comments

Comments
 (0)