conn = HTTPConnection(self.oarserver['ip'],
self.oarserver['port'])
conn.request("GET", self.oarserver['uri'], data, headers)
- resp = (conn.getresponse()).read()
+ resp = conn.getresponse()
+ body = resp.read()
+ except Exception as error:
+ logger.log_exc("GET_OAR_SRVR : Connection error: %s "
+ % (error))
+ raise Exception ("GET_OAR_SRVR : Connection error %s " %(error))
+
+ finally:
conn.close()
- except HTTPException, error:
- logger.log_exc("GET_OAR_SRVR : Problem with OAR server : %s "
- % (error))
+ # except HTTPException, error:
+ # logger.log_exc("GET_OAR_SRVR : Problem with OAR server : %s "
+ # % (error))
#raise ServerError("GET_OAR_SRVR : Could not reach OARserver")
+ if resp.status >= 400:
+ raise ValueError ("Response Error %s, %s" %(resp.status,
+ resp.reason))
try:
- js_dict = json.loads(resp)
+ js_dict = json.loads(body)
#print "\r\n \t\t\t js_dict keys" , js_dict.keys(), " \r\n", js_dict
return js_dict
except ValueError, error:
logger.log_exc("Failed to parse Server Response: %s ERROR %s"
- % (js_dict, error))
+ % (body, error))
#raise ServerError("Failed to parse Server Response:" + js)
conn = HTTPConnection(self.oarserver['ip'], \
self.oarserver['port'])
conn.request("POST", self.oarserver['uri'], data, headers)
- resp = (conn.getresponse()).read()
- conn.close()
+ resp = conn.getresponse()
+ body = resp.read()
+
except NotConnected:
logger.log_exc("POSTRequestToOARRestAPI NotConnected ERROR: \
data %s \r\n \t\n \t\t headers %s uri %s" \
%(data,headers,self.oarserver['uri']))
+ except Exception as error:
+ logger.log_exc("POST_OAR_SERVER : Connection error: %s "
+ % (error))
+ raise Exception ("POST_OAR_SERVER : Connection error %s " %(error))
+
+ finally:
+ conn.close()
+
+ if resp.status >= 400:
+ raise ValueError ("Response Error %s, %s" %(resp.status,
+ resp.reason))
- #raise ServerError("POST_OAR_SRVR : error")
try:
- answer = json.loads(resp)
+ answer = json.loads(body)
logger.debug("POSTRequestToOARRestAPI : answer %s" % (answer))
return answer
'archi': self.AddHardwareType,
'state': self.AddBootState,
'id': self.AddOarNodeId,
+ 'mobility_type': self.AddMobilityType,
}
# """
# tuplelist.append(('radio', str(value)))
+ def AddMobilityType(self, tuplelist, value):
+ """Adds which kind of mobility it is, train or roomba robot.
+
+ :param tuplelist: tuple list on which to add the node's mobility status.
+ The tuplelist is the value associated with the node's id in the
+ OARGETParser's dictionary node_dictlist.
+ :param value: tells if a node is a mobile node or not. The value is
+ found in the json.
+
+ :type tuplelist: list
+ :type value: integer
+
+ """
+ tuplelist.append(('mobility_type', str(value)))
+
def AddMobility(self, tuplelist, value):
"""Add if the node is a mobile node or not to the tuple list.
:rtype: dict
.. warning:: unused
- .. seealso:: GetSites (IotlabTestbedAPI)
+ .. seealso:: GetSites (IotlabShell)
"""
self.ChangeRawJsonDependingOnApilibVersion()