B&R: Save image name and tags present in local registry

During backup save all images in the form 'name:tag'. Save to a list
in the ansible overrides file picked up by restore procedure.

Doing so the images in local registry will be repopulated during
restore. More specific during the bootstrap playbook import of the
restore procedure.

Closes-Bug: 1886152
Depends-On: Ia9b2276e1654b9e413ec5402a9c2e0d804f66f9b
Change-Id: I189428d10c83dae54e2121e6c8f6363fbb14f53a
Signed-off-by: Dan Voiculeasa <dan.voiculeasa@windriver.com>
This commit is contained in:
Dan Voiculeasa 2020-07-02 22:22:25 +03:00
parent fb3840bbad
commit eee995ced9
1 changed files with 21 additions and 0 deletions

View File

@ -10,7 +10,9 @@ import yaml
from sysinv.common import constants
from sysinv.common import service
from sysinv.conductor import rpcapi as conductor_rpcapi
from sysinv.db import api
from sysinv.openstack.common import context
from oslo_config import cfg
from oslo_log import log as logging
@ -24,6 +26,10 @@ CONF = cfg.CONF
def create_host_overrides(filename):
try:
ctxt = context.get_admin_context()
rpcapi = conductor_rpcapi.ConductorAPI(
topic=conductor_rpcapi.MANAGER_TOPIC)
dbapi = api.get_instance()
data = {}
@ -156,6 +162,21 @@ def create_host_overrides(filename):
elif docker.name == constants.SERVICE_PARAM_NAME_DOCKER_HTTPS_PROXY:
data.update({'docker_https_proxy': docker.value})
# Save local registry images tags
temp_image_name_list = rpcapi.docker_registry_image_list(ctxt)
image_name_tag_list = []
for temp_image_name in temp_image_name_list:
image_name = temp_image_name.get('name', None)
if image_name:
temp_image_tags = rpcapi.docker_registry_image_tags(ctxt,
image_name)
for image_name_tag in temp_image_tags:
image_tag = image_name_tag.get('tag', None)
if image_tag:
image_name_tag_list.append("%s:%s" % (image_name, image_tag))
data.update({'additional_local_registry_images': image_name_tag_list})
# Save collected information in file
with open(filename, 'w') as outfile:
yaml.safe_dump(data, outfile, default_flow_style=False)