Debian Codegraph @

aodhclient/osc.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 """OpenStackClient plugin for Telemetry Alarming service."""
16
17 from osc_lib import utils
18
19
20 DEFAULT_ALARMING_API_VERSION = '2'
21 API_VERSION_OPTION = 'os_alarming_api_version'
22 API_NAME = "alarming"
23 API_VERSIONS = {
24 "2": "aodhclient.v2.client.Client",
25 }
26
27
28 def make_client(instance):
29 """Returns an queues service client."""
30 version = instance._api_version[API_NAME]
31 try:
32 version = int(version)
33 except ValueError:
34 version = float(version)
35
36 aodh_client = utils.get_client_class(
37 API_NAME,
38 version,
39 API_VERSIONS)
40 # NOTE(sileht): ensure setup of the session is done
41 instance.setup_auth()
42 return aodh_client(session=instance.session,
43 interface=instance.interface,
44 region_name=instance.region_name)
45
46
47 def build_option_parser(parser):
48 """Hook to add global options."""
49 parser.add_argument(
50 '--os-alarming-api-version',
51 metavar='<alarming-api-version>',
52 default=utils.env(
53 'OS_ALARMING_API_VERSION',
54 default=DEFAULT_ALARMING_API_VERSION),
55 help=('Queues API version, default=' +
56 DEFAULT_ALARMING_API_VERSION +
57 ' (Env: OS_ALARMING_API_VERSION)'))
58 return parser