From 6f821872878cc866cb35df6793a10c145167fb6e Mon Sep 17 00:00:00 2001 From: caberos Date: Fri, 19 Jun 2020 20:08:04 -0400 Subject: [PATCH 1/7] new feature edit ip note and add ipAddress table in detail --- SoftLayer/CLI/routes.py | 1 + SoftLayer/CLI/subnet/detail.py | 13 ++++++++- SoftLayer/CLI/subnet/edit_ip.py | 27 +++++++++++++++++++ .../fixtures/SoftLayer_Network_Subnet.py | 7 ++++- .../SoftLayer_Network_Subnet_IpAddress.py | 2 ++ SoftLayer/managers/network.py | 5 ++++ tests/CLI/modules/subnet_tests.py | 8 ++++++ 7 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 SoftLayer/CLI/subnet/edit_ip.py diff --git a/SoftLayer/CLI/routes.py b/SoftLayer/CLI/routes.py index cc67a7d2f..fe492d46e 100644 --- a/SoftLayer/CLI/routes.py +++ b/SoftLayer/CLI/routes.py @@ -289,6 +289,7 @@ ('subnet:detail', 'SoftLayer.CLI.subnet.detail:cli'), ('subnet:list', 'SoftLayer.CLI.subnet.list:cli'), ('subnet:lookup', 'SoftLayer.CLI.subnet.lookup:cli'), + ('subnet:edit-ip', 'SoftLayer.CLI.subnet.edit_ip:cli'), ('tags', 'SoftLayer.CLI.tags'), ('tags:cleanup', 'SoftLayer.CLI.tags.cleanup:cli'), diff --git a/SoftLayer/CLI/subnet/detail.py b/SoftLayer/CLI/subnet/detail.py index 1c8f7e2dc..39dbb700d 100644 --- a/SoftLayer/CLI/subnet/detail.py +++ b/SoftLayer/CLI/subnet/detail.py @@ -25,7 +25,10 @@ def cli(env, identifier, no_vs, no_hardware): mgr = SoftLayer.NetworkManager(env.client) subnet_id = helpers.resolve_id(mgr.resolve_subnet_ids, identifier, name='subnet') - subnet = mgr.get_subnet(subnet_id) + + mask = 'mask[ipAddresses[id, ipAddress], datacenter, virtualGuests,hardware]' + + subnet = mgr.get_subnet(subnet_id, mask=mask) table = formatting.KeyValueTable(['name', 'value']) table.align['name'] = 'r' @@ -45,6 +48,14 @@ def cli(env, identifier, no_vs, no_hardware): table.add_row(['usable ips', subnet.get('usableIpAddressCount', formatting.blank())]) + ip_address = subnet.get('ipAddresses') + + ip_table = formatting.KeyValueTable(['ipAddress','value']) + for address in ip_address: + ip_table.add_row([address.get('id'),address.get('ipAddress')]) + + table.add_row(['ipAddresses', ip_table]) + if not no_vs: if subnet['virtualGuests']: vs_table = formatting.Table(['hostname', 'domain', 'public_ip', 'private_ip']) diff --git a/SoftLayer/CLI/subnet/edit_ip.py b/SoftLayer/CLI/subnet/edit_ip.py new file mode 100644 index 000000000..00077ad2c --- /dev/null +++ b/SoftLayer/CLI/subnet/edit_ip.py @@ -0,0 +1,27 @@ +"""Edit ip note""" +# :license: MIT, see LICENSE for more details. + +import click + +import SoftLayer +from SoftLayer.CLI import environment + + +@click.command() +@click.argument('identifier') +@click.option('--ip', required=True, + help='Assume the ipAddress to set the note.') +@click.option('--note', help="set ip address note of subnet") +@environment.pass_env +def cli(env, identifier, ip, note): + """Set the note of the ipAddress subnet""" + + data = { + 'note': note + } + mgr = SoftLayer.NetworkManager(env.client) + ips = mgr.get_subnet(identifier, mask='id,ipAddresses[id,ipAddress]').get('ipAddresses') + + for address in ips: + if ip == address.get('ipAddress'): + mgr.set_subnet_ipddress_note(address.get('id'), data) diff --git a/SoftLayer/fixtures/SoftLayer_Network_Subnet.py b/SoftLayer/fixtures/SoftLayer_Network_Subnet.py index 7fc1e34dd..c6658165a 100644 --- a/SoftLayer/fixtures/SoftLayer_Network_Subnet.py +++ b/SoftLayer/fixtures/SoftLayer_Network_Subnet.py @@ -25,5 +25,10 @@ } ], 'hardware': [], - 'usableIpAddressCount': 22 + 'usableIpAddressCount': 22, + 'ipAddresses': [ + {'id': 123456, + 'ipAddress': '16.26.26.25'}, + {'id': 123457, + 'ipAddress': '16.26.26.26'}] } diff --git a/SoftLayer/fixtures/SoftLayer_Network_Subnet_IpAddress.py b/SoftLayer/fixtures/SoftLayer_Network_Subnet_IpAddress.py index d7ed9749d..5274ffeda 100644 --- a/SoftLayer/fixtures/SoftLayer_Network_Subnet_IpAddress.py +++ b/SoftLayer/fixtures/SoftLayer_Network_Subnet_IpAddress.py @@ -7,3 +7,5 @@ 'isReserved': False, 'subnetId': 5678, } + +editObject= True diff --git a/SoftLayer/managers/network.py b/SoftLayer/managers/network.py index dbfb9c3f6..786f45f4c 100644 --- a/SoftLayer/managers/network.py +++ b/SoftLayer/managers/network.py @@ -685,3 +685,8 @@ def get_nas_credentials(self, identifier, **kwargs): """ result = self.network_storage.getObject(id=identifier, **kwargs) return result + + def set_subnet_ipddress_note(self, identifier, note): + """Set the ip address note of the subnet""" + result = self.client.call('SoftLayer_Network_Subnet_IpAddress','editObject', note, id=identifier) + return result \ No newline at end of file diff --git a/tests/CLI/modules/subnet_tests.py b/tests/CLI/modules/subnet_tests.py index 1971aa420..650161dea 100644 --- a/tests/CLI/modules/subnet_tests.py +++ b/tests/CLI/modules/subnet_tests.py @@ -36,6 +36,9 @@ def test_detail(self): 'private_ip': '10.0.1.2' } ], + 'ipAddresses': { + '123456': '16.26.26.25', + '123457': '16.26.26.26'}, 'hardware': 'none', 'usable ips': 22 }, @@ -134,3 +137,8 @@ def test_create_subnet_static_ipv6(self, confirm_mock): ] self.assertEqual(output, json.loads(result.output)) + + def test_editrou_Ip(self): + result = self.run_command(['subnet', 'edit-ip', '123456', '--ip=16.26.26.26', '--note=test']) + self.assert_no_fail(result) + self.assertTrue(result) From 2d55c6f039a45ff6c75fef65d8994cfa776018ee Mon Sep 17 00:00:00 2001 From: caberos Date: Fri, 19 Jun 2020 20:15:26 -0400 Subject: [PATCH 2/7] fix tox tool --- SoftLayer/CLI/subnet/detail.py | 4 ++-- docs/cli/subnet.rst | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/SoftLayer/CLI/subnet/detail.py b/SoftLayer/CLI/subnet/detail.py index 39dbb700d..e965df55d 100644 --- a/SoftLayer/CLI/subnet/detail.py +++ b/SoftLayer/CLI/subnet/detail.py @@ -50,9 +50,9 @@ def cli(env, identifier, no_vs, no_hardware): ip_address = subnet.get('ipAddresses') - ip_table = formatting.KeyValueTable(['ipAddress','value']) + ip_table = formatting.KeyValueTable(['ipAddress', 'value']) for address in ip_address: - ip_table.add_row([address.get('id'),address.get('ipAddress')]) + ip_table.add_row([address.get('id'), address.get('ipAddress')]) table.add_row(['ipAddresses', ip_table]) diff --git a/docs/cli/subnet.rst b/docs/cli/subnet.rst index 20fce0def..5ba25c1f3 100644 --- a/docs/cli/subnet.rst +++ b/docs/cli/subnet.rst @@ -22,3 +22,7 @@ Subnets .. click:: SoftLayer.CLI.subnet.lookup:cli :prog: subnet lookup :show-nested: + +.. click:: SoftLayer.CLI.subnet.edit-ip:cli + :prog: subnet edit-ip + :show-nested: From 520d4f68494b531f0f8075427672978f76231d8d Mon Sep 17 00:00:00 2001 From: caberos Date: Fri, 19 Jun 2020 20:20:57 -0400 Subject: [PATCH 3/7] fix tox tool --- SoftLayer/managers/network.py | 2 +- docs/cli/subnet.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/SoftLayer/managers/network.py b/SoftLayer/managers/network.py index 786f45f4c..fa26ca04b 100644 --- a/SoftLayer/managers/network.py +++ b/SoftLayer/managers/network.py @@ -688,5 +688,5 @@ def get_nas_credentials(self, identifier, **kwargs): def set_subnet_ipddress_note(self, identifier, note): """Set the ip address note of the subnet""" - result = self.client.call('SoftLayer_Network_Subnet_IpAddress','editObject', note, id=identifier) + result = self.client.call('SoftLayer_Network_Subnet_IpAddress', 'editObject', note, id=identifier) return result \ No newline at end of file diff --git a/docs/cli/subnet.rst b/docs/cli/subnet.rst index 5ba25c1f3..124f36cde 100644 --- a/docs/cli/subnet.rst +++ b/docs/cli/subnet.rst @@ -23,6 +23,6 @@ Subnets :prog: subnet lookup :show-nested: -.. click:: SoftLayer.CLI.subnet.edit-ip:cli +.. click:: SoftLayer.CLI.subnet.edit_ip:cli :prog: subnet edit-ip :show-nested: From a24dcfcba8201353f383f97a2327908c234b6a6d Mon Sep 17 00:00:00 2001 From: caberos Date: Fri, 19 Jun 2020 20:24:41 -0400 Subject: [PATCH 4/7] fix tox tool --- SoftLayer/managers/network.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/SoftLayer/managers/network.py b/SoftLayer/managers/network.py index fa26ca04b..a2fef4e5a 100644 --- a/SoftLayer/managers/network.py +++ b/SoftLayer/managers/network.py @@ -689,4 +689,5 @@ def get_nas_credentials(self, identifier, **kwargs): def set_subnet_ipddress_note(self, identifier, note): """Set the ip address note of the subnet""" result = self.client.call('SoftLayer_Network_Subnet_IpAddress', 'editObject', note, id=identifier) - return result \ No newline at end of file + return result + \ No newline at end of file From b6cd35aba9459579dad69c385dd029c57f5a6c14 Mon Sep 17 00:00:00 2001 From: caberos Date: Fri, 19 Jun 2020 20:28:37 -0400 Subject: [PATCH 5/7] fix tox tool --- SoftLayer/managers/network.py | 1 - 1 file changed, 1 deletion(-) diff --git a/SoftLayer/managers/network.py b/SoftLayer/managers/network.py index a2fef4e5a..cac9b630c 100644 --- a/SoftLayer/managers/network.py +++ b/SoftLayer/managers/network.py @@ -690,4 +690,3 @@ def set_subnet_ipddress_note(self, identifier, note): """Set the ip address note of the subnet""" result = self.client.call('SoftLayer_Network_Subnet_IpAddress', 'editObject', note, id=identifier) return result - \ No newline at end of file From cc4c6ed2c73e5b4042fcc1ee7ce13cd28b428929 Mon Sep 17 00:00:00 2001 From: caberos Date: Mon, 22 Jun 2020 14:22:26 -0400 Subject: [PATCH 6/7] fix tox tool --- SoftLayer/CLI/subnet/edit_ip.py | 6 +++--- SoftLayer/fixtures/SoftLayer_Network_Subnet_IpAddress.py | 2 +- tests/CLI/modules/subnet_tests.py | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/SoftLayer/CLI/subnet/edit_ip.py b/SoftLayer/CLI/subnet/edit_ip.py index 00077ad2c..8cf65cb9b 100644 --- a/SoftLayer/CLI/subnet/edit_ip.py +++ b/SoftLayer/CLI/subnet/edit_ip.py @@ -9,11 +9,11 @@ @click.command() @click.argument('identifier') -@click.option('--ip', required=True, +@click.option('--ip-address', required=True, help='Assume the ipAddress to set the note.') @click.option('--note', help="set ip address note of subnet") @environment.pass_env -def cli(env, identifier, ip, note): +def cli(env, identifier, ip_address, note): """Set the note of the ipAddress subnet""" data = { @@ -23,5 +23,5 @@ def cli(env, identifier, ip, note): ips = mgr.get_subnet(identifier, mask='id,ipAddresses[id,ipAddress]').get('ipAddresses') for address in ips: - if ip == address.get('ipAddress'): + if ip_address == address.get('ipAddress'): mgr.set_subnet_ipddress_note(address.get('id'), data) diff --git a/SoftLayer/fixtures/SoftLayer_Network_Subnet_IpAddress.py b/SoftLayer/fixtures/SoftLayer_Network_Subnet_IpAddress.py index 5274ffeda..15778d238 100644 --- a/SoftLayer/fixtures/SoftLayer_Network_Subnet_IpAddress.py +++ b/SoftLayer/fixtures/SoftLayer_Network_Subnet_IpAddress.py @@ -8,4 +8,4 @@ 'subnetId': 5678, } -editObject= True +editObject = True diff --git a/tests/CLI/modules/subnet_tests.py b/tests/CLI/modules/subnet_tests.py index 650161dea..3489ec97e 100644 --- a/tests/CLI/modules/subnet_tests.py +++ b/tests/CLI/modules/subnet_tests.py @@ -36,9 +36,9 @@ def test_detail(self): 'private_ip': '10.0.1.2' } ], - 'ipAddresses': { - '123456': '16.26.26.25', - '123457': '16.26.26.26'}, + 'ipAddresses': { + '123456': '16.26.26.25', + '123457': '16.26.26.26'}, 'hardware': 'none', 'usable ips': 22 }, @@ -139,6 +139,6 @@ def test_create_subnet_static_ipv6(self, confirm_mock): self.assertEqual(output, json.loads(result.output)) def test_editrou_Ip(self): - result = self.run_command(['subnet', 'edit-ip', '123456', '--ip=16.26.26.26', '--note=test']) + result = self.run_command(['subnet', 'edit-ip', '123456', '--ip-address=16.26.26.26', '--note=test']) self.assert_no_fail(result) self.assertTrue(result) From d2e3958d11b6f0ea41080eb465aab07bde07eb61 Mon Sep 17 00:00:00 2001 From: caberos Date: Mon, 22 Jun 2020 14:42:06 -0400 Subject: [PATCH 7/7] fix tox tool --- SoftLayer/managers/network.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/SoftLayer/managers/network.py b/SoftLayer/managers/network.py index cac9b630c..73ea5fc0f 100644 --- a/SoftLayer/managers/network.py +++ b/SoftLayer/managers/network.py @@ -13,6 +13,8 @@ from SoftLayer.managers import event_log +# pylint: disable=too-many-public-methods + DEFAULT_SUBNET_MASK = ','.join(['hardware', 'datacenter', 'ipAddressCount',