Fix client API version to support Manila API

The Manila client's API version is now '2.5' so that it matches the
Manila server's API version.

The client also supports the Manila V2 Keystone endpoint such that it
will only communicate with the Manila V2 API.

Closes-bug: 1494360

Change-Id: I3d011046bbe4f9223d93341f3d3ac09074f52990
This commit is contained in:
cFouts 2015-09-10 10:59:23 -04:00 committed by Chuck Fouts
parent 66ef98d87f
commit 3cd57eb32e
6 changed files with 59 additions and 51 deletions

@ -28,6 +28,7 @@ from manilaclient import exceptions
def get_client_class(version):
version_map = {
'1': 'manilaclient.v1.client.Client',
'2': 'manilaclient.v1.client.Client',
}
try:
client_path = version_map[str(version)]
@ -45,4 +46,4 @@ def get_major_version(version):
def Client(version, *args, **kwargs):
client_class = get_client_class(get_major_version(version))
return client_class(version, *args, **kwargs)
return client_class(*args, **kwargs)

@ -40,4 +40,7 @@ SNAPSHOT_SORT_KEY_VALUES = (
)
EXPERIMENTAL_HTTP_HEADER = 'X-OpenStack-Manila-API-Experimental'
MAX_API_VERSION = '1.6'
MAX_API_VERSION = '2.5'
V1_API_VERSION = '1.0'
V1_SERVICE_TYPE = 'share'
V2_SERVICE_TYPE = 'sharev2'

@ -38,11 +38,10 @@ from manilaclient import exceptions as exc
import manilaclient.extension
from manilaclient.openstack.common import cliutils
from manilaclient.v1 import shell as shell_v1
# from manilaclient.v2 import shell as shell_v2
DEFAULT_OS_SHARE_API_VERSION = constants.MAX_API_VERSION
DEFAULT_MANILA_ENDPOINT_TYPE = 'publicURL'
DEFAULT_MANILA_SERVICE_TYPE = 'share'
DEFAULT_MANILA_SERVICE_TYPE = constants.V2_SERVICE_TYPE
logger = logging.getLogger(__name__)
@ -295,7 +294,9 @@ class OpenStackManilaShell(object):
def _discover_via_contrib_path(self, version):
module_path = os.path.dirname(os.path.abspath(__file__))
version_str = "v%s" % version.split('.')[0]
# NOTE(cfouts) - temporary change to maintain other clients that are
# hardcoded to use the v1/client.py
version_str = 'v1'
ext_path = os.path.join(module_path, version_str, 'contrib')
ext_glob = os.path.join(ext_path, "*.py")
@ -446,7 +447,8 @@ class OpenStackManilaShell(object):
http_log_debug=args.debug,
cacert=cacert,
use_keyring=os_cache,
force_new_token=os_reset_cache)
force_new_token=os_reset_cache,
api_version=options.os_share_api_version)
args.func(self.cs, args)

@ -18,7 +18,7 @@ import manilaclient.v1.client
class ClientTest(utils.TestCase):
def test_get_client_class_v1(self):
output = manilaclient.client.get_client_class('1')
output = manilaclient.client.get_client_class('2')
self.assertEqual(output, manilaclient.v1.client.Client)
def test_get_client_class_unknown(self):

