Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable to specify port in OpenStack ex_attach_floating_ip_to_node #2027 #2028

Open
wants to merge 4 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ Common
Compute
~~~~~~~

- [OpenStack] Add optional node port ID to attach the floating IP in OpenStack
ex_attach_floating_ip_to_node function.
(#2028)
[Miguel Caballer - @micafer]

- [OpenStack] Add metadata fields ``os_distro`` and ``os_version`` provided
by OpenStack Image API (if set) to the ``extra`` field of the OpenStack NodeImage.
(#1982)
Expand Down
14 changes: 10 additions & 4 deletions libcloud/compute/drivers/openstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -4298,7 +4298,7 @@ def ex_delete_floating_ip(self, ip):
resp = self.network_connection.request("/v2.0/floatingips/%s" % ip.id, method="DELETE")
return resp.status in (httplib.NO_CONTENT, httplib.ACCEPTED)

def ex_attach_floating_ip_to_node(self, node, ip):
def ex_attach_floating_ip_to_node(self, node, ip, port_id=None):
"""
Attach the floating IP to the node

Expand All @@ -4308,6 +4308,9 @@ def ex_attach_floating_ip_to_node(self, node, ip):
:param ip: floating IP to attach
:type ip: ``str`` or :class:`OpenStack_1_1_FloatingIpAddress`

:param port_id: Optional node port ID to attach the floating IP
:type ip: ``str``

:rtype: ``bool``
"""
ip_id = None
Expand All @@ -4320,13 +4323,16 @@ def ex_attach_floating_ip_to_node(self, node, ip):
ip_id = fip.id
if not ip_id:
return False
ports = self.ex_get_node_ports(node)
if ports:
if not port_id:
ports = self.ex_get_node_ports(node)
if ports:
port_id = ports[0].id
if port_id:
# Set to the first node port
resp = self.network_connection.request(
"/v2.0/floatingips/%s" % ip_id,
method="PUT",
data={"floatingip": {"port_id": ports[0].id}},
data={"floatingip": {"port_id": port_id}},
)
return resp.status == httplib.OK
else:
Expand Down
10 changes: 10 additions & 0 deletions libcloud/test/compute/test_openstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -2547,6 +2547,16 @@ def test_ex_delete_floating_ip(self):
ip = OpenStack_1_1_FloatingIpAddress("foo-bar-id", "42.42.42.42", None)
self.assertTrue(self.driver.ex_delete_floating_ip(ip))

def test_ex_attach_floating_ip_to_node(self):
image = NodeImage(id=11, name="Ubuntu 8.10 (intrepid)", driver=self.driver)
size = NodeSize(1, "256 slice", None, None, None, None, driver=self.driver)
node = self.driver.create_node(name="racktest", image=image, size=size)
node.id = 4242
ip = "42.42.42.42"
port_id = "ce531f90-199f-48c0-816c-13e38010b442"

self.assertTrue(self.driver.ex_attach_floating_ip_to_node(node, ip, port_id))


class OpenStack_1_1_FactoryMethodTests(OpenStack_1_1_Tests):
should_list_locations = False
Expand Down