Coverage for manila/image/glance.py: 96%
23 statements
« prev ^ index » next coverage.py v7.11.0, created at 2026-02-18 22:19 +0000
« prev ^ index » next coverage.py v7.11.0, created at 2026-02-18 22:19 +0000
1# All Rights Reserved.
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.
15"""
16Handles all requests to Glance.
17"""
19from keystoneauth1 import loading as ks_loading
20import openstack
21from oslo_config import cfg
23from manila.common import client_auth
24from manila.common.config import core_opts
25from manila.db import base
27GLANCE_GROUP = 'glance'
30glance_opts = [
31 cfg.StrOpt('api_microversion',
32 default='2',
33 help='Version of Glance API to be used.'),
34 cfg.StrOpt('region_name',
35 default='RegionOne',
36 help='Region name for connecting to glance.'),
37 cfg.StrOpt('endpoint_type',
38 default='publicURL',
39 choices=['publicURL', 'internalURL', 'adminURL',
40 'public', 'internal', 'admin'],
41 help='Endpoint type to be used with glance client calls.'),
42 ]
44CONF = cfg.CONF
45CONF.register_opts(core_opts)
46CONF.register_opts(glance_opts, GLANCE_GROUP)
47ks_loading.register_session_conf_options(CONF, GLANCE_GROUP)
48ks_loading.register_auth_conf_options(CONF, GLANCE_GROUP)
51def list_opts():
52 return client_auth.AuthClientLoader.list_opts(GLANCE_GROUP)
55def openstackclient(context):
56 auth = ks_loading.load_auth_from_conf_options(CONF, 'glance')
57 session = ks_loading.load_session_from_conf_options(
58 CONF, 'glance', auth=auth)
59 return openstack.connection.Connection(
60 session=session,
61 context=context,
62 image_version=CONF[GLANCE_GROUP].api_microversion,
63 image_interface=CONF[GLANCE_GROUP].endpoint_type,
64 region_name=CONF[GLANCE_GROUP].region_name)
67class API(base.Base):
69 def image_list(self, context):
70 client = openstackclient(context)
71 return client.image.images()