Skip to content

Commit 5c2793e

Browse files
Merge pull request #2000 from softlayer/issue_1990
slcli bandwidth pools-create with single locations as option #1990
2 parents d873844 + 04db849 commit 5c2793e

File tree

3 files changed

+39
-4
lines changed

3 files changed

+39
-4
lines changed

SoftLayer/CLI/bandwidth/pools_create.py

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,42 @@
2121
"FRA": "FRA"
2222
}
2323

24+
regions = ['SJC/DAL/WDC/TOR/MON', 'AMS/LON/MAD/PAR', 'SNG/HKG/OSA/TOK', 'SYD', 'MEX', 'SAO', 'CHE', 'MIL', 'SEO', 'FRA']
25+
26+
27+
def check_region_param(ctx, param, value): # pylint: disable=unused-argument
28+
"""Check if provided region is region group or part of region"""
29+
30+
# :params string value: Region or Region-Groups
31+
# return string Region-Groups
32+
33+
region_group = None
34+
for key in location_groups:
35+
if value in key or value is key:
36+
region_group = key
37+
38+
if region_group:
39+
return region_group
40+
else:
41+
raise click.BadParameter(f"{value} is not a region or part of any region."
42+
" Available Choices: ['SJC/DAL/WDC/TOR/MON', 'AMS/LON/MAD/PAR',"
43+
" 'SNG/HKG/OSA/TOK', 'SYD', 'MEX', 'SAO', 'CHE', 'MIL', 'SEO', 'FRA']")
44+
2445

2546
@click.command(cls=SLCommand)
2647
@click.option('--name', required=True, help="Pool name")
2748
@click.option('--region', required=True,
28-
type=click.Choice(['SJC/DAL/WDC/TOR/MON', 'AMS/LON/MAD/PAR', 'SNG/HKG/OSA/TOK',
29-
'SYD', 'MEX', 'SAO', 'CHE', 'MIL', 'SEO', 'FRA']),
30-
help="Region selected")
49+
help=f"Choose Region/Region-Group {regions}", callback=check_region_param)
50+
@click.help_option('--help', '-h')
3151
@environment.pass_env
3252
def cli(env, name, region):
33-
"""Create bandwidth pool."""
53+
"""Create bandwidth pool.
54+
55+
Region can be the full zone name 'SJC/DAL/WDC/TOR/MON', or just a single datacenter like 'SJC'.
56+
Example::
57+
slcli bandwidth pool-create --name testPool --region DAL
58+
slcli bandwidth pool-create --name testPool --region SJC/DAL/WDC/TOR/MON
59+
"""
3460

3561
manager = BandwidthManager(env.client)
3662
locations = manager.get_location_group()

slcli

100644100755
File mode changed.

tests/CLI/modules/bandwidth_tests.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,15 @@ def test_delete_bandwidth(self):
6868
json_output = json.loads(result.output)
6969
self.assertEqual("Bandwidth pool 123456 has been scheduled for deletion.", json_output)
7070

71+
def test_create_bandwidth_single_region(self):
72+
result = self.run_command(['bandwidth', 'pools-create', '--name=NewRegion', '--region=AMS'])
73+
self.assert_no_fail(result)
74+
self.assert_called_with('SoftLayer_Network_Bandwidth_Version1_Allotment', 'createObject')
75+
json_output = json.loads(result.output)
76+
self.assertEqual(123456789, json_output['Id'])
77+
self.assertEqual('NewRegion', json_output['Name Pool'])
78+
self.assertEqual('AMS/LON/MAD/PAR', json_output['Region'])
79+
7180

7281
def _bandwidth_advanced_search():
7382
result = [

0 commit comments

Comments
 (0)