Skip to content

Commit ee1d940

Browse files
committed
issue#1210 - Correcting formatting and adding input check.
1 parent 7818cb4 commit ee1d940

File tree

5 files changed

+70
-46
lines changed

5 files changed

+70
-46
lines changed

SoftLayer/CLI/block/subnets/assign.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,31 @@
77

88

99
@click.command()
10-
@click.argument('access_id')
10+
@click.argument('access_id', type=int)
1111
@click.option('--subnet-id', multiple=True, type=int,
1212
help="ID of the subnets to assign; e.g.: --subnet-id 1234")
1313
@environment.pass_env
1414
def cli(env, access_id, subnet_id):
1515
"""Assign block storage subnets to the given host id.
1616
17-
access_id is the allowed_host_id from slcli block access-list
17+
access_id is the host_id obtained by: slcli block access-list <volume_id>
1818
"""
19-
subnets_id = list(subnet_id)
20-
block_manager = SoftLayer.BlockStorageManager(env.client)
21-
assigned_subnets = block_manager.assign_subnets_to_acl(access_id,
22-
subnets_id)
19+
try:
20+
subnet_ids = list(subnet_id)
21+
block_manager = SoftLayer.BlockStorageManager(env.client)
22+
assigned_subnets = block_manager.assign_subnets_to_acl(access_id, subnet_ids)
2323

24-
for subnet in assigned_subnets:
25-
click.echo("Successfully assigned subnet id: " + str(subnet) +
26-
' to allowed host id: ' + str(access_id) + '.')
24+
for subnet in assigned_subnets:
25+
message = "{0}".format("Successfully assigned subnet id: " + str(subnet) +
26+
' to allowed host id: ' + str(access_id) + '.')
27+
click.echo(message)
2728

28-
failed_to_assign_subnets = list(set(subnets_id) - set(assigned_subnets))
29-
for subnet in failed_to_assign_subnets:
30-
click.echo("Failed to assign subnet id: " + str(subnet) +
31-
' to allowed host id: ' + str(access_id) + '.')
29+
failed_to_assign_subnets = list(set(subnet_ids) - set(assigned_subnets))
30+
for subnet in failed_to_assign_subnets:
31+
message = "{0}".format("Failed to assign subnet id: " + str(subnet) +
32+
' to allowed host id: ' + str(access_id) + '.')
33+
click.echo(message)
34+
35+
except SoftLayer.SoftLayerAPIError as ex:
36+
message = "{0}".format("Unable to assign subnets.\nReason: " + ex.faultString)
37+
click.echo(message)

SoftLayer/CLI/block/subnets/list.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,29 @@
1616

1717

1818
@click.command()
19-
@click.argument('access_id')
19+
@click.argument('access_id', type=int)
2020
@environment.pass_env
2121
def cli(env, access_id):
2222
"""List block storage assigned subnets for the given host id.
2323
24-
access_id is the allowed_host_id from slcli block access-list
24+
access_id is the host_id obtained by: slcli block access-list <volume_id>
2525
"""
2626

27-
block_manager = SoftLayer.BlockStorageManager(env.client)
28-
subnets = block_manager.get_subnets_in_acl(access_id)
27+
try:
28+
block_manager = SoftLayer.BlockStorageManager(env.client)
29+
subnets = block_manager.get_subnets_in_acl(access_id)
2930

30-
table = formatting.Table(COLUMNS)
31-
for subnet in subnets:
32-
row = ["{0}".format(subnet['id']),
33-
"{0}".format(subnet['createDate']),
34-
"{0}".format(subnet['networkIdentifier']),
35-
"{0}".format(subnet['cidr'])]
36-
table.add_row(row)
31+
table = formatting.Table(COLUMNS)
32+
for subnet in subnets:
33+
row = ["{0}".format(subnet['id']),
34+
"{0}".format(subnet['createDate']),
35+
"{0}".format(subnet['networkIdentifier']),
36+
"{0}".format(subnet['cidr'])]
37+
table.add_row(row)
3738

38-
env.fout(table)
39+
env.fout(table)
40+
41+
except SoftLayer.SoftLayerAPIError as ex:
42+
message = "{0}".format("Unable to list assigned subnets for access-id: " +
43+
str(access_id) + ".\nReason: " + ex.faultString)
44+
click.echo(message)

SoftLayer/CLI/block/subnets/remove.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,31 @@
77

88