@ -17,6 +17,7 @@ from keystoneclient.v2_0 import client as keystone_client_v2
from keystoneclient.v3 import client as keystone_client_v3
import six
from manilaclient.common import constants
from manilaclient import exceptions
from manilaclient import httpclient
from manilaclient.v1 import limits
@ -59,16 +60,17 @@ class Client(object):
>>> client.shares.list()
...
"""
def __init__(self, api_version, username=None, api_key=None,
def __init__(self, username=None, api_key=None,
project_id=None, auth_url=None, insecure=False, timeout=None,
tenant_id=None, project_name=None, region_name=None,
endpoint_type='publicURL', extensions=None,
service_type='share', service_name=None, retries=None,
http_log_debug=False, input_auth_token=None, session=None,
auth=None, cacert=None, service_catalog_url=None,
user_agent='python-manilaclient',
service_type=constants.V1_SERVICE_TYPE, service_name=None,
retries=None, http_log_debug=False, input_auth_token=None,
session=None, auth=None, cacert=None,
service_catalog_url=None, user_agent='python-manilaclient',
use_keyring=False, force_new_token=False,
cached_token_lifetime=300, **kwargs):
cached_token_lifetime=300,
api_version=constants.V1_API_VERSION, **kwargs):
service_name = kwargs.get("share_service_name", service_name)
def check_deprecated_arguments():

@ -299,7 +299,7 @@ def do_quota_defaults(cs, args):
default=None,
help='Whether force update the quota even if the already used '
'and reserved exceeds the new quota.')
@cliutils.service_type('share')
@cliutils.service_type('sharev2')
def do_quota_update(cs, args):
"""Update the quotas for a tenant/user."""
@ -330,7 +330,7 @@ def do_quota_delete(cs, args):
'class_name',
metavar='<class>',
help='Name of quota class to list the quotas for.')
@cliutils.service_type('share')
@cliutils.service_type('sharev2')
def do_quota_class_show(cs, args):
"""List the quotas for a quota class."""
@ -373,14 +373,14 @@ def do_quota_class_show(cs, args):
type=int,
default=None,
help='New value for the "share_networks" quota.')
@cliutils.service_type('share')
@cliutils.service_type('sharev2')
def do_quota_class_update(cs, args):
"""Update the quotas for a quota class."""
_quota_update(cs.quota_classes, args.class_name, args)
@cliutils.service_type('share')
@cliutils.service_type('sharev2')
def do_absolute_limits(cs, args):
"""Print a list of absolute limits for a user."""
limits = cs.limits.get().absolute
@ -388,7 +388,7 @@ def do_absolute_limits(cs, args):
cliutils.print_list(limits, columns)
@cliutils.service_type('share')
@cliutils.service_type('sharev2')
def do_rate_limits(cs, args):
"""Print a list of rate limits for a user."""
limits = cs.limits.get().rate
@ -453,7 +453,7 @@ def do_rate_limits(cs, args):
default=None,
action='single_alias',
help='Availability zone in which share should be created.')
@cliutils.service_type('share')
@cliutils.service_type('sharev2')
def do_create(cs, args):
"""Creates a new share (NFS, CIFS, GlusterFS or HDFS)."""
@ -483,7 +483,7 @@ def do_create(cs, args):
'force-migration, which bypasses driver '
'optimizations. Default=False.',
default=False)
@cliutils.service_type('share')
@cliutils.service_type('sharev2')
@api_versions.experimental_api
def do_migrate(cs, args):
"""Migrates share to a new host."""
@ -506,7 +506,7 @@ def do_migrate(cs, args):
nargs='+',
default=[],
help='Metadata to set or unset (key is only necessary on unset).')
@cliutils.service_type('share')
@cliutils.service_type('sharev2')
def do_metadata(cs, args):
"""Set or delete metadata on a share."""
share = _find_share(cs, args.share)
@ -522,7 +522,7 @@ def do_metadata(cs, args):
'share',
metavar='<share>',
help='Name or ID of the share.')
@cliutils.service_type('share')
@cliutils.service_type('sharev2')
def do_metadata_show(cs, args):
"""Show metadata of given share."""
share = _find_share(cs, args.share)
@ -540,7 +540,7 @@ def do_metadata_show(cs, args):
nargs='+',
default=[],
help='Metadata entry or entries to update.')
@cliutils.service_type('share')
@cliutils.service_type('sharev2')
def do_metadata_update_all(cs, args):
"""Update all metadata of a share."""
share = _find_share(cs, args.share)
@ -659,7 +659,7 @@ def do_force_delete(cs, args):
'share',
metavar='<share>',
help='Name or ID of the NAS share.')
@cliutils.service_type('share')
@cliutils.service_type('sharev2')
def do_show(cs, args):
"""Show details about a NAS share."""
share = _find_share(cs, args.share)
@ -688,7 +688,7 @@ def do_show(cs, args):
choices=['rw', 'ro'],
help='Share access level ("rw" and "ro" access levels are supported). '
'Defaults to None.')
@cliutils.service_type('share')
@cliutils.service_type('sharev2')
def do_access_allow(cs, args):
"""Allow access to the share."""
share = _find_share(cs, args.share)
@ -704,7 +704,7 @@ def do_access_allow(cs, args):
'id',
metavar='<id>',
help='ID of the access rule to be deleted.')
@cliutils.service_type('share')
@cliutils.service_type('sharev2')
def do_access_deny(cs, args):
"""Deny access to a share."""
share = _find_share(cs, args.share)
@ -715,7 +715,7 @@ def do_access_deny(cs, args):
'share',
metavar='<share>',
help='Name or ID of the share.')
@cliutils.service_type('share')
@cliutils.service_type('sharev2')
def do_access_list(cs, args):
"""Show access list for share."""
share = _find_share(cs, args.share)
@ -846,7 +846,7 @@ def do_access_list(cs, args):
action='store_true',
default=False,
help="Add public shares from all tenants to result.")
@cliutils.service_type('share')
@cliutils.service_type('sharev2')
def do_list(cs, args):
"""List NAS shares with filters."""
list_of_keys = [
@ -895,7 +895,7 @@ def do_list(cs, args):
default=None,
action='single_alias',
help='Filter results by share ID.')
@cliutils.service_type('share')
@cliutils.service_type('sharev2')
def do_share_instance_list(cs, args):
"""List share instances."""
share = _find_share(cs, args.share_id) if args.share_id else None
@ -916,7 +916,7 @@ def do_share_instance_list(cs, args):
'instance',
metavar='<instance>',
help='Name or ID of the share instance.')
@cliutils.service_type('share')
@cliutils.service_type('sharev2')
def do_share_instance_show(cs, args):
"""Show details about a share instance."""
instance = _find_share_instance(cs, args.instance)
@ -954,7 +954,7 @@ def do_share_instance_force_delete(cs, args):
help=('Indicate which state to assign the instance. Options include '
'available, error, creating, deleting, error_deleting. If no '
'state is provided, available will be used.'))
@cliutils.service_type('share')
@cliutils.service_type('sharev2')
def do_share_instance_reset_state(cs, args):
"""Explicitly update the state of a share instance."""
instance = _find_share_instance(cs, args.instance)
@ -1030,7 +1030,7 @@ def do_share_instance_reset_state(cs, args):
action='single_alias',
help='Sort direction, available values are %(values)s. '
'OPTIONAL: Default=None.' % {'values': constants.SORT_DIR_VALUES})
@cliutils.service_type('share')
@cliutils.service_type('sharev2')
def do_snapshot_list(cs, args):
"""List all the snapshots."""
list_of_keys = [
@ -1060,7 +1060,7 @@ def do_snapshot_list(cs, args):
'snapshot',
metavar='<snapshot>',
help='Name or ID of the snapshot.')
@cliutils.service_type('share')
@cliutils.service_type('sharev2')
def do_snapshot_show(cs, args):
"""Show details about a snapshot."""
snapshot = _find_share_snapshot(cs, args.snapshot)
@ -1088,7 +1088,7 @@ def do_snapshot_show(cs, args):
metavar='<description>',
default=None,
help='Optional snapshot description. (Default=None)')
@cliutils.service_type('share')
@cliutils.service_type('sharev2')
def do_snapshot_create(cs, args):
"""Add a new snapshot."""
share = _find_share(cs, args.share)
@ -1121,7 +1121,7 @@ def do_snapshot_create(cs, args):
type=str,
action="single_alias",
help='Public share is visible for all tenants.')
@cliutils.service_type('share')
@cliutils.service_type('sharev2')
def do_update(cs, args):
"""Rename a share."""
kwargs = {}
@ -1153,7 +1153,7 @@ def do_update(cs, args):
metavar='<description>',
help='Optional snapshot description. (Default=None)',
default=None)
@cliutils.service_type('share')
@cliutils.service_type('sharev2')
def do_snapshot_rename(cs, args):
"""Rename a snapshot."""
kwargs = {}
@ -1172,7 +1172,7 @@ def do_snapshot_rename(cs, args):
'snapshot',
metavar='<snapshot>',
help='Name or ID of the snapshot to delete.')
@cliutils.service_type('share')
@cliutils.service_type('sharev2')
def do_snapshot_delete(cs, args):
"""Remove a snapshot."""
snapshot = _find_share_snapshot(cs, args.snapshot)
@ -1183,7 +1183,7 @@ def do_snapshot_delete(cs, args):
'snapshot',
metavar='<snapshot>',
help='Name or ID of the snapshot to force delete.')
@cliutils.service_type('share')
@cliutils.service_type('sharev2')
def do_snapshot_force_delete(cs, args):
"""Attempt force-delete of snapshot, regardless of state."""
snapshot = _find_share_snapshot(cs, args.snapshot)
@ -1202,7 +1202,7 @@ def do_snapshot_force_delete(cs, args):
'Options include available, error, creating, deleting, '
'error_deleting. If no state is provided, '
'available will be used.'))
@cliutils.service_type('share')
@cliutils.service_type('sharev2')
def do_snapshot_reset_state(cs, args):
"""Explicitly update the state of a snapshot."""
snapshot = _find_share_snapshot(cs, args.snapshot)
@ -1220,7 +1220,7 @@ def do_snapshot_reset_state(cs, args):
help=('Indicate which state to assign the share. Options include '
'available, error, creating, deleting, error_deleting. If no '
'state is provided, available will be used.'))
@cliutils.service_type('share')
@cliutils.service_type('sharev2')
def do_reset_state(cs, args):
"""Explicitly update the state of a share."""
share = _find_share(cs, args.share)
@ -1940,7 +1940,7 @@ def _find_share_type(cs, stype):
return apiclient_utils.find_resource(cs.share_types, stype)
@cliutils.service_type('share')
@cliutils.service_type('sharev2')
@cliutils.arg(
'--all',
dest='all',
@ -1958,7 +1958,7 @@ def do_type_list(cs, args):
_print_share_type_list(stypes, default_share_type=default)
@cliutils.service_type('share')
@cliutils.service_type('sharev2')
def do_extra_specs_list(cs, args):
"""Print a list of current 'share types and extra specs' (Admin Only)."""
stypes = cs.share_types.list()
@ -1988,7 +1988,7 @@ def do_extra_specs_list(cs, args):
metavar='<is_public>',
action='single_alias',
help="Make type accessible to the public (default true).")
@cliutils.service_type('share')
@cliutils.service_type('sharev2')
def do_type_create(cs, args):
"""Create a new share type."""
kwargs = {
@ -2020,7 +2020,7 @@ def do_type_create(cs, args):
'id',
metavar='<id>',
help="Name or ID of the share type to delete.")
@cliutils.service_type('share')
@cliutils.service_type('sharev2')
def do_type_delete(cs, args):
"""Delete a specific share type."""
share_type = _find_share_type(cs, args.id)
@ -2042,7 +2042,7 @@ def do_type_delete(cs, args):
nargs='*',
default=None,
help='Extra_specs to set or unset (key is only necessary on unset).')
@cliutils.service_type('share')
@cliutils.service_type('sharev2')
def do_type_key(cs, args):
"""Set or unset extra_spec for a share type."""
stype = _find_share_type(cs, args.stype)
@ -2074,7 +2074,7 @@ def do_type_key(cs, args):
type=str,
default='.*',
help='Filter results by pool name. Regular expressions are supported.')
@cliutils.service_type('share')
@cliutils.service_type('sharev2')
def do_pool_list(cs, args):
"""List all backend storage pools known to the scheduler (Admin only)."""
@ -2092,7 +2092,7 @@ def do_pool_list(cs, args):
'share_type',
metavar='<share_type>',
help="Filter results by share type name or ID.")
@cliutils.service_type('share')
@cliutils.service_type('sharev2')
def do_type_access_list(cs, args):
"""Print access information about the given share type."""
share_type = _find_share_type(cs, args.share_type)
@ -2114,7 +2114,7 @@ def do_type_access_list(cs, args):
'project_id',
metavar='<project_id>',
help='Project ID to add share type access for.')
@cliutils.service_type('share')
@cliutils.service_type('sharev2')
def do_type_access_add(cs, args):
"""Adds share type access for the given project."""
vtype = _find_share_type(cs, args.share_type)
@ -2130,7 +2130,7 @@ def do_type_access_add(cs, args):
'project_id',
metavar='<project_id>',
help='Project ID to remove share type access for.')
@cliutils.service_type('share')
@cliutils.service_type('sharev2')
def do_type_access_remove(cs, args):
"""Removes share type access for the given project."""
vtype = _find_share_type(cs, args.share_type)
@ -2144,7 +2144,7 @@ def do_type_access_remove(cs, args):
metavar='<new_size>',
type=int,
help='New size of share, in GBs.')
@cliutils.service_type('share')
@cliutils.service_type('sharev2')
def do_extend(cs, args):
"""Increases the size of an existing share."""
share = _find_share(cs, args.share)
@ -2157,7 +2157,7 @@ def do_extend(cs, args):
metavar='<new_size>',
type=int,
help='New size of share, in GBs.')
@cliutils.service_type('share')
@cliutils.service_type('sharev2')
def do_shrink(cs, args):
"""Decreases the size of an existing share."""
share = _find_share(cs, args.share)