Skip to content

Commit 4cc756d

Browse files
author
anasouma
committed
wrap id handling in a helper to avoid index exception
1 parent 14ee912 commit 4cc756d

1 file changed

Lines changed: 17 additions & 4 deletions

File tree

SoftLayer/CLI/modules/firewall.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,19 @@
2424
DELIMITER = "=========================================\n"
2525

2626

27+
def get_ids(input_id):
28+
""" Helper package to retrieve the actual IDs
29+
:param input_id: the ID provided by the user
30+
:returns: A list of valid IDs
31+
"""
32+
key_value = input_id.split(':')
33+
34+
if len(key_value) != 2:
35+
raise CLIAbort('Invalid ID %s: ID should be of the form xxx:yyy'
36+
% input_id)
37+
return key_value
38+
39+
2740
def print_package_info(package):
2841
""" Helper package to print the firewall price.
2942
@@ -270,7 +283,7 @@ class FWCancel(CLIRunnable):
270283
def execute(self, args):
271284
mgr = FirewallManager(self.client)
272285
input_id = args.get('<identifier>')
273-
key_value = input_id.split(':')
286+
key_value = get_ids(input_id)
274287
firewall_id = int(key_value[1])
275288

276289
if args['--really'] or confirm("This action will cancel a firewall"
@@ -340,9 +353,9 @@ class FWDetails(CLIRunnable):
340353

341354
def execute(self, args):
342355
mgr = FirewallManager(self.client)
343-
firewall_id = args.get('<identifier>')
356+
input_id = args.get('<identifier>')
344357

345-
key_value = firewall_id.split(':')
358+
key_value = get_ids(input_id)
346359
if key_value[0] == 'vlan':
347360
rules = mgr.get_dedicated_fwl_rules(key_value[1])
348361
else:
@@ -363,7 +376,7 @@ def execute(self, args):
363376
mgr = FirewallManager(self.client)
364377
input_id = args.get('<identifier>')
365378

366-
key_value = input_id.split(':')
379+
key_value = get_ids(input_id)
367380
firewall_id = int(key_value[1])
368381
if key_value[0] == 'vlan':
369382
orig_rules = mgr.get_dedicated_fwl_rules(firewall_id)

0 commit comments

Comments
 (0)