Move Capsule from Experimental API to v1
Part of blueprint golang-client Depends-On: Id47c95ca60a47ce43f4a89c29cb5d19b09427b7b Change-Id: I51196335faba517e98ee748955d893b5da92dbda Signed-off-by: Kevin Zhao <kevin.zhao@arm.com>
This commit is contained in:
parent
2f77408bcf
commit
9e167c6608
@ -1,123 +0,0 @@
|
||||
# Copyright 2017 Arm Limited.
|
||||
#
|
||||
# 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 keystoneauth1 import loading
|
||||
from keystoneauth1 import session as ksa_session
|
||||
from oslo_utils import importutils
|
||||
|
||||
from zunclient.common import httpclient
|
||||
from zunclient.experimental import capsules
|
||||
|
||||
profiler = importutils.try_import("osprofiler.profiler")
|
||||
|
||||
|
||||
class Client(object):
|
||||
def __init__(self, username=None, api_key=None, project_id=None,
|
||||
project_name=None, auth_url=None, zun_url=None,
|
||||
endpoint_type=None, endpoint_override=None,
|
||||
service_type='container-experimental',
|
||||
region_name=None, input_auth_token=None,
|
||||
session=None, password=None, auth_type='password',
|
||||
interface='public', service_name=None, insecure=False,
|
||||
user_domain_id=None, user_domain_name=None,
|
||||
project_domain_id=None, project_domain_name=None,
|
||||
api_version=None, **kwargs):
|
||||
|
||||
# We have to keep the api_key are for backwards compat, but let's
|
||||
# remove it from the rest of our code since it's not a keystone
|
||||
# concept
|
||||
if not password:
|
||||
password = api_key
|
||||
# Backwards compat for people assing in endpoint_type
|
||||
if endpoint_type:
|
||||
interface = endpoint_type
|
||||
|
||||
# fix (yolanda): os-cloud-config is using endpoint_override
|
||||
# instead of zun_url
|
||||
if endpoint_override and not zun_url:
|
||||
zun_url = endpoint_override
|
||||
|
||||
if zun_url and input_auth_token:
|
||||
auth_type = 'admin_token'
|
||||
session = None
|
||||
loader_kwargs = dict(
|
||||
token=input_auth_token,
|
||||
endpoint=zun_url)
|
||||
elif input_auth_token and not session:
|
||||
auth_type = 'token'
|
||||
loader_kwargs = dict(
|
||||
token=input_auth_token,
|
||||
auth_url=auth_url,
|
||||
project_id=project_id,
|
||||
project_name=project_name,
|
||||
user_domain_id=user_domain_id,
|
||||
user_domain_name=user_domain_name,
|
||||
project_domain_id=project_domain_id,
|
||||
project_domain_name=project_domain_name)
|
||||
else:
|
||||
loader_kwargs = dict(
|
||||
username=username,
|
||||
password=password,
|
||||
auth_url=auth_url,
|
||||
project_id=project_id,
|
||||
project_name=project_name,
|
||||
user_domain_id=user_domain_id,
|
||||
user_domain_name=user_domain_name,
|
||||
project_domain_id=project_domain_id,
|
||||
project_domain_name=project_domain_name)
|
||||
|
||||
# Backwards compatibility for people not passing in Session
|
||||
if session is None:
|
||||
loader = loading.get_plugin_loader(auth_type)
|
||||
|
||||
# This should be able to handle v2 and v3 Keystone Auth
|
||||
auth_plugin = loader.load_from_options(**loader_kwargs)
|
||||
session = ksa_session.Session(
|
||||
auth=auth_plugin, verify=(not insecure))
|
||||
|
||||
client_kwargs = {}
|
||||
if zun_url:
|
||||
client_kwargs['endpoint_override'] = zun_url
|
||||
|
||||
if not zun_url:
|
||||
try:
|
||||
# Trigger an auth error so that we can throw the exception
|
||||
# we always have
|
||||
session.get_endpoint(
|
||||
service_type=service_type,
|
||||
service_name=service_name,
|
||||
interface=interface,
|
||||
region_name=region_name)
|
||||
except Exception:
|
||||
raise RuntimeError("Not Authorized")
|
||||
|
||||
self.http_client = httpclient.SessionClient(
|
||||
service_type=service_type,
|
||||
service_name=service_name,
|
||||
interface=interface,
|
||||
region_name=region_name,
|
||||
session=session,
|
||||
api_version=api_version,
|
||||
**client_kwargs)
|
||||
self.capsules = capsules.CapsuleManager(self.http_client)
|
||||
|
||||
profile = kwargs.pop("profile", None)
|
||||
if profiler and profile:
|
||||
# Initialize the root of the future trace: the created trace ID
|
||||
# will be used as the very first parent to which all related
|
||||
# traces will be bound to. The given HMAC key must correspond to
|
||||
# the one set in zun-api zun.conf, otherwise the latter
|
||||
# will fail to check the request signature and will skip
|
||||
# initialization of osprofiler on the server side.
|
||||
profiler.init(profile)
|
@ -1,19 +0,0 @@
|
||||
# Copyright 2017 Arm Limited.
|
||||
#
|
||||
# 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 zunclient.experimental import capsules_shell
|
||||
|
||||
COMMAND_MODULES = [
|
||||
capsules_shell,
|
||||
]
|
@ -57,8 +57,6 @@ from zunclient import client as base_client
|
||||
from zunclient.common.apiclient import auth
|
||||
from zunclient.common import cliutils
|
||||
from zunclient import exceptions as exc
|
||||
from zunclient.experimental import client as client_experimental
|
||||
from zunclient.experimental import shell as shell_experimental
|
||||
from zunclient.i18n import _
|
||||
from zunclient.v1 import shell as shell_v1
|
||||
from zunclient import version
|
||||
@ -66,7 +64,6 @@ from zunclient import version
|
||||
DEFAULT_API_VERSION = api_versions.DEFAULT_API_VERSION
|
||||
DEFAULT_ENDPOINT_TYPE = 'publicURL'
|
||||
DEFAULT_SERVICE_TYPE = 'container'
|
||||
EXPERIENTAL_SERVICE_TYPE = 'container-experimental'
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@ -364,10 +361,6 @@ class OpenStackZunShell(object):
|
||||
action='store_true',
|
||||
help="Do not verify https connections")
|
||||
|
||||
parser.add_argument('--experimental-api',
|
||||
action='store_true',
|
||||
help="Using experimental API")
|
||||
|
||||
if profiler:
|
||||
parser.add_argument('--profile',
|
||||
metavar='HMAC_KEY',
|
||||
@ -389,16 +382,13 @@ class OpenStackZunShell(object):
|
||||
|
||||
return parser
|
||||
|
||||
def get_subcommand_parser(self, version, experimental, do_help=False):
|
||||
def get_subcommand_parser(self, version, do_help=False):
|
||||
parser = self.get_base_parser()
|
||||
|
||||
self.subcommands = {}
|
||||
subparsers = parser.add_subparsers(metavar='<subcommand>')
|
||||
|
||||
actions_modules = shell_v1.COMMAND_MODULES
|
||||
if experimental:
|
||||
for items in shell_experimental.COMMAND_MODULES:
|
||||
actions_modules.append(items)
|
||||
|
||||
for action_modules in actions_modules:
|
||||
self._find_actions(subparsers, action_modules, version, do_help)
|
||||
@ -509,12 +499,8 @@ class OpenStackZunShell(object):
|
||||
spot = argv.index('--endpoint_type')
|
||||
argv[spot] = '--endpoint-type'
|
||||
|
||||
experimental = False
|
||||
if '--experimental-api' in argv:
|
||||
experimental = True
|
||||
|
||||
subcommand_parser = self.get_subcommand_parser(
|
||||
api_version, experimental, do_help=("help" in args))
|
||||
api_version, do_help=("help" in args))
|
||||
|
||||
self.parser = subcommand_parser
|
||||
|
||||
@ -559,8 +545,6 @@ class OpenStackZunShell(object):
|
||||
if not service_type:
|
||||
service_type = DEFAULT_SERVICE_TYPE
|
||||
|
||||
if experimental:
|
||||
service_type = EXPERIENTAL_SERVICE_TYPE
|
||||
# NA - there is only one service this CLI accesses
|
||||
# service_type = utils.get_service_type(args.func) or service_type
|
||||
|
||||
@ -620,10 +604,7 @@ class OpenStackZunShell(object):
|
||||
'--os-password, env[OS_PASSWORD], or '
|
||||
'prompted response')
|
||||
|
||||
if experimental:
|
||||
client = client_experimental
|
||||
else:
|
||||
client = base_client
|
||||
client = base_client
|
||||
|
||||
kwargs = {}
|
||||
if profiler:
|
||||
|
@ -28,10 +28,7 @@ def _show_capsule(capsule):
|
||||
@utils.arg('-f', '--template-file', metavar='<file>',
|
||||
required=True, help=_('Path to the template.'))
|
||||
def do_capsule_create(cs, args):
|
||||
"""Create a capsule.
|
||||
|
||||
Add '--experimental-api' due to capsule now is the experimental API
|
||||
"""
|
||||
"""Create a capsule."""
|
||||
opts = {}
|
||||
if args.template_file:
|
||||
template = template_utils.get_template_contents(
|
||||
@ -62,10 +59,7 @@ def do_capsule_create(cs, args):
|
||||
choices=['desc', 'asc'],
|
||||
help='Direction to sort. "asc" or "desc".')
|
||||
def do_capsule_list(cs, args):
|
||||
"""Print a list of available capsules.
|
||||
|
||||
Add '--experimental-api' due to capsule now is the experimental API
|
||||
"""
|
||||
"""Print a list of available capsules."""
|
||||
opts = {}
|
||||
opts['all_projects'] = args.all_projects
|
||||
opts['marker'] = args.marker
|
||||
@ -85,10 +79,7 @@ def do_capsule_list(cs, args):
|
||||
action='store_true',
|
||||
help='Force delete the capsule.')
|
||||
def do_capsule_delete(cs, args):
|
||||
"""Delete specified capsules.
|
||||
|
||||
Add '--experimental-api' due to capsule now is the experimental API
|
||||
"""
|
||||
"""Delete specified capsules."""
|
||||
for capsule in args.capsules:
|
||||
try:
|
||||
cs.capsules.delete(capsule, args.force)
|
@ -17,6 +17,7 @@ from keystoneauth1 import loading
|
||||
from keystoneauth1 import session as ksa_session
|
||||
|
||||
from zunclient.common import httpclient
|
||||
from zunclient.v1 import capsules
|
||||
from zunclient.v1 import containers
|
||||
from zunclient.v1 import hosts
|
||||
from zunclient.v1 import images
|
||||
@ -125,6 +126,7 @@ class Client(object):
|
||||
self.services = services.ServiceManager(self.http_client)
|
||||
self.hosts = hosts.HostManager(self.http_client)
|
||||
self.versions = versions.VersionManager(self.http_client)
|
||||
self.capsules = capsules.CapsuleManager(self.http_client)
|
||||
|
||||
@property
|
||||
def api_version(self):
|
||||
|
@ -13,6 +13,7 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from zunclient.v1 import capsules_shell
|
||||
from zunclient.v1 import containers_shell
|
||||
from zunclient.v1 import hosts_shell
|
||||
from zunclient.v1 import images_shell
|
||||
@ -25,4 +26,5 @@ COMMAND_MODULES = [
|
||||
services_shell,
|
||||
hosts_shell,
|
||||
versions_shell,
|
||||
capsules_shell,
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user