From e8283abea755fea07e60549e4bede8e75ebdf50a Mon Sep 17 00:00:00 2001 From: tierno Date: Tue, 17 Jan 2017 17:35:27 +0000 Subject: [PATCH] fixed a bug at deployment using public images Signed-off-by: tierno --- httpserver.py | 18 +++++++++++++++--- openvimd.py | 2 +- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/httpserver.py b/httpserver.py index 5d48beb..08ea403 100644 --- a/httpserver.py +++ b/httpserver.py @@ -1376,12 +1376,24 @@ def http_post_server_id(tenant_id): server['flavor']=content[0] #check image valid and take info result, content = my.db.get_table(FROM='tenants_images as ti right join images as i on ti.image_id=i.uuid', - SELECT=('path','metadata'), WHERE={'uuid':server['image_id'], "status":"ACTIVE"}, - WHERE_OR={'tenant_id':tenant_id, 'public': 'yes'}, WHERE_AND_OR="AND", DISTINCT=True) + SELECT=('path', 'metadata', 'image_id'), + WHERE={'uuid':server['image_id'], "status":"ACTIVE"}, + WHERE_OR={'tenant_id':tenant_id, 'public': 'yes'}, + WHERE_AND_OR="AND", + DISTINCT=True) if result<=0: bottle.abort(HTTP_Not_Found, 'image_id %s not found or not ACTIVE' % server['image_id']) return - server['image']=content[0] + for image_dict in content: + if image_dict.get("image_id"): + break + else: + # insert in data base tenants_images + r2, c2 = my.db.new_row('tenants_images', {'image_id': server['image_id'], 'tenant_id': tenant_id}) + if r2<=0: + bottle.abort(HTTP_Not_Found, 'image_id %s cannot be used. Error %s' % (server['image_id'], c2)) + return + server['image']={"path": content[0]["path"], "metadata": content[0]["metadata"]} if "hosts_id" in server: result, content = my.db.get_table(FROM='hosts', SELECT=('uuid',), WHERE={'uuid': server['host_id']}) if result<=0: diff --git a/openvimd.py b/openvimd.py index d85e5b1..9cd321c 100755 --- a/openvimd.py +++ b/openvimd.py @@ -30,7 +30,7 @@ and host controllers __author__="Alfonso Tierno" __date__ ="$10-jul-2014 12:07:15$" -__version__="0.5.1-r507" +__version__="0.5.2-r516" version_date="Jan 2017" database_version="0.9" #expected database schema version -- 2.25.1