99
@click.command()
10-
@click.argument('access_id')
10+
@click.argument('access_id', type=int)
1111
@click.option('--subnet-id', multiple=True, type=int,
1212
help="ID of the subnets to remove; e.g.: --subnet-id 1234")
1313
@environment.pass_env
1414
def cli(env, access_id, subnet_id):
1515
"""Remove block storage subnets for the given host id.
1616
17-
access_id is the allowed_host_id from slcli block access-list
17+
access_id is the host_id obtained by: slcli block access-list <volume_id>
1818
"""
19-
subnets_id = list(subnet_id)
20-
block_manager = SoftLayer.BlockStorageManager(env.client)
21-
removed_subnets = block_manager.remove_subnets_from_acl(access_id,
22-
subnets_id)
19+
try:
20+
subnet_ids = list(subnet_id)
21+
block_manager = SoftLayer.BlockStorageManager(env.client)
22+
removed_subnets = block_manager.remove_subnets_from_acl(access_id, subnet_ids)
2323

24-
for subnet in removed_subnets:
25-
click.echo("Successfully removed subnet id: " + str(subnet) +
26-
' to allowed host id: ' + str(access_id) + '.')
24+
for subnet in removed_subnets:
25+
message = "{0}".format("Successfully removed subnet id: " + str(subnet) +
26+
' for allowed host id: ' + str(access_id) + '.')
27+
click.echo(message)
2728

28-
failed_to_remove_subnets = list(set(subnets_id) - set(removed_subnets))
29-
for subnet in failed_to_remove_subnets:
30-
click.echo("Failed to remove subnet id: " + str(subnet) +
31-
' to allowed host id: ' + str(access_id) + '.')
29+
failed_to_remove_subnets = list(set(subnet_ids) - set(removed_subnets))
30+
for subnet in failed_to_remove_subnets:
31+
message = "{0}".format("Failed to remove subnet id: " + str(subnet) +
32+
' for allowed host id: ' + str(access_id) + '.')
33+
click.echo(message)
34+
35+
except SoftLayer.SoftLayerAPIError as ex:
36+
message = "{0}".format("Unable to remove subnets.\nReason: " + ex.faultString)
37+
click.echo(message)

SoftLayer/managers/block.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,33 +201,39 @@ def deauthorize_host_to_volume(self, volume_id,
201201
return self.client.call('Network_Storage', 'removeAccessFromHostList',
202202
host_templates, id=volume_id, **kwargs)
203203

204-
def assign_subnets_to_acl(self, access_id, subnets_id):
204+
def assign_subnets_to_acl(self, access_id, subnet_ids):
205205
"""Assigns subnet records to ACL for the access host.
206206
207+
access_id is the host_id obtained by: slcli block access-list <volume_id>
208+
207209
:param integer access_id: id of the access host
208-
:param integer subnets_id: The ids of the subnets to be assigned
210+
:param list subnet_ids: The ids of the subnets to be assigned
209211
:return: Returns int array of assigned subnet ids
210212
"""
211213
return self.client.call('Network_Storage_Allowed_Host',
212214
'assignSubnetsToAcl',
213-
subnets_id,
215+
subnet_ids,
214216
id=access_id)
215217

216-
def remove_subnets_from_acl(self, access_id, subnets_id):
218+
def remove_subnets_from_acl(self, access_id, subnet_ids):
217219
"""Removes subnet records from ACL for the access host.
218220
221+
access_id is the host_id obtained by: slcli block access-list <volume_id>
222+
219223
:param integer access_id: id of the access host
220-
:param integer subnets_id: The ids of the subnets to be removed
224+
:param list subnet_ids: The ids of the subnets to be removed
221225
:return: Returns int array of removed subnet ids
222226
"""
223227
return self.client.call('Network_Storage_Allowed_Host',
224228
'removeSubnetsFromAcl',
225-
subnets_id,
229+
subnet_ids,
226230
id=access_id)
227231

228232
def get_subnets_in_acl(self, access_id):
229233
"""Returns a list of subnet records for the access host.
230234
235+
access_id is the host_id obtained by: slcli block access-list <volume_id>
236+
231237
:param integer access_id: id of the access host
232238
:return: Returns an array of SoftLayer_Network_Subnet objects
233239
"""

tests/managers/block_tests.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ def test_deauthorize_host_to_volume(self):
489489
def test_assign_subnets_to_acl(self):
490490
result = self.block.assign_subnets_to_acl(
491491
12345,
492-
subnets_id=[12345678])
492+
subnet_ids=[12345678])
493493

494494
self.assertEqual(fixtures.SoftLayer_Network_Storage_Allowed_Host.
495495
assignSubnetsToAcl, result)
@@ -502,7 +502,7 @@ def test_assign_subnets_to_acl(self):
502502
def test_remove_subnets_from_acl(self):
503503
result = self.block.remove_subnets_from_acl(
504504
12345,
505-
subnets_id=[12345678])
505+
subnet_ids=[12345678])
506506

507507
self.assertEqual(fixtures.SoftLayer_Network_Storage_Allowed_Host.
508508
removeSubnetsFromAcl, result)

0 commit comments

Comments
 (0)