def application(self, environ, start_response): req = Request(environ) res = Response() location = req.path_info logger.debug('the location in GET request: ' + location) headers = [] if location == '/-/': _categories = category_registry.get_categories() _ca_render = category_renderer() for _category in _categories: logger.debug('the type of category is: ' + str(type(_categories.get(_category)))) __category_instance = _categories.get(_category) headers.append(_ca_render.renderer(__category_instance).get('Category')) res.server = 'OCCI/1.1' if req.content_type == 'text/plain' or req.content_type == '*/*': for a in headers: res.body += 'Category: ' + a + '\n' res.content_type = 'text/plain' res.status = 200 elif req.content_type == 'text/occi': res.content_type = 'text/occi' res.content_length = 50 __category_result = '' for a in headers: __category_result += a + ',\n' res.headers.add('Category', __category_result ) res.body = 'OK' res.status = 200 elif req.content_type == 'text/uri-list': res.content_type = 'text/uri-list' res.status = 200 #################################################################### # for future work regarding JSON or XML it should be inserted here #################################################################### else: logger.warning('Unsupported Media Type (only text/occi, text/plain or text/uri-list are supported') res.status = 415 return res(environ, start_response) # start_response('200 OK', [('Content-Type', 'text/plain')]) # return ['Hello, World if!\r\n'] else: return res(environ, start_response) # start_response('200 OK', [('Content-Type', 'text/plain')]) # return ['Hello, World else!\r\n'] # ======================================================================== # GET request # ======================================================================== # ======================================================================== # POST request # ======================================================================== # ======================================================================== # PUT request # ======================================================================== # ======================================================================== # DELETE request # ======================================================================== pass
# PUT request # ======================================================================== # ======================================================================== # DELETE request # ======================================================================== pass pass if __name__ == '__main__': logger.debug('############ BEGIN OCCI Category rendering ###############') c = category_renderer() result = c.renderer(Compute._kind) logger.debug(result.get('Category')) logger.debug('############# END OCCI Category rendering ################') logger.debug('############ BEGIN OCCI Link instance rendering ###############') network_instance = Network('/network/123', 'active') location_registry.register_location("/network/123", network_instance) networkinterface_instance = NetworkInterface('456', 'source', '/network/123', '192.168.1.2', '00:00:10:20:30:40', 'active') location_registry.register_location("/link/networkinterface/456", networkinterface_instance) l = link_renderer() result = l.renderer(NetworkInterface('456', 'source', '/network/123', 'eth0', '00:01:20:50:90:80', 'active')) logger.debug(result.get('Link'))