Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion SoftLayer/CLI/hardware/cancel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
10 changes: 6 additions & 4 deletions SoftLayer/CLI/hardware/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions tests/CLI/modules/server_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
8 changes: 8 additions & 0 deletions tests/managers/hardware_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)