Skip to content
This repository has been archived by the owner on Oct 10, 2020. It is now read-only.

Commit

Permalink
syscontainers: refactor common code
Browse files Browse the repository at this point in the history
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
  • Loading branch information
giuseppe committed Feb 14, 2017
1 parent 1814e5a commit 5e8d4dd
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions Atomic/syscontainers.py
Expand Up @@ -308,6 +308,16 @@ def _checkout(self, repo, name, img, deployment, upgrade, values=None, destinati
pass
raise e

@staticmethod
def _get_image_id_from_manifest(image_manifest):
image_id = None
image_manifest = json.loads(image_manifest)
if 'Digest' in image_manifest:
image_id = image_manifest['Digest']
if 'config' in image_manifest and 'digest' in image_manifest['config']:
image_id = image_manifest['config']['digest']
return SystemContainers._drop_sha256_prefix(image_id)

# Accept both name and version Id, and return the ostree rev
def _resolve_image(self, repo, img, allow_multiple=False):
imagebranch = SystemContainers._get_ostree_image_branch(img)
Expand Down Expand Up @@ -507,12 +517,7 @@ def _write_template(inputfilename, data, values, destination):
image_manifest = self._image_manifest(repo, rev)
image_id = rev
if image_manifest:
image_manifest = json.loads(image_manifest)
if 'Digest' in image_manifest:
image_id = image_manifest['Digest']
if 'config' in image_manifest and 'digest' in image_manifest['config']:
image_id = image_manifest['config']['digest']
image_id = SystemContainers._drop_sha256_prefix(image_id)
image_id = SystemContainers._get_image_id_from_manifest(image_manifest) or image_id

with open(os.path.join(destination, "info"), 'w') as info_file:
info = {"image" : img,
Expand Down Expand Up @@ -838,15 +843,7 @@ def _inspect_system_branch(self, repo, imagebranch):
image_id = commit_rev

if manifest:
manifest = json.loads(manifest)
if 'Labels' in manifest:
labels = manifest['Labels']

if 'config' in manifest:
image_id = manifest['config']['digest']
if 'Digest' in manifest:
image_id = manifest['Digest']
image_id = SystemContainers._drop_sha256_prefix(image_id)
image_id = SystemContainers._get_image_id_from_manifest(manifest) or image_id

if self.user:
image_type = "user"
Expand Down

0 comments on commit 5e8d4dd

Please sign in to comment.