def render_backends_page(self): """Shows template displaying all the app's backends.""" if hasattr(self.stub, 'get_backend_info'): backend_info = self.stub.get_backend_info() or [] else: backend_info = [] backend_list = [] for backend in backend_info: backend_list.append({ 'name': backend.name, 'instances': backend.instances, 'instanceclass': backend.get_class() or 'B2', 'address': backends.get_hostname(backend.name), 'state': 'running', 'options': backend.options, }) values = { 'request': self.request, 'backends': backend_list, 'backend_path': self.base_path() + self.PATH, } self.generate('backends.html', values)
def render_backend_page(self, backend_name): """Shows template displaying a single backend.""" backend = self.get_backend_entry(backend_name) instances = [] if backend: for i in range(backend.instances): instances.append({ 'id': i, 'address': backends.get_hostname(backend_name, i), 'state': 'running', }) values = { 'request': self.request, 'backend_name': backend_name, 'backend_path': self.base_path() + self.PATH, 'instances': instances, } self.generate('backend.html', values)
# support regular 'appspot.com' app ids only assert ':' not in _APP_ID, ('{} app ids are unsupported'.format( _APP_ID.split(':')[0])) # Automatically detect deployments to other app ids if _APP_ID not in _APP_IDS: appids.PLAYGROUND_APP_ID = _APP_ID appids.MIMIC_APP_ID = _APP_ID TWO_COLLABORATING_APP_IDS = appids.PLAYGROUND_APP_ID != appids.MIMIC_APP_ID if _DEV_MODE: PLAYGROUND_HOSTS = ( 'localhost:8080', '127.0.0.1:8080', # port 7070 for karma e2e test 'localhost:7070', '127.0.0.1:7070', app_identity.get_default_version_hostname()) # PLAYGROUND_USER_CONTENT_HOST = backends.get_hostname('user-content-backend') PLAYGROUND_USER_CONTENT_HOST = None MIMIC_HOST = backends.get_hostname('exec-code-backend') else: PLAYGROUND_HOSTS = ('{}.appspot.com'.format(appids.PLAYGROUND_APP_ID), '{}.appspot.com'.format( appids.PLAYGROUND_APP_ID_ALIAS)) # PLAYGROUND_USER_CONTENT_HOST = ('{0}-dot-{1}.appspot.com' # .format(USER_CONTENT_PREFIX, # appids.PLAYGROUND_APP_ID)) PLAYGROUND_USER_CONTENT_HOST = None MIMIC_HOST = '{0}.appspot.com'.format(appids.MIMIC_APP_ID)
'secure': not _DEV_MODE, } # One hour MIN_EXPIRATION_SECONDS = 3600 # One week DEFAULT_EXPIRATION_SECONDS = 604800 # Extensions to exclude when creating template projects SKIP_EXTENSIONS = ('swp', 'pyc', 'svn') if _DEV_MODE: PLAYGROUND_HOSTS = ['localhost:8080', '127.0.0.1:8080', # port 7070 for karma e2e test 'localhost:7070', '127.0.0.1:7070', app_identity.get_default_version_hostname()] # PLAYGROUND_USER_CONTENT_HOST = backends.get_hostname('user-content-backend') PLAYGROUND_USER_CONTENT_HOST = None MIMIC_HOST = backends.get_hostname('exec-code-backend') else: PLAYGROUND_HOSTS = ['{}.appspot.com'.format(appids.PLAYGROUND_APP_ID)] if appids.PLAYGROUND_APP_ID_ALIAS: PLAYGROUND_HOSTS.append('{}.appspot.com' .format(appids.PLAYGROUND_APP_ID_ALIAS)) # PLAYGROUND_USER_CONTENT_HOST = ('{0}-dot-{1}.appspot.com' # .format(USER_CONTENT_PREFIX, # appids.PLAYGROUND_APP_ID)) PLAYGROUND_USER_CONTENT_HOST = None MIMIC_HOST = '{0}.appspot.com'.format(appids.MIMIC_APP_ID)
def get(self): self.response.out.write('Hello world!') self.response.out.write('backend: %s' % backends.get_hostname('memdb'))
import logging import time import random from google.appengine.ext import webapp from google.appengine.ext.webapp import util from google.appengine.ext import db from google.appengine.api import memcache from google.appengine.api import backends from google.appengine.api.urlfetch import fetch KEY_NAME = 'spam' DATA = 'spam' * 10 MEMDB_BACKEND_ID = 'memdb' MEMDB_HOSTNAME = backends.get_hostname(MEMDB_BACKEND_ID) def get_key_name(): return ''.join([random.choice('abcdefghijklmnopqrstuvwzyz') for x in range(10)]) class Data(db.Model): data = db.StringProperty() def stop_watch(op_name): def outer(func): def wrapper(self): start_at = time.time() func(self) end_at = time.time() log = '[%s] %s' % (op_name, end_at-start_at) logging.info(log) self.response.out.write(log) return wrapper