
The parser should not rely on the OS_* environment variables for authentication, as it will fail with more complex setups, when using the "clouds.yaml" configuration file or when being called through osc with arguments instead of environment variables. Moreover, the client should not use "requests" directly to do GETs to access the nova flavors and glance images, but it should use the existing clients. When used through the python-openstackclient it is possible to force the client to request authentication. The authentication will be handled by the client, so that the parser does not need to worry about it (so that authentication plugins can be used). Then, the existing authentication session can be reused for all the client interaction with OpenStack to fetch the flavor and images information. Change-Id: I9f65e7d46686c37bb44ef18756ebd295ee4961de
82 lines
3.4 KiB
Python
82 lines
3.4 KiB
Python
# 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.
|
|
|
|
import logging
|
|
|
|
# NOTE(aloga): this should be safe. If we do not have the clients, we won't
|
|
# have the session below, therefore the clients won't be ever called.
|
|
try:
|
|
import glanceclient.client
|
|
except ImportError:
|
|
pass
|
|
|
|
log = logging.getLogger('heat-translator')
|
|
|
|
|
|
_IMAGES = {
|
|
'ubuntu-software-config-os-init': {'architecture': 'x86_64',
|
|
'type': 'Linux',
|
|
'distribution': 'Ubuntu',
|
|
'version': '14.04'},
|
|
'ubuntu-12.04-software-config-os-init': {'architecture': 'x86_64',
|
|
'type': 'Linux',
|
|
'distribution': 'Ubuntu',
|
|
'version': '12.04'},
|
|
'fedora-amd64-heat-config': {'architecture': 'x86_64',
|
|
'type': 'Linux',
|
|
'distribution': 'Fedora',
|
|
'version': '18.0'},
|
|
'F18-x86_64-cfntools': {'architecture': 'x86_64',
|
|
'type': 'Linux',
|
|
'distribution': 'Fedora',
|
|
'version': '19'},
|
|
'Fedora-x86_64-20-20131211.1-sda': {'architecture': 'x86_64',
|
|
'type': 'Linux',
|
|
'distribution': 'Fedora',
|
|
'version': '20'},
|
|
'cirros-0.3.1-x86_64-uec': {'architecture': 'x86_64',
|
|
'type': 'Linux',
|
|
'distribution': 'CirrOS',
|
|
'version': '0.3.1'},
|
|
'cirros-0.3.2-x86_64-uec': {'architecture': 'x86_64',
|
|
'type': 'Linux',
|
|
'distribution': 'CirrOS',
|
|
'version': '0.3.2'},
|
|
'rhel-6.5-test-image': {'architecture': 'x86_64',
|
|
'type': 'Linux',
|
|
'distribution': 'RHEL',
|
|
'version': '6.5'}
|
|
}
|
|
|
|
SESSION = None
|
|
|
|
|
|
def get_images():
|
|
ret = {}
|
|
|
|
if SESSION is not None:
|
|
try:
|
|
client = glanceclient.client.Client("2", session=SESSION)
|
|
except Exception as e:
|
|
# Handles any exception coming from openstack
|
|
log.warn(_('Choosing predefined images since received '
|
|
'Openstack Exception: %s') % str(e))
|
|
else:
|
|
for image in client.images.list():
|
|
metadata = ["architecture", "type", "distribution", "version"]
|
|
if any(key in image.keys() for key in metadata):
|
|
ret = [image["name"]] = {}
|
|
for key in metadata:
|
|
if key in image.keys():
|
|
ret[image["name"]][key] = image[key]
|
|
return ret or _IMAGES
|