<commit_before># -*- coding: utf-8 -*-

'''
Master listens on port default 8000, but it is indtended to run on port 80.
It is web app that manages slaves.
It allows users to register, and manage their instances/containers.
Admin is allowed to modify many aspects of web app.

Sections:
    Dashboard
        - live stats
        - earning [super-only]
        - spending [user-only]
    
    Hosts [super]
        - list
        - add
        - remove
        - update
    
    Images [per-user, or all for super]
        - list
        - add
        - remove
        - update
    
    Volumes
        - list
        - add
        - remove
        - update [only name]
    
    Containers [per-user, or all for super]
        - list
        - create
        
        # - clone
        - start
        - restart
        - stop
        - attach
        - logs
        - destory
    
    Networking
        - list
        - add
        - remove
        - update
    
    Settings [super]
        - set title
        - set logo
    
    Profile
        - update
'''

__all__ = ['app']
import os
import sys
from ConfigParser import SafeConfigParser

# requests
import requests

# werkzeug
from werkzeug.contrib.fixers import ProxyFix

# flask
from flask import (
    Flask, request, session, g,
    redirect, url_for, abort,
    render_template, flash, jsonify,
    Blueprint, abort,
    send_from_directory,
    current_app,
)

# flask login
from flask.ext.login import (
    current_user, login_required, fresh_login_required,
    login_user, logout_user, confirm_login,
)

# config
from config.flask import FlaskConfig
_flask_config_path = os.path.join('config', 'flask.conf')

if os.path.exists(_flask_config_path):
    cp = SafeConfigParser()
    cp.optionxform = str
    cp.read(_flask_config_path)
    items = cp.items('FlaskConfig')
    items = dict(items)
    FlaskConfig.__dict__.update(items)

# app
app = Flask(__name__)

if FlaskConfig.PROXY_FIX:
    app.wsgi_app = ProxyFix(app.wsgi_app)

app.config.from_object(FlaskConfig)

# flask-sqlalchemy
from model.db import init_db, object_to_dict, objects_to_list
db = init_db(app)

# model
from model.user import UserAccount, UserQuota, UserStat
from model.host import Host
from model.image import Image
from model.volume import Volume
from model.mount import MountPoint
from model.container import Container
from model.network import Domain, Route

# model - create all tables
# db.drop_all()
db.create_all()

# create super user if does not exits
if not UserAccount.query.filter_by(username='admin').count():
    user_account = UserAccount(
        username = 'admin',
        password = '<PASSWORD>',
        email = '<EMAIL>',
        usertype = 'super',
    )
    db.session.add(user_account)
    db.session.commit()

# create quota for super user
if not UserQuota.query.filter_by(username='admin').count():
    user_quota = UserQuota(
        username = 'admin',
    )
    db.session.add(user_quota)
    db.session.commit()<commit_msg>mount points, volume, slave<commit_after># -*- coding: utf-8 -*-

'''
Master listens on port default 8000, but it is indtended to run on port 80.
It is web app that manages slaves.
It allows users to register, and manage their instances/containers.
Admin is allowed to modify many aspects of web app.

Sections:
    Dashboard
        - live stats
        - earning [super-only]
        - spending [user-only]
    
    Hosts [super]
        - list
        - add
        - remove
        - update
    
    Images [per-user, or all for super]
        - list
        - add
        - remove
        - update
    
    Volumes
        - list
        - add
        - remove
        - update [only name]
    
    Containers [per-user, or all for super]
        - list
        - create
        
        # - clone
        - start
        - restart
        - stop
        - attach
        - logs
        - destory
    
    Networking
        - list
        - add
        - remove
        - update
    
    Settings [super]
        - set title
        - set logo
    
    Profile
        - update
'''

__all__ = ['app']
import os
import sys
from ConfigParser import SafeConfigParser

# requests
import requests

# werkzeug
from werkzeug.contrib.fixers import ProxyFix

# flask
from flask import (
    Flask, request, session, g,
    redirect, url_for, abort,
    render_template, flash, jsonify,
    Blueprint, abort,
    send_from_directory,
    current_app,
)

# flask login
from flask.ext.login import (
    current_user, login_required, fresh_login_required,
    login_user, logout_user, confirm_login,
)

# config
from config.flask import FlaskConfig
_flask_config_path = os.path.join('config', 'flask.conf')

if os.path.exists(_flask_config_path):
    cp = SafeConfigParser()
    cp.optionxform = str
    cp.read(_flask_config_path)
    items = cp.items('FlaskConfig')
    items = dict(items)
    FlaskConfig.__dict__.update(items)

# app
app = Flask(__name__)

if FlaskConfig.PROXY_FIX:
    app.wsgi_app = ProxyFix(app.wsgi_app)

app.config.from_object(FlaskConfig)

# flask-sqlalchemy
from model.db import init_db, object_to_dict, objects_to_list
db = init_db(app)

# model
from model.user import UserAccount, UserQuota, UserStat
from model.host import Host
from model.image import Image
from model.volume import Volume
from model.mount import MountPoint
from model.container import Container
from model.network import Domain, Route

# model - create all tables
db.drop_all()
db.create_all()

# create super user if does not exits
if not UserAccount.query.filter_by(username='admin').count():
    user_account = UserAccount(
        username = 'admin',
        password = '<PASSWORD>',
        email = '<EMAIL>',
        usertype = 'super',
    )
    db.session.add(user_account)
    db.session.commit()

# create quota for super user
if not UserQuota.query.filter_by(username='admin').count():
    user_quota = UserQuota(
        username = 'admin',
    )
    db.session.add(user_quota)
    db.session.commit()
{'fraction_non_alphanumeric': 0.08916666666666667, 'fraction_numerical': 0.0023333333333333335, 'mean_word_length': 2.3469046291132183, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2517032', 'n_tokens_mistral': 1875, 'n_tokens_neox': 1848, 'n_words': 524}