Last active
August 29, 2015 14:00
-
-
Save jmatt/11159266 to your computer and use it in GitHub Desktop.
Decorators could simplify using different services and endpoints.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from decorators import cinder | |
| # ... | |
| @cinder | |
| def ex_list_all_volumes(self): | |
| """ | |
| List all volumes from all tenants of a user | |
| """ | |
| resp = self.connection.request( | |
| '/volumes/detail?all_tenants=1', | |
| method='GET') | |
| return self._to_volumes(resp.object, glance=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def ex_list_all_volumes(self): | |
| """ | |
| List all volumes from all tenants of a user | |
| """ | |
| lc_conn = self.connection | |
| if not lc_conn.service_catalog: | |
| lc_conn.get_service_catalog() | |
| #Change base_url, make request, update base_url | |
| if lc_conn._ex_force_base_url: | |
| old_endpoint = lc_conn._ex_force_base_url | |
| else: | |
| old_endpoint = lc_conn.get_endpoint() | |
| try: | |
| new_service = lc_conn.service_catalog.get_endpoint( | |
| service_type='volume', name='cinder', | |
| region=lc_conn.service_region) | |
| lc_conn._ex_force_base_url = new_service['publicURL'] | |
| server_resp = lc_conn.request( | |
| '/volumes/detail?all_tenants=1', | |
| method='GET') | |
| return self._to_volumes(server_resp.object, glance=True) | |
| finally: | |
| lc_conn._ex_force_base_url = old_endpoint |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment