[lxc-devel] [lxd/master] Storage: Add default content type to /1.0/storage-pools/{name}/volumes route

tomponline on Github lxc-bot at linuxcontainers.org
Tue Dec 1 14:24:08 UTC 2020


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 345 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20201201/cfbf61b9/attachment.bin>
-------------- next part --------------
From d97041090a02bfd27e21c6fd950cef4eaeaaf45e Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Tue, 1 Dec 2020 14:14:01 +0000
Subject: [PATCH 1/8] lxd/storage/volumes: Replace hardcoded "filesystem" with
 db.StoragePoolVolumeContentTypeNameFS in storagePoolVolumesTypePost

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 lxd/storage_volumes.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lxd/storage_volumes.go b/lxd/storage_volumes.go
index 2c95560f3e..dd865ccf2a 100644
--- a/lxd/storage_volumes.go
+++ b/lxd/storage_volumes.go
@@ -290,7 +290,7 @@ func storagePoolVolumesTypePost(d *Daemon, r *http.Request) response.Response {
 
 	// Backward compatibility.
 	if req.ContentType == "" {
-		req.ContentType = "filesystem"
+		req.ContentType = db.StoragePoolVolumeContentTypeNameFS
 	}
 
 	_, err = storagePools.VolumeContentTypeNameToContentType(req.ContentType)

From c353cb7bf4eba967b9058a9692d485076560eb8f Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Tue, 1 Dec 2020 14:14:24 +0000
Subject: [PATCH 2/8] lxd/storage/volumes: Error quoting in
 storagePoolVolumesTypePost

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 lxd/storage_volumes.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lxd/storage_volumes.go b/lxd/storage_volumes.go
index dd865ccf2a..ec83cfd155 100644
--- a/lxd/storage_volumes.go
+++ b/lxd/storage_volumes.go
@@ -303,7 +303,7 @@ func storagePoolVolumesTypePost(d *Daemon, r *http.Request) response.Response {
 	// We currently only allow to create storage volumes of type storagePoolVolumeTypeCustom.
 	// So check, that nothing else was requested.
 	if req.Type != db.StoragePoolVolumeTypeNameCustom {
-		return response.BadRequest(fmt.Errorf(`Currently not allowed to create storage volumes of type %q`, req.Type))
+		return response.BadRequest(fmt.Errorf("Currently not allowed to create storage volumes of type %q", req.Type))
 	}
 
 	poolID, err := d.cluster.GetStoragePoolID(poolName)

From e9532a3f3da83473c691a23da833cf9ea8e753a9 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Tue, 1 Dec 2020 14:14:35 +0000
Subject: [PATCH 3/8] lxd/storage/volumes: Fixes misleading comment in
 storagePoolVolumesPost

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 lxd/storage_volumes.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lxd/storage_volumes.go b/lxd/storage_volumes.go
index ec83cfd155..9143c1ed34 100644
--- a/lxd/storage_volumes.go
+++ b/lxd/storage_volumes.go
@@ -385,7 +385,7 @@ func doVolumeCreateOrCopy(d *Daemon, projectName, poolName string, req *api.Stor
 	return operations.OperationResponse(op)
 }
 
-// /1.0/storage-pools/{name}/volumes/{type}
+// /1.0/storage-pools/{name}/volumes
 // Create a storage volume of a given volume type in a given storage pool.
 func storagePoolVolumesPost(d *Daemon, r *http.Request) response.Response {
 	resp := forwardedResponseIfTargetIsRemote(d, r)

From f0047ce2de38b73355dd53a4272f7beb31361755 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Tue, 1 Dec 2020 14:15:12 +0000
Subject: [PATCH 4/8] lxd/storage/volumes: Set default volume content type to
 filesystem in storagePoolVolumesPost

Fixes #8203

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 lxd/storage_volumes.go | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/lxd/storage_volumes.go b/lxd/storage_volumes.go
index 9143c1ed34..9350a3270c 100644
--- a/lxd/storage_volumes.go
+++ b/lxd/storage_volumes.go
@@ -422,6 +422,11 @@ func storagePoolVolumesPost(d *Daemon, r *http.Request) response.Response {
 		return response.BadRequest(fmt.Errorf(`Currently not allowed to create storage volumes of type %q`, req.Type))
 	}
 
+	// Backward compatibility.
+	if req.ContentType == "" {
+		req.ContentType = db.StoragePoolVolumeContentTypeNameFS
+	}
+
 	projectName, err := project.StorageVolumeProject(d.State().Cluster, projectParam(r), db.StoragePoolVolumeTypeCustom)
 	if err != nil {
 		return response.SmartError(err)

From fe4bfde7491f24c5d4f582df07240e58c971c085 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Tue, 1 Dec 2020 14:16:00 +0000
Subject: [PATCH 5/8] lxd/storage/volumes: Error quoting in
 storagePoolVolumesPost

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 lxd/storage_volumes.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lxd/storage_volumes.go b/lxd/storage_volumes.go
index 9350a3270c..831f9cebde 100644
--- a/lxd/storage_volumes.go
+++ b/lxd/storage_volumes.go
@@ -419,7 +419,7 @@ func storagePoolVolumesPost(d *Daemon, r *http.Request) response.Response {
 	// We currently only allow to create storage volumes of type storagePoolVolumeTypeCustom.
 	// So check, that nothing else was requested.
 	if req.Type != db.StoragePoolVolumeTypeNameCustom {
-		return response.BadRequest(fmt.Errorf(`Currently not allowed to create storage volumes of type %q`, req.Type))
+		return response.BadRequest(fmt.Errorf("Currently not allowed to create storage volumes of type %q", req.Type))
 	}
 
 	// Backward compatibility.

From dce20f9484afb0f5fdd27464fd9869b14654d345 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Tue, 1 Dec 2020 14:18:02 +0000
Subject: [PATCH 6/8] lxd/storage/utils: Align error returned from
 VolumeContentTypeNameToContentType with similar functions

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 lxd/storage/utils.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lxd/storage/utils.go b/lxd/storage/utils.go
index c070c3375f..cf79c49af1 100644
--- a/lxd/storage/utils.go
+++ b/lxd/storage/utils.go
@@ -188,7 +188,7 @@ func VolumeContentTypeNameToContentType(contentTypeName string) (int, error) {
 		return db.StoragePoolVolumeContentTypeBlock, nil
 	}
 
-	return -1, fmt.Errorf("Invalid storage volume content type name: %s", contentTypeName)
+	return -1, fmt.Errorf("Invalid volume content type name")
 }
 
 // VolumeDBCreate creates a volume in the database.

From bb31b61e3e2c4926fb8183fa860517f1d01501d2 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Tue, 1 Dec 2020 14:20:03 +0000
Subject: [PATCH 7/8] lxd/storage/volumes: Removes stuttering in errors in
 storagePoolVolumesTypePost

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 lxd/storage_volumes.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lxd/storage_volumes.go b/lxd/storage_volumes.go
index 831f9cebde..2b8230d334 100644
--- a/lxd/storage_volumes.go
+++ b/lxd/storage_volumes.go
@@ -295,7 +295,7 @@ func storagePoolVolumesTypePost(d *Daemon, r *http.Request) response.Response {
 
 	_, err = storagePools.VolumeContentTypeNameToContentType(req.ContentType)
 	if err != nil {
-		return response.BadRequest(fmt.Errorf("Invalid content type %q", req.ContentType))
+		return response.BadRequest(err)
 	}
 
 	req.Type = mux.Vars(r)["type"]

From 1a3676f5e7feb197376c60b5646d70e2bb26ffce Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Tue, 1 Dec 2020 14:21:54 +0000
Subject: [PATCH 8/8] lxd/networks: Use SmartError for response when loading
 networks

Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
 lxd/networks.go | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/lxd/networks.go b/lxd/networks.go
index ea12c70c4e..329b5900ce 100644
--- a/lxd/networks.go
+++ b/lxd/networks.go
@@ -605,7 +605,7 @@ func networkDelete(d *Daemon, r *http.Request) response.Response {
 	// Get the existing network.
 	n, err := network.LoadByName(state, projectName, name)
 	if err != nil {
-		return response.NotFound(err)
+		return response.SmartError(err)
 	}
 
 	clientType := cluster.UserAgentClientType(r.Header.Get("User-Agent"))
@@ -666,11 +666,7 @@ func networkPost(d *Daemon, r *http.Request) response.Response {
 	// Get the existing network.
 	n, err := network.LoadByName(state, projectName, name)
 	if err != nil {
-		if err == db.ErrNoSuchObject {
-			return response.NotFound(fmt.Errorf("Network not found"))
-		}
-
-		return response.InternalError(errors.Wrapf(err, "Failed loading network"))
+		return response.SmartError(err)
 	}
 
 	if n.Status() != api.NetworkStatusCreated {
@@ -733,7 +729,7 @@ func networkPut(d *Daemon, r *http.Request) response.Response {
 	// Get the existing network.
 	n, err := network.LoadByName(d.State(), projectName, name)
 	if err != nil {
-		return response.NotFound(err)
+		return response.SmartError(err)
 	}
 
 	targetNode := queryParam(r, "target")


More information about the lxc-devel mailing list