Debian Codegraph @

adjutantclient/osc/plugin.py

raw
1 # Copyright 2014 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 logging
16
17 from osc_lib import utils
18
19 LOG = logging.getLogger(__name__)
20
21 DEFAULT_OS_ADMIN_LOGIC_VERSION = '1'
22 DEFAULT_API_VERSION = '1'
23 API_VERSION_OPTION = 'os_admin_logic_version'
24 API_NAME = "admin_logic"
25 API_VERSIONS = {
26 "1": "adjutantclient.v1.client.Client",
27 }
28
29
30 def make_client(instance):
31 """Returns an adjutant service client."""
32 version = instance._api_version[API_NAME]
33 try:
34 version = int(version)
35 except ValueError:
36 version = float(version)
37
38 version = 1
39
40 adjutant_client = utils.get_client_class(
41 API_NAME,
42 version,
43 API_VERSIONS)
44
45 LOG.debug('Instantiating adjutant client: %s', adjutant_client)
46
47 kwargs = {'region_name': instance.region_name}
48
49 if instance.session:
50 kwargs.update({'session': instance.session})
51 else:
52 kwargs.update({'auth_url': instance.auth.auth_url,
53 'username': instance.auth_ref.username,
54 'token': instance.auth_ref.auth_token})
55
56 client = adjutant_client(**kwargs)
57
58 return client
59
60
61 def build_option_parser(parser):
62 """Hook to add global options."""
63 parser.add_argument(
64 '--os-admin-logic-version',
65 metavar='<admin-logic-version>',
66 default=utils.env(
67 'OS_ADMIN_LOGIC_VERSION',
68 default=DEFAULT_OS_ADMIN_LOGIC_VERSION),
69 help=('Client version, default=' +
70 DEFAULT_OS_ADMIN_LOGIC_VERSION +
71 ' (Env: DEFAULT_OS_ADMIN_LOGIC_VERSION)'))
72 return parser