From c0485663560e6b192816d35cc9044084d44d4084 Mon Sep 17 00:00:00 2001 From: Ramkishor Chaladi Date: Mon, 21 Aug 2023 15:54:14 +0530 Subject: [PATCH 1/2] added force flag --- SoftLayer/CLI/hardware/cancel.py | 8 +++++++- SoftLayer/CLI/hardware/create.py | 10 ++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/SoftLayer/CLI/hardware/cancel.py b/SoftLayer/CLI/hardware/cancel.py index 8af077872..ed8633fcf 100644 --- a/SoftLayer/CLI/hardware/cancel.py +++ b/SoftLayer/CLI/hardware/cancel.py @@ -20,8 +20,9 @@ help="An optional comment to add to the cancellation ticket") @click.option('--reason', help="An optional cancellation reason. See cancel-reasons for a list of available options") +@click.option('--force', default=False, is_flag=True, help="Force modify") @environment.pass_env -def cli(env, identifier, immediate, comment, reason): +def cli(env, identifier, immediate, comment, reason, force): """Cancel a dedicated server.""" mgr = SoftLayer.HardwareManager(env.client) @@ -30,4 +31,9 @@ def cli(env, identifier, immediate, comment, reason): if not (env.skip_confirmations or formatting.no_going_back(hw_id)): raise exceptions.CLIAbort('Aborted') + if not force: + if not (env.skip_confirmations or + formatting.confirm("This action will incur charges on your account. Continue?")): + raise exceptions.CLIAbort('Aborted') + mgr.cancel_hardware(hw_id, reason, comment, immediate) diff --git a/SoftLayer/CLI/hardware/create.py b/SoftLayer/CLI/hardware/create.py index 3547344ac..eaa9e0a23 100644 --- a/SoftLayer/CLI/hardware/create.py +++ b/SoftLayer/CLI/hardware/create.py @@ -37,8 +37,9 @@ help="The ID of the private ROUTER on which you want the virtual server placed") @helpers.multi_option('--key', '-k', help="SSH keys to add to the root user") @helpers.multi_option('--extra', '-e', help="Extra option Key Names") +@click.option('--force', default=False, is_flag=True, help="Force modify") @environment.pass_env -def cli(env, **args): +def cli(env, force, **args): """Order/create a dedicated server.""" mgr = SoftLayer.HardwareManager(env.client) network = SoftLayer.NetworkManager(env.client) @@ -105,9 +106,10 @@ def cli(env, **args): for pod in pods: if args.get('datacenter') in pod['name']: click.secho(f"Warning: Closed soon: {pod['name']}", fg='yellow') - if not (env.skip_confirmations or formatting.confirm( - "This action will incur charges on your account. Continue?")): - raise exceptions.CLIAbort('Aborting dedicated server order.') + if not force: + if not (env.skip_confirmations or formatting.confirm( + "This action will incur charges on your account. Continue?")): + raise exceptions.CLIAbort('Aborting dedicated server order.') result = mgr.place_order(**order) From 6df4ccb1ab548d3387304fb6869b5560f5b8986b Mon Sep 17 00:00:00 2001 From: Ramkishor Chaladi Date: Mon, 21 Aug 2023 16:14:10 +0530 Subject: [PATCH 2/2] added force flag --- tests/CLI/modules/server_tests.py | 1 + tests/managers/hardware_tests.py | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/tests/CLI/modules/server_tests.py b/tests/CLI/modules/server_tests.py index 1f17e0c2a..7a4d1de39 100644 --- a/tests/CLI/modules/server_tests.py +++ b/tests/CLI/modules/server_tests.py @@ -922,6 +922,7 @@ def test_create_hw_no_confirm(self, confirm_mock): '--network=TEST_NETWORK', '--os=UBUNTU_12_64']) self.assertEqual(result.exit_code, 2) + self.assertEqual('Aborting dedicated server order.', result.exception.message) @mock.patch('SoftLayer.CLI.formatting.confirm') def test_authorize_hw_no_confirm(self, confirm_mock): diff --git a/tests/managers/hardware_tests.py b/tests/managers/hardware_tests.py index e8f70840c..05790469a 100644 --- a/tests/managers/hardware_tests.py +++ b/tests/managers/hardware_tests.py @@ -1052,3 +1052,11 @@ def test_is_private(self): item_public = {'attributes': [{'attributeTypeKeyName': 'NOT_PRIVATE_NETWORK_ONLY'}]} self.assertTrue(managers.hardware._is_private_port_speed_item(item_private)) self.assertFalse(managers.hardware._is_private_port_speed_item(item_public)) + + @mock.patch('SoftLayer.CLI.formatting.confirm') + def test_hardware_cancel_no_force(self, confirm_mock): + confirm_mock.return_value = False + result = self.run_command(['hardware', 'cancel', '102']) + + self.assertEqual(2, result.exit_code) + self.assertEqual('Aborted', result.exception.message)