Skip to content

Commit 54acd22

Browse files
committed
review
1 parent 63341f9 commit 54acd22

4 files changed

Lines changed: 86 additions & 54 deletions

File tree

cmd/eip.go

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -90,27 +90,27 @@ func NewCmdEIPList() *cobra.Command {
9090
eipList = resp.EIPSet
9191
}
9292

93+
list := make([]EIPRow, 0)
94+
for _, eip := range eipList {
95+
row := EIPRow{}
96+
row.Name = eip.Name
97+
for _, ip := range eip.EIPAddr {
98+
row.IP += ip.IP + " " + ip.OperatorName + " "
99+
}
100+
row.ResourceID = eip.EIPId
101+
row.Group = eip.Tag
102+
row.ChargeMode = eip.PayMode
103+
row.Bandwidth = strconv.Itoa(eip.Bandwidth) + "Mb"
104+
if eip.Resource.ResourceId != "" {
105+
row.BindResource = fmt.Sprintf("%s|%s(%s)", eip.Resource.ResourceName, eip.Resource.ResourceId, eip.Resource.ResourceType)
106+
}
107+
row.Status = eip.Status
108+
row.ExpirationTime = time.Unix(int64(eip.ExpireTime), 0).Format("2006-01-02")
109+
list = append(list, row)
110+
}
93111
if global.json {
94-
base.PrintJSON(eipList)
112+
base.PrintJSON(list)
95113
} else {
96-
list := make([]EIPRow, 0)
97-
for _, eip := range eipList {
98-
row := EIPRow{}
99-
row.Name = eip.Name
100-
for _, ip := range eip.EIPAddr {
101-
row.IP += ip.IP + " " + ip.OperatorName + " "
102-
}
103-
row.ResourceID = eip.EIPId
104-
row.Group = eip.Tag
105-
row.ChargeMode = eip.PayMode
106-
row.Bandwidth = strconv.Itoa(eip.Bandwidth) + "Mb"
107-
if eip.Resource.ResourceId != "" {
108-
row.BindResource = fmt.Sprintf("%s|%s(%s)", eip.Resource.ResourceName, eip.Resource.ResourceId, eip.Resource.ResourceType)
109-
}
110-
row.Status = eip.Status
111-
row.ExpirationTime = time.Unix(int64(eip.ExpireTime), 0).Format("2006-01-02")
112-
list = append(list, row)
113-
}
114114
base.PrintTableS(list)
115115
}
116116
},
@@ -368,14 +368,15 @@ func NewCmdEIPRelease() *cobra.Command {
368368
return cmd
369369
}
370370

