Skip to content

Commit da699ef

Browse files
Added network flag to update-firmware, added option to specify what to update for the firmware as well. Fixed #2124
1 parent 16d18f2 commit da699ef

File tree

5 files changed

+36
-47
lines changed

5 files changed

+36
-47
lines changed

SoftLayer/CLI/formatting.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,7 @@ def no_going_back(confirmation):
259259
if not confirmation:
260260
confirmation = 'yes'
261261

262-
prompt = ('This action cannot be undone! Type "%s" or press Enter '
263-
'to abort' % confirmation)
262+
prompt = f"This action cannot be undone! Type '{confirmation}' or press Enter to abort"
264263

265264
ans = click.prompt(prompt, default='', show_default=False)
266265
if ans.lower() == str(confirmation):

SoftLayer/CLI/hardware/update_firmware.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,23 @@
1212

1313
@click.command(cls=SoftLayer.CLI.command.SLCommand, )
1414
@click.argument('identifier')
15+
@click.option('-i', '--ipmi', is_flag=True, help="Update IPMI firmware")
16+
@click.option('-r', '--raid', is_flag=True, help="Update RAID firmware")
17+
@click.option('-b', '--bios', is_flag=True, help="Update BIOS firmware")
18+
@click.option('-d', '--harddrive', is_flag=True, help="Update Hard Drives firmware")
19+
@click.option('-n', '--network', is_flag=True, help="Update Network Card firmware")
1520
@environment.pass_env
16-
def cli(env, identifier):
17-
"""Update server firmware."""
21+
def cli(env, identifier, ipmi, raid, bios, harddrive, network):
22+
"""Update server firmware. By default will update all available server components."""
1823

1924
mgr = SoftLayer.HardwareManager(env.client)
2025
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-
'update device firmware. Continue?' % hw_id)):
26+
confirm_message = f"This will power off the server with id {hw_id} and update device firmware. Continue?"
27+
if not (env.skip_confirmations or formatting.confirm(confirm_message)):
2428
raise exceptions.CLIAbort('Aborted.')
2529

26-
mgr.update_firmware(hw_id)
30+
# If no options were specified, set them all to enabled.
31+
if not any([ipmi, raid, bios, harddrive, network]):
32+
ipmi = raid = bios = harddrive = network = 1
33+
mgr.update_firmware(hw_id, ipmi, raid, bios, harddrive, network)
34+
env.fout(f"[green]Firmware update for {identifier} started")

