|
18 | 18 | import itertools |
19 | 19 | import sys |
20 | 20 |
|
| 21 | +from openstack import exceptions as sdk_exceptions |
| 22 | +from openstack.network.v2 import quota as _quota |
21 | 23 | from osc_lib.command import command |
22 | 24 | from osc_lib import utils |
23 | 25 | import six |
@@ -251,7 +253,39 @@ def get_network_quota(self, parsed_args): |
251 | 253 | project = self._get_project(parsed_args) |
252 | 254 | client = self.app.client_manager.network |
253 | 255 | if parsed_args.default: |
254 | | - network_quota = client.get_quota_default(project) |
| 256 | + # TODO(dtroyer): Remove the top of this if block once the |
| 257 | + # fixed SDK QuotaDefault class is the minimum |
| 258 | + # required version. This is expected to be |
| 259 | + # SDK release 0.9.13 |
| 260 | + if hasattr(_quota.QuotaDefault, 'project'): |
| 261 | + # hack 0.9.11+ |
| 262 | + quotadef_obj = client._get_resource( |
| 263 | + _quota.QuotaDefault, |
| 264 | + project, |
| 265 | + ) |
| 266 | + quotadef_obj.base_path = quotadef_obj.base_path % { |
| 267 | + 'project': project, |
| 268 | + } |
| 269 | + try: |
| 270 | + network_quota = quotadef_obj.get( |
| 271 | + client.session, |
| 272 | + requires_id=False, |
| 273 | + ) |
| 274 | + except sdk_exceptions.NotFoundException as e: |
| 275 | + raise sdk_exceptions.ResourceNotFound( |
| 276 | + message="No %s found for %s" % |
| 277 | + (_quota.QuotaDefault.__name__, project), |
| 278 | + details=e.details, |
| 279 | + response=e.response, |
| 280 | + request_id=e.request_id, |
| 281 | + url=e.url, |
| 282 | + method=e.method, |
| 283 | + http_status=e.http_status, |
| 284 | + cause=e.cause, |
| 285 | + ) |
| 286 | + # end hack-around |
| 287 | + else: |
| 288 | + network_quota = client.get_quota_default(project) |
255 | 289 | else: |
256 | 290 | network_quota = client.get_quota(project) |
257 | 291 | return network_quota |
|
0 commit comments