Skip to content

Commit

Permalink
Merge pull request canonical#6509 from tomponline/tp-storage-instance
Browse files Browse the repository at this point in the history
Storage instance interface
  • Loading branch information
stgraber authored Nov 26, 2019
2 parents 0809f16 + 4762e9c commit a92fdab
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 73 deletions.
38 changes: 19 additions & 19 deletions lxd/storage/backend_lxd.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ func (b *lxdBackend) removeInstanceSnapshotSymlinkIfUnused(instanceType instance
}

// CreateInstance creates an empty instance.
func (b *lxdBackend) CreateInstance(inst Instance, op *operations.Operation) error {
func (b *lxdBackend) CreateInstance(inst instance.Instance, op *operations.Operation) error {
logger := logging.AddContext(b.logger, log.Ctx{"project": inst.Project(), "instance": inst.Name()})
logger.Debug("CreateInstance started")
defer logger.Debug("CreateInstance finished")
Expand Down Expand Up @@ -327,12 +327,12 @@ func (b *lxdBackend) CreateInstance(inst Instance, op *operations.Operation) err
return nil
}

func (b *lxdBackend) CreateInstanceFromBackup(inst Instance, sourcePath string, op *operations.Operation) error {
func (b *lxdBackend) CreateInstanceFromBackup(inst instance.Instance, sourcePath string, op *operations.Operation) error {
return ErrNotImplemented
}

// CreateInstanceFromCopy copies an instance volume and optionally its snapshots to new volume(s).
func (b *lxdBackend) CreateInstanceFromCopy(inst Instance, src Instance, snapshots bool, op *operations.Operation) error {
func (b *lxdBackend) CreateInstanceFromCopy(inst instance.Instance, src instance.Instance, snapshots bool, op *operations.Operation) error {
logger := logging.AddContext(b.logger, log.Ctx{"project": inst.Project(), "instance": inst.Name(), "src": src.Name(), "snapshots": snapshots})
logger.Debug("CreateInstanceFromCopy started")
defer logger.Debug("CreateInstanceFromCopy finished")
Expand Down Expand Up @@ -632,7 +632,7 @@ func (b *lxdBackend) imageFiller(fingerprint string, op *operations.Operation) f
}

// CreateInstanceFromImage creates a new volume for an instance populated with the image requested.
func (b *lxdBackend) CreateInstanceFromImage(inst Instance, fingerprint string, op *operations.Operation) error {
func (b *lxdBackend) CreateInstanceFromImage(inst instance.Instance, fingerprint string, op *operations.Operation) error {
logger := logging.AddContext(b.logger, log.Ctx{"project": inst.Project(), "instance": inst.Name()})
logger.Debug("CreateInstanceFromImage started")
defer logger.Debug("CreateInstanceFromImage finished")
Expand Down Expand Up @@ -703,7 +703,7 @@ func (b *lxdBackend) CreateInstanceFromImage(inst Instance, fingerprint string,

// CreateInstanceFromMigration receives an instance being migrated.
// The args.Name and args.Config fields are ignored and, instance properties are used instead.
func (b *lxdBackend) CreateInstanceFromMigration(inst Instance, conn io.ReadWriteCloser, args migration.VolumeTargetArgs, op *operations.Operation) error {
func (b *lxdBackend) CreateInstanceFromMigration(inst instance.Instance, conn io.ReadWriteCloser, args migration.VolumeTargetArgs, op *operations.Operation) error {
logger := logging.AddContext(b.logger, log.Ctx{"project": inst.Project(), "instance": inst.Name(), "args": args})
logger.Debug("CreateInstanceFromMigration started")
defer logger.Debug("CreateInstanceFromMigration finished")
Expand Down Expand Up @@ -746,7 +746,7 @@ func (b *lxdBackend) CreateInstanceFromMigration(inst Instance, conn io.ReadWrit
}

// RenameInstance renames the instance's root volume and any snapshot volumes.
func (b *lxdBackend) RenameInstance(inst Instance, newName string, op *operations.Operation) error {
func (b *lxdBackend) RenameInstance(inst instance.Instance, newName string, op *operations.Operation) error {
logger := logging.AddContext(b.logger, log.Ctx{"project": inst.Project(), "instance": inst.Name(), "newName": newName})
logger.Debug("RenameInstance started")
defer logger.Debug("RenameInstance finished")
Expand Down Expand Up @@ -853,7 +853,7 @@ func (b *lxdBackend) RenameInstance(inst Instance, newName string, op *operation
}

// DeleteInstance removes the instance's root volume (all snapshots need to be removed first).
func (b *lxdBackend) DeleteInstance(inst Instance, op *operations.Operation) error {
func (b *lxdBackend) DeleteInstance(inst instance.Instance, op *operations.Operation) error {
logger := logging.AddContext(b.logger, log.Ctx{"project": inst.Project(), "instance": inst.Name()})
logger.Debug("DeleteInstance started")
defer logger.Debug("DeleteInstance finished")
Expand Down Expand Up @@ -917,7 +917,7 @@ func (b *lxdBackend) DeleteInstance(inst Instance, op *operations.Operation) err

// MigrateInstance sends an instance volume for migration.
// The args.Name field is ignored and the name of the instance is used instead.
func (b *lxdBackend) MigrateInstance(inst Instance, conn io.ReadWriteCloser, args migration.VolumeSourceArgs, op *operations.Operation) error {
func (b *lxdBackend) MigrateInstance(inst instance.Instance, conn io.ReadWriteCloser, args migration.VolumeSourceArgs, op *operations.Operation) error {
logger := logging.AddContext(b.logger, log.Ctx{"project": inst.Project(), "instance": inst.Name(), "args": args})
logger.Debug("MigrateInstance started")
defer logger.Debug("MigrateInstance finished")
Expand Down Expand Up @@ -948,12 +948,12 @@ func (b *lxdBackend) MigrateInstance(inst Instance, conn io.ReadWriteCloser, arg
return nil
}

func (b *lxdBackend) BackupInstance(inst Instance, targetPath string, optimized bool, snapshots bool, op *operations.Operation) error {
func (b *lxdBackend) BackupInstance(inst instance.Instance, targetPath string, optimized bool, snapshots bool, op *operations.Operation) error {
return ErrNotImplemented
}

// GetInstanceUsage returns the disk usage of the instance's root volume.
func (b *lxdBackend) GetInstanceUsage(inst Instance) (int64, error) {
func (b *lxdBackend) GetInstanceUsage(inst instance.Instance) (int64, error) {
logger := logging.AddContext(b.logger, log.Ctx{"project": inst.Project(), "instance": inst.Name()})
logger.Debug("GetInstanceUsage started")
defer logger.Debug("GetInstanceUsage finished")
Expand All @@ -968,7 +968,7 @@ func (b *lxdBackend) GetInstanceUsage(inst Instance) (int64, error) {
// SetInstanceQuota sets the quota on the instance's root volume.
// Returns ErrRunningQuotaResizeNotSupported if the instance is running and the storage driver
// doesn't support resizing whilst the instance is running.
func (b *lxdBackend) SetInstanceQuota(inst Instance, size string, op *operations.Operation) error {
func (b *lxdBackend) SetInstanceQuota(inst instance.Instance, size string, op *operations.Operation) error {
logger := logging.AddContext(b.logger, log.Ctx{"project": inst.Project(), "instance": inst.Name()})
logger.Debug("SetInstanceQuota started")
defer logger.Debug("SetInstanceQuota finished")
Expand All @@ -990,7 +990,7 @@ func (b *lxdBackend) SetInstanceQuota(inst Instance, size string, op *operations
}

// MountInstance mounts the instance's root volume.
func (b *lxdBackend) MountInstance(inst Instance, op *operations.Operation) (bool, error) {
func (b *lxdBackend) MountInstance(inst instance.Instance, op *operations.Operation) (bool, error) {
logger := logging.AddContext(b.logger, log.Ctx{"project": inst.Project(), "instance": inst.Name()})
logger.Debug("MountInstance started")
defer logger.Debug("MountInstance finished")
Expand All @@ -1008,7 +1008,7 @@ func (b *lxdBackend) MountInstance(inst Instance, op *operations.Operation) (boo
}

// UnmountInstance unmounts the instance's root volume.
func (b *lxdBackend) UnmountInstance(inst Instance, op *operations.Operation) (bool, error) {
func (b *lxdBackend) UnmountInstance(inst instance.Instance, op *operations.Operation) (bool, error) {
logger := logging.AddContext(b.logger, log.Ctx{"project": inst.Project(), "instance": inst.Name()})
logger.Debug("UnmountInstance started")
defer logger.Debug("UnmountInstance finished")
Expand All @@ -1026,7 +1026,7 @@ func (b *lxdBackend) UnmountInstance(inst Instance, op *operations.Operation) (b
}

// GetInstanceDisk returns the location of the disk.
func (b *lxdBackend) GetInstanceDisk(inst Instance) (string, error) {
func (b *lxdBackend) GetInstanceDisk(inst instance.Instance) (string, error) {
if inst.Type() != instancetype.VM {
return "", ErrNotImplemented
}
Expand Down Expand Up @@ -1104,7 +1104,7 @@ func (b *lxdBackend) CreateInstanceSnapshot(inst instance.Instance, src instance
}

// RenameInstanceSnapshot renames an instance snapshot.
func (b *lxdBackend) RenameInstanceSnapshot(inst Instance, newName string, op *operations.Operation) error {
func (b *lxdBackend) RenameInstanceSnapshot(inst instance.Instance, newName string, op *operations.Operation) error {
logger := logging.AddContext(b.logger, log.Ctx{"project": inst.Project(), "instance": inst.Name(), "newName": newName})
logger.Debug("RenameInstanceSnapshot started")
defer logger.Debug("RenameInstanceSnapshot finished")
Expand Down Expand Up @@ -1152,7 +1152,7 @@ func (b *lxdBackend) RenameInstanceSnapshot(inst Instance, newName string, op *o
}

// DeleteInstanceSnapshot removes the snapshot volume for the supplied snapshot instance.
func (b *lxdBackend) DeleteInstanceSnapshot(inst Instance, op *operations.Operation) error {
func (b *lxdBackend) DeleteInstanceSnapshot(inst instance.Instance, op *operations.Operation) error {
logger := logging.AddContext(b.logger, log.Ctx{"project": inst.Project(), "instance": inst.Name()})
logger.Debug("DeleteInstanceSnapshot started")
defer logger.Debug("DeleteInstanceSnapshot finished")
Expand Down Expand Up @@ -1199,13 +1199,13 @@ func (b *lxdBackend) DeleteInstanceSnapshot(inst Instance, op *operations.Operat
return nil
}

func (b *lxdBackend) RestoreInstanceSnapshot(inst Instance, op *operations.Operation) error {
func (b *lxdBackend) RestoreInstanceSnapshot(inst instance.Instance, op *operations.Operation) error {
return ErrNotImplemented
}

// MountInstanceSnapshot mounts an instance snapshot. It is mounted as read only so that the
// snapshot cannot be modified.
func (b *lxdBackend) MountInstanceSnapshot(inst Instance, op *operations.Operation) (bool, error) {
func (b *lxdBackend) MountInstanceSnapshot(inst instance.Instance, op *operations.Operation) (bool, error) {
logger := logging.AddContext(b.logger, log.Ctx{"project": inst.Project(), "instance": inst.Name()})
logger.Debug("MountInstanceSnapshot started")
defer logger.Debug("MountInstanceSnapshot finished")
Expand All @@ -1230,7 +1230,7 @@ func (b *lxdBackend) MountInstanceSnapshot(inst Instance, op *operations.Operati
}

// UnmountInstanceSnapshot unmounts an instance snapshot.
func (b *lxdBackend) UnmountInstanceSnapshot(inst Instance, op *operations.Operation) (bool, error) {
func (b *lxdBackend) UnmountInstanceSnapshot(inst instance.Instance, op *operations.Operation) (bool, error) {
logger := logging.AddContext(b.logger, log.Ctx{"project": inst.Project(), "instance": inst.Name()})
logger.Debug("UnmountInstanceSnapshot started")
defer logger.Debug("UnmountInstanceSnapshot finished")
Expand Down
38 changes: 19 additions & 19 deletions lxd/storage/backend_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,87 +59,87 @@ func (b *mockBackend) Unmount() (bool, error) {
return true, nil
}

func (b *mockBackend) CreateInstance(i Instance, op *operations.Operation) error {
func (b *mockBackend) CreateInstance(inst instance.Instance, op *operations.Operation) error {
return nil
}

func (b *mockBackend) CreateInstanceFromBackup(i Instance, sourcePath string, op *operations.Operation) error {
func (b *mockBackend) CreateInstanceFromBackup(inst instance.Instance, sourcePath string, op *operations.Operation) error {
return nil
}

func (b *mockBackend) CreateInstanceFromCopy(i Instance, src Instance, snapshots bool, op *operations.Operation) error {
func (b *mockBackend) CreateInstanceFromCopy(inst instance.Instance, src instance.Instance, snapshots bool, op *operations.Operation) error {
return nil
}

func (b *mockBackend) CreateInstanceFromImage(i Instance, fingerprint string, op *operations.Operation) error {
func (b *mockBackend) CreateInstanceFromImage(inst instance.Instance, fingerprint string, op *operations.Operation) error {
return nil
}

func (b *mockBackend) CreateInstanceFromMigration(inst Instance, conn io.ReadWriteCloser, args migration.VolumeTargetArgs, op *operations.Operation) error {
func (b *mockBackend) CreateInstanceFromMigration(inst instance.Instance, conn io.ReadWriteCloser, args migration.VolumeTargetArgs, op *operations.Operation) error {
return nil
}

func (b *mockBackend) RenameInstance(i Instance, newName string, op *operations.Operation) error {
func (b *mockBackend) RenameInstance(inst instance.Instance, newName string, op *operations.Operation) error {
return nil
}

func (b *mockBackend) DeleteInstance(i Instance, op *operations.Operation) error {
func (b *mockBackend) DeleteInstance(inst instance.Instance, op *operations.Operation) error {
return nil
}

func (b *mockBackend) MigrateInstance(inst Instance, conn io.ReadWriteCloser, args migration.VolumeSourceArgs, op *operations.Operation) error {
func (b *mockBackend) MigrateInstance(inst instance.Instance, conn io.ReadWriteCloser, args migration.VolumeSourceArgs, op *operations.Operation) error {
return nil
}

func (b *mockBackend) RefreshInstance(i instance.Instance, src instance.Instance, srcSnapshots []instance.Instance, op *operations.Operation) error {
return nil
}

func (b *mockBackend) BackupInstance(i Instance, targetPath string, optimized bool, snapshots bool, op *operations.Operation) error {
func (b *mockBackend) BackupInstance(inst instance.Instance, targetPath string, optimized bool, snapshots bool, op *operations.Operation) error {
return nil
}

func (b *mockBackend) GetInstanceUsage(i Instance) (int64, error) {
func (b *mockBackend) GetInstanceUsage(inst instance.Instance) (int64, error) {
return 0, nil
}

func (b *mockBackend) SetInstanceQuota(i Instance, size string, op *operations.Operation) error {
func (b *mockBackend) SetInstanceQuota(inst instance.Instance, size string, op *operations.Operation) error {
return nil
}

func (b *mockBackend) MountInstance(i Instance, op *operations.Operation) (bool, error) {
func (b *mockBackend) MountInstance(inst instance.Instance, op *operations.Operation) (bool, error) {
return true, nil
}

func (b *mockBackend) UnmountInstance(i Instance, op *operations.Operation) (bool, error) {
func (b *mockBackend) UnmountInstance(inst instance.Instance, op *operations.Operation) (bool, error) {
return true, nil
}

func (b *mockBackend) GetInstanceDisk(i Instance) (string, error) {
func (b *mockBackend) GetInstanceDisk(inst instance.Instance) (string, error) {
return "", nil
}

func (b *mockBackend) CreateInstanceSnapshot(i instance.Instance, src instance.Instance, op *operations.Operation) error {
return nil
}

func (b *mockBackend) RenameInstanceSnapshot(i Instance, newName string, op *operations.Operation) error {
func (b *mockBackend) RenameInstanceSnapshot(inst instance.Instance, newName string, op *operations.Operation) error {
return nil
}

func (b *mockBackend) DeleteInstanceSnapshot(i Instance, op *operations.Operation) error {
func (b *mockBackend) DeleteInstanceSnapshot(inst instance.Instance, op *operations.Operation) error {
return nil
}

func (b *mockBackend) RestoreInstanceSnapshot(i Instance, op *operations.Operation) error {
func (b *mockBackend) RestoreInstanceSnapshot(inst instance.Instance, op *operations.Operation) error {
return nil
}

func (b *mockBackend) MountInstanceSnapshot(i Instance, op *operations.Operation) (bool, error) {
func (b *mockBackend) MountInstanceSnapshot(inst instance.Instance, op *operations.Operation) (bool, error) {
return true, nil
}

func (b *mockBackend) UnmountInstanceSnapshot(i Instance, op *operations.Operation) (bool, error) {
func (b *mockBackend) UnmountInstanceSnapshot(inst instance.Instance, op *operations.Operation) (bool, error) {
return true, nil
}

Expand Down
3 changes: 2 additions & 1 deletion lxd/storage/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"strings"

"github.com/lxc/lxd/lxd/db"
"github.com/lxc/lxd/lxd/instance"
"github.com/lxc/lxd/lxd/operations"
"github.com/lxc/lxd/lxd/state"
"github.com/lxc/lxd/lxd/storage/drivers"
Expand Down Expand Up @@ -151,7 +152,7 @@ func GetPoolByName(state *state.State, name string) (Pool, error) {
// GetPoolByInstance retrieves the pool from the database using the instance's pool.
// If the pool's driver is not recognised then drivers.ErrUnknownDriver is returned. If the pool's
// driver does not support the instance's type then drivers.ErrNotImplemented is returned.
func GetPoolByInstance(s *state.State, inst Instance) (Pool, error) {
func GetPoolByInstance(s *state.State, inst instance.Instance) (Pool, error) {
poolName, err := s.Cluster.InstancePool(inst.Project(), inst.Name())
if err != nil {
return nil, err
Expand Down
Loading

0 comments on commit a92fdab

Please sign in to comment.