<s> import json <EOL> import re <EOL> import uuid <EOL> import webob . dec <EOL> import webob . exc <EOL> from ooi import utils <EOL> import ooi . wsgi <EOL> application_url = "<STR_LIT>" <EOL> tenants = { <EOL> "<STR_LIT:foo>" : { "<STR_LIT:id>" : uuid . uuid4 ( ) . hex , <EOL> "<STR_LIT:name>" : "<STR_LIT:foo>" } , <EOL> "<STR_LIT:bar>" : { "<STR_LIT:id>" : uuid . uuid4 ( ) . hex , <EOL> "<STR_LIT:name>" : "<STR_LIT:bar>" } , <EOL> "<STR_LIT>" : { "<STR_LIT:id>" : uuid . uuid4 ( ) . hex , <EOL> "<STR_LIT:name>" : "<STR_LIT>" } , <EOL> } <EOL> flavors = { <EOL> <NUM_LIT:1> : { <EOL> "<STR_LIT:id>" : <NUM_LIT:1> , <EOL> "<STR_LIT:name>" : "<STR_LIT:foo>" , <EOL> "<STR_LIT>" : <NUM_LIT:2> , <EOL> "<STR_LIT>" : <NUM_LIT> , <EOL> "<STR_LIT>" : <NUM_LIT:10> , <EOL> } , <EOL> <NUM_LIT:2> : { <EOL> "<STR_LIT:id>" : <NUM_LIT:2> , <EOL> "<STR_LIT:name>" : "<STR_LIT:bar>" , <EOL> "<STR_LIT>" : <NUM_LIT:4> , <EOL> "<STR_LIT>" : <NUM_LIT> , <EOL> "<STR_LIT>" : <NUM_LIT:20> , <EOL> } <EOL> } <EOL> images = { <EOL> "<STR_LIT:foo>" : { <EOL> "<STR_LIT:id>" : "<STR_LIT:foo>" , <EOL> "<STR_LIT:name>" : "<STR_LIT:foo>" , <EOL> } , <EOL> "<STR_LIT:bar>" : { <EOL> "<STR_LIT:id>" : "<STR_LIT:bar>" , <EOL> "<STR_LIT:name>" : "<STR_LIT:bar>" , <EOL> } <EOL> } <EOL> volumes = { <EOL> tenants [ "<STR_LIT:foo>" ] [ "<STR_LIT:id>" ] : [ <EOL> { <EOL> "<STR_LIT:id>" : uuid . uuid4 ( ) . hex , <EOL> "<STR_LIT>" : "<STR_LIT:foo>" , <EOL> "<STR_LIT:size>" : <NUM_LIT:2> , <EOL> "<STR_LIT:status>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : [ ] , <EOL> } , <EOL> { <EOL> "<STR_LIT:id>" : uuid . uuid4 ( ) . hex , <EOL> "<STR_LIT>" : "<STR_LIT:bar>" , <EOL> "<STR_LIT:size>" : <NUM_LIT:3> , <EOL> "<STR_LIT:status>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : [ ] , <EOL> } , <EOL> { <EOL> "<STR_LIT:id>" : uuid . uuid4 ( ) . hex , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:size>" : <NUM_LIT:5> , <EOL> "<STR_LIT:status>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : [ ] , <EOL> } , <EOL> ] , <EOL> tenants [ "<STR_LIT:bar>" ] [ "<STR_LIT:id>" ] : [ ] , <EOL> tenants [ "<STR_LIT>" ] [ "<STR_LIT:id>" ] : [ <EOL> { <EOL> "<STR_LIT:id>" : uuid . uuid4 ( ) . hex , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:size>" : <NUM_LIT:5> , <EOL> "<STR_LIT:status>" : "<STR_LIT>" , <EOL> } , <EOL> ] , <EOL> } <EOL> pools = { <EOL> tenants [ "<STR_LIT:foo>" ] [ "<STR_LIT:id>" ] : [ <EOL> { <EOL> "<STR_LIT:id>" : "<STR_LIT:foo>" , <EOL> "<STR_LIT:name>" : "<STR_LIT:foo>" , <EOL> } , <EOL> { <EOL> "<STR_LIT:id>" : "<STR_LIT:bar>" , <EOL> "<STR_LIT:name>" : "<STR_LIT:bar>" , <EOL> } <EOL> ] , <EOL> tenants [ "<STR_LIT:bar>" ] [ "<STR_LIT:id>" ] : [ ] , <EOL> tenants [ "<STR_LIT>" ] [ "<STR_LIT:id>" ] : [ <EOL> { <EOL> "<STR_LIT:id>" : "<STR_LIT>" , <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> } , <EOL> ] , <EOL> } <EOL> linked_vm_id = uuid . uuid4 ( ) . hex <EOL> allocated_ip = "<STR_LIT>" <EOL> floating_ips = { <EOL> tenants [ "<STR_LIT:foo>" ] [ "<STR_LIT:id>" ] : [ ] , <EOL> tenants [ "<STR_LIT:bar>" ] [ "<STR_LIT:id>" ] : [ ] , <EOL> tenants [ "<STR_LIT>" ] [ "<STR_LIT:id>" ] : [ <EOL> { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:id>" : uuid . uuid4 ( ) . hex , <EOL> "<STR_LIT>" : linked_vm_id , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : pools [ tenants [ "<STR_LIT>" ] [ "<STR_LIT:id>" ] ] [ <NUM_LIT:0> ] [ "<STR_LIT:name>" ] , <EOL> } , <EOL> { <EOL> "<STR_LIT>" : None , <EOL> "<STR_LIT:id>" : uuid . uuid4 ( ) . hex , <EOL> "<STR_LIT>" : None , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : pools [ tenants [ "<STR_LIT>" ] [ "<STR_LIT:id>" ] ] [ <NUM_LIT:0> ] [ "<STR_LIT:name>" ] , <EOL> } , <EOL> ] , <EOL> } <EOL> servers = { <EOL> tenants [ "<STR_LIT:foo>" ] [ "<STR_LIT:id>" ] : [ <EOL> { <EOL> "<STR_LIT:id>" : uuid . uuid4 ( ) . hex , <EOL> "<STR_LIT:name>" : "<STR_LIT:foo>" , <EOL> "<STR_LIT>" : { "<STR_LIT:id>" : flavors [ <NUM_LIT:1> ] [ "<STR_LIT:id>" ] } , <EOL> "<STR_LIT:image>" : { "<STR_LIT:id>" : images [ "<STR_LIT:foo>" ] [ "<STR_LIT:id>" ] } , <EOL> "<STR_LIT:status>" : "<STR_LIT>" , <EOL> } , <EOL> { <EOL> "<STR_LIT:id>" : uuid . uuid4 ( ) . hex , <EOL> "<STR_LIT:name>" : "<STR_LIT:bar>" , <EOL> "<STR_LIT>" : { "<STR_LIT:id>" : flavors [ <NUM_LIT:2> ] [ "<STR_LIT:id>" ] } , <EOL> "<STR_LIT:image>" : { "<STR_LIT:id>" : images [ "<STR_LIT:bar>" ] [ "<STR_LIT:id>" ] } , <EOL> "<STR_LIT:status>" : "<STR_LIT>" , <EOL> } , <EOL> { <EOL> "<STR_LIT:id>" : uuid . uuid4 ( ) . hex , <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : { "<STR_LIT:id>" : flavors [ <NUM_LIT:1> ] [ "<STR_LIT:id>" ] } , <EOL> "<STR_LIT:image>" : { "<STR_LIT:id>" : images [ "<STR_LIT:bar>" ] [ "<STR_LIT:id>" ] } , <EOL> "<STR_LIT:status>" : "<STR_LIT>" , <EOL> } , <EOL> ] , <EOL> tenants [ "<STR_LIT:bar>" ] [ "<STR_LIT:id>" ] : [ ] , <EOL> tenants [ "<STR_LIT>" ] [ "<STR_LIT:id>" ] : [ <EOL> { <EOL> "<STR_LIT:id>" : linked_vm_id , <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : { "<STR_LIT:id>" : flavors [ <NUM_LIT:1> ] [ "<STR_LIT:id>" ] } , <EOL> "<STR_LIT:image>" : { "<STR_LIT:id>" : images [ "<STR_LIT:bar>" ] [ "<STR_LIT:id>" ] } , <EOL> "<STR_LIT:status>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : [ <EOL> { "<STR_LIT:id>" : volumes [ tenants [ "<STR_LIT>" ] [ "<STR_LIT:id>" ] ] [ <NUM_LIT:0> ] [ "<STR_LIT:id>" ] } <EOL> ] , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : [ <EOL> { "<STR_LIT>" : floating_ips [ tenants [ "<STR_LIT>" ] [ "<STR_LIT:id>" ] ] [ <NUM_LIT:0> ] [ "<STR_LIT>" ] , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" } , <EOL> { "<STR_LIT>" : floating_ips [ tenants [ "<STR_LIT>" ] [ "<STR_LIT:id>" ] ] [ <NUM_LIT:0> ] [ "<STR_LIT>" ] , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" } , <EOL> ] <EOL> } <EOL> } <EOL> ] , <EOL> } <EOL> volumes [ tenants [ "<STR_LIT>" ] [ "<STR_LIT:id>" ] ] [ <NUM_LIT:0> ] [ "<STR_LIT>" ] = [ { <EOL> "<STR_LIT>" : servers [ tenants [ "<STR_LIT>" ] [ "<STR_LIT:id>" ] ] [ <NUM_LIT:0> ] [ "<STR_LIT:id>" ] , <EOL> "<STR_LIT>" : servers [ tenants [ "<STR_LIT>" ] [ "<STR_LIT:id>" ] ] [ <NUM_LIT:0> ] [ "<STR_LIT:id>" ] , <EOL> "<STR_LIT>" : uuid . uuid4 ( ) . hex , <EOL> "<STR_LIT>" : volumes [ tenants [ "<STR_LIT>" ] [ "<STR_LIT:id>" ] ] [ <NUM_LIT:0> ] [ "<STR_LIT:id>" ] , <EOL> "<STR_LIT>" : volumes [ tenants [ "<STR_LIT>" ] [ "<STR_LIT:id>" ] ] [ <NUM_LIT:0> ] [ "<STR_LIT:id>" ] , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:id>" : volumes [ tenants [ "<STR_LIT>" ] [ "<STR_LIT:id>" ] ] [ <NUM_LIT:0> ] [ "<STR_LIT:id>" ] , <EOL> } ] <EOL> def fake_query_results ( ) : <EOL> cats = [ ] <EOL> cats . append ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % application_url ) <EOL> cats . append ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % application_url ) <EOL> cats . append ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % application_url ) <EOL> cats . append ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % application_url ) <EOL> cats . append ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> cats . append ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> cats . append ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> cats . append ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> cats . append ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % application_url ) <EOL> cats . append ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % application_url ) <EOL> cats . append ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % application_url ) <EOL> cats . append ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % application_url ) <EOL> cats . append ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % application_url ) <EOL> cats . append ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % application_url ) <EOL> cats . append ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % application_url ) <EOL> cats . append ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> cats . append ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> cats . append ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> cats . append ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % application_url ) <EOL> cats . append ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> cats . append ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % application_url ) <EOL> cats . append ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % application_url ) <EOL> cats . append ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> cats . append ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> cats . append ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> cats . append ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> cats . append ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> cats . append ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> cats . append ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> result = [ ] <EOL> for c in cats : <EOL> result . append ( ( "<STR_LIT>" , c ) ) <EOL> return result <EOL> class FakeOpenStackFault ( ooi . wsgi . Fault ) : <EOL> _fault_names = { <EOL> <NUM_LIT> : "<STR_LIT>" , <EOL> <NUM_LIT> : "<STR_LIT>" , <EOL> <NUM_LIT> : "<STR_LIT>" , <EOL> <NUM_LIT> : "<STR_LIT>" , <EOL> <NUM_LIT> : "<STR_LIT>" , <EOL> <NUM_LIT> : "<STR_LIT>" , <EOL> <NUM_LIT> : "<STR_LIT>" , <EOL> <NUM_LIT> : "<STR_LIT>" , <EOL> <NUM_LIT> : "<STR_LIT>" , <EOL> <NUM_LIT> : "<STR_LIT>" , <EOL> <NUM_LIT> : "<STR_LIT>" , <EOL> <NUM_LIT> : "<STR_LIT>" } <EOL> @ webob . dec . wsgify ( ) <EOL> def __call__ ( self , req ) : <EOL> code = self . wrapped_exc . status_int <EOL> fault_name = self . _fault_names . get ( code ) <EOL> explanation = self . wrapped_exc . explanation <EOL> fault_data = { <EOL> fault_name : { <EOL> '<STR_LIT:code>' : code , <EOL> '<STR_LIT:message>' : explanation } } <EOL> self . wrapped_exc . body = utils . utf8 ( json . dumps ( fault_data ) ) <EOL> self . wrapped_exc . content_type = "<STR_LIT:application/json>" <EOL> return self . wrapped_exc <EOL> class FakeApp ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . routes = { } <EOL> for tenant in tenants . values ( ) : <EOL> path = "<STR_LIT>" % tenant [ "<STR_LIT:id>" ] <EOL> self . _populate ( path , "<STR_LIT>" , servers [ tenant [ "<STR_LIT:id>" ] ] , actions = True ) <EOL> self . _populate ( path , "<STR_LIT>" , volumes [ tenant [ "<STR_LIT:id>" ] ] , "<STR_LIT>" ) <EOL> self . _populate ( path , "<STR_LIT>" , pools [ tenant [ "<STR_LIT:id>" ] ] , <EOL> "<STR_LIT>" ) <EOL> self . _populate ( path , "<STR_LIT>" , floating_ips [ tenant [ "<STR_LIT:id>" ] ] , <EOL> "<STR_LIT>" ) <EOL> self . _populate ( path , "<STR_LIT:image>" , list ( images . values ( ) ) ) <EOL> self . _populate ( path , "<STR_LIT>" , list ( flavors . values ( ) ) ) <EOL> self . _populate_attached_volumes ( path , servers [ tenant [ "<STR_LIT:id>" ] ] , <EOL> volumes [ tenant [ "<STR_LIT:id>" ] ] ) <EOL> def _populate ( self , path_base , obj_name , obj_list , <EOL> objs_path = None , actions = [ ] ) : <EOL> objs_name = "<STR_LIT>" % obj_name <EOL> if objs_path : <EOL> path = "<STR_LIT>" % ( path_base , objs_path ) <EOL> else : <EOL> path = "<STR_LIT>" % ( path_base , objs_name ) <EOL> objs_details_path = "<STR_LIT>" % path <EOL> self . routes [ path ] = create_fake_json_resp ( { objs_name : obj_list } ) <EOL> self . routes [ objs_details_path ] = create_fake_json_resp ( <EOL> { objs_name : obj_list } ) <EOL> for o in obj_list : <EOL> obj_path = "<STR_LIT>" % ( path , o [ "<STR_LIT:id>" ] ) <EOL> self . routes [ obj_path ] = create_fake_json_resp ( { obj_name : o } ) <EOL> if actions : <EOL> action_path = "<STR_LIT>" % obj_path <EOL> self . routes [ action_path ] = webob . Response ( status = <NUM_LIT> ) <EOL> def _populate_attached_volumes ( self , path , server_list , vol_list ) : <EOL> for s in server_list : <EOL> attachments = [ ] <EOL> if "<STR_LIT>" in s : <EOL> for attach in s [ "<STR_LIT>" ] : <EOL> for v in vol_list : <EOL> if attach [ "<STR_LIT:id>" ] == v [ "<STR_LIT:id>" ] : <EOL> attachments . append ( v [ "<STR_LIT>" ] [ <NUM_LIT:0> ] ) <EOL> path_base = "<STR_LIT>" % ( path , s [ "<STR_LIT:id>" ] ) <EOL> self . routes [ path_base ] = create_fake_json_resp ( <EOL> { "<STR_LIT>" : attachments } <EOL> ) <EOL> for attach in attachments : <EOL> obj_path = "<STR_LIT>" % ( path_base , attach [ "<STR_LIT:id>" ] ) <EOL> self . routes [ obj_path ] = create_fake_json_resp ( <EOL> { "<STR_LIT>" : attach } ) <EOL> @ webob . dec . wsgify ( ) <EOL> def __call__ ( self , req ) : <EOL> if req . method == "<STR_LIT:GET>" : <EOL> return self . _do_get ( req ) <EOL> elif req . method == "<STR_LIT:POST>" : <EOL> return self . _do_post ( req ) <EOL> elif req . method == "<STR_LIT>" : <EOL> return self . _do_delete ( req ) <EOL> def _do_create_server ( self , req ) : <EOL> s = { "<STR_LIT>" : { "<STR_LIT:id>" : "<STR_LIT:foo>" , <EOL> "<STR_LIT:name>" : "<STR_LIT:foo>" , <EOL> "<STR_LIT>" : { "<STR_LIT:id>" : "<STR_LIT:1>" } , <EOL> "<STR_LIT:image>" : { "<STR_LIT:id>" : "<STR_LIT:2>" } , <EOL> "<STR_LIT:status>" : "<STR_LIT>" } } <EOL> return create_fake_json_resp ( s ) <EOL> def _do_create_volume ( self , req ) : <EOL> s = { "<STR_LIT>" : { "<STR_LIT:id>" : "<STR_LIT:foo>" , <EOL> "<STR_LIT>" : "<STR_LIT:foo>" , <EOL> "<STR_LIT:size>" : <NUM_LIT:1> , <EOL> "<STR_LIT:status>" : "<STR_LIT>" } } <EOL> return create_fake_json_resp ( s ) <EOL> def _do_create_attachment ( self , req ) : <EOL> v = { "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT:foo>" , <EOL> "<STR_LIT>" : "<STR_LIT:bar>" , <EOL> "<STR_LIT>" : "<STR_LIT>" } } <EOL> return create_fake_json_resp ( v , <NUM_LIT> ) <EOL> def _do_allocate_ip ( self , req ) : <EOL> tenant = req . path_info . split ( '<STR_LIT:/>' ) [ <NUM_LIT:1> ] <EOL> body = req . json_body . copy ( ) <EOL> pool = body . popitem ( ) <EOL> if pool [ <NUM_LIT:1> ] : <EOL> for p in pools [ tenant ] : <EOL> if p [ "<STR_LIT:name>" ] == pool [ <NUM_LIT:1> ] : <EOL> break <EOL> else : <EOL> exc = webob . exc . HTTPNotFound ( ) <EOL> return FakeOpenStackFault ( exc ) <EOL> ip = { "<STR_LIT>" : { "<STR_LIT>" : allocated_ip , "<STR_LIT:id>" : <NUM_LIT:1> } } <EOL> return create_fake_json_resp ( ip , <NUM_LIT> ) <EOL> def _do_post ( self , req ) : <EOL> if req . path_info . endswith ( "<STR_LIT>" ) : <EOL> return self . _do_create_server ( req ) <EOL> if req . path_info . endswith ( "<STR_LIT>" ) : <EOL> return self . _do_create_volume ( req ) <EOL> elif req . path_info . endswith ( "<STR_LIT:action>" ) : <EOL> body = req . json_body . copy ( ) <EOL> action = body . popitem ( ) <EOL> if action [ <NUM_LIT:0> ] in [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" ] : <EOL> return self . _get_from_routes ( req ) <EOL> elif req . path_info . endswith ( "<STR_LIT>" ) : <EOL> return self . _do_create_attachment ( req ) <EOL> elif req . path_info . endswith ( "<STR_LIT>" ) : <EOL> return self . _do_allocate_ip ( req ) <EOL> raise Exception <EOL> def _do_delete ( self , req ) : <EOL> self . _do_get ( req ) <EOL> tested_paths = { <EOL> r"<STR_LIT>" : <NUM_LIT> , <EOL> r"<STR_LIT>" : <NUM_LIT> , <EOL> r"<STR_LIT>" : <NUM_LIT> , <EOL> r"<STR_LIT>" : <NUM_LIT> , <EOL> } <EOL> for p , st in tested_paths . items ( ) : <EOL> if re . match ( p , req . path_info ) : <EOL> return create_fake_json_resp ( { } , st ) <EOL> raise Exception <EOL> def _do_get ( self , req ) : <EOL> return self . _get_from_routes ( req ) <EOL> def _get_from_routes ( self , req ) : <EOL> try : <EOL> ret = self . routes [ req . path_info ] <EOL> except KeyError : <EOL> exc = webob . exc . HTTPNotFound ( ) <EOL> ret = FakeOpenStackFault ( exc ) <EOL> return ret <EOL> def create_fake_json_resp ( data , status = <NUM_LIT:200> ) : <EOL> r = webob . Response ( ) <EOL> r . headers [ "<STR_LIT:Content-Type>" ] = "<STR_LIT:application/json>" <EOL> r . charset = "<STR_LIT:utf8>" <EOL> r . body = json . dumps ( data ) . encode ( "<STR_LIT:utf8>" ) <EOL> r . status_code = status <EOL> return r </s>
