def _identifier_as_cid(self, identifier): """ Returns a container uuid for identifier. If identifier is an image UUID or image tag, create a temporary container and return its uuid. """ def __cname_matches(container, identifier): return any([ n for n in (container['Names'] or []) if matches(n, '/' + identifier) ]) # Determine if identifier is a container containers = [ c['Id'] for c in self.d.containers(all=True) if (__cname_matches(c, identifier) or matches(c['Id'], identifier + '*')) ] if len(containers) > 1: raise SelectionMatchError(identifier, containers) elif len(containers) == 1: c = containers[0] return c if self.live else self._clone(c) # Determine if identifier is an image UUID images = [ i for i in set(self.d.images(all=True, quiet=True)) if i.startswith(identifier) ] if len(images) > 1: raise SelectionMatchError(identifier, images) elif len(images) == 1: return self._create_temp_container(images[0]) # Check if identifier is fully qualified # local import only from Atomic.objects.image import Image _image = Image(identifier) if _image.fully_qualified: return self._create_temp_container(identifier) # Match image tag. images = util.image_by_name(identifier) if len(images) > 1: tags = [t for i in images for t in i['RepoTags']] raise SelectionMatchError(identifier, tags) elif len(images) == 1: return self._create_temp_container(images[0]['Id'].replace( "sha256:", "")) raise MountError('{} did not match any image or container.' ''.format(identifier))
def _make_image(self, image, img_struct, deep=False, remote=False): img_obj = Image(image, remote=remote) img_obj.backend = self if not remote: img_obj.id = img_struct['Id'] img_obj.repotags = img_struct['RepoTags'] img_obj.created = img_struct['Created'] img_obj.size = img_struct['Size'] img_obj.virtual_size = img_struct['VirtualSize'] img_obj.original_structure = img_struct if deep: img_obj.deep = True img_obj.repotags = img_struct['RepoTags'] img_obj.config = img_struct['Config'] or {} img_obj.labels = img_obj.config.get("Labels", None) img_obj.os = img_struct['Os'] img_obj.arch = img_struct['Architecture'] img_obj.graph_driver = img_struct['GraphDriver'] img_obj.version = img_obj.get_label('Version') img_obj.release = img_obj.get_label('Release') img_obj.parent = img_struct['Parent'] img_obj.original_structure = img_struct img_obj.cmd = img_obj.original_structure['Config']['Cmd'] return img_obj
def _make_image(self, image, info, remote=False): img_obj = Image(image, backend=self, remote=remote) if remote: return img_obj name = info['Id'] img_obj.input_name = image img_obj.name = image img_obj.config = info img_obj.backend = self img_obj.id = name img_obj.registry, img_obj.repo, img_obj.image, img_obj.tag, _ = Decompose( image).all img_obj.repotags = info['RepoTags'] img_obj.created = info['Created'] img_obj.size = None img_obj.original_structure = info img_obj.deep = True img_obj.labels = info.get('Labels', None) img_obj.version = img_obj.get_label("Version") img_obj.release = img_obj.get_label("Release") ostree_manifest = self.syscontainers.get_manifest(image) if ostree_manifest: ostree_manifest = json_loads(ostree_manifest) img_obj.digest = None if ostree_manifest is None else ostree_manifest.get( 'Digest') or ostree_manifest.get('digest') img_obj.os = img_obj.get_label("Os") img_obj.arch = img_obj.get_label("Arch") img_obj.graph_driver = None return img_obj
def _make_image(self, image, info, remote=False): img_obj = Image(image, backend=self, remote=remote) if remote: return img_obj name = info['Id'] img_obj.input_name = image img_obj.name = image img_obj.config = info img_obj.backend = self img_obj.id = name img_obj.registry, img_obj.repo, img_obj.image, img_obj.tag, _ = Decompose(image).all img_obj.repotags = info['RepoTags'] img_obj.created = info['Created'] img_obj.size = info.get('VirtualSize', None) img_obj.virtual_size = info.get('VirtualSize', None) img_obj.original_structure = info img_obj.deep = True img_obj.labels = info.get('Labels', None) img_obj.version = img_obj.get_label("Version") img_obj.release = img_obj.get_label("Release") ostree_manifest = self.syscontainers.get_manifest(image) if ostree_manifest: ostree_manifest = json_loads(ostree_manifest) img_obj.digest = None if ostree_manifest is None else ostree_manifest.get('Digest') or ostree_manifest.get('digest') img_obj.os = img_obj.get_label("Os") img_obj.arch = img_obj.get_label("Arch") img_obj.graph_driver = None return img_obj
def _make_image(self, image, img_struct, deep=False, remote=False): img_obj = Image(image, remote=remote) img_obj.backend = self if not remote and not deep: img_obj.size = img_struct['size'] img_obj.virtual_size = img_obj.size img_obj.version = img_obj.version img_obj.repotags = img_struct['names'] if not remote: try: img_obj.id = img_struct['id'] except KeyError: img_obj.id = img_struct['ID'] try: img_obj.created = DT.datetime.strptime( img_struct['created'], "%b %d, %Y %H:%M").strftime("%Y-%m-%d %H:%M") except KeyError: img_obj.created = time.mktime( time.strptime(img_struct['Created'].split(".")[0], "%Y-%m-%dT%H:%M:%S")) try: img_obj.size = img_struct['size'] except KeyError: img_obj.size = img_struct['Size'] try: img_obj.digest = img_struct['digest'] except KeyError: img_obj.digest = img_struct['Digest'] if deep: img_obj.deep = True img_obj.repotags = img_struct['Tags'] img_obj.config = img_struct['Config'] or {} img_obj.labels = img_obj.config.get("Labels", None) img_obj.os = img_struct['OS'] img_obj.arch = img_struct['Architecture'] img_obj.graph_driver = img_struct['GraphDriver'] img_obj.version = img_obj.get_label('Version') img_obj.release = img_obj.get_label('Release') # kpod inspect has no Parent right now #img_obj.parent = img_struct['Parent'] img_obj.original_structure = img_struct img_obj.cmd = img_obj.original_structure['Config']['Cmd'] return img_obj
def _make_image(self, image, img_struct, deep=False, remote=False): img_obj = Image(image, remote=remote) img_obj.backend = self if not remote: img_obj.id = img_struct["Id"] img_obj.repotags = img_struct["RepoTags"] img_obj.created = img_struct["Created"] img_obj.size = img_struct["Size"] img_obj.virtual_size = img_struct["VirtualSize"] img_obj.original_structure = img_struct if deep: img_obj.deep = True img_obj.repotags = img_struct["RepoTags"] img_obj.config = img_struct["Config"] or {} img_obj.labels = img_obj.config.get("Labels", None) img_obj.os = img_struct["Os"] img_obj.arch = img_struct["Architecture"] img_obj.graph_driver = img_struct["GraphDriver"] img_obj.version = img_obj.get_label("Version") img_obj.release = img_obj.get_label("Release") img_obj.parent = img_struct["Parent"] img_obj.original_structure = img_struct img_obj.cmd = img_obj.original_structure["Config"]["Cmd"] return img_obj
def _make_image(self, image, info): name = info['Id'] img_obj = Image(image, backend=self, remote=False) img_obj.input_name = image img_obj.name = image img_obj.config = info img_obj.backend = self img_obj.id = name img_obj.registry = None img_obj.repo = None img_obj.image = name img_obj.tag = name img_obj.repotags = info['RepoTags'] img_obj.created = info['Created'] img_obj.size = None img_obj.original_structure = info img_obj.deep = True img_obj.labels = info['Labels'] img_obj.version = img_obj.get_label("Version") img_obj.release = img_obj.get_label("Release") img_obj.digest = None img_obj.os = img_obj.get_label("Os") img_obj.arch = img_obj.get_label("Arch") img_obj.graph_driver = None return img_obj
def _make_image(self, image, info): name = info['Id'] image = Image(image, backend=self, remote=False) image.name = name image.config = info image.backend = self image.id = name image.registry = None image.repo = None image.image = name image.tag = name image.repotags = info['RepoTags'] image.created = info['Created'] image.size = None image.original_structure = info image.input_name = info['Id'] image.deep = True image.labels = info['Labels'] image.version = image.get_label("Version") image.release = image.get_label("Release") image.digest = None image.os = image.get_label("Os") image.arch = image.get_label("Arch") image.graph_driver = None return image
def _make_image(self, image, img_struct, deep=False, remote=False): img_obj = Image(image, remote=remote) img_obj.backend = self if not remote and not deep: img_obj.size = img_struct['size'] img_obj.virtual_size = img_obj.size img_obj.version = img_obj.version img_obj.repotags = img_struct['names'] if not remote: try: img_obj.id = img_struct['id'] except KeyError: img_obj.id = img_struct['ID'] try: img_obj.created = DT.datetime.strptime(img_struct['created'], "%b %d, %Y %H:%M").strftime("%Y-%m-%d %H:%M") except KeyError: img_obj.created = time.mktime(time.strptime(img_struct['Created'].split(".")[0], "%Y-%m-%dT%H:%M:%S")) try: img_obj.size = img_struct['size'] except KeyError: img_obj.size = img_struct['Size'] try: img_obj.digest = img_struct['digest'] except KeyError: img_obj.digest = img_struct['Digest'] if deep: img_obj.deep = True img_obj.repotags = img_struct['Tags'] img_obj.config = img_struct['Config'] or {} img_obj.labels = img_obj.config.get("Labels", None) img_obj.os = img_struct['OS'] img_obj.arch = img_struct['Architecture'] img_obj.graph_driver = img_struct['GraphDriver'] img_obj.version = img_obj.get_label('Version') img_obj.release = img_obj.get_label('Release') # kpod inspect has no Parent right now #img_obj.parent = img_struct['Parent'] img_obj.original_structure = img_struct img_obj.cmd = img_obj.original_structure['Config']['Cmd'] return img_obj