@@ -426,24 +426,38 @@ def start(self) -> None:
426
426
def cold_boot (self ) -> None :
427
427
pass
428
428
429
- def version (self ) -> str :
429
+ def _version_via_redfish (self ) -> Optional [ str ] :
430
430
url = f"https://{ self .url } :8443/redfish/v1/Managers/1"
431
431
res = self ._run_curl (f"-k '{ url } '" )
432
432
if res .returncode != 0 :
433
- raise RuntimeError ( f"Cannot detect Redfish version: failure to fetch URL { repr ( url ) } " )
433
+ return None
434
434
try :
435
435
data = json .loads (res .out )
436
436
except Exception :
437
- raise RuntimeError ( f"Cannot detect Redfish version: not valid JSON received but { repr ( res . out ) } " )
437
+ return None
438
438
fwversion = data .get ("FirmwareVersion" )
439
439
if not isinstance (fwversion , str ):
440
- raise RuntimeError (f"Cannot detect Redfish version: FirmwareVersion field not present in { repr (res .out )} " )
441
- fwversion = fwversion .strip ()
442
- match = re .search (r"^MEV-.*\.([0-9]+\.[0-9]+\.[0-9]+)\.[0-9]+$" , fwversion )
440
+ return None
441
+ match = re .search (r"^MEV-.*\.([0-9]+\.[0-9]+\.[0-9]+)\.[0-9]+$" , fwversion .strip ())
443
442
if not match :
444
- raise RuntimeError ( f"Cannot detect Redfish version: FirmwareVersion is unexpected { repr ( fwversion ) } " )
443
+ return None
445
444
return match .group (1 )
446
445
446
+ def _version_via_ssh (self ) -> Optional [str ]:
447
+ rh = host .RemoteHost (self .url )
448
+ rh .ssh_connect ("root" , password = "" , discover_auth = False )
449
+ contents = rh .read_file ("/etc/issue" )
450
+ match = re .search (r"Version: (\S+)" , contents )
451
+ if not match :
452
+ return None
453
+ return match .group (1 ).strip ()
454
+
455
+ def version (self ) -> str :
456
+ fwversion = self ._version_via_redfish () or self ._version_via_ssh ()
457
+ if not fwversion :
458
+ raise RuntimeError (f"Failed to detect Redfish version on { self .url } " )
459
+ return fwversion
460
+
447
461
448
462
def extract_server (url : str ) -> str :
449
463
"""
0 commit comments