Exemple #1
0
 def get_resource(self, disk_id):
     datastore = self.get_datastore(disk_id)
     if datastore is None:
         raise DiskNotFoundException(disk_id)
     resource = Disk(disk_id)
     resource.flavor = Flavor("default")  # TODO
     resource.persistent = False  # TODO
     resource.new_disk = False
     resource.capacity_gb = -1  # TODO
     resource.image = None
     resource.datastore = datastore
     return resource
    def get_resource(self, disk_id):
        datastore = self.get_datastore(disk_id)
        if datastore is None:
            raise DiskNotFoundException(disk_id)

        size = os.path.getsize(self._disk_path(datastore, disk_id))

        resource = Disk(disk_id)
        resource.flavor = Flavor("default")
        resource.persistent = False
        resource.new_disk = False
        # Every one byte in fake world equals to one G byte in real world
        resource.capacity_gb = size
        resource.image = None
        resource.datastore = datastore
        return resource
 def copy_disk(self,
               source_datastore,
               source,
               dest_datastore,
               dest,
               force=False):
     if not self.hypervisor.image_manager.check_image(
             source, source_datastore):
         raise DiskNotFoundException("ENOENT")
     dest_file = self._disk_path(dest_datastore, dest)
     image_file = self.hypervisor.image_manager.image_file(
         source_datastore, source)
     self._check_free_space(dest_datastore, os.path.getsize(image_file))
     if not force:
         # force allows overwriting existing destination
         self._assert_not_exists(dest, dest_datastore)
     mkdir_p(os.path.dirname(dest_file))
     with open(dest_file, "a") as f:
         image_file = self.hypervisor.image_manager.image_file(
             source_datastore, source)
         f.truncate(os.path.getsize(image_file))
 def _assert_exists(self, name, datastore):
     if not os.path.exists(self._disk_path(datastore, name)):
         self._logger.warning("disk in datastore (%s,%s) doesn't exist" %
                              (name, datastore))
         raise DiskNotFoundException("ENOENT")