Debian Codegraph @

neutronclient/osc/plugin.py

raw
1 # Licensed under the Apache License, Version 2.0 (the "License"); you may
2 # not use this file except in compliance with the License. You may obtain
3 # a copy of the License at
4 #
5 # http://www.apache.org/licenses/LICENSE-2.0
6 #
7 # Unless required by applicable law or agreed to in writing, software
8 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10 # License for the specific language governing permissions and limitations
11 # under the License.
12 #
13
14 """OpenStackClient plugin for advanced Networking service."""
15
16 import logging
17
18 # TODO(rtheis/amotoki): Add functional test infrastructure for OSC
19 # plugin commands.
20 # TODO(amotoki): Add and update document on OSC plugin.
21
22 from osc_lib import utils
23
24 LOG = logging.getLogger(__name__)
25
26 DEFAULT_API_VERSION = '2.0'
27 API_VERSION_OPTION = 'os_network_api_version'
28 # NOTE(rtheis): API_NAME must NOT be set to 'network' since
29 # 'network' is owned by OSC! The OSC 'network' client uses
30 # the OpenStack SDK.
31 API_NAME = 'neutronclient'
32 API_VERSIONS = {
33 '2.0': 'neutronclient.v2_0.client.Client',
34 '2': 'neutronclient.v2_0.client.Client',
35 }
36
37
38 def make_client(instance):
39 """Returns an neutron client."""
40 neutron_client = utils.get_client_class(
41 API_NAME,
42 instance._api_version[API_NAME],
43 API_VERSIONS)
44 LOG.debug('Instantiating neutron client: %s', neutron_client)
45
46 # TODO(amotoki): Check the following arguments need to be passed
47 # to neutronclient class. Check keystoneauth code.
48 # - endpoint_type (do we need to specify it explicitly?)
49 # - auth (session object contains auth. Is it required?)
50 client = neutron_client(session=instance.session,
51 region_name=instance.region_name,
52 endpoint_type=instance.interface,
53 insecure=not instance.verify,
54 ca_cert=instance.cacert)
55 return client
56
57
58 def build_option_parser(parser):
59 """Hook to add global options"""
60
61 # NOTE(amotoki): At now we register no option.
62 # OSC itself has an option for Network API version # and we refer to it.
63 return parser