Skip to content

Commit

Permalink
Merge pull request softlayer#2091 from ramkishor-ch/issue_2038
Browse files Browse the repository at this point in the history
added force feature for hardware poweron and poweroff
  • Loading branch information
allmightyspiff authored Sep 21, 2023
2 parents 0189f4d + 5d3da1a commit 15c627e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
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

0 comments on commit 15c627e

Please sign in to comment.