Skip to content

Commit

Permalink
Adds glance registry req id to glance api logging
Browse files Browse the repository at this point in the history
Fixes bug 1036409

Change-Id: Ifadfa74ba4b8de854d248c4c72e5c195e8bdc4ed
  • Loading branch information
isethi committed Aug 20, 2012
1 parent 564c11e commit 56b80d7
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions glance/registry/client.py
Expand Up @@ -24,8 +24,11 @@

from glance.common.client import BaseClient
from glance.common import crypt
import glance.openstack.common.log as logging
from glance.registry.api.v1 import images

LOG = logging.getLogger(__name__)


class RegistryClient(BaseClient):

Expand Down Expand Up @@ -80,6 +83,22 @@ def get_images(self, **kwargs):
image = self.decrypt_metadata(image)
return image_list

def do_request(self, method, action, **kwargs):
try:
res = super(RegistryClient, self).do_request(method,
action, **kwargs)
status = res.status
request_id = res.getheader('x-openstack-request-id')
msg = _("Registry request %(method)s %(action)s HTTP %(status)s"\
" request id %(request_id)s")
LOG.debug(msg % locals())

except:
LOG.exception(_("Registry request %(method)s %(action)s Exception")
% locals())
raise
return res

def get_images_detailed(self, **kwargs):
"""
Returns a list of detailed image data mappings from Registry
Expand Down Expand Up @@ -118,7 +137,7 @@ def add_image(self, image_metadata):
image_metadata['image'])
body = json.dumps(image_metadata)

res = self.do_request("POST", "/images", body, headers=headers)
res = self.do_request("POST", "/images", body=body, headers=headers)
# Registry returns a JSONified dict(image=image_info)
data = json.loads(res.read())
image = data['image']
Expand All @@ -142,7 +161,8 @@ def update_image(self, image_id, image_metadata, purge_props=False):
if purge_props:
headers["X-Glance-Registry-Purge-Props"] = "true"

res = self.do_request("PUT", "/images/%s" % image_id, body, headers)
res = self.do_request("PUT", "/images/%s" % image_id, body=body,
headers=headers)
data = json.loads(res.read())
image = data['image']
return self.decrypt_metadata(image)
Expand Down Expand Up @@ -181,7 +201,7 @@ def replace_members(self, image_id, member_data):
headers = {'Content-Type': 'application/json', }

res = self.do_request("PUT", "/images/%s/members" % image_id,
body, headers)
body=body, headers=headers)
return self.get_status_code(res) == 204

def add_member(self, image_id, member_id, can_share=None):
Expand All @@ -193,8 +213,9 @@ def add_member(self, image_id, member_id, can_share=None):
body = json.dumps(dict(member=dict(can_share=can_share)))
headers['Content-Type'] = 'application/json'

res = self.do_request("PUT", "/images/%s/members/%s" %
(image_id, member_id), body, headers)
url = "/images/%s/members/%s" % (image_id, member_id)
res = self.do_request("PUT", url, body=body,
headers=headers)
return self.get_status_code(res) == 204

def delete_member(self, image_id, member_id):
Expand Down

0 comments on commit 56b80d7

Please sign in to comment.