@@ -454,7 +454,7 @@ class RestClientBase(object):
454454 def __init__ (self , base_url , username = None , password = None ,
455455 default_prefix = '/redfish/v1/' , sessionkey = None ,
456456 capath = None , cafile = None , timeout = None ,
457- max_retry = None , proxies = None ):
457+ max_retry = None , proxies = None , check_connectivity = True ):
458458 """Initialization of the base class RestClientBase
459459
460460 :param base_url: The URL of the remote system
@@ -477,6 +477,9 @@ def __init__(self, base_url, username=None, password=None,
477477 :type max_retry: int
478478 :param proxies: Dictionary containing protocol to proxy URL mappings
479479 :type proxies: dict
480+ :param check_connectivity: A boolean to determine whether the client immediately checks for
481+ connectivity to the base_url or not.
482+ :type check_connectivity: bool
480483
481484 """
482485
@@ -497,7 +500,9 @@ def __init__(self, base_url, username=None, password=None,
497500 self .default_prefix = default_prefix
498501 self .capath = capath
499502 self .cafile = cafile
500- self .get_root_object ()
503+
504+ if check_connectivity :
505+ self .get_root_object ()
501506
502507 def __enter__ (self ):
503508 self .login ()
@@ -965,6 +970,8 @@ def login(self, username=None, password=None, auth=AuthMethod.SESSION):
965970 :type auth: object/instance of class AuthMethod
966971
967972 """
973+ if getattr (self , "root_resp" , None ) is None :
974+ self .get_root_object ()
968975
969976 self .__username = username if username else self .__username
970977 self .__password = password if password else self .__password
@@ -999,7 +1006,7 @@ def login(self, username=None, password=None, auth=AuthMethod.SESSION):
9991006 message_item = search_message (resp , "Base" , "PasswordChangeRequired" )
10001007 if not message_item is None :
10011008 raise RedfishPasswordChangeRequiredError ("Password Change Required\n " , message_item ["MessageArgs" ][0 ])
1002-
1009+
10031010 if not self .__session_key and resp .status not in [200 , 201 , 202 , 204 ]:
10041011 if resp .status == 401 :
10051012 # Invalid credentials supplied
@@ -1042,7 +1049,7 @@ def __init__(self, base_url, username=None, password=None,
10421049 default_prefix = '/redfish/v1/' ,
10431050 sessionkey = None , capath = None ,
10441051 cafile = None , timeout = None ,
1045- max_retry = None , proxies = None ):
1052+ max_retry = None , proxies = None , check_connectivity = True ):
10461053 """Initialize HttpClient
10471054
10481055 :param base_url: The url of the remote system
@@ -1065,17 +1072,21 @@ def __init__(self, base_url, username=None, password=None,
10651072 :type max_retry: int
10661073 :param proxies: Dictionary containing protocol to proxy URL mappings
10671074 :type proxies: dict
1075+ :param check_connectivity: A boolean to determine whether the client immediately checks for
1076+ connectivity to the base_url or not.
1077+ :type check_connectivity: bool
10681078
10691079 """
10701080 super (HttpClient , self ).__init__ (base_url , username = username ,
10711081 password = password , default_prefix = default_prefix ,
10721082 sessionkey = sessionkey , capath = capath ,
10731083 cafile = cafile , timeout = timeout ,
1074- max_retry = max_retry , proxies = proxies )
1084+ max_retry = max_retry , proxies = proxies ,
1085+ check_connectivity = check_connectivity )
10751086
10761087 try :
10771088 self .login_url = self .root .Links .Sessions ['@odata.id' ]
1078- except KeyError :
1089+ except ( KeyError , AttributeError ) :
10791090 # While the "Links/Sessions" property is required, we can fallback
10801091 # on the URI hardened in 1.6.0 of the specification if not found
10811092 LOGGER .debug ('"Links/Sessions" not found in Service Root.' )
@@ -1128,7 +1139,7 @@ def redfish_client(base_url=None, username=None, password=None,
11281139 default_prefix = '/redfish/v1/' ,
11291140 sessionkey = None , capath = None ,
11301141 cafile = None , timeout = None ,
1131- max_retry = None , proxies = None ):
1142+ max_retry = None , proxies = None , check_connectivity = True ):
11321143 """Create and return appropriate REDFISH client instance."""
11331144 """ Instantiates appropriate Redfish object based on existing"""
11341145 """ configuration. Use this to retrieve a pre-configured Redfish object
@@ -1153,6 +1164,9 @@ def redfish_client(base_url=None, username=None, password=None,
11531164 :type max_retry: int
11541165 :param proxies: Dictionary containing protocol to proxy URL mappings
11551166 :type proxies: dict
1167+ :param check_connectivity: A boolean to determine whether the client immediately checks for
1168+ connectivity to the base_url or not.
1169+ :type check_connectivity: bool
11561170 :returns: a client object.
11571171
11581172 """
@@ -1162,4 +1176,4 @@ def redfish_client(base_url=None, username=None, password=None,
11621176 return HttpClient (base_url = base_url , username = username , password = password ,
11631177 default_prefix = default_prefix , sessionkey = sessionkey ,
11641178 capath = capath , cafile = cafile , timeout = timeout ,
1165- max_retry = max_retry , proxies = proxies )
1179+ max_retry = max_retry , proxies = proxies , check_connectivity = check_connectivity )
0 commit comments