Skip to content

added force feature for hardware poweron and poweroff #2091

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 21, 2023
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
22 changes: 16 additions & 6 deletions SoftLayer/CLI/hardware/power.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,18 @@

@click.command(cls=SoftLayer.CLI.command.SLCommand, )
@click.argument('identifier')
@click.option('--force', default=False, is_flag=True, help="Force modify")
@environment.pass_env
def power_off(env, identifier):
def power_off(env, identifier, force):
"""Power off an active server."""

mgr = SoftLayer.HardwareManager(env.client)
hw_id = helpers.resolve_id(mgr.resolve_ids, identifier, 'hardware')
if not (env.skip_confirmations or
formatting.confirm('This will power off the server with id %s '
'Continue?' % hw_id)):
raise exceptions.CLIAbort('Aborted.')
if not force:
if not (env.skip_confirmations or
formatting.confirm('This will power off the server with id %s '
'Continue?' % hw_id)):
raise exceptions.CLIAbort('Aborted.')

env.client['Hardware_Server'].powerOff(id=hw_id)

Expand Down Expand Up @@ -53,12 +55,20 @@ def reboot(env, identifier, hard):

@click.command(cls=SoftLayer.CLI.command.SLCommand, )
@click.argument('identifier')
@click.option('--force', default=False, is_flag=True, help="Force modify")
@environment.pass_env
def power_on(env, identifier):
def power_on(env, identifier, force):
"""Power on a server."""

mgr = SoftLayer.HardwareManager(env.client)
hw_id = helpers.resolve_id(mgr.resolve_ids, identifier, 'hardware')

if not force:
if not (env.skip_confirmations or
formatting.confirm('This will power off the server with id %s. '
'Continue?' % hw_id)):
raise exceptions.CLIAbort('Aborted.')

env.client['Hardware_Server'].powerOn(id=hw_id)


Expand Down
14 changes: 14 additions & 0 deletions tests/CLI/modules/server_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,20 @@ def test_server_power_on(self):
self.assert_called_with('SoftLayer_Hardware_Server', 'powerOn',
identifier=12345)

@mock.patch('SoftLayer.CLI.formatting.confirm')
def test_harware_power_on_force(self, confirm_mock):
confirm_mock.return_value = False
result = self.run_command(['hardware', 'power-on', '12345'])
self.assertEqual(2, result.exit_code)
self.assertEqual('Aborted.', result.exception.message)

@mock.patch('SoftLayer.CLI.formatting.confirm')
def test_harware_power_off_force(self, confirm_mock):
confirm_mock.return_value = False
result = self.run_command(['hardware', 'power-off', '12345'])
self.assertEqual(2, result.exit_code)
self.assertEqual('Aborted.', result.exception.message)

def test_server_power_cycle(self):
result = self.run_command(['--really', 'server', 'power-cycle',
'12345'])
Expand Down