1212 group-delete Delete a service group from the load balancer
1313 group-edit Edit the properties of a service group
1414 group-reset Resets all the connections on a service group
15- health-checks List the different health check values
15+ health-check List the different health check values
1616 list List active load balancers
1717 routing-methods List supported routing methods
1818 routing-types List supported routing types
2929from SoftLayer .CLI .helpers import CLIAbort
3030
3131
32+ def get_ids (input_id ):
33+ """ Helper package to retrieve the actual IDs
34+
35+ :param input_id: the ID provided by the user
36+ :returns: A list of valid IDs
37+ """
38+ key_value = input_id .split (':' )
39+ if len (key_value ) != 2 :
40+ raise CLIAbort ('Invalid ID %s: ID should be of the form xxx:yyy'
41+ % input_id )
42+ return key_value
43+
44+
3245def get_local_lbs_table (load_balancers ):
3346 """ Helper package to format the local load balancers into a table.
3447
@@ -42,11 +55,7 @@ def get_local_lbs_table(load_balancers):
4255 'Connections/second' ,
4356 'Type' ])
4457
45- table .align ['VIP Address' ] = 'r'
46- table .align ['Location' ] = 'r'
47- table .align ['Connections/second' ] = 'r'
4858 table .align ['Connections/second' ] = 'r'
49- table .align ['Type' ] = 'r'
5059
5160 for load_balancer in load_balancers :
5261 ssl_support = 'Not Supported'
@@ -113,7 +122,9 @@ def get_local_lb_table(load_balancer):
113122
114123 table3 = Table (['Service_ID' , 'IP Address' , 'Port' ,
115124 'Health Check' , 'Weight' , 'Enabled' , 'Status' ])
125+ service_exist = False
116126 for service in group ['services' ]:
127+ service_exist = True
117128 health_check = service ['healthChecks' ][0 ]
118129 table3 .add_row ([
119130 '%s:%s' % (load_balancer ['id' ], service ['id' ]),
@@ -125,7 +136,10 @@ def get_local_lb_table(load_balancer):
125136 service ['enabled' ],
126137 service ['status' ]
127138 ])
128- table .add_row ([' Services' , table3 ])
139+ if service_exist :
140+ table .add_row ([' Services' , table3 ])
141+ else :
142+ table .add_row ([' Services' , 'None' ])
129143 return table
130144
131145
@@ -147,11 +161,11 @@ def execute(self, args):
147161
148162class LoadBalancerHealthChecks (CLIRunnable ):
149163 """
150- usage: sl loadbal health-check-types [options]
164+ usage: sl loadbal health-checks [options]
151165
152166List load balancer service health check types that can be used
153167"""
154- action = 'health-check-types '
168+ action = 'health-checks '
155169
156170 def execute (self , args ):
157171 mgr = LoadBalancerManager (self .client )
@@ -222,7 +236,7 @@ def execute(self, args):
222236
223237 input_id = args .get ('<identifier>' )
224238
225- key_value = input_id . split ( ':' )
239+ key_value = get_ids ( input_id )
226240 loadbal_id = int (key_value [1 ])
227241
228242 load_balancer = mgr .get_local_lb (loadbal_id )
@@ -234,18 +248,16 @@ class LoadBalancerCancel(CLIRunnable):
234248usage: sl loadbal cancel <identifier> [options]
235249
236250Cancels an existing load_balancer
237- Options:
238- --really Whether to skip the confirmation prompt
239251
240252"""
241253 action = 'cancel'
242- options = ['really ' ]
254+ options = ['confirm ' ]
243255
244256 def execute (self , args ):
245257 mgr = LoadBalancerManager (self .client )
246258 input_id = args .get ('<identifier>' )
247259
248- key_value = input_id . split ( ':' )
260+ key_value = get_ids ( input_id )
249261 loadbal_id = int (key_value [1 ])
250262
251263 if args ['--really' ] or confirm ("This action will cancel a load "
@@ -261,18 +273,16 @@ class LoadBalancerServiceDelete(CLIRunnable):
261273usage: sl loadbal service-delete <identifier> [options]
262274
263275Deletes an existing load_balancer service
264- Options:
265- --really Whether to skip the confirmation prompt
266276
267277"""
268278 action = 'service-delete'
269- options = ['really ' ]
279+ options = ['confirm ' ]
270280
271281 def execute (self , args ):
272282 mgr = LoadBalancerManager (self .client )
273283 input_id = args .get ('<identifier>' )
274284
275- key_value = input_id . split ( ':' )
285+ key_value = get_ids ( input_id )
276286 service_id = int (key_value [1 ])
277287
278288 if args ['--really' ] or confirm ("This action will cancel a service "
@@ -288,18 +298,16 @@ class LoadBalancerServiceToggle(CLIRunnable):
288298usage: sl loadbal service-toggle <identifier> [options]
289299
290300Toggle the status of an existing load_balancer service
291- Options:
292- --really Whether to skip the confirmation prompt
293301
294302"""
295303 action = 'service-toggle'
296- options = ['really ' ]
304+ options = ['confirm ' ]
297305
298306 def execute (self , args ):
299307 mgr = LoadBalancerManager (self .client )
300308 input_id = args .get ('<identifier>' )
301309
302- key_value = input_id . split ( ':' )
310+ key_value = get_ids ( input_id )
303311 service_id = int (key_value [1 ])
304312
305313 if args ['--really' ] or confirm ("This action will toggle the service "
@@ -329,7 +337,7 @@ def execute(self, args):
329337 mgr = LoadBalancerManager (self .client )
330338 input_id = args .get ('<identifier>' )
331339
332- key_value = input_id . split ( ':' )
340+ key_value = get_ids ( input_id )
333341 loadbal_id = int (key_value [0 ])
334342 service_id = int (key_value [1 ])
335343
@@ -339,7 +347,7 @@ def execute(self, args):
339347 return 'At least one property is required to be changed!'
340348
341349 # check if the IP is valid
342- ip_address_id = 0
350+ ip_address_id = None
343351 if args ['--ip' ]:
344352 ip_address = mgr .get_ip_address (args ['--ip' ])
345353 if not ip_address :
@@ -350,10 +358,10 @@ def execute(self, args):
350358 mgr .edit_service (loadbal_id ,
351359 service_id ,
352360 ip_address_id = ip_address_id ,
353- enabled = int ( args .get ('--enabled' ) or - 1 ),
354- port = int ( args .get ('--port' ) or - 1 ),
355- weight = int ( args .get ('--weight' ) or - 1 ),
356- hc_type = int ( args .get ('--hc_type' ) or - 1 ))
361+ enabled = args .get ('--enabled' ),
362+ port = args .get ('--port' ),
363+ weight = args .get ('--weight' ),
364+ hc_type = args .get ('--hc_type' ))
357365 return 'Load balancer service %s is being modified!' % input_id
358366
359367
@@ -377,7 +385,7 @@ def execute(self, args):
377385 mgr = LoadBalancerManager (self .client )
378386 input_id = args .get ('<identifier>' )
379387
380- key_value = input_id . split ( ':' )
388+ key_value = get_ids ( input_id )
381389 loadbal_id = int (key_value [0 ])
382390 group_id = int (key_value [1 ])
383391
@@ -403,18 +411,16 @@ class LoadBalancerServiceGroupDelete(CLIRunnable):
403411usage: sl loadbal group-delete <identifier> [options]
404412
405413Deletes an existing load_balancer service group
406- Options:
407- --really Whether to skip the confirmation prompt
408414
409415"""
410416 action = 'group-delete'
411- options = ['really ' ]
417+ options = ['confirm ' ]
412418
413419 def execute (self , args ):
414420 mgr = LoadBalancerManager (self .client )
415421 input_id = args .get ('<identifier>' )
416422
417- key_value = input_id . split ( ':' )
423+ key_value = get_ids ( input_id )
418424 group_id = int (key_value [1 ])
419425
420426 if args ['--really' ] or confirm ("This action will cancel a service"
@@ -431,7 +437,7 @@ class LoadBalancerServiceGroupEdit(CLIRunnable):
431437
432438Edits an existing load_balancer service group
433439Options:
434- --allocation=ALLOC Change the allocated % of connections
440+ --allocation=PERC Change the allocated % of connections
435441--port=PORT Change the port
436442--routing_type=TYPE Change the port routing type
437443--routing_method=METHOD Change the routing method
@@ -443,7 +449,7 @@ def execute(self, args):
443449 mgr = LoadBalancerManager (self .client )
444450 input_id = args .get ('<identifier>' )
445451
446- key_value = input_id . split ( ':' )
452+ key_value = get_ids ( input_id )
447453 loadbal_id = int (key_value [0 ])
448454 group_id = int (key_value [1 ])
449455
@@ -457,10 +463,10 @@ def execute(self, args):
457463
458464 mgr .edit_service_group (loadbal_id ,
459465 group_id ,
460- allocation = int ( args .get ('--allocation' ) or - 1 ),
461- port = int ( args .get ('--port' ) or 0 ),
462- routing_type = int ( routing_type or 0 ) ,
463- routing_method = int ( routing_method or 0 ) )
466+ allocation = args .get ('--allocation' ),
467+ port = args .get ('--port' ),
468+ routing_type = routing_type ,
469+ routing_method = routing_method )
464470
465471 return 'Load balancer service group %s is being updated!' % input_id
466472
@@ -478,7 +484,7 @@ def execute(self, args):
478484 mgr = LoadBalancerManager (self .client )
479485 input_id = args .get ('<identifier>' )
480486
481- key_value = input_id . split ( ':' )
487+ key_value = get_ids ( input_id )
482488 loadbal_id = int (key_value [0 ])
483489 group_id = int (key_value [1 ])
484490
@@ -488,12 +494,12 @@ def execute(self, args):
488494
489495class LoadBalancerServiceGroupAdd (CLIRunnable ):
490496 """
491- usage: sl loadbal group-add <identifier> --allocation=ALLOC --port=PORT \
497+ usage: sl loadbal group-add <identifier> --allocation=PERC --port=PORT \
492498 --routing_type=TYPE --routing_method=METHOD [options]
493499
494500Adds a new load_balancer service
495501Required:
496- --allocation=ALLOC The % of connections that will be allocated
502+ --allocation=PERC The % of connections that will be allocated
497503--port=PORT The virtual port number for the group
498504--routing_type=TYPE The routing type for the group
499505--routing_method=METHOD The routing method for the group
@@ -504,7 +510,7 @@ class LoadBalancerServiceGroupAdd(CLIRunnable):
504510 def execute (self , args ):
505511 mgr = LoadBalancerManager (self .client )
506512 input_id = args .get ('<identifier>' )
507- key_value = input_id . split ( ':' )
513+ key_value = get_ids ( input_id )
508514
509515 loadbal_id = int (key_value [1 ])
510516
@@ -527,10 +533,9 @@ class LoadBalancerCreate(CLIRunnable):
527533 -d, --datacenter=DC Datacenter shortname (sng01, dal05, ...)
528534 Note: Omitting this value defaults to the first
529535 available datacenter
530- --really Whether to skip the confirmation prompt
531536"""
532537 action = 'create'
533- options = ['really ' ]
538+ options = ['confirm ' ]
534539
535540 def execute (self , args ):
536541 mgr = LoadBalancerManager (self .client )
0 commit comments