[lxc-devel] [lxd/master] Cleanup db function names
freeekanayaka on Github
lxc-bot at linuxcontainers.org
Thu Apr 30 15:06:59 UTC 2020
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 494 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200430/a142b6a7/attachment-0001.bin>
-------------- next part --------------
From b602e6fe34039873b15e2724ece29db2b8e2dc99 Mon Sep 17 00:00:00 2001
From: Free Ekanayaka <free.ekanayaka at canonical.com>
Date: Thu, 30 Apr 2020 14:49:50 +0100
Subject: [PATCH 01/38] lxd/db: Rename CertificatesGet to GetCertificates
Signed-off-by: Free Ekanayaka <free.ekanayaka at canonical.com>
---
lxd/certificates.go | 4 ++--
lxd/db/certificates.go | 4 ++--
lxd/db/migration_test.go | 2 +-
3 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/lxd/certificates.go b/lxd/certificates.go
index a236770bb1..d7b95f92b2 100644
--- a/lxd/certificates.go
+++ b/lxd/certificates.go
@@ -47,7 +47,7 @@ func certificatesGet(d *Daemon, r *http.Request) response.Response {
if recursion {
certResponses := []api.Certificate{}
- baseCerts, err := d.cluster.CertificatesGet()
+ baseCerts, err := d.cluster.GetCertificates()
if err != nil {
return response.SmartError(err)
}
@@ -78,7 +78,7 @@ func certificatesGet(d *Daemon, r *http.Request) response.Response {
func readSavedClientCAList(d *Daemon) {
d.clientCerts = map[string]x509.Certificate{}
- dbCerts, err := d.cluster.CertificatesGet()
+ dbCerts, err := d.cluster.GetCertificates()
if err != nil {
logger.Infof("Error reading certificates from database: %s", err)
return
diff --git a/lxd/db/certificates.go b/lxd/db/certificates.go
index e024215f93..aef85275a0 100644
--- a/lxd/db/certificates.go
+++ b/lxd/db/certificates.go
@@ -16,8 +16,8 @@ type CertInfo struct {
Certificate string
}
-// CertificatesGet returns all certificates from the DB as CertBaseInfo objects.
-func (c *Cluster) CertificatesGet() (certs []*CertInfo, err error) {
+// GetCertificates returns all certificates from the DB as CertBaseInfo objects.
+func (c *Cluster) GetCertificates() (certs []*CertInfo, err error) {
err = c.Transaction(func(tx *ClusterTx) error {
rows, err := tx.tx.Query(
"SELECT id, fingerprint, type, name, certificate FROM certificates",
diff --git a/lxd/db/migration_test.go b/lxd/db/migration_test.go
index fecb33b2e6..7060892c6c 100644
--- a/lxd/db/migration_test.go
+++ b/lxd/db/migration_test.go
@@ -60,7 +60,7 @@ func TestImportPreClusteringData(t *testing.T) {
defer cluster.Close()
// certificates
- certs, err := cluster.CertificatesGet()
+ certs, err := cluster.GetCertificates()
require.NoError(t, err)
assert.Len(t, certs, 1)
cert := certs[0]
From 55e8045d9893b7ce8c04b3fb7f366041fc9ad978 Mon Sep 17 00:00:00 2001
From: Free Ekanayaka <free.ekanayaka at canonical.com>
Date: Thu, 30 Apr 2020 14:51:47 +0100
Subject: [PATCH 02/38] lxd/db: Rename CertificateGet to GetCertificate
Signed-off-by: Free Ekanayaka <free.ekanayaka at canonical.com>
---
lxd/api_cluster.go | 2 +-
lxd/certificates.go | 6 +++---
lxd/db/certificates.go | 4 ++--
3 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/lxd/api_cluster.go b/lxd/api_cluster.go
index 2e98cc5b74..5a0b9977ea 100644
--- a/lxd/api_cluster.go
+++ b/lxd/api_cluster.go
@@ -486,7 +486,7 @@ func clusterPutJoin(d *Daemon, req api.ClusterPut) response.Response {
}
// Remove our old server certificate from the trust store, since it's not needed anymore.
- _, err = d.cluster.CertificateGet(fingerprint)
+ _, err = d.cluster.GetCertificate(fingerprint)
if err != db.ErrNoSuchObject {
if err != nil {
return err
diff --git a/lxd/certificates.go b/lxd/certificates.go
index d7b95f92b2..e7c2676048 100644
--- a/lxd/certificates.go
+++ b/lxd/certificates.go
@@ -168,7 +168,7 @@ func certificatesPost(d *Daemon, r *http.Request) response.Response {
if !isClusterNotification(r) {
// Check if we already have the certificate
- existingCert, _ := d.cluster.CertificateGet(fingerprint)
+ existingCert, _ := d.cluster.GetCertificate(fingerprint)
if existingCert != nil {
// Deal with the cache being potentially out of sync
_, ok := d.clientCerts[fingerprint]
@@ -232,7 +232,7 @@ func certificateGet(d *Daemon, r *http.Request) response.Response {
func doCertificateGet(db *db.Cluster, fingerprint string) (api.Certificate, error) {
resp := api.Certificate{}
- dbCertInfo, err := db.CertificateGet(fingerprint)
+ dbCertInfo, err := db.GetCertificate(fingerprint)
if err != nil {
return resp, err
}
@@ -322,7 +322,7 @@ func doCertificateUpdate(d *Daemon, fingerprint string, req api.CertificatePut)
func certificateDelete(d *Daemon, r *http.Request) response.Response {
fingerprint := mux.Vars(r)["fingerprint"]
- certInfo, err := d.cluster.CertificateGet(fingerprint)
+ certInfo, err := d.cluster.GetCertificate(fingerprint)
if err != nil {
return response.NotFound(err)
}
diff --git a/lxd/db/certificates.go b/lxd/db/certificates.go
index aef85275a0..1665439768 100644
--- a/lxd/db/certificates.go
+++ b/lxd/db/certificates.go
@@ -49,12 +49,12 @@ func (c *Cluster) GetCertificates() (certs []*CertInfo, err error) {
return certs, nil
}
-// CertificateGet gets an CertBaseInfo object from the database.
+// GetCertificate gets an CertBaseInfo object from the database.
// The argument fingerprint will be queried with a LIKE query, means you can
// pass a shortform and will get the full fingerprint.
// There can never be more than one image with a given fingerprint, as it is
// enforced by a UNIQUE constraint in the schema.
-func (c *Cluster) CertificateGet(fingerprint string) (cert *CertInfo, err error) {
+func (c *Cluster) GetCertificate(fingerprint string) (cert *CertInfo, err error) {
cert = new(CertInfo)
inargs := []interface{}{fingerprint + "%"}
From 4e97ab7426565e6f6c115ded4280290ec7e2b888 Mon Sep 17 00:00:00 2001
From: Free Ekanayaka <free.ekanayaka at canonical.com>
Date: Thu, 30 Apr 2020 14:54:14 +0100
Subject: [PATCH 03/38] lxd/db: Rename CertSave to CreateCertificate
Signed-off-by: Free Ekanayaka <free.ekanayaka at canonical.com>
---
lxd/certificates.go | 2 +-
lxd/db/certificates.go | 6 +++---
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/lxd/certificates.go b/lxd/certificates.go
index e7c2676048..8c63fb1844 100644
--- a/lxd/certificates.go
+++ b/lxd/certificates.go
@@ -188,7 +188,7 @@ func certificatesPost(d *Daemon, r *http.Request) response.Response {
Certificate: string(pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: cert.Raw})),
}
- err = d.cluster.CertSave(&dbCert)
+ err = d.cluster.CreateCertificate(&dbCert)
if err != nil {
return response.SmartError(err)
}
diff --git a/lxd/db/certificates.go b/lxd/db/certificates.go
index 1665439768..fcfab199b2 100644
--- a/lxd/db/certificates.go
+++ b/lxd/db/certificates.go
@@ -84,9 +84,9 @@ func (c *Cluster) GetCertificate(fingerprint string) (cert *CertInfo, err error)
return cert, err
}
-// CertSave stores a CertBaseInfo object in the db,
-// it will ignore the ID field from the CertInfo.
-func (c *Cluster) CertSave(cert *CertInfo) error {
+// CreateCertificate stores a CertInfo object in the db, it will ignore the ID
+// field from the CertInfo.
+func (c *Cluster) CreateCertificate(cert *CertInfo) error {
err := c.Transaction(func(tx *ClusterTx) error {
stmt, err := tx.tx.Prepare(`
INSERT INTO certificates (
From f8363b0fa213836e9a5d591b486461ad6cbdd531 Mon Sep 17 00:00:00 2001
From: Free Ekanayaka <free.ekanayaka at canonical.com>
Date: Thu, 30 Apr 2020 14:55:23 +0100
Subject: [PATCH 04/38] lxd/db: Rename CertDelete to DeleteCertificate
Signed-off-by: Free Ekanayaka <free.ekanayaka at canonical.com>
---
lxd/api_cluster.go | 2 +-
lxd/certificates.go | 2 +-
lxd/db/certificates.go | 4 ++--
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/lxd/api_cluster.go b/lxd/api_cluster.go
index 5a0b9977ea..e55d892059 100644
--- a/lxd/api_cluster.go
+++ b/lxd/api_cluster.go
@@ -492,7 +492,7 @@ func clusterPutJoin(d *Daemon, req api.ClusterPut) response.Response {
return err
}
- err := d.cluster.CertDelete(fingerprint)
+ err := d.cluster.DeleteCertificate(fingerprint)
if err != nil {
return errors.Wrap(err, "Failed to delete joining member's certificate")
}
diff --git a/lxd/certificates.go b/lxd/certificates.go
index 8c63fb1844..d0b63c0545 100644
--- a/lxd/certificates.go
+++ b/lxd/certificates.go
@@ -327,7 +327,7 @@ func certificateDelete(d *Daemon, r *http.Request) response.Response {
return response.NotFound(err)
}
- err = d.cluster.CertDelete(certInfo.Fingerprint)
+ err = d.cluster.DeleteCertificate(certInfo.Fingerprint)
if err != nil {
return response.SmartError(err)
}
diff --git a/lxd/db/certificates.go b/lxd/db/certificates.go
index fcfab199b2..06a2b04489 100644
--- a/lxd/db/certificates.go
+++ b/lxd/db/certificates.go
@@ -114,8 +114,8 @@ func (c *Cluster) CreateCertificate(cert *CertInfo) error {
return err
}
-// CertDelete deletes a certificate from the db.
-func (c *Cluster) CertDelete(fingerprint string) error {
+// DeleteCertificate deletes a certificate from the db.
+func (c *Cluster) DeleteCertificate(fingerprint string) error {
err := exec(c.db, "DELETE FROM certificates WHERE fingerprint=?", fingerprint)
if err != nil {
return err
From 096d941085f0fafbac6302b45959b6fbd01fa0c1 Mon Sep 17 00:00:00 2001
From: Free Ekanayaka <free.ekanayaka at canonical.com>
Date: Thu, 30 Apr 2020 14:56:13 +0100
Subject: [PATCH 05/38] lxd/db: Rename CertUpdate to UpdateCertificate
Signed-off-by: Free Ekanayaka <free.ekanayaka at canonical.com>
---
lxd/certificates.go | 2 +-
lxd/db/certificates.go | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/lxd/certificates.go b/lxd/certificates.go
index d0b63c0545..32eba870f4 100644
--- a/lxd/certificates.go
+++ b/lxd/certificates.go
@@ -311,7 +311,7 @@ func doCertificateUpdate(d *Daemon, fingerprint string, req api.CertificatePut)
return response.BadRequest(fmt.Errorf("Unknown request type %s", req.Type))
}
- err := d.cluster.CertUpdate(fingerprint, req.Name, 1)
+ err := d.cluster.UpdateCertificate(fingerprint, req.Name, 1)
if err != nil {
return response.SmartError(err)
}
diff --git a/lxd/db/certificates.go b/lxd/db/certificates.go
index 06a2b04489..40835e24a1 100644
--- a/lxd/db/certificates.go
+++ b/lxd/db/certificates.go
@@ -124,8 +124,8 @@ func (c *Cluster) DeleteCertificate(fingerprint string) error {
return nil
}
-// CertUpdate updates the certificate with the given fingerprint.
-func (c *Cluster) CertUpdate(fingerprint string, certName string, certType int) error {
+// UpdateCertificate updates the certificate with the given fingerprint.
+func (c *Cluster) UpdateCertificate(fingerprint string, certName string, certType int) error {
err := c.Transaction(func(tx *ClusterTx) error {
_, err := tx.tx.Exec("UPDATE certificates SET name=?, type=? WHERE fingerprint=?", certName, certType, fingerprint)
return err
From dab2be684849255eeb8309898d127fc9fd15fa9c Mon Sep 17 00:00:00 2001
From: Free Ekanayaka <free.ekanayaka at canonical.com>
Date: Thu, 30 Apr 2020 14:57:33 +0100
Subject: [PATCH 06/38] lxd/db: Drop unused ConfigValueSet
Signed-off-by: Free Ekanayaka <free.ekanayaka at canonical.com>
---
lxd/db/config.go | 26 --------------------------
1 file changed, 26 deletions(-)
diff --git a/lxd/db/config.go b/lxd/db/config.go
index 61c8c87ee0..b39e5ca0ae 100644
--- a/lxd/db/config.go
+++ b/lxd/db/config.go
@@ -25,29 +25,3 @@ func (c *ClusterTx) Config() (map[string]string, error) {
func (c *ClusterTx) UpdateConfig(values map[string]string) error {
return query.UpdateConfig(c.tx, "config", values)
}
-
-// ConfigValueSet is a convenience to set a cluster-level key/value config pair
-// in a single transaction.
-func ConfigValueSet(c *Cluster, key string, value string) error {
- err := c.Transaction(func(tx *ClusterTx) error {
- _, err := tx.tx.Exec("DELETE FROM config WHERE key=?", key)
- if err != nil {
- return err
- }
-
- if value != "" {
- str := `INSERT INTO config (key, value) VALUES (?, ?);`
- stmt, err := tx.tx.Prepare(str)
- if err != nil {
- return err
- }
- defer stmt.Close()
- _, err = stmt.Exec(key, value)
- if err != nil {
- return err
- }
- }
- return nil
- })
- return err
-}
From ea650e08c0a5117bfdf59244d1ac483121f5e26c Mon Sep 17 00:00:00 2001
From: Free Ekanayaka <free.ekanayaka at canonical.com>
Date: Thu, 30 Apr 2020 14:59:00 +0100
Subject: [PATCH 07/38] lxd/db: Rename InstanceNames to GetInstanceNames
Signed-off-by: Free Ekanayaka <free.ekanayaka at canonical.com>
---
lxd/db/containers.go | 4 ++--
lxd/instances_post.go | 4 ++--
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/lxd/db/containers.go b/lxd/db/containers.go
index dd4fed1e15..cf9e3abb4c 100644
--- a/lxd/db/containers.go
+++ b/lxd/db/containers.go
@@ -169,8 +169,8 @@ type InstanceBackupArgs struct {
CompressionAlgorithm string
}
-// InstanceNames returns the names of all containers the given project.
-func (c *ClusterTx) InstanceNames(project string) ([]string, error) {
+// GetInstanceNames returns the names of all containers the given project.
+func (c *ClusterTx) GetInstanceNames(project string) ([]string, error) {
stmt := `
SELECT instances.name FROM instances
JOIN projects ON projects.id = instances.project_id
diff --git a/lxd/instances_post.go b/lxd/instances_post.go
index 77fba7b94e..0d41ec8a24 100644
--- a/lxd/instances_post.go
+++ b/lxd/instances_post.go
@@ -13,7 +13,7 @@ import (
"os"
"strings"
- "github.com/dustinkirkland/golang-petname"
+ petname "github.com/dustinkirkland/golang-petname"
"github.com/gorilla/websocket"
"github.com/pkg/errors"
@@ -852,7 +852,7 @@ func containersPost(d *Daemon, r *http.Request) response.Response {
}
if req.Name == "" {
- names, err := tx.InstanceNames(project)
+ names, err := tx.GetInstanceNames(project)
if err != nil {
return err
}
From c8d0380e37e5d63b9372006c90a2b8b526002eb1 Mon Sep 17 00:00:00 2001
From: Free Ekanayaka <free.ekanayaka at canonical.com>
Date: Thu, 30 Apr 2020 15:02:14 +0100
Subject: [PATCH 08/38] lxd/db: Rename ContainerNodeAddress to
GetNodeAddressOfInstance
Signed-off-by: Free Ekanayaka <free.ekanayaka at canonical.com>
---
lxd/cluster/connect.go | 2 +-
lxd/db/containers.go | 6 +++---
lxd/instance_post.go | 2 +-
lxd/instances_post.go | 2 +-
4 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/lxd/cluster/connect.go b/lxd/cluster/connect.go
index 2d1a1783cc..7d12dd6099 100644
--- a/lxd/cluster/connect.go
+++ b/lxd/cluster/connect.go
@@ -69,7 +69,7 @@ func ConnectIfInstanceIsRemote(cluster *db.Cluster, project, name string, cert *
var address string // Node address
err := cluster.Transaction(func(tx *db.ClusterTx) error {
var err error
- address, err = tx.ContainerNodeAddress(project, name, instanceType)
+ address, err = tx.GetNodeAddressOfInstance(project, name, instanceType)
return err
})
if err != nil {
diff --git a/lxd/db/containers.go b/lxd/db/containers.go
index cf9e3abb4c..428db2a235 100644
--- a/lxd/db/containers.go
+++ b/lxd/db/containers.go
@@ -179,11 +179,11 @@ SELECT instances.name FROM instances
return query.SelectStrings(c.tx, stmt, project, instancetype.Any)
}
-// ContainerNodeAddress returns the address of the node hosting the container
-// with the given name in the given project.
+// GetNodeAddressOfInstance returns the address of the node hosting the
+// instance with the given name in the given project.
//
// It returns the empty string if the container is hosted on this node.
-func (c *ClusterTx) ContainerNodeAddress(project string, name string, instanceType instancetype.Type) (string, error) {
+func (c *ClusterTx) GetNodeAddressOfInstance(project string, name string, instanceType instancetype.Type) (string, error) {
var stmt string
args := make([]interface{}, 0, 4) // Expect up to 4 filters.
diff --git a/lxd/instance_post.go b/lxd/instance_post.go
index af2cec96c2..2f2bc41fbd 100644
--- a/lxd/instance_post.go
+++ b/lxd/instance_post.go
@@ -81,7 +81,7 @@ func containerPost(d *Daemon, r *http.Request) response.Response {
targetNodeOffline = node.IsOffline(config.OfflineThreshold())
// Load source node.
- address, err := tx.ContainerNodeAddress(project, name, instanceType)
+ address, err := tx.GetNodeAddressOfInstance(project, name, instanceType)
if err != nil {
return errors.Wrap(err, "Failed to get address of instance's node")
}
diff --git a/lxd/instances_post.go b/lxd/instances_post.go
index 0d41ec8a24..a921aad5fb 100644
--- a/lxd/instances_post.go
+++ b/lxd/instances_post.go
@@ -958,7 +958,7 @@ func clusterCopyContainerInternal(d *Daemon, source instance.Instance, project s
var err error
// Load source node.
- nodeAddress, err = tx.ContainerNodeAddress(project, name, source.Type())
+ nodeAddress, err = tx.GetNodeAddressOfInstance(project, name, source.Type())
if err != nil {
return errors.Wrap(err, "Failed to get address of instance's node")
}
From 2c091ce543ac4a49bfe9995f36880228cf4cbc04 Mon Sep 17 00:00:00 2001
From: Free Ekanayaka <free.ekanayaka at canonical.com>
Date: Thu, 30 Apr 2020 15:04:07 +0100
Subject: [PATCH 09/38] lxd/db: Rename ContainersListByNodeAddress to
GetInstanceNamesByNodeAddress
Signed-off-by: Free Ekanayaka <free.ekanayaka at canonical.com>
---
lxd/db/containers.go | 4 ++--
lxd/db/containers_test.go | 4 ++--
lxd/instances_get.go | 2 +-
3 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/lxd/db/containers.go b/lxd/db/containers.go
index 428db2a235..2789ad2497 100644
--- a/lxd/db/containers.go
+++ b/lxd/db/containers.go
@@ -265,14 +265,14 @@ SELECT nodes.id, nodes.address
return address, nil
}
-// ContainersListByNodeAddress returns the names of all containers grouped by
+// GetInstanceNamesByNodeAddress returns the names of all containers grouped by
// cluster node address.
//
// The node address of containers running on the local node is set to the empty
// string, to distinguish it from remote nodes.
//
// Containers whose node is down are addeded to the special address "0.0.0.0".
-func (c *ClusterTx) ContainersListByNodeAddress(project string, instanceType instancetype.Type) (map[string][]string, error) {
+func (c *ClusterTx) GetInstanceNamesByNodeAddress(project string, instanceType instancetype.Type) (map[string][]string, error) {
offlineThreshold, err := c.NodeOfflineThreshold()
if err != nil {
return nil, err
diff --git a/lxd/db/containers_test.go b/lxd/db/containers_test.go
index ea8648dd5c..0a6e149372 100644
--- a/lxd/db/containers_test.go
+++ b/lxd/db/containers_test.go
@@ -297,7 +297,7 @@ func TestInstanceCreate_Snapshot(t *testing.T) {
}
// Containers are grouped by node address.
-func TestContainersListByNodeAddress(t *testing.T) {
+func TestGetInstanceNamesByNodeAddress(t *testing.T) {
tx, cleanup := db.NewTestClusterTx(t)
defer cleanup()
@@ -315,7 +315,7 @@ func TestContainersListByNodeAddress(t *testing.T) {
addContainer(t, tx, nodeID3, "c3")
addContainer(t, tx, nodeID2, "c4")
- result, err := tx.ContainersListByNodeAddress("default", instancetype.Container)
+ result, err := tx.GetInstanceNamesByNodeAddress("default", instancetype.Container)
require.NoError(t, err)
assert.Equal(
t,
diff --git a/lxd/instances_get.go b/lxd/instances_get.go
index 2c7635d093..1ce487f36c 100644
--- a/lxd/instances_get.go
+++ b/lxd/instances_get.go
@@ -102,7 +102,7 @@ func doContainersGet(d *Daemon, r *http.Request) (interface{}, error) {
err = d.cluster.Transaction(func(tx *db.ClusterTx) error {
var err error
- result, err = tx.ContainersListByNodeAddress(project, instanceType)
+ result, err = tx.GetInstanceNamesByNodeAddress(project, instanceType)
if err != nil {
return err
}
From a711a42c84c9b1dba1b34e01f78e1078e80cc54c Mon Sep 17 00:00:00 2001
From: Free Ekanayaka <free.ekanayaka at canonical.com>
Date: Thu, 30 Apr 2020 15:11:19 +0100
Subject: [PATCH 10/38] lxd/db: Rename ContainersByNodeName to
GetInstanceToNodeMap
Signed-off-by: Free Ekanayaka <free.ekanayaka at canonical.com>
---
lxd/db/containers.go | 6 +++---
lxd/db/containers_test.go | 6 +++---
lxd/instances_get.go | 2 +-
3 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/lxd/db/containers.go b/lxd/db/containers.go
index 2789ad2497..412176ee18 100644
--- a/lxd/db/containers.go
+++ b/lxd/db/containers.go
@@ -390,9 +390,9 @@ func (c *ClusterTx) instanceListExpanded() ([]Instance, error) {
return instances, nil
}
-// ContainersByNodeName returns a map associating each container to the name of
-// its node.
-func (c *ClusterTx) ContainersByNodeName(project string, instanceType instancetype.Type) (map[string]string, error) {
+// GetInstanceToNodeMap returns a map associating the name of each
+// instance in the given project to the name of the node hosting the instance.
+func (c *ClusterTx) GetInstanceToNodeMap(project string, instanceType instancetype.Type) (map[string]string, error) {
args := make([]interface{}, 0, 2) // Expect up to 2 filters.
var filters strings.Builder
diff --git a/lxd/db/containers_test.go b/lxd/db/containers_test.go
index 0a6e149372..1fd4480c75 100644
--- a/lxd/db/containers_test.go
+++ b/lxd/db/containers_test.go
@@ -326,8 +326,8 @@ func TestGetInstanceNamesByNodeAddress(t *testing.T) {
}, result)
}
-// Containers are associated with their node name.
-func TestContainersByNodeName(t *testing.T) {
+// Instances are associated with their node name.
+func TestGetInstanceToNodeMap(t *testing.T) {
tx, cleanup := db.NewTestClusterTx(t)
defer cleanup()
@@ -339,7 +339,7 @@ func TestContainersByNodeName(t *testing.T) {
addContainer(t, tx, nodeID2, "c1")
addContainer(t, tx, nodeID1, "c2")
- result, err := tx.ContainersByNodeName("default", instancetype.Container)
+ result, err := tx.GetInstanceToNodeMap("default", instancetype.Container)
require.NoError(t, err)
assert.Equal(
t,
diff --git a/lxd/instances_get.go b/lxd/instances_get.go
index 1ce487f36c..eb503044e7 100644
--- a/lxd/instances_get.go
+++ b/lxd/instances_get.go
@@ -107,7 +107,7 @@ func doContainersGet(d *Daemon, r *http.Request) (interface{}, error) {
return err
}
- nodes, err = tx.ContainersByNodeName(project, instanceType)
+ nodes, err = tx.GetInstanceToNodeMap(project, instanceType)
if err != nil {
return err
}
From aad165eb0689a9ce9ed3ccd2682b166b6e522afc Mon Sep 17 00:00:00 2001
From: Free Ekanayaka <free.ekanayaka at canonical.com>
Date: Thu, 30 Apr 2020 15:13:52 +0100
Subject: [PATCH 11/38] lxd/db: Rename ContainerNodeMove to UpdateInstanceNode
Signed-off-by: Free Ekanayaka <free.ekanayaka at canonical.com>
---
lxd/db/containers.go | 6 +++---
lxd/instance_post.go | 2 +-
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/lxd/db/containers.go b/lxd/db/containers.go
index 412176ee18..3dbfbee6c1 100644
--- a/lxd/db/containers.go
+++ b/lxd/db/containers.go
@@ -439,11 +439,11 @@ SELECT instances.name, nodes.name
return result, nil
}
-// ContainerNodeMove changes the node associated with a container.
+// UpdateInstanceNode changes the node hosting an instance.
//
-// It's meant to be used when moving a non-running container backed by ceph
+// It's meant to be used when moving a non-running instance backed by ceph
// from one cluster node to another.
-func (c *ClusterTx) ContainerNodeMove(project, oldName, newName, newNode string) error {
+func (c *ClusterTx) UpdateInstanceNode(project, oldName, newName, newNode string) error {
// First check that the container to be moved is backed by a ceph
// volume.
poolName, err := c.InstancePool(project, oldName)
diff --git a/lxd/instance_post.go b/lxd/instance_post.go
index 2f2bc41fbd..1ae40fd0ab 100644
--- a/lxd/instance_post.go
+++ b/lxd/instance_post.go
@@ -440,7 +440,7 @@ func containerPostClusteringMigrateWithCeph(d *Daemon, c instance.Instance, proj
// Re-link the database entries against the new node name.
err = d.cluster.Transaction(func(tx *db.ClusterTx) error {
- err := tx.ContainerNodeMove(projectName, oldName, newName, newNode)
+ err := tx.UpdateInstanceNode(projectName, oldName, newName, newNode)
if err != nil {
return errors.Wrapf(
err, "Move container %s to %s with new name %s", oldName, newNode, newName)
From d9b7d51ea968cbb8481bcee5c4319a7d9add3f97 Mon Sep 17 00:00:00 2001
From: Free Ekanayaka <free.ekanayaka at canonical.com>
Date: Thu, 30 Apr 2020 15:16:22 +0100
Subject: [PATCH 12/38] lxd/db: Rename ContainerNodeProjectList to
GetLocalInstancesInProject
Signed-off-by: Free Ekanayaka <free.ekanayaka at canonical.com>
---
lxd/db/containers.go | 5 +++--
lxd/db/containers_test.go | 4 ++--
lxd/instance.go | 2 +-
lxd/instance/instance_utils.go | 4 ++--
4 files changed, 8 insertions(+), 7 deletions(-)
diff --git a/lxd/db/containers.go b/lxd/db/containers.go
index 3dbfbee6c1..19bfc9c233 100644
--- a/lxd/db/containers.go
+++ b/lxd/db/containers.go
@@ -522,8 +522,9 @@ func (c *ClusterTx) UpdateInstanceNode(project, oldName, newName, newNode string
return nil
}
-// ContainerNodeProjectList returns all container objects on the local node within the given project.
-func (c *ClusterTx) ContainerNodeProjectList(project string, instanceType instancetype.Type) ([]Instance, error) {
+// GetLocalInstancesInProject retuurns all instances of the given type on the
+// local node within the given project.
+func (c *ClusterTx) GetLocalInstancesInProject(project string, instanceType instancetype.Type) ([]Instance, error) {
node, err := c.NodeName()
if err != nil {
return nil, errors.Wrap(err, "Local node name")
diff --git a/lxd/db/containers_test.go b/lxd/db/containers_test.go
index 1fd4480c75..da01de60e3 100644
--- a/lxd/db/containers_test.go
+++ b/lxd/db/containers_test.go
@@ -406,7 +406,7 @@ func TestContainersNodeList(t *testing.T) {
}
// All containers on a node are loaded in bulk.
-func TestContainerNodeProjectList(t *testing.T) {
+func TestGetLocalInstancesInProject(t *testing.T) {
tx, cleanup := db.NewTestClusterTx(t)
defer cleanup()
@@ -427,7 +427,7 @@ func TestContainerNodeProjectList(t *testing.T) {
addContainerDevice(t, tx, "c2", "eth0", "nic", nil)
addContainerDevice(t, tx, "c4", "root", "disk", map[string]string{"x": "y"})
- containers, err := tx.ContainerNodeProjectList("", instancetype.Container)
+ containers, err := tx.GetLocalInstancesInProject("", instancetype.Container)
require.NoError(t, err)
assert.Len(t, containers, 3)
diff --git a/lxd/instance.go b/lxd/instance.go
index 456655d947..6d0e3ff9d6 100644
--- a/lxd/instance.go
+++ b/lxd/instance.go
@@ -682,7 +682,7 @@ func instanceLoadNodeProjectAll(s *state.State, project string, instanceType ins
var cts []db.Instance
err := s.Cluster.Transaction(func(tx *db.ClusterTx) error {
var err error
- cts, err = tx.ContainerNodeProjectList(project, instanceType)
+ cts, err = tx.GetLocalInstancesInProject(project, instanceType)
if err != nil {
return err
}
diff --git a/lxd/instance/instance_utils.go b/lxd/instance/instance_utils.go
index 6804a0a6fd..0ead675ccf 100644
--- a/lxd/instance/instance_utils.go
+++ b/lxd/instance/instance_utils.go
@@ -12,7 +12,7 @@ import (
"github.com/pkg/errors"
- "github.com/lxc/lxd/client"
+ lxd "github.com/lxc/lxd/client"
"github.com/lxc/lxd/lxd/backup"
"github.com/lxc/lxd/lxd/db"
deviceConfig "github.com/lxc/lxd/lxd/device/config"
@@ -570,7 +570,7 @@ func LoadNodeAll(s *state.State, instanceType instancetype.Type) ([]Instance, er
var insts []db.Instance
err := s.Cluster.Transaction(func(tx *db.ClusterTx) error {
var err error
- insts, err = tx.ContainerNodeProjectList("", instanceType)
+ insts, err = tx.GetLocalInstancesInProject("", instanceType)
if err != nil {
return err
}
From 87b8442b4bae3b5a5bb2f9682159b093b740a7a8 Mon Sep 17 00:00:00 2001
From: Free Ekanayaka <free.ekanayaka at canonical.com>
Date: Thu, 30 Apr 2020 15:18:13 +0100
Subject: [PATCH 13/38] lxd/db: Rename ContainerConfigInsert to
CreateInstanceConfig
Signed-off-by: Free Ekanayaka <free.ekanayaka at canonical.com>
---
lxd/db/containers.go | 10 +++++-----
lxd/instance/drivers/driver_lxc.go | 4 ++--
lxd/instance/drivers/driver_qemu.go | 4 ++--
lxd/instance_post.go | 2 +-
4 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/lxd/db/containers.go b/lxd/db/containers.go
index 19bfc9c233..03936b8436 100644
--- a/lxd/db/containers.go
+++ b/lxd/db/containers.go
@@ -539,9 +539,9 @@ func (c *ClusterTx) GetLocalInstancesInProject(project string, instanceType inst
return c.InstanceList(filter)
}
-// ContainerConfigInsert inserts a new config for the container with the given ID.
-func (c *ClusterTx) ContainerConfigInsert(id int, config map[string]string) error {
- return ContainerConfigInsert(c.tx, id, config)
+// CreateInstanceConfig inserts a new config for the container with the given ID.
+func (c *ClusterTx) CreateInstanceConfig(id int, config map[string]string) error {
+ return CreateInstanceConfig(c.tx, id, config)
}
// ContainerConfigUpdate inserts/updates/deletes the provided keys
@@ -667,8 +667,8 @@ func ContainerConfigClear(tx *sql.Tx, id int) error {
return err
}
-// ContainerConfigInsert inserts a new config for the container with the given ID.
-func ContainerConfigInsert(tx *sql.Tx, id int, config map[string]string) error {
+// CreateInstanceConfig inserts a new config for the instance with the given ID.
+func CreateInstanceConfig(tx *sql.Tx, id int, config map[string]string) error {
stmt, err := tx.Prepare("INSERT INTO instances_config (instance_id, key, value) values (?, ?, ?)")
if err != nil {
return err
diff --git a/lxd/instance/drivers/driver_lxc.go b/lxd/instance/drivers/driver_lxc.go
index 5c7b72d378..036cf77790 100644
--- a/lxd/instance/drivers/driver_lxc.go
+++ b/lxd/instance/drivers/driver_lxc.go
@@ -4372,7 +4372,7 @@ func (c *lxc) Update(args db.InstanceArgs, userRequested bool) error {
return err
}
- err = db.ContainerConfigInsert(tx, c.id, c.localConfig)
+ err = db.CreateInstanceConfig(tx, c.id, c.localConfig)
if err != nil {
tx.Rollback()
return errors.Wrap(err, "Config insert")
@@ -6251,7 +6251,7 @@ func (c *lxc) FillNetworkDevice(name string, m deviceConfig.Device) (deviceConfi
return err
}
- err = db.ContainerConfigInsert(tx, c.id, map[string]string{key: value})
+ err = db.CreateInstanceConfig(tx, c.id, map[string]string{key: value})
if err != nil {
tx.Rollback()
return err
diff --git a/lxd/instance/drivers/driver_qemu.go b/lxd/instance/drivers/driver_qemu.go
index b92b08f6f3..c2139a3e9e 100644
--- a/lxd/instance/drivers/driver_qemu.go
+++ b/lxd/instance/drivers/driver_qemu.go
@@ -2617,7 +2617,7 @@ func (vm *qemu) Update(args db.InstanceArgs, userRequested bool) error {
return err
}
- err = db.ContainerConfigInsert(tx, vm.id, vm.localConfig)
+ err = db.CreateInstanceConfig(tx, vm.id, vm.localConfig)
if err != nil {
tx.Rollback()
return errors.Wrap(err, "Config insert")
@@ -4060,7 +4060,7 @@ func (vm *qemu) FillNetworkDevice(name string, m deviceConfig.Device) (deviceCon
return err
}
- err = db.ContainerConfigInsert(tx, vm.id, map[string]string{key: value})
+ err = db.CreateInstanceConfig(tx, vm.id, map[string]string{key: value})
if err != nil {
tx.Rollback()
return err
diff --git a/lxd/instance_post.go b/lxd/instance_post.go
index 1ae40fd0ab..30f0a22037 100644
--- a/lxd/instance_post.go
+++ b/lxd/instance_post.go
@@ -388,7 +388,7 @@ func containerPostClusteringMigrate(d *Daemon, c instance.Instance, oldName, new
"volatile.apply_template": origVolatileApplyTemplate,
}
err := d.cluster.Transaction(func(tx *db.ClusterTx) error {
- return tx.ContainerConfigInsert(id, config)
+ return tx.CreateInstanceConfig(id, config)
})
if err != nil {
return errors.Wrap(err, "Failed to set volatile.apply_template config key")
From 7f2ec890a9cc079e9b729d3d2e6079373a117677 Mon Sep 17 00:00:00 2001
From: Free Ekanayaka <free.ekanayaka at canonical.com>
Date: Thu, 30 Apr 2020 15:20:45 +0100
Subject: [PATCH 14/38] lxd/db: Rename ContainerConfigUpdate to
UpdateInstanceConfig
Signed-off-by: Free Ekanayaka <free.ekanayaka at canonical.com>
---
lxd/db/containers.go | 4 ++--
lxd/instance/drivers/driver_lxc.go | 2 +-
lxd/instance/drivers/driver_qemu.go | 2 +-
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/lxd/db/containers.go b/lxd/db/containers.go
index 03936b8436..fcf6405ae9 100644
--- a/lxd/db/containers.go
+++ b/lxd/db/containers.go
@@ -544,8 +544,8 @@ func (c *ClusterTx) CreateInstanceConfig(id int, config map[string]string) error
return CreateInstanceConfig(c.tx, id, config)
}
-// ContainerConfigUpdate inserts/updates/deletes the provided keys
-func (c *ClusterTx) ContainerConfigUpdate(id int, values map[string]string) error {
+// UpdateInstanceConfig inserts/updates/deletes the provided keys
+func (c *ClusterTx) UpdateInstanceConfig(id int, values map[string]string) error {
insertSQL := fmt.Sprintf("INSERT OR REPLACE INTO instances_config (instance_id, key, value) VALUES")
deleteSQL := "DELETE FROM instances_config WHERE key IN %s AND instance_id=?"
return c.configUpdate(id, values, insertSQL, deleteSQL)
diff --git a/lxd/instance/drivers/driver_lxc.go b/lxd/instance/drivers/driver_lxc.go
index 036cf77790..8b78e8bcb5 100644
--- a/lxd/instance/drivers/driver_lxc.go
+++ b/lxd/instance/drivers/driver_lxc.go
@@ -3733,7 +3733,7 @@ func (c *lxc) VolatileSet(changes map[string]string) error {
})
} else {
err = c.state.Cluster.Transaction(func(tx *db.ClusterTx) error {
- return tx.ContainerConfigUpdate(c.id, changes)
+ return tx.UpdateInstanceConfig(c.id, changes)
})
}
if err != nil {
diff --git a/lxd/instance/drivers/driver_qemu.go b/lxd/instance/drivers/driver_qemu.go
index c2139a3e9e..becc25cab9 100644
--- a/lxd/instance/drivers/driver_qemu.go
+++ b/lxd/instance/drivers/driver_qemu.go
@@ -3284,7 +3284,7 @@ func (vm *qemu) VolatileSet(changes map[string]string) error {
})
} else {
err = vm.state.Cluster.Transaction(func(tx *db.ClusterTx) error {
- return tx.ContainerConfigUpdate(vm.id, changes)
+ return tx.UpdateInstanceConfig(vm.id, changes)
})
}
if err != nil {
From e0e90c92dc4db3b6d2ee7513b3d32620a6ed35f0 Mon Sep 17 00:00:00 2001
From: Free Ekanayaka <free.ekanayaka at canonical.com>
Date: Thu, 30 Apr 2020 15:22:04 +0100
Subject: [PATCH 15/38] lxd/db: Rename InstanceRemove to RemoveInstance
Signed-off-by: Free Ekanayaka <free.ekanayaka at canonical.com>
---
lxd/api_internal.go | 4 ++--
lxd/db/containers.go | 4 ++--
lxd/instance.go | 2 +-
lxd/instance/drivers/driver_lxc.go | 2 +-
lxd/instance/drivers/driver_qemu.go | 2 +-
5 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/lxd/api_internal.go b/lxd/api_internal.go
index c5f1def35d..4f9811f40e 100644
--- a/lxd/api_internal.go
+++ b/lxd/api_internal.go
@@ -584,7 +584,7 @@ func internalImport(d *Daemon, r *http.Request) response.Response {
if instanceErr == nil {
// Remove the storage volume db entry for the instance since force was specified.
- err := d.cluster.InstanceRemove(projectName, req.Name)
+ err := d.cluster.RemoveInstance(projectName, req.Name)
if err != nil {
return response.SmartError(err)
}
@@ -690,7 +690,7 @@ func internalImport(d *Daemon, r *http.Request) response.Response {
}
if snapErr == nil {
- err := d.cluster.InstanceRemove(projectName, snap.Name)
+ err := d.cluster.RemoveInstance(projectName, snap.Name)
if err != nil {
return response.SmartError(err)
}
diff --git a/lxd/db/containers.go b/lxd/db/containers.go
index fcf6405ae9..6a1ac07218 100644
--- a/lxd/db/containers.go
+++ b/lxd/db/containers.go
@@ -599,8 +599,8 @@ func (c *ClusterTx) configUpdate(id int, values map[string]string, insertSQL, de
return nil
}
-// InstanceRemove removes the instance with the given name from the database.
-func (c *Cluster) InstanceRemove(project, name string) error {
+// RemoveInstance removes the instance with the given name from the database.
+func (c *Cluster) RemoveInstance(project, name string) error {
if strings.Contains(name, shared.SnapshotDelimiter) {
parts := strings.SplitN(name, shared.SnapshotDelimiter, 2)
return c.Transaction(func(tx *ClusterTx) error {
diff --git a/lxd/instance.go b/lxd/instance.go
index 6d0e3ff9d6..3be1c2e4ef 100644
--- a/lxd/instance.go
+++ b/lxd/instance.go
@@ -625,7 +625,7 @@ func instanceCreateInternal(s *state.State, args db.InstanceArgs) (instance.Inst
return
}
- s.Cluster.InstanceRemove(dbInst.Project, dbInst.Name)
+ s.Cluster.RemoveInstance(dbInst.Project, dbInst.Name)
}()
// Wipe any existing log for this instance name.
diff --git a/lxd/instance/drivers/driver_lxc.go b/lxd/instance/drivers/driver_lxc.go
index 8b78e8bcb5..4f10756ff3 100644
--- a/lxd/instance/drivers/driver_lxc.go
+++ b/lxd/instance/drivers/driver_lxc.go
@@ -3519,7 +3519,7 @@ func (c *lxc) Delete() error {
}
// Remove the database record of the instance or snapshot instance.
- if err := c.state.Cluster.InstanceRemove(c.project, c.Name()); err != nil {
+ if err := c.state.Cluster.RemoveInstance(c.project, c.Name()); err != nil {
logger.Error("Failed deleting container entry", log.Ctx{"name": c.Name(), "err": err})
return err
}
diff --git a/lxd/instance/drivers/driver_qemu.go b/lxd/instance/drivers/driver_qemu.go
index becc25cab9..46750bf3b6 100644
--- a/lxd/instance/drivers/driver_qemu.go
+++ b/lxd/instance/drivers/driver_qemu.go
@@ -2970,7 +2970,7 @@ func (vm *qemu) Delete() error {
}
// Remove the database record of the instance or snapshot instance.
- if err := vm.state.Cluster.InstanceRemove(vm.Project(), vm.Name()); err != nil {
+ if err := vm.state.Cluster.RemoveInstance(vm.Project(), vm.Name()); err != nil {
logger.Error("Failed deleting instance entry", log.Ctx{"project": vm.Project(), "instance": vm.Name(), "err": err})
return err
}
From e5a2945fed2bf8a9141a274c5cc83794b012e716 Mon Sep 17 00:00:00 2001
From: Free Ekanayaka <free.ekanayaka at canonical.com>
Date: Thu, 30 Apr 2020 15:23:32 +0100
Subject: [PATCH 16/38] lxd/db: Rename ContainerProjectAndName to
GetInstanceProjectAndName
Signed-off-by: Free Ekanayaka <free.ekanayaka at canonical.com>
---
lxd/db/containers.go | 4 ++--
lxd/instance/instance_utils.go | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/lxd/db/containers.go b/lxd/db/containers.go
index 6a1ac07218..379a9a2064 100644
--- a/lxd/db/containers.go
+++ b/lxd/db/containers.go
@@ -612,9 +612,9 @@ func (c *Cluster) RemoveInstance(project, name string) error {
})
}
-// ContainerProjectAndName returns the project and the name of the container
+// GetInstanceProjectAndName returns the project and the name of the instance
// with the given ID.
-func (c *Cluster) ContainerProjectAndName(id int) (string, string, error) {
+func (c *Cluster) GetInstanceProjectAndName(id int) (string, string, error) {
q := `
SELECT projects.name, instances.name
FROM instances
diff --git a/lxd/instance/instance_utils.go b/lxd/instance/instance_utils.go
index 0ead675ccf..258273abec 100644
--- a/lxd/instance/instance_utils.go
+++ b/lxd/instance/instance_utils.go
@@ -392,7 +392,7 @@ func ParseRawIdmap(value string) ([]idmap.IdmapEntry, error) {
// LoadByID loads an instance by ID.
func LoadByID(s *state.State, id int) (Instance, error) {
// Get the DB record
- project, name, err := s.Cluster.ContainerProjectAndName(id)
+ project, name, err := s.Cluster.GetInstanceProjectAndName(id)
if err != nil {
return nil, err
}
From bfee4fe3bd42bff08dde1be062ebca31795d1c04 Mon Sep 17 00:00:00 2001
From: Free Ekanayaka <free.ekanayaka at canonical.com>
Date: Thu, 30 Apr 2020 15:25:34 +0100
Subject: [PATCH 17/38] lxd/db: Rename ContainerConfigClear to
DeleteInstanceConfig
Signed-off-by: Free Ekanayaka <free.ekanayaka at canonical.com>
---
lxd/db/containers.go | 4 ++--
lxd/instance/drivers/driver_lxc.go | 2 +-
lxd/instance/drivers/driver_qemu.go | 2 +-
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/lxd/db/containers.go b/lxd/db/containers.go
index 379a9a2064..8aabf4a1b9 100644
--- a/lxd/db/containers.go
+++ b/lxd/db/containers.go
@@ -644,9 +644,9 @@ func (c *Cluster) InstanceID(project, name string) (int, error) {
return int(id), err
}
-// ContainerConfigClear removes any config associated with the container with
+// DeleteInstanceConfig removes any config associated with the instance with
// the given ID.
-func ContainerConfigClear(tx *sql.Tx, id int) error {
+func DeleteInstanceConfig(tx *sql.Tx, id int) error {
_, err := tx.Exec("DELETE FROM instances_config WHERE instance_id=?", id)
if err != nil {
return err
diff --git a/lxd/instance/drivers/driver_lxc.go b/lxd/instance/drivers/driver_lxc.go
index 4f10756ff3..7b7a3b08b9 100644
--- a/lxd/instance/drivers/driver_lxc.go
+++ b/lxd/instance/drivers/driver_lxc.go
@@ -4366,7 +4366,7 @@ func (c *lxc) Update(args db.InstanceArgs, userRequested bool) error {
return errors.Wrap(err, "Snapshot update")
}
} else {
- err = db.ContainerConfigClear(tx, c.id)
+ err = db.DeleteInstanceConfig(tx, c.id)
if err != nil {
tx.Rollback()
return err
diff --git a/lxd/instance/drivers/driver_qemu.go b/lxd/instance/drivers/driver_qemu.go
index 46750bf3b6..aa49442857 100644
--- a/lxd/instance/drivers/driver_qemu.go
+++ b/lxd/instance/drivers/driver_qemu.go
@@ -2611,7 +2611,7 @@ func (vm *qemu) Update(args db.InstanceArgs, userRequested bool) error {
return errors.Wrap(err, "Snapshot update")
}
} else {
- err = db.ContainerConfigClear(tx, vm.id)
+ err = db.DeleteInstanceConfig(tx, vm.id)
if err != nil {
tx.Rollback()
return err
From 58d5f0fed95037de66b27c06a74c5eeb194ca1f8 Mon Sep 17 00:00:00 2001
From: Free Ekanayaka <free.ekanayaka at canonical.com>
Date: Thu, 30 Apr 2020 15:27:48 +0100
Subject: [PATCH 18/38] lxd/db: Rename ContainerConfigGet to GetInstanceConfig
Signed-off-by: Free Ekanayaka <free.ekanayaka at canonical.com>
---
lxd/db/containers.go | 4 ++--
lxd/instance/drivers/driver_lxc.go | 4 ++--
lxd/instance/drivers/driver_qemu.go | 2 +-
3 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/lxd/db/containers.go b/lxd/db/containers.go
index 8aabf4a1b9..93f7bc1298 100644
--- a/lxd/db/containers.go
+++ b/lxd/db/containers.go
@@ -692,8 +692,8 @@ func CreateInstanceConfig(tx *sql.Tx, id int, config map[string]string) error {
}
// ContainerConfigGet returns the value of the given key in the configuration
-// of the container with the given ID.
-func (c *Cluster) ContainerConfigGet(id int, key string) (string, error) {
+// of the instance with the given ID.
+func (c *Cluster) GetInstanceConfig(id int, key string) (string, error) {
q := "SELECT value FROM instances_config WHERE instance_id=? AND key=?"
value := ""
arg1 := []interface{}{id, key}
diff --git a/lxd/instance/drivers/driver_lxc.go b/lxd/instance/drivers/driver_lxc.go
index 7b7a3b08b9..f7014a45a6 100644
--- a/lxd/instance/drivers/driver_lxc.go
+++ b/lxd/instance/drivers/driver_lxc.go
@@ -6281,7 +6281,7 @@ func (c *lxc) FillNetworkDevice(name string, m deviceConfig.Device) (deviceConfi
err := updateKey(configKey, volatileHwaddr)
if err != nil {
// Check if something else filled it in behind our back
- value, err1 := c.state.Cluster.ContainerConfigGet(c.id, configKey)
+ value, err1 := c.state.Cluster.GetInstanceConfig(c.id, configKey)
if err1 != nil || value == "" {
return err
}
@@ -6317,7 +6317,7 @@ func (c *lxc) FillNetworkDevice(name string, m deviceConfig.Device) (deviceConfi
err = updateKey(configKey, volatileName)
if err != nil {
// Check if something else filled it in behind our back
- value, err1 := c.state.Cluster.ContainerConfigGet(c.id, configKey)
+ value, err1 := c.state.Cluster.GetInstanceConfig(c.id, configKey)
if err1 != nil || value == "" {
return nil, err
}
diff --git a/lxd/instance/drivers/driver_qemu.go b/lxd/instance/drivers/driver_qemu.go
index aa49442857..88717809fe 100644
--- a/lxd/instance/drivers/driver_qemu.go
+++ b/lxd/instance/drivers/driver_qemu.go
@@ -4090,7 +4090,7 @@ func (vm *qemu) FillNetworkDevice(name string, m deviceConfig.Device) (deviceCon
err := updateKey(configKey, volatileHwaddr)
if err != nil {
// Check if something else filled it in behind our back
- value, err1 := vm.state.Cluster.ContainerConfigGet(vm.id, configKey)
+ value, err1 := vm.state.Cluster.GetInstanceConfig(vm.id, configKey)
if err1 != nil || value == "" {
return err
}
From 7c049133089587c9b7fcf3800998735e11f26e0b Mon Sep 17 00:00:00 2001
From: Free Ekanayaka <free.ekanayaka at canonical.com>
Date: Thu, 30 Apr 2020 15:29:21 +0100
Subject: [PATCH 19/38] lxd/db: Rename ContainerConfigRemove to
DeleteInstanceConfigKey
Signed-off-by: Free Ekanayaka <free.ekanayaka at canonical.com>
---
lxd/db/containers.go | 4 ++--
lxd/instance/drivers/driver_lxc.go | 2 +-
lxd/instance/drivers/driver_qemu.go | 2 +-
lxd/instance_post.go | 2 +-
4 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/lxd/db/containers.go b/lxd/db/containers.go
index 93f7bc1298..c347699da9 100644
--- a/lxd/db/containers.go
+++ b/lxd/db/containers.go
@@ -706,9 +706,9 @@ func (c *Cluster) GetInstanceConfig(id int, key string) (string, error) {
return value, err
}
-// ContainerConfigRemove removes the given key from the config of the container
+// DeleteInstanceConfigKey removes the given key from the config of the instance
// with the given ID.
-func (c *Cluster) ContainerConfigRemove(id int, key string) error {
+func (c *Cluster) DeleteInstanceConfigKey(id int, key string) error {
err := exec(c.db, "DELETE FROM instances_config WHERE key=? AND instance_id=?", key, id)
return err
}
diff --git a/lxd/instance/drivers/driver_lxc.go b/lxd/instance/drivers/driver_lxc.go
index f7014a45a6..5106650090 100644
--- a/lxd/instance/drivers/driver_lxc.go
+++ b/lxd/instance/drivers/driver_lxc.go
@@ -2469,7 +2469,7 @@ func (c *lxc) onStart(_ map[string]string) error {
}
// Remove the volatile key from the DB
- err := c.state.Cluster.ContainerConfigRemove(c.id, key)
+ err := c.state.Cluster.DeleteInstanceConfigKey(c.id, key)
if err != nil {
apparmor.Destroy(c.state, c)
if ourStart {
diff --git a/lxd/instance/drivers/driver_qemu.go b/lxd/instance/drivers/driver_qemu.go
index 88717809fe..f5604745ac 100644
--- a/lxd/instance/drivers/driver_qemu.go
+++ b/lxd/instance/drivers/driver_qemu.go
@@ -1367,7 +1367,7 @@ echo "To start it now, unmount this filesystem and run: systemctl start lxd-agen
}
// Remove the volatile key from the DB.
- err := vm.state.Cluster.ContainerConfigRemove(vm.id, key)
+ err := vm.state.Cluster.DeleteInstanceConfigKey(vm.id, key)
if err != nil {
return err
}
diff --git a/lxd/instance_post.go b/lxd/instance_post.go
index 30f0a22037..a8a862dce4 100644
--- a/lxd/instance_post.go
+++ b/lxd/instance_post.go
@@ -378,7 +378,7 @@ func containerPostClusteringMigrate(d *Daemon, c instance.Instance, oldName, new
return errors.Wrap(err, "Failed to get ID of moved instance")
}
- err = d.cluster.ContainerConfigRemove(id, "volatile.apply_template")
+ err = d.cluster.DeleteInstanceConfigKey(id, "volatile.apply_template")
if err != nil {
return errors.Wrap(err, "Failed to remove volatile.apply_template config key")
}
From 697a38fe398129b87439753b45eac4ae2e04abfa Mon Sep 17 00:00:00 2001
From: Free Ekanayaka <free.ekanayaka at canonical.com>
Date: Thu, 30 Apr 2020 15:30:36 +0100
Subject: [PATCH 20/38] lxd/db: Rename ContainerSetStateful to
UpdateInstanceStatefulFlag
Signed-off-by: Free Ekanayaka <free.ekanayaka at canonical.com>
---
lxd/db/containers.go | 6 +++---
lxd/instance/drivers/driver_lxc.go | 6 +++---
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/lxd/db/containers.go b/lxd/db/containers.go
index c347699da9..b2287b3b5a 100644
--- a/lxd/db/containers.go
+++ b/lxd/db/containers.go
@@ -713,9 +713,9 @@ func (c *Cluster) DeleteInstanceConfigKey(id int, key string) error {
return err
}
-// ContainerSetStateful toggles the stateful flag of the container with the
-// given ID.
-func (c *Cluster) ContainerSetStateful(id int, stateful bool) error {
+// UpdateInstanceStatefulFlag toggles the stateful flag of the instance with
+// the given ID.
+func (c *Cluster) UpdateInstanceStatefulFlag(id int, stateful bool) error {
statefulInt := 0
if stateful {
statefulInt = 1
diff --git a/lxd/instance/drivers/driver_lxc.go b/lxd/instance/drivers/driver_lxc.go
index 5106650090..316353d8b1 100644
--- a/lxd/instance/drivers/driver_lxc.go
+++ b/lxd/instance/drivers/driver_lxc.go
@@ -2331,7 +2331,7 @@ func (c *lxc) Start(stateful bool) error {
os.RemoveAll(c.StatePath())
c.stateful = false
- err = c.state.Cluster.ContainerSetStateful(c.id, false)
+ err = c.state.Cluster.UpdateInstanceStatefulFlag(c.id, false)
if err != nil {
logger.Error("Failed starting container", ctxMap)
return errors.Wrap(err, "Start container")
@@ -2356,7 +2356,7 @@ func (c *lxc) Start(stateful bool) error {
}
c.stateful = false
- err = c.state.Cluster.ContainerSetStateful(c.id, false)
+ err = c.state.Cluster.UpdateInstanceStatefulFlag(c.id, false)
if err != nil {
return errors.Wrap(err, "Persist stateful flag")
}
@@ -2589,7 +2589,7 @@ func (c *lxc) Stop(stateful bool) error {
}
c.stateful = true
- err = c.state.Cluster.ContainerSetStateful(c.id, true)
+ err = c.state.Cluster.UpdateInstanceStatefulFlag(c.id, true)
if err != nil {
op.Done(err)
logger.Error("Failed stopping container", ctxMap)
From ce221e7171b7e3ce9cd69cc526f2d5d572c34679 Mon Sep 17 00:00:00 2001
From: Free Ekanayaka <free.ekanayaka at canonical.com>
Date: Thu, 30 Apr 2020 15:35:29 +0100
Subject: [PATCH 21/38] lxd/db: Rename ContainerProfilesInsert to
AddProfilesToInstance
Signed-off-by: Free Ekanayaka <free.ekanayaka at canonical.com>
---
lxd/db/containers.go | 4 ++--
lxd/db/instances.mapper.go | 2 +-
lxd/instance/drivers/driver_lxc.go | 2 +-
lxd/instance/drivers/driver_qemu.go | 2 +-
shared/generate/db/method.go | 2 +-
5 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/lxd/db/containers.go b/lxd/db/containers.go
index b2287b3b5a..0cb831cdd2 100644
--- a/lxd/db/containers.go
+++ b/lxd/db/containers.go
@@ -725,9 +725,9 @@ func (c *Cluster) UpdateInstanceStatefulFlag(id int, stateful bool) error {
return err
}
-// ContainerProfilesInsert associates the container with the given ID with the
+// AddProfilesToInstance associates the instance with the given ID with the
// profiles with the given names in the given project.
-func ContainerProfilesInsert(tx *sql.Tx, id int, project string, profiles []string) error {
+func AddProfilesToInstance(tx *sql.Tx, id int, project string, profiles []string) error {
enabled, err := projectHasProfiles(tx, project)
if err != nil {
return errors.Wrap(err, "Check if project has profiles")
diff --git a/lxd/db/instances.mapper.go b/lxd/db/instances.mapper.go
index bac855fa3d..06ccb110c3 100644
--- a/lxd/db/instances.mapper.go
+++ b/lxd/db/instances.mapper.go
@@ -554,7 +554,7 @@ func (c *ClusterTx) InstanceCreate(object Instance) (int64, error) {
}
// Insert profiles reference.
- err = ContainerProfilesInsert(c.tx, int(id), object.Project, object.Profiles)
+ err = AddProfilesToInstance(c.tx, int(id), object.Project, object.Profiles)
if err != nil {
return -1, errors.Wrap(err, "Insert profiles for instance")
}
diff --git a/lxd/instance/drivers/driver_lxc.go b/lxd/instance/drivers/driver_lxc.go
index 316353d8b1..a55b57550b 100644
--- a/lxd/instance/drivers/driver_lxc.go
+++ b/lxd/instance/drivers/driver_lxc.go
@@ -4378,7 +4378,7 @@ func (c *lxc) Update(args db.InstanceArgs, userRequested bool) error {
return errors.Wrap(err, "Config insert")
}
- err = db.ContainerProfilesInsert(tx, c.id, c.project, c.profiles)
+ err = db.AddProfilesToInstance(tx, c.id, c.project, c.profiles)
if err != nil {
tx.Rollback()
return errors.Wrap(err, "Profiles insert")
diff --git a/lxd/instance/drivers/driver_qemu.go b/lxd/instance/drivers/driver_qemu.go
index f5604745ac..99f59bd026 100644
--- a/lxd/instance/drivers/driver_qemu.go
+++ b/lxd/instance/drivers/driver_qemu.go
@@ -2623,7 +2623,7 @@ func (vm *qemu) Update(args db.InstanceArgs, userRequested bool) error {
return errors.Wrap(err, "Config insert")
}
- err = db.ContainerProfilesInsert(tx, vm.id, vm.project, vm.profiles)
+ err = db.AddProfilesToInstance(tx, vm.id, vm.project, vm.profiles)
if err != nil {
tx.Rollback()
return errors.Wrap(err, "Profiles insert")
diff --git a/shared/generate/db/method.go b/shared/generate/db/method.go
index f329b48bbf..5c78b58927 100644
--- a/shared/generate/db/method.go
+++ b/shared/generate/db/method.go
@@ -732,7 +732,7 @@ func (m *Method) create(buf *file.Buffer) error {
if field.Name == "Profiles" {
// TODO: get rid of the special case
buf.L("// Insert profiles reference. ")
- buf.L("err = ContainerProfilesInsert(c.tx, int(id), object.Project, object.Profiles)")
+ buf.L("err = AddProfilesToInstance(c.tx, int(id), object.Project, object.Profiles)")
buf.L("if err != nil {")
buf.L(" return -1, errors.Wrap(err, \"Insert profiles for %s\")", m.entity)
buf.L("}")
From f22e9325e32d8574259dd341b6b344f1b00536e5 Mon Sep 17 00:00:00 2001
From: Free Ekanayaka <free.ekanayaka at canonical.com>
Date: Thu, 30 Apr 2020 15:36:51 +0100
Subject: [PATCH 22/38] lxd/db: Drop unused ContainerProfiles
Signed-off-by: Free Ekanayaka <free.ekanayaka at canonical.com>
---
lxd/db/containers.go | 27 ---------------------------
lxd/db/db_internal_test.go | 15 ---------------
2 files changed, 42 deletions(-)
diff --git a/lxd/db/containers.go b/lxd/db/containers.go
index 0cb831cdd2..3b5f141523 100644
--- a/lxd/db/containers.go
+++ b/lxd/db/containers.go
@@ -766,33 +766,6 @@ INSERT INTO instances_profiles (instance_id, profile_id, apply_order)
return nil
}
-// ContainerProfiles returns a list of profiles for a given container ID.
-func (c *Cluster) ContainerProfiles(id int) ([]string, error) {
- var name string
- var profiles []string
-
- query := `
- SELECT name FROM instances_profiles
- JOIN profiles ON instances_profiles.profile_id=profiles.id
- WHERE instance_id=?
- ORDER BY instances_profiles.apply_order`
- inargs := []interface{}{id}
- outfmt := []interface{}{name}
-
- results, err := queryScan(c.db, query, inargs, outfmt)
- if err != nil {
- return nil, err
- }
-
- for _, r := range results {
- name = r[0].(string)
-
- profiles = append(profiles, name)
- }
-
- return profiles, nil
-}
-
// ContainerConfig gets the container configuration map from the DB
func (c *Cluster) ContainerConfig(id int) (map[string]string, error) {
var key, value string
diff --git a/lxd/db/db_internal_test.go b/lxd/db/db_internal_test.go
index faec44a409..aebff5da70 100644
--- a/lxd/db/db_internal_test.go
+++ b/lxd/db/db_internal_test.go
@@ -315,21 +315,6 @@ func (s *dbTestSuite) Test_dbProfileConfig() {
}
}
-func (s *dbTestSuite) Test_ContainerProfiles() {
- var err error
- var result []string
- var expected []string
-
- expected = []string{"theprofile"}
- result, err = s.db.ContainerProfiles(1)
- s.Nil(err)
-
- for i := range expected {
- s.Equal(expected[i], result[i],
- fmt.Sprintf("Mismatching contents for profile list: %s != %s", result[i], expected[i]))
- }
-}
-
func (s *dbTestSuite) Test_dbDevices_profiles() {
var err error
var result deviceConfig.Devices
From 821e26a1d49bbdb2f0421e83de98c9949373f907 Mon Sep 17 00:00:00 2001
From: Free Ekanayaka <free.ekanayaka at canonical.com>
Date: Thu, 30 Apr 2020 15:38:08 +0100
Subject: [PATCH 23/38] lxd/db: Drop unused ContainerConfig
Signed-off-by: Free Ekanayaka <free.ekanayaka at canonical.com>
---
lxd/db/containers.go | 26 --------------------------
lxd/db/db_internal_test.go | 23 -----------------------
2 files changed, 49 deletions(-)
diff --git a/lxd/db/containers.go b/lxd/db/containers.go
index 3b5f141523..9ea197a8ee 100644
--- a/lxd/db/containers.go
+++ b/lxd/db/containers.go
@@ -766,32 +766,6 @@ INSERT INTO instances_profiles (instance_id, profile_id, apply_order)
return nil
}
-// ContainerConfig gets the container configuration map from the DB
-func (c *Cluster) ContainerConfig(id int) (map[string]string, error) {
- var key, value string
- q := `SELECT key, value FROM instances_config WHERE instance_id=?`
-
- inargs := []interface{}{id}
- outfmt := []interface{}{key, value}
-
- // Results is already a slice here, not db Rows anymore.
- results, err := queryScan(c.db, q, inargs, outfmt)
- if err != nil {
- return nil, err //SmartError will wrap this and make "not found" errors pretty
- }
-
- config := map[string]string{}
-
- for _, r := range results {
- key = r[0].(string)
- value = r[1].(string)
-
- config[key] = value
- }
-
- return config, nil
-}
-
// LegacyContainersList returns the names of all the containers.
//
// NOTE: this is a pre-projects legacy API that is used only by patches. Don't
diff --git a/lxd/db/db_internal_test.go b/lxd/db/db_internal_test.go
index aebff5da70..28b6013eb3 100644
--- a/lxd/db/db_internal_test.go
+++ b/lxd/db/db_internal_test.go
@@ -269,29 +269,6 @@ func (s *dbTestSuite) Test_ImageSourceGetCachedFingerprint_no_match() {
s.Equal(err, ErrNoSuchObject)
}
-func (s *dbTestSuite) Test_ContainerConfig() {
- var err error
- var result map[string]string
- var expected map[string]string
-
- tx, commit := s.CreateTestTx()
-
- _, err = tx.Exec("INSERT INTO instances_config (instance_id, key, value) VALUES (1, 'something', 'something else');")
- s.Nil(err)
-
- commit()
-
- result, err = s.db.ContainerConfig(1)
- s.Nil(err)
-
- expected = map[string]string{"thekey": "thevalue", "something": "something else"}
-
- for key, value := range expected {
- s.Equal(result[key], value,
- fmt.Sprintf("Mismatching value for key %s: %s != %s", key, result[key], value))
- }
-}
-
func (s *dbTestSuite) Test_dbProfileConfig() {
var err error
var result map[string]string
From 7b9905f58fb27947d4cdb38b4db47204db84d70f Mon Sep 17 00:00:00 2001
From: Free Ekanayaka <free.ekanayaka at canonical.com>
Date: Thu, 30 Apr 2020 15:39:30 +0100
Subject: [PATCH 24/38] lxd/db: Remove unused ContainersNodeList
Signed-off-by: Free Ekanayaka <free.ekanayaka at canonical.com>
---
lxd/db/containers.go | 20 --------------------
lxd/db/containers_test.go | 24 ------------------------
2 files changed, 44 deletions(-)
diff --git a/lxd/db/containers.go b/lxd/db/containers.go
index 9ea197a8ee..13d8dbb28f 100644
--- a/lxd/db/containers.go
+++ b/lxd/db/containers.go
@@ -816,26 +816,6 @@ WHERE type=? ORDER BY instances.name, instances_snapshots.name
return ret, nil
}
-// ContainersNodeList returns the names of all the containers of the given type
-// running on the local node.
-func (c *Cluster) ContainersNodeList(instanceType instancetype.Type) ([]string, error) {
- q := fmt.Sprintf("SELECT name FROM instances WHERE type=? AND node_id=? ORDER BY name")
- inargs := []interface{}{instanceType, c.nodeID}
- var container string
- outfmt := []interface{}{container}
- result, err := queryScan(c.db, q, inargs, outfmt)
- if err != nil {
- return nil, err
- }
-
- var ret []string
- for _, container := range result {
- ret = append(ret, container[0].(string))
- }
-
- return ret, nil
-}
-
// ContainersResetState resets the power state of all containers.
func (c *Cluster) ContainersResetState() error {
// Reset all container states
diff --git a/lxd/db/containers_test.go b/lxd/db/containers_test.go
index da01de60e3..52f4d44fee 100644
--- a/lxd/db/containers_test.go
+++ b/lxd/db/containers_test.go
@@ -381,30 +381,6 @@ func TestInstancePool(t *testing.T) {
assert.Equal(t, "default", poolName)
}
-// Only containers running on the local node are returned.
-func TestContainersNodeList(t *testing.T) {
- cluster, cleanup := db.NewTestCluster(t)
- defer cleanup()
-
- nodeID1 := int64(1) // This is the default local node
-
- // Add another node
- var nodeID2 int64
- err := cluster.Transaction(func(tx *db.ClusterTx) error {
- var err error
- nodeID2, err = tx.NodeAdd("node2", "1.2.3.4:666")
- require.NoError(t, err)
- addContainer(t, tx, nodeID1, "c1")
- addContainer(t, tx, nodeID2, "c2")
- return nil
- })
- require.NoError(t, err)
-
- names, err := cluster.ContainersNodeList(instancetype.Container)
- require.NoError(t, err)
- assert.Equal(t, names, []string{"c1"})
-}
-
// All containers on a node are loaded in bulk.
func TestGetLocalInstancesInProject(t *testing.T) {
tx, cleanup := db.NewTestClusterTx(t)
From 50c08dc39065c75ed228f368274bb5ab0b63273e Mon Sep 17 00:00:00 2001
From: Free Ekanayaka <free.ekanayaka at canonical.com>
Date: Thu, 30 Apr 2020 15:40:59 +0100
Subject: [PATCH 25/38] lxd/db: Rename ContainersResetState to
ResetInstancesPowerState
Signed-off-by: Free Ekanayaka <free.ekanayaka at canonical.com>
---
lxd/db/containers.go | 4 ++--
lxd/instances.go | 4 ++--
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/lxd/db/containers.go b/lxd/db/containers.go
index 13d8dbb28f..9bd78ce275 100644
--- a/lxd/db/containers.go
+++ b/lxd/db/containers.go
@@ -816,8 +816,8 @@ WHERE type=? ORDER BY instances.name, instances_snapshots.name
return ret, nil
}
-// ContainersResetState resets the power state of all containers.
-func (c *Cluster) ContainersResetState() error {
+// ResetInstancesPowerState resets the power state of all instances.
+func (c *Cluster) ResetInstancesPowerState() error {
// Reset all container states
err := exec(c.db, "DELETE FROM instances_config WHERE key='volatile.last_state.power'")
return err
diff --git a/lxd/instances.go b/lxd/instances.go
index b7f8366daf..900d938d73 100644
--- a/lxd/instances.go
+++ b/lxd/instances.go
@@ -350,8 +350,8 @@ func containersShutdown(s *state.State) error {
sort.Sort(containerStopList(instances))
if dbAvailable {
- // Reset all container states
- err = s.Cluster.ContainersResetState()
+ // Reset all instances states
+ err = s.Cluster.ResetInstancesPowerState()
if err != nil {
return err
}
From 7792cfab143d21e250482dc83661dedc446709bf Mon Sep 17 00:00:00 2001
From: Free Ekanayaka <free.ekanayaka at canonical.com>
Date: Thu, 30 Apr 2020 15:42:21 +0100
Subject: [PATCH 26/38] lxd/db: Rename ContainerSetState to
UpdateInstancePowerState
Signed-off-by: Free Ekanayaka <free.ekanayaka at canonical.com>
---
lxd/db/containers.go | 11 ++++++-----
lxd/instance/drivers/driver_lxc.go | 4 ++--
lxd/instance/drivers/driver_qemu.go | 4 ++--
3 files changed, 10 insertions(+), 9 deletions(-)
diff --git a/lxd/db/containers.go b/lxd/db/containers.go
index 9bd78ce275..0263bf3409 100644
--- a/lxd/db/containers.go
+++ b/lxd/db/containers.go
@@ -823,16 +823,17 @@ func (c *Cluster) ResetInstancesPowerState() error {
return err
}
-// ContainerSetState sets the the power state of the container with the given ID.
-func (c *Cluster) ContainerSetState(id int, state string) error {
+// UpdateInstancePowerState sets the the power state of the instance with the
+// given ID.
+func (c *Cluster) UpdateInstancePowerState(id int, state string) error {
err := c.Transaction(func(tx *ClusterTx) error {
- return tx.ContainerSetState(id, state)
+ return tx.UpdateInstancePowerState(id, state)
})
return err
}
-// ContainerSetState sets the the power state of the container with the given ID.
-func (c *ClusterTx) ContainerSetState(id int, state string) error {
+// UpdateInstancePowerState sets the the power state of the container with the given ID.
+func (c *ClusterTx) UpdateInstancePowerState(id int, state string) error {
// Set the new value
str := fmt.Sprintf("INSERT OR REPLACE INTO instances_config (instance_id, key, value) VALUES (?, 'volatile.last_state.power', ?)")
stmt, err := c.tx.Prepare(str)
diff --git a/lxd/instance/drivers/driver_lxc.go b/lxd/instance/drivers/driver_lxc.go
index a55b57550b..da2a4fcc1d 100644
--- a/lxd/instance/drivers/driver_lxc.go
+++ b/lxd/instance/drivers/driver_lxc.go
@@ -2505,7 +2505,7 @@ func (c *lxc) onStart(_ map[string]string) error {
// Database updates
err = c.state.Cluster.Transaction(func(tx *db.ClusterTx) error {
// Record current state
- err = tx.ContainerSetState(c.id, "RUNNING")
+ err = tx.UpdateInstancePowerState(c.id, "RUNNING")
if err != nil {
return errors.Wrap(err, "Error updating container state")
}
@@ -2811,7 +2811,7 @@ func (c *lxc) onStop(args map[string]string) error {
}
// Record power state
- err = c.state.Cluster.ContainerSetState(c.id, "STOPPED")
+ err = c.state.Cluster.UpdateInstancePowerState(c.id, "STOPPED")
if err != nil {
logger.Error("Failed to set container state", log.Ctx{"container": c.Name(), "err": err})
}
diff --git a/lxd/instance/drivers/driver_qemu.go b/lxd/instance/drivers/driver_qemu.go
index 99f59bd026..7a9a9d02a5 100644
--- a/lxd/instance/drivers/driver_qemu.go
+++ b/lxd/instance/drivers/driver_qemu.go
@@ -495,7 +495,7 @@ func (vm *qemu) onStop(target string) error {
vm.unmount()
// Record power state.
- err := vm.state.Cluster.ContainerSetState(vm.id, "STOPPED")
+ err := vm.state.Cluster.UpdateInstancePowerState(vm.id, "STOPPED")
if err != nil {
op.Done(err)
return err
@@ -916,7 +916,7 @@ func (vm *qemu) Start(stateful bool) error {
// Database updates
err = vm.state.Cluster.Transaction(func(tx *db.ClusterTx) error {
// Record current state
- err = tx.ContainerSetState(vm.id, "RUNNING")
+ err = tx.UpdateInstancePowerState(vm.id, "RUNNING")
if err != nil {
err = errors.Wrap(err, "Error updating instance state")
op.Done(err)
From f00dc462dd999b2f287e0927235c32a486298a02 Mon Sep 17 00:00:00 2001
From: Free Ekanayaka <free.ekanayaka at canonical.com>
Date: Thu, 30 Apr 2020 15:43:42 +0100
Subject: [PATCH 27/38] lxd/db: Rename ContainerUpdate to UpdateInstance
Signed-off-by: Free Ekanayaka <free.ekanayaka at canonical.com>
---
lxd/db/containers.go | 6 +++---
lxd/instance/drivers/driver_lxc.go | 2 +-
lxd/instance/drivers/driver_qemu.go | 2 +-
3 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/lxd/db/containers.go b/lxd/db/containers.go
index 0263bf3409..563ada38b5 100644
--- a/lxd/db/containers.go
+++ b/lxd/db/containers.go
@@ -850,9 +850,9 @@ func (c *ClusterTx) UpdateInstancePowerState(id int, state string) error {
return nil
}
-// ContainerUpdate updates the description, architecture and ephemeral flag of
-// the container with the given ID.
-func ContainerUpdate(tx *sql.Tx, id int, description string, architecture int, ephemeral bool,
+// UpdateInstance updates the description, architecture and ephemeral flag of
+// the instance with the given ID.
+func UpdateInstance(tx *sql.Tx, id int, description string, architecture int, ephemeral bool,
expiryDate time.Time) error {
str := fmt.Sprintf("UPDATE instances SET description=?, architecture=?, ephemeral=?, expiry_date=? WHERE id=?")
stmt, err := tx.Prepare(str)
diff --git a/lxd/instance/drivers/driver_lxc.go b/lxd/instance/drivers/driver_lxc.go
index da2a4fcc1d..a0f39d7dc7 100644
--- a/lxd/instance/drivers/driver_lxc.go
+++ b/lxd/instance/drivers/driver_lxc.go
@@ -4390,7 +4390,7 @@ func (c *lxc) Update(args db.InstanceArgs, userRequested bool) error {
return errors.Wrap(err, "Device add")
}
- err = db.ContainerUpdate(tx, c.id, c.description, c.architecture, c.ephemeral, c.expiryDate)
+ err = db.UpdateInstance(tx, c.id, c.description, c.architecture, c.ephemeral, c.expiryDate)
if err != nil {
tx.Rollback()
return errors.Wrap(err, "Container update")
diff --git a/lxd/instance/drivers/driver_qemu.go b/lxd/instance/drivers/driver_qemu.go
index 7a9a9d02a5..f0f2348552 100644
--- a/lxd/instance/drivers/driver_qemu.go
+++ b/lxd/instance/drivers/driver_qemu.go
@@ -2635,7 +2635,7 @@ func (vm *qemu) Update(args db.InstanceArgs, userRequested bool) error {
return errors.Wrap(err, "Device add")
}
- err = db.ContainerUpdate(tx, vm.id, vm.description, vm.architecture, vm.ephemeral, vm.expiryDate)
+ err = db.UpdateInstance(tx, vm.id, vm.description, vm.architecture, vm.ephemeral, vm.expiryDate)
if err != nil {
tx.Rollback()
return errors.Wrap(err, "Instance update")
From 60cc8ae3cc2bf21f79214555d899815f3ad9860d Mon Sep 17 00:00:00 2001
From: Free Ekanayaka <free.ekanayaka at canonical.com>
Date: Thu, 30 Apr 2020 15:45:37 +0100
Subject: [PATCH 28/38] lxd/db: Rename InstanceSnapshotCreationUpdate to
UpdateInstanceSnapshotCreationDate
Signed-off-by: Free Ekanayaka <free.ekanayaka at canonical.com>
---
lxd/db/containers.go | 2 +-
lxd/instance.go | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/lxd/db/containers.go b/lxd/db/containers.go
index 563ada38b5..8c6aa58b58 100644
--- a/lxd/db/containers.go
+++ b/lxd/db/containers.go
@@ -879,7 +879,7 @@ func UpdateInstance(tx *sql.Tx, id int, description string, architecture int, ep
}
// InstanceSnapshotCreationUpdate updates the creation_date field of the instance snapshot with ID.
-func (c *Cluster) InstanceSnapshotCreationUpdate(instanceID int, date time.Time) error {
+func (c *Cluster) UpdateInstanceSnapshotCreationDate(instanceID int, date time.Time) error {
stmt := `UPDATE instances_snapshots SET creation_date=? WHERE id=?`
err := exec(c.db, stmt, date, instanceID)
return err
diff --git a/lxd/instance.go b/lxd/instance.go
index 3be1c2e4ef..c5a1de4d49 100644
--- a/lxd/instance.go
+++ b/lxd/instance.go
@@ -287,7 +287,7 @@ func instanceCreateAsCopy(s *state.State, args db.InstanceArgs, sourceInst insta
}
// Set snapshot creation date to that of the source snapshot.
- err = s.Cluster.InstanceSnapshotCreationUpdate(snapInst.ID(), srcSnap.CreationDate())
+ err = s.Cluster.UpdateInstanceSnapshotCreationDate(snapInst.ID(), srcSnap.CreationDate())
if err != nil {
return nil, err
}
From 1134328b3210e4b8c4d9eca4d43f7eb0eff117c3 Mon Sep 17 00:00:00 2001
From: Free Ekanayaka <free.ekanayaka at canonical.com>
Date: Thu, 30 Apr 2020 15:46:50 +0100
Subject: [PATCH 29/38] lxd/db: Rename ContainerLastUsedUpdate to
UpdateInstanceLastUsedDate
Signed-off-by: Free Ekanayaka <free.ekanayaka at canonical.com>
---
lxd/db/containers.go | 4 ++--
lxd/instance/drivers/driver_lxc.go | 2 +-
lxd/instance/drivers/driver_qemu.go | 2 +-
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/lxd/db/containers.go b/lxd/db/containers.go
index 8c6aa58b58..ea3e897ed1 100644
--- a/lxd/db/containers.go
+++ b/lxd/db/containers.go
@@ -885,9 +885,9 @@ func (c *Cluster) UpdateInstanceSnapshotCreationDate(instanceID int, date time.T
return err
}
-// ContainerLastUsedUpdate updates the last_use_date field of the container
+// UpdateInstanceLastUsedDate updates the last_use_date field of the instance
// with the given ID.
-func (c *ClusterTx) ContainerLastUsedUpdate(id int, date time.Time) error {
+func (c *ClusterTx) UpdateInstanceLastUsedDate(id int, date time.Time) error {
str := `UPDATE instances SET last_use_date=? WHERE id=?`
stmt, err := c.tx.Prepare(str)
if err != nil {
diff --git a/lxd/instance/drivers/driver_lxc.go b/lxd/instance/drivers/driver_lxc.go
index a0f39d7dc7..98e8da236f 100644
--- a/lxd/instance/drivers/driver_lxc.go
+++ b/lxd/instance/drivers/driver_lxc.go
@@ -2511,7 +2511,7 @@ func (c *lxc) onStart(_ map[string]string) error {
}
// Update time container last started time
- err = tx.ContainerLastUsedUpdate(c.id, time.Now().UTC())
+ err = tx.UpdateInstanceLastUsedDate(c.id, time.Now().UTC())
if err != nil {
return errors.Wrap(err, "Error updating last used")
}
diff --git a/lxd/instance/drivers/driver_qemu.go b/lxd/instance/drivers/driver_qemu.go
index f0f2348552..fb09c11100 100644
--- a/lxd/instance/drivers/driver_qemu.go
+++ b/lxd/instance/drivers/driver_qemu.go
@@ -924,7 +924,7 @@ func (vm *qemu) Start(stateful bool) error {
}
// Update time instance last started time
- err = tx.ContainerLastUsedUpdate(vm.id, time.Now().UTC())
+ err = tx.UpdateInstanceLastUsedDate(vm.id, time.Now().UTC())
if err != nil {
err = errors.Wrap(err, "Error updating instance last used")
op.Done(err)
From f0492c8738f2d960d03f81dcf144a7719acdba94 Mon Sep 17 00:00:00 2001
From: Free Ekanayaka <free.ekanayaka at canonical.com>
Date: Thu, 30 Apr 2020 15:52:23 +0100
Subject: [PATCH 30/38] lxd/db: Rename ContainerGetSnapshots to
GetInstanceSnapshotsNames
Signed-off-by: Free Ekanayaka <free.ekanayaka at canonical.com>
---
lxd/db/containers.go | 8 ++++----
lxd/instance/drivers/driver_lxc.go | 4 ++--
lxd/instance/drivers/driver_qemu.go | 4 ++--
lxd/instance/instance_utils.go | 2 +-
lxd/instance_post.go | 2 +-
lxd/instance_snapshot.go | 2 +-
lxd/patches.go | 6 +++---
lxd/storage/backend_lxd.go | 4 ++--
8 files changed, 16 insertions(+), 16 deletions(-)
diff --git a/lxd/db/containers.go b/lxd/db/containers.go
index ea3e897ed1..d57a3964c0 100644
--- a/lxd/db/containers.go
+++ b/lxd/db/containers.go
@@ -903,9 +903,9 @@ func (c *ClusterTx) UpdateInstanceLastUsedDate(id int, date time.Time) error {
return nil
}
-// ContainerGetSnapshots returns the names of all snapshots of the container
+// GetInstanceSnapshotsNames returns the names of all snapshots of the instance
// in the given project with the given name.
-func (c *Cluster) ContainerGetSnapshots(project, name string) ([]string, error) {
+func (c *Cluster) GetInstanceSnapshotsNames(project, name string) ([]string, error) {
result := []string{}
q := `
@@ -930,8 +930,8 @@ ORDER BY date(instances_snapshots.creation_date)
return result, nil
}
-// ContainerGetSnapshotsFull returns all container objects for snapshots of a given container
-func (c *ClusterTx) ContainerGetSnapshotsFull(project string, name string) ([]Instance, error) {
+// GetInstanceSnapshots returns all snapshots of a given instance.
+func (c *ClusterTx) GetInstanceSnapshots(project string, name string) ([]Instance, error) {
instance, err := c.InstanceGet(project, name)
if err != nil {
return nil, err
diff --git a/lxd/instance/drivers/driver_lxc.go b/lxd/instance/drivers/driver_lxc.go
index 98e8da236f..630e025473 100644
--- a/lxd/instance/drivers/driver_lxc.go
+++ b/lxd/instance/drivers/driver_lxc.go
@@ -3187,7 +3187,7 @@ func (c *lxc) Snapshots() ([]instance.Instance, error) {
// Get all the snapshots
err := c.state.Cluster.Transaction(func(tx *db.ClusterTx) error {
var err error
- snaps, err = tx.ContainerGetSnapshotsFull(c.Project(), c.name)
+ snaps, err = tx.GetInstanceSnapshots(c.Project(), c.name)
if err != nil {
return err
}
@@ -3585,7 +3585,7 @@ func (c *lxc) Rename(newName string) error {
if !c.IsSnapshot() {
// Rename all the instance snapshot database entries.
- results, err := c.state.Cluster.ContainerGetSnapshots(c.project, oldName)
+ results, err := c.state.Cluster.GetInstanceSnapshotsNames(c.project, oldName)
if err != nil {
logger.Error("Failed to get container snapshots", ctxMap)
return err
diff --git a/lxd/instance/drivers/driver_qemu.go b/lxd/instance/drivers/driver_qemu.go
index fb09c11100..848696ca3c 100644
--- a/lxd/instance/drivers/driver_qemu.go
+++ b/lxd/instance/drivers/driver_qemu.go
@@ -2184,7 +2184,7 @@ func (vm *qemu) Snapshots() ([]instance.Instance, error) {
// Get all the snapshots
err := vm.state.Cluster.Transaction(func(tx *db.ClusterTx) error {
var err error
- snaps, err = tx.ContainerGetSnapshotsFull(vm.Project(), vm.name)
+ snaps, err = tx.GetInstanceSnapshots(vm.Project(), vm.name)
if err != nil {
return err
}
@@ -2260,7 +2260,7 @@ func (vm *qemu) Rename(newName string) error {
if !vm.IsSnapshot() {
// Rename all the instance snapshot database entries.
- results, err := vm.state.Cluster.ContainerGetSnapshots(vm.project, oldName)
+ results, err := vm.state.Cluster.GetInstanceSnapshotsNames(vm.project, oldName)
if err != nil {
logger.Error("Failed to get instance snapshots", ctxMap)
return err
diff --git a/lxd/instance/instance_utils.go b/lxd/instance/instance_utils.go
index 258273abec..d94aca94a9 100644
--- a/lxd/instance/instance_utils.go
+++ b/lxd/instance/instance_utils.go
@@ -586,7 +586,7 @@ func LoadNodeAll(s *state.State, instanceType instancetype.Type) ([]Instance, er
// DeleteSnapshots calls the Delete() function on each of the supplied instance's snapshots.
func DeleteSnapshots(s *state.State, projectName, instanceName string) error {
- results, err := s.Cluster.ContainerGetSnapshots(projectName, instanceName)
+ results, err := s.Cluster.GetInstanceSnapshotsNames(projectName, instanceName)
if err != nil {
return err
}
diff --git a/lxd/instance_post.go b/lxd/instance_post.go
index a8a862dce4..3aab1d50f1 100644
--- a/lxd/instance_post.go
+++ b/lxd/instance_post.go
@@ -512,7 +512,7 @@ func containerPostCreateContainerMountPoint(d *Daemon, project, containerName st
if err != nil {
return errors.Wrap(err, "Failed get pool name of moved instance on target node")
}
- snapshotNames, err := d.cluster.ContainerGetSnapshots(project, containerName)
+ snapshotNames, err := d.cluster.GetInstanceSnapshotsNames(project, containerName)
if err != nil {
return errors.Wrap(err, "Failed to create instance snapshot names")
}
diff --git a/lxd/instance_snapshot.go b/lxd/instance_snapshot.go
index 5c323366a0..18865f675b 100644
--- a/lxd/instance_snapshot.go
+++ b/lxd/instance_snapshot.go
@@ -48,7 +48,7 @@ func containerSnapshotsGet(d *Daemon, r *http.Request) response.Response {
resultMap := []*api.InstanceSnapshot{}
if !recursion {
- snaps, err := d.cluster.ContainerGetSnapshots(projectName, cname)
+ snaps, err := d.cluster.GetInstanceSnapshotsNames(projectName, cname)
if err != nil {
return response.SmartError(err)
}
diff --git a/lxd/patches.go b/lxd/patches.go
index 64a8663bef..f4b0d495e4 100644
--- a/lxd/patches.go
+++ b/lxd/patches.go
@@ -619,7 +619,7 @@ func upgradeFromStorageTypeBtrfs(name string, d *Daemon, defaultPoolName string,
}
// Check if we need to account for snapshots for this container.
- ctSnapshots, err := d.cluster.ContainerGetSnapshots("default", ct)
+ ctSnapshots, err := d.cluster.GetInstanceSnapshotsNames("default", ct)
if err != nil {
return err
}
@@ -1304,7 +1304,7 @@ func upgradeFromStorageTypeLvm(name string, d *Daemon, defaultPoolName string, d
}
// Check if we need to account for snapshots for this container.
- ctSnapshots, err := d.cluster.ContainerGetSnapshots("default", ct)
+ ctSnapshots, err := d.cluster.GetInstanceSnapshotsNames("default", ct)
if err != nil {
return err
}
@@ -1763,7 +1763,7 @@ func upgradeFromStorageTypeZfs(name string, d *Daemon, defaultPoolName string, d
}
// Check if we need to account for snapshots for this container.
- ctSnapshots, err := d.cluster.ContainerGetSnapshots("default", ct)
+ ctSnapshots, err := d.cluster.GetInstanceSnapshotsNames("default", ct)
if err != nil {
logger.Errorf("Failed to query database")
return err
diff --git a/lxd/storage/backend_lxd.go b/lxd/storage/backend_lxd.go
index 574ff172d7..2c4ed19c5e 100644
--- a/lxd/storage/backend_lxd.go
+++ b/lxd/storage/backend_lxd.go
@@ -1170,7 +1170,7 @@ func (b *lxdBackend) RenameInstance(inst instance.Instance, newName string, op *
defer revert.Fail()
// Get any snapshots the instance has in the format <instance name>/<snapshot name>.
- snapshots, err := b.state.Cluster.ContainerGetSnapshots(inst.Project(), inst.Name())
+ snapshots, err := b.state.Cluster.GetInstanceSnapshotsNames(inst.Project(), inst.Name())
if err != nil {
return err
}
@@ -1283,7 +1283,7 @@ func (b *lxdBackend) DeleteInstance(inst instance.Instance, op *operations.Opera
}
// Get any snapshots the instance has in the format <instance name>/<snapshot name>.
- snapshots, err := b.state.Cluster.ContainerGetSnapshots(inst.Project(), inst.Name())
+ snapshots, err := b.state.Cluster.GetInstanceSnapshotsNames(inst.Project(), inst.Name())
if err != nil {
return err
}
From 5f8f11b2e00d5f82f06000a3e5d40bb7192fce7c Mon Sep 17 00:00:00 2001
From: Free Ekanayaka <free.ekanayaka at canonical.com>
Date: Thu, 30 Apr 2020 15:54:06 +0100
Subject: [PATCH 31/38] lxd/db: Rename ContainerNextSnapshot to
GetNextInstanceSnapshotIndex
Signed-off-by: Free Ekanayaka <free.ekanayaka at canonical.com>
---
lxd/db/containers.go | 6 +++---
lxd/instance.go | 4 ++--
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/lxd/db/containers.go b/lxd/db/containers.go
index d57a3964c0..c9cb878199 100644
--- a/lxd/db/containers.go
+++ b/lxd/db/containers.go
@@ -956,9 +956,9 @@ func (c *ClusterTx) GetInstanceSnapshots(project string, name string) ([]Instanc
return instances, nil
}
-// ContainerNextSnapshot returns the index the next snapshot of the container
-// with the given name and pattern should have.
-func (c *Cluster) ContainerNextSnapshot(project string, name string, pattern string) int {
+// GetNextInstanceSnapshotIndex returns the index that the next snapshot of the
+// instance with the given name and pattern should have.
+func (c *Cluster) GetNextInstanceSnapshotIndex(project string, name string, pattern string) int {
q := `
SELECT instances_snapshots.name
FROM instances_snapshots
diff --git a/lxd/instance.go b/lxd/instance.go
index c5a1de4d49..e98e6500fb 100644
--- a/lxd/instance.go
+++ b/lxd/instance.go
@@ -941,7 +941,7 @@ func containerDetermineNextSnapshotName(d *Daemon, c instance.Instance, defaultP
if count > 1 {
return "", fmt.Errorf("Snapshot pattern may contain '%%d' only once")
} else if count == 1 {
- i := d.cluster.ContainerNextSnapshot(c.Project(), c.Name(), pattern)
+ i := d.cluster.GetNextInstanceSnapshotIndex(c.Project(), c.Name(), pattern)
return strings.Replace(pattern, "%d", strconv.Itoa(i), 1), nil
}
@@ -963,7 +963,7 @@ func containerDetermineNextSnapshotName(d *Daemon, c instance.Instance, defaultP
// Append '-0', '-1', etc. if the actual pattern/snapshot name already exists
if snapshotExists {
pattern = fmt.Sprintf("%s-%%d", pattern)
- i := d.cluster.ContainerNextSnapshot(c.Project(), c.Name(), pattern)
+ i := d.cluster.GetNextInstanceSnapshotIndex(c.Project(), c.Name(), pattern)
return strings.Replace(pattern, "%d", strconv.Itoa(i), 1), nil
}
From 982408e7416e50a31bc136ca7b7452d0798e4b3d Mon Sep 17 00:00:00 2001
From: Free Ekanayaka <free.ekanayaka at canonical.com>
Date: Thu, 30 Apr 2020 15:56:24 +0100
Subject: [PATCH 32/38] lxd/db: Rename InstancePool to GetInstancePool
Signed-off-by: Free Ekanayaka <free.ekanayaka at canonical.com>
---
lxd/db/containers.go | 14 +++++++-------
lxd/db/containers_test.go | 4 ++--
lxd/instance/drivers/driver_lxc.go | 2 +-
lxd/instance/drivers/driver_qemu.go | 2 +-
lxd/instance_post.go | 2 +-
lxd/storage/load.go | 2 +-
6 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/lxd/db/containers.go b/lxd/db/containers.go
index c9cb878199..64f324414a 100644
--- a/lxd/db/containers.go
+++ b/lxd/db/containers.go
@@ -446,7 +446,7 @@ SELECT instances.name, nodes.name
func (c *ClusterTx) UpdateInstanceNode(project, oldName, newName, newNode string) error {
// First check that the container to be moved is backed by a ceph
// volume.
- poolName, err := c.InstancePool(project, oldName)
+ poolName, err := c.GetInstancePool(project, oldName)
if err != nil {
return errors.Wrap(err, "Failed to get instance's storage pool name")
}
@@ -991,21 +991,21 @@ WHERE projects.name=? AND instances.name=?`
return max
}
-// InstancePool returns the storage pool of a given instance.
+// GetInstancePool returns the storage pool of a given instance.
//
-// This is a non-transactional variant of ClusterTx.InstancePool().
-func (c *Cluster) InstancePool(project, instanceName string) (string, error) {
+// This is a non-transactional variant of ClusterTx.GetInstancePool().
+func (c *Cluster) GetInstancePool(project, instanceName string) (string, error) {
var poolName string
err := c.Transaction(func(tx *ClusterTx) error {
var err error
- poolName, err = tx.InstancePool(project, instanceName)
+ poolName, err = tx.GetInstancePool(project, instanceName)
return err
})
return poolName, err
}
-// InstancePool returns the storage pool of a given instance.
-func (c *ClusterTx) InstancePool(project, instanceName string) (string, error) {
+// GetInstancePool returns the storage pool of a given instance.
+func (c *ClusterTx) GetInstancePool(project, instanceName string) (string, error) {
if strings.Contains(instanceName, shared.SnapshotDelimiter) {
return c.instancePoolSnapshot(project, instanceName)
}
diff --git a/lxd/db/containers_test.go b/lxd/db/containers_test.go
index 52f4d44fee..2a92c8ce94 100644
--- a/lxd/db/containers_test.go
+++ b/lxd/db/containers_test.go
@@ -349,7 +349,7 @@ func TestGetInstanceToNodeMap(t *testing.T) {
}, result)
}
-func TestInstancePool(t *testing.T) {
+func TestGetInstancePool(t *testing.T) {
cluster, cleanup := db.NewTestCluster(t)
defer cleanup()
@@ -376,7 +376,7 @@ func TestInstancePool(t *testing.T) {
})
require.NoError(t, err)
- poolName, err := cluster.InstancePool("default", "c1")
+ poolName, err := cluster.GetInstancePool("default", "c1")
require.NoError(t, err)
assert.Equal(t, "default", poolName)
}
diff --git a/lxd/instance/drivers/driver_lxc.go b/lxd/instance/drivers/driver_lxc.go
index 630e025473..9293e33259 100644
--- a/lxd/instance/drivers/driver_lxc.go
+++ b/lxd/instance/drivers/driver_lxc.go
@@ -6650,7 +6650,7 @@ func (c *lxc) StatePath() string {
// StoragePool storage pool name.
func (c *lxc) StoragePool() (string, error) {
- poolName, err := c.state.Cluster.InstancePool(c.Project(), c.Name())
+ poolName, err := c.state.Cluster.GetInstancePool(c.Project(), c.Name())
if err != nil {
return "", err
}
diff --git a/lxd/instance/drivers/driver_qemu.go b/lxd/instance/drivers/driver_qemu.go
index 848696ca3c..7f26e80883 100644
--- a/lxd/instance/drivers/driver_qemu.go
+++ b/lxd/instance/drivers/driver_qemu.go
@@ -4015,7 +4015,7 @@ func (vm *qemu) StatePath() string {
// StoragePool returns the name of the instance's storage pool.
func (vm *qemu) StoragePool() (string, error) {
- poolName, err := vm.state.Cluster.InstancePool(vm.Project(), vm.Name())
+ poolName, err := vm.state.Cluster.GetInstancePool(vm.Project(), vm.Name())
if err != nil {
return "", err
}
diff --git a/lxd/instance_post.go b/lxd/instance_post.go
index 3aab1d50f1..a787da7e09 100644
--- a/lxd/instance_post.go
+++ b/lxd/instance_post.go
@@ -179,7 +179,7 @@ func containerPost(d *Daemon, r *http.Request) response.Response {
}
// Check if we are migrating a ceph-based container.
- poolName, err := d.cluster.InstancePool(project, name)
+ poolName, err := d.cluster.GetInstancePool(project, name)
if err != nil {
err = errors.Wrap(err, "Failed to fetch instance's pool name")
return response.SmartError(err)
diff --git a/lxd/storage/load.go b/lxd/storage/load.go
index c8d5ed83dd..eb421dcb79 100644
--- a/lxd/storage/load.go
+++ b/lxd/storage/load.go
@@ -174,7 +174,7 @@ func GetPoolByName(state *state.State, name string) (Pool, error) {
// 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.Instance) (Pool, error) {
- poolName, err := s.Cluster.InstancePool(inst.Project(), inst.Name())
+ poolName, err := s.Cluster.GetInstancePool(inst.Project(), inst.Name())
if err != nil {
return nil, err
}
From 551884423cf0559524a36a7202866afe422c9166 Mon Sep 17 00:00:00 2001
From: Free Ekanayaka <free.ekanayaka at canonical.com>
Date: Thu, 30 Apr 2020 15:58:06 +0100
Subject: [PATCH 33/38] lxd/db: Rename ContainerBackupID to getInstanceBackupID
Signed-off-by: Free Ekanayaka <free.ekanayaka at canonical.com>
---
lxd/db/containers.go | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/lxd/db/containers.go b/lxd/db/containers.go
index 64f324414a..4311893f11 100644
--- a/lxd/db/containers.go
+++ b/lxd/db/containers.go
@@ -1065,8 +1065,8 @@ SELECT storage_pools.name FROM storage_pools
return poolName, nil
}
-// ContainerBackupID returns the ID of the container backup with the given name.
-func (c *Cluster) ContainerBackupID(name string) (int, error) {
+// Returns the ID of the instance backup with the given name.
+func (c *Cluster) getInstanceBackupID(name string) (int, error) {
q := "SELECT id FROM instances_backups WHERE name=?"
id := -1
arg1 := []interface{}{name}
@@ -1143,7 +1143,7 @@ WHERE projects.name=? AND instances.name=?`
// InstanceBackupCreate creates a new backup.
func (c *Cluster) InstanceBackupCreate(args InstanceBackupArgs) error {
- _, err := c.ContainerBackupID(args.Name)
+ _, err := c.getInstanceBackupID(args.Name)
if err == nil {
return ErrAlreadyDefined
}
@@ -1185,7 +1185,7 @@ func (c *Cluster) InstanceBackupCreate(args InstanceBackupArgs) error {
// InstanceBackupRemove removes the container backup with the given name from the database.
func (c *Cluster) InstanceBackupRemove(name string) error {
- id, err := c.ContainerBackupID(name)
+ id, err := c.getInstanceBackupID(name)
if err != nil {
return err
}
From 4bf21f470c0bd6529ac5c2c20bb7075025d21d91 Mon Sep 17 00:00:00 2001
From: Free Ekanayaka <free.ekanayaka at canonical.com>
Date: Thu, 30 Apr 2020 15:59:40 +0100
Subject: [PATCH 34/38] Rename ContainerGetBackup to GetInstanceBackup
Signed-off-by: Free Ekanayaka <free.ekanayaka at canonical.com>
---
lxd/db/containers.go | 10 +++++-----
lxd/instance/drivers/driver_lxc.go | 2 +-
lxd/instance/instance_utils.go | 2 +-
3 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/lxd/db/containers.go b/lxd/db/containers.go
index 4311893f11..6a088ece37 100644
--- a/lxd/db/containers.go
+++ b/lxd/db/containers.go
@@ -1079,8 +1079,8 @@ func (c *Cluster) getInstanceBackupID(name string) (int, error) {
return id, err
}
-// ContainerGetBackup returns the backup with the given name.
-func (c *Cluster) ContainerGetBackup(project, name string) (InstanceBackupArgs, error) {
+// GetInstanceBackup returns the backup with the given name.
+func (c *Cluster) GetInstanceBackup(project, name string) (InstanceBackupArgs, error) {
args := InstanceBackupArgs{}
args.Name = name
@@ -1118,9 +1118,9 @@ SELECT instances_backups.id, instances_backups.instance_id,
return args, nil
}
-// ContainerGetBackups returns the names of all backups of the container
-// with the given name.
-func (c *Cluster) ContainerGetBackups(project, name string) ([]string, error) {
+// GetInstanceBackups returns the names of all backups of the instance with the
+// given name.
+func (c *Cluster) GetInstanceBackups(project, name string) ([]string, error) {
var result []string
q := `SELECT instances_backups.name FROM instances_backups
diff --git a/lxd/instance/drivers/driver_lxc.go b/lxd/instance/drivers/driver_lxc.go
index 9293e33259..83b978fd19 100644
--- a/lxd/instance/drivers/driver_lxc.go
+++ b/lxd/instance/drivers/driver_lxc.go
@@ -3215,7 +3215,7 @@ func (c *lxc) Snapshots() ([]instance.Instance, error) {
// Backups returns the backups of the instance.
func (c *lxc) Backups() ([]backup.Backup, error) {
// Get all the backups
- backupNames, err := c.state.Cluster.ContainerGetBackups(c.project, c.name)
+ backupNames, err := c.state.Cluster.GetInstanceBackups(c.project, c.name)
if err != nil {
return nil, err
}
diff --git a/lxd/instance/instance_utils.go b/lxd/instance/instance_utils.go
index d94aca94a9..bd6b8af1a4 100644
--- a/lxd/instance/instance_utils.go
+++ b/lxd/instance/instance_utils.go
@@ -628,7 +628,7 @@ func DeviceNextInterfaceHWAddr() (string, error) {
// BackupLoadByName load an instance backup from the database.
func BackupLoadByName(s *state.State, project, name string) (*backup.Backup, error) {
// Get the backup database record
- args, err := s.Cluster.ContainerGetBackup(project, name)
+ args, err := s.Cluster.GetInstanceBackup(project, name)
if err != nil {
return nil, errors.Wrap(err, "Load backup from database")
}
From 5656c78b724cf437ee10bc6c4ecb6c37778f5a6a Mon Sep 17 00:00:00 2001
From: Free Ekanayaka <free.ekanayaka at canonical.com>
Date: Thu, 30 Apr 2020 16:00:52 +0100
Subject: [PATCH 35/38] lxd/db: Rename InstanceCreateBackup to
CreateInstanceBackup
Signed-off-by: Free Ekanayaka <free.ekanayaka at canonical.com>
---
lxd/backup.go | 2 +-
lxd/db/containers.go | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/lxd/backup.go b/lxd/backup.go
index 1db85bcb57..247818fc00 100644
--- a/lxd/backup.go
+++ b/lxd/backup.go
@@ -53,7 +53,7 @@ func backupCreate(s *state.State, args db.InstanceBackupArgs, sourceInst instanc
}
// Create the database entry.
- err = s.Cluster.InstanceBackupCreate(args)
+ err = s.Cluster.CreateInstanceBackup(args)
if err != nil {
if err == db.ErrAlreadyDefined {
return fmt.Errorf("Backup %q already exists", args.Name)
diff --git a/lxd/db/containers.go b/lxd/db/containers.go
index 6a088ece37..9dbe9cf68e 100644
--- a/lxd/db/containers.go
+++ b/lxd/db/containers.go
@@ -1141,8 +1141,8 @@ WHERE projects.name=? AND instances.name=?`
return result, nil
}
-// InstanceBackupCreate creates a new backup.
-func (c *Cluster) InstanceBackupCreate(args InstanceBackupArgs) error {
+// CreateInstanceBackup creates a new backup.
+func (c *Cluster) CreateInstanceBackup(args InstanceBackupArgs) error {
_, err := c.getInstanceBackupID(args.Name)
if err == nil {
return ErrAlreadyDefined
From cdf3cefa7baba78205e48a78f4d43c15c4909efb Mon Sep 17 00:00:00 2001
From: Free Ekanayaka <free.ekanayaka at canonical.com>
Date: Thu, 30 Apr 2020 16:01:47 +0100
Subject: [PATCH 36/38] lxd/db: Rename InstanceBackupRemove to
DeleteInstanceBackup
Signed-off-by: Free Ekanayaka <free.ekanayaka at canonical.com>
---
lxd/backup.go | 2 +-
lxd/backup/backup.go | 2 +-
lxd/db/containers.go | 4 ++--
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/lxd/backup.go b/lxd/backup.go
index 247818fc00..d08b023519 100644
--- a/lxd/backup.go
+++ b/lxd/backup.go
@@ -62,7 +62,7 @@ func backupCreate(s *state.State, args db.InstanceBackupArgs, sourceInst instanc
return errors.Wrap(err, "Insert backup info into database")
}
- revert.Add(func() { s.Cluster.InstanceBackupRemove(args.Name) })
+ revert.Add(func() { s.Cluster.DeleteInstanceBackup(args.Name) })
// Get the backup struct.
b, err := instance.BackupLoadByName(s, sourceInst.Project(), args.Name)
diff --git a/lxd/backup/backup.go b/lxd/backup/backup.go
index 47be52f619..8783c02603 100644
--- a/lxd/backup/backup.go
+++ b/lxd/backup/backup.go
@@ -247,7 +247,7 @@ func DoBackupDelete(s *state.State, projectName, backupName, containerName strin
}
// Remove the database record
- err := s.Cluster.InstanceBackupRemove(backupName)
+ err := s.Cluster.DeleteInstanceBackup(backupName)
if err != nil {
return err
}
diff --git a/lxd/db/containers.go b/lxd/db/containers.go
index 9dbe9cf68e..4621ed6a63 100644
--- a/lxd/db/containers.go
+++ b/lxd/db/containers.go
@@ -1183,8 +1183,8 @@ func (c *Cluster) CreateInstanceBackup(args InstanceBackupArgs) error {
return err
}
-// InstanceBackupRemove removes the container backup with the given name from the database.
-func (c *Cluster) InstanceBackupRemove(name string) error {
+// DeleteInstanceBackup removes the instance backup with the given name from the database.
+func (c *Cluster) DeleteInstanceBackup(name string) error {
id, err := c.getInstanceBackupID(name)
if err != nil {
return err
From db57fec2ee9099126c112a3b20255501de3ac4e4 Mon Sep 17 00:00:00 2001
From: Free Ekanayaka <free.ekanayaka at canonical.com>
Date: Thu, 30 Apr 2020 16:03:00 +0100
Subject: [PATCH 37/38] lxd/db: ContainerBackupRename to RenameInstanceBackup
Signed-off-by: Free Ekanayaka <free.ekanayaka at canonical.com>
---
lxd/backup/backup.go | 2 +-
lxd/db/containers.go | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/lxd/backup/backup.go b/lxd/backup/backup.go
index 8783c02603..3648f2d375 100644
--- a/lxd/backup/backup.go
+++ b/lxd/backup/backup.go
@@ -199,7 +199,7 @@ func (b *Backup) Rename(newName string) error {
}
// Rename the database record
- err = b.state.Cluster.ContainerBackupRename(b.name, newName)
+ err = b.state.Cluster.RenameInstanceBackup(b.name, newName)
if err != nil {
return err
}
diff --git a/lxd/db/containers.go b/lxd/db/containers.go
index 4621ed6a63..13e6b52099 100644
--- a/lxd/db/containers.go
+++ b/lxd/db/containers.go
@@ -1198,9 +1198,9 @@ func (c *Cluster) DeleteInstanceBackup(name string) error {
return nil
}
-// ContainerBackupRename renames a container backup from the given current name
+// RenameInstanceBackup renames an instance backup from the given current name
// to the new one.
-func (c *Cluster) ContainerBackupRename(oldName, newName string) error {
+func (c *Cluster) RenameInstanceBackup(oldName, newName string) error {
err := c.Transaction(func(tx *ClusterTx) error {
str := fmt.Sprintf("UPDATE instances_backups SET name = ? WHERE name = ?")
stmt, err := tx.tx.Prepare(str)
From 3e81cf4be8f76d4e8d307ff895128564cf9e5956 Mon Sep 17 00:00:00 2001
From: Free Ekanayaka <free.ekanayaka at canonical.com>
Date: Thu, 30 Apr 2020 16:04:40 +0100
Subject: [PATCH 38/38] lxd/db: Rename ContainerBackupsGetExpired to
GetExpiredInstanceBackups
Signed-off-by: Free Ekanayaka <free.ekanayaka at canonical.com>
---
lxd/backup.go | 2 +-
lxd/db/containers.go | 4 ++--
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/lxd/backup.go b/lxd/backup.go
index d08b023519..a1bef75103 100644
--- a/lxd/backup.go
+++ b/lxd/backup.go
@@ -250,7 +250,7 @@ func pruneExpiredContainerBackupsTask(d *Daemon) (task.Func, task.Schedule) {
func pruneExpiredContainerBackups(ctx context.Context, d *Daemon) error {
// Get the list of expired backups.
- backups, err := d.cluster.ContainerBackupsGetExpired()
+ backups, err := d.cluster.GetExpiredInstanceBackups()
if err != nil {
return errors.Wrap(err, "Unable to retrieve the list of expired instance backups")
}
diff --git a/lxd/db/containers.go b/lxd/db/containers.go
index 13e6b52099..084a9298d8 100644
--- a/lxd/db/containers.go
+++ b/lxd/db/containers.go
@@ -1224,8 +1224,8 @@ func (c *Cluster) RenameInstanceBackup(oldName, newName string) error {
return err
}
-// ContainerBackupsGetExpired returns a list of expired container backups.
-func (c *Cluster) ContainerBackupsGetExpired() ([]InstanceBackupArgs, error) {
+// GetExpiredInstanceBackups returns a list of expired instance backups.
+func (c *Cluster) GetExpiredInstanceBackups() ([]InstanceBackupArgs, error) {
var result []InstanceBackupArgs
var name string
var expiryDate string
More information about the lxc-devel
mailing list