def cleanup(node_name = None): config = aws.read_config() if node_name: if config.has_section(node_name): aws.terminate_instance(node_name) else: for section in config.sections(): aws.terminate_instance(section)
def cleanup(node_name=None): """ destroys AWS EC2 isntances """ config = aws.read_config() if node_name: if config.has_section(node_name): aws.terminate_instance(node_name) else: for section in config.sections(): aws.terminate_instance(section)
def process_notification(job_id): """ Handles the PUT /v1/notifications/<job-id>?status=xxx request. This enpoint is used by the spot instances to notify about some important event (notably the container has started or finished). The database is updated so that future GET /v1/jobs/<job-id> requests get the latest information. If a "finished" status has been sent, the user defined callback endpoint (if any) for that job is called and the spot instance is terminated. In addition, a note is stored in the "notes" column stating if the callback ran ok or not. """ # Get the status sent status = request.args.get('status') if status == None: return make_response(jsonify({'Error': \ 'Missing status= parameter'}), 400) # Try to update the DB with the status try: db.update_db(db_conn, job_id, status=status) # If status is "finished', then execute the user defined callback # for this job and terminate the spot instance. if status == "finished": logging.info("Executing job %s user callback function: %s", \ job_id, callback_function(job_id)) call_callback(job_id) instance_id = db.job_db_data(db_conn, job_id, "instance_id") logging.info("Terminating job %s spot instance %s", \ job_id, instance_id) aws.terminate_instance(instance_id) logging.info("Marking job %s as done", job_id) db.update_db(db_conn, job_id, status='%s' % STATUS_DONE) return make_response(jsonify({'Success': \ 'Notification has been processed, status updated to %s' % \ status}), 200) except Exception as e: return make_response(jsonify({'Error': \ 'Something went wrong when updating DB - %s' % str(e)}), 500)
def stop(node_name): """ Terminate a named node """ aws.terminate_instance(node_name)