Skip to content

Fixes the function ex_create_floating_ip for Openstack#725

Closed
marko-p wants to merge 3 commits into
apache:trunkfrom
marko-p:trunk
Closed

Fixes the function ex_create_floating_ip for Openstack#725
marko-p wants to merge 3 commits into
apache:trunkfrom
marko-p:trunk

Conversation

@marko-p
Copy link
Copy Markdown

@marko-p marko-p commented Mar 21, 2016

I'm not sure if this function is supported or not (floating_ip_pool.create_floating_ip is working), but I fixed it since it is the only documented function for creating floating IPs on http://libcloud.readthedocs.org/en/latest/compute/drivers/openstack.html ... and I fixed it before I found the "floating_ip_pool.create_floating_ip" function.

@tonybaloney
Copy link
Copy Markdown
Contributor

hi @marko-p thanks for the contribution. I was just looking at the docs and it says that pool is optional http://developer.openstack.org/api-ref-compute-v2.1.html#createFloatingIP please can you extend the logic to support pool as an optional argument, this will also support existing users of the method.

…ng_ip. This is useful in case there is only one IP pool available.
@marko-p
Copy link
Copy Markdown
Author

marko-p commented Mar 21, 2016

Thanks for such a quick reply! The pool is optional only if there is only one pool available. I made the ip_pool attribute optional, but in case there are more than one IP pools available, not providing the ip_pool will return None - without printing anything. I'm not sure this is the correct way to handle this, because I did not read the whole guideline for contributing to libcloud (sorry!), I just looked up other functions in the same file.

@marko-p
Copy link
Copy Markdown
Author

marko-p commented Mar 21, 2016

One more note, I don't have an option to test my code against an Openstack tenant with only one floating IP pool.

Comment thread libcloud/compute/drivers/openstack.py Outdated
"""
if (ip_pool is None) and (len(self.ex_list_floating_ip_pools()) == 1):
ip_pool = self.ex_list_floating_ip_pools()[0].name
elif (ip_pool is None) and (len(self.ex_list_floating_ip_pools()) > 1):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about this, if the behavior of open-stack changes, we've bound ourselves to this assumption. I would remove this safety check and instead say

data = {} if ip_pool is None else {'pool': ip_pool}

keeping it all on one line.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks nicer indeed, but leaving data = {} raises an exception.
Would you care to explain what assumption are you talking about? I guess you are talking about selecting the first IP pool in case the user did not provide it as an attribute. I did it like this, because data = {} does not work with Openstack implementation, but it may work in cases where there is only one pool available (I can't test that). The problem with your suggestion is that it raises an exception in case the user did not provide the pool name and the Openstack infrastructure has more than one pool. As I see it, it is safer to check for the number of pools available in case the user did not provide us with the pool name. I will update my code shortly ...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The assumption that it raises an exception, I'm saying if OpenStack change that behavior, the users have to upgrade libcloud to get the benefit.
If you update the docstring instead to say it is required under what circumstances

@marko-p
Copy link
Copy Markdown
Author

marko-p commented Mar 22, 2016

I modified your suggestion a bit in order to follow the guideline to use "is not None" when checking if a variable is provided or defined

Again, this code raises an exception in case the user does not provide the pool name and there are more than one pools available. Is that ok? Forget that, I've read your answer about what assumption you are talking about :)

@tonybaloney
Copy link
Copy Markdown
Contributor

perfect. I think this behavior is correct since the error states what the issue is. Merging

@asfgit asfgit closed this in ac4a8c1 Mar 22, 2016
asfgit pushed a commit that referenced this pull request Mar 22, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants