def __init__(self): print "DEBUG: Controller constructor called." if ( not buildController ): # DONT allow construction of more than 1 controller instance (i.e. none other than the buildController here) print "DEBUG: Controller Singleton constructor called." try: self.settings = load_settings_from_file("controller_settings.json") self.conn = amqp.Connection( host=self.settings["rabbit_url"], userid=self.settings["rabbit_userid"], password=self.settings["rabbit_password"], virtual_host=self.settings["rabbit_virtual_host"], insist=self.settings["rabbit_insist"], ) self.chan = self.conn.channel() # declare exchange. self.chan.exchange_declare(exchange=pybit.exchange_name, type="direct", durable=True, auto_delete=False) # declare command queue. self.chan.queue_declare(queue=pybit.status_queue, durable=True, exclusive=False, auto_delete=False) # bind routing from exchange to command queue based on routing key. self.chan.queue_bind( queue=pybit.status_queue, exchange=pybit.exchange_name, routing_key=pybit.status_route ) except Exception as e: raise Exception("Error creating controller (Maybe we cannot connect to queue?) - " + str(e)) return
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301, USA. import jsonpickle from pybitweb.bottle import Bottle,route,run,template,debug,HTTPError,response,error,redirect,request, hook, static_file from pybitweb.db import Database,myDb from pybitweb import lookups, buildd, job, package, packageinstance from pybitweb.controller import Controller,buildController from pybit.common import load_settings_from_file settings = load_settings_from_file('web_settings.json') @error(404) def error404(error): return 'HTTP Error 404 - Not Found.' # Remove this to get more debug. @error(500) def error404(error): return 'HTTP Error 500 - Internal Server Error.' # Things in here are applied to all requests. We need to set this header so strict browsers can query it using jquery #http://en.wikipedia.org/wiki/Cross-origin_resource_sharing @hook('after_request') def enable_cors(): response.headers['Access-Control-Allow-Origin'] = '*'