Skip to content

Commit 9f25809

Browse files
Merge pull request #1106 from follower46/firmwareReflash
hardware firmware reflash support
2 parents c0553f4 + e6aa806 commit 9f25809

File tree

6 files changed

+82
-0
lines changed

6 files changed

+82
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""Reflash firmware."""
2+
# :license: MIT, see LICENSE for more details.
3+
4+
import click
5+
6+
import SoftLayer
7+
from SoftLayer.CLI import environment
8+
from SoftLayer.CLI import exceptions
9+
from SoftLayer.CLI import formatting
10+
from SoftLayer.CLI import helpers
11+
12+
13+
@click.command()
14+
@click.argument('identifier')
15+
@environment.pass_env
16+
def cli(env, identifier):
17+
"""Reflash server firmware."""
18+
19+
mgr = SoftLayer.HardwareManager(env.client)
20+
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 and '
23+
'reflash device firmware. Continue?' % hw_id)):
24+
raise exceptions.CLIAbort('Aborted.')
25+
26+
mgr.reflash_firmware(hw_id)

SoftLayer/CLI/routes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@
240240
('hardware:reload', 'SoftLayer.CLI.hardware.reload:cli'),
241241
('hardware:credentials', 'SoftLayer.CLI.hardware.credentials:cli'),
242242
('hardware:update-firmware', 'SoftLayer.CLI.hardware.update_firmware:cli'),
243+
('hardware:reflash-firmware', 'SoftLayer.CLI.hardware.reflash_firmware:cli'),
243244
('hardware:rescue', 'SoftLayer.CLI.hardware.power:rescue'),
244245
('hardware:ready', 'SoftLayer.CLI.hardware.ready:cli'),
245246
('hardware:toggle-ipmi', 'SoftLayer.CLI.hardware.toggle_ipmi:cli'),

SoftLayer/fixtures/SoftLayer_Hardware_Server.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
rebootDefault = True
8282
rebootHard = True
8383
createFirmwareUpdateTransaction = True
84+
createFirmwareReflashTransaction = True
8485
setUserMetadata = ['meta']
8586
reloadOperatingSystem = 'OK'
8687
getReverseDomainRecords = [

SoftLayer/managers/hardware.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,31 @@ def update_firmware(self,
613613
return self.hardware.createFirmwareUpdateTransaction(
614614
bool(ipmi), bool(raid_controller), bool(bios), bool(hard_drive), id=hardware_id)
615615

616+
def reflash_firmware(self,
617+
hardware_id,
618+
ipmi=True,
619+
raid_controller=True,
620+
bios=True):
621+
"""Reflash hardware firmware.
622+
623+
This will cause the server to be unavailable for ~60 minutes.
624+
The firmware will not be upgraded but rather reflashed to the version installed.
625+
626+
:param int hardware_id: The ID of the hardware to have its firmware
627+
reflashed.
628+
:param bool ipmi: Reflash the ipmi firmware.
629+
:param bool raid_controller: Reflash the raid controller firmware.
630+
:param bool bios: Reflash the bios firmware.
631+
632+
Example::
633+
634+
# Check the servers active transactions to see progress
635+
result = mgr.reflash_firmware(hardware_id=1234)
636+
"""
637+
638+
return self.hardware.createFirmwareReflashTransaction(
639+
bool(ipmi), bool(raid_controller), bool(bios), id=hardware_id)
640+
616641
def wait_for_ready(self, instance_id, limit=14400, delay=10, pending=False):
617642
"""Determine if a Server is ready.
618643

tests/CLI/modules/server_tests.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,17 @@ def test_update_firmware(self, confirm_mock):
482482
'createFirmwareUpdateTransaction',
483483
args=((1, 1, 1, 1)), identifier=1000)
484484

485+
@mock.patch('SoftLayer.CLI.formatting.confirm')
486+
def test_reflash_firmware(self, confirm_mock):
487+
confirm_mock.return_value = True
488+
result = self.run_command(['server', 'reflash-firmware', '1000'])
489+
490+
self.assert_no_fail(result)
491+
self.assertEqual(result.output, "")
492+
self.assert_called_with('SoftLayer_Hardware_Server',
493+
'createFirmwareReflashTransaction',
494+
args=((1, 1, 1)), identifier=1000)
495+
485496
def test_edit(self):
486497
result = self.run_command(['server', 'edit',
487498
'--domain=example.com',

tests/managers/hardware_tests.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,24 @@ def test_update_firmware_selective(self):
392392
'createFirmwareUpdateTransaction',
393393
identifier=100, args=(0, 1, 1, 0))
394394

395+
def test_reflash_firmware(self):
396+
result = self.hardware.reflash_firmware(100)
397+
398+
self.assertEqual(result, True)
399+
self.assert_called_with('SoftLayer_Hardware_Server',
400+
'createFirmwareReflashTransaction',
401+
identifier=100, args=(1, 1, 1))
402+
403+
def test_reflash_firmware_selective(self):
404+
result = self.hardware.reflash_firmware(100,
405+
raid_controller=False,
406+
bios=False)
407+
408+
self.assertEqual(result, True)
409+
self.assert_called_with('SoftLayer_Hardware_Server',
410+
'createFirmwareReflashTransaction',
411+
identifier=100, args=(1, 0, 0))
412+
395413

396414
class HardwareHelperTests(testing.TestCase):
397415
def test_get_extra_price_id_no_items(self):

0 commit comments

Comments
 (0)