|
| 1 | +package ugn |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + |
| 6 | + "github.com/spf13/cobra" |
| 7 | + |
| 8 | + ugnsdk "github.com/ucloud/ucloud-sdk-go/services/ugn" |
| 9 | + |
| 10 | + "github.com/ucloud/ucloud-cli/pkg/cli" |
| 11 | + "github.com/ucloud/ucloud-cli/pkg/command" |
| 12 | +) |
| 13 | + |
| 14 | +// newBWCreate ucloud ugn bw create |
| 15 | +func newBWCreate(ctx *cli.Context) *cobra.Command { |
| 16 | + client := cli.NewServiceClient(ctx, ugnsdk.NewClient) |
| 17 | + req := client.NewCreateSimpleUGNBwPackageRequest() |
| 18 | + cmd := &cobra.Command{ |
| 19 | + Use: "create", |
| 20 | + Short: "Create a ugn bandwidth package", |
| 21 | + Long: "Create a ugn bandwidth package", |
| 22 | + Run: func(c *cobra.Command, args []string) { |
| 23 | + _, err := client.CreateSimpleUGNBwPackage(req) |
| 24 | + if err != nil { |
| 25 | + ctx.HandleError(err) |
| 26 | + return |
| 27 | + } |
| 28 | + fmt.Fprintf(ctx.ProgressWriter(), "ugn bw created\n") |
| 29 | + ctx.EmitResult(cli.OpResultRow{Action: "create-bw", Status: "Created"}) |
| 30 | + }, |
| 31 | + } |
| 32 | + |
| 33 | + flags := cmd.Flags() |
| 34 | + flags.SortFlags = false |
| 35 | + |
| 36 | + req.UGNID = flags.String("ugn-id", "", "Required. Resource ID of the ugn instance") |
| 37 | + req.BandWidth = flags.Int("bandwidth", 0, "Required. Bandwidth value in Mbps") |
| 38 | + req.Path = flags.String("path", "IGP", "Path policy: Delay/IGP/TCO") |
| 39 | + req.PayMode = flags.String("pay-mode", "", "Required. Pay mode: FixedBw/Max5/Traffic") |
| 40 | + req.ChargeType = flags.String("charge-type", "", "Required. Charge type: Month/Postpay") |
| 41 | + req.RegionA = flags.String("region-a", "", "Required. Region A of the bandwidth package") |
| 42 | + req.RegionB = flags.String("region-b", "", "Required. Region B of the bandwidth package") |
| 43 | + req.Name = flags.String("name", "", "Optional. Bandwidth package name") |
| 44 | + req.Qos = flags.String("qos", "Platinum", "Optional. QoS: Diamond/Platinum/Gold") |
| 45 | + req.CouponId = flags.String("coupon-id", "", "Optional. Coupon ID") |
| 46 | + req.Quantity = flags.Float64("quantity", 1, "Optional. Duration in months, default 1") |
| 47 | + |
| 48 | + ctx.BindProjectID(cmd, req) |
| 49 | + ctx.SetCompletion(cmd, "ugn-id", func() []string { |
| 50 | + return getAllUGNIdNames(ctx, *req.ProjectId) |
| 51 | + }) |
| 52 | + ctx.SetCompletion(cmd, "project-id", ctx.ProjectList) |
| 53 | + command.SetFlagValues(cmd, "path", "Delay", "IGP", "TCO") |
| 54 | + command.SetFlagValues(cmd, "pay-mode", "FixedBw", "Max5", "Traffic") |
| 55 | + command.SetFlagValues(cmd, "charge-type", "Month", "Postpay") |
| 56 | + command.SetFlagValues(cmd, "qos", "Diamond", "Platinum", "Gold") |
| 57 | + |
| 58 | + cmd.MarkFlagRequired("ugn-id") |
| 59 | + cmd.MarkFlagRequired("bandwidth") |
| 60 | + cmd.MarkFlagRequired("pay-mode") |
| 61 | + cmd.MarkFlagRequired("charge-type") |
| 62 | + cmd.MarkFlagRequired("region-a") |
| 63 | + cmd.MarkFlagRequired("region-b") |
| 64 | + |
| 65 | + return cmd |
| 66 | +} |
0 commit comments