(self, imagerepo, tag, structure, tmp_imagedir)
return True
Prepare structure with metadata for the image
Prepare structure with metadata for the image
Prepare structure with metadata for the image
def _save_image(self, imagerepo, tag, structure, tmp_imagedir):
        """Prepare structure with metadata for the image"""
        self.localrepo.cd_imagerepo(imagerepo, tag)
        (container_json, layer_files) = self.localrepo.get_image_attributes()
        json_file = tmp_imagedir + "/container.json"
        if (not container_json) or \
           (not self.localrepo.save_json(json_file, container_json)):
            return False
        config_layer_file = str(ChkSUM().sha256(json_file)) + ".json"
        FileUtil(json_file).rename(tmp_imagedir + '/' + config_layer_file)
        manifest_item = dict()
        manifest_item["Config"] = config_layer_file
        manifest_item["RepoTags"] = [imagerepo + ':' + tag, ]
        manifest_item["Layers"] = []
        if imagerepo not in structure["repositories"]:
            structure["repositories"][imagerepo] = dict()
        parent_layer_id = ""
        for layer_f in layer_files:
            try:
                layer_id = re.search(r"^(?:[^:]+:)?([a-z0-9]+)(?:\.layer)?$",
                                     os.path.basename(layer_f)).group(1)
            except AttributeError:
                return False
            if os.path.exists(tmp_imagedir + "/" + layer_id):
                continue
            FileUtil(tmp_imagedir + "/" + layer_id).mkdir()
            if not FileUtil(layer_f).copyto(tmp_imagedir + "/"
                                            + layer_id + "/layer.tar"):
                return False
            manifest_item["Layers"].append(layer_id + "/layer.tar")
            json_string = self.create_container_meta(layer_id)
            if parent_layer_id:
                json_string["parent"] = parent_layer_id
            else:
                structure["repositories"][imagerepo][tag] = layer_id
            parent_layer_id = layer_id
            if not self.localrepo.save_json(tmp_imagedir + "/"
                                            + layer_id + "/json", json_string):
                return False
            if not FileUtil(tmp_imagedir + "/" +
                            layer_id + "/VERSION").putdata("1.0", 'w'):
                return False
        structure["manifest"].append(manifest_item)
        return True
def _save_image ( self , imagerepo , tag , structure , tmp_imagedir ) : self . localrepo . cd_imagerepo ( imagerepo , tag ) ( container_json , layer_files ) = self . localrepo . get_image_attributes ( ) json_file = tmp_imagedir + "/container.json" if ( not container_json ) or ( not self . localrepo . save_json ( json_file , container_json ) ) : return False config_layer_file = str ( ChkSUM ( ) . sha256 ( json_file ) ) + ".json" FileUtil ( json_file ) . rename ( tmp_imagedir + '/' + config_layer_file ) manifest_item = dict ( ) manifest_item [ "Config" ] = config_layer_file manifest_item [ "RepoTags" ] = [ imagerepo + ':' + tag , ] manifest_item [ "Layers" ] = [ ] if imagerepo not in structure [ "repositories" ] : structure [ "repositories" ] [ imagerepo ] = dict ( ) parent_layer_id = "" for layer_f in layer_files : try : layer_id = re . search ( r"^(?:[^:]+:)?([a-z0-9]+)(?:\.layer)?$" , os . path . basename ( layer_f ) ) . group ( 1 ) except AttributeError : return False if os . path . exists ( tmp_imagedir + "/" + layer_id ) : continue FileUtil ( tmp_imagedir + "/" + layer_id ) . mkdir ( ) if not FileUtil ( layer_f ) . copyto ( tmp_imagedir + "/" + layer_id + "/layer.tar" ) : return False manifest_item [ "Layers" ] . append ( layer_id + "/layer.tar" ) json_string = self . create_container_meta ( layer_id ) if parent_layer_id : json_string [ "parent" ] = parent_layer_id else : structure [ "repositories" ] [ imagerepo ] [ tag ] = layer_id parent_layer_id = layer_id if not self . localrepo . save_json ( tmp_imagedir + "/" + layer_id + "/json" , json_string ) : return False if not FileUtil ( tmp_imagedir + "/" + layer_id + "/VERSION" ) . putdata ( "1.0" , 'w' ) : return False structure [ "manifest" ] . append ( manifest_item ) return True