Skip to content

Commit 15c627e

Browse files
Merge pull request #2091 from ramkishor-ch/issue_2038
added force feature for hardware poweron and poweroff
2 parents 0189f4d + 5d3da1a commit 15c627e

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

Diff for: SoftLayer/CLI/hardware/power.py

+16-6
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,18 @@
1212

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

1920
mgr = SoftLayer.HardwareManager(env.client)
2021
hw_id = helpers.resolve_id(mgr.resolve_ids, identifier, 'hardware')
21-
if not (env.skip_confirmations or
22-
formatting.confirm('This will power off the server with id %s '
23-
'Continue?' % hw_id)):
24-
raise exceptions.CLIAbort('Aborted.')
22+
if not force:
23+
if not (env.skip_confirmations or
24+
formatting.confirm('This will power off the server with id %s '
25+
'Continue?' % hw_id)):
26+
raise exceptions.CLIAbort('Aborted.')
2527

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

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

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

6063
mgr = SoftLayer.HardwareManager(env.client)
6164
hw_id = helpers.resolve_id(mgr.resolve_ids, identifier, 'hardware')
65+
66+
if not force:
67+
if not (env.skip_confirmations or
68+
formatting.confirm('This will power off the server with id %s. '
69+
'Continue?' % hw_id)):
70+
raise exceptions.CLIAbort('Aborted.')
71+
6272
env.client['Hardware_Server'].powerOn(id=hw_id)
6373

6474

Diff for: tests/CLI/modules/server_tests.py

+14
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,20 @@ def test_server_power_on(self):
321321
self.assert_called_with('SoftLayer_Hardware_Server', 'powerOn',
322322
identifier=12345)
323323

324+
@mock.patch('SoftLayer.CLI.formatting.confirm')
325+
def test_harware_power_on_force(self, confirm_mock):
326+
confirm_mock.return_value = False
327+
result = self.run_command(['hardware', 'power-on', '12345'])
328+
self.assertEqual(2, result.exit_code)
329+
self.assertEqual('Aborted.', result.exception.message)
330+
331+
@mock.patch('SoftLayer.CLI.formatting.confirm')
332+
def test_harware_power_off_force(self, confirm_mock):
333+
confirm_mock.return_value = False
334+
result = self.run_command(['hardware', 'power-off', '12345'])
335+
self.assertEqual(2, result.exit_code)
336+
self.assertEqual('Aborted.', result.exception.message)
337+
324338
def test_server_power_cycle(self):
325339
result = self.run_command(['--really', 'server', 'power-cycle',
326340
'12345'])

0 commit comments

Comments
 (0)