SoftLayer/managers/hardware.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -723,44 +723,46 @@ def edit(self, hardware_id, userdata=None, hostname=None, domain=None,
723723

724724
return self.hardware.editObject(obj, id=hardware_id)
725725

726-
def update_firmware(self,
727-
hardware_id,
728-
ipmi=True,
729-
raid_controller=True,
730-
bios=True,
731-
hard_drive=True):
726+
def update_firmware(self, hardware_id: int,
727+
ipmi: bool = True,
728+
raid_controller: bool = True,
729+
bios: bool = True,
730+
hard_drive: bool = True,
731+
network: bool = True):
732732
"""Update hardware firmware.
733733
734734
This will cause the server to be unavailable for ~20 minutes.
735+
https://sldn.softlayer.com/reference/services/SoftLayer_Hardware_Server/createFirmwareUpdateTransaction/
735736
736-
:param int hardware_id: The ID of the hardware to have its firmware
737-
updated.
737+
:param int hardware_id: The ID of the hardware to have its firmware updated.
738738
:param bool ipmi: Update the ipmi firmware.
739739
:param bool raid_controller: Update the raid controller firmware.
740740
:param bool bios: Update the bios firmware.
741741
:param bool hard_drive: Update the hard drive firmware.
742+
:param bool network: Update the network card firmware
742743
743744
Example::
744745
745746
# Check the servers active transactions to see progress
746747
result = mgr.update_firmware(hardware_id=1234)
747748
"""
748749

749-
return self.hardware.createFirmwareUpdateTransaction(
750-
bool(ipmi), bool(raid_controller), bool(bios), bool(hard_drive), id=hardware_id)
750+
return self.client.call(
751+
'SoftLayer_Hardware_Server', 'createFirmwareUpdateTransaction',
752+
bool(ipmi), bool(raid_controller), bool(bios), bool(hard_drive), bool(network), id=hardware_id
753+
)
751754

752-
def reflash_firmware(self,
753-
hardware_id,
754-
ipmi=True,
755-
raid_controller=True,
756-
bios=True):
755+
def reflash_firmware(self, hardware_id: int,
756+
ipmi: bool = True,
757+
raid_controller: bool = True,
758+
bios: bool = True,):
757759
"""Reflash hardware firmware.
758760
759761
This will cause the server to be unavailable for ~60 minutes.
760762
The firmware will not be upgraded but rather reflashed to the version installed.
763+
https://sldn.softlayer.com/reference/services/SoftLayer_Hardware_Server/createFirmwareReflashTransaction/
761764
762-
:param int hardware_id: The ID of the hardware to have its firmware
763-
reflashed.
765+
:param int hardware_id: The ID of the hardware to have its firmware reflashed.
764766
:param bool ipmi: Reflash the ipmi firmware.
765767
:param bool raid_controller: Reflash the raid controller firmware.
766768
:param bool bios: Reflash the bios firmware.

tests/CLI/modules/hardware/hardware_basic_tests.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -498,26 +498,6 @@ def test_edit_server_userfile(self):
498498
self.assert_called_with('SoftLayer_Hardware_Server', 'setUserMetadata',
499499
args=(['some data'],), identifier=1000)
500500

501-
@mock.patch('SoftLayer.CLI.formatting.confirm')
502-
def test_update_firmware(self, confirm_mock):
503-
confirm_mock.return_value = True
504-
result = self.run_command(['server', 'update-firmware', '1000'])
505-
506-
self.assert_no_fail(result)
507-
self.assertEqual(result.output, "")
508-
self.assert_called_with('SoftLayer_Hardware_Server', 'createFirmwareUpdateTransaction',
509-
args=((1, 1, 1, 1)), identifier=1000)
510-
511-
@mock.patch('SoftLayer.CLI.formatting.confirm')
512-
def test_reflash_firmware(self, confirm_mock):
513-
confirm_mock.return_value = True
514-
result = self.run_command(['server', 'reflash-firmware', '1000'])
515-
516-
self.assert_no_fail(result)
517-
self.assertEqual(result.output, 'Successfully device firmware reflashed\n')
518-
self.assert_called_with('SoftLayer_Hardware_Server', 'createFirmwareReflashTransaction',
519-
args=((1, 1, 1)), identifier=1000)
520-
521501
def test_edit(self):
522502
result = self.run_command(['server', 'edit',
523503
'--domain=example.com',

tests/managers/hardware_tests.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -543,14 +543,14 @@ def test_update_firmware(self):
543543

544544
self.assertEqual(result, True)
545545
self.assert_called_with('SoftLayer_Hardware_Server', 'createFirmwareUpdateTransaction',
546-
identifier=100, args=(1, 1, 1, 1))
546+
identifier=100, args=(1, 1, 1, 1, 1))
547547

548548
def test_update_firmware_selective(self):
549549
result = self.hardware.update_firmware(100, ipmi=False, hard_drive=False)
550550

551551
self.assertEqual(result, True)
552552
self.assert_called_with('SoftLayer_Hardware_Server', 'createFirmwareUpdateTransaction',
553-
identifier=100, args=(0, 1, 1, 0))
553+
identifier=100, args=(0, 1, 1, 0, 1))
554554

555555
def test_reflash_firmware(self):
556556
result = self.hardware.reflash_firmware(100)

0 commit comments

Comments
 (0)