Skip to content

Lazy entry#822

Merged
asfgit merged 8 commits into
apache:trunkfrom
tonybaloney:lazy_entry
Oct 9, 2016
Merged

Lazy entry#822
asfgit merged 8 commits into
apache:trunkfrom
tonybaloney:lazy_entry

Conversation

@tonybaloney
Copy link
Copy Markdown
Contributor

@tonybaloney tonybaloney commented Jun 24, 2016

Introduce a convenience method to the libcloud module for getting drivers

Description

I find the current mechanism for fetching drivers a little cumbersome, 2 namespaces to import. After using the requests library I really like the module __init__ accessors for common attributes. The most common factory is get_driver and the most common enum is the Provider enum.

This code allows for this example:

import libcloud
cls = libcloud.get_driver(libcloud.DriverType.COMPUTE, libcloud.DriverType.COMPUTE.RACKSPACE)

Status

  • done, ready for review

Checklist (tick everything that applies)

  • Code linting (required, can be done after the PR checks)
  • Documentation
  • Tests
  • ICLA (required for bigger changes)

@Kami
Copy link
Copy Markdown
Member

Kami commented Jun 25, 2016

I'm not too opinionated about of and I'm fine with the overall change and "external API".

Comment thread libcloud/__init__.py Outdated
_init_once()


class DriverType:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Good idea to be consistent and inherit from object even if it's just used as an ENUM class.

@tonybaloney
Copy link
Copy Markdown
Contributor Author

@Kami updated

Comment thread libcloud/base.py Outdated
try:
return DriverTypeFactoryMap[type](provider)
except KeyError:
raise DriverTypeNotFoundError()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think it would also be good to include type in the error message.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

And test for it would be nice :)

Besides that, LGTM, 👍

@Kami
Copy link
Copy Markdown
Member

Kami commented Jun 25, 2016

Would also be good to be update upgrade notes if want this to be a preferred approach for retrieving a driver down the road :)

For that though, it might be worth soliciting feedback and reaching consensus from more people.

@erjohnso
Copy link
Copy Markdown
Contributor

erjohnso commented Jul 3, 2016

Looks good to me. A good follow-on would be to update site docs / examples for this new approach.

@JamieCressey
Copy link
Copy Markdown
Contributor

Observation from an outsider...

If you're defining a provider class as libcloud.DriverType.SERVICE.PROVIDER. Can we not determine the service from the provider, negating the requirement to also provide a service object, therefore simplifying the instantiation from:

cls = libcloud.get_driver(libcloud.DriverType.COMPUTE, libcloud.DriverType.COMPUTE.RACKSPACE)

to:

cls = libcloud.get_driver(libcloud.DriverType.COMPUTE.RACKSPACE)

Just a thought, either way seems much cleaner than the current method.

@tonybaloney
Copy link
Copy Markdown
Contributor Author

@JamieCressey that would be better using the Enum base type in Python 3.4+ but once it has been called, its already been converted into the value (string), and there's no difference in values between storage.Providers.RACKSPACE and loadbalancer.Providers.RACKSPACE, they're both 'rackspace'.
Instead I created seperate factory methods, get_compute_driver, get_storage_driver with the type inbuilt.
There are some cases where people might want to generate a driver dynamically without knowing the type, so get_driver is there as a catch-all.

@tonybaloney
Copy link
Copy Markdown
Contributor Author

I'm pushing this in unless any serious objections?

@tonybaloney
Copy link
Copy Markdown
Contributor Author

merging

@asfgit asfgit merged commit 7db284c into apache:trunk Oct 9, 2016
asfgit pushed a commit that referenced this pull request Oct 9, 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.

5 participants