Merge "make glance driver support image:tag"
This commit is contained in:
commit
620f1b43ac
@ -285,6 +285,8 @@ class Manager(periodic_task.PeriodicTasks):
|
||||
try:
|
||||
if image['driver'] == 'glance':
|
||||
self.driver.read_tar_image(image)
|
||||
if image['tag'] != tag:
|
||||
LOG.warning("The input tag is different from the tag in tar")
|
||||
container = self.driver.create(context, container, image,
|
||||
requested_networks,
|
||||
requested_volumes)
|
||||
|
@ -35,13 +35,13 @@ class GlanceDriver(driver.ContainerImageDriver):
|
||||
def __init__(self):
|
||||
super(GlanceDriver, self).__init__()
|
||||
|
||||
def _search_image_on_host(self, context, repo):
|
||||
def _search_image_on_host(self, context, repo, tag):
|
||||
LOG.debug('Searching for image %s locally', repo)
|
||||
images_directory = CONF.glance.images_directory
|
||||
try:
|
||||
# TODO(mkrai): Change this to search image entry in zun db
|
||||
# after the image endpoint is merged.
|
||||
image_meta = utils.find_image(context, repo)
|
||||
image_meta = utils.find_image(context, repo, tag)
|
||||
except exception.ImageNotFound:
|
||||
return None
|
||||
if image_meta:
|
||||
@ -75,7 +75,7 @@ class GlanceDriver(driver.ContainerImageDriver):
|
||||
# TODO(shubhams): glance driver does not handle tags
|
||||
# once metadata is stored in db then handle tags
|
||||
image_loaded = False
|
||||
image = self._search_image_on_host(context, repo)
|
||||
image = self._search_image_on_host(context, repo, tag)
|
||||
|
||||
if not common_utils.should_pull_image(image_pull_policy, bool(image)):
|
||||
if image:
|
||||
@ -89,7 +89,7 @@ class GlanceDriver(driver.ContainerImageDriver):
|
||||
|
||||
LOG.debug('Pulling image from glance %s', repo)
|
||||
try:
|
||||
image_meta = utils.find_image(context, repo)
|
||||
image_meta = utils.find_image(context, repo, tag)
|
||||
LOG.debug('Image %s was found in glance, downloading now...', repo)
|
||||
image_chunks = utils.download_image_in_chunks(context,
|
||||
image_meta.id)
|
||||
@ -119,7 +119,7 @@ class GlanceDriver(driver.ContainerImageDriver):
|
||||
LOG.debug('Searching image in glance %s', repo)
|
||||
try:
|
||||
# TODO(hongbin): find image by both repo and tag
|
||||
return utils.find_images(context, repo, exact_match)
|
||||
return utils.find_images(context, repo, tag, exact_match)
|
||||
except Exception as e:
|
||||
raise exception.ZunException(six.text_type(e))
|
||||
|
||||
|
@ -34,12 +34,12 @@ def create_glanceclient(context):
|
||||
return osc.glance()
|
||||
|
||||
|
||||
def find_image(context, image_ident):
|
||||
matches = find_images(context, image_ident, exact_match=True)
|
||||
def find_image(context, image_ident, tag):
|
||||
matches = find_images(context, image_ident, tag, exact_match=True)
|
||||
LOG.debug('Found matches %s ', matches)
|
||||
if len(matches) == 0:
|
||||
raise exception.ImageNotFound(image=image_ident)
|
||||
if len(matches) > 1:
|
||||
if len(matches) > 1 and tag != 'latest':
|
||||
msg = ("Multiple images exist with same name "
|
||||
"%(image_ident)s. Please use the image id "
|
||||
"instead.") % {'image_ident': image_ident}
|
||||
@ -47,7 +47,7 @@ def find_image(context, image_ident):
|
||||
return matches[0]
|
||||
|
||||
|
||||
def find_images(context, image_ident, exact_match):
|
||||
def find_images(context, image_ident, tag, exact_match):
|
||||
glance = create_glanceclient(context)
|
||||
if uuidutils.is_uuid_like(image_ident):
|
||||
images = []
|
||||
@ -59,8 +59,15 @@ def find_images(context, image_ident, exact_match):
|
||||
# ignore exception
|
||||
pass
|
||||
else:
|
||||
filters = {'container_format': 'docker'}
|
||||
images = list(glance.images.list(filters=filters))
|
||||
kwargs = {}
|
||||
kwargs['sort-dir'] = 'desc'
|
||||
kwargs['sort-key'] = 'updated_at'
|
||||
if tag == 'latest':
|
||||
filters = {'container_format': 'docker'}
|
||||
else:
|
||||
filters = {'container_format': 'docker', 'tag': [tag]}
|
||||
kwargs['filters'] = filters
|
||||
images = list(glance.images.list(**kwargs))
|
||||
if exact_match:
|
||||
images = [i for i in images if i.name == image_ident]
|
||||
else:
|
||||
|
Loading…
x
Reference in New Issue
Block a user