def chk_and_launch_docker(self, user_id): if self.redirect_to_logged_in_instance(user_id): return nhops = int(self.get_argument('h', 0)) numhopmax = JBoxCfg.get('numhopmax', 0) max_hop = nhops > numhopmax launched = self.try_launch_container(user_id, max_hop=max_hop) if launched: self.set_container_initialized(Compute.get_instance_local_ip(), user_id) self.rendertpl("loading.tpl", user_id=user_id, cfg=JBoxCfg.nv, js_includes=JBPluginHandler.PLUGIN_JAVASCRIPTS) return self.unset_affinity() self.log_debug("at hop %d for user %s", nhops, user_id) if max_hop: if JBoxCfg.get('cloud_host.scale_down'): msg = "JuliaBox is experiencing a sudden surge. Please try in a few minutes while we increase our capacity." else: msg = "JuliaBox servers are fully loaded. Please try after sometime." self.log_error("Server maxed out. Can't launch container at hop %d for user %s", nhops, user_id) self.rendertpl("index.tpl", cfg=JBoxCfg.nv, state=self.state(error=msg, success='')) else: redirect_instance = Compute.get_redirect_instance_id() if redirect_instance is not None: redirect_ip = Compute.get_instance_local_ip(redirect_instance) self.set_redirect_instance_id(redirect_ip) self.redirect('/?h=' + str(nhops + 1))
def process_commands(argv): with open(argv[2]) as f: uplcourse = eval(f.read()) conf_dir = os.path.abspath( os.path.join(os.path.dirname(__file__), '../../host/tornado/conf')) conf_file = os.path.join(conf_dir, 'tornado.conf') user_conf_file = os.path.join('/jboxengine/conf', 'jbox.user') JBoxCfg.read(conf_file, user_conf_file) LoggerMixin.configure() db.configure() Compute.configure() cmd = argv[1] if cmd == "upload": HomeworkHandler.upload_course(None, uplcourse) elif cmd == "report": as_csv = (argv[3] == "csv") if len(argv) > 3 else False get_report(uplcourse, as_csv) elif cmd == "answers": get_answers(uplcourse) else: print("Unknown option %s" % (cmd, )) print("DONE!")
def configure(): JBoxLoopbackVol.DISK_LIMIT = JBoxCfg.get('disk_limit') JBoxLoopbackVol.FS_LOC = os.path.expanduser(JBoxCfg.get('mnt_location')) JBoxLoopbackVol.MAX_DISKS = JBoxCfg.get('numdisksmax') JBoxLoopbackVol.DISK_RESERVE_SECS = JBoxCfg.get('disk_reserve_secs', 180) JBoxLoopbackVol.LOCK = threading.Lock() JBoxLoopbackVol.refresh_disk_use_status()
def configure(): backup_location = JBoxCfg.get('backup_location') if backup_location is not None: backup_location = os.path.expanduser(backup_location) make_sure_path_exists(backup_location) JBoxVol.BACKUP_LOC = backup_location JBoxVol.DCKR = JBoxCfg.dckr JBoxVol.NOTEBOOK_WEBSOCK_PROTO = JBoxCfg.get( 'websocket_protocol') + '://' JBoxVol.USER_HOME_IMG = os.path.expanduser( JBoxCfg.get('user_home_image')) JBoxVol.PKG_IMG = os.path.expanduser(JBoxCfg.get('pkg_image')) JBoxVol.LOCAL_TZ_OFFSET = JBoxVol.local_time_offset() JBoxVol.BACKUP_BUCKET = JBoxCfg.get('cloud_host.backup_bucket') for plugin in JBoxVol.plugins: assert issubclass(plugin, JBoxVol) plugin.configure() JBoxVol.log_info("Found plugin %r provides %r", plugin, plugin.provides) if len(JBoxVol.plugins) == 0: JBoxVol.log_warn("No plugins found!") if JBoxVol.SH_DEVICE_VERSION is None: JBoxVol.SH_DEVICE_VERSION = create_host_mnt_command( 'stat --format 0x%t,0x%T')
def configure(): CompEC2.SCALE_UP_AT_LOAD = JBoxCfg.get('cloud_host.scale_up_at_load', 80) CompEC2.SCALE_UP_POLICY = JBoxCfg.get('cloud_host.scale_up_policy', None) CompEC2.AUTOSCALE_GROUP = JBoxCfg.get('cloud_host.autoscale_group', None) CompEC2.INSTALL_ID = JBoxCfg.get('cloud_host.install_id', 'JuliaBox') CompEC2.REGION = JBoxCfg.get('cloud_host.region', 'us-east-1')
def configure(): JBoxLoopbackVol.DISK_LIMIT = JBoxCfg.get('disk_limit') JBoxLoopbackVol.FS_LOC = os.path.expanduser( JBoxCfg.get('mnt_location')) JBoxLoopbackVol.MAX_DISKS = JBoxCfg.get('numdisksmax') JBoxLoopbackVol.LOCK = threading.Lock() JBoxLoopbackVol.refresh_disk_use_status()
def get(self): sessname = self.get_session_id() user_id = self.get_user_id() if (sessname is None) or (user_id is None): self.send_error() return user = JBoxUserV2(user_id) is_admin = sessname in JBoxCfg.get("admin_sessnames", []) manage_containers = is_admin or user.has_role(JBoxUserV2.ROLE_MANAGE_CONTAINERS) show_report = is_admin or user.has_role(JBoxUserV2.ROLE_ACCESS_STATS) cont = SessContainer.get_by_name(sessname) if cont is None: self.send_error() return if self.handle_if_logout(cont): return if self.handle_if_stats(is_admin or show_report): return if self.handle_if_show_cfg(is_admin): return if self.handle_if_instance_info(is_admin): return if self.handle_switch_julia_img(user): return if self.handle_if_open_port(sessname, user_id): return juliaboxver, _upgrade_available = self.get_upgrade_available(cont) jimg_type = 0 if user.has_resource_profile(JBoxUserV2.RES_PROF_JULIA_PKG_PRECOMP): jimg_type = JBoxUserV2.RES_PROF_JULIA_PKG_PRECOMP expire = JBoxCfg.get('interactive.expire') d = dict( manage_containers=manage_containers, show_report=show_report, sessname=sessname, user_id=user_id, created=isodate.datetime_isoformat(cont.time_created()), started=isodate.datetime_isoformat(cont.time_started()), allowed_till=isodate.datetime_isoformat((cont.time_started() + timedelta(seconds=expire))), mem=cont.get_memory_allocated(), cpu=cont.get_cpu_allocated(), disk=cont.get_disk_allocated(), expire=expire, juliaboxver=juliaboxver, jimg_type=jimg_type ) self.rendertpl("ipnbadmin.tpl", d=d)
def configure(): num_disks_max = JBoxCfg.get('numdisksmax') JBoxEBSVol.DISK_LIMIT = 10 JBoxEBSVol.MAX_DISKS = num_disks_max JBoxEBSVol.DISK_TEMPLATE_SNAPSHOT = JBoxCfg.get('cloud_host.ebs_template') JBoxEBSVol.DEVICES = JBoxEBSVol._guess_configured_devices('xvd', num_disks_max) JBoxEBSVol.log_debug("Assuming %d EBS volumes configured in range xvdba..xvdcz", len(JBoxEBSVol.DEVICES)) JBoxEBSVol.LOCK = threading.Lock() JBoxEBSVol.refresh_disk_use_status()
def configure(): BaseContainer.DCKR = JBoxCfg.dckr SessContainer.DCKR_IMAGE = JBoxCfg.get('interactive.docker_image') SessContainer.MEM_LIMIT = JBoxCfg.get('interactive.mem_limit') SessContainer.ULIMITS = [] limits = JBoxCfg.get('interactive.ulimits') for (n, v) in limits.iteritems(): SessContainer.ULIMITS.append(Ulimit(name=n, soft=v, hard=v)) SessContainer.CPU_LIMIT = JBoxCfg.get('interactive.cpu_limit') SessContainer.MAX_CONTAINERS = JBoxCfg.get('interactive.numlocalmax')
def configure(): num_disks_max = JBoxCfg.get('numdisksmax') JBoxEBSVol.DISK_LIMIT = 10 JBoxEBSVol.MAX_DISKS = num_disks_max JBoxEBSVol.DISK_TEMPLATE_SNAPSHOT = JBoxCfg.get( 'cloud_host.ebs_template') JBoxEBSVol.DEVICES = JBoxEBSVol._guess_configured_devices( 'xvd', num_disks_max) JBoxEBSVol.log_debug( "Assuming %d EBS volumes configured in range xvdba..xvdcz", len(JBoxEBSVol.DEVICES)) JBoxEBSVol.LOCK = threading.Lock() JBoxEBSVol.refresh_disk_use_status()
def configure(): mail_data = JBoxCfg.get('user_activation') JBoxd.SENDER_PASSWORD = mail_data['sender_password'] JBoxd.SMTP_URL = mail_data['smtp_url'] JBoxd.SMTP_PORT_NO = mail_data['smtp_port_no'] JBoxd.MAX_24HRS = mail_data['max_24hrs'] JBoxd.MAX_RATE_PER_SEC = mail_data['max_rate_per_sec']
def post(self): self.log_debug("API management handler got POST request") sessname = self.get_session_id() user_id = self.get_user_id() if (sessname is None) or (user_id is None): self.send_error() return user = JBoxUserV2(user_id) is_admin = sessname in JBoxCfg.get( "admin_sessnames", []) or user.has_role(JBoxUserV2.ROLE_SUPER) self.log_info("API manager. user_id[%s] is_admin[%r]", user_id, is_admin) if user.has_resource_profile(JBoxUserV2.RES_PROF_API_PUBLISHER): if self.handle_get_api_info(user_id, is_admin): return if self.handle_create_api(user_id, is_admin): return if self.handle_delete_api(user_id, is_admin): return else: if self.handle_enable_api(user_id, is_admin): return self.log_error("no handlers found") # only AJAX requests responded to self.send_error()
def get(self): self.log_debug("APIInfo handler got GET request") key = self.get_argument("key", None) sign = self.get_argument("sign", None) if key is None or sign is None: self.send_error() return sign2 = signstr(key, JBoxCfg.get('sesskey')) if sign != sign2: self.log_info("signature mismatch. key:%r sign:%r expected:%r", key, sign, sign2) self.send_error() return api_status = APIContainer.get_cluster_api_status() self.log_info("cluster api status: %r", api_status) # filter out instances that should not accept more load filtered_api_status = {k: v for (k, v) in api_status.iteritems() if v['accept']} preferred_instances = filtered_api_status.keys() # flip the dict per_api_instances = dict() for (inst, status) in filtered_api_status.iteritems(): api_names = status['api_status'].keys() for api_name in api_names: v = per_api_instances.get(api_name, []) v.append(inst) per_api_instances[" preferred "] = preferred_instances self.log_info("per api instances: %r", per_api_instances) self.write(per_api_instances) return
def post(self): self.log_debug("API management handler got POST request") sessname = self.get_session_id() user_id = self.get_user_id() if (sessname is None) or (user_id is None): self.send_error() return user = JBoxUserV2(user_id) is_admin = sessname in JBoxCfg.get("admin_sessnames", []) or user.has_role(JBoxUserV2.ROLE_SUPER) self.log_info("API manager. user_id[%s] is_admin[%r]", user_id, is_admin) if user.has_resource_profile(JBoxUserV2.RES_PROF_API_PUBLISHER): if self.handle_get_api_info(user_id, is_admin): return if self.handle_create_api(user_id, is_admin): return if self.handle_delete_api(user_id, is_admin): return else: if self.handle_enable_api(user_id, is_admin): return self.log_error("no handlers found") # only AJAX requests responded to self.send_error()
def post(self): self.log_debug("User management handler got POST request") sessname = self.get_session_id() user_id = self.get_user_id() if (sessname is None) or (user_id is None): self.send_error() return user = JBoxUserV2(user_id) is_admin = sessname in JBoxCfg.get( "admin_sessnames", []) or user.has_role(JBoxUserV2.ROLE_SUPER) self.log_info("User manager. user_id[%s] is_admin[%r]", user_id, is_admin) if not is_admin: self.send_error(status_code=403) return if self.handle_get_user(user_id, is_admin): return if self.handle_update_user(user_id, is_admin): return self.log_error("no handlers found") # only AJAX requests responded to self.send_error()
def get_user_id(self, validate=True): if (self._user_id is None) or (validate and (not self._valid_user)): try: jbox_cookie = self.get_cookie(JBoxCookies.COOKIE_AUTH) if jbox_cookie is None: return None jbox_cookie = json.loads(base64.b64decode(jbox_cookie)) if validate: sign = signstr(jbox_cookie['u'] + jbox_cookie['t'], JBoxCfg.get('sesskey')) if sign != jbox_cookie['x']: self.log_info("signature mismatch for " + jbox_cookie['u']) return None d = isodate.parse_datetime(jbox_cookie['t']) age = (datetime.datetime.now(pytz.utc) - d).total_seconds() if age > JBoxCookies.AUTH_VALID_SECS: self.log_info("cookie older than allowed days: " + jbox_cookie['t']) return None self._valid_user = True self._user_id = jbox_cookie['u'] except: self.log_error("exception while reading auth cookie") traceback.print_exc() return None return self._user_id
def configure(): pkg_location = os.path.expanduser(JBoxCfg.get('pkg_location')) make_sure_path_exists(pkg_location) JBoxDefaultPackagesVol.FS_LOC = pkg_location JBoxDefaultPackagesVol.LOCK = threading.Lock() JBoxDefaultPackagesVol.refresh_disk_use_status()
def configure(): polsar_location = os.path.expanduser(JBoxCfg.get("polsar_location")) make_sure_path_exists(polsar_location) JBoxPolsarDiskVol.FS_LOC = polsar_location JBoxPolsarDiskVol.refresh_disk_use_status()
def post(self): self.log_debug("Homework handler got POST request") sessname = self.get_session_id() user_id = self.get_user_id() if (sessname is None) or (user_id is None): self.log_info("Homework handler got invalid sessname[%r] or user_id[%r]", sessname, user_id) self.send_error() return user = JBoxUserV2(user_id) is_admin = sessname in JBoxCfg.get("admin_sessnames", []) or user.has_role(JBoxUserV2.ROLE_SUPER) course_owner = is_admin or user.has_role(JBoxUserV2.ROLE_OFFER_COURSES) cont = SessContainer.get_by_name(sessname) self.log_info("user_id[%r], is_admin[%r], course_owner[%r]", user_id, is_admin, course_owner) if cont is None: self.log_info("user_id[%r] container not found", user_id) self.send_error() return courses_offered = user.get_courses_offered() if self.handle_if_check(user_id): return if self.handle_create_course(user_id): return if self.handle_get_metadata(is_admin, courses_offered): return if self.handle_if_report(user_id, is_admin, courses_offered): return self.log_error("no handlers found") # only AJAX requests responded to self.send_error()
def post(self): self.log_debug("User management handler got POST request") sessname = self.get_session_id() user_id = self.get_user_id() if (sessname is None) or (user_id is None): self.send_error() return user = JBoxUserV2(user_id) is_admin = sessname in JBoxCfg.get("admin_sessnames", []) or user.has_role(JBoxUserV2.ROLE_SUPER) self.log_info("User manager. user_id[%s] is_admin[%r]", user_id, is_admin) if not is_admin: self.send_error(status_code=403) return if self.handle_get_user(user_id, is_admin): return if self.handle_update_user(user_id, is_admin): return self.log_error("no handlers found") # only AJAX requests responded to self.send_error()
def is_allowed(handler): user_id = UserAdminUIModule.get_user_id(handler) if user_id is None: return False user = JBoxUserV2(user_id) sessname = handler.get_session_id() is_admin = sessname in JBoxCfg.get("admin_sessnames", []) or user.has_role(JBoxUserV2.ROLE_SUPER) return is_admin
def configure(): mail_data = JBoxCfg.get('user_activation') JBoxSMTP.SENDER = mail_data['sender'] JBoxSMTP.SENDER_PASSWORD = mail_data['sender_password'] JBoxSMTP.SMTP_URL = mail_data['smtp_url'] JBoxSMTP.SMTP_PORT_NO = mail_data['smtp_port_no'] JBoxSMTP.MAX_24HRS = mail_data['max_24hrs'] JBoxSMTP.MAX_RATE_PER_SEC = mail_data['max_rate_per_sec']
def configure(): dbconf = JBoxCfg.get("db") JBoxCloudSQL.log_debug("db_conf: %r", dbconf) if dbconf is not None: JBoxCloudSQL.USER = dbconf['user'] JBoxCloudSQL.PASSWD = dbconf['passwd'] JBoxCloudSQL.UNIX_SOCKET = dbconf['unix_socket'] JBoxCloudSQL.DB = dbconf['db']
def pack(self): args = dict() for cookie in [JBoxCookies.COOKIE_SESS, JBoxCookies.COOKIE_INSTANCEID, JBoxCookies.COOKIE_AUTH]: args[cookie] = self.get_cookie(cookie) for cookie in self.cookies: if cookie.startswith(JBoxCookies.COOKIE_PFX_PORT): args[cookie] = self.get_cookie(cookie) return tornado.escape.url_escape(base64.b64encode(encrypt(json.dumps(args), JBoxCfg.get('sesskey'))))
def _set_container_cookies(self, cookies): max_session_time = JBoxCfg.get('interactive.expire') if max_session_time == 0: max_session_time = JBoxCookies.AUTH_VALID_SECS expires = datetime.datetime.utcnow() + datetime.timedelta(seconds=max_session_time) for n, v in cookies.iteritems(): self.set_cookie(n, str(v), expires=expires)
def unpack(self, packed): args = json.loads(decrypt(base64.b64decode(packed), JBoxCfg.get('sesskey'))) for oldcookie in self.cookies: if oldcookie not in args or args[oldcookie] is None: self.clear_cookie(oldcookie) for cname, cval in args.iteritems(): if cval is not None: self.set_cookie(cname, cval)
def _set_container_cookies(self, cookies): max_session_time = JBoxCfg.get('interactive.expire') if max_session_time == 0: max_session_time = JBoxCookies.AUTH_VALID_SECS expires = datetime.datetime.utcnow() + datetime.timedelta( seconds=max_session_time) for n, v in cookies.iteritems(): self.set_cookie(n, str(v), expires=expires)
def configure(): plugin = JBPluginCloud.jbox_get_plugin(JBPluginCloud.JBP_COMPUTE) if plugin is None: Compute.log_error("No plugin found for compute host") raise Exception("No plugin found for compute host") plugin.configure() Compute.impl = plugin Compute.SCALE = JBoxCfg.get('cloud_host.scale_down')
def is_allowed(handler): user_id = UserAdminUIModule.get_user_id(handler) if user_id is None: return False user = JBoxUserV2(user_id) sessname = handler.get_session_id() is_admin = sessname in JBoxCfg.get( "admin_sessnames", []) or user.has_role(JBoxUserV2.ROLE_SUPER) return is_admin
def configure(): if not EmailVerifyHandler.CONFIGURED: plugin = JBPluginCloud.jbox_get_plugin(JBPluginCloud.JBP_SENDMAIL) if plugin is None: EmailVerifyHandler.log_error("No plugin found for sending mails. Cannot send verification mail.") EmailVerifyHandler.EMAIL_PLUGIN = plugin EmailVerifyHandler.EMAIL_SENDER = JBoxCfg.get('user_activation')['sender'] EmailVerifyHandler.CONFIGURED = True
def unpack(self, packed): args = json.loads( decrypt(base64.b64decode(packed), JBoxCfg.get('sesskey'))) for oldcookie in self.cookies: if oldcookie not in args or args[oldcookie] is None: self.clear_cookie(oldcookie) for cname, cval in args.iteritems(): if cval is not None: self.set_cookie(cname, cval)
def configure(): if not EmailVerifyHandler.CONFIGURED: plugin = JBPluginCloud.jbox_get_plugin(JBPluginCloud.JBP_SENDMAIL) if plugin is None: EmailVerifyHandler.log_error( "No plugin found for sending mails. Cannot send verification mail." ) EmailVerifyHandler.EMAIL_PLUGIN = plugin EmailVerifyHandler.EMAIL_SENDER = JBoxCfg.get( 'user_activation')['sender'] EmailVerifyHandler.CONFIGURED = True
def configure(): if not SiteRedirectHandler.CONFIGURED: data = JBoxCfg.get('site_redirect') SiteRedirectHandler.REDIRECT_URL = data['url'] SiteRedirectHandler.REDIRECT_MSG = data['msg'] rtype = data.get('user_type', 'new') SiteRedirectHandler.REDIRECT_TYPE = SiteRedirectHandler.TYPE_ALL if rtype == 'all' \ else SiteRedirectHandler.TYPE_NEW SiteRedirectHandler.log_info("Configured to redirect %s users to %s", rtype, SiteRedirectHandler.REDIRECT_URL) SiteRedirectHandler.CONFIGURED = True
def configure(): if not EmailWhitelistHandler.CONFIGURED: data = JBoxCfg.get('email_whitelist') if data == None: EmailWhitelistHandler.log_error("No email_whitelist config entry") return EmailWhitelistHandler.WHITELIST = data.get('allowed_addresses') if len(EmailWhitelistHandler.WHITELIST) == 0: EmailWhitelistHandler.log_error("No allowed_addresses config entry for email_whitelist") EmailWhitelistHandler.CONFIGURED = True
def configure(): JBoxDB.configure() tablenames = JBoxCfg.get('db.tables', dict()) for cls in (JBoxUserV2, JBoxSessionProps, JBoxDynConfig, JBoxAPISpec): cls.NAME = tablenames.get(cls.NAME, cls.NAME) JBoxDB.log_info("%s provided by table %s", cls.__name__, cls.NAME) for plugin in JBPluginDB.jbox_get_plugins(JBPluginDB.JBP_TABLE): JBoxDB.log_info("Found plugin %r provides %r", plugin, plugin.provides) plugin.NAME = tablenames.get(plugin.NAME, plugin.NAME) JBoxDB.log_info("%s provided by table %s", plugin.__name__, plugin.NAME)
def configure(): BaseContainer.DCKR = JBoxCfg.dckr APIContainer.DCKR_IMAGE = JBoxCfg.get('api.docker_image') APIContainer.MEM_LIMIT = JBoxCfg.get('api.mem_limit') APIContainer.CPU_LIMIT = JBoxCfg.get('api.cpu_limit') APIContainer.MAX_CONTAINERS = JBoxCfg.get('api.numlocalmax') APIContainer.MAX_PER_API_CONTAINERS = JBoxCfg.get('api.numapilocalmax') APIContainer.EXPIRE_SECS = JBoxCfg.get('api.expire') APIContainer.HOST_LOG_FOLDER = JBoxCfg.get('api.log_location') print("The host log folder = %s", APIContainer.HOST_LOG_FOLDER)
def configure(): CompGCE.SCALE_UP_AT_LOAD = JBoxCfg.get('cloud_host.scale_up_at_load', 80) CompGCE.SCALE_UP_POLICY = JBoxCfg.get('cloud_host.scale_up_policy', None) CompGCE.AUTOSCALE_GROUP = JBoxCfg.get('cloud_host.autoscale_group', None) CompGCE.INSTALL_ID = JBoxCfg.get('cloud_host.install_id', None) CompGCE.MIN_UPTIME = JBoxCfg.get('cloud_host.min_uptime', 50) CompGCE.SCALE_UP_INTERVAL = JBoxCfg.get('cloud_host.scale_up_interval', 300)
def configure(): if not SiteRedirectHandler.CONFIGURED: data = JBoxCfg.get('site_redirect') SiteRedirectHandler.REDIRECT_URL = data['url'] SiteRedirectHandler.REDIRECT_MSG = data['msg'] rtype = data.get('user_type', 'new') SiteRedirectHandler.REDIRECT_TYPE = SiteRedirectHandler.TYPE_ALL if rtype == 'all' \ else SiteRedirectHandler.TYPE_NEW SiteRedirectHandler.log_info( "Configured to redirect %s users to %s", rtype, SiteRedirectHandler.REDIRECT_URL) SiteRedirectHandler.CONFIGURED = True
def set_authenticated(self, user_id): """ Marks user_id as authenticated with a cookie named COOKIE_AUTH (juliabox). Cookie contains: - Creation timestamp and is treated as valid for AUTH_VALID_SECS time. - Signature for validity check. :param user_id: the user id being marked as authenticated :return: None """ t = datetime.datetime.now(pytz.utc).isoformat() sign = signstr(user_id + t, JBoxCfg.get('sesskey')) jbox_cookie = {'u': user_id, 't': t, 'x': sign} self.set_cookie(JBoxCookies.COOKIE_AUTH, base64.b64encode(json.dumps(jbox_cookie)))
def pack(self): args = dict() for cookie in [ JBoxCookies.COOKIE_SESS, JBoxCookies.COOKIE_INSTANCEID, JBoxCookies.COOKIE_AUTH ]: args[cookie] = self.get_cookie(cookie) for cookie in self.cookies: if cookie.startswith(JBoxCookies.COOKIE_PFX_PORT): args[cookie] = self.get_cookie(cookie) return tornado.escape.url_escape( base64.b64encode(encrypt(json.dumps(args), JBoxCfg.get('sesskey'))))
def configure(): BaseContainer.DCKR = JBoxCfg.dckr APIContainer.DCKR_IMAGE = JBoxCfg.get('api.docker_image') APIContainer.MEM_LIMIT = JBoxCfg.get('api.mem_limit') APIContainer.CPU_LIMIT = JBoxCfg.get('api.cpu_limit') APIContainer.MAX_CONTAINERS = JBoxCfg.get('api.numlocalmax') APIContainer.MAX_PER_API_CONTAINERS = JBoxCfg.get('api.numapilocalmax') APIContainer.EXPIRE_SECS = JBoxCfg.get('api.expire')
def configure(): if not EmailWhitelistHandler.CONFIGURED: data = JBoxCfg.get('email_whitelist') if data == None: EmailWhitelistHandler.log_error( "No email_whitelist config entry") return EmailWhitelistHandler.WHITELIST = data.get('allowed_addresses') if len(EmailWhitelistHandler.WHITELIST) == 0: EmailWhitelistHandler.log_error( "No allowed_addresses config entry for email_whitelist") EmailWhitelistHandler.CONFIGURED = True
def set_container_ports(self, ports): """ Sets cookies to mark the ports being accessible. :param ports: dict of portname and port numbers. Port name can be referred to in the URL path. :return: """ sig1 = self._get_sig(JBoxCookies.COOKIE_AUTH) sig2 = self._get_sig(JBoxCookies.COOKIE_SESS) cookies = dict() for portname, portnum in ports.iteritems(): sign = signstr(sig1 + sig2 + portname + str(portnum), JBoxCfg.get('sesskey')) port_cookie = {'p': portnum, 'x': sign} cookies[JBoxCookies.COOKIE_PFX_PORT + portname] = base64.b64encode(json.dumps(port_cookie)) self._set_container_cookies(cookies)
def configure(): backup_location = JBoxCfg.get('backup_location') if backup_location is not None: backup_location = os.path.expanduser(backup_location) make_sure_path_exists(backup_location) JBoxVol.BACKUP_LOC = backup_location JBoxVol.DCKR = JBoxCfg.dckr JBoxVol.NOTEBOOK_WEBSOCK_PROTO = JBoxCfg.get('websocket_protocol') + '://' JBoxVol.USER_HOME_IMG = os.path.expanduser(JBoxCfg.get('user_home_image')) JBoxVol.PKG_IMG = os.path.expanduser(JBoxCfg.get('pkg_image')) JBoxVol.LOCAL_TZ_OFFSET = JBoxVol.local_time_offset() JBoxVol.BACKUP_BUCKET = JBoxCfg.get('cloud_host.backup_bucket') for plugin in JBoxVol.plugins: assert issubclass(plugin, JBoxVol) plugin.configure() JBoxVol.log_info("Found plugin %r provides %r", plugin, plugin.provides) if len(JBoxVol.plugins) == 0: JBoxVol.log_warn("No plugins found!") if JBoxVol.SH_DEVICE_VERSION is None: JBoxVol.SH_DEVICE_VERSION = create_host_mnt_command('stat --format 0x%t,0x%T')
def configure(): BaseContainer.DCKR = JBoxCfg.dckr APIContainer.DCKR_IMAGE = JBoxCfg.get('api.docker_image') APIContainer.MEM_LIMIT = JBoxCfg.get('api.mem_limit') APIContainer.ULIMITS = [] limits = JBoxCfg.get('interactive.ulimits') for (n, v) in limits.iteritems(): APIContainer.ULIMITS.append(Ulimit(name=n, soft=v, hard=v)) APIContainer.CPU_LIMIT = JBoxCfg.get('api.cpu_limit') APIContainer.MAX_CONTAINERS = JBoxCfg.get('api.numlocalmax') APIContainer.MAX_PER_API_CONTAINERS = JBoxCfg.get('api.numapilocalmax') APIContainer.EXPIRE_SECS = JBoxCfg.get('api.expire')
def configure(): def adapt_decimal(d): return str(d) def convert_decimal(s): return decimal.Decimal(s) # Register the adapter sqlite3.register_adapter(decimal.Decimal, adapt_decimal) # Register the converter sqlite3.register_converter("decimal", convert_decimal) dbconf = JBoxCfg.get("db") JBoxSQLite3.log_debug("db_conf: %r", dbconf) if dbconf is not None and 'connect_str' in dbconf: JBoxSQLite3.CONNECT_STR = dbconf['connect_str']
def set_container_ports(self, ports): """ Sets cookies to mark the ports being accessible. :param ports: dict of portname and port numbers. Port name can be referred to in the URL path. :return: """ sig1 = self._get_sig(JBoxCookies.COOKIE_AUTH) sig2 = self._get_sig(JBoxCookies.COOKIE_SESS) cookies = dict() for portname, portnum in ports.iteritems(): sign = signstr(sig1 + sig2 + portname + str(portnum), JBoxCfg.get('sesskey')) port_cookie = {'p': portnum, 'x': sign} cookies[JBoxCookies.COOKIE_PFX_PORT + portname] = base64.b64encode( json.dumps(port_cookie)) self._set_container_cookies(cookies)
def configure(): CompGCE.SCALE_UP_AT_LOAD = JBoxCfg.get('cloud_host.scale_up_at_load', 80) CompGCE.SCALE_UP_POLICY = JBoxCfg.get('cloud_host.scale_up_policy', None) CompGCE.AUTOSCALE_GROUP = JBoxCfg.get('cloud_host.autoscale_group', None) CompGCE.INSTALL_ID = JBoxCfg.get('cloud_host.install_id', None) CompGCE.MIN_UPTIME = JBoxCfg.get('cloud_host.min_uptime', 50) CompGCE.SCALE_UP_INTERVAL = JBoxCfg.get('cloud_host.scale_up_interval', 300) scaler = CompGCE._get_scaler_plugin() if scaler: scaler.configure()