@ -7,6 +7,7 @@ __metaclass__ = type
import json
import json
import re
import re
from ansible . module_utils . urls import open_url
from ansible . module_utils . urls import open_url
from ansible . module_utils . _text import to_text
from ansible . module_utils . six . moves . urllib . error import URLError , HTTPError
from ansible . module_utils . six . moves . urllib . error import URLError , HTTPError
HEADERS = { ' content-type ' : ' application/json ' }
HEADERS = { ' content-type ' : ' application/json ' }
@ -35,8 +36,9 @@ class RedfishUtils(object):
except URLError as e :
except URLError as e :
return { ' ret ' : False , ' msg ' : " URL Error: %s " % e . reason }
return { ' ret ' : False , ' msg ' : " URL Error: %s " % e . reason }
# Almost all errors should be caught above, but just in case
# Almost all errors should be caught above, but just in case
except Exception :
except Exception as e :
return { ' ret ' : False , ' msg ' : " Unknown error " }
return { ' ret ' : False ,
' msg ' : ' Failed GET operation against Redfish API server: %s ' % to_text ( e ) }
return { ' ret ' : True , ' data ' : data }
return { ' ret ' : True , ' data ' : data }
def post_request ( self , uri , pyld , hdrs ) :
def post_request ( self , uri , pyld , hdrs ) :
@ -53,8 +55,9 @@ class RedfishUtils(object):
except URLError as e :
except URLError as e :
return { ' ret ' : False , ' msg ' : " URL Error: %s " % e . reason }
return { ' ret ' : False , ' msg ' : " URL Error: %s " % e . reason }
# Almost all errors should be caught above, but just in case
# Almost all errors should be caught above, but just in case
except Exception :
except Exception as e :
return { ' ret ' : False , ' msg ' : " Unknown error " }
return { ' ret ' : False ,
' msg ' : ' Failed POST operation against Redfish API server: %s ' % to_text ( e ) }
return { ' ret ' : True , ' resp ' : resp }
return { ' ret ' : True , ' resp ' : resp }
def patch_request ( self , uri , pyld , hdrs ) :
def patch_request ( self , uri , pyld , hdrs ) :
@ -71,8 +74,9 @@ class RedfishUtils(object):
except URLError as e :
except URLError as e :
return { ' ret ' : False , ' msg ' : " URL Error: %s " % e . reason }
return { ' ret ' : False , ' msg ' : " URL Error: %s " % e . reason }
# Almost all errors should be caught above, but just in case
# Almost all errors should be caught above, but just in case
except Exception :
except Exception as e :
return { ' ret ' : False , ' msg ' : " Unknown error " }
return { ' ret ' : False ,
' msg ' : ' Failed PATCH operation against Redfish API server: %s ' % to_text ( e ) }
return { ' ret ' : True , ' resp ' : resp }
return { ' ret ' : True , ' resp ' : resp }
def delete_request ( self , uri , pyld , hdrs ) :
def delete_request ( self , uri , pyld , hdrs ) :
@ -89,8 +93,9 @@ class RedfishUtils(object):
except URLError as e :
except URLError as e :
return { ' ret ' : False , ' msg ' : " URL Error: %s " % e . reason }
return { ' ret ' : False , ' msg ' : " URL Error: %s " % e . reason }
# Almost all errors should be caught above, but just in case
# Almost all errors should be caught above, but just in case
except Exception :
except Exception as e :
return { ' ret ' : False , ' msg ' : " Unknown error " }
return { ' ret ' : False ,
' msg ' : ' Failed DELETE operation against Redfish API server: %s ' % to_text ( e ) }
return { ' ret ' : True , ' resp ' : resp }
return { ' ret ' : True , ' resp ' : resp }
def _init_session ( self ) :
def _init_session ( self ) :