kea_connector2.py 1.12 KB
Newer Older
1 2 3 4 5
# Copyright (C) 2017 Internet Systems Consortium, Inc. ("ISC")
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
6

7 8 9
"""
This is PYTHON 2.x version of HTTP connection establishment
"""
10 11 12

import httplib

13 14 15
from kea_conn import CAResponse # CARequest

def send_to_control_agent(params):
Tomek Mrugalski's avatar
Tomek Mrugalski committed
16 17 18
    """ Sends a request to Control Agent, receives a response and returns it."""

    # Establish HTTP connection first.
19 20
    conn = httplib.HTTPConnection(params.http_host, params.http_port)
    conn.connect()
21

22 23
    # Use POST to send it
    _ = conn.putrequest('POST', params.path)
24

25 26 27 28
    # Send the headers first
    for k in params.headers:
        conn.putheader(k, params.headers[k])
    conn.endheaders()
29

Tomek Mrugalski's avatar
Tomek Mrugalski committed
30
    # Send the body (i.e. the actual content)
31
    conn.send(params.content)
32

33 34
    # Now get the response
    resp = conn.getresponse()
35

36 37 38 39
    # Now get the response details, put it in CAResponse and
    # return it
    result = CAResponse(resp.status, resp.reason, resp.read())
    conn.close()
40

41
    return result