371-
//NewCmdEIPModifyBandwidth ucloud eip modify-bandwidth
371+
//NewCmdEIPModifyBandwidth ucloud eip modify-bw
372372
func NewCmdEIPModifyBandwidth() *cobra.Command {
373373
ids := []string{}
374374
req := base.BizClient.NewModifyEIPBandwidthRequest()
375375
cmd := &cobra.Command{
376-
Use: "modify-bandwidth",
377-
Short: "Modify bandwith of EIP instances",
378-
Long: "Modify bandwith of EIP instances",
376+
Use: "modify-bw",
377+
Short: "Modify bandwith of EIP instances",
378+
Long: "Modify bandwith of EIP instances",
379+
Example: "ucloud eip modify-bw --eip-id eip-xxx --bandwidth-mb 20",
379380
Run: func(cmd *cobra.Command, args []string) {
380381
for _, id := range ids {
381382
id = base.PickResourceID(id)
@@ -407,9 +408,10 @@ func NewCmdEIPSetChargeMode() *cobra.Command {
407408
ids := []string{}
408409
req := base.BizClient.NewSetEIPPayModeRequest()
409410
cmd := &cobra.Command{
410-
Use: "modify-charge-mode",
411-
Short: "Modify charge mode of EIP instances",
412-
Long: "Modify charge mode of EIP instances",
411+
Use: "modify-charge-mode",
412+
Short: "Modify charge mode of EIP instances",
413+
Long: "Modify charge mode of EIP instances",
414+
Example: "ucloud eip modify-charge-mode --eip-id eip-xxx --charge-mode Traffic",
413415
Run: func(cmd *cobra.Command, args []string) {
414416
for _, id := range ids {
415417
id = base.PickResourceID(id)
@@ -424,7 +426,7 @@ func NewCmdEIPSetChargeMode() *cobra.Command {
424426
if err != nil {
425427
base.HandleError(err)
426428
} else {
427-
base.Cxt.Printf("eip[%s]'s charge mode modified to %s\n", id, *req.PayMode)
429+
base.Cxt.Printf("eip[%s]'s charge mode was modified to %s\n", id, *req.PayMode)
428430
}
429431
}
430432
},
@@ -449,9 +451,10 @@ func NewCmdEIPJoinSharedBW() *cobra.Command {
449451
eipIDs := []string{}
450452
req := base.BizClient.NewAssociateEIPWithShareBandwidthRequest()
451453
cmd := &cobra.Command{
452-
Use: "join-shared-bw",
453-
Short: "Join shared bandwidth",
454-
Long: "Join shared bandwidth",
454+
Use: "join-shared-bw",
455+
Short: "Join shared bandwidth",
456+
Long: "Join shared bandwidth",
457+
Example: "ucloud eip join-shared-bw --eip-id eip-xxx --shared-bw-id bwshare-xxx",
455458
Run: func(c *cobra.Command, args []string) {
456459
for _, eip := range eipIDs {
457460
req.EIPIds = append(req.EIPIds, base.PickResourceID(eip))
@@ -489,9 +492,10 @@ func NewCmdEIPLeaveSharedBW() *cobra.Command {
489492
eipIDs := []string{}
490493
req := base.BizClient.NewDisassociateEIPWithShareBandwidthRequest()
491494
cmd := &cobra.Command{
492-
Use: "leave-shared-bw",
493-
Short: "Leave shared bandwidth",
494-
Long: "Leave shared bandwidth",
495+
Use: "leave-shared-bw",
496+
Short: "Leave shared bandwidth",
497+
Long: "Leave shared bandwidth",
498+
Example: "ucloud eip leave-shared-bw --eip-id eip-b2gvu3",
495499
Run: func(c *cobra.Command, args []string) {
496500
if *req.ShareBandwidthId == "" {
497501
for _, eipID := range eipIDs {

cmd/firewall.go

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -290,12 +290,16 @@ func NewCmdFirewallDeleteRule(out io.Writer) *cobra.Command {
290290
for r := range ruleMap {
291291
req.Rule = append(req.Rule, r)
292292
}
293+
if len(req.Rule) == 0 {
294+
fmt.Fprintf(out, "Error: rules can't be all deleted\n")
295+
return
296+
}
293297
_, err = base.BizClient.UpdateFirewall(req)
294298
if err != nil {
295299
base.HandleError(err)
296300
return
297301
}
298-
base.Cxt.Printf("firewall[%s] updated\n", fwID)
302+
fmt.Fprintf(out, "firewall[%s] updated\n", fwID)
299303
}
300304
},
301305
}
@@ -322,9 +326,10 @@ func NewCmdFirewallApply() *cobra.Command {
322326
resourceIDs := []string{}
323327
fwID := ""
324328
cmd := &cobra.Command{
325-
Use: "apply",
326-
Short: "Applay firewall to ucloud service",
327-
Long: "Applay firewall to ucloud service",
329+
Use: "apply",
330+
Short: "Applay firewall to ucloud service",
331+
Long: "Applay firewall to ucloud service",
332+
Example: "ucloud firewall apply --fw-id firewall-xxx --resource-id uhost-xxx --resource-type uhost",
328333
Run: func(c *cobra.Command, args []string) {
329334
req.FWId = sdk.String(base.PickResourceID(fwID))
330335
for _, id := range resourceIDs {
@@ -365,9 +370,10 @@ func NewCmdFirewallCopy() *cobra.Command {
365370
srcRegion := ""
366371
req := base.BizClient.NewCreateFirewallRequest()
367372
cmd := &cobra.Command{
368-
Use: "copy",
369-
Short: "Copy firewall",
370-
Long: "Copy firewall",
373+
Use: "copy",
374+
Short: "Copy firewall",
375+
Long: "Copy firewall",
376+
Example: "ucloud firewall copy --src-fw firewall-xxx --target-region cn-bj2 --name test",
371377
Run: func(c *cobra.Command, args []string) {
372378
fwID := base.PickResourceID(srcFirewall)
373379
firewall, err := getFirewall(fwID, *req.ProjectId, srcRegion)
@@ -415,9 +421,10 @@ func NewCmdFirewallDelete() *cobra.Command {
415421
req := base.BizClient.NewDeleteFirewallRequest()
416422
ids := []string{}
417423
cmd := &cobra.Command{
418-
Use: "delete",
419-
Short: "Delete firewall by resource ids or names",
420-
Long: "Delete firewall by resource ids or names",
424+
Use: "delete",
425+
Short: "Delete firewall by resource ids or names",
426+
Long: "Delete firewall by resource ids or names",
427+
Example: "ucloud firewall delete --fw-id firewall-xxx",
421428
Run: func(c *cobra.Command, args []string) {
422429
for _, id := range ids {
423430
req.FWId = sdk.String(base.PickResourceID(id))
@@ -519,6 +526,15 @@ func NewCmdFirewallUpdate(out io.Writer) *cobra.Command {
519526
fmt.Fprintln(out, "Error: name, group and remark can't be all empty")
520527
return
521528
}
529+
if *req.Name == "" {
530+
req.Name = nil
531+
}
532+
if *req.Tag == "" {
533+
req.Tag = nil
534+
}
535+
if *req.Remark == "" {
536+
req.Remark = nil
537+
}
522538
for _, id := range fwIDs {
523539
req.FWId = sdk.String(base.PickResourceID(id))
524540
_, err := base.BizClient.UpdateFirewallAttribute(req)

cmd/share_bw.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ func NewCmdSharedBWCreate() *cobra.Command {
6969
req.ChargeType = flags.String("charge-type", "Month", "Optional.'Year',pay yearly;'Month',pay monthly;'Dynamic', pay hourly")
7070
req.Quantity = flags.Int("quantity", 1, "Optional. The duration of the instance. N years/months.")
7171
flags.SetFlagValues("charge-type", "Month", "Year", "Dynamic")
72+
7273
cmd.MarkFlagRequired("name")
74+
7375
return cmd
7476
}
7577

@@ -125,9 +127,10 @@ func NewCmdSharedBWList() *cobra.Command {
125127
}
126128
flags := cmd.Flags()
127129
flags.SortFlags = false
130+
128131
req.Region = flags.String("region", base.ConfigInstance.Region, "Optional. Region, see 'ucloud region'")
129132
req.ProjectId = flags.String("project-id", base.ConfigInstance.ProjectID, "Optional. Project-id, see 'ucloud project list'")
130-
flags.StringSliceVar(&req.ShareBandwidthIds, "resource-id", nil, "Resource ID of shared bandwidth instances to list")
133+
flags.StringSliceVar(&req.ShareBandwidthIds, "shared-bw-id", nil, "Resource ID of shared bandwidth instances to list")
131134

132135
return cmd
133136
}
@@ -153,16 +156,23 @@ func NewCmdSharedBWResize() *cobra.Command {
153156
base.Cxt.Printf("shared bandwidth[%s] resized to %dMb\n", *req.ShareBandwidthId, *req.ShareBandwidth)
154157
},
155158
}
159+
156160
flags := cmd.Flags()
157161
flags.SortFlags = false
158-
req.ShareBandwidthId = flags.String("resource-id", "", "Required. Resource ID of shared bandwidth instance to resize")
162+
163+
req.ShareBandwidthId = flags.String("shared-bw-id", "", "Required. Resource ID of shared bandwidth instance to resize")
159164
req.ShareBandwidth = flags.Int("bandwidth-mb", 0, "Required. Unit:Mb. resize to bandwidth value")
160165
req.Region = flags.String("region", base.ConfigInstance.Region, "Optional. Region, see 'ucloud region'")
161166
req.ProjectId = flags.String("project-id", base.ConfigInstance.ProjectID, "Optional. Project-id, see 'ucloud project list'")
162-
flags.SetFlagValuesFunc("resource-id", func() []string {
167+
168+
flags.SetFlagValuesFunc("shared-bw-id", func() []string {
163169
list, _ := getAllSharedBW(*req.ProjectId, *req.Region)
164170
return list
165171
})
172+
173+
cmd.MarkFlagRequired("shared-bw-id")
174+
cmd.MarkFlagRequired("bandwidth-mb")
175+
166176
return cmd
167177
}
168178

@@ -188,17 +198,19 @@ func NewCmdSharedBWDelete() *cobra.Command {
188198
}
189199
flags := cmd.Flags()
190200
flags.SortFlags = false
191-
flags.StringSliceVar(&ids, "resource-id", nil, "Required. Resource ID of shared bandwidth instances to delete")
201+
202+
flags.StringSliceVar(&ids, "shared-bw-id", nil, "Required. Resource ID of shared bandwidth instances to delete")
192203
req.EIPBandwidth = flags.Int("eip-bandwidth-mb", 1, "Optional. Bandwidth of the joined EIPs,after deleting the shared bandwidth instance")
193204
req.PayMode = flags.String("charge-mode", "", "Optional. Charge mode of joined EIPs,after deleting the shared bandwidth")
194205
req.Region = flags.String("region", base.ConfigInstance.Region, "Optional. Region, see 'ucloud region'")
195206
req.ProjectId = flags.String("project-id", base.ConfigInstance.ProjectID, "Optional. Project-id, see 'ucloud project list'")
196-
flags.SetFlagValuesFunc("resource-id", func() []string {
207+
flags.SetFlagValuesFunc("shared-bw-id", func() []string {
197208
list, _ := getAllSharedBW(*req.ProjectId, *req.Region)
198209
return list
199210
})
200211
flags.SetFlagValues("charge-mode", "Bandwidth", "Traffic")
201-
cmd.MarkFlagRequired("resource-id")
212+
213+
cmd.MarkFlagRequired("shared-bw-id")
202214

203215
return cmd
204216
}

cmd/unet.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@ import (
2020
"strconv"
2121
"time"
2222

23-
"github.com/ucloud/ucloud-sdk-go/services/udpn"
24-
2523
"github.com/spf13/cobra"
2624

25+
"github.com/ucloud/ucloud-sdk-go/services/udpn"
2726
sdk "github.com/ucloud/ucloud-sdk-go/ucloud"
2827

2928
"github.com/ucloud/ucloud-cli/base"
@@ -167,9 +166,10 @@ func NewCmdBandwidthPkgDelete() *cobra.Command {
167166
ids := []string{}
168167
req := base.BizClient.NewDeleteBandwidthPackageRequest()
169168
cmd := &cobra.Command{
170-
Use: "delete",
171-
Short: "Delete bandwidth packages",
172-
Long: "Delete bandwidth packages",
169+
Use: "delete",
170+
Short: "Delete bandwidth packages",
171+
Long: "Delete bandwidth packages",
172+
Example: "ucloud bw-pkg delete --resource-id bwpack-xxx",
173173
Run: func(c *cobra.Command, args []string) {
174174
for _, id := range ids {
175175
id := base.PickResourceID(id)

0 commit comments

Comments
 (0)