[lxc-devel] [lxd/master] Rename db function names part 6
freeekanayaka on Github
lxc-bot at linuxcontainers.org
Thu May 7 15:29:42 UTC 2020
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 301 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200507/6f075ff4/attachment-0001.bin>
-------------- next part --------------
From b076363fce0261029062991c33986c688fc9ff14 Mon Sep 17 00:00:00 2001
From: Free Ekanayaka <free.ekanayaka at canonical.com>
Date: Thu, 7 May 2020 15:44:04 +0100
Subject: [PATCH 01/11] lxd/db: Rename StoragePoolVolumeGetType to
GetStoragePoolVolume
Signed-off-by: Free Ekanayaka <free.ekanayaka at canonical.com>
---
lxd/db/storage_pools_export_test.go | 2 +-
lxd/db/storage_pools_test.go | 10 +++++-----
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/lxd/db/storage_pools_export_test.go b/lxd/db/storage_pools_export_test.go
index 6a83c10bc3..1225bc0c71 100644
--- a/lxd/db/storage_pools_export_test.go
+++ b/lxd/db/storage_pools_export_test.go
@@ -4,6 +4,6 @@ package db
import "github.com/lxc/lxd/shared/api"
-func (c *Cluster) StoragePoolVolumeGetType(project string, volumeName string, volumeType int, poolID, nodeID int64) (int64, *api.StorageVolume, error) {
+func (c *Cluster) GetStoragePoolVolume(project string, volumeName string, volumeType int, poolID, nodeID int64) (int64, *api.StorageVolume, error) {
return c.storagePoolVolumeGetType(project, volumeName, volumeType, poolID, nodeID)
}
diff --git a/lxd/db/storage_pools_test.go b/lxd/db/storage_pools_test.go
index 15ef1abf2c..f7f8b9e564 100644
--- a/lxd/db/storage_pools_test.go
+++ b/lxd/db/storage_pools_test.go
@@ -173,12 +173,12 @@ func TestStoragePoolVolume_Ceph(t *testing.T) {
// The returned volume ID is the one of the volume created on the local
// node (node 1).
- thisVolumeID, _, err := cluster.StoragePoolVolumeGetType("default", "v1", 1, poolID, 1)
+ thisVolumeID, _, err := cluster.GetStoragePoolVolume("default", "v1", 1, poolID, 1)
require.NoError(t, err)
assert.Equal(t, volumeID, thisVolumeID)
// Another volume was created for the second node.
- _, volume, err := cluster.StoragePoolVolumeGetType("default", "v1", 1, poolID, 2)
+ _, volume, err := cluster.GetStoragePoolVolume("default", "v1", 1, poolID, 2)
require.NoError(t, err)
assert.NotNil(t, volume)
assert.Equal(t, config, volume.Config)
@@ -188,7 +188,7 @@ func TestStoragePoolVolume_Ceph(t *testing.T) {
err = cluster.UpdateStoragePoolVolume("default", "v1", 1, poolID, "volume 1", config)
require.NoError(t, err)
for _, nodeID := range []int64{1, 2} {
- _, volume, err := cluster.StoragePoolVolumeGetType("default", "v1", 1, poolID, nodeID)
+ _, volume, err := cluster.GetStoragePoolVolume("default", "v1", 1, poolID, nodeID)
require.NoError(t, err)
assert.Equal(t, "volume 1", volume.Description)
assert.Equal(t, config, volume.Config)
@@ -196,7 +196,7 @@ func TestStoragePoolVolume_Ceph(t *testing.T) {
err = cluster.RenameStoragePoolVolume("default", "v1", "v1-new", 1, poolID)
require.NoError(t, err)
for _, nodeID := range []int64{1, 2} {
- _, volume, err := cluster.StoragePoolVolumeGetType("default", "v1-new", 1, poolID, nodeID)
+ _, volume, err := cluster.GetStoragePoolVolume("default", "v1-new", 1, poolID, nodeID)
require.NoError(t, err)
assert.NotNil(t, volume)
}
@@ -206,7 +206,7 @@ func TestStoragePoolVolume_Ceph(t *testing.T) {
err = cluster.RemoveStoragePoolVolume("default", "v1-new", 1, poolID)
require.NoError(t, err)
for _, nodeID := range []int64{1, 2} {
- _, volume, err := cluster.StoragePoolVolumeGetType("default", "v1-new", 1, poolID, nodeID)
+ _, volume, err := cluster.GetStoragePoolVolume("default", "v1-new", 1, poolID, nodeID)
assert.Equal(t, db.ErrNoSuchObject, err)
assert.Nil(t, volume)
}
From 35650e75d0a89bde4eb2fd384c740d14cd4fa796 Mon Sep 17 00:00:00 2001
From: Free Ekanayaka <free.ekanayaka at canonical.com>
Date: Thu, 7 May 2020 16:11:54 +0100
Subject: [PATCH 02/11] lxd/db: Rename StoragePoolVolumeSnapshotCreate to
CreateStorageVolumeSnapshot
Signed-off-by: Free Ekanayaka <free.ekanayaka at canonical.com>
---
lxd/db/storage_pools_test.go | 2 +-
lxd/db/storage_volume_snapshots.go | 4 ++--
lxd/instance/drivers/driver_lxc.go | 2 +-
lxd/instance/drivers/driver_qemu.go | 2 +-
lxd/patches.go | 8 ++++----
lxd/storage/utils.go | 2 +-
lxd/storage_volumes_snapshot.go | 2 +-
7 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/lxd/db/storage_pools_test.go b/lxd/db/storage_pools_test.go
index f7f8b9e564..29372a48e4 100644
--- a/lxd/db/storage_pools_test.go
+++ b/lxd/db/storage_pools_test.go
@@ -225,7 +225,7 @@ func TestCreateStoragePoolVolume_Snapshot(t *testing.T) {
require.NoError(t, err)
config = map[string]string{"k": "v"}
- _, err = cluster.StoragePoolVolumeSnapshotCreate("default", "v1/snap0", "", 1, poolID, config, time.Time{})
+ _, err = cluster.CreateStorageVolumeSnapshot("default", "v1/snap0", "", 1, poolID, config, time.Time{})
require.NoError(t, err)
n := cluster.StorageVolumeNextSnapshot("v1", 1, "snap%d")
diff --git a/lxd/db/storage_volume_snapshots.go b/lxd/db/storage_volume_snapshots.go
index 213dfbb543..aac12762c6 100644
--- a/lxd/db/storage_volume_snapshots.go
+++ b/lxd/db/storage_volume_snapshots.go
@@ -14,9 +14,9 @@ import (
"github.com/lxc/lxd/shared"
)
-// StoragePoolVolumeSnapshotCreate creates a new storage volume snapshot attached to a given
+// CreateStorageVolumeSnapshot creates a new storage volume snapshot attached to a given
// storage pool.
-func (c *Cluster) StoragePoolVolumeSnapshotCreate(project, volumeName, volumeDescription string, volumeType int, poolID int64, volumeConfig map[string]string, expiryDate time.Time) (int64, error) {
+func (c *Cluster) CreateStorageVolumeSnapshot(project, volumeName, volumeDescription string, volumeType int, poolID int64, volumeConfig map[string]string, expiryDate time.Time) (int64, error) {
var thisVolumeID int64
var snapshotName string
diff --git a/lxd/instance/drivers/driver_lxc.go b/lxd/instance/drivers/driver_lxc.go
index 00236f0dcc..ff4f3d700a 100644
--- a/lxd/instance/drivers/driver_lxc.go
+++ b/lxd/instance/drivers/driver_lxc.go
@@ -235,7 +235,7 @@ func lxcCreate(s *state.State, args db.InstanceArgs) (instance.Instance, error)
// Create a new database entry for the container's storage volume
if c.IsSnapshot() {
- _, err = s.Cluster.StoragePoolVolumeSnapshotCreate(args.Project, args.Name, "", db.StoragePoolVolumeTypeContainer, poolID, volumeConfig, time.Time{})
+ _, err = s.Cluster.CreateStorageVolumeSnapshot(args.Project, args.Name, "", db.StoragePoolVolumeTypeContainer, poolID, volumeConfig, time.Time{})
} else {
_, err = s.Cluster.CreateStoragePoolVolume(args.Project, args.Name, "", db.StoragePoolVolumeTypeContainer, poolID, volumeConfig)
}
diff --git a/lxd/instance/drivers/driver_qemu.go b/lxd/instance/drivers/driver_qemu.go
index 3c2c81f83d..f13f89db4b 100644
--- a/lxd/instance/drivers/driver_qemu.go
+++ b/lxd/instance/drivers/driver_qemu.go
@@ -246,7 +246,7 @@ func qemuCreate(s *state.State, args db.InstanceArgs) (instance.Instance, error)
// Create a new database entry for the instance's storage volume.
if vm.IsSnapshot() {
- _, err = s.Cluster.StoragePoolVolumeSnapshotCreate(args.Project, args.Name, "", db.StoragePoolVolumeTypeVM, poolID, volumeConfig, time.Time{})
+ _, err = s.Cluster.CreateStorageVolumeSnapshot(args.Project, args.Name, "", db.StoragePoolVolumeTypeVM, poolID, volumeConfig, time.Time{})
} else {
_, err = s.Cluster.CreateStoragePoolVolume(args.Project, args.Name, "", db.StoragePoolVolumeTypeVM, poolID, volumeConfig)
diff --git a/lxd/patches.go b/lxd/patches.go
index 616d918e79..7c72cc536a 100644
--- a/lxd/patches.go
+++ b/lxd/patches.go
@@ -658,7 +658,7 @@ func upgradeFromStorageTypeBtrfs(name string, d *Daemon, defaultPoolName string,
}
} else if err == db.ErrNoSuchObject {
// Insert storage volumes for containers into the database.
- _, err := d.cluster.StoragePoolVolumeSnapshotCreate("default", cs, "", db.StoragePoolVolumeTypeContainer, poolID, snapshotPoolVolumeConfig, time.Time{})
+ _, err := d.cluster.CreateStorageVolumeSnapshot("default", cs, "", db.StoragePoolVolumeTypeContainer, poolID, snapshotPoolVolumeConfig, time.Time{})
if err != nil {
logger.Errorf("Could not insert a storage volume for snapshot \"%s\"", cs)
return err
@@ -977,7 +977,7 @@ func upgradeFromStorageTypeDir(name string, d *Daemon, defaultPoolName string, d
}
} else if err == db.ErrNoSuchObject {
// Insert storage volumes for containers into the database.
- _, err := d.cluster.StoragePoolVolumeSnapshotCreate("default", cs, "", db.StoragePoolVolumeTypeContainer, poolID, snapshotPoolVolumeConfig, time.Time{})
+ _, err := d.cluster.CreateStorageVolumeSnapshot("default", cs, "", db.StoragePoolVolumeTypeContainer, poolID, snapshotPoolVolumeConfig, time.Time{})
if err != nil {
logger.Errorf("Could not insert a storage volume for snapshot \"%s\"", cs)
return err
@@ -1330,7 +1330,7 @@ func upgradeFromStorageTypeLvm(name string, d *Daemon, defaultPoolName string, d
}
} else if err == db.ErrNoSuchObject {
// Insert storage volumes for containers into the database.
- _, err := d.cluster.StoragePoolVolumeSnapshotCreate("default", cs, "", db.StoragePoolVolumeTypeContainer, poolID, snapshotPoolVolumeConfig, time.Time{})
+ _, err := d.cluster.CreateStorageVolumeSnapshot("default", cs, "", db.StoragePoolVolumeTypeContainer, poolID, snapshotPoolVolumeConfig, time.Time{})
if err != nil {
logger.Errorf("Could not insert a storage volume for snapshot \"%s\"", cs)
return err
@@ -1791,7 +1791,7 @@ func upgradeFromStorageTypeZfs(name string, d *Daemon, defaultPoolName string, d
}
} else if err == db.ErrNoSuchObject {
// Insert storage volumes for containers into the database.
- _, err := d.cluster.StoragePoolVolumeSnapshotCreate("default", cs, "", db.StoragePoolVolumeTypeContainer, poolID, snapshotPoolVolumeConfig, time.Time{})
+ _, err := d.cluster.CreateStorageVolumeSnapshot("default", cs, "", db.StoragePoolVolumeTypeContainer, poolID, snapshotPoolVolumeConfig, time.Time{})
if err != nil {
logger.Errorf("Could not insert a storage volume for snapshot \"%s\"", cs)
return err
diff --git a/lxd/storage/utils.go b/lxd/storage/utils.go
index 8d9925606c..587cc4b4c5 100644
--- a/lxd/storage/utils.go
+++ b/lxd/storage/utils.go
@@ -157,7 +157,7 @@ func VolumeDBCreate(s *state.State, project, poolName, volumeName, volumeDescrip
// Create the database entry for the storage volume.
if snapshot {
- _, err = s.Cluster.StoragePoolVolumeSnapshotCreate(project, volumeName, volumeDescription, volumeType, poolID, volumeConfig, expiryDate)
+ _, err = s.Cluster.CreateStorageVolumeSnapshot(project, volumeName, volumeDescription, volumeType, poolID, volumeConfig, expiryDate)
} else {
_, err = s.Cluster.CreateStoragePoolVolume(project, volumeName, volumeDescription, volumeType, poolID, volumeConfig)
}
diff --git a/lxd/storage_volumes_snapshot.go b/lxd/storage_volumes_snapshot.go
index a61b3760ea..c5abaa154d 100644
--- a/lxd/storage_volumes_snapshot.go
+++ b/lxd/storage_volumes_snapshot.go
@@ -730,7 +730,7 @@ func autoCreateCustomVolumeSnapshots(ctx context.Context, d *Daemon, volumes []d
return
}
- _, err = d.cluster.StoragePoolVolumeSnapshotCreate(v.ProjectName, snapshotName, v.Description, db.StoragePoolVolumeTypeCustom, poolID, v.Config, expiry)
+ _, err = d.cluster.CreateStorageVolumeSnapshot(v.ProjectName, snapshotName, v.Description, db.StoragePoolVolumeTypeCustom, poolID, v.Config, expiry)
if err != nil {
logger.Error("Error creating volume snaphost", log.Ctx{"err": err, "volume": v})
}
From 12109f3a21164c3efa48857e6c6f75006a62fb28 Mon Sep 17 00:00:00 2001
From: Free Ekanayaka <free.ekanayaka at canonical.com>
Date: Thu, 7 May 2020 16:12:55 +0100
Subject: [PATCH 03/11] lxd/db: Rename StoragePoolVolumeSnapshotUpdateByProject
to UpdateStoragePoolVolumeSnapshot
Signed-off-by: Free Ekanayaka <free.ekanayaka at canonical.com>
---
lxd/db/storage_volume_snapshots.go | 4 ++--
lxd/storage/backend_lxd.go | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/lxd/db/storage_volume_snapshots.go b/lxd/db/storage_volume_snapshots.go
index aac12762c6..6341e03766 100644
--- a/lxd/db/storage_volume_snapshots.go
+++ b/lxd/db/storage_volume_snapshots.go
@@ -87,8 +87,8 @@ func (c *Cluster) CreateStorageVolumeSnapshot(project, volumeName, volumeDescrip
return thisVolumeID, err
}
-// StoragePoolVolumeSnapshotUpdateByProject updates the storage volume snapshot attached to a given storage pool.
-func (c *Cluster) StoragePoolVolumeSnapshotUpdateByProject(project, volumeName string, volumeType int, poolID int64, volumeDescription string, volumeConfig map[string]string, expiryDate time.Time) error {
+// UpdateStorageVolumeSnapshot updates the storage volume snapshot attached to a given storage pool.
+func (c *Cluster) UpdateStorageVolumeSnapshot(project, volumeName string, volumeType int, poolID int64, volumeDescription string, volumeConfig map[string]string, expiryDate time.Time) error {
volumeID, _, err := c.GetLocalStoragePoolVolume(project, volumeName, volumeType, poolID)
if err != nil {
return err
diff --git a/lxd/storage/backend_lxd.go b/lxd/storage/backend_lxd.go
index dcc23a2c23..b4907e077d 100644
--- a/lxd/storage/backend_lxd.go
+++ b/lxd/storage/backend_lxd.go
@@ -2682,7 +2682,7 @@ func (b *lxdBackend) UpdateCustomVolumeSnapshot(projectName string, volName stri
// Update the database if description changed. Use current config.
if newDesc != curVol.Description || newExpiryDate != curExpiryDate {
- err = b.state.Cluster.StoragePoolVolumeSnapshotUpdateByProject(projectName, volName, db.StoragePoolVolumeTypeCustom, b.ID(), newDesc, curVol.Config, newExpiryDate)
+ err = b.state.Cluster.UpdateStorageVolumeSnapshot(projectName, volName, db.StoragePoolVolumeTypeCustom, b.ID(), newDesc, curVol.Config, newExpiryDate)
if err != nil {
return err
}
From 46929d477ef0f7f5f80a88ef849264fc3eac5043 Mon Sep 17 00:00:00 2001
From: Free Ekanayaka <free.ekanayaka at canonical.com>
Date: Thu, 7 May 2020 16:15:56 +0100
Subject: [PATCH 04/11] lxd/db: Rename StorageVolumeSnapshotExpiryGet to
GetStorageVolumeSnapshotExpiry
Signed-off-by: Free Ekanayaka <free.ekanayaka at canonical.com>
---
lxd/db/storage_volume_snapshots.go | 4 ++--
lxd/storage/backend_lxd.go | 2 +-
lxd/storage_volumes_snapshot.go | 4 ++--
3 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/lxd/db/storage_volume_snapshots.go b/lxd/db/storage_volume_snapshots.go
index 6341e03766..605d280749 100644
--- a/lxd/db/storage_volume_snapshots.go
+++ b/lxd/db/storage_volume_snapshots.go
@@ -126,8 +126,8 @@ func (c *Cluster) UpdateStorageVolumeSnapshot(project, volumeName string, volume
return err
}
-// StorageVolumeSnapshotExpiryGet gets the expiry date of a storage volume snapshot.
-func (c *Cluster) StorageVolumeSnapshotExpiryGet(volumeID int64) (time.Time, error) {
+// GetStorageVolumeSnapshotExpiry gets the expiry date of a storage volume snapshot.
+func (c *Cluster) GetStorageVolumeSnapshotExpiry(volumeID int64) (time.Time, error) {
var expiry time.Time
query := "SELECT expiry_date FROM storage_volumes_snapshots WHERE id=?"
diff --git a/lxd/storage/backend_lxd.go b/lxd/storage/backend_lxd.go
index b4907e077d..2f1215b32a 100644
--- a/lxd/storage/backend_lxd.go
+++ b/lxd/storage/backend_lxd.go
@@ -2668,7 +2668,7 @@ func (b *lxdBackend) UpdateCustomVolumeSnapshot(projectName string, volName stri
return err
}
- curExpiryDate, err := b.state.Cluster.StorageVolumeSnapshotExpiryGet(volID)
+ curExpiryDate, err := b.state.Cluster.GetStorageVolumeSnapshotExpiry(volID)
if err != nil {
return err
}
diff --git a/lxd/storage_volumes_snapshot.go b/lxd/storage_volumes_snapshot.go
index c5abaa154d..781a423576 100644
--- a/lxd/storage_volumes_snapshot.go
+++ b/lxd/storage_volumes_snapshot.go
@@ -374,7 +374,7 @@ func storagePoolVolumeSnapshotTypeGet(d *Daemon, r *http.Request) response.Respo
return response.SmartError(err)
}
- expiry, err := d.cluster.StorageVolumeSnapshotExpiryGet(volID)
+ expiry, err := d.cluster.GetStorageVolumeSnapshotExpiry(volID)
if err != nil {
return response.SmartError(err)
}
@@ -442,7 +442,7 @@ func storagePoolVolumeSnapshotTypePut(d *Daemon, r *http.Request) response.Respo
return response.SmartError(err)
}
- expiry, err := d.cluster.StorageVolumeSnapshotExpiryGet(volID)
+ expiry, err := d.cluster.GetStorageVolumeSnapshotExpiry(volID)
if err != nil {
return response.SmartError(err)
}
From ffd6fa84543722e1f8eff1465004e2cd7f0adbc0 Mon Sep 17 00:00:00 2001
From: Free Ekanayaka <free.ekanayaka at canonical.com>
Date: Thu, 7 May 2020 16:16:54 +0100
Subject: [PATCH 05/11] lxd/db: Rename StorageVolumeSnapshotsGetExpired to
GetExpiredStorageVolumeSnapshots
Signed-off-by: Free Ekanayaka <free.ekanayaka at canonical.com>
---
lxd/db/storage_volume_snapshots.go | 4 ++--
lxd/storage_volumes_snapshot.go | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/lxd/db/storage_volume_snapshots.go b/lxd/db/storage_volume_snapshots.go
index 605d280749..9be3f5048c 100644
--- a/lxd/db/storage_volume_snapshots.go
+++ b/lxd/db/storage_volume_snapshots.go
@@ -145,8 +145,8 @@ func (c *Cluster) GetStorageVolumeSnapshotExpiry(volumeID int64) (time.Time, err
return expiry, nil
}
-// StorageVolumeSnapshotsGetExpired returns a list of expired volume snapshots.
-func (c *Cluster) StorageVolumeSnapshotsGetExpired() ([]StorageVolumeArgs, error) {
+// GetExpiredStorageVolumeSnapshots returns a list of expired volume snapshots.
+func (c *Cluster) GetExpiredStorageVolumeSnapshots() ([]StorageVolumeArgs, error) {
var result []StorageVolumeArgs
var volumeName string
var snapshotName string
diff --git a/lxd/storage_volumes_snapshot.go b/lxd/storage_volumes_snapshot.go
index 781a423576..252cbe1171 100644
--- a/lxd/storage_volumes_snapshot.go
+++ b/lxd/storage_volumes_snapshot.go
@@ -556,7 +556,7 @@ func storagePoolVolumeSnapshotTypeDelete(d *Daemon, r *http.Request) response.Re
func pruneExpireCustomVolumeSnapshotsTask(d *Daemon) (task.Func, task.Schedule) {
f := func(ctx context.Context) {
// Get the list of expired custom volume snapshots.
- expiredSnapshots, err := d.cluster.StorageVolumeSnapshotsGetExpired()
+ expiredSnapshots, err := d.cluster.GetExpiredStorageVolumeSnapshots()
if err != nil {
logger.Error("Unable to retrieve the list of expired custom volume snapshots", log.Ctx{"err": err})
return
From abb6b408c973795d4eed4d1bd8b3c6a2173d2ed6 Mon Sep 17 00:00:00 2001
From: Free Ekanayaka <free.ekanayaka at canonical.com>
Date: Thu, 7 May 2020 16:18:30 +0100
Subject: [PATCH 06/11] lxd/db: Rename StorageVolumeNodeAddresses to
GetStorageVolumeNodeAddresses
Signed-off-by: Free Ekanayaka <free.ekanayaka at canonical.com>
---
lxd/cluster/connect.go | 2 +-
lxd/db/storage_volumes.go | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/lxd/cluster/connect.go b/lxd/cluster/connect.go
index ef45505957..92eda9bba4 100644
--- a/lxd/cluster/connect.go
+++ b/lxd/cluster/connect.go
@@ -93,7 +93,7 @@ func ConnectIfVolumeIsRemote(cluster *db.Cluster, poolID int64, volumeName strin
var addresses []string // Node addresses
err := cluster.Transaction(func(tx *db.ClusterTx) error {
var err error
- addresses, err = tx.StorageVolumeNodeAddresses(poolID, "default", volumeName, volumeType)
+ addresses, err = tx.GetStorageVolumeNodeAddresses(poolID, "default", volumeName, volumeType)
return err
})
if err != nil {
diff --git a/lxd/db/storage_volumes.go b/lxd/db/storage_volumes.go
index c1aba1c0a6..58bcec3823 100644
--- a/lxd/db/storage_volumes.go
+++ b/lxd/db/storage_volumes.go
@@ -39,13 +39,13 @@ type StorageVolumeArgs struct {
ProjectName string
}
-// StorageVolumeNodeAddresses returns the addresses of all nodes on which the
+// GetStorageVolumeNodeAddresses returns the addresses of all nodes on which the
// volume with the given name if defined.
//
// The volume name can be either a regular name or a volume snapshot name.
//
// The empty string is used in place of the address of the current node.
-func (c *ClusterTx) StorageVolumeNodeAddresses(poolID int64, project, name string, typ int) ([]string, error) {
+func (c *ClusterTx) GetStorageVolumeNodeAddresses(poolID int64, project, name string, typ int) ([]string, error) {
nodes := []struct {
id int64
address string
From b13b0b96cd52d676973cb893089f570590e0adc9 Mon Sep 17 00:00:00 2001
From: Free Ekanayaka <free.ekanayaka at canonical.com>
Date: Thu, 7 May 2020 16:19:42 +0100
Subject: [PATCH 07/11] lxd/db: Rename StorageVolumeDescriptionGet to
GetStorageVolumeDescription
Signed-off-by: Free Ekanayaka <free.ekanayaka at canonical.com>
---
lxd/db/storage_pools.go | 2 +-
lxd/db/storage_volumes.go | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/lxd/db/storage_pools.go b/lxd/db/storage_pools.go
index d7b243e409..bbb59d1d8c 100644
--- a/lxd/db/storage_pools.go
+++ b/lxd/db/storage_pools.go
@@ -932,7 +932,7 @@ func (c *Cluster) storagePoolVolumeGetType(project string, volumeName string, vo
return -1, nil, err
}
- volumeDescription, err := c.StorageVolumeDescriptionGet(volumeID)
+ volumeDescription, err := c.GetStorageVolumeDescription(volumeID)
if err != nil {
return -1, nil, err
}
diff --git a/lxd/db/storage_volumes.go b/lxd/db/storage_volumes.go
index 58bcec3823..5c46dd3b3d 100644
--- a/lxd/db/storage_volumes.go
+++ b/lxd/db/storage_volumes.go
@@ -148,8 +148,8 @@ func (c *Cluster) storageVolumeConfigGet(volumeID int64, isSnapshot bool) (map[s
return config, nil
}
-// StorageVolumeDescriptionGet gets the description of a storage volume.
-func (c *Cluster) StorageVolumeDescriptionGet(volumeID int64) (string, error) {
+// GetStorageVolumeDescription gets the description of a storage volume.
+func (c *Cluster) GetStorageVolumeDescription(volumeID int64) (string, error) {
description := sql.NullString{}
query := "SELECT description FROM storage_volumes_all WHERE id=?"
inargs := []interface{}{volumeID}
From 8899de8ffbb1e7feff5342ac72c988f90a8afed3 Mon Sep 17 00:00:00 2001
From: Free Ekanayaka <free.ekanayaka at canonical.com>
Date: Thu, 7 May 2020 16:22:32 +0100
Subject: [PATCH 08/11] addresses
Signed-off-by: Free Ekanayaka <free.ekanayaka at canonical.com>
---
lxd/db/storage_volumes_test.go | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lxd/db/storage_volumes_test.go b/lxd/db/storage_volumes_test.go
index ae7bd7592e..3e13fc5f68 100644
--- a/lxd/db/storage_volumes_test.go
+++ b/lxd/db/storage_volumes_test.go
@@ -29,7 +29,7 @@ func TestStorageVolumeNodeAddresses(t *testing.T) {
addVolume(t, tx, poolID, nodeID3, "volume2")
addVolume(t, tx, poolID, nodeID2, "volume2")
- addresses, err := tx.StorageVolumeNodeAddresses(poolID, "default", "volume1", 1)
+ addresses, err := tx.GetStorageVolumeNodeAddresses(poolID, "default", "volume1", 1)
require.NoError(t, err)
assert.Equal(t, []string{"", "1.2.3.4:666"}, addresses)
From abdb472e88e14954dbd24740c165ee26373524ca Mon Sep 17 00:00:00 2001
From: Free Ekanayaka <free.ekanayaka at canonical.com>
Date: Thu, 7 May 2020 16:22:57 +0100
Subject: [PATCH 09/11] lxd/db: Rename StorageVolumeNextSnapshot to
GetNextStorageVolumeSnapshotIndex
Signed-off-by: Free Ekanayaka <free.ekanayaka at canonical.com>
---
lxd/db/storage_pools_test.go | 2 +-
lxd/db/storage_volumes.go | 4 ++--
lxd/storage_volumes_snapshot.go | 6 +++---
3 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/lxd/db/storage_pools_test.go b/lxd/db/storage_pools_test.go
index 29372a48e4..7aa75c1eec 100644
--- a/lxd/db/storage_pools_test.go
+++ b/lxd/db/storage_pools_test.go
@@ -228,7 +228,7 @@ func TestCreateStoragePoolVolume_Snapshot(t *testing.T) {
_, err = cluster.CreateStorageVolumeSnapshot("default", "v1/snap0", "", 1, poolID, config, time.Time{})
require.NoError(t, err)
- n := cluster.StorageVolumeNextSnapshot("v1", 1, "snap%d")
+ n := cluster.GetNextStorageVolumeSnapshotIndex("v1", 1, "snap%d")
assert.Equal(t, n, 1)
}
diff --git a/lxd/db/storage_volumes.go b/lxd/db/storage_volumes.go
index 5c46dd3b3d..f4439bbf09 100644
--- a/lxd/db/storage_volumes.go
+++ b/lxd/db/storage_volumes.go
@@ -166,12 +166,12 @@ func (c *Cluster) GetStorageVolumeDescription(volumeID int64) (string, error) {
return description.String, nil
}
-// StorageVolumeNextSnapshot returns the index of the next snapshot of the storage
+// GetNextStorageVolumeSnapshotIndex returns the index of the next snapshot of the storage
// volume with the given name should have.
//
// Note, the code below doesn't deal with snapshots of snapshots.
// To do that, we'll need to weed out based on # slashes in names
-func (c *Cluster) StorageVolumeNextSnapshot(name string, typ int, pattern string) int {
+func (c *Cluster) GetNextStorageVolumeSnapshotIndex(name string, typ int, pattern string) int {
q := fmt.Sprintf(`
SELECT storage_volumes_snapshots.name FROM storage_volumes_snapshots
JOIN storage_volumes ON storage_volumes_snapshots.storage_volume_id=storage_volumes.id
diff --git a/lxd/storage_volumes_snapshot.go b/lxd/storage_volumes_snapshot.go
index 252cbe1171..22aa0ab8ed 100644
--- a/lxd/storage_volumes_snapshot.go
+++ b/lxd/storage_volumes_snapshot.go
@@ -79,7 +79,7 @@ func storagePoolVolumeSnapshotsTypePost(d *Daemon, r *http.Request) response.Res
// Get a snapshot name.
if req.Name == "" {
- i := d.cluster.StorageVolumeNextSnapshot(volumeName, volumeType, "snap%d")
+ i := d.cluster.GetNextStorageVolumeSnapshotIndex(volumeName, volumeType, "snap%d")
req.Name = fmt.Sprintf("snap%d", i)
}
@@ -766,7 +766,7 @@ func volumeDetermineNextSnapshotName(d *Daemon, volume db.StorageVolumeArgs, def
if count > 1 {
return "", fmt.Errorf("Snapshot pattern may contain '%%d' only once")
} else if count == 1 {
- i := d.cluster.StorageVolumeNextSnapshot(volume.Name, db.StoragePoolVolumeTypeCustom, pattern)
+ i := d.cluster.GetNextStorageVolumeSnapshotIndex(volume.Name, db.StoragePoolVolumeTypeCustom, pattern)
return strings.Replace(pattern, "%d", strconv.Itoa(i), 1), nil
}
@@ -814,7 +814,7 @@ func volumeDetermineNextSnapshotName(d *Daemon, volume db.StorageVolumeArgs, def
}
if snapshotExists {
- i := d.cluster.StorageVolumeNextSnapshot(volume.Name, db.StoragePoolVolumeTypeCustom, pattern)
+ i := d.cluster.GetNextStorageVolumeSnapshotIndex(volume.Name, db.StoragePoolVolumeTypeCustom, pattern)
return strings.Replace(pattern, "%d", strconv.Itoa(i), 1), nil
}
From 06df1ddc5bb37607b030b4fdffea215b7f4bc626 Mon Sep 17 00:00:00 2001
From: Free Ekanayaka <free.ekanayaka at canonical.com>
Date: Thu, 7 May 2020 16:24:48 +0100
Subject: [PATCH 10/11] lxd/db: Rename StorageVolumeCleanupImages to
RemoveStorageVolumeImages
Signed-off-by: Free Ekanayaka <free.ekanayaka at canonical.com>
---
lxd/db/storage_volumes.go | 5 +++--
lxd/patches.go | 2 +-
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/lxd/db/storage_volumes.go b/lxd/db/storage_volumes.go
index f4439bbf09..56563e0757 100644
--- a/lxd/db/storage_volumes.go
+++ b/lxd/db/storage_volumes.go
@@ -347,8 +347,9 @@ SELECT storage_volumes_all.id
return ids64, nil
}
-// StorageVolumeCleanupImages removes the volumes with the given fingerprints.
-func (c *Cluster) StorageVolumeCleanupImages(fingerprints []string) error {
+// RemoveStorageVolumeImages removes the volumes associated with the images
+// with the given fingerprints.
+func (c *Cluster) RemoveStorageVolumeImages(fingerprints []string) error {
stmt := fmt.Sprintf(
"DELETE FROM storage_volumes WHERE type=? AND name NOT IN %s",
query.Params(len(fingerprints)))
diff --git a/lxd/patches.go b/lxd/patches.go
index 7c72cc536a..a40fc4fe26 100644
--- a/lxd/patches.go
+++ b/lxd/patches.go
@@ -2183,7 +2183,7 @@ func patchStorageApiDirCleanup(name string, d *Daemon) error {
if err != nil {
return err
}
- return d.cluster.StorageVolumeCleanupImages(fingerprints)
+ return d.cluster.RemoveStorageVolumeImages(fingerprints)
}
func patchStorageApiLvmKeys(name string, d *Daemon) error {
From b7bd36ed5d70fe9371563602233c695447dc1ca7 Mon Sep 17 00:00:00 2001
From: Free Ekanayaka <free.ekanayaka at canonical.com>
Date: Thu, 7 May 2020 16:26:54 +0100
Subject: [PATCH 11/11] lxd/db: Rename StorageVolumeMoveToLVMThinPoolNameKey to
UpgradeStorageVolumConfigToLVMThinPoolNameKey
Signed-off-by: Free Ekanayaka <free.ekanayaka at canonical.com>
---
lxd/db/storage_volumes.go | 4 ++--
lxd/patches.go | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/lxd/db/storage_volumes.go b/lxd/db/storage_volumes.go
index 56563e0757..d987860d14 100644
--- a/lxd/db/storage_volumes.go
+++ b/lxd/db/storage_volumes.go
@@ -361,9 +361,9 @@ func (c *Cluster) RemoveStorageVolumeImages(fingerprints []string) error {
return err
}
-// StorageVolumeMoveToLVMThinPoolNameKey upgrades the config keys of LVM
+// UpgradeStorageVolumConfigToLVMThinPoolNameKey upgrades the config keys of LVM
// volumes.
-func (c *Cluster) StorageVolumeMoveToLVMThinPoolNameKey() error {
+func (c *Cluster) UpgradeStorageVolumConfigToLVMThinPoolNameKey() error {
err := exec(c.db, "UPDATE storage_pools_config SET key='lvm.thinpool_name' WHERE key='volume.lvm.thinpool_name';")
if err != nil {
return err
diff --git a/lxd/patches.go b/lxd/patches.go
index a40fc4fe26..ea0fdc19ea 100644
--- a/lxd/patches.go
+++ b/lxd/patches.go
@@ -2187,7 +2187,7 @@ func patchStorageApiDirCleanup(name string, d *Daemon) error {
}
func patchStorageApiLvmKeys(name string, d *Daemon) error {
- return d.cluster.StorageVolumeMoveToLVMThinPoolNameKey()
+ return d.cluster.UpgradeStorageVolumConfigToLVMThinPoolNameKey()
}
func patchStorageApiKeys(name string, d *Daemon) error {
More information about the lxc-devel
mailing list