예제 #1
0
func (d *diskDeployer) migrateDisk(
	originalDisk bidisk.Disk,
	diskPool bideplmanifest.DiskPool,
	vm VM,
	stage biui.Stage,
) (newDisk bidisk.Disk, err error) {
	d.logger.Debug(d.logTag, "Migrating disk '%s'", originalDisk.CID())

	err = stage.Perform("Creating disk", func() error {
		newDisk, err = d.diskManager.Create(diskPool, vm.CID())
		return err
	})
	if err != nil {
		return newDisk, err
	}

	stageName := fmt.Sprintf("Attaching disk '%s' to VM '%s'", newDisk.CID(), vm.CID())
	err = stage.Perform(stageName, func() error {
		return vm.AttachDisk(newDisk)
	})
	if err != nil {
		return newDisk, err
	}

	stageName = fmt.Sprintf("Migrating disk content from '%s' to '%s'", originalDisk.CID(), newDisk.CID())
	err = stage.Perform(stageName, func() error {
		return vm.MigrateDisk()
	})
	if err != nil {
		return newDisk, err
	}

	err = d.updateCurrentDiskRecord(newDisk)
	if err != nil {
		return newDisk, err
	}

	stageName = fmt.Sprintf("Detaching disk '%s'", originalDisk.CID())
	err = stage.Perform(stageName, func() error {
		return vm.DetachDisk(originalDisk)
	})
	if err != nil {
		return newDisk, err
	}

	stageName = fmt.Sprintf("Deleting disk '%s'", originalDisk.CID())
	err = stage.Perform(stageName, func() error {
		return originalDisk.Delete()
	})
	if err != nil {
		return newDisk, err
	}

	return newDisk, nil
}
예제 #2
0
func (d *deployment) deleteDisk(deleteStage biui.Stage, disk bidisk.Disk) error {
	stepName := fmt.Sprintf("Deleting disk '%s'", disk.CID())
	return deleteStage.Perform(stepName, func() error {
		err := disk.Delete()
		cloudErr, ok := err.(bicloud.Error)
		if ok && cloudErr.Type() == bicloud.DiskNotFoundError {
			return biui.NewSkipStageError(cloudErr, "Disk not found")
		}
		return err
	})
}