@@ -65,38 +65,34 @@ func NewCmdEIPList() *cobra.Command {
6565 Run : func (cmd * cobra.Command , args []string ) {
6666 resp , err := BizClient .DescribeEIP (req )
6767 if err != nil {
68- Cxt . PrintErr (err )
68+ HandleError (err )
6969 } else {
70- if resp .RetCode == 0 {
71- if global .json {
72- PrintJSON (resp .EIPSet )
73- } else {
74- list := make ([]EIPRow , 0 )
75- for _ , eip := range resp .EIPSet {
76- row := EIPRow {}
77- row .Name = eip .Name
78- for _ , ip := range eip .EIPAddr {
79- row .IP += ip .IP + " " + ip .OperatorName + " "
80- }
81- row .ResourceID = eip .EIPId
82- row .UGroup = eip .Tag
83- row .Billing = eip .PayMode
84- row .Bandwidth = strconv .Itoa (eip .Bandwidth ) + "Mb"
85- row .BindResource = fmt .Sprintf ("%s(%s)" , eip .Resource .ResourceName , eip .Resource .ResourceType )
86- row .Status = eip .Status
87- row .ExpirationTime = time .Unix (int64 (eip .ExpireTime ), 0 ).Format ("2006-01-02" )
88- list = append (list , row )
70+ if global .json {
71+ PrintJSON (resp .EIPSet )
72+ } else {
73+ list := make ([]EIPRow , 0 )
74+ for _ , eip := range resp .EIPSet {
75+ row := EIPRow {}
76+ row .Name = eip .Name
77+ for _ , ip := range eip .EIPAddr {
78+ row .IP += ip .IP + " " + ip .OperatorName + " "
8979 }
90- PrintTable (list , []string {"Name" , "IP" , "ResourceID" , "UGroup" , "Billing" , "Bandwidth" , "BindResource" , "Status" , "ExpirationTime" })
80+ row .ResourceID = eip .EIPId
81+ row .UGroup = eip .Tag
82+ row .Billing = eip .PayMode
83+ row .Bandwidth = strconv .Itoa (eip .Bandwidth ) + "Mb"
84+ row .BindResource = fmt .Sprintf ("%s(%s)" , eip .Resource .ResourceName , eip .Resource .ResourceType )
85+ row .Status = eip .Status
86+ row .ExpirationTime = time .Unix (int64 (eip .ExpireTime ), 0 ).Format ("2006-01-02" )
87+ list = append (list , row )
9188 }
92- } else {
93- HandleBizError (resp )
89+ PrintTable (list , []string {"Name" , "IP" , "ResourceID" , "UGroup" , "Billing" , "Bandwidth" , "BindResource" , "Status" , "ExpirationTime" })
9490 }
9591 }
9692 },
9793 }
98- req .Region = cmd .Flags ().String ("region " , ConfigInstance .Region , "Assign region(override default region of your config) " )
99- req .ProjectId = cmd .Flags ().String ("project-id " , ConfigInstance .ProjectID , "Assign project-id(override default projec-id of your config) " )
94+ req .ProjectId = cmd .Flags ().String ("project-id " , ConfigInstance .ProjectID , "Assign project-id " )
95+ req .Region = cmd .Flags ().String ("region " , ConfigInstance .Region , "Assign region " )
10096 return cmd
10197}
10298
@@ -111,24 +107,20 @@ func NewCmdEIPAllocate() *cobra.Command {
111107 Run : func (cmd * cobra.Command , args []string ) {
112108 resp , err := BizClient .AllocateEIP (req )
113109 if err != nil {
114- Cxt . PrintErr (err )
110+ HandleError (err )
115111 } else {
116- if resp .RetCode == 0 {
117- for _ , eip := range resp .EIPSet {
118- Cxt .Printf ("EIPId:%s," , eip .EIPId )
119- for _ , ip := range eip .EIPAddr {
120- Cxt .Printf ("IP:%s,Line:%s \n " , ip .IP , ip .OperatorName )
121- }
112+ for _ , eip := range resp .EIPSet {
113+ Cxt .Printf ("EIPId:%s," , eip .EIPId )
114+ for _ , ip := range eip .EIPAddr {
115+ Cxt .Printf ("IP:%s,Line:%s \n " , ip .IP , ip .OperatorName )
122116 }
123- } else {
124- HandleBizError (resp )
125117 }
126118 }
127119 },
128120 }
129121 cmd .Flags ().SortFlags = false
130- req .Region = cmd .Flags ().String ("region " , ConfigInstance .Region , "Assign region(override default region of your config) " )
131- req .ProjectId = cmd .Flags ().String ("project-id " , ConfigInstance .ProjectID , "Assign project-id(override default projec-id of your config) " )
122+ req .ProjectId = cmd .Flags ().String ("project-id " , ConfigInstance .ProjectID , "Assign project-id " )
123+ req .Region = cmd .Flags ().String ("region " , ConfigInstance .Region , "Assign region " )
132124 req .OperatorName = cmd .Flags ().String ("line" , "" , "Line 'Bgp' or 'International'. 'Bgp' can be set in region cn-sh1,cn-sh2,cn-gd,cn-bj1 and cn-bj2. 'International' can be set in region hk,us-ca,th-bkk,kr-seoul,us-ws,ge-fra,sg,tw-kh and other oversea regions. Required" )
133125 req .Bandwidth = cmd .Flags ().Int ("bandwidth" , 0 , "Bandwidth(Unit:Mbps). When paying by traffic, it ranges from 1 to 200; when paying by bandwidth, it ranges from 1 to 800, and when shared bandwidth is used, its value is 0. Required" )
134126 req .PayMode = cmd .Flags ().String ("pay-mode" , "Bandwidth" , "pay-mode is an enumeration value. 'Traffic','Bandwidth' or 'ShareBandwidth'" )
@@ -153,21 +145,17 @@ func NewCmdEIPBind() *cobra.Command {
153145 Example : "ucloud eip bind --eip-id eip-xxx --resource-id uhost-xxx" ,
154146 Run : func (cmd * cobra.Command , args []string ) {
155147 req .ResourceType = sdk .String ("uhost" )
156- resp , err := BizClient .BindEIP (req )
148+ _ , err := BizClient .BindEIP (req )
157149 if err != nil {
158- Cxt . PrintErr (err )
150+ HandleError (err )
159151 } else {
160- if resp .RetCode == 0 {
161- fmt .Printf ("EIP: %s bind with %s:%s successfully \n " , * req .EIPId , * req .ResourceType , * req .ResourceId )
162- } else {
163- HandleBizError (resp )
164- }
152+ Cxt .Printf ("EIP: %s bind with %s:%s successfully \n " , * req .EIPId , * req .ResourceType , * req .ResourceId )
165153 }
166154 },
167155 }
168156 cmd .Flags ().SortFlags = false
169- req .Region = cmd .Flags ().String ("region " , ConfigInstance .Region , "Assign region(override default region of your config) " )
170- req .ProjectId = cmd .Flags ().String ("project-id " , ConfigInstance .ProjectID , "Assign project-id(override default projec-id of your config) " )
157+ req .ProjectId = cmd .Flags ().String ("project-id " , ConfigInstance .ProjectID , "Assign project-id " )
158+ req .Region = cmd .Flags ().String ("region " , ConfigInstance .Region , "Assign region " )
171159 req .EIPId = cmd .Flags ().String ("eip-id" , "" , "EIPId to bind. Required" )
172160 req .ResourceId = cmd .Flags ().String ("resource-id" , "" , "ResourceID , which is the UHostId of uhost. Required" )
173161 cmd .MarkFlagRequired ("eip-id" )
@@ -186,21 +174,17 @@ func NewCmdEIPUnbind() *cobra.Command {
186174 Example : "ucloud eip unbind --eip-id eip-xxx --resource-id uhost-xxx" ,
187175 Run : func (cmd * cobra.Command , args []string ) {
188176 req .ResourceType = sdk .String ("uhost" )
189- resp , err := BizClient .UnBindEIP (req )
177+ _ , err := BizClient .UnBindEIP (req )
190178 if err != nil {
191- Cxt . PrintErr (err )
179+ HandleError (err )
192180 } else {
193- if resp .RetCode == 0 {
194- Cxt .Printf ("EIP: %s unbind with %s:%s successfully \n " , * req .EIPId , * req .ResourceType , * req .ResourceId )
195- } else {
196- HandleBizError (resp )
197- }
181+ Cxt .Printf ("EIP: %s unbind with %s:%s successfully \n " , * req .EIPId , * req .ResourceType , * req .ResourceId )
198182 }
199183 },
200184 }
201185 cmd .Flags ().SortFlags = false
202- req .Region = cmd .Flags ().String ("region " , ConfigInstance .Region , "Assign region(override default region of your config) " )
203- req .ProjectId = cmd .Flags ().String ("project-id " , ConfigInstance .ProjectID , "Assign project-id(override default projec-id of your config) " )
186+ req .ProjectId = cmd .Flags ().String ("project-id " , ConfigInstance .ProjectID , "Assign project-id " )
187+ req .Region = cmd .Flags ().String ("region " , ConfigInstance .Region , "Assign region " )
204188 req .EIPId = cmd .Flags ().String ("eip-id" , "" , "EIPId to unbind. Required" )
205189 req .ResourceId = cmd .Flags ().String ("resource-id" , "" , "ResourceID , which is the UHostId of uhost. Required" )
206190 cmd .MarkFlagRequired ("eip-id" )
@@ -221,21 +205,17 @@ func NewCmdEIPRelease() *cobra.Command {
221205 Run : func (cmd * cobra.Command , args []string ) {
222206 for _ , id := range ids {
223207 req .EIPId = & id
224- resp , err := BizClient .ReleaseEIP (req )
208+ _ , err := BizClient .ReleaseEIP (req )
225209 if err != nil {
226- Cxt . PrintErr (err )
210+ HandleError (err )
227211 } else {
228- if resp .RetCode == 0 {
229- Cxt .Printf ("EIP: %v released \n " , req .EIPId )
230- } else {
231- HandleBizError (resp )
232- }
212+ Cxt .Printf ("EIP: %v released \n " , req .EIPId )
233213 }
234214 }
235215 },
236216 }
237- req .Region = cmd .Flags ().String ("region " , ConfigInstance .Region , "Assign region(override default region of your config) " )
238- req .ProjectId = cmd .Flags ().String ("project-id " , ConfigInstance .ProjectID , "Assign project-id(override default projec-id of your config) " )
217+ req .ProjectId = cmd .Flags ().String ("project-id " , ConfigInstance .ProjectID , "Assign project-id " )
218+ req .Region = cmd .Flags ().String ("region " , ConfigInstance .Region , "Assign region " )
239219 cmd .Flags ().StringArrayVarP (& ids , "eip-id" , "" , make ([]string , 0 ), "EIPId of the EIP you want to release. Required" )
240220 cmd .MarkFlagRequired ("eip-id" )
241221 cmd .MarkFlagRequired ("bandwidth" )
0 commit comments