@@ -53,6 +53,11 @@ def untested(meth):
53
53
return meth
54
54
55
55
class IloError (Exception ):
56
+ def __init__ (self , message , errorcode = None ):
57
+ super (IloError , self ).__init__ (message )
58
+ self .errorcode = error_code
59
+
60
+ class IloCommunicationError (IloError ):
56
61
pass
57
62
58
63
class IloLoginFailed (IloError ):
@@ -201,7 +206,7 @@ def _upload_file(self, filename, progress):
201
206
except socket .sslerror : # Connection closed
202
207
e = sys .exc_info ()[1 ]
203
208
if not data :
204
- raise IloError ("Communication with %s:%d failed: %s" % (self .hostname , self .port , str (e )))
209
+ raise IloCommunicationError ("Communication with %s:%d failed: %s" % (self .hostname , self .port , str (e )))
205
210
206
211
self ._debug (1 , "Received %d bytes" % len (data ))
207
212
self ._debug (2 , data )
@@ -216,7 +221,7 @@ def _get_socket(self):
216
221
sp = subprocess .Popen ([self .hponcfg , '--input' , '--xmlverbose' ], stdin = subprocess .PIPE , stdout = subprocess .PIPE , stderr = None )
217
222
except OSError :
218
223
e = sys .exc_info ()[1 ]
219
- raise IloError ("Cannot run %s: %s" % (self .hponcfg , str (e )))
224
+ raise IloCommunicationError ("Cannot run %s: %s" % (self .hponcfg , str (e )))
220
225
sp .write = sp .stdin .write
221
226
sp .read = sp .stdout .read
222
227
return sp
@@ -227,15 +232,15 @@ def _get_socket(self):
227
232
try :
228
233
sock .connect ((self .hostname , self .port ))
229
234
except socket .timeout :
230
- raise IloError ("Timeout connecting to %s:%d" % (self .hostname , self .port ))
235
+ raise IloCommunicationError ("Timeout connecting to %s:%d" % (self .hostname , self .port ))
231
236
except socket .error :
232
237
e = sys .exc_info ()[1 ]
233
- raise IloError ("Error connecting to %s:%d: %s" % (self .hostname , self .port , str (e )))
238
+ raise IloCommunicationError ("Error connecting to %s:%d: %s" % (self .hostname , self .port , str (e )))
234
239
try :
235
240
return ssl .wrap_socket (sock , ssl_version = ssl .PROTOCOL_TLSv1 )
236
241
except socket .sslerror :
237
242
e = sys .exc_info ()[1 ]
238
- raise IloError ("Cannot establish ssl session with %s:%d: %s" % (self .hostname , self .port , e .message or str (e )))
243
+ raise IloCommunicationError ("Cannot establish ssl session with %s:%d: %s" % (self .hostname , self .port , e .message or str (e )))
239
244
240
245
def _communicate (self , xml , protocol , progress = None ):
241
246
sock = self ._get_socket ()
@@ -303,7 +308,7 @@ def _communicate(self, xml, protocol, progress=None):
303
308
except socket .sslerror : # Connection closed
304
309
e = sys .exc_info ()[1 ]
305
310
if not data :
306
- raise IloError ("Communication with %s:%d failed: %s" % (self .hostname , self .port , str (e )))
311
+ raise IloCommunicationError ("Communication with %s:%d failed: %s" % (self .hostname , self .port , str (e )))
307
312
308
313
self ._debug (1 , "Received %d bytes" % len (data ))
309
314
@@ -375,10 +380,12 @@ def _parse_message(self, data, include_inform=False):
375
380
# This is triggered when doing protocol detection, ignore
376
381
pass
377
382
else :
378
- if int (child .get ('STATUS' ), 16 ) in IloLoginFailed .possible_codes or \
379
- child .get ('MESSAGE' ) in IloLoginFailed .possible_messages :
380
- raise IloLoginFailed
381
- raise IloError ("Error communicating with iLO: %s" % child .get ('MESSAGE' ))
383
+ status = int (child .get ('STATUS' ), 16 )
384
+ message = child .get ('MESSAGE' )
385
+ if status in IloLoginFailed .possible_codes or \
386
+ message in IloLoginFailed .possible_messages :
387
+ raise IloLoginFailed (message , status )
388
+ raise IloError (message , status )
382
389
# And this type of message is the actual payload.
383
390
else :
384
391
return message
@@ -555,7 +562,7 @@ def computer_lock_config(self, computer_lock=None, computer_lock_key=None):
555
562
if computer_lock_key :
556
563
computer_lock = "custom"
557
564
if not computer_lock :
558
- raise IloError ("A value must be specified for computer_lock" )
565
+ raise ValueError ("A value must be specified for computer_lock" )
559
566
elements = [etree .Element ('COMPUTER_LOCK' , VALUE = computer_lock )]
560
567
if computer_lock_key :
561
568
elements .append (etree .Element ('COMPUTER_LOCK_KEY' , VALUE = computer_lock_key ))
0 commit comments