def wipe(self, _f=None): """Wipe the volume""" self._get_registered_object('auth').assert_user_type('ClusterUser', allow_indirect=True) System.perform_dd(source=System.WIPE, destination=self.get_path(), size=self.get_size())
def create(self, size, _f=None): """Create volume in storage backend""" self._get_registered_object('auth').assert_permission(PERMISSIONS.MANAGE_STORAGE_VOLUME) # Ensure volume does not already exist if self.check_exists(): raise VolumeAlreadyExistsError('Volume (%s) already exists' % self.name) try: # Create on local node System.perform_dd(source=System.WIPE, destination=self.get_path(), size=size) except DDCommandError, exc: raise ExternalStorageCommandErrorException( "Error whilst creating disk logical volume:\n" + str(exc) )
def duplicate(self, destination_vm_object, storage_backend=None): """Clone the hard drive and attach it to the new VM object""" self.ensure_exists() if not storage_backend: storage_backend = self.storage_backend # Create new disk object, using the same type, size and disk_id new_hdd = self._get_registered_object('hard_drive_factory').create( size=self.get_size(), storage_type=self.get_type(), driver=self.driver, storage_backend=storage_backend) # Get path of source and new disks source_block_device = self._getDiskPath() destination_block_device = new_hdd.getDiskPath() # Use dd to duplicate the old disk to the new disk System.perform_dd(source=source_block_device, destination=destination_block_device, size=self.get_size()) return new_hdd