Skip to content

Commit e94c73c

Browse files
stephenfinSilviaWachira
authored andcommitted
share: Bootstrap new service
In preparation for import of the commands. With time we will migrate commands to SDK and a lot of the client logic introduced here can go away, but we need it until that happens. Change-Id: Ibb369de02e2e8de4d8925c3d6d11a8b7006c377f Signed-off-by: Stephen Finucane <stephenfin@redhat.com> Signed-off-by: Silvia Wachira <wachirasilvia8@gmail.com>
1 parent db4a8b4 commit e94c73c

7 files changed

Lines changed: 114 additions & 1 deletion

File tree

openstackclient/common/clientmanager.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class ClientManager(clientmanager.ClientManager):
5858
image: image_v2.Proxy
5959
network: network_v2.Proxy
6060
object_store: object_store_v1.APIv1
61+
share: Any
6162
volume: Any
6263

6364
def __init__(
@@ -73,7 +74,7 @@ def __init__(
7374
)
7475

7576
# TODO(dtroyer): For compatibility; mark this for removal when plugin
76-
# interface v2 is removed
77+
# interface v2 is removed
7778
self._region_name = self.region_name
7879
self._interface = self.interface
7980
self._cacert = self.cacert

openstackclient/share/__init__.py

Whitespace-only changes.

openstackclient/share/client.py

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# Copyright 2012-2013 OpenStack Foundation
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
4+
# not use this file except in compliance with the License. You may obtain
5+
# a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
# License for the specific language governing permissions and limitations
13+
# under the License.
14+
15+
import argparse
16+
import logging
17+
from typing import TYPE_CHECKING, Any
18+
19+
if TYPE_CHECKING:
20+
from manilaclient import client
21+
22+
from osc_lib import exceptions
23+
from osc_lib import utils
24+
25+
from openstackclient.i18n import _
26+
27+
LOG = logging.getLogger(__name__)
28+
29+
# global variables used when building the shell
30+
DEFAULT_API_VERSION = '2'
31+
API_VERSION_OPTION = 'os_share_api_version'
32+
API_NAME = 'share'
33+
34+
# Save the microversion if in use
35+
_share_api_version = None
36+
37+
38+
def make_client(instance: Any) -> 'client.Client':
39+
"""Returns a manilaclient.client.Client instance."""
40+
from manilaclient import api_versions
41+
from manilaclient import client
42+
43+
check_version = instance._api_version[API_NAME]
44+
if check_version.isdigit():
45+
check_version = f"{check_version}.0"
46+
47+
version = api_versions.get_api_version(check_version)
48+
49+
instance.setup_auth()
50+
51+
LOG.debug('Instantiating Shared File System client: %s', client.Client)
52+
LOG.debug('Shared File System API version: %s', version)
53+
54+
return client.Client(
55+
version,
56+
session=instance.session,
57+
endpoint_type=instance.interface,
58+
region_name=instance.region_name,
59+
auth=instance.auth,
60+
cacert=instance.cacert,
61+
cert=instance.cert,
62+
insecure=not instance.verify,
63+
)
64+
65+
66+
def build_option_parser(
67+
parser: argparse.ArgumentParser,
68+
) -> argparse.ArgumentParser:
69+
"""Hook to add global options"""
70+
parser.add_argument(
71+
'--os-share-api-version',
72+
metavar='<share-api-version>',
73+
default=utils.env('OS_SHARE_API_VERSION'),
74+
help=_(
75+
"Shared File System API version, default=%s "
76+
"(Env: OS_SHARE_API_VERSION)"
77+
)
78+
% DEFAULT_API_VERSION,
79+
)
80+
return parser
81+
82+
83+
def check_api_version(check_version: str) -> bool:
84+
# Defer client imports until we actually need them
85+
from manilaclient import api_versions
86+
87+
global _share_api_version
88+
89+
# TODO(stephenfin): Other clients (novaclient, cinderclient, ...) do this
90+
# normalization for us
91+
if check_version.isdigit():
92+
check_version = f"{check_version}.0"
93+
94+
_share_api_version = api_versions.get_api_version(check_version)
95+
96+
# Bypass X.latest format microversion
97+
if not _share_api_version.is_latest():
98+
if _share_api_version > api_versions.APIVersion("2.0"):
99+
if not _share_api_version.matches(
100+
api_versions.MIN_VERSION,
101+
api_versions.MAX_VERSION,
102+
):
103+
msg = _("versions supported by client: %(min)s - %(max)s") % {
104+
"min": api_versions.MIN_VERSION,
105+
"max": api_versions.MAX_VERSION,
106+
}
107+
raise exceptions.CommandError(msg)
108+
109+
return True
110+
111+
return False

openstackclient/share/v2/__init__.py

Whitespace-only changes.

openstackclient/tests/unit/share/__init__.py

Whitespace-only changes.

openstackclient/tests/unit/share/v2/__init__.py

Whitespace-only changes.

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ osc-lib>=4.6.0 # Apache-2.0
1010
oslo.i18n>=3.15.3 # Apache-2.0
1111
python-keystoneclient>=3.22.0 # Apache-2.0
1212
python-cinderclient>=3.3.0 # Apache-2.0
13+
python-manilaclient>=5.7.0 # Apache-2.0
1314
requests>=2.27.0 # Apache-2.0
1415
stevedore>=2.0.1 # Apache-2.0

0 commit comments

Comments
 (0)