griddynamics better logging
This commit is contained in:
commit
d96f3c5462
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
*.pyc
|
||||
.idea
|
@ -45,9 +45,9 @@ copyright = u'Rackspace, based on work by Jacob Kaplan-Moss'
|
||||
# built documents.
|
||||
#
|
||||
# The short X.Y version.
|
||||
version = '2.4'
|
||||
version = '2.5'
|
||||
# The full version, including alpha/beta/rc tags.
|
||||
release = '2.4.4'
|
||||
release = '2.5.0'
|
||||
|
||||
# The language for content autogenerated by Sphinx. Refer to documentation
|
||||
# for a list of supported languages.
|
||||
|
@ -2,10 +2,10 @@
|
||||
Release notes
|
||||
=============
|
||||
|
||||
2.5.0 (June 2, 2011) - soon
|
||||
2.5.0 (June 3, 2011)
|
||||
=================
|
||||
|
||||
* better logging
|
||||
* better logging thanks to GridDynamics
|
||||
|
||||
2.4.4 (June 1, 2011)
|
||||
=================
|
||||
|
@ -7,6 +7,8 @@ import time
|
||||
import urlparse
|
||||
import urllib
|
||||
import httplib2
|
||||
import logging
|
||||
|
||||
try:
|
||||
import json
|
||||
except ImportError:
|
||||
@ -20,6 +22,7 @@ if not hasattr(urlparse, 'parse_qsl'):
|
||||
import novaclient
|
||||
from novaclient import exceptions
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
class OpenStackClient(httplib2.Http):
|
||||
|
||||
@ -37,6 +40,23 @@ class OpenStackClient(httplib2.Http):
|
||||
# httplib2 overrides
|
||||
self.force_exception_to_status_code = True
|
||||
|
||||
def http_log(self, args, kwargs, resp, body):
|
||||
if not _logger.isEnabledFor(logging.DEBUG):
|
||||
return
|
||||
|
||||
string_parts = ['curl -i']
|
||||
for element in args:
|
||||
if element in ('GET','POST'):
|
||||
string_parts.append(' -X %s' % element)
|
||||
else:
|
||||
string_parts.append(' %s' % element)
|
||||
|
||||
for element in kwargs['headers']:
|
||||
string_parts.append(' -H "%s: %s"' % (element,kwargs['headers'][element]))
|
||||
|
||||
_logger.debug("REQ: %s\n" % "".join(string_parts))
|
||||
_logger.debug("RESP:%s %s\n", resp,body)
|
||||
|
||||
def request(self, *args, **kwargs):
|
||||
kwargs.setdefault('headers', {})
|
||||
kwargs['headers']['User-Agent'] = self.USER_AGENT
|
||||
@ -44,12 +64,10 @@ class OpenStackClient(httplib2.Http):
|
||||
kwargs['headers']['Content-Type'] = 'application/json'
|
||||
kwargs['body'] = json.dumps(kwargs['body'])
|
||||
|
||||
if httplib2.debuglevel == 1:
|
||||
print "ARGS:", args
|
||||
resp, body = super(OpenStackClient, self).request(*args, **kwargs)
|
||||
if httplib2.debuglevel == 1:
|
||||
print "RESPONSE", resp
|
||||
print "BODY", body
|
||||
|
||||
self.http_log(args, kwargs, resp, body)
|
||||
|
||||
if body:
|
||||
try:
|
||||
body = json.loads(body)
|
||||
|
@ -21,13 +21,16 @@ class FlavorManager(base.ManagerWithFind):
|
||||
"""
|
||||
resource_class = Flavor
|
||||
|
||||
def list(self):
|
||||
def list(self, detailed=True):
|
||||
"""
|
||||
Get a list of all flavors.
|
||||
|
||||
:rtype: list of :class:`Flavor`.
|
||||
"""
|
||||
return self._list("/flavors/detail", "flavors")
|
||||
detail = ""
|
||||
if detailed:
|
||||
detail = "/detail"
|
||||
return self._list("/flavors%s" % detail, "flavors")
|
||||
|
||||
def get(self, flavor):
|
||||
"""
|
||||
|
@ -35,13 +35,17 @@ class ImageManager(base.ManagerWithFind):
|
||||
"""
|
||||
return self._get("/images/%s" % base.getid(image), "image")
|
||||
|
||||
def list(self):
|
||||
def list(self, detailed=True):
|
||||
"""
|
||||
Get a list of all images.
|
||||
|
||||
:rtype: list of :class:`Image`
|
||||
"""
|
||||
return self._list("/images/detail", "images")
|
||||
detail = ""
|
||||
if detailed:
|
||||
detail = "/detail"
|
||||
return self._list("/images%s" % detail, "images")
|
||||
|
||||
|
||||
def create(self, name, server):
|
||||
"""
|
||||
|
@ -20,13 +20,16 @@ class IPGroup(base.Resource):
|
||||
class IPGroupManager(base.ManagerWithFind):
|
||||
resource_class = IPGroup
|
||||
|
||||
def list(self):
|
||||
def list(self, detailed=True):
|
||||
"""
|
||||
Get a list of all groups.
|
||||
|
||||
:rtype: list of :class:`IPGroup`
|
||||
"""
|
||||
return self._list("/shared_ip_groups/detail", "sharedIpGroups")
|
||||
detail = ""
|
||||
if detailed:
|
||||
detail = "/detail"
|
||||
return self._list("/shared_ip_groups%s" % detail, "sharedIpGroups")
|
||||
|
||||
def get(self, group):
|
||||
"""
|
||||
|
@ -187,9 +187,10 @@ class ServerManager(base.BootingManagerWithFind):
|
||||
"""
|
||||
return self._get("/servers/%s" % base.getid(server), "server")
|
||||
|
||||
def list(self, reservation_id=None):
|
||||
def list(self, detailed=True, reservation_id=None):
|
||||
"""
|
||||
Get a list of servers.
|
||||
Optional detailed returns details server info.
|
||||
Optional reservation_id only returns instances with that
|
||||
reservation_id.
|
||||
|
||||
@ -198,7 +199,11 @@ class ServerManager(base.BootingManagerWithFind):
|
||||
reservation = ""
|
||||
if reservation_id:
|
||||
reservation = "?reservation_id=%s" % reservation_id
|
||||
return self._list("/servers/detail%s" % reservation, "servers")
|
||||
|
||||
detail = ""
|
||||
if detailed:
|
||||
detail = "/detail"
|
||||
return self._list("/servers%s%s" % (detail, reservation), "servers")
|
||||
|
||||
def create(self, name, image, flavor, ipgroup=None, meta=None, files=None,
|
||||
zone_blob=None, reservation_id=None):
|
||||
|
@ -80,12 +80,15 @@ class ZoneManager(base.BootingManagerWithFind):
|
||||
"""
|
||||
return self._get("/zones/%s" % base.getid(zone), "zone")
|
||||
|
||||
def list(self):
|
||||
def list(self, detailed=True):
|
||||
"""
|
||||
Get a list of child zones.
|
||||
:rtype: list of :class:`Zone`
|
||||
"""
|
||||
return self._list("/zones/detail", "zones")
|
||||
detail = ""
|
||||
if detailed:
|
||||
detail = "/detail"
|
||||
return self._list("/zones%s" % detail, "zones")
|
||||
|
||||
def create(self, api_url, username, password):
|
||||
"""
|
||||
|
2
setup.py
2
setup.py
@ -11,7 +11,7 @@ if sys.version_info < (2,6):
|
||||
|
||||
setup(
|
||||
name = "python-novaclient",
|
||||
version = "2.4.4",
|
||||
version = "2.5.0",
|
||||
description = "Client library for OpenStack Nova API",
|
||||
long_description = read('README.rst'),
|
||||
url = 'https://github.com/rackspace/python-novaclient',
|
||||
|
@ -12,6 +12,12 @@ def test_list_flavors():
|
||||
[assert_isinstance(f, Flavor) for f in fl]
|
||||
|
||||
|
||||
def test_list_flavors_undetailed():
|
||||
fl = cs.flavors.list(detailed=False)
|
||||
cs.assert_called('GET', '/flavors')
|
||||
[assert_isinstance(f, Flavor) for f in fl]
|
||||
|
||||
|
||||
def test_get_flavor_details():
|
||||
f = cs.flavors.get(1)
|
||||
cs.assert_called('GET', '/flavors/1')
|
||||
|
@ -12,6 +12,12 @@ def test_list_images():
|
||||
[assert_isinstance(i, Image) for i in il]
|
||||
|
||||
|
||||
def test_list_images_undetailed():
|
||||
il = cs.images.list(detailed=False)
|
||||
cs.assert_called('GET', '/images')
|
||||
[assert_isinstance(i, Image) for i in il]
|
||||
|
||||
|
||||
def test_get_image_details():
|
||||
i = cs.images.get(1)
|
||||
cs.assert_called('GET', '/images/1')
|
||||
|
@ -12,6 +12,12 @@ def test_list_ipgroups():
|
||||
[assert_isinstance(ipg, IPGroup) for ipg in ipl]
|
||||
|
||||
|
||||
def test_list_ipgroups_undetailed():
|
||||
ipl = cs.ipgroups.list(detailed=False)
|
||||
cs.assert_called('GET', '/shared_ip_groups')
|
||||
[assert_isinstance(ipg, IPGroup) for ipg in ipl]
|
||||
|
||||
|
||||
def test_get_ipgroup():
|
||||
ipg = cs.ipgroups.get(1)
|
||||
cs.assert_called('GET', '/shared_ip_groups/1')
|
||||
|
@ -13,6 +13,12 @@ def test_list_servers():
|
||||
[assert_isinstance(s, Server) for s in sl]
|
||||
|
||||
|
||||
def test_list_servers_undetailed():
|
||||
sl = cs.servers.list(detailed=False)
|
||||
cs.assert_called('GET', '/servers')
|
||||
[assert_isinstance(s, Server) for s in sl]
|
||||
|
||||
|
||||
def test_get_server_details():
|
||||
s = cs.servers.get(1234)
|
||||
cs.assert_called('GET', '/servers/1234')
|
||||
|
@ -13,6 +13,12 @@ def test_list_zones():
|
||||
[assert_isinstance(s, Zone) for s in sl]
|
||||
|
||||
|
||||
def test_list_zones_undetailed():
|
||||
sl = os.zones.list(detailed=False)
|
||||
os.assert_called('GET', '/zones')
|
||||
[assert_isinstance(s, Zone) for s in sl]
|
||||
|
||||
|
||||
def test_get_zone_details():
|
||||
s = os.zones.get(1)
|
||||
os.assert_called('GET', '/zones/1')
|
||||
|
Loading…
x
Reference in New Issue
Block a user