Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lxc/network_load_balancer: add Example to create (from Incus) #13984

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 28 additions & 23 deletions lxc/network_load_balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,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)
Expand Down Expand Up @@ -194,11 +194,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
Expand Down Expand Up @@ -236,6 +236,11 @@ func (c *cmdNetworkLoadBalancerCreate) command() *cobra.Command {
cmd.Use = usage("create", i18n.G("[<remote>:]<network> [<listen_address>] [key=value...]"))
cmd.Short = i18n.G("Create new network load balancers")
cmd.Long = cli.FormatSection(i18n.G("Description"), i18n.G("Create new network load balancers"))
cmd.Example = cli.FormatSection("", i18n.G(`lxc network load-balancer create n1 127.0.0.1

lxc network load-balancer create n1 127.0.0.1 < config.yaml
Create network load-balancer for network n1 with configuration from config.yaml`))

cmd.RunE = c.run

cmd.Flags().StringVar(&c.networkLoadBalancer.flagTarget, "target", "", i18n.G("Cluster member name")+"``")
Expand All @@ -258,7 +263,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()
Expand Down Expand Up @@ -404,11 +409,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.
Expand Down Expand Up @@ -477,11 +482,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
Expand Down Expand Up @@ -623,11 +628,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
Expand Down Expand Up @@ -743,11 +748,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
Expand Down Expand Up @@ -819,11 +824,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
Expand Down Expand Up @@ -883,11 +888,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
Expand Down Expand Up @@ -918,7 +923,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
Expand Down Expand Up @@ -984,11 +989,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
Expand Down Expand Up @@ -1046,11 +1051,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
Expand Down Expand Up @@ -1094,7 +1099,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
Expand All @@ -1105,7 +1110,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
Expand Down
Loading
Loading