add image arch and properties specification
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
|
||||
import logging
|
||||
import zaza.openstack.utilities.openstack as openstack_utils
|
||||
import zaza.utilities.deployment_env as deployment_env
|
||||
|
||||
CIRROS_IMAGE_NAME = "cirros"
|
||||
CIRROS_ALT_IMAGE_NAME = "cirros_alt"
|
||||
@@ -31,7 +32,8 @@ def basic_setup():
|
||||
"""
|
||||
|
||||
|
||||
def add_image(image_url, glance_client=None, image_name=None, tags=[]):
|
||||
def add_image(image_url, glance_client=None, image_name=None, tags=[],
|
||||
properties=None):
|
||||
"""Retrieve image from ``image_url`` and add it to glance.
|
||||
|
||||
:param image_url: Retrievable URL with image data
|
||||
@@ -42,6 +44,8 @@ def add_image(image_url, glance_client=None, image_name=None, tags=[]):
|
||||
:type image_name: str
|
||||
:param tags: List of tags to add to image
|
||||
:type tags: list of str
|
||||
:param properties: Properties to add to image
|
||||
:type properties: dict
|
||||
"""
|
||||
if not glance_client:
|
||||
keystone_session = openstack_utils.get_overcloud_keystone_session()
|
||||
@@ -60,7 +64,8 @@ def add_image(image_url, glance_client=None, image_name=None, tags=[]):
|
||||
glance_client,
|
||||
image_url,
|
||||
image_name,
|
||||
tags=tags)
|
||||
tags=tags,
|
||||
properties=properties)
|
||||
|
||||
|
||||
def add_cirros_image(glance_client=None, image_name=None):
|
||||
@@ -90,7 +95,8 @@ def add_cirros_alt_image(glance_client=None, image_name=None):
|
||||
add_cirros_image(glance_client, image_name)
|
||||
|
||||
|
||||
def add_lts_image(glance_client=None, image_name=None, release=None):
|
||||
def add_lts_image(glance_client=None, image_name=None, release=None,
|
||||
properties=None):
|
||||
"""Add an Ubuntu LTS image to the current deployment.
|
||||
|
||||
:param glance: Authenticated glanceclient
|
||||
@@ -99,12 +105,22 @@ def add_lts_image(glance_client=None, image_name=None, release=None):
|
||||
:type image_name: str
|
||||
:param release: Name of ubuntu release.
|
||||
:type release: str
|
||||
:param properties: Custom image properties
|
||||
:type properties: dict
|
||||
"""
|
||||
deploy_ctxt = deployment_env.get_deployment_context()
|
||||
image_arch = deploy_ctxt.get('TEST_IMAGE_ARCH', 'amd64')
|
||||
arch_image_properties = {
|
||||
'arm64': {'hw_firmware_type': 'uefi'},
|
||||
'ppc64el': {'architecture': 'ppc64'}}
|
||||
properties = properties or arch_image_properties.get(image_arch)
|
||||
logging.info("Image architecture set to {}".format(image_arch))
|
||||
image_name = image_name or LTS_IMAGE_NAME
|
||||
release = release or LTS_RELEASE
|
||||
image_url = openstack_utils.find_ubuntu_image(
|
||||
release=release,
|
||||
arch='amd64')
|
||||
arch=image_arch)
|
||||
add_image(image_url,
|
||||
glance_client=glance_client,
|
||||
image_name=image_name)
|
||||
image_name=image_name,
|
||||
properties=properties)
|
||||
|
||||
@@ -2036,7 +2036,8 @@ def upload_image_to_glance(glance, local_path, image_name, disk_format='qcow2',
|
||||
return image
|
||||
|
||||
|
||||
def create_image(glance, image_url, image_name, image_cache_dir=None, tags=[]):
|
||||
def create_image(glance, image_url, image_name, image_cache_dir=None, tags=[],
|
||||
properties=None):
|
||||
"""Download the image and upload it to glance.
|
||||
|
||||
Download an image from image_url and upload it to glance labelling
|
||||
@@ -2053,6 +2054,8 @@ def create_image(glance, image_url, image_name, image_cache_dir=None, tags=[]):
|
||||
:type image_cache_dir: Option[str, None]
|
||||
:param tags: Tags to add to image
|
||||
:type tags: list of str
|
||||
:param properties: Properties and values to add to image
|
||||
:type properties: dict
|
||||
:returns: glance image pointer
|
||||
:rtype: glanceclient.common.utils.RequestIdProxy
|
||||
"""
|
||||
@@ -2074,6 +2077,11 @@ def create_image(glance, image_url, image_name, image_cache_dir=None, tags=[]):
|
||||
logging.debug(
|
||||
'applying tag to image: glance.image_tags.update({}, {}) = {}'
|
||||
.format(image.id, tags, result))
|
||||
|
||||
logging.info("Setting image properties: {}".format(properties))
|
||||
if properties:
|
||||
result = glance.images.update(image.id, **properties)
|
||||
|
||||
return image
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user