<s> import os <EOL> import sys <EOL> root_dir = os . path . dirname ( os . path . dirname ( os . path . dirname ( os . path . abspath ( __file__ ) ) ) ) <EOL> web_dir = os . path . join ( root_dir , '<STR_LIT>' , '<STR_LIT>' ) <EOL> sys . path . insert ( <NUM_LIT:0> , root_dir ) <EOL> import cherrypy <EOL> from jinja2 import Environment , FileSystemLoader <EOL> from rackspace_monitoring . types import Provider <EOL> from rackspace_monitoring . providers import get_driver <EOL> env = Environment ( loader = FileSystemLoader ( os . path . join ( web_dir , '<STR_LIT>' ) ) ) <EOL> def http_methods_allowed ( methods = [ '<STR_LIT:GET>' , '<STR_LIT>' ] ) : <EOL> method = cherrypy . request . method . upper ( ) <EOL> if method not in methods : <EOL> cherrypy . response . headers [ '<STR_LIT>' ] = "<STR_LIT:U+002CU+0020>" . join ( methods ) <EOL> raise cherrypy . HTTPError ( <NUM_LIT> ) <EOL> cherrypy . tools . allow = cherrypy . Tool ( '<STR_LIT>' , http_methods_allowed ) <EOL> class Root : <EOL> def _driver ( self ) : <EOL> cookie = cherrypy . request . cookie <EOL> username = None <EOL> apikey = None <EOL> if cookie . has_key ( '<STR_LIT>' ) : <EOL> username = cookie [ '<STR_LIT>' ] . value <EOL> if cookie . has_key ( '<STR_LIT>' ) : <EOL> apikey = cookie [ '<STR_LIT>' ] . value <EOL> raxMon = get_driver ( Provider . RACKSPACE ) <EOL> driver = raxMon ( username , apikey , ex_force_base_url = "<STR_LIT>" ) <EOL> return driver <EOL> @ cherrypy . expose <EOL> def list_entities ( self ) : <EOL> driver = self . _driver ( ) <EOL> entities = driver . list_entities ( ) <EOL> print entities <EOL> tmpl = env . get_template ( '<STR_LIT>' ) <EOL> return tmpl . render ( entities = entities ) <EOL> @ cherrypy . expose <EOL> @ cherrypy . tools . allow ( methods = [ '<STR_LIT:POST>' ] ) <EOL> def setapikey ( self , username , apikey ) : <EOL> cherrypy . response . cookie [ '<STR_LIT>' ] = username <EOL> cherrypy . response . cookie [ '<STR_LIT>' ] = apikey <EOL> raise cherrypy . HTTPRedirect ( '<STR_LIT>' ) <EOL> @ cherrypy . expose <EOL> def index ( self ) : <EOL> cookie = cherrypy . request . cookie <EOL> if cookie . has_key ( '<STR_LIT>' ) and cookie . has_key ( '<STR_LIT>' ) : <EOL> return self . list_entities ( ) <EOL> else : <EOL> tmpl = env . get_template ( '<STR_LIT>' ) <EOL> return tmpl . render ( ) <EOL> cherrypy . tree . mount ( Root ( ) , script_name = '<STR_LIT:/>' ) <EOL> cherrypy . config . update ( { '<STR_LIT>' : False } ) </s>
