|
| 1 | +package cmd |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + |
| 6 | + "github.com/gluster/glusterd2/pkg/api" |
| 7 | + |
| 8 | + log "github.com/sirupsen/logrus" |
| 9 | + "github.com/spf13/cobra" |
| 10 | +) |
| 11 | + |
| 12 | +const ( |
| 13 | + labelCreateHelpShort = "Create a label" |
| 14 | + labelCreateHelpLong = "Create a label that can use to tag different objects. Label values will be created with default values if choose to omit, specific label values should provide using relevant flags." |
| 15 | +) |
| 16 | + |
| 17 | +var ( |
| 18 | + flagSnapMaxHardLimit uint64 |
| 19 | + flagSnapMaxSoftLimit uint64 |
| 20 | + flagActivateOnCreate bool |
| 21 | + flagAutoDelete bool |
| 22 | + flagDescription string |
| 23 | + |
| 24 | + labelCreateCmd = &cobra.Command{ |
| 25 | + Use: "create <labelname>", |
| 26 | + Short: labelCreateHelpShort, |
| 27 | + Long: labelCreateHelpLong, |
| 28 | + Args: cobra.MinimumNArgs(1), |
| 29 | + Run: labelCreateCmdRun, |
| 30 | + } |
| 31 | +) |
| 32 | + |
| 33 | +func init() { |
| 34 | + labelCreateCmd.Flags().Uint64Var(&flagSnapMaxHardLimit, "snap-max-hard-limit", 256, "Snapshot maximum hard limit count") |
| 35 | + labelCreateCmd.Flags().Uint64Var(&flagSnapMaxSoftLimit, "snap-max-soft-limit", 230, "Snapshot maximum soft limit count") |
| 36 | + labelCreateCmd.Flags().BoolVar(&flagActivateOnCreate, "activate-on-create", false, "If enabled, Further snapshots will be activated after creation") |
| 37 | + labelCreateCmd.Flags().BoolVar(&flagAutoDelete, "auto-delete", false, "If enabled, Snapshots will be deleted upon reaching snap-max-soft-limit. If disabled A warning log will be generated") |
| 38 | + labelCreateCmd.Flags().StringVar(&flagDescription, "description", "", "Label description") |
| 39 | + |
| 40 | + labelCmd.AddCommand(labelCreateCmd) |
| 41 | +} |
| 42 | + |
| 43 | +func labelCreateCmdRun(cmd *cobra.Command, args []string) { |
| 44 | + labelname := args[0] |
| 45 | + |
| 46 | + req := api.LabelCreateReq{ |
| 47 | + Name: labelname, |
| 48 | + SnapMaxHardLimit: flagSnapMaxHardLimit, |
| 49 | + SnapMaxSoftLimit: flagSnapMaxSoftLimit, |
| 50 | + ActivateOnCreate: flagActivateOnCreate, |
| 51 | + AutoDelete: flagAutoDelete, |
| 52 | + Description: flagDescription, |
| 53 | + } |
| 54 | + |
| 55 | + info, err := client.LabelCreate(req) |
| 56 | + if err != nil { |
| 57 | + if GlobalFlag.Verbose { |
| 58 | + log.WithError(err).WithFields( |
| 59 | + log.Fields{ |
| 60 | + "labelname": labelname, |
| 61 | + }).Error("label creation failed") |
| 62 | + } |
| 63 | + failure("Label creation failed", err, 1) |
| 64 | + } |
| 65 | + fmt.Printf("%s Label created successfully\n", info.Name) |
| 66 | +} |
0 commit comments