@@ -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 port_id: ``str``
4313+
43114314 :rtype: ``bool``
43124315 """
43134316 ip_id = None
@@ -4320,13 +4323,16 @@ 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 )
4324- if ports :
4326+ if not port_id :
4327+ ports = self .ex_get_node_ports (node )
4328+ if ports :
4329+ port_id = ports [0 ].id
4330+ if port_id :
43254331 # Set to the first node port
43264332 resp = self .network_connection .request (
43274333 "/v2.0/floatingips/%s" % ip_id ,
43284334 method = "PUT" ,
4329- data = {"floatingip" : {"port_id" : ports [ 0 ]. id }},
4335+ data = {"floatingip" : {"port_id" : port_id }},
43304336 )
43314337 return resp .status == httplib .OK
43324338 else :
0 commit comments