Beispiel #1
0
 def destroy(self):
     path = self.path
     if zfs_destroy(self.zfs_filesystem, recursive=True) != 0:
         raise OCIError('Could not destroy zfs filesystem (%s)' %
                        self.zfs_filesystem)
     if path is not None:
         rm(path)
Beispiel #2
0
 def commit(self, changeset_file_path):
     zfs_snapshot('diff', self.zfs_filesystem)
     self.save_changeset(changeset_file_path)
     diff_id = sha256sum(changeset_file_path)
     if diff_id is None:
         raise OCIError('Could not get hash of file (%s)' %
                        str(changeset_file_path))
     previous_path = self.path
     zfs_set(self.zfs_filesystem, mountpoint='none')
     rm(previous_path)
     return diff_id
 def destroy_config(self):
     log.debug('Start removing image (%s) config' % self.id)
     if self.config is None:
         raise OCIError('Image (%s) has no config' % self.id)
     config_descriptor = self.manifest.get('Config')
     config_digest = config_descriptor.get('Digest')
     config_id = digest_to_id(config_digest)
     configs_path = pathlib.Path(oci_config['global']['path'], 'configs')
     config_file_path = configs_path.joinpath(config_id)
     rm(config_file_path)
     self.config = None
     log.info('Deleted config: %s' % config_digest)
     log.debug('Finish removing image (%s) config' % self.id)
 def destroy(self):
     log.debug('Start destroying layer (%s)' % self.id)
     layers_path = pathlib.Path(oci_config['global']['path'], 'layers')
     layer_file_path = layers_path.joinpath(self.id)
     rm(layer_file_path)
     layer_digest = self.digest
     layer_id = self.id
     self.descriptor = None
     self.filesystem = None
     self.diff_id = None
     self.size = None
     log.info('Deleted layer: %s' % layer_digest)
     log.debug('Finish destroying layer (%s)' % layer_id)
 def destroy_manifest(self):
     log.debug('Start removing image (%s) manifest' % self.id)
     if self.manifest is None:
         raise OCIError('Image (%s) has no manifest' % self.id)
     self.remove_layers()
     self.destroy_config()
     manifests_path = pathlib.Path(oci_config['global']['path'],
                                   'manifests')
     manifest_digest = self.digest
     manifest_file_path = manifests_path.joinpath(self.id)
     rm(manifest_file_path)
     self.manifest = None
     log.info('Deleted manifest: %s' % manifest_digest)
     log.debug('Finish removing image (%s) manifest' % self.id)
Beispiel #6
0
 def mount(self, container_id, path):
     if self.container_id is not None:
         if self.container_id == container_id:
             log.warning(
                 'Filesystem (%s) already mounted for container (%s)' %
                 (self.id, container_id))
             if self.path != path:
                 raise OCIError('Filesystem (%s) path (%s) should be (%s)' %
                                (self.id, self.path, path))
         else:
             raise OCIError(
                 'Filesystem (%s) already mounted for container (%s)' %
                 (self.id, self.container_id))
     else:
         self.container_id = container_id
         previous_path = self.path
         zfs_set(self.zfs_filesystem, mountpoint=path)
         rm(previous_path)
Beispiel #7
0
 def load_changeset(self, changeset_file_path):
     log.debug('Start loading changeset (%s)' % str(changeset_file_path))
     path = self.path
     size = 0
     with tarfile.open(changeset_file_path, "r") as tar_file:
         for member in tar_file:
             file_path = pathlib.Path(member.name)
             if file_path.name.startswith('.wh.'):
                 file_path = path.joinpath(file_path)
                 if file_path.name == '.wh..wh..opq':
                     rm(file_path.parent, recursive=True)
                 else:
                     file_path = file_path.parent.joinpath(
                         file_path.name[4:])
                     rm(file_path)
             else:
                 size += member.size
                 tar_file.extract(member, path)
     log.debug('Finish loading changeset (%s), size: %s' %
               (str(changeset_file_path), humanize.naturalsize(size)))
Beispiel #8
0
 def destroy(self, remove_filesystem=True):
     container_id = self.id
     log.debug('Start destroying container (%s)' % container_id)
     container_status = self.status()
     if container_status != 'exited':
         self.delete_container()
     Driver().unmount_filesystem(self.id, remove=remove_filesystem)
     container_path = pathlib.Path(oci_config['global']['path'], 'containers', self.id)
     rm(container_path.joinpath('config.json'))
     rootfs_path = pathlib.Path(self.config.get('Root').get('Path'))
     if self.config.get('Platform').get('OS') == 'SunOS':
         rm(rootfs_path.joinpath('root'))
     rm(rootfs_path)
     rm(container_path)
     self.config = None
     self.id = None
     self.name = None
     self.create_time = None
     log.debug('Finish destroying container (%s)' % container_id)