[lxc-devel] [lxd/master] Add new storage interfaces

stgraber on Github lxc-bot at linuxcontainers.org
Fri Oct 4 23:04:28 UTC 2019


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 379 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20191004/142e130b/attachment.bin>
-------------- next part --------------
From 205f1be16c93ff0b342638563e78ee0e7c9ab369 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Fri, 4 Oct 2019 19:02:38 -0400
Subject: [PATCH] lxd/storage: Add new interfaces
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxd/migration/interfaces.go      | 12 ++++
 lxd/storage/drivers/interface.go | 43 +++++++++++++++
 lxd/storage/interfaces.go        | 95 ++++++++++++++++++++++++++++++++
 3 files changed, 150 insertions(+)
 create mode 100644 lxd/migration/interfaces.go
 create mode 100644 lxd/storage/drivers/interface.go
 create mode 100644 lxd/storage/interfaces.go

diff --git a/lxd/migration/interfaces.go b/lxd/migration/interfaces.go
new file mode 100644
index 0000000000..7264e9ef91
--- /dev/null
+++ b/lxd/migration/interfaces.go
@@ -0,0 +1,12 @@
+package migration
+
+// FIXME: empty stubs until we're ready to move the migration code over
+
+type SourceArgs struct {
+}
+
+type SinkArgs struct {
+}
+
+type StorageSourceDriver interface {
+}
diff --git a/lxd/storage/drivers/interface.go b/lxd/storage/drivers/interface.go
new file mode 100644
index 0000000000..a552f93d66
--- /dev/null
+++ b/lxd/storage/drivers/interface.go
@@ -0,0 +1,43 @@
+package drivers
+
+import (
+	"github.com/lxc/lxd/lxd/migration"
+	"github.com/lxc/lxd/lxd/operations"
+	"github.com/lxc/lxd/shared/api"
+)
+
+// VolumeType represents a storage volume type.
+type VolumeType string
+
+// VolumeTypeCustom represents a custom storage volume.
+const VolumeTypeCustom = VolumeType("custom")
+
+// VolumeTypeContainer represents a container storage volume.
+const VolumeTypeContainer = VolumeType("containers")
+
+// VolumeTypeImage represents an image storage volume.
+const VolumeTypeImage = VolumeType("images")
+
+// VolumeTypeVM represents a virtual-machine storage volume.
+const VolumeTypeVM = VolumeType("virtual-machines")
+
+// Driver repreents a low-level storage driver.
+type Driver interface {
+    // Internal
+    Name() string
+    Version() string
+
+    // Pool
+    Delete(op *operations.Operation) error
+    Mount() (bool, error)
+    Unmount() (bool, error)
+    GetResources() (*api.ResourcesStoragePool, error)
+
+    // Volumes
+    DeleteVolume(volType VolumeType, name string, op *operations.Operation) (error)
+    RenameVolume(volType VolumeType, name string, newName string, op *operations.Operation) (error)
+
+    // Migration
+    MigrationType() migration.MigrationFSType
+    PreservesInodes() bool
+}
diff --git a/lxd/storage/interfaces.go b/lxd/storage/interfaces.go
new file mode 100644
index 0000000000..421dc900f0
--- /dev/null
+++ b/lxd/storage/interfaces.go
@@ -0,0 +1,95 @@
+package storage
+
+import (
+	"github.com/gorilla/websocket"
+
+	"github.com/lxc/lxd/lxd/instance/instancetype"
+	"github.com/lxc/lxd/lxd/migration"
+	"github.com/lxc/lxd/lxd/operations"
+	"github.com/lxc/lxd/lxd/state"
+	"github.com/lxc/lxd/lxd/storage/drivers"
+	"github.com/lxc/lxd/shared/api"
+)
+
+// Instance represents the storage relevant subset of a LXD instance
+type Instance interface {
+	Name() string
+	Project() string
+	Type() instancetype.Type
+	Path() string
+
+	IsRunning() bool
+	Snapshots() ([]Instance, error)
+	TemplateApply(trigger string) error
+}
+
+// Pool represents a LXD storage pool
+type Pool interface {
+    // Internal
+    DaemonState() *state.State
+
+    // Pool
+    ID() int64
+    Name() string
+    Driver() drivers.Driver
+
+    GetResources() (*api.ResourcesStoragePool, error)
+    Delete(op *operations.Operation) error
+
+    Mount() (bool, error)
+    Unmount() (bool, error)
+
+    // Instances
+    CreateInstance(i Instance, op *operations.Operation) error
+    CreateInstanceFromBackup(i Instance, sourcePath string, op *operations.Operation) error
+    CreateInstanceFromCopy(i Instance, src Instance, snapshots bool, op *operations.Operation) error
+    CreateInstanceFromImage(i Instance, fingerprint string, op *operations.Operation) error
+    CreateInstanceFromMigration(i Instance, conn *websocket.Conn, args migration.SinkArgs, op *operations.Operation) error
+    RenameInstance(i Instance, newName string, op *operations.Operation) error
+    DeleteInstance(i Instance, op *operations.Operation) error
+
+    MigrateInstance(i Instance, snapshots bool, args migration.SourceArgs) (migration.StorageSourceDriver, error)
+    RefreshInstance(i Instance, src Instance, snapshots bool, op *operations.Operation) error
+    BackupInstance(i Instance, targetPath string, optimized bool, snapshots bool, op *operations.Operation) error
+
+    GetInstanceUsage(i Instance) (uint64, error)
+    SetInstanceQuota(i Instance, quota uint64) error
+
+    MountInstance(i Instance) (bool, error)
+    UnmountInstance(i Instance) (bool, error)
+    GetInstanceDisk(i Instance) (string, string, error)
+
+    // Instance snapshots
+    CreateInstanceSnapshot(i Instance, name string, op *operations.Operation) error
+    RenameInstanceSnapshot(i Instance, newName string, op *operations.Operation) error
+    DeleteInstanceSnapshot(i Instance, op *operations.Operation) error
+
+    RestoreInstanceSnapshot(i Instance, op *operations.Operation) error
+
+    MountInstanceSnapshot(i Instance) (bool, error)
+    UnmountInstanceSnapshot(i Instance) (bool, error)
+
+    // Images
+    CreateImage(img api.Image, op *operations.Operation) error
+    DeleteImage(img api.Image, op *operations.Operation) error
+
+    // Custom volumes
+    CreateCustomVolume(vol api.StorageVolume, op *operations.Operation) error
+    CreateCustomVolumeFromCopy(vol api.StorageVolume, src api.StorageVolume, snapshots bool, op *operations.Operation) error
+    CreateCustomVolumeFromMigration(vol api.StorageVolume, conn *websocket.Conn, args migration.SinkArgs, op *operations.Operation) error
+    RenameCustomVolume(vol api.StorageVolume, newName string, op *operations.Operation) error
+    DeleteCustomVolume(vol api.StorageVolume, op *operations.Operation) error
+
+    MigrateCustomVolume(vol api.StorageVolume, snapshots bool, args migration.SourceArgs) (migration.StorageSourceDriver, error)
+
+    GetCustomVolumeUsage(vol api.StorageVolume) (uint64, error)
+    SetCustomVolumeQuota(vol api.StorageVolume, quota uint64) error
+
+    MountCustomVolume(vol api.StorageVolume) (bool, error)
+    UnmountCustomVolume(vol api.StorageVolume) (bool, error)
+
+    // Custom volume snapshots
+    CreateCustomVolumeSnapshot(vol api.StorageVolume, name string, op *operations.Operation) error
+    RenameCustomVolumeSnapshot(vol api.StorageVolume, newName string, op *operations.Operation) error
+    DeleteCustomVolumeSnapshot(vol api.StorageVolume, op *operations.Operation) error
+}


More information about the lxc-devel mailing list