Files
python-cinderclient/cinderclient/v2/shell.py
scottda 27e6f6f7f8 Add /v3 endpoint support for cinderclient
Add support for Cinder API /v3 endpoint.
A couple of unit tests for /v3 endpoint were added to v3/test_shell.py
to ensure that the v3 shell works, and to also test that modules work
with:
from cinderclient.v2.availability_zones import *
syntax.

Change-Id: I6ae0ada221bebb4ab1850d9c99b10fcbb585201f
Implements: https://blueprints.launchpad.net/python-cinderclient/+spec/add-v3-endpoint-support
2016-04-18 10:49:51 -06:00

67 lines
2.5 KiB
Python

# Copyright (c) 2013-2014 OpenStack Foundation
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from cinderclient.v3.shell import * # flake8: noqa
from cinderclient import utils
utils.retype_method('volumev3', 'volumev2', globals())
# Below is shameless hack for unit tests
# TODO remove after deciding if unit tests are moved to /v3/ dir
def _treeizeAvailabilityZone(zone):
"""Builds a tree view for availability zones."""
AvailabilityZone = availability_zones.AvailabilityZone
az = AvailabilityZone(zone.manager,
copy.deepcopy(zone._info), zone._loaded)
result = []
# Zone tree view item
az.zoneName = zone.zoneName
az.zoneState = ('available'
if zone.zoneState['available'] else 'not available')
az._info['zoneName'] = az.zoneName
az._info['zoneState'] = az.zoneState
result.append(az)
if getattr(zone, "hosts", None) and zone.hosts is not None:
for (host, services) in zone.hosts.items():
# Host tree view item
az = AvailabilityZone(zone.manager,
copy.deepcopy(zone._info), zone._loaded)
az.zoneName = '|- %s' % host
az.zoneState = ''
az._info['zoneName'] = az.zoneName
az._info['zoneState'] = az.zoneState
result.append(az)
for (svc, state) in services.items():
# Service tree view item
az = AvailabilityZone(zone.manager,
copy.deepcopy(zone._info), zone._loaded)
az.zoneName = '| |- %s' % svc
az.zoneState = '%s %s %s' % (
'enabled' if state['active'] else 'disabled',
':-)' if state['available'] else 'XXX',
state['updated_at'])
az._info['zoneName'] = az.zoneName
az._info['zoneState'] = az.zoneState
result.append(az)
return result