def update_juliabox_status(): instances = Compute.get_all_instances() in_error = 0 HTML = "<html><body><center><pre>\nJuliaBox is Up.\n\nLast updated: " + datetime.datetime.now().isoformat() + " UTC\n\nLoads: " for inst in instances: try: status = JBoxAsyncJob.sync_api_status(inst)['data'] HTML += (str(status['load']) + '% ') except: in_error += 1 pass HTML += ("\n\nErrors: " + str(in_error) + "\n\nAWS Status: <a href='http://status.aws.amazon.com/'>status.aws.amazon.com</a></pre></center></body></html>") plugin = JBPluginCloud.jbox_get_plugin(JBPluginCloud.JBP_BUCKETSTORE) bkt = JBoxCfg.get("cloud_host.status_bucket") if plugin is not None and bkt is not None: try: f = open("/tmp/index.html", "w") f.write(HTML) f.close() plugin.push(bkt, "/tmp/index.html") finally: os.remove("/tmp/index.html") else: JBox.log_debug("Status: %s", HTML) return None
def auto_activate(): plugin = JBPluginCloud.jbox_get_plugin(JBPluginCloud.JBP_SENDMAIL) if plugin is None: JBoxd.log_error("No plugin found for sending mails. Can not auto activate users.") return num_mails_24h, rate = plugin.get_email_rates() rate_per_second = min(JBoxd.MAX_ACTIVATIONS_PER_SEC, rate) num_mails = min(JBoxd.MAX_AUTO_ACTIVATIONS_PER_RUN, num_mails_24h) JBoxd.log_info("Will activate max %d users at %d per second. AWS limits: %d mails at %d per second", num_mails, rate_per_second, num_mails_24h, rate) user_ids = JBoxUserV2.get_pending_activations(num_mails) JBoxd.log_info("Got %d user_ids to be activated", len(user_ids)) for user_id in user_ids: JBoxd.log_info("Activating %s", user_id) # send email by SES plugin.send_email(user_id, JBoxd.ACTIVATION_SENDER, JBoxd.ACTIVATION_SUBJECT, JBoxd.ACTIVATION_BODY) # set user as activated user = JBoxUserV2(user_id) user.set_activation_state(JBoxUserV2.ACTIVATION_CODE_AUTO, JBoxUserV2.ACTIVATION_GRANTED) user.save() rate_per_second -= 1 if rate_per_second <= 0: rate_per_second = min(JBoxd.MAX_ACTIVATIONS_PER_SEC, rate) time.sleep(1)
def update_juliabox_status(): in_error = len( JBoxInstanceProps.get_stale_instances(Compute.get_install_id())) instance_status = JBoxInstanceProps.get_instance_status( Compute.get_install_id()) HTML = "<html><body><center><pre>\nJuliaBox is Up.\n\nLast updated: " + datetime.datetime.now( ).isoformat() + " UTC\n\nLoads: " for iid in instance_status: HTML += (str(instance_status[iid]['load']) + '% ') HTML += ( "\n\nErrors: " + str(in_error) + "\n\nAWS Status: <a href='http://status.aws.amazon.com/'>status.aws.amazon.com</a></pre></center></body></html>" ) plugin = JBPluginCloud.jbox_get_plugin(JBPluginCloud.JBP_BUCKETSTORE) bkt = JBoxCfg.get("cloud_host.status_bucket") if plugin is not None and bkt is not None: try: f = open("/tmp/index.html", "w") f.write(HTML) f.close() plugin.push(bkt, "/tmp/index.html") finally: os.remove("/tmp/index.html") else: JBox.log_debug("Status: %s", HTML) return None