Juan Hernandez has uploaded a new change for review.

Change subject: sdk: Add debug logging of the HTTP messages
......................................................................

sdk: Add debug logging of the HTTP messages

Currently it is quite difficult to analyze what is going back and
forward between the SDK and the RESTAPI, specially if using HTTPS as
sniffing traffic is not an option.

This patch adds logging so that the HTTP traffic will be sent to the log
if debug is enabled. The debug output, for the creation of a cluster,
for example, will look like this:

2012-04-27 19:02:07,063 DEBUG Sending request with method "POST" and URL 
"/api/clusters".
2012-04-27 19:02:07,064 DEBUG Sending request header with name "Content-type" 
and value "application/xml".
2012-04-27 19:02:07,064 DEBUG Sending request header with name "Authorization" 
and value "Basic ***".
2012-04-27 19:02:07,064 DEBUG Sending request body "<cluster>
    <name>mycluster</name>
    <cpu id="Intel Nehalem Family"/>
    <data_center href="/api/datacenters/a802c8c9-1c39-4387-8540-7faa10b64564" 
id="a802c8c9-1c39-4387-8540-7faa10b64564">
        <name>mydc</name>
        <link 
href="/api/datacenters/a802c8c9-1c39-4387-8540-7faa10b64564/storagedomains" 
rel="storagedomains"/>
        <link 
href="/api/datacenters/a802c8c9-1c39-4387-8540-7faa10b64564/permissions" 
rel="permissions"/>
        <storage_type>iscsi</storage_type>
        <version major="3" minor="0"/>
        <supported_versions>
            <version major="3" minor="1"/>
            <version major="3" minor="0"/>
        </supported_versions>
        <status>
            <state>uninitialized</state>
        </status>
    </data_center>
    <version major="3" minor="0"/>
</cluster>
".
2012-04-27 19:02:07,166 DEBUG Received response status code 201 and reason 
"Created".
2012-04-27 19:02:07,166 DEBUG Received response header with name 
"content-length" and value "876".
2012-04-27 19:02:07,166 DEBUG Received response header with name "set-cookie" 
and value "JSESSIONID=DNoRYO44rJFeLPNuoLxMpqmu; Path=/api".
2012-04-27 19:02:07,166 DEBUG Received response header with name "server" and 
value "Apache-Coyote/1.1".
2012-04-27 19:02:07,166 DEBUG Received response header with name "location" and 
value 
"http://localhost:8080/api/api/clusters/b8652596-908a-11e1-b522-73448ac46353";.
2012-04-27 19:02:07,166 DEBUG Received response header with name "date" and 
value "Fri, 27 Apr 2012 17:02:06 GMT".
2012-04-27 19:02:07,167 DEBUG Received response header with name "content-type" 
and value "application/xml".
2012-04-27 19:02:07,167 DEBUG Received response body "<?xml version="1.0" 
encoding="UTF-8" standalone="yes"?>
<cluster href="/api/clusters/b8652596-908a-11e1-b522-73448ac46353" 
id="b8652596-908a-11e1-b522-73448ac46353">
    <name>mycluster</name>
    <link href="/api/clusters/b8652596-908a-11e1-b522-73448ac46353/networks" 
rel="networks"/>
    <link href="/api/clusters/b8652596-908a-11e1-b522-73448ac46353/permissions" 
rel="permissions"/>
    <cpu id="Intel Nehalem Family"/>
    <data_center href="/api/datacenters/a802c8c9-1c39-4387-8540-7faa10b64564" 
id="a802c8c9-1c39-4387-8540-7faa10b64564"/>
    <memory_policy>
        <overcommit percent="200"/>
        <transparent_hugepages>
            <enabled>true</enabled>
        </transparent_hugepages>
    </memory_policy>
    <scheduling_policy/>
    <version major="3" minor="0"/>
    <error_handling>
        <on_error>migrate</on_error>
    </error_handling>
</cluster>
".

The logging mechanism used is the standard python logging module. Debug
output can be enabled in the program using the SDK as follows:

handler = logging.StreamHandler(sys.stdout)
handler.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
handler.setFormatter(formatter)
logging.root.addHandler(handler)
logging.root.setLevel(logging.DEBUG)

Change-Id: I82d9101ebae8197df6554992d583faacf6bc2a9d
---
M src/ovirtsdk/infrastructure/proxy.py
M src/ovirtsdk/web/connection.py
2 files changed, 43 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine-sdk refs/changes/34/3934/1
--
To view, visit http://gerrit.ovirt.org/3934
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I82d9101ebae8197df6554992d583faacf6bc2a9d
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine-sdk
Gerrit-Branch: master
Gerrit-Owner: Juan Hernandez <juan.hernan...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to