-
Notifications
You must be signed in to change notification settings - Fork 20
/
nlb_update.go
67 lines (55 loc) · 1.51 KB
/
nlb_update.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package cmd
import (
"fmt"
apiv2 "github.com/exoscale/egoscale/api/v2"
"github.com/spf13/cobra"
)
var nlbUpdateCmd = &cobra.Command{
Use: "update <name | ID>",
Short: "Update a Network Load Balancer",
PreRunE: func(cmd *cobra.Command, args []string) error {
if len(args) != 1 {
cmdExitOnUsageError(cmd, "missing arguments")
}
cmdSetZoneFlagFromDefault(cmd)
return cmdCheckRequiredFlags(cmd, []string{"zone"})
},
RunE: func(cmd *cobra.Command, args []string) error {
zone, err := cmd.Flags().GetString("zone")
if err != nil {
return err
}
ctx := apiv2.WithEndpoint(gContext, apiv2.NewReqEndpoint(gCurrentAccount.Environment, zone))
nlb, err := lookupNLB(ctx, zone, args[0])
if err != nil {
return err
}
name, err := cmd.Flags().GetString("name")
if err != nil {
return err
}
if cmd.Flags().Changed("name") {
nlb.Name = name
}
description, err := cmd.Flags().GetString("description")
if err != nil {
return err
}
if cmd.Flags().Changed("description") {
nlb.Description = description
}
if _, err := cs.UpdateNetworkLoadBalancer(ctx, zone, nlb); err != nil {
return fmt.Errorf("unable to update Network Load Balancer: %s", err)
}
if !gQuiet {
return output(showNLB(zone, nlb.ID))
}
return nil
},
}
func init() {
nlbUpdateCmd.Flags().StringP("zone", "z", "", "Network Load Balancer zone")
nlbUpdateCmd.Flags().String("name", "", "service name")
nlbUpdateCmd.Flags().String("description", "", "service description")
nlbCmd.AddCommand(nlbUpdateCmd)
}