X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=httpserver.py;h=ce433aed7268908d4934561fa4172dbebf0f4bf6;hb=69a5739aef6bdc5e0ebc12ebfe6a4775e8211304;hp=88b1f0a745e33eac3f5daa3545d224ccdfe23611;hpb=24595390fde6736753946648ee083c178b60759c;p=osm%2Fopenvim.git diff --git a/httpserver.py b/httpserver.py index 88b1f0a..ce433ae 100644 --- a/httpserver.py +++ b/httpserver.py @@ -30,13 +30,15 @@ __author__="Alfonso Tierno" __date__ ="$10-jul-2014 12:07:15$" import bottle +import urlparse import yaml import json import threading import datetime import hashlib import os -import RADclass +import imp +#import only if needed because not needed in test mode. To allow an easier installation import RADclass from jsonschema import validate as js_v, exceptions as js_e import host_thread as ht from vim_schema import host_new_schema, host_edit_schema, tenant_new_schema, \ @@ -49,6 +51,8 @@ from vim_schema import host_new_schema, host_edit_schema, tenant_new_schema, \ global my global url_base global config_dic +global RADclass_module +RADclass=None #RADclass module is charged only if not in test mode url_base="/openvim" @@ -451,6 +455,18 @@ def check_valid_uuid(uuid): except js_e.ValidationError: return False + +def is_url(url): + ''' + Check if string value is a well-wormed url + :param url: string url + :return: True if is a valid url, False if is not well-formed + ''' + + parsed_url = urlparse.urlparse(url) + return parsed_url + + @bottle.error(400) @bottle.error(401) @bottle.error(404) @@ -522,9 +538,14 @@ def http_post_hosts(): ip_name=host['ip_name'] user=host['user'] password=host.get('password', None) + if not RADclass_module: + try: + RADclass_module = imp.find_module("RADclass") + except (IOError, ImportError) as e: + raise ImportError("Cannot import RADclass.py Openvim not properly installed" +str(e)) #fill rad info - rad = RADclass.RADclass() + rad = RADclass_module.RADclass() (return_status, code) = rad.obtain_RAD(user, password, ip_name) #return @@ -586,7 +607,6 @@ def http_post_hosts(): sriov['source_name'] = index index += 1 interfaces.append ({'pci':str(port_k), 'Mbps': port_v['speed']/1000000, 'sriovs': new_sriovs, 'mac':port_v['mac'], 'source_name':port_v['source_name']}) - #@TODO LA memoria devuelta por el RAD es incorrecta, almenos para IVY1, NFV100 memory=node['memory']['node_size'] / (1024*1024*1024) #memory=get_next_2pow(node['memory']['hugepage_nr']) host['numas'].append( {'numa_socket': node['id'], 'hugepages': node['memory']['hugepage_nr'], 'memory':memory, 'interfaces': interfaces, 'cores': cores } ) @@ -1022,10 +1042,11 @@ def http_get_images(tenant_id): ('id','name','description','path','public') ) if tenant_id=='any': from_ ='images' + where_or_ = None else: - from_ ='tenants_images inner join images on tenants_images.image_id=images.uuid' - where_['tenant_id'] = tenant_id - result, content = my.db.get_table(SELECT=select_, FROM=from_, WHERE=where_, LIMIT=limit_) + from_ ='tenants_images right join images on tenants_images.image_id=images.uuid' + where_or_ = {'tenant_id': tenant_id, 'public': 'yes'} + result, content = my.db.get_table(SELECT=select_, FROM=from_, WHERE=where_, WHERE_OR=where_or_, WHERE_AND_OR="AND", LIMIT=limit_) if result < 0: print "http_get_images Error", content bottle.abort(-result, content) @@ -1047,11 +1068,12 @@ def http_get_image_id(tenant_id, image_id): ('id','name','description','progress', 'status','path', 'created', 'updated','public') ) if tenant_id=='any': from_ ='images' + where_or_ = None else: - from_ ='tenants_images as ti inner join images as i on ti.image_id=i.uuid' - where_['tenant_id'] = tenant_id + from_ ='tenants_images as ti right join images as i on ti.image_id=i.uuid' + where_or_ = {'tenant_id': tenant_id, 'public': "yes"} where_['uuid'] = image_id - result, content = my.db.get_table(SELECT=select_, FROM=from_, WHERE=where_, LIMIT=limit_) + result, content = my.db.get_table(SELECT=select_, FROM=from_, WHERE=where_, WHERE_OR=where_or_, WHERE_AND_OR="AND", LIMIT=limit_) if result < 0: print "http_get_images error %d %s" % (result, content) @@ -1091,6 +1113,8 @@ def http_post_images(tenant_id): image_file = http_content['image'].get('path',None) if os.path.exists(image_file): http_content['image']['checksum'] = md5(image_file) + elif is_url(image_file): + pass else: if not host_test_mode: content = "Image file not found"