diff options
| author | Richard Theis <rtheis@us.ibm.com> | 2016-01-15 15:23:08 -0600 |
|---|---|---|
| committer | Richard Theis <rtheis@us.ibm.com> | 2016-02-02 08:08:25 -0600 |
| commit | 4d332defbc4231f77b7459d4abda88a36a65d37d (patch) | |
| tree | 5690f01cd067e1ecea8117b4e38180f95d884705 /openstackclient/common | |
| parent | f36177ebdd4ea25028337efaf667c23d62e3bf9e (diff) | |
| download | python-openstackclient-4d332defbc4231f77b7459d4abda88a36a65d37d.tar.gz | |
Support listing network availability zones
Update the "os availability zone list" command to support listing
network availability zones along with the currently listed compute
and volume availability zones. This adds the --network option to
the command in order to only list network availability zones. By
default, all availability zones are listed. The --long option
was also updated to include a "Zone Resource" column which is
applicable to network availability zones. Example zone resources
include "network" and "router".
If the Network API does not support listing availability zones
then a warning message will be issued when the --network option
is specified.
This support requires an updated release of the SDK in order
to pull in [1].
[1] https://bugs.launchpad.net/python-openstacksdk/+bug/1532274
Change-Id: I78811d659b793d9d2111ea54665d5fe7e4887264
Closes-Bug: #1534202
Diffstat (limited to 'openstackclient/common')
| -rw-r--r-- | openstackclient/common/availability_zone.py | 66 |
1 files changed, 56 insertions, 10 deletions
diff --git a/openstackclient/common/availability_zone.py b/openstackclient/common/availability_zone.py index fa5aee47..a941418b 100644 --- a/openstackclient/common/availability_zone.py +++ b/openstackclient/common/availability_zone.py @@ -30,6 +30,8 @@ def _xform_common_availability_zone(az, zone_info): if hasattr(az, 'zoneName'): zone_info['zone_name'] = az.zoneName + zone_info['zone_resource'] = '' + def _xform_compute_availability_zone(az, include_extra): result = [] @@ -69,6 +71,18 @@ def _xform_volume_availability_zone(az): return result +def _xform_network_availability_zone(az): + result = [] + zone_info = {} + zone_info['zone_name'] = getattr(az, 'name', '') + zone_info['zone_status'] = getattr(az, 'state', '') + if 'unavailable' == zone_info['zone_status']: + zone_info['zone_status'] = 'not available' + zone_info['zone_resource'] = getattr(az, 'resource', '') + result.append(zone_info) + return result + + class ListAvailabilityZone(command.Lister): """List availability zones and their status""" @@ -80,6 +94,11 @@ class ListAvailabilityZone(command.Lister): default=False, help='List compute availability zones') parser.add_argument( + '--network', + action='store_true', + default=False, + help='List network availability zones') + parser.add_argument( '--volume', action='store_true', default=False, @@ -92,7 +111,7 @@ class ListAvailabilityZone(command.Lister): ) return parser - def get_compute_availability_zones(self, parsed_args): + def _get_compute_availability_zones(self, parsed_args): compute_client = self.app.client_manager.compute try: data = compute_client.availability_zones.list() @@ -108,36 +127,63 @@ class ListAvailabilityZone(command.Lister): result += _xform_compute_availability_zone(zone, parsed_args.long) return result - def get_volume_availability_zones(self, parsed_args): + def _get_volume_availability_zones(self, parsed_args): volume_client = self.app.client_manager.volume + data = [] try: data = volume_client.availability_zones.list() - except Exception: - message = "Availability zones list not supported by " \ - "Block Storage API" - self.log.warning(message) + except Exception as e: + self.log.debug('Volume availability zone exception: ' + str(e)) + if parsed_args.volume: + message = "Availability zones list not supported by " \ + "Block Storage API" + self.log.warning(message) result = [] for zone in data: result += _xform_volume_availability_zone(zone) return result + def _get_network_availability_zones(self, parsed_args): + network_client = self.app.client_manager.network + data = [] + try: + # Verify that the extension exists. + network_client.find_extension('Availability Zone', + ignore_missing=False) + data = network_client.availability_zones() + except Exception as e: + self.log.debug('Network availability zone exception: ' + str(e)) + if parsed_args.network: + message = "Availability zones list not supported by " \ + "Network API" + self.log.warning(message) + + result = [] + for zone in data: + result += _xform_network_availability_zone(zone) + return result + def take_action(self, parsed_args): if parsed_args.long: - columns = ('Zone Name', 'Zone Status', + columns = ('Zone Name', 'Zone Status', 'Zone Resource', 'Host Name', 'Service Name', 'Service Status') else: columns = ('Zone Name', 'Zone Status') # Show everything by default. - show_all = (not parsed_args.compute and not parsed_args.volume) + show_all = (not parsed_args.compute and + not parsed_args.volume and + not parsed_args.network) result = [] if parsed_args.compute or show_all: - result += self.get_compute_availability_zones(parsed_args) + result += self._get_compute_availability_zones(parsed_args) if parsed_args.volume or show_all: - result += self.get_volume_availability_zones(parsed_args) + result += self._get_volume_availability_zones(parsed_args) + if parsed_args.network or show_all: + result += self._get_network_availability_zones(parsed_args) return (columns, (utils.get_dict_properties( |
