Merge pull request #242 from mpeuster/master
[osm/vim-emu.git] / src / emuvim / api / openstack / openstack_dummies / glance_dummy_api.py
index d9ca091..8113397 100755 (executable)
@@ -1,6 +1,7 @@
 from flask_restful import Resource
 from flask import Response, request
 from emuvim.api.openstack.openstack_dummies.base_openstack_dummy import BaseOpenstackDummy
+from emuvim.api.openstack.helper import get_host
 import logging
 import json
 
@@ -134,7 +135,10 @@ class GlanceListImagesApi(Resource):
         like the image was just created to make orchestrators, like OSM, happy.
         """
         LOG.debug("API CALL: %s POST" % str(self.__class__.__name__))
-        body_data = json.loads(request.data)
+        try:
+            body_data = json.loads(request.data)
+        except:
+            body_data = dict()
         # lets see what we should create
         img_name = request.headers.get("X-Image-Meta-Name")
         img_size = request.headers.get("X-Image-Meta-Size")
@@ -179,7 +183,7 @@ class GlanceListImagesApi(Resource):
         resp['image'] = f
         # build actual response with headers and everything
         r = Response(json.dumps(resp), status=201, mimetype="application/json")
-        r.headers.add("Location", "http://%s:%d/v1/images/%s" % (self.api.ip,
+        r.headers.add("Location", "http://%s:%d/v1/images/%s" % (get_host(request),
                                                                  self.api.port,
                                                                  img_id))
         return r