diff --git a/lxc/action.go b/lxc/action.go index 61f8b0d3b6c6..b96b2d9919db 100644 --- a/lxc/action.go +++ b/lxc/action.go @@ -1,6 +1,7 @@ package main import ( + "errors" "fmt" "os" "strings" @@ -160,7 +161,7 @@ func (c *cmdAction) Command(action string) *cobra.Command { func (c *cmdAction) doActionAll(action string, resource remoteResource) error { if resource.name != "" { // both --all and instance name given. - return fmt.Errorf(i18n.G("Both --all and instance name given")) + return errors.New(i18n.G("Both --all and instance name given")) } remote := resource.remote @@ -232,7 +233,7 @@ func (c *cmdAction) doAction(action string, conf *config.Config, nameArg string) } if action == "stop" && c.flagForce && c.flagConsole != "" { - return fmt.Errorf(i18n.G("--console can't be used while forcing instance shutdown")) + return errors.New(i18n.G("--console can't be used while forcing instance shutdown")) } remote, name, err := conf.ParseRemote(nameArg) @@ -337,7 +338,7 @@ func (c *cmdAction) run(cmd *cobra.Command, args []string) error { for _, resource := range resources { // We don't allow instance names with --all. if resource.name != "" { - return fmt.Errorf(i18n.G("Both --all and instance name given")) + return errors.New(i18n.G("Both --all and instance name given")) } // See if we can use the bulk API. @@ -381,11 +382,11 @@ func (c *cmdAction) run(cmd *cobra.Command, args []string) error { if c.flagConsole != "" { if c.flagAll { - return fmt.Errorf(i18n.G("--console can't be used with --all")) + return errors.New(i18n.G("--console can't be used with --all")) } if len(names) != 1 { - return fmt.Errorf(i18n.G("--console only works with a single instance")) + return errors.New(i18n.G("--console only works with a single instance")) } } diff --git a/lxc/cluster.go b/lxc/cluster.go index c29c713f8b49..82fb0e280ab7 100644 --- a/lxc/cluster.go +++ b/lxc/cluster.go @@ -2,6 +2,7 @@ package main import ( "bufio" + "errors" "fmt" "io" "os" @@ -163,7 +164,7 @@ func (c *cmdClusterList) run(cmd *cobra.Command, args []string) error { } if !cluster.Enabled { - return fmt.Errorf(i18n.G("LXD server isn't part of a cluster")) + return errors.New(i18n.G("LXD server isn't part of a cluster")) } // Get the cluster members @@ -621,7 +622,7 @@ Are you really sure you want to force removing %s? (yes/no): `), name) input = strings.TrimSuffix(input, "\n") if !shared.ValueInSlice(strings.ToLower(input), []string{i18n.G("yes")}) { - return fmt.Errorf(i18n.G("User aborted delete operation")) + return errors.New(i18n.G("User aborted delete operation")) } return nil @@ -725,7 +726,7 @@ func (c *cmdClusterEnable) run(cmd *cobra.Command, args []string) error { } if server.Config["core.https_address"] == "" && server.Config["cluster.https_address"] == "" { - return fmt.Errorf(i18n.G("This LXD server is not available on the network")) + return errors.New(i18n.G("This LXD server is not available on the network")) } // Check if already enabled @@ -735,7 +736,7 @@ func (c *cmdClusterEnable) run(cmd *cobra.Command, args []string) error { } if currentCluster.Enabled { - return fmt.Errorf(i18n.G("This LXD server is already clustered")) + return errors.New(i18n.G("This LXD server is already clustered")) } // Enable clustering. @@ -807,7 +808,7 @@ func (c *cmdClusterEdit) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing cluster member name")) + return errors.New(i18n.G("Missing cluster member name")) } // If stdin isn't a terminal, read text from it @@ -922,7 +923,7 @@ func (c *cmdClusterAdd) run(cmd *cobra.Command, args []string) error { // Determine the machine name. if resource.name != "" && c.flagName != "" && resource.name != c.flagName { - return fmt.Errorf(i18n.G("Cluster member name was provided as both a flag and as an argument")) + return errors.New(i18n.G("Cluster member name was provided as both a flag and as an argument")) } if resource.name == "" { @@ -1016,7 +1017,7 @@ func (c *cmdClusterListTokens) run(cmd *cobra.Command, args []string) error { } if !cluster.Enabled { - return fmt.Errorf(i18n.G("LXD server isn't part of a cluster")) + return errors.New(i18n.G("LXD server isn't part of a cluster")) } // Get the cluster member join tokens. Use default project as join tokens are created in default project. @@ -1119,7 +1120,7 @@ func (c *cmdClusterRevokeToken) run(cmd *cobra.Command, args []string) error { } if !cluster.Enabled { - return fmt.Errorf(i18n.G("LXD server isn't part of a cluster")) + return errors.New(i18n.G("LXD server isn't part of a cluster")) } // Get the cluster member join tokens. Use default project as join tokens are created in default project. @@ -1227,7 +1228,7 @@ func (c *cmdClusterUpdateCertificate) run(cmd *cobra.Command, args []string) err } if !cluster.Enabled { - return fmt.Errorf(i18n.G("LXD server isn't part of a cluster")) + return errors.New(i18n.G("LXD server isn't part of a cluster")) } if !shared.PathExists(certFile) { @@ -1363,7 +1364,7 @@ func (c *cmdClusterEvacuateAction) run(cmd *cobra.Command, args []string) error resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing cluster member name")) + return errors.New(i18n.G("Missing cluster member name")) } if !c.flagForce { diff --git a/lxc/cluster_group.go b/lxc/cluster_group.go index 188fc3a0f6b0..81460a07f894 100644 --- a/lxc/cluster_group.go +++ b/lxc/cluster_group.go @@ -1,6 +1,7 @@ package main import ( + "errors" "fmt" "io" "os" @@ -125,7 +126,7 @@ func (c *cmdClusterGroupAssign) run(cmd *cobra.Command, args []string) error { // Assign the cluster group if resource.name == "" { - return fmt.Errorf(i18n.G("Missing cluster member name")) + return errors.New(i18n.G("Missing cluster member name")) } member, etag, err := resource.server.GetClusterMember(resource.name) @@ -199,7 +200,7 @@ func (c *cmdClusterGroupCreate) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing cluster group name")) + return errors.New(i18n.G("Missing cluster group name")) } // Create the cluster group @@ -264,7 +265,7 @@ func (c *cmdClusterGroupDelete) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing cluster group name")) + return errors.New(i18n.G("Missing cluster group name")) } // Delete the cluster group @@ -324,7 +325,7 @@ func (c *cmdClusterGroupEdit) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing cluster group name")) + return errors.New(i18n.G("Missing cluster group name")) } // If stdin isn't a terminal, read text from it @@ -460,7 +461,7 @@ func (c *cmdClusterGroupList) run(cmd *cobra.Command, args []string) error { } if !cluster.Enabled { - return fmt.Errorf(i18n.G("LXD server isn't part of a cluster")) + return errors.New(i18n.G("LXD server isn't part of a cluster")) } groups, err := resource.server.GetClusterGroups() @@ -534,7 +535,7 @@ func (c *cmdClusterGroupRemove) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing cluster member name")) + return errors.New(i18n.G("Missing cluster member name")) } // Remove the cluster group @@ -671,7 +672,7 @@ func (c *cmdClusterGroupShow) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing cluster group name")) + return errors.New(i18n.G("Missing cluster group name")) } // Show the cluster group @@ -736,7 +737,7 @@ func (c *cmdClusterGroupAdd) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing cluster member name")) + return errors.New(i18n.G("Missing cluster member name")) } // Retrieve cluster member information. diff --git a/lxc/cluster_role.go b/lxc/cluster_role.go index 20877790ca48..911bd9a4e716 100644 --- a/lxc/cluster_role.go +++ b/lxc/cluster_role.go @@ -1,6 +1,7 @@ package main import ( + "errors" "fmt" "github.com/spf13/cobra" @@ -78,7 +79,7 @@ func (c *cmdClusterRoleAdd) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing cluster member name")) + return errors.New(i18n.G("Missing cluster member name")) } // Extract the current value @@ -146,7 +147,7 @@ func (c *cmdClusterRoleRemove) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing cluster member name")) + return errors.New(i18n.G("Missing cluster member name")) } // Extract the current value diff --git a/lxc/config.go b/lxc/config.go index b825bee760a0..161418e3d910 100644 --- a/lxc/config.go +++ b/lxc/config.go @@ -1,6 +1,7 @@ package main import ( + "errors" "fmt" "io" "os" @@ -166,7 +167,7 @@ func (c *cmdConfigEdit) run(cmd *cobra.Command, args []string) error { if resource.name != "" { // Quick checks. if c.config.flagTarget != "" { - return fmt.Errorf(i18n.G("--target cannot be used with instances")) + return errors.New(i18n.G("--target cannot be used with instances")) } // If stdin isn't a terminal, read text from it @@ -302,7 +303,7 @@ func (c *cmdConfigEdit) run(cmd *cobra.Command, args []string) error { // Targeting if c.config.flagTarget != "" { if !resource.server.IsClustered() { - return fmt.Errorf(i18n.G("To use --target, the destination remote must be a cluster")) + return errors.New(i18n.G("To use --target, the destination remote must be a cluster")) } resource.server = resource.server.UseTarget(c.config.flagTarget) @@ -439,7 +440,7 @@ func (c *cmdConfigGet) run(cmd *cobra.Command, args []string) error { if resource.name != "" { // Quick checks. if c.config.flagTarget != "" { - return fmt.Errorf(i18n.G("--target cannot be used with instances")) + return errors.New(i18n.G("--target cannot be used with instances")) } if isSnapshot { @@ -489,13 +490,13 @@ func (c *cmdConfigGet) run(cmd *cobra.Command, args []string) error { } else { // Quick check. if c.flagExpanded { - return fmt.Errorf(i18n.G("--expanded cannot be used with a server")) + return errors.New(i18n.G("--expanded cannot be used with a server")) } // Targeting if c.config.flagTarget != "" { if !resource.server.IsClustered() { - return fmt.Errorf(i18n.G("To use --target, the destination remote must be a cluster")) + return errors.New(i18n.G("To use --target, the destination remote must be a cluster")) } resource.server = resource.server.UseTarget(c.config.flagTarget) @@ -624,7 +625,7 @@ func (c *cmdConfigSet) run(cmd *cobra.Command, args []string) error { if resource.name != "" { // Quick checks. if c.config.flagTarget != "" { - return fmt.Errorf(i18n.G("--target cannot be used with instances")) + return errors.New(i18n.G("--target cannot be used with instances")) } keys, err := getConfig(args[1:]...) @@ -662,7 +663,7 @@ func (c *cmdConfigSet) run(cmd *cobra.Command, args []string) error { return op.Wait() } - return fmt.Errorf(i18n.G("There is no config key to set on an instance snapshot.")) + return errors.New(i18n.G("There is no config key to set on an instance snapshot.")) } inst, etag, err := resource.server.GetInstance(resource.name) @@ -711,7 +712,7 @@ func (c *cmdConfigSet) run(cmd *cobra.Command, args []string) error { // Targeting if c.config.flagTarget != "" { if !resource.server.IsClustered() { - return fmt.Errorf(i18n.G("To use --target, the destination remote must be a cluster")) + return errors.New(i18n.G("To use --target, the destination remote must be a cluster")) } resource.server = resource.server.UseTarget(c.config.flagTarget) @@ -805,13 +806,13 @@ func (c *cmdConfigShow) run(cmd *cobra.Command, args []string) error { if resource.name == "" { // Quick check. if c.flagExpanded { - return fmt.Errorf(i18n.G("--expanded cannot be used with a server")) + return errors.New(i18n.G("--expanded cannot be used with a server")) } // Targeting if c.config.flagTarget != "" { if !resource.server.IsClustered() { - return fmt.Errorf(i18n.G("To use --target, the destination remote must be a cluster")) + return errors.New(i18n.G("To use --target, the destination remote must be a cluster")) } resource.server = resource.server.UseTarget(c.config.flagTarget) @@ -831,7 +832,7 @@ func (c *cmdConfigShow) run(cmd *cobra.Command, args []string) error { } else { // Quick checks. if c.config.flagTarget != "" { - return fmt.Errorf(i18n.G("--target cannot be used with instances")) + return errors.New(i18n.G("--target cannot be used with instances")) } // Instance or snapshot config @@ -1004,7 +1005,7 @@ func (c *cmdConfigUefiGet) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Instance name must be specified")) + return errors.New(i18n.G("Instance name must be specified")) } // Get the UEFI variable @@ -1015,7 +1016,7 @@ func (c *cmdConfigUefiGet) run(cmd *cobra.Command, args []string) error { efiVariable, ok := resp.Variables[args[len(args)-1]] if !ok { - return fmt.Errorf(i18n.G("Requested UEFI variable does not exist")) + return errors.New(i18n.G("Requested UEFI variable does not exist")) } fmt.Println(efiVariable.Data) @@ -1062,7 +1063,7 @@ func (c *cmdConfigUefiSet) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Instance name must be specified")) + return errors.New(i18n.G("Instance name must be specified")) } // Set the config keys @@ -1181,7 +1182,7 @@ func (c *cmdConfigUefiShow) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Instance name must be specified")) + return errors.New(i18n.G("Instance name must be specified")) } instEFI, _, err := resource.server.GetInstanceUEFIVars(resource.name) @@ -1273,7 +1274,7 @@ func (c *cmdConfigUefiEdit) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Instance name must be specified")) + return errors.New(i18n.G("Instance name must be specified")) } // If stdin isn't a terminal, read text from it diff --git a/lxc/config_device.go b/lxc/config_device.go index 964f09564e6d..c0ead2681a71 100644 --- a/lxc/config_device.go +++ b/lxc/config_device.go @@ -1,6 +1,7 @@ package main import ( + "errors" "fmt" "strings" @@ -128,7 +129,7 @@ func (c *cmdConfigDeviceAdd) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing name")) + return errors.New(i18n.G("Missing name")) } // Add the device @@ -160,7 +161,7 @@ func (c *cmdConfigDeviceAdd) run(cmd *cobra.Command, args []string) error { _, ok := profile.Devices[devname] if ok { - return fmt.Errorf(i18n.G("The device already exists")) + return errors.New(i18n.G("The device already exists")) } profile.Devices[devname] = device @@ -177,7 +178,7 @@ func (c *cmdConfigDeviceAdd) run(cmd *cobra.Command, args []string) error { _, ok := inst.Devices[devname] if ok { - return fmt.Errorf(i18n.G("The device already exists")) + return errors.New(i18n.G("The device already exists")) } inst.Devices[devname] = device @@ -261,7 +262,7 @@ func (c *cmdConfigDeviceGet) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing name")) + return errors.New(i18n.G("Missing name")) } // Get the config key @@ -276,7 +277,7 @@ func (c *cmdConfigDeviceGet) run(cmd *cobra.Command, args []string) error { dev, ok := profile.Devices[devname] if !ok { - return fmt.Errorf(i18n.G("Device doesn't exist")) + return errors.New(i18n.G("Device doesn't exist")) } fmt.Println(dev[key]) @@ -290,10 +291,10 @@ func (c *cmdConfigDeviceGet) run(cmd *cobra.Command, args []string) error { if !ok { _, ok = inst.ExpandedDevices[devname] if !ok { - return fmt.Errorf(i18n.G("Device doesn't exist")) + return errors.New(i18n.G("Device doesn't exist")) } - return fmt.Errorf(i18n.G("Device from profile(s) cannot be retrieved for individual instance")) + return errors.New(i18n.G("Device from profile(s) cannot be retrieved for individual instance")) } fmt.Println(dev[key]) @@ -355,7 +356,7 @@ func (c *cmdConfigDeviceList) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing name")) + return errors.New(i18n.G("Missing name")) } // List the devices @@ -429,7 +430,7 @@ func (c *cmdConfigDeviceOverride) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing name")) + return errors.New(i18n.G("Missing name")) } // Override the device @@ -441,12 +442,12 @@ func (c *cmdConfigDeviceOverride) run(cmd *cobra.Command, args []string) error { devname := args[1] _, ok := inst.Devices[devname] if ok { - return fmt.Errorf(i18n.G("The device already exists")) + return errors.New(i18n.G("The device already exists")) } device, ok := inst.ExpandedDevices[devname] if !ok { - return fmt.Errorf(i18n.G("The profile device doesn't exist")) + return errors.New(i18n.G("The profile device doesn't exist")) } if len(args) > 2 { @@ -541,7 +542,7 @@ func (c *cmdConfigDeviceRemove) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing name")) + return errors.New(i18n.G("Missing name")) } // Remove the device @@ -554,7 +555,7 @@ func (c *cmdConfigDeviceRemove) run(cmd *cobra.Command, args []string) error { for _, devname := range args[1:] { _, ok := profile.Devices[devname] if !ok { - return fmt.Errorf(i18n.G("Device doesn't exist")) + return errors.New(i18n.G("Device doesn't exist")) } delete(profile.Devices, devname) @@ -575,10 +576,10 @@ func (c *cmdConfigDeviceRemove) run(cmd *cobra.Command, args []string) error { if !ok { _, ok := inst.ExpandedDevices[devname] if !ok { - return fmt.Errorf(i18n.G("Device doesn't exist")) + return errors.New(i18n.G("Device doesn't exist")) } - return fmt.Errorf(i18n.G("Device from profile(s) cannot be removed from individual instance. Override device or modify profile instead")) + return errors.New(i18n.G("Device from profile(s) cannot be removed from individual instance. Override device or modify profile instead")) } delete(inst.Devices, devname) @@ -670,7 +671,7 @@ func (c *cmdConfigDeviceSet) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing name")) + return errors.New(i18n.G("Missing name")) } // Set the device config key @@ -689,7 +690,7 @@ func (c *cmdConfigDeviceSet) run(cmd *cobra.Command, args []string) error { dev, ok := profile.Devices[devname] if !ok { - return fmt.Errorf(i18n.G("Device doesn't exist")) + return errors.New(i18n.G("Device doesn't exist")) } for k, v := range keys { @@ -712,10 +713,10 @@ func (c *cmdConfigDeviceSet) run(cmd *cobra.Command, args []string) error { if !ok { _, ok = inst.ExpandedDevices[devname] if !ok { - return fmt.Errorf(i18n.G("Device doesn't exist")) + return errors.New(i18n.G("Device doesn't exist")) } - return fmt.Errorf(i18n.G("Device from profile(s) cannot be modified for individual instance. Override device or modify profile instead")) + return errors.New(i18n.G("Device from profile(s) cannot be modified for individual instance. Override device or modify profile instead")) } for k, v := range keys { @@ -791,7 +792,7 @@ func (c *cmdConfigDeviceShow) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing name")) + return errors.New(i18n.G("Missing name")) } // Show the devices diff --git a/lxc/config_metadata.go b/lxc/config_metadata.go index 3ffc5e5253e4..119ccf9a5ded 100644 --- a/lxc/config_metadata.go +++ b/lxc/config_metadata.go @@ -1,6 +1,7 @@ package main import ( + "errors" "fmt" "io" "os" @@ -108,7 +109,7 @@ func (c *cmdConfigMetadataEdit) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing instance name")) + return errors.New(i18n.G("Missing instance name")) } // Edit the metadata @@ -217,7 +218,7 @@ func (c *cmdConfigMetadataShow) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing instance name")) + return errors.New(i18n.G("Missing instance name")) } // Show the instance metadata diff --git a/lxc/config_template.go b/lxc/config_template.go index 2180a452a3f8..7b78ed6ddea7 100644 --- a/lxc/config_template.go +++ b/lxc/config_template.go @@ -2,6 +2,7 @@ package main import ( "bytes" + "errors" "fmt" "io" "os" @@ -96,7 +97,7 @@ func (c *cmdConfigTemplateCreate) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing instance name")) + return errors.New(i18n.G("Missing instance name")) } // Create instance file template @@ -151,7 +152,7 @@ func (c *cmdConfigTemplateDelete) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing instance name")) + return errors.New(i18n.G("Missing instance name")) } // Delete instance file template @@ -205,7 +206,7 @@ func (c *cmdConfigTemplateEdit) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing instance name")) + return errors.New(i18n.G("Missing instance name")) } // Edit instance file template @@ -302,7 +303,7 @@ func (c *cmdConfigTemplateList) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing instance name")) + return errors.New(i18n.G("Missing instance name")) } // List the templates @@ -373,7 +374,7 @@ func (c *cmdConfigTemplateShow) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing instance name")) + return errors.New(i18n.G("Missing instance name")) } // Show the template diff --git a/lxc/copy.go b/lxc/copy.go index 18ffcddb59d4..7c012a68e618 100644 --- a/lxc/copy.go +++ b/lxc/copy.go @@ -1,6 +1,7 @@ package main import ( + "errors" "fmt" "strings" @@ -94,12 +95,12 @@ func (c *cmdCopy) copyInstance(conf *config.Config, sourceResource string, destR // Make sure we have an instance or snapshot name if sourceName == "" { - return fmt.Errorf(i18n.G("You must specify a source instance name")) + return errors.New(i18n.G("You must specify a source instance name")) } // Don't allow refreshing without profiles. if c.flagRefresh && c.flagNoProfiles { - return fmt.Errorf(i18n.G("--no-profiles cannot be used with --refresh")) + return errors.New(i18n.G("--no-profiles cannot be used with --refresh")) } // If the instance is being copied to a different remote and no destination name is @@ -111,7 +112,7 @@ func (c *cmdCopy) copyInstance(conf *config.Config, sourceResource string, destR // Ensure that a destination name is provided. if destName == "" { - return fmt.Errorf(i18n.G("You must specify a destination instance name")) + return errors.New(i18n.G("You must specify a destination instance name")) } // Connect to the source host @@ -140,7 +141,7 @@ func (c *cmdCopy) copyInstance(conf *config.Config, sourceResource string, destR // Confirm that --target is only used with a cluster if c.flagTarget != "" && !dest.IsClustered() { - return fmt.Errorf(i18n.G("To use --target, the destination remote must be a cluster")) + return errors.New(i18n.G("To use --target, the destination remote must be a cluster")) } // Parse the config overrides @@ -165,7 +166,7 @@ func (c *cmdCopy) copyInstance(conf *config.Config, sourceResource string, destR if shared.IsSnapshot(sourceName) { if instanceOnly { - return fmt.Errorf(i18n.G("--instance-only can't be passed when the source is a snapshot")) + return errors.New(i18n.G("--instance-only can't be passed when the source is a snapshot")) } // Prepare the instance creation request @@ -176,7 +177,7 @@ func (c *cmdCopy) copyInstance(conf *config.Config, sourceResource string, destR } if c.flagRefresh { - return fmt.Errorf(i18n.G("--refresh can only be used with instances")) + return errors.New(i18n.G("--refresh can only be used with instances")) } // Copy of a snapshot into a new instance diff --git a/lxc/delete.go b/lxc/delete.go index a96b4371456c..a6d3bbe1808f 100644 --- a/lxc/delete.go +++ b/lxc/delete.go @@ -2,6 +2,7 @@ package main import ( "bufio" + "errors" "fmt" "os" "strings" @@ -49,7 +50,7 @@ func (c *cmdDelete) promptDelete(name string) error { input = strings.TrimSuffix(input, "\n") if !shared.ValueInSlice(strings.ToLower(input), []string{i18n.G("yes")}) { - return fmt.Errorf(i18n.G("User aborted delete operation")) + return errors.New(i18n.G("User aborted delete operation")) } return nil @@ -124,7 +125,7 @@ func (c *cmdDelete) run(cmd *cobra.Command, args []string) error { if ct.StatusCode != 0 && ct.StatusCode != api.Stopped { if !c.flagForce { - return fmt.Errorf(i18n.G("The instance is currently running, stop it first or pass --force")) + return errors.New(i18n.G("The instance is currently running, stop it first or pass --force")) } req := api.InstanceStatePut{ diff --git a/lxc/exec.go b/lxc/exec.go index 05c0e84a369d..15658ea0f13b 100644 --- a/lxc/exec.go +++ b/lxc/exec.go @@ -2,7 +2,7 @@ package main import ( "bytes" - "fmt" + "errors" "io" "os" "strconv" @@ -98,11 +98,11 @@ func (c *cmdExec) run(cmd *cobra.Command, args []string) error { } if c.flagForceInteractive && c.flagForceNonInteractive { - return fmt.Errorf(i18n.G("You can't pass -t and -T at the same time")) + return errors.New(i18n.G("You can't pass -t and -T at the same time")) } if c.flagMode != "auto" && (c.flagForceInteractive || c.flagForceNonInteractive) { - return fmt.Errorf(i18n.G("You can't pass -t or -T at the same time as --mode")) + return errors.New(i18n.G("You can't pass -t or -T at the same time as --mode")) } // Connect to the daemon diff --git a/lxc/image.go b/lxc/image.go index cc6e86bc76f3..ac4b7b11f150 100644 --- a/lxc/image.go +++ b/lxc/image.go @@ -2,6 +2,7 @@ package main import ( "encoding/json" + "errors" "fmt" "io" "os" @@ -196,7 +197,7 @@ func (c *cmdImageCopy) run(cmd *cobra.Command, args []string) error { } if c.flagMode != "pull" && c.flagAutoUpdate { - return fmt.Errorf(i18n.G("Auto update is only available in pull mode")) + return errors.New(i18n.G("Auto update is only available in pull mode")) } // Parse source remote @@ -229,7 +230,7 @@ func (c *cmdImageCopy) run(cmd *cobra.Command, args []string) error { destinationServer := resources[0].server if resources[0].name != "" { - return fmt.Errorf(i18n.G("Can't provide a name for the target image")) + return errors.New(i18n.G("Can't provide a name for the target image")) } // Resolve image type @@ -360,7 +361,7 @@ func (c *cmdImageDelete) run(cmd *cobra.Command, args []string) error { for _, resource := range resources { if resource.name == "" { - return fmt.Errorf(i18n.G("Image identifier missing")) + return errors.New(i18n.G("Image identifier missing")) } image, _, err := c.image.dereferenceAlias(resource.server, "", resource.name) @@ -720,9 +721,9 @@ Directory import is only available on Linux and must be performed as root.`)) func (c *cmdImageImport) packImageDir(path string) (string, error) { // Quick checks. if os.Geteuid() == -1 { - return "", fmt.Errorf(i18n.G("Directory import is not available on this platform")) + return "", errors.New(i18n.G("Directory import is not available on this platform")) } else if os.Geteuid() != 0 { - return "", fmt.Errorf(i18n.G("Must run as root to import from directory")) + return "", errors.New(i18n.G("Must run as root to import from directory")) } outFile, err := os.CreateTemp("", "lxd_image_") @@ -799,7 +800,7 @@ func (c *cmdImageImport) run(cmd *cobra.Command, args []string) error { } if strings.HasPrefix(imageFile, "http://") { - return fmt.Errorf(i18n.G("Only https:// is supported for remote image import")) + return errors.New(i18n.G("Only https:// is supported for remote image import")) } var createArgs *lxd.ImageCreateArgs @@ -1013,7 +1014,7 @@ func (c *cmdImageInfo) run(cmd *cobra.Command, args []string) error { fmt.Printf(i18n.G("Architecture: %s")+"\n", info.Architecture) fmt.Printf(i18n.G("Type: %s")+"\n", imgType) fmt.Printf(i18n.G("Public: %s")+"\n", public) - fmt.Printf(i18n.G("Timestamps:") + "\n") + fmt.Print(i18n.G("Timestamps:") + "\n") const layout = "2006/01/02 15:04 UTC" if shared.TimeIsSet(info.CreatedAt) { @@ -1025,13 +1026,13 @@ func (c *cmdImageInfo) run(cmd *cobra.Command, args []string) error { if shared.TimeIsSet(info.ExpiresAt) { fmt.Printf(" "+i18n.G("Expires: %s")+"\n", info.ExpiresAt.UTC().Format(layout)) } else { - fmt.Printf(" " + i18n.G("Expires: never") + "\n") + fmt.Print(" " + i18n.G("Expires: never") + "\n") } if shared.TimeIsSet(info.LastUsedAt) { fmt.Printf(" "+i18n.G("Last used: %s")+"\n", info.LastUsedAt.UTC().Format(layout)) } else { - fmt.Printf(" " + i18n.G("Last used: never") + "\n") + fmt.Print(" " + i18n.G("Last used: never") + "\n") } fmt.Println(i18n.G("Properties:")) @@ -1059,7 +1060,7 @@ func (c *cmdImageInfo) run(cmd *cobra.Command, args []string) error { } if len(info.Profiles) == 0 { - fmt.Printf(i18n.G("Profiles: ") + "[]\n") + fmt.Print(i18n.G("Profiles: ") + "[]\n") } else { fmt.Println(i18n.G("Profiles:")) for _, name := range info.Profiles { @@ -1438,7 +1439,7 @@ func (c *cmdImageRefresh) run(cmd *cobra.Command, args []string) error { for _, resource := range resources { if resource.name == "" { - return fmt.Errorf(i18n.G("Image identifier missing")) + return errors.New(i18n.G("Image identifier missing")) } image, _, err := c.image.dereferenceAlias(resource.server, "", resource.name) @@ -1615,7 +1616,7 @@ func (c *cmdImageGetProp) run(cmd *cobra.Command, args []string) error { prop, propFound := image.Properties[args[1]] if !propFound { - return fmt.Errorf(i18n.G("Property not found")) + return errors.New(i18n.G("Property not found")) } fmt.Println(prop) diff --git a/lxc/info.go b/lxc/info.go index 801a7c62b2cf..02a84bfe4447 100644 --- a/lxc/info.go +++ b/lxc/info.go @@ -1,6 +1,7 @@ package main import ( + "errors" "fmt" "io" "sort" @@ -113,7 +114,7 @@ func (c *cmdInfo) renderGPU(gpu api.ResourcesGPUCard, prefix string, initial boo } if gpu.DRM != nil { - fmt.Printf(prefix + i18n.G("DRM:") + "\n") + fmt.Print(prefix + i18n.G("DRM:") + "\n") fmt.Printf(prefix+" "+i18n.G("ID: %d")+"\n", gpu.DRM.ID) if gpu.DRM.CardName != "" { @@ -130,7 +131,7 @@ func (c *cmdInfo) renderGPU(gpu api.ResourcesGPUCard, prefix string, initial boo } if gpu.Nvidia != nil { - fmt.Printf(prefix + i18n.G("NVIDIA information:") + "\n") + fmt.Print(prefix + i18n.G("NVIDIA information:") + "\n") fmt.Printf(prefix+" "+i18n.G("Architecture: %v")+"\n", gpu.Nvidia.Architecture) fmt.Printf(prefix+" "+i18n.G("Brand: %v")+"\n", gpu.Nvidia.Brand) fmt.Printf(prefix+" "+i18n.G("Model: %v")+"\n", gpu.Nvidia.Model) @@ -140,7 +141,7 @@ func (c *cmdInfo) renderGPU(gpu api.ResourcesGPUCard, prefix string, initial boo } if gpu.SRIOV != nil { - fmt.Printf(prefix + i18n.G("SR-IOV information:") + "\n") + fmt.Print(prefix + i18n.G("SR-IOV information:") + "\n") fmt.Printf(prefix+" "+i18n.G("Current number of VFs: %d")+"\n", gpu.SRIOV.CurrentVFs) fmt.Printf(prefix+" "+i18n.G("Maximum number of VFs: %d")+"\n", gpu.SRIOV.MaximumVFs) if len(gpu.SRIOV.VFs) > 0 { @@ -153,7 +154,7 @@ func (c *cmdInfo) renderGPU(gpu api.ResourcesGPUCard, prefix string, initial boo } if gpu.Mdev != nil { - fmt.Printf(prefix + i18n.G("Mdev profiles:") + "\n") + fmt.Print(prefix + i18n.G("Mdev profiles:") + "\n") keys := make([]string, 0, len(gpu.Mdev)) for k := range gpu.Mdev { @@ -199,7 +200,7 @@ func (c *cmdInfo) renderNIC(nic api.ResourcesNetworkCard, prefix string, initial } if len(nic.Ports) > 0 { - fmt.Printf(prefix + i18n.G("Ports:") + "\n") + fmt.Print(prefix + i18n.G("Ports:") + "\n") for _, port := range nic.Ports { fmt.Printf(prefix+" "+i18n.G("- Port %d (%s)")+"\n", port.Port, port.Protocol) fmt.Printf(prefix+" "+i18n.G("ID: %s")+"\n", port.ID) @@ -231,7 +232,7 @@ func (c *cmdInfo) renderNIC(nic api.ResourcesNetworkCard, prefix string, initial } if port.Infiniband != nil { - fmt.Printf(prefix + " " + i18n.G("Infiniband:") + "\n") + fmt.Print(prefix + " " + i18n.G("Infiniband:") + "\n") if port.Infiniband.IsSMName != "" { fmt.Printf(prefix+" "+i18n.G("IsSM: %s (%s)")+"\n", port.Infiniband.IsSMName, port.Infiniband.IsSMDevice) @@ -249,7 +250,7 @@ func (c *cmdInfo) renderNIC(nic api.ResourcesNetworkCard, prefix string, initial } if nic.SRIOV != nil { - fmt.Printf(prefix + i18n.G("SR-IOV information:") + "\n") + fmt.Print(prefix + i18n.G("SR-IOV information:") + "\n") fmt.Printf(prefix+" "+i18n.G("Current number of VFs: %d")+"\n", nic.SRIOV.CurrentVFs) fmt.Printf(prefix+" "+i18n.G("Maximum number of VFs: %d")+"\n", nic.SRIOV.MaximumVFs) if len(nic.SRIOV.VFs) > 0 { @@ -291,7 +292,7 @@ func (c *cmdInfo) renderDisk(disk api.ResourcesStorageDisk, prefix string, initi fmt.Printf(prefix+i18n.G("Removable: %v")+"\n", disk.Removable) if len(disk.Partitions) != 0 { - fmt.Printf(prefix + i18n.G("Partitions:") + "\n") + fmt.Print(prefix + i18n.G("Partitions:") + "\n") for _, partition := range disk.Partitions { fmt.Printf(prefix+" "+i18n.G("- Partition %d")+"\n", partition.Partition) fmt.Printf(prefix+" "+i18n.G("ID: %s")+"\n", partition.ID) @@ -313,17 +314,17 @@ func (c *cmdInfo) renderCPU(cpu api.ResourcesCPUSocket, prefix string) { } if cpu.Cache != nil { - fmt.Printf(prefix + i18n.G("Caches:") + "\n") + fmt.Print(prefix + i18n.G("Caches:") + "\n") for _, cache := range cpu.Cache { fmt.Printf(prefix+" "+i18n.G("- Level %d (type: %s): %s")+"\n", cache.Level, cache.Type, units.GetByteSizeStringIEC(int64(cache.Size), 0)) } } - fmt.Printf(prefix + i18n.G("Cores:") + "\n") + fmt.Print(prefix + i18n.G("Cores:") + "\n") for _, core := range cpu.Cores { fmt.Printf(prefix+" - "+i18n.G("Core %d")+"\n", core.Core) fmt.Printf(prefix+" "+i18n.G("Frequency: %vMhz")+"\n", core.Frequency) - fmt.Printf(prefix + " " + i18n.G("Threads:") + "\n") + fmt.Print(prefix + " " + i18n.G("Threads:") + "\n") for _, thread := range core.Threads { fmt.Printf(prefix+" - "+i18n.G("%d (id: %d, online: %v, NUMA node: %v)")+"\n", thread.Thread, thread.ID, thread.Online, thread.NUMANode) } @@ -342,7 +343,7 @@ func (c *cmdInfo) remoteInfo(d lxd.InstanceServer) error { // Targeting if c.flagTarget != "" { if !d.IsClustered() { - return fmt.Errorf(i18n.G("To use --target, the destination remote must be a cluster")) + return errors.New(i18n.G("To use --target, the destination remote must be a cluster")) } d = d.UseTarget(c.flagTarget) @@ -350,7 +351,7 @@ func (c *cmdInfo) remoteInfo(d lxd.InstanceServer) error { if c.flagResources { if !d.HasExtension("resources_v2") { - return fmt.Errorf(i18n.G("The server doesn't implement the newer v2 resources API")) + return errors.New(i18n.G("The server doesn't implement the newer v2 resources API")) } resources, err := d.GetServerResources() @@ -371,20 +372,20 @@ func (c *cmdInfo) remoteInfo(d lxd.InstanceServer) error { } // Memory - fmt.Printf("\n" + i18n.G("Memory:") + "\n") + fmt.Print("\n" + i18n.G("Memory:") + "\n") if resources.Memory.HugepagesTotal > 0 { - fmt.Printf(" " + i18n.G("Hugepages:"+"\n")) + fmt.Print(" " + i18n.G("Hugepages:"+"\n")) fmt.Printf(" "+i18n.G("Free: %v")+"\n", units.GetByteSizeStringIEC(int64(resources.Memory.HugepagesTotal-resources.Memory.HugepagesUsed), 2)) fmt.Printf(" "+i18n.G("Used: %v")+"\n", units.GetByteSizeStringIEC(int64(resources.Memory.HugepagesUsed), 2)) fmt.Printf(" "+i18n.G("Total: %v")+"\n", units.GetByteSizeStringIEC(int64(resources.Memory.HugepagesTotal), 2)) } if len(resources.Memory.Nodes) > 1 { - fmt.Printf(" " + i18n.G("NUMA nodes:"+"\n")) + fmt.Print(" " + i18n.G("NUMA nodes:"+"\n")) for _, node := range resources.Memory.Nodes { fmt.Printf(" "+i18n.G("Node %d:"+"\n"), node.NUMANode) if node.HugepagesTotal > 0 { - fmt.Printf(" " + i18n.G("Hugepages:"+"\n")) + fmt.Print(" " + i18n.G("Hugepages:"+"\n")) fmt.Printf(" "+i18n.G("Free: %v")+"\n", units.GetByteSizeStringIEC(int64(node.HugepagesTotal-node.HugepagesUsed), 2)) fmt.Printf(" "+i18n.G("Used: %v")+"\n", units.GetByteSizeStringIEC(int64(node.HugepagesUsed), 2)) fmt.Printf(" "+i18n.G("Total: %v")+"\n", units.GetByteSizeStringIEC(int64(node.HugepagesTotal), 2)) @@ -402,10 +403,10 @@ func (c *cmdInfo) remoteInfo(d lxd.InstanceServer) error { // GPUs if len(resources.GPU.Cards) == 1 { - fmt.Printf("\n" + i18n.G("GPU:") + "\n") + fmt.Print("\n" + i18n.G("GPU:") + "\n") c.renderGPU(resources.GPU.Cards[0], " ", true) } else if len(resources.GPU.Cards) > 1 { - fmt.Printf("\n" + i18n.G("GPUs:") + "\n") + fmt.Print("\n" + i18n.G("GPUs:") + "\n") for id, gpu := range resources.GPU.Cards { fmt.Printf(" "+i18n.G("Card %d:")+"\n", id) c.renderGPU(gpu, " ", true) @@ -414,10 +415,10 @@ func (c *cmdInfo) remoteInfo(d lxd.InstanceServer) error { // Network interfaces if len(resources.Network.Cards) == 1 { - fmt.Printf("\n" + i18n.G("NIC:") + "\n") + fmt.Print("\n" + i18n.G("NIC:") + "\n") c.renderNIC(resources.Network.Cards[0], " ", true) } else if len(resources.Network.Cards) > 1 { - fmt.Printf("\n" + i18n.G("NICs:") + "\n") + fmt.Print("\n" + i18n.G("NICs:") + "\n") for id, nic := range resources.Network.Cards { fmt.Printf(" "+i18n.G("Card %d:")+"\n", id) c.renderNIC(nic, " ", true) @@ -426,10 +427,10 @@ func (c *cmdInfo) remoteInfo(d lxd.InstanceServer) error { // Storage if len(resources.Storage.Disks) == 1 { - fmt.Printf("\n" + i18n.G("Disk:") + "\n") + fmt.Print("\n" + i18n.G("Disk:") + "\n") c.renderDisk(resources.Storage.Disks[0], " ", true) } else if len(resources.Storage.Disks) > 1 { - fmt.Printf("\n" + i18n.G("Disks:") + "\n") + fmt.Print("\n" + i18n.G("Disks:") + "\n") for id, nic := range resources.Storage.Disks { fmt.Printf(" "+i18n.G("Disk %d:")+"\n", id) c.renderDisk(nic, " ", true) @@ -457,7 +458,7 @@ func (c *cmdInfo) remoteInfo(d lxd.InstanceServer) error { func (c *cmdInfo) instanceInfo(d lxd.InstanceServer, name string, showLog bool) error { // Quick checks. if c.flagTarget != "" { - return fmt.Errorf(i18n.G("--target cannot be used with instances")) + return errors.New(i18n.G("--target cannot be used with instances")) } // Get the full instance data. diff --git a/lxc/init.go b/lxc/init.go index 2b31e6e66bf9..9522c8b45179 100644 --- a/lxc/init.go +++ b/lxc/init.go @@ -1,6 +1,7 @@ package main import ( + "errors" "fmt" "io" "net/url" @@ -138,7 +139,7 @@ func (c *cmdInit) create(conf *config.Config, args []string, launch bool) (lxd.I if c.flagEmpty { if len(args) > 1 { - return nil, "", fmt.Errorf(i18n.G("--empty cannot be combined with an image name")) + return nil, "", errors.New(i18n.G("--empty cannot be combined with an image name")) } if len(args) == 0 { @@ -174,13 +175,13 @@ func (c *cmdInit) create(conf *config.Config, args []string, launch bool) (lxd.I if !c.global.flagQuiet { if d.HasExtension("instance_create_start") && launch { if name == "" { - fmt.Printf(i18n.G("Launching the instance") + "\n") + fmt.Print(i18n.G("Launching the instance") + "\n") } else { fmt.Printf(i18n.G("Launching %s")+"\n", name) } } else { if name == "" { - fmt.Printf(i18n.G("Creating the instance") + "\n") + fmt.Print(i18n.G("Creating the instance") + "\n") } else { fmt.Printf(i18n.G("Creating %s")+"\n", name) } @@ -338,7 +339,7 @@ func (c *cmdInit) create(conf *config.Config, args []string, launch bool) (lxd.I if conf.Remotes[iremote].Protocol != "simplestreams" { if imgInfo.Type != "virtual-machine" && c.flagVM { - return nil, "", fmt.Errorf(i18n.G("Asked for a VM but image is of type container")) + return nil, "", errors.New(i18n.G("Asked for a VM but image is of type container")) } req.Type = api.InstanceType(imgInfo.Type) @@ -398,7 +399,7 @@ func (c *cmdInit) create(conf *config.Config, args []string, launch bool) (lxd.I // Try using the older "containers" field instances, ok = opInfo.Resources["containers"] if !ok || len(instances) == 0 { - return nil, "", fmt.Errorf(i18n.G("Didn't get any affected image, instance or snapshot from server")) + return nil, "", errors.New(i18n.G("Didn't get any affected image, instance or snapshot from server")) } } @@ -430,7 +431,7 @@ func (c *cmdInit) checkNetwork(d lxd.InstanceServer, name string) { } } - fmt.Fprintf(os.Stderr, "\n"+i18n.G("The instance you are starting doesn't have any network attached to it.")+"\n") - fmt.Fprintf(os.Stderr, " "+i18n.G("To create a new network, use: lxc network create")+"\n") - fmt.Fprintf(os.Stderr, " "+i18n.G("To attach a network to an instance, use: lxc network attach")+"\n\n") + fmt.Fprint(os.Stderr, "\n"+i18n.G("The instance you are starting doesn't have any network attached to it.")+"\n") + fmt.Fprint(os.Stderr, " "+i18n.G("To create a new network, use: lxc network create")+"\n") + fmt.Fprint(os.Stderr, " "+i18n.G("To attach a network to an instance, use: lxc network attach")+"\n\n") } diff --git a/lxc/list.go b/lxc/list.go index 9c5079faf18d..3035a9d38bc0 100644 --- a/lxc/list.go +++ b/lxc/list.go @@ -1,6 +1,7 @@ package main import ( + "errors" "fmt" "net" "regexp" @@ -463,7 +464,7 @@ func (c *cmdList) run(cmd *cobra.Command, args []string) error { } if c.global.flagProject != "" && c.flagAllProjects { - return fmt.Errorf(i18n.G("Can't specify --project with --all-projects")) + return errors.New(i18n.G("Can't specify --project with --all-projects")) } // Parse the remote @@ -590,7 +591,7 @@ func (c *cmdList) parseColumns(clustered bool) ([]column, bool, error) { if c.flagFast { if c.flagColumns != defaultColumns && c.flagColumns != defaultColumnsAllProjects { // --columns was specified too - return nil, false, fmt.Errorf(i18n.G("Can't specify --fast with --columns")) + return nil, false, errors.New(i18n.G("Can't specify --fast with --columns")) } if c.flagColumns == defaultColumnsAllProjects { @@ -606,7 +607,7 @@ func (c *cmdList) parseColumns(clustered bool) ([]column, bool, error) { } else { if c.flagColumns != defaultColumns && c.flagColumns != defaultColumnsAllProjects { if strings.ContainsAny(c.flagColumns, "L") { - return nil, false, fmt.Errorf(i18n.G("Can't specify column L when not clustered")) + return nil, false, errors.New(i18n.G("Can't specify column L when not clustered")) } } c.flagColumns = strings.Replace(c.flagColumns, "L", "", -1) diff --git a/lxc/main.go b/lxc/main.go index 0ddffd117187..ef3848c0f4d4 100644 --- a/lxc/main.go +++ b/lxc/main.go @@ -2,6 +2,7 @@ package main import ( "bufio" + "errors" "fmt" "os" "os/user" @@ -500,7 +501,8 @@ func (c *cmdGlobal) CheckArgs(cmd *cobra.Command, args []string, minArgs int, ma return true, nil } - return true, fmt.Errorf(i18n.G("Invalid number of arguments")) + msg := i18n.G("Invalid number of arguments") + return true, errors.New(msg) } return false, nil diff --git a/lxc/move.go b/lxc/move.go index 87ee56eab5b0..700b5d1d9922 100644 --- a/lxc/move.go +++ b/lxc/move.go @@ -1,6 +1,7 @@ package main import ( + "errors" "fmt" "strings" @@ -126,7 +127,7 @@ func (c *cmdMove) run(cmd *cobra.Command, args []string) error { // simply won't work). if sourceRemote == destRemote && c.flagTarget == "" && c.flagStorage == "" && c.flagTargetProject == "" { if c.flagConfig != nil || c.flagDevice != nil || c.flagProfile != nil || c.flagNoProfiles { - return fmt.Errorf(i18n.G("Can't override configuration or profiles in local rename")) + return errors.New(i18n.G("Can't override configuration or profiles in local rename")) } source, err := conf.GetInstanceServer(sourceRemote) @@ -140,11 +141,11 @@ func (c *cmdMove) run(cmd *cobra.Command, args []string) error { dstParent, dstSnap, dstIsSnap := api.GetParentAndSnapshotName(destName) if srcParent != dstParent { - return fmt.Errorf(i18n.G("Invalid new snapshot name, parent must be the same as source")) + return errors.New(i18n.G("Invalid new snapshot name, parent must be the same as source")) } if !dstIsSnap { - return fmt.Errorf(i18n.G("Invalid new snapshot name")) + return errors.New(i18n.G("Invalid new snapshot name")) } op, err := source.RenameInstanceSnapshot(srcParent, srcSnap, api.InstanceSnapshotPost{Name: dstSnap}) @@ -177,19 +178,19 @@ func (c *cmdMove) run(cmd *cobra.Command, args []string) error { // cluster member to another, let's use the dedicated API. if sourceRemote == destRemote { if c.flagInstanceOnly { - return fmt.Errorf(i18n.G("The --instance-only flag can't be used with --target")) + return errors.New(i18n.G("The --instance-only flag can't be used with --target")) } if c.flagStorage != "" { - return fmt.Errorf(i18n.G("The --storage flag can't be used with --target")) + return errors.New(i18n.G("The --storage flag can't be used with --target")) } if c.flagTargetProject != "" { - return fmt.Errorf(i18n.G("The --target-project flag can't be used with --target")) + return errors.New(i18n.G("The --target-project flag can't be used with --target")) } if c.flagMode != moveDefaultMode { - return fmt.Errorf(i18n.G("The --mode flag can't be used with --target")) + return errors.New(i18n.G("The --mode flag can't be used with --target")) } return moveClusterInstance(conf, sourceResource, destResource, c.flagTarget, c.global.flagQuiet, stateful) @@ -201,7 +202,7 @@ func (c *cmdMove) run(cmd *cobra.Command, args []string) error { } if !dest.IsClustered() { - return fmt.Errorf(i18n.G("The destination LXD server is not clustered")) + return errors.New(i18n.G("The destination LXD server is not clustered")) } } @@ -215,7 +216,7 @@ func (c *cmdMove) run(cmd *cobra.Command, args []string) error { if source.HasExtension("instance_move_config") { if c.flagMode != moveDefaultMode { - return fmt.Errorf(i18n.G("The --mode flag can't be used with --storage or --target-project")) + return errors.New(i18n.G("The --mode flag can't be used with --storage or --target-project")) } // Evaluate provided profiles. If no profiles were provided and flag noProfiles is false, @@ -236,7 +237,7 @@ func (c *cmdMove) run(cmd *cobra.Command, args []string) error { } if c.flagMode != moveDefaultMode { - return fmt.Errorf(i18n.G("The --mode flag can't be used with --storage or --target-project")) + return errors.New(i18n.G("The --mode flag can't be used with --storage or --target-project")) } return moveInstance(conf, sourceResource, destResource, c.flagStorage, c.flagTargetProject, []string{}, []string{}, nil, c.flagInstanceOnly, stateful) @@ -289,7 +290,7 @@ func moveClusterInstance(conf *config.Config, sourceResource string, destResourc // Make sure we have an instance or snapshot name. if sourceName == "" { - return fmt.Errorf(i18n.G("You must specify a source instance name")) + return errors.New(i18n.G("You must specify a source instance name")) } // The destination name is optional. @@ -305,7 +306,7 @@ func moveClusterInstance(conf *config.Config, sourceResource string, destResourc // Check that it's a cluster if !source.IsClustered() { - return fmt.Errorf(i18n.G("The source LXD server is not clustered")) + return errors.New(i18n.G("The source LXD server is not clustered")) } // The migrate API will do the right thing when passed a target. @@ -365,7 +366,7 @@ func moveInstance(conf *config.Config, sourceResource string, destResource strin // Make sure we have an instance or snapshot name. if sourceName == "" { - return fmt.Errorf(i18n.G("You must specify a source instance name")) + return errors.New(i18n.G("You must specify a source instance name")) } // The destination name is optional. diff --git a/lxc/network.go b/lxc/network.go index a21269c3f4e7..dfaf2fc71752 100644 --- a/lxc/network.go +++ b/lxc/network.go @@ -1,6 +1,7 @@ package main import ( + "errors" "fmt" "io" "os" @@ -168,7 +169,7 @@ func (c *cmdNetworkAttach) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing network name")) + return errors.New(i18n.G("Missing network name")) } // Default name is same as network @@ -265,7 +266,7 @@ func (c *cmdNetworkAttachProfile) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing network name")) + return errors.New(i18n.G("Missing network name")) } // Default name is same as network @@ -433,7 +434,7 @@ func (c *cmdNetworkDelete) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing network name")) + return errors.New(i18n.G("Missing network name")) } // Delete the network @@ -495,7 +496,7 @@ func (c *cmdNetworkDetach) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing network name")) + return errors.New(i18n.G("Missing network name")) } // Default name is same as network @@ -515,7 +516,7 @@ func (c *cmdNetworkDetach) run(cmd *cobra.Command, args []string) error { for n, d := range inst.Devices { if d["type"] == "nic" && (d["parent"] == resource.name || d["network"] == resource.name) { if devName != "" { - return fmt.Errorf(i18n.G("More than one device matches, specify the device name")) + return errors.New(i18n.G("More than one device matches, specify the device name")) } devName = n @@ -524,16 +525,16 @@ func (c *cmdNetworkDetach) run(cmd *cobra.Command, args []string) error { } if devName == "" { - return fmt.Errorf(i18n.G("No device found for this network")) + return errors.New(i18n.G("No device found for this network")) } device, ok := inst.Devices[devName] if !ok { - return fmt.Errorf(i18n.G("The specified device doesn't exist")) + return errors.New(i18n.G("The specified device doesn't exist")) } if device["type"] != "nic" || (device["parent"] != resource.name && device["network"] != resource.name) { - return fmt.Errorf(i18n.G("The specified device doesn't match the network")) + return errors.New(i18n.G("The specified device doesn't match the network")) } // Remove the device @@ -592,7 +593,7 @@ func (c *cmdNetworkDetachProfile) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing network name")) + return errors.New(i18n.G("Missing network name")) } // Default name is same as network @@ -612,7 +613,7 @@ func (c *cmdNetworkDetachProfile) run(cmd *cobra.Command, args []string) error { for n, d := range profile.Devices { if d["type"] == "nic" && (d["parent"] == resource.name || d["network"] == resource.name) { if devName != "" { - return fmt.Errorf(i18n.G("More than one device matches, specify the device name")) + return errors.New(i18n.G("More than one device matches, specify the device name")) } devName = n @@ -621,16 +622,16 @@ func (c *cmdNetworkDetachProfile) run(cmd *cobra.Command, args []string) error { } if devName == "" { - return fmt.Errorf(i18n.G("No device found for this network")) + return errors.New(i18n.G("No device found for this network")) } device, ok := profile.Devices[devName] if !ok { - return fmt.Errorf(i18n.G("The specified device doesn't exist")) + return errors.New(i18n.G("The specified device doesn't exist")) } if device["type"] != "nic" || (device["parent"] != resource.name && device["network"] != resource.name) { - return fmt.Errorf(i18n.G("The specified device doesn't match the network")) + return errors.New(i18n.G("The specified device doesn't match the network")) } // Remove the device @@ -705,7 +706,7 @@ func (c *cmdNetworkEdit) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing network name")) + return errors.New(i18n.G("Missing network name")) } // If stdin isn't a terminal, read text from it @@ -731,7 +732,7 @@ func (c *cmdNetworkEdit) run(cmd *cobra.Command, args []string) error { } if !network.Managed { - return fmt.Errorf(i18n.G("Only managed networks can be modified")) + return errors.New(i18n.G("Only managed networks can be modified")) } data, err := yaml.Marshal(&network) @@ -828,7 +829,7 @@ func (c *cmdNetworkGet) run(cmd *cobra.Command, args []string) error { client := resource.server if resource.name == "" { - return fmt.Errorf(i18n.G("Missing network name")) + return errors.New(i18n.G("Missing network name")) } // Get the network key @@ -904,13 +905,13 @@ func (c *cmdNetworkInfo) run(cmd *cobra.Command, args []string) error { client := resource.server if resource.name == "" { - return fmt.Errorf(i18n.G("Missing network name")) + return errors.New(i18n.G("Missing network name")) } // Targeting. if c.network.flagTarget != "" { if !client.IsClustered() { - return fmt.Errorf(i18n.G("To use --target, the destination remote must be a cluster")) + return errors.New(i18n.G("To use --target, the destination remote must be a cluster")) } client = client.UseTarget(c.network.flagTarget) @@ -929,7 +930,7 @@ func (c *cmdNetworkInfo) run(cmd *cobra.Command, args []string) error { fmt.Printf(i18n.G("Type: %s")+"\n", state.Type) // IP addresses. - if state.Addresses != nil && len(state.Addresses) > 0 { + if len(state.Addresses) > 0 { fmt.Println("") fmt.Println(i18n.G("IP addresses:")) for _, addr := range state.Addresses { @@ -1040,7 +1041,7 @@ func (c *cmdNetworkList) run(cmd *cobra.Command, args []string) error { // List the networks if resource.name != "" { - return fmt.Errorf(i18n.G("Filtering isn't supported yet")) + return errors.New(i18n.G("Filtering isn't supported yet")) } networks, err := resource.server.GetNetworks() @@ -1135,7 +1136,7 @@ func (c *cmdNetworkListLeases) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing network name")) + return errors.New(i18n.G("Missing network name")) } // List DHCP leases @@ -1213,7 +1214,7 @@ func (c *cmdNetworkRename) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing network name")) + return errors.New(i18n.G("Missing network name")) } // Rename the network @@ -1279,7 +1280,7 @@ func (c *cmdNetworkSet) run(cmd *cobra.Command, args []string) error { client := resource.server if resource.name == "" { - return fmt.Errorf(i18n.G("Missing network name")) + return errors.New(i18n.G("Missing network name")) } // Handle targeting @@ -1294,7 +1295,7 @@ func (c *cmdNetworkSet) run(cmd *cobra.Command, args []string) error { } if !network.Managed { - return fmt.Errorf(i18n.G("Only managed networks can be modified")) + return errors.New(i18n.G("Only managed networks can be modified")) } // Set the keys @@ -1371,7 +1372,7 @@ func (c *cmdNetworkShow) run(cmd *cobra.Command, args []string) error { client := resource.server if resource.name == "" { - return fmt.Errorf(i18n.G("Missing network name")) + return errors.New(i18n.G("Missing network name")) } // Show the network config diff --git a/lxc/network_acl.go b/lxc/network_acl.go index 0eb263715887..7e88f5a746c4 100644 --- a/lxc/network_acl.go +++ b/lxc/network_acl.go @@ -1,6 +1,7 @@ package main import ( + "errors" "fmt" "io" "os" @@ -129,7 +130,7 @@ func (c *cmdNetworkACLList) run(cmd *cobra.Command, args []string) error { // List the networks. if resource.name != "" { - return fmt.Errorf(i18n.G("Filtering isn't supported yet")) + return errors.New(i18n.G("Filtering isn't supported yet")) } acls, err := resource.server.GetNetworkACLs() @@ -200,7 +201,7 @@ func (c *cmdNetworkACLShow) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing network ACL name")) + return errors.New(i18n.G("Missing network ACL name")) } // Show the network ACL config. @@ -260,7 +261,7 @@ func (c *cmdNetworkACLShowLog) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing network ACL name")) + return errors.New(i18n.G("Missing network ACL name")) } // Get the ACL log. @@ -323,7 +324,7 @@ func (c *cmdNetworkACLGet) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing network ACL name")) + return errors.New(i18n.G("Missing network ACL name")) } resp, _, err := resource.server.GetNetworkACL(resource.name) @@ -391,7 +392,7 @@ func (c *cmdNetworkACLCreate) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing network ACL name")) + return errors.New(i18n.G("Missing network ACL name")) } // If stdin isn't a terminal, read yaml from it. @@ -489,7 +490,7 @@ func (c *cmdNetworkACLSet) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing network ACL name")) + return errors.New(i18n.G("Missing network ACL name")) } // Get the network ACL. @@ -642,7 +643,7 @@ func (c *cmdNetworkACLEdit) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing network ACL name")) + return errors.New(i18n.G("Missing network ACL name")) } // If stdin isn't a terminal, read text from it @@ -753,7 +754,7 @@ func (c *cmdNetworkACLRename) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing network ACL name")) + return errors.New(i18n.G("Missing network ACL name")) } // Rename the network. @@ -810,7 +811,7 @@ func (c *cmdNetworkACLDelete) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing network ACL name")) + return errors.New(i18n.G("Missing network ACL name")) } // Delete the network ACL. @@ -946,7 +947,7 @@ func (c *cmdNetworkACLRule) runAdd(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing network ACL name")) + return errors.New(i18n.G("Missing network ACL name")) } // Get config keys from arguments. @@ -979,7 +980,7 @@ func (c *cmdNetworkACLRule) runAdd(cmd *cobra.Command, args []string) error { } else if args[1] == "egress" { netACL.Egress = append(netACL.Egress, *rule) } else { - return fmt.Errorf(i18n.G("The direction argument must be one of: ingress, egress")) + return errors.New(i18n.G("The direction argument must be one of: ingress, egress")) } return resource.server.UpdateNetworkACL(resource.name, netACL.Writable(), etag) @@ -1029,7 +1030,7 @@ func (c *cmdNetworkACLRule) runRemove(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing network ACL name")) + return errors.New(i18n.G("Missing network ACL name")) } // Get config filters from arguments. @@ -1084,7 +1085,7 @@ func (c *cmdNetworkACLRule) runRemove(cmd *cobra.Command, args []string) error { for _, r := range rules { if isFilterMatch(&r, filters) { if removed && !c.flagRemoveForce { - return nil, fmt.Errorf(i18n.G("Multiple rules match. Use --force to remove them all")) + return nil, errors.New(i18n.G("Multiple rules match. Use --force to remove them all")) } removed = true @@ -1095,7 +1096,7 @@ func (c *cmdNetworkACLRule) runRemove(cmd *cobra.Command, args []string) error { } if !removed { - return nil, fmt.Errorf(i18n.G("No matching rule(s) found")) + return nil, errors.New(i18n.G("No matching rule(s) found")) } return newRules, nil @@ -1117,7 +1118,7 @@ func (c *cmdNetworkACLRule) runRemove(cmd *cobra.Command, args []string) error { netACL.Egress = rules } else { - return fmt.Errorf(i18n.G("The direction argument must be one of: ingress, egress")) + return errors.New(i18n.G("The direction argument must be one of: ingress, egress")) } return resource.server.UpdateNetworkACL(resource.name, netACL.Writable(), etag) diff --git a/lxc/network_forward.go b/lxc/network_forward.go index 840c25c8cf34..6b44435b432e 100644 --- a/lxc/network_forward.go +++ b/lxc/network_forward.go @@ -124,7 +124,7 @@ func (c *cmdNetworkForwardList) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing network name")) + return errors.New(i18n.G("Missing network name")) } forwards, err := resource.server.GetNetworkForwards(resource.name) @@ -212,11 +212,11 @@ func (c *cmdNetworkForwardShow) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing network name")) + return errors.New(i18n.G("Missing network name")) } if args[1] == "" { - return fmt.Errorf(i18n.G("Missing listen address")) + return errors.New(i18n.G("Missing listen address")) } client := resource.server @@ -276,7 +276,7 @@ func (c *cmdNetworkForwardCreate) run(cmd *cobra.Command, args []string) error { } if networkName == "" { - return fmt.Errorf(i18n.G("Missing network name")) + return errors.New(i18n.G("Missing network name")) } transporter, wrapper := newLocationHeaderTransportWrapper() @@ -437,11 +437,11 @@ func (c *cmdNetworkForwardGet) run(cmd *cobra.Command, args []string) error { client := resource.server if resource.name == "" { - return fmt.Errorf(i18n.G("Missing network name")) + return errors.New(i18n.G("Missing network name")) } if args[1] == "" { - return fmt.Errorf(i18n.G("Missing listen address")) + return errors.New(i18n.G("Missing listen address")) } // Get the current config. @@ -522,11 +522,11 @@ func (c *cmdNetworkForwardSet) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing network name")) + return errors.New(i18n.G("Missing network name")) } if args[1] == "" { - return fmt.Errorf(i18n.G("Missing listen address")) + return errors.New(i18n.G("Missing listen address")) } client := resource.server @@ -697,11 +697,11 @@ func (c *cmdNetworkForwardEdit) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing network name")) + return errors.New(i18n.G("Missing network name")) } if args[1] == "" { - return fmt.Errorf(i18n.G("Missing listen address")) + return errors.New(i18n.G("Missing listen address")) } client := resource.server @@ -828,11 +828,11 @@ func (c *cmdNetworkForwardDelete) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing network name")) + return errors.New(i18n.G("Missing network name")) } if args[1] == "" { - return fmt.Errorf(i18n.G("Missing listen address")) + return errors.New(i18n.G("Missing listen address")) } client := resource.server @@ -921,11 +921,11 @@ func (c *cmdNetworkForwardPort) runAdd(cmd *cobra.Command, args []string) error resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing network name")) + return errors.New(i18n.G("Missing network name")) } if args[1] == "" { - return fmt.Errorf(i18n.G("Missing listen address")) + return errors.New(i18n.G("Missing listen address")) } client := resource.server @@ -1003,11 +1003,11 @@ func (c *cmdNetworkForwardPort) runRemove(cmd *cobra.Command, args []string) err resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing network name")) + return errors.New(i18n.G("Missing network name")) } if args[1] == "" { - return fmt.Errorf(i18n.G("Missing listen address")) + return errors.New(i18n.G("Missing listen address")) } client := resource.server @@ -1051,7 +1051,7 @@ func (c *cmdNetworkForwardPort) runRemove(cmd *cobra.Command, args []string) err for _, port := range ports { if isFilterMatch(&port, filterArgs) { if removed && !c.flagRemoveForce { - return nil, fmt.Errorf(i18n.G("Multiple ports match. Use --force to remove them all")) + return nil, errors.New(i18n.G("Multiple ports match. Use --force to remove them all")) } removed = true @@ -1062,7 +1062,7 @@ func (c *cmdNetworkForwardPort) runRemove(cmd *cobra.Command, args []string) err } if !removed { - return nil, fmt.Errorf(i18n.G("No matching port(s) found")) + return nil, errors.New(i18n.G("No matching port(s) found")) } return newPorts, nil diff --git a/lxc/network_load_balancer.go b/lxc/network_load_balancer.go index 747d090dff20..17f5a2016f2e 100644 --- a/lxc/network_load_balancer.go +++ b/lxc/network_load_balancer.go @@ -128,7 +128,7 @@ func (c *cmdNetworkLoadBalancerList) run(cmd *cobra.Command, args []string) erro resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing network name")) + return errors.New(i18n.G("Missing network name")) } loadBalancers, err := resource.server.GetNetworkLoadBalancers(resource.name) @@ -214,11 +214,11 @@ func (c *cmdNetworkLoadBalancerShow) run(cmd *cobra.Command, args []string) erro resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing network name")) + return errors.New(i18n.G("Missing network name")) } if args[1] == "" { - return fmt.Errorf(i18n.G("Missing listen address")) + return errors.New(i18n.G("Missing listen address")) } client := resource.server @@ -278,7 +278,7 @@ func (c *cmdNetworkLoadBalancerCreate) run(cmd *cobra.Command, args []string) er } if networkName == "" { - return fmt.Errorf(i18n.G("Missing network name")) + return errors.New(i18n.G("Missing network name")) } transporter, wrapper := newLocationHeaderTransportWrapper() @@ -424,11 +424,11 @@ func (c *cmdNetworkLoadBalancerGet) run(cmd *cobra.Command, args []string) error client := resource.server if resource.name == "" { - return fmt.Errorf(i18n.G("Missing network name")) + return errors.New(i18n.G("Missing network name")) } if args[1] == "" { - return fmt.Errorf(i18n.G("Missing listen address")) + return errors.New(i18n.G("Missing listen address")) } // Get the current config. @@ -509,11 +509,11 @@ func (c *cmdNetworkLoadBalancerSet) run(cmd *cobra.Command, args []string) error resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing network name")) + return errors.New(i18n.G("Missing network name")) } if args[1] == "" { - return fmt.Errorf(i18n.G("Missing listen address")) + return errors.New(i18n.G("Missing listen address")) } client := resource.server @@ -667,11 +667,11 @@ func (c *cmdNetworkLoadBalancerEdit) run(cmd *cobra.Command, args []string) erro resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing network name")) + return errors.New(i18n.G("Missing network name")) } if args[1] == "" { - return fmt.Errorf(i18n.G("Missing listen address")) + return errors.New(i18n.G("Missing listen address")) } client := resource.server @@ -799,11 +799,11 @@ func (c *cmdNetworkLoadBalancerDelete) run(cmd *cobra.Command, args []string) er resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing network name")) + return errors.New(i18n.G("Missing network name")) } if args[1] == "" { - return fmt.Errorf(i18n.G("Missing listen address")) + return errors.New(i18n.G("Missing listen address")) } client := resource.server @@ -887,11 +887,11 @@ func (c *cmdNetworkLoadBalancerBackend) runAdd(cmd *cobra.Command, args []string resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing network name")) + return errors.New(i18n.G("Missing network name")) } if args[1] == "" { - return fmt.Errorf(i18n.G("Missing listen address")) + return errors.New(i18n.G("Missing listen address")) } client := resource.server @@ -963,11 +963,11 @@ func (c *cmdNetworkLoadBalancerBackend) runRemove(cmd *cobra.Command, args []str resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing network name")) + return errors.New(i18n.G("Missing network name")) } if args[1] == "" { - return fmt.Errorf(i18n.G("Missing listen address")) + return errors.New(i18n.G("Missing listen address")) } client := resource.server @@ -998,7 +998,7 @@ func (c *cmdNetworkLoadBalancerBackend) runRemove(cmd *cobra.Command, args []str } if !removed { - return nil, fmt.Errorf(i18n.G("No matching backend found")) + return nil, errors.New(i18n.G("No matching backend found")) } return newBackends, nil @@ -1076,11 +1076,11 @@ func (c *cmdNetworkLoadBalancerPort) runAdd(cmd *cobra.Command, args []string) e resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing network name")) + return errors.New(i18n.G("Missing network name")) } if args[1] == "" { - return fmt.Errorf(i18n.G("Missing listen address")) + return errors.New(i18n.G("Missing listen address")) } client := resource.server @@ -1150,11 +1150,11 @@ func (c *cmdNetworkLoadBalancerPort) runRemove(cmd *cobra.Command, args []string resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing network name")) + return errors.New(i18n.G("Missing network name")) } if args[1] == "" { - return fmt.Errorf(i18n.G("Missing listen address")) + return errors.New(i18n.G("Missing listen address")) } client := resource.server @@ -1198,7 +1198,7 @@ func (c *cmdNetworkLoadBalancerPort) runRemove(cmd *cobra.Command, args []string for _, port := range ports { if isFilterMatch(&port, filterArgs) { if removed && !c.flagRemoveForce { - return nil, fmt.Errorf(i18n.G("Multiple ports match. Use --force to remove them all")) + return nil, errors.New(i18n.G("Multiple ports match. Use --force to remove them all")) } removed = true @@ -1209,7 +1209,7 @@ func (c *cmdNetworkLoadBalancerPort) runRemove(cmd *cobra.Command, args []string } if !removed { - return nil, fmt.Errorf(i18n.G("No matching port(s) found")) + return nil, errors.New(i18n.G("No matching port(s) found")) } return newPorts, nil diff --git a/lxc/network_peer.go b/lxc/network_peer.go index c26da46aef5a..6c4c816bd61d 100644 --- a/lxc/network_peer.go +++ b/lxc/network_peer.go @@ -1,6 +1,7 @@ package main import ( + "errors" "fmt" "io" "os" @@ -115,7 +116,7 @@ func (c *cmdNetworkPeerList) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing network name")) + return errors.New(i18n.G("Missing network name")) } peers, err := resource.server.GetNetworkPeers(resource.name) @@ -197,11 +198,11 @@ func (c *cmdNetworkPeerShow) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing network name")) + return errors.New(i18n.G("Missing network name")) } if args[1] == "" { - return fmt.Errorf(i18n.G("Missing peer name")) + return errors.New(i18n.G("Missing peer name")) } client := resource.server @@ -262,15 +263,15 @@ func (c *cmdNetworkPeerCreate) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing network name")) + return errors.New(i18n.G("Missing network name")) } if args[1] == "" { - return fmt.Errorf(i18n.G("Missing peer name")) + return errors.New(i18n.G("Missing peer name")) } if args[2] == "" { - return fmt.Errorf(i18n.G("Missing target network")) + return errors.New(i18n.G("Missing target network")) } targetParts := strings.SplitN(args[2], "/", 2) @@ -397,11 +398,11 @@ func (c *cmdNetworkPeerGet) run(cmd *cobra.Command, args []string) error { client := resource.server if resource.name == "" { - return fmt.Errorf(i18n.G("Missing network name")) + return errors.New(i18n.G("Missing network name")) } if args[1] == "" { - return fmt.Errorf(i18n.G("Missing peer name")) + return errors.New(i18n.G("Missing peer name")) } // Get the current config. @@ -481,11 +482,11 @@ func (c *cmdNetworkPeerSet) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing network name")) + return errors.New(i18n.G("Missing network name")) } if args[1] == "" { - return fmt.Errorf(i18n.G("Missing peer name")) + return errors.New(i18n.G("Missing peer name")) } client := resource.server @@ -640,11 +641,11 @@ func (c *cmdNetworkPeerEdit) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing network name")) + return errors.New(i18n.G("Missing network name")) } if args[1] == "" { - return fmt.Errorf(i18n.G("Missing peer name")) + return errors.New(i18n.G("Missing peer name")) } client := resource.server @@ -761,11 +762,11 @@ func (c *cmdNetworkPeerDelete) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing network name")) + return errors.New(i18n.G("Missing network name")) } if args[1] == "" { - return fmt.Errorf(i18n.G("Missing peer name")) + return errors.New(i18n.G("Missing peer name")) } client := resource.server diff --git a/lxc/network_zone.go b/lxc/network_zone.go index 0eeff7271485..5e2b7bd65327 100644 --- a/lxc/network_zone.go +++ b/lxc/network_zone.go @@ -1,6 +1,7 @@ package main import ( + "errors" "fmt" "io" "os" @@ -120,7 +121,7 @@ func (c *cmdNetworkZoneList) run(cmd *cobra.Command, args []string) error { // List the networks. if resource.name != "" { - return fmt.Errorf(i18n.G("Filtering isn't supported yet")) + return errors.New(i18n.G("Filtering isn't supported yet")) } zones, err := resource.server.GetNetworkZones() @@ -191,7 +192,7 @@ func (c *cmdNetworkZoneShow) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing network zone name")) + return errors.New(i18n.G("Missing network zone name")) } // Show the network zone config. @@ -260,7 +261,7 @@ func (c *cmdNetworkZoneGet) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing network zone name")) + return errors.New(i18n.G("Missing network zone name")) } resp, _, err := resource.server.GetNetworkZone(resource.name) @@ -328,7 +329,7 @@ func (c *cmdNetworkZoneCreate) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing network zone name")) + return errors.New(i18n.G("Missing network zone name")) } // If stdin isn't a terminal, read yaml from it. @@ -424,7 +425,7 @@ func (c *cmdNetworkZoneSet) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing network zone name")) + return errors.New(i18n.G("Missing network zone name")) } // Get the network zone. @@ -565,7 +566,7 @@ func (c *cmdNetworkZoneEdit) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing network zone name")) + return errors.New(i18n.G("Missing network zone name")) } // If stdin isn't a terminal, read text from it @@ -676,7 +677,7 @@ func (c *cmdNetworkZoneDelete) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing network zone name")) + return errors.New(i18n.G("Missing network zone name")) } // Delete the network zone. @@ -790,7 +791,7 @@ func (c *cmdNetworkZoneRecordList) run(cmd *cobra.Command, args []string) error resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing network zone name")) + return errors.New(i18n.G("Missing network zone name")) } // List the records. @@ -870,7 +871,7 @@ func (c *cmdNetworkZoneRecordShow) run(cmd *cobra.Command, args []string) error resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing network zone name")) + return errors.New(i18n.G("Missing network zone name")) } // Show the network zone config. @@ -940,7 +941,7 @@ func (c *cmdNetworkZoneRecordGet) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing network zone record name")) + return errors.New(i18n.G("Missing network zone record name")) } resp, _, err := resource.server.GetNetworkZoneRecord(resource.name, args[1]) @@ -1011,7 +1012,7 @@ func (c *cmdNetworkZoneRecordCreate) run(cmd *cobra.Command, args []string) erro resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing network zone name")) + return errors.New(i18n.G("Missing network zone name")) } // If stdin isn't a terminal, read yaml from it. @@ -1108,7 +1109,7 @@ func (c *cmdNetworkZoneRecordSet) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing network zone name")) + return errors.New(i18n.G("Missing network zone name")) } // Get the network zone. @@ -1370,7 +1371,7 @@ func (c *cmdNetworkZoneRecordDelete) run(cmd *cobra.Command, args []string) erro resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing network zone name")) + return errors.New(i18n.G("Missing network zone name")) } // Delete the network zone. @@ -1447,7 +1448,7 @@ func (c *cmdNetworkZoneRecordEntry) runAdd(cmd *cobra.Command, args []string) er resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing network zone name")) + return errors.New(i18n.G("Missing network zone name")) } // Get the network record. @@ -1504,7 +1505,7 @@ func (c *cmdNetworkZoneRecordEntry) runRemove(cmd *cobra.Command, args []string) resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing network zone name")) + return errors.New(i18n.G("Missing network zone name")) } // Get the network zone record. @@ -1524,7 +1525,7 @@ func (c *cmdNetworkZoneRecordEntry) runRemove(cmd *cobra.Command, args []string) } if !found { - return fmt.Errorf(i18n.G("Couldn't find a matching entry")) + return errors.New(i18n.G("Couldn't find a matching entry")) } return resource.server.UpdateNetworkZoneRecord(resource.name, args[1], netRecord.Writable(), etag) diff --git a/lxc/profile.go b/lxc/profile.go index 713546841024..58c321136793 100644 --- a/lxc/profile.go +++ b/lxc/profile.go @@ -1,6 +1,7 @@ package main import ( + "errors" "fmt" "io" "net/http" @@ -137,7 +138,7 @@ func (c *cmdProfileAdd) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing instance name")) + return errors.New(i18n.G("Missing instance name")) } // Add the profile @@ -218,7 +219,7 @@ func (c *cmdProfileAssign) run(cmd *cobra.Command, args []string) error { // Assign the profiles if resource.name == "" { - return fmt.Errorf(i18n.G("Missing instance name")) + return errors.New(i18n.G("Missing instance name")) } inst, etag, err := resource.server.GetInstance(resource.name) @@ -306,7 +307,7 @@ func (c *cmdProfileCopy) run(cmd *cobra.Command, args []string) error { dest := resources[1] if source.name == "" { - return fmt.Errorf(i18n.G("Missing source profile name")) + return errors.New(i18n.G("Missing source profile name")) } if dest.name == "" { @@ -400,7 +401,7 @@ func (c *cmdProfileCreate) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing profile name")) + return fmt.Errorf("%s", i18n.G("Missing project name")) } // Create the profile @@ -463,7 +464,7 @@ func (c *cmdProfileDelete) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing profile name")) + return errors.New(i18n.G("Missing profile name")) } // Delete the profile @@ -545,7 +546,7 @@ func (c *cmdProfileEdit) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing profile name")) + return errors.New(i18n.G("Missing profile name")) } // If stdin isn't a terminal, read text from it @@ -663,7 +664,7 @@ func (c *cmdProfileGet) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing profile name")) + return errors.New(i18n.G("Missing profile name")) } // Get the configuration key @@ -804,7 +805,7 @@ func (c *cmdProfileRemove) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing instance name")) + return errors.New(i18n.G("Missing instance name")) } // Remove the profile @@ -888,7 +889,7 @@ func (c *cmdProfileRename) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing profile name")) + return errors.New(i18n.G("Missing profile name")) } // Rename the profile @@ -956,7 +957,7 @@ func (c *cmdProfileSet) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing profile name")) + return errors.New(i18n.G("Missing profile name")) } // Get the profile @@ -1037,7 +1038,7 @@ func (c *cmdProfileShow) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing profile name")) + return errors.New(i18n.G("Missing profile name")) } // Show the profile diff --git a/lxc/project.go b/lxc/project.go index c3cb052fe950..0bdf811dc7eb 100644 --- a/lxc/project.go +++ b/lxc/project.go @@ -1,6 +1,7 @@ package main import ( + "errors" "fmt" "io" "os" @@ -123,7 +124,7 @@ func (c *cmdProjectCreate) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing project name")) + return errors.New(i18n.G("Missing project name")) } // Create the project @@ -200,7 +201,7 @@ func (c *cmdProjectDelete) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing project name")) + return errors.New(i18n.G("Missing project name")) } // Delete the project @@ -290,7 +291,7 @@ func (c *cmdProjectEdit) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing project name")) + return errors.New(i18n.G("Missing project name")) } // If stdin isn't a terminal, read text from it @@ -407,7 +408,7 @@ func (c *cmdProjectGet) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing project name")) + return errors.New(i18n.G("Missing project name")) } // Get the configuration key @@ -597,7 +598,7 @@ func (c *cmdProjectRename) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing project name")) + return errors.New(i18n.G("Missing project name")) } // Rename the project @@ -666,7 +667,7 @@ func (c *cmdProjectSet) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing project name")) + return errors.New(i18n.G("Missing project name")) } // Get the project @@ -794,7 +795,7 @@ func (c *cmdProjectShow) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing project name")) + return errors.New(i18n.G("Missing project name")) } // Show the project @@ -923,7 +924,7 @@ func (c *cmdProjectInfo) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing project name")) + return errors.New(i18n.G("Missing project name")) } // Get the current allocations diff --git a/lxc/publish.go b/lxc/publish.go index 2fa0ca962d94..512ece940a1a 100644 --- a/lxc/publish.go +++ b/lxc/publish.go @@ -1,6 +1,7 @@ package main import ( + "errors" "fmt" "strings" "time" @@ -89,11 +90,11 @@ func (c *cmdPublish) run(cmd *cobra.Command, args []string) error { } if cName == "" { - return fmt.Errorf(i18n.G("Instance name is mandatory")) + return errors.New(i18n.G("Instance name is mandatory")) } if iName != "" { - return fmt.Errorf(i18n.G("There is no \"image name\". Did you want an alias?")) + return errors.New(i18n.G("There is no \"image name\". Did you want an alias?")) } d, err := conf.GetInstanceServer(iRemote) @@ -120,7 +121,7 @@ func (c *cmdPublish) run(cmd *cobra.Command, args []string) error { if wasRunning { if !c.flagForce { - return fmt.Errorf(i18n.G("The instance is currently running. Use --force to have it stopped and restarted")) + return errors.New(i18n.G("The instance is currently running. Use --force to have it stopped and restarted")) } if ct.Ephemeral { @@ -151,7 +152,7 @@ func (c *cmdPublish) run(cmd *cobra.Command, args []string) error { err = op.Wait() if err != nil { - return fmt.Errorf(i18n.G("Stopping instance failed!")) + return errors.New(i18n.G("Stopping instance failed!")) } // Start the instance back up on exit. diff --git a/lxc/remote.go b/lxc/remote.go index d8e87cdb067e..cdbeed7a4531 100644 --- a/lxc/remote.go +++ b/lxc/remote.go @@ -3,6 +3,7 @@ package main import ( "crypto/x509" "encoding/pem" + "errors" "fmt" "net" "net/http" @@ -187,7 +188,7 @@ func (c *cmdRemoteAdd) runToken(server string, token string, rawToken *api.Certi } if len(line) == 0 { - return fmt.Errorf(i18n.G("Failed to add remote")) + return errors.New(i18n.G("Failed to add remote")) } err = c.addRemoteFromToken(string(line), server, token, rawToken.Fingerprint) @@ -221,7 +222,7 @@ func (c *cmdRemoteAdd) addRemoteFromToken(addr string, server string, token stri dnam := conf.ConfigPath("servercerts") err := os.MkdirAll(dnam, 0750) if err != nil { - return fmt.Errorf(i18n.G("Could not create server cert dir")) + return errors.New(i18n.G("Could not create server cert dir")) } certf := conf.ServerCertPath(server) @@ -290,12 +291,12 @@ func (c *cmdRemoteAdd) run(cmd *cobra.Command, args []string) error { } if len(addr) == 0 { - return fmt.Errorf(i18n.G("Remote address must not be empty")) + return errors.New(i18n.G("Remote address must not be empty")) } // Validate the server name. if strings.Contains(server, ":") { - return fmt.Errorf(i18n.G("Remote names may not contain colons")) + return errors.New(i18n.G("Remote names may not contain colons")) } // Check for existing remote @@ -332,7 +333,7 @@ func (c *cmdRemoteAdd) run(cmd *cobra.Command, args []string) error { // Fast track simplestreams if c.flagProtocol == "simplestreams" { if remoteURL.Scheme != "https" { - return fmt.Errorf(i18n.G("Only https URLs are supported for simplestreams")) + return errors.New(i18n.G("Only https URLs are supported for simplestreams")) } conf.Remotes[server] = config.Remote{Addr: addr, Public: true, Protocol: c.flagProtocol} @@ -460,9 +461,9 @@ func (c *cmdRemoteAdd) run(cmd *cobra.Command, args []string) error { if string(line) != digest { if len(line) < 1 || strings.ToLower(string(line[0])) == i18n.G("n") { - return fmt.Errorf(i18n.G("Server certificate NACKed by user")) + return errors.New(i18n.G("Server certificate NACKed by user")) } else if strings.ToLower(string(line[0])) != i18n.G("y") { - return fmt.Errorf(i18n.G("Please type 'y', 'n' or the fingerprint:")) + return errors.New(i18n.G("Please type 'y', 'n' or the fingerprint:")) } } } @@ -470,7 +471,7 @@ func (c *cmdRemoteAdd) run(cmd *cobra.Command, args []string) error { dnam := conf.ConfigPath("servercerts") err := os.MkdirAll(dnam, 0750) if err != nil { - return fmt.Errorf(i18n.G("Could not create server cert dir")) + return errors.New(i18n.G("Could not create server cert dir")) } certf := conf.ServerCertPath(server) @@ -612,7 +613,7 @@ func (c *cmdRemoteAdd) run(cmd *cobra.Command, args []string) error { } if srv.Auth != "trusted" { - return fmt.Errorf(i18n.G("Server doesn't trust us after authentication")) + return errors.New(i18n.G("Server doesn't trust us after authentication")) } if c.flagAuthType == api.AuthenticationMethodTLS { @@ -890,7 +891,7 @@ func (c *cmdRemoteRemove) run(cmd *cobra.Command, args []string) error { } if conf.DefaultRemote == args[0] { - return fmt.Errorf(i18n.G("Can't remove the default remote")) + return errors.New(i18n.G("Can't remove the default remote")) } delete(conf.Remotes, args[0]) diff --git a/lxc/rename.go b/lxc/rename.go index 4312506034c4..201d2d1168ac 100644 --- a/lxc/rename.go +++ b/lxc/rename.go @@ -1,6 +1,7 @@ package main import ( + "errors" "fmt" "strings" @@ -56,7 +57,7 @@ func (c *cmdRename) run(cmd *cobra.Command, args []string) error { if sourceRemote != destRemote { // We just do renames if strings.Contains(args[1], ":") { - return fmt.Errorf(i18n.G("Can't specify a different remote for rename")) + return errors.New(i18n.G("Can't specify a different remote for rename")) } // Don't require the remote to be passed as both source and target diff --git a/lxc/storage.go b/lxc/storage.go index 892b69eb4cbe..e5526384214e 100644 --- a/lxc/storage.go +++ b/lxc/storage.go @@ -1,6 +1,7 @@ package main import ( + "errors" "fmt" "io" "net/url" @@ -207,7 +208,7 @@ func (c *cmdStorageDelete) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing pool name")) + return errors.New(i18n.G("Missing pool name")) } // Delete the pool @@ -285,7 +286,7 @@ func (c *cmdStorageEdit) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing pool name")) + return errors.New(i18n.G("Missing pool name")) } // If stdin isn't a terminal, read text from it @@ -403,7 +404,7 @@ func (c *cmdStorageGet) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing pool name")) + return errors.New(i18n.G("Missing pool name")) } // If a target member was specified, we return also member-specific config values. @@ -481,13 +482,13 @@ func (c *cmdStorageInfo) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing pool name")) + return errors.New(i18n.G("Missing pool name")) } // Targeting if c.storage.flagTarget != "" { if !resource.server.IsClustered() { - return fmt.Errorf(i18n.G("To use --target, the destination remote must be a cluster")) + return errors.New(i18n.G("To use --target, the destination remote must be a cluster")) } resource.server = resource.server.UseTarget(c.storage.flagTarget) @@ -752,7 +753,7 @@ func (c *cmdStorageSet) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing pool name")) + return errors.New(i18n.G("Missing pool name")) } client := resource.server @@ -858,7 +859,7 @@ func (c *cmdStorageShow) run(cmd *cobra.Command, args []string) error { client := resource.server if resource.name == "" { - return fmt.Errorf(i18n.G("Missing pool name")) + return errors.New(i18n.G("Missing pool name")) } // If a target member was specified, we return also member-specific config values. diff --git a/lxc/storage_volume.go b/lxc/storage_volume.go index e2c25648b2ab..57b88833dd11 100644 --- a/lxc/storage_volume.go +++ b/lxc/storage_volume.go @@ -1,6 +1,7 @@ package main import ( + "errors" "fmt" "io" "net/url" @@ -205,12 +206,12 @@ func (c *cmdStorageVolumeAttach) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing pool name")) + return errors.New(i18n.G("Missing pool name")) } volName, volType := parseVolume("custom", args[1]) if volType != "custom" { - return fmt.Errorf(i18n.G("Only \"custom\" volumes can be attached to instances")) + return errors.New(i18n.G("Only \"custom\" volumes can be attached to instances")) } // Attach the volume @@ -243,7 +244,7 @@ func (c *cmdStorageVolumeAttach) run(cmd *cobra.Command, args []string) error { devName = args[1] default: - return fmt.Errorf(i18n.G("Unsupported content type for attaching to instances")) + return errors.New(i18n.G("Unsupported content type for attaching to instances")) } } else if len(args) == 5 { // Path and device name have been given to us. @@ -319,7 +320,7 @@ func (c *cmdStorageVolumeAttachProfile) run(cmd *cobra.Command, args []string) e resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing pool name")) + return errors.New(i18n.G("Missing pool name")) } // Attach the volume @@ -339,7 +340,7 @@ func (c *cmdStorageVolumeAttachProfile) run(cmd *cobra.Command, args []string) e volName, volType := parseVolume("custom", args[1]) if volType != "custom" { - return fmt.Errorf(i18n.G("Only \"custom\" volumes can be attached to instances")) + return errors.New(i18n.G("Only \"custom\" volumes can be attached to instances")) } // Check if the requested storage volume actually exists @@ -428,7 +429,7 @@ func (c *cmdStorageVolumeCopy) run(cmd *cobra.Command, args []string) error { // Source srcResource := resources[0] if srcResource.name == "" { - return fmt.Errorf(i18n.G("Missing source volume name")) + return errors.New(i18n.G("Missing source volume name")) } srcServer := srcResource.server @@ -436,13 +437,13 @@ func (c *cmdStorageVolumeCopy) run(cmd *cobra.Command, args []string) error { // If the source server is standalone then --target cannot be provided. if c.storage.flagTarget != "" && !srcServer.IsClustered() { - return fmt.Errorf(i18n.G("Cannot set --target when source server is not clustered")) + return errors.New(i18n.G("Cannot set --target when source server is not clustered")) } // Get source pool and volume name srcVolName, srcVolPool := c.storageVolume.parseVolumeWithPool(srcPath) if srcVolPool == "" { - return fmt.Errorf(i18n.G("No storage pool for source volume specified")) + return errors.New(i18n.G("No storage pool for source volume specified")) } if c.storage.flagTarget != "" { @@ -482,7 +483,7 @@ func (c *cmdStorageVolumeCopy) run(cmd *cobra.Command, args []string) error { // places the volume on the target member, for remote volumes this does nothing). if c.storageVolume.flagDestinationTarget != "" { if !dstServer.IsClustered() { - return fmt.Errorf(i18n.G("Cannot set --destination-target when destination server is not clustered")) + return errors.New(i18n.G("Cannot set --destination-target when destination server is not clustered")) } dstServer = dstServer.UseTarget(c.storageVolume.flagDestinationTarget) @@ -492,7 +493,7 @@ func (c *cmdStorageVolumeCopy) run(cmd *cobra.Command, args []string) error { // TODO: Make is possible to run lxc storage volume copy pool/vol/snap new-pool/new-vol/new-snap dstVolName, dstVolPool := c.storageVolume.parseVolumeWithPool(dstPath) if dstVolPool == "" { - return fmt.Errorf(i18n.G("No storage pool for target volume specified")) + return errors.New(i18n.G("No storage pool for target volume specified")) } // Parse the mode @@ -635,7 +636,7 @@ func (c *cmdStorageVolumeCreate) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing pool name")) + return errors.New(i18n.G("Missing pool name")) } client := resource.server @@ -724,7 +725,7 @@ func (c *cmdStorageVolumeDelete) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing pool name")) + return errors.New(i18n.G("Missing pool name")) } client := resource.server @@ -815,7 +816,7 @@ func (c *cmdStorageVolumeDetach) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing pool name")) + return errors.New(i18n.G("Missing pool name")) } // Detach storage volumes @@ -835,7 +836,7 @@ func (c *cmdStorageVolumeDetach) run(cmd *cobra.Command, args []string) error { for n, d := range inst.Devices { if d["type"] == "disk" && d["pool"] == resource.name && d["source"] == args[1] { if devName != "" { - return fmt.Errorf(i18n.G("More than one device matches, specify the device name")) + return errors.New(i18n.G("More than one device matches, specify the device name")) } devName = n @@ -844,12 +845,12 @@ func (c *cmdStorageVolumeDetach) run(cmd *cobra.Command, args []string) error { } if devName == "" { - return fmt.Errorf(i18n.G("No device found for this storage volume")) + return errors.New(i18n.G("No device found for this storage volume")) } _, ok := inst.Devices[devName] if !ok { - return fmt.Errorf(i18n.G("The specified device doesn't exist")) + return errors.New(i18n.G("The specified device doesn't exist")) } // Remove the device @@ -913,7 +914,7 @@ func (c *cmdStorageVolumeDetachProfile) run(cmd *cobra.Command, args []string) e resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing pool name")) + return errors.New(i18n.G("Missing pool name")) } devName := "" @@ -932,7 +933,7 @@ func (c *cmdStorageVolumeDetachProfile) run(cmd *cobra.Command, args []string) e for n, d := range profile.Devices { if d["type"] == "disk" && d["pool"] == resource.name && d["source"] == args[1] { if devName != "" { - return fmt.Errorf(i18n.G("More than one device matches, specify the device name")) + return errors.New(i18n.G("More than one device matches, specify the device name")) } devName = n @@ -941,12 +942,12 @@ func (c *cmdStorageVolumeDetachProfile) run(cmd *cobra.Command, args []string) e } if devName == "" { - return fmt.Errorf(i18n.G("No device found for this storage volume")) + return errors.New(i18n.G("No device found for this storage volume")) } _, ok := profile.Devices[devName] if !ok { - return fmt.Errorf(i18n.G("The specified device doesn't exist")) + return errors.New(i18n.G("The specified device doesn't exist")) } // Remove the device @@ -1027,7 +1028,7 @@ func (c *cmdStorageVolumeEdit) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing pool name")) + return errors.New(i18n.G("Missing pool name")) } client := resource.server @@ -1038,7 +1039,7 @@ func (c *cmdStorageVolumeEdit) run(cmd *cobra.Command, args []string) error { isSnapshot := false fields := strings.Split(volName, "/") if len(fields) > 2 { - return fmt.Errorf(i18n.G("Invalid snapshot name")) + return errors.New(i18n.G("Invalid snapshot name")) } else if len(fields) > 1 { isSnapshot = true } @@ -1244,7 +1245,7 @@ func (c *cmdStorageVolumeGet) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing pool name")) + return errors.New(i18n.G("Missing pool name")) } client := resource.server @@ -1255,7 +1256,7 @@ func (c *cmdStorageVolumeGet) run(cmd *cobra.Command, args []string) error { isSnapshot := false fields := strings.Split(volName, "/") if len(fields) > 2 { - return fmt.Errorf(i18n.G("Invalid snapshot name")) + return errors.New(i18n.G("Invalid snapshot name")) } else if len(fields) > 1 { isSnapshot = true } @@ -1368,7 +1369,7 @@ func (c *cmdStorageVolumeInfo) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing storage pool name")) + return errors.New(i18n.G("Missing storage pool name")) } client := resource.server @@ -1379,14 +1380,14 @@ func (c *cmdStorageVolumeInfo) run(cmd *cobra.Command, args []string) error { isSnapshot := false fields := strings.Split(volName, "/") if len(fields) > 2 { - return fmt.Errorf(i18n.G("Invalid snapshot name")) + return errors.New(i18n.G("Invalid snapshot name")) } else if len(fields) > 1 { isSnapshot = true } // Check if syntax matches a snapshot if isSnapshot || volType == "image" { - return fmt.Errorf(i18n.G("Only instance or custom volumes are supported")) + return errors.New(i18n.G("Only instance or custom volumes are supported")) } // If a target member was specified, get the volume with the matching @@ -1717,7 +1718,7 @@ func (c *cmdStorageVolumeList) parseColumns(clustered bool, allVolumes bool) ([] } else { if c.flagColumns != c.defaultColumns { if strings.ContainsAny(c.flagColumns, "L") { - return nil, fmt.Errorf(i18n.G("Can't specify column L when not clustered")) + return nil, errors.New(i18n.G("Can't specify column L when not clustered")) } } c.flagColumns = strings.Replace(c.flagColumns, "L", "", -1) @@ -1858,7 +1859,7 @@ func (c *cmdStorageVolumeMove) run(cmd *cobra.Command, args []string) error { // Source srcResource := resources[0] if srcResource.name == "" { - return fmt.Errorf(i18n.G("Missing source volume name")) + return errors.New(i18n.G("Missing source volume name")) } srcRemote := srcResource.remote @@ -1867,7 +1868,7 @@ func (c *cmdStorageVolumeMove) run(cmd *cobra.Command, args []string) error { // Get source pool and volume name srcVolName, srcVolPool := c.storageVolume.parseVolumeWithPool(srcPath) if srcVolPool == "" { - return fmt.Errorf(i18n.G("No storage pool for source volume specified")) + return errors.New(i18n.G("No storage pool for source volume specified")) } // Destination @@ -1878,7 +1879,7 @@ func (c *cmdStorageVolumeMove) run(cmd *cobra.Command, args []string) error { // Get target pool and volume name dstVolName, dstVolPool := c.storageVolume.parseVolumeWithPool(dstPath) if dstVolPool == "" { - return fmt.Errorf(i18n.G("No storage pool for target volume specified")) + return errors.New(i18n.G("No storage pool for target volume specified")) } // Rename volume if both remotes and pools of source and target are equal @@ -1948,7 +1949,7 @@ func (c *cmdStorageVolumeRename) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing pool name")) + return errors.New(i18n.G("Missing pool name")) } client := resource.server @@ -1959,7 +1960,7 @@ func (c *cmdStorageVolumeRename) run(cmd *cobra.Command, args []string) error { isSnapshot := false fields := strings.Split(volName, "/") if len(fields) > 2 { - return fmt.Errorf(i18n.G("Invalid snapshot name")) + return errors.New(i18n.G("Invalid snapshot name")) } else if len(fields) > 1 { isSnapshot = true } @@ -1970,11 +1971,11 @@ func (c *cmdStorageVolumeRename) run(cmd *cobra.Command, args []string) error { dstParentName, dstSnapName, dstIsSnap := api.GetParentAndSnapshotName(args[2]) if dstParentName != fields[0] { - return fmt.Errorf(i18n.G("Invalid new snapshot name, parent volume must be the same as source")) + return errors.New(i18n.G("Invalid new snapshot name, parent volume must be the same as source")) } if !dstIsSnap { - return fmt.Errorf(i18n.G("Invalid new snapshot name")) + return errors.New(i18n.G("Invalid new snapshot name")) } vol.Name = dstSnapName @@ -1986,7 +1987,7 @@ func (c *cmdStorageVolumeRename) run(cmd *cobra.Command, args []string) error { } if len(fields) != 2 { - return fmt.Errorf(i18n.G("Not a snapshot name")) + return errors.New(i18n.G("Not a snapshot name")) } op, err := client.RenameStoragePoolVolumeSnapshot(resource.name, volType, fields[0], fields[1], vol) @@ -2089,7 +2090,7 @@ func (c *cmdStorageVolumeSet) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing pool name")) + return errors.New(i18n.G("Missing pool name")) } client := resource.server @@ -2106,7 +2107,7 @@ func (c *cmdStorageVolumeSet) run(cmd *cobra.Command, args []string) error { isSnapshot := false fields := strings.Split(volName, "/") if len(fields) > 2 { - return fmt.Errorf(i18n.G("Invalid snapshot name")) + return errors.New(i18n.G("Invalid snapshot name")) } else if len(fields) > 1 { isSnapshot = true } @@ -2141,7 +2142,7 @@ func (c *cmdStorageVolumeSet) run(cmd *cobra.Command, args []string) error { return nil } - return fmt.Errorf(i18n.G("Snapshots are read-only and can't have their configuration changed")) + return errors.New(i18n.G("Snapshots are read-only and can't have their configuration changed")) } // If a target was specified, create the volume on the given member. @@ -2247,7 +2248,7 @@ func (c *cmdStorageVolumeShow) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing pool name")) + return errors.New(i18n.G("Missing pool name")) } client := resource.server @@ -2258,7 +2259,7 @@ func (c *cmdStorageVolumeShow) run(cmd *cobra.Command, args []string) error { isSnapshot := false fields := strings.Split(volName, "/") if len(fields) > 2 { - return fmt.Errorf(i18n.G("Invalid snapshot name")) + return errors.New(i18n.G("Invalid snapshot name")) } else if len(fields) > 1 { isSnapshot = true } @@ -2418,7 +2419,7 @@ func (c *cmdStorageVolumeSnapshot) run(cmd *cobra.Command, args []string) error resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing pool name")) + return errors.New(i18n.G("Missing pool name")) } client := resource.server @@ -2431,7 +2432,7 @@ func (c *cmdStorageVolumeSnapshot) run(cmd *cobra.Command, args []string) error // Parse the input volName, volType := parseVolume("custom", args[1]) if volType != "custom" { - return fmt.Errorf(i18n.G("Only \"custom\" volumes can be snapshotted")) + return errors.New(i18n.G("Only \"custom\" volumes can be snapshotted")) } // Check if the requested storage volume actually exists @@ -2529,7 +2530,7 @@ func (c *cmdStorageVolumeRestore) run(cmd *cobra.Command, args []string) error { resource := resources[0] if resource.name == "" { - return fmt.Errorf(i18n.G("Missing pool name")) + return errors.New(i18n.G("Missing pool name")) } client := resource.server @@ -2626,7 +2627,7 @@ func (c *cmdStorageVolumeExport) run(cmd *cobra.Command, args []string) error { volName, volType := parseVolume("custom", args[1]) if volType != "custom" { - return fmt.Errorf(i18n.G("Only \"custom\" volumes can be exported")) + return errors.New(i18n.G("Only \"custom\" volumes can be exported")) } req := api.StoragePoolVolumeBackupsPost{