Example #1
0
def http_get(ctl, args):
    # ignore = args['--force']
    timeout = args['--timeout']
    if timeout is not None:
        timeout = int(timeout)
    # import hashlib
    template_url = "http://{}:{}/restconf/{}"
    url = template_url.format(ctl.ipAddr, ctl.portNum, args['<resource>'])
    status = OperStatus()
    # resourcehash = int(hashlib.md5(resource).hexdigest(), 16)
    # if not (os.path.exists(utils.get_cachedir())):
    #     utils.prepare_directory(utils.get_cachedir())
    # filename = os.path.join(utils.get_cachedir(), str(resourcehash))
    # (buf, status) = utils.check_file_and_print(filename)
    # if ignore or not status:
    # retval = _http_get(ctl, resource)

    resp = ctl.http_get_request(url, data=None, headers=None, timeout=timeout)
    if(resp is None):
        status.set_status(STATUS.CONN_ERROR)
    elif(resp.content is None):
        status.set_status(STATUS.CTRL_INTERNAL_ERROR)
    elif(resp.status_code == 200 or resp.status_code == 204):
        status.set_status(STATUS.OK)
    else:
        status.set_status(STATUS.HTTP_ERROR, resp)
    return Result(status, resp)
Example #2
0
def http_delete(ctl, args):
    # ignore = args['--force']
    template_url = "http://{}:{}/restconf/{}"
    status = OperStatus()
    url = template_url.format(ctl.ipAddr, ctl.portNum, args['<resource>'])
    resp = ctl.http_delete_request(url, data=None, headers=None)
    if(resp is None):
        status.set_status(STATUS.CONN_ERROR)
    elif(resp.content is None):
        status.set_status(STATUS.CTRL_INTERNAL_ERROR)
    elif(resp.status_code == 200 or resp.status_code == 204):
        status.set_status(STATUS.OK)
    else:
        status.set_status(STATUS.HTTP_ERROR, resp)
    return Result(status, resp)
Example #3
0
def http_put(ctl, args):
    if args['--payload']:
        payload = args['<payload>']
    elif args['--file']:
        payload = util.load_json_file(args['<file>'])
    status = OperStatus()
    headers = {'content-type': 'application/yang.data+json',
               'accept': 'text/json, text/html, application/xml, */*'}
    template_url = "http://{}:{}/restconf/{}"
    url = template_url.format(ctl.ipAddr, ctl.portNum, args['<resource>'])
    resp = ctl.http_put_request(url, json.dumps(payload), headers)
    if(resp is None):
        status.set_status(STATUS.CONN_ERROR)
    elif(resp.content is None):
        status.set_status(STATUS.CTRL_INTERNAL_ERROR)
    elif(resp.status_code == 200 or resp.status_code == 204):
        status.set_status(STATUS.OK)
    else:
        status.set_status(STATUS.HTTP_ERROR, resp)
    return Result(status, resp)