From f856db39019fcf7ae561103ec4b1a333dde938a5 Mon Sep 17 00:00:00 2001 From: ATGE Date: Mon, 19 Nov 2018 15:28:32 -0400 Subject: [PATCH 1/6] #1059 adding toggle_ipmi.py to hardware cli --- SoftLayer/CLI/hardware/toggle_ipmi.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 SoftLayer/CLI/hardware/toggle_ipmi.py diff --git a/SoftLayer/CLI/hardware/toggle_ipmi.py b/SoftLayer/CLI/hardware/toggle_ipmi.py new file mode 100644 index 000000000..965e809ef --- /dev/null +++ b/SoftLayer/CLI/hardware/toggle_ipmi.py @@ -0,0 +1,23 @@ +"""Toggle the IPMI interface on and off.""" +# :license: MIT, see LICENSE for more details. + +import click + +import SoftLayer +from SoftLayer.CLI import environment +from SoftLayer.CLI import helpers + + +@click.command() +@click.argument('identifier') +@click.option('--enabled', + type=click.BOOL, + help="Whether to enable or disable the interface.") +@environment.pass_env +def cli(env, identifier, enabled): + """Toggle the IPMI interface on and off""" + + mgr = SoftLayer.HardwareManager(env.client) + hw_id = helpers.resolve_id(mgr.resolve_ids, identifier, 'hardware') + result = env.client['Hardware_Server'].toggleManagementInterface(enabled, id=hw_id) + env.fout(result) From 0f0030a824b57623adcc99d6bee1bbd3b7fb78fe Mon Sep 17 00:00:00 2001 From: ATGE Date: Mon, 19 Nov 2018 15:30:23 -0400 Subject: [PATCH 2/6] #1059 adding cli route for hardware toggle-ipmi --- SoftLayer/CLI/routes.py | 1 + 1 file changed, 1 insertion(+) diff --git a/SoftLayer/CLI/routes.py b/SoftLayer/CLI/routes.py index e80a0b50a..cebf2bc0b 100644 --- a/SoftLayer/CLI/routes.py +++ b/SoftLayer/CLI/routes.py @@ -237,6 +237,7 @@ ('hardware:update-firmware', 'SoftLayer.CLI.hardware.update_firmware:cli'), ('hardware:rescue', 'SoftLayer.CLI.hardware.power:rescue'), ('hardware:ready', 'SoftLayer.CLI.hardware.ready:cli'), + ('hardware:toggle-ipmi', 'SoftLayer.CLI.hardware.toggle_ipmi:cli'), ('securitygroup', 'SoftLayer.CLI.securitygroup'), ('securitygroup:list', 'SoftLayer.CLI.securitygroup.list:cli'), From a5e70dca66d47e0b6f9faad252fea68c520ae1d7 Mon Sep 17 00:00:00 2001 From: ATGE Date: Mon, 19 Nov 2018 15:31:38 -0400 Subject: [PATCH 3/6] #1059 adding server test for toggle-ipmi --- tests/CLI/modules/server_tests.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/CLI/modules/server_tests.py b/tests/CLI/modules/server_tests.py index 2f26c4ec6..b278c6bb0 100644 --- a/tests/CLI/modules/server_tests.py +++ b/tests/CLI/modules/server_tests.py @@ -580,3 +580,9 @@ def test_going_ready(self, _sleep): result = self.run_command(['hw', 'ready', '100', '--wait=100']) self.assert_no_fail(result) self.assertEqual(result.output, '"READY"\n') + + def test_toggle_impi(self): + mock.return_value = True + result = self.run_command(['server', 'toggle-ipmi', '--enabled=True', '12345']) + self.assert_no_fail(result) + self.assertEqual(result.output, 'True\n') From cc2fed09d3e6ce7d046181c4ac9dc0dd30a3933c Mon Sep 17 00:00:00 2001 From: ATGE Date: Mon, 19 Nov 2018 15:34:22 -0400 Subject: [PATCH 4/6] #1059 adding toggleManagementInterface to server fixtures --- SoftLayer/fixtures/SoftLayer_Hardware_Server.py | 1 + 1 file changed, 1 insertion(+) diff --git a/SoftLayer/fixtures/SoftLayer_Hardware_Server.py b/SoftLayer/fixtures/SoftLayer_Hardware_Server.py index 61bdbf984..9a9587b81 100644 --- a/SoftLayer/fixtures/SoftLayer_Hardware_Server.py +++ b/SoftLayer/fixtures/SoftLayer_Hardware_Server.py @@ -73,6 +73,7 @@ setTags = True setPrivateNetworkInterfaceSpeed = True setPublicNetworkInterfaceSpeed = True +toggleManagementInterface = True powerOff = True powerOn = True powerCycle = True From 5aeff0c3edb9464105befa324243d6f9a73c7e5c Mon Sep 17 00:00:00 2001 From: ATGE Date: Tue, 20 Nov 2018 21:12:28 -0400 Subject: [PATCH 5/6] #1059 updating toggle-ipmi test --- tests/CLI/modules/server_tests.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/CLI/modules/server_tests.py b/tests/CLI/modules/server_tests.py index b278c6bb0..c9e030770 100644 --- a/tests/CLI/modules/server_tests.py +++ b/tests/CLI/modules/server_tests.py @@ -581,8 +581,14 @@ def test_going_ready(self, _sleep): self.assert_no_fail(result) self.assertEqual(result.output, '"READY"\n') - def test_toggle_impi(self): + def test_toggle_ipmi_on(self): mock.return_value = True - result = self.run_command(['server', 'toggle-ipmi', '--enabled=True', '12345']) + result = self.run_command(['server', 'toggle-ipmi', '--enable', '12345']) + self.assert_no_fail(result) + self.assertEqual(result.output, 'True\n') + + def test_toggle_ipmi_off(self): + mock.return_value = True + result = self.run_command(['server', 'toggle-ipmi', '--disable', '12345']) self.assert_no_fail(result) self.assertEqual(result.output, 'True\n') From b2a09e6f5f246311471cec1d6da5153b7be3068f Mon Sep 17 00:00:00 2001 From: ATGE Date: Tue, 20 Nov 2018 21:17:04 -0400 Subject: [PATCH 6/6] #1059 Updating click.option to Boolean Flag --- SoftLayer/CLI/hardware/toggle_ipmi.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/SoftLayer/CLI/hardware/toggle_ipmi.py b/SoftLayer/CLI/hardware/toggle_ipmi.py index 965e809ef..2e49bd72f 100644 --- a/SoftLayer/CLI/hardware/toggle_ipmi.py +++ b/SoftLayer/CLI/hardware/toggle_ipmi.py @@ -10,14 +10,13 @@ @click.command() @click.argument('identifier') -@click.option('--enabled', - type=click.BOOL, - help="Whether to enable or disable the interface.") +@click.option('--enable/--disable', default=True, + help="Whether enable (DEFAULT) or disable the interface.") @environment.pass_env -def cli(env, identifier, enabled): +def cli(env, identifier, enable): """Toggle the IPMI interface on and off""" mgr = SoftLayer.HardwareManager(env.client) hw_id = helpers.resolve_id(mgr.resolve_ids, identifier, 'hardware') - result = env.client['Hardware_Server'].toggleManagementInterface(enabled, id=hw_id) + result = env.client['Hardware_Server'].toggleManagementInterface(enable, id=hw_id) env.fout(result)