Skip to content

Commit

Permalink
lxd/storage/drivers: Remove unnecessary fmt.Sprintfs
Browse files Browse the repository at this point in the history
Signed-off-by: Max Asnaashari <[email protected]>
  • Loading branch information
masnax committed Oct 23, 2024
1 parent e6f6866 commit a552128
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 20 deletions.
12 changes: 6 additions & 6 deletions lxd/storage/drivers/driver_ceph.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (d *ceph) FillConfig() error {

if d.config["ceph.osd.pool_size"] == "" {
size, err := shared.TryRunCommand("ceph",
"--name", fmt.Sprintf("client.%s", d.config["ceph.user.name"]),
"--name", "client.%s"+d.config["ceph.user.name"],
"--cluster", d.config["ceph.cluster_name"],
"config",
"get",
Expand Down Expand Up @@ -183,7 +183,7 @@ func (d *ceph) Create() error {
if !poolExists {
// Create new osd pool.
_, err := shared.TryRunCommand("ceph",
"--name", fmt.Sprintf("client.%s", d.config["ceph.user.name"]),
"--name", "client.%s"+d.config["ceph.user.name"],
"--cluster", d.config["ceph.cluster_name"],
"osd",
"pool",
Expand All @@ -197,7 +197,7 @@ func (d *ceph) Create() error {
revert.Add(func() { _ = d.osdDeletePool() })

_, err = shared.TryRunCommand("ceph",
"--name", fmt.Sprintf("client.%s", d.config["ceph.user.name"]),
"--name", "client.%s"+d.config["ceph.user.name"],
"--cluster", d.config["ceph.cluster_name"],
"osd",
"pool",
Expand Down Expand Up @@ -256,7 +256,7 @@ func (d *ceph) Create() error {

// Use existing OSD pool.
msg, err := shared.RunCommand("ceph",
"--name", fmt.Sprintf("client.%s", d.config["ceph.user.name"]),
"--name", "client.%s"+d.config["ceph.user.name"],
"--cluster", d.config["ceph.cluster_name"],
"osd",
"pool",
Expand Down Expand Up @@ -407,7 +407,7 @@ func (d *ceph) Update(changedConfig map[string]string) error {
newSize := changedConfig["ceph.osd.pool_size"]
if newSize != d.config["ceph.osd.pool_size"] && newSize != "" {
_, err := shared.TryRunCommand("ceph",
"--name", fmt.Sprintf("client.%s", d.config["ceph.user.name"]),
"--name", "client.%s"+d.config["ceph.user.name"],
"--cluster", d.config["ceph.cluster_name"],
"osd",
"pool",
Expand Down Expand Up @@ -451,7 +451,7 @@ func (d *ceph) GetResources() (*api.ResourcesStoragePool, error) {

err := shared.RunCommandWithFds(context.TODO(), nil, &stdout,
"ceph",
"--name", fmt.Sprintf("client.%s", d.config["ceph.user.name"]),
"--name", "client.%s"+d.config["ceph.user.name"],
"--cluster", d.config["ceph.cluster_name"],
"df",
"-f", "json")
Expand Down
4 changes: 2 additions & 2 deletions lxd/storage/drivers/driver_ceph_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ var cephVolTypePrefixes = map[VolumeType]string{
func (d *ceph) osdPoolExists() (bool, error) {
_, err := shared.RunCommand(
"ceph",
"--name", fmt.Sprintf("client.%s", d.config["ceph.user.name"]),
"--name", "client.%s"+d.config["ceph.user.name"],
"--cluster", d.config["ceph.cluster_name"],
"osd",
"pool",
Expand Down Expand Up @@ -83,7 +83,7 @@ func (d *ceph) osdPoolExists() (bool, error) {
func (d *ceph) osdDeletePool() error {
_, err := shared.RunCommand(
"ceph",
"--name", fmt.Sprintf("client.%s", d.config["ceph.user.name"]),
"--name", "client.%s"+d.config["ceph.user.name"],
"--cluster", d.config["ceph.cluster_name"],
"osd",
"pool",
Expand Down
16 changes: 8 additions & 8 deletions lxd/storage/drivers/driver_cephfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (d *cephfs) FillConfig() error {

if d.config["cephfs.osd_pool_size"] == "" {
size, err := shared.TryRunCommand("ceph",
"--name", fmt.Sprintf("client.%s", d.config["cephfs.user.name"]),
"--name", "client."+d.config["cephfs.user.name"],
"--cluster", d.config["cephfs.cluster_name"],
"config",
"get",
Expand Down Expand Up @@ -201,7 +201,7 @@ func (d *cephfs) Create() error {
if !osdPoolExists {
// Create new osd pool.
_, err := shared.RunCommand("ceph",
"--name", fmt.Sprintf("client.%s", d.config["cephfs.user.name"]),
"--name", "client."+d.config["cephfs.user.name"],
"--cluster", d.config["cephfs.cluster_name"],
"osd",
"pool",
Expand All @@ -216,7 +216,7 @@ func (d *cephfs) Create() error {
revert.Add(func() {
// Delete the OSD pool.
_, _ = shared.RunCommand("ceph",
"--name", fmt.Sprintf("client.%s", d.config["cephfs.user.name"]),
"--name", "client."+d.config["cephfs.user.name"],
"--cluster", d.config["cephfs.cluster_name"],
"osd",
"pool",
Expand All @@ -228,7 +228,7 @@ func (d *cephfs) Create() error {
})

_, err = shared.TryRunCommand("ceph",
"--name", fmt.Sprintf("client.%s", d.config["cephfs.user.name"]),
"--name", "client."+d.config["cephfs.user.name"],
"--cluster", d.config["cephfs.cluster_name"],
"osd",
"pool",
Expand All @@ -245,7 +245,7 @@ func (d *cephfs) Create() error {

// Create the filesystem.
_, err := shared.RunCommand("ceph",
"--name", fmt.Sprintf("client.%s", d.config["cephfs.user.name"]),
"--name", "client."+d.config["cephfs.user.name"],
"--cluster", d.config["cephfs.cluster_name"],
"fs",
"new",
Expand All @@ -260,7 +260,7 @@ func (d *cephfs) Create() error {
revert.Add(func() {
// Set the FS to fail so that we can remove it.
_, _ = shared.RunCommand("ceph",
"--name", fmt.Sprintf("client.%s", d.config["cephfs.user.name"]),
"--name", "client."+d.config["cephfs.user.name"],
"--cluster", d.config["cephfs.cluster_name"],
"fs",
"fail",
Expand All @@ -269,7 +269,7 @@ func (d *cephfs) Create() error {

// Delete the FS.
_, _ = shared.RunCommand("ceph",
"--name", fmt.Sprintf("client.%s", d.config["cephfs.user.name"]),
"--name", "client."+d.config["cephfs.user.name"],
"--cluster", d.config["cephfs.cluster_name"],
"fs",
"rm",
Expand Down Expand Up @@ -491,7 +491,7 @@ func (d *cephfs) Update(changedConfig map[string]string) error {
}

_, err := shared.TryRunCommand("ceph",
"--name", fmt.Sprintf("client.%s", d.config["cephfs.user.name"]),
"--name", "client."+d.config["cephfs.user.name"],
"--cluster", d.config["cephfs.cluster_name"],
"osd",
"pool",
Expand Down
6 changes: 2 additions & 4 deletions lxd/storage/drivers/driver_cephfs_utils.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package drivers

import (
"fmt"

"github.com/canonical/lxd/shared"
)

// fsExists checks that the Ceph FS instance indeed exists.
func (d *cephfs) fsExists(clusterName string, userName string, fsName string) (bool, error) {
_, err := shared.RunCommand("ceph", "--name", fmt.Sprintf("client.%s", userName), "--cluster", clusterName, "fs", "get", fsName)
_, err := shared.RunCommand("ceph", "--name", "client.%s"+userName, "--cluster", clusterName, "fs", "get", fsName)
if err != nil {
status, _ := shared.ExitStatus(err)
// If the error status code is 2, the fs definitely doesn't exist.
Expand All @@ -27,7 +25,7 @@ func (d *cephfs) fsExists(clusterName string, userName string, fsName string) (b

// osdPoolExists checks that the Ceph OSD Pool indeed exists.
func (d *cephfs) osdPoolExists(clusterName string, userName string, osdPoolName string) (bool, error) {
_, err := shared.RunCommand("ceph", "--name", fmt.Sprintf("client.%s", userName), "--cluster", clusterName, "osd", "pool", "get", osdPoolName, "size")
_, err := shared.RunCommand("ceph", "--name", "client.%s"+userName, "--cluster", clusterName, "osd", "pool", "get", osdPoolName, "size")
if err != nil {
status, _ := shared.ExitStatus(err)
// If the error status code is 2, the pool definitely doesn't exist.
Expand Down

0 comments on commit a552128

Please sign in to comment.