示例#1
0
def ipython_shell(user_ns):
    if getattr(IPython, 'version_info', None) and IPython.version_info[0] >= 1:
        from IPython.terminal.ipapp import TerminalIPythonApp
        from IPython.terminal.interactiveshell import TerminalInteractiveShell
    else:
        from IPython.frontend.terminal.ipapp import TerminalIPythonApp
        from IPython.frontend.terminal.interactiveshell import TerminalInteractiveShell

    class ShireIPythonApp(TerminalIPythonApp):
        def init_shell(self):
            self.shell = TerminalInteractiveShell.instance(
                config=self.config,
                display_banner=False,
                profile_dir=self.profile_dir,
                ipython_dir=self.ipython_dir,
                banner1=get_banner(),
                banner2='')
            self.shell.configurables.append(self)

    app = ShireIPythonApp.instance()
    app.initialize()
    app.shell.user_ns.update(user_ns)

    eru_app, _ = create_app_with_celery()
    with eru_app.app_context():
        sys.exit(app.start())
示例#2
0
文件: shell.py 项目: CMGS/eru-core
def ipython_shell(user_ns):
    if getattr(IPython, 'version_info', None) and IPython.version_info[0] >= 1:
        from IPython.terminal.ipapp import TerminalIPythonApp
        from IPython.terminal.interactiveshell import TerminalInteractiveShell
    else:
        from IPython.frontend.terminal.ipapp import TerminalIPythonApp
        from IPython.frontend.terminal.interactiveshell import TerminalInteractiveShell

    class ShireIPythonApp(TerminalIPythonApp):
        def init_shell(self):
            self.shell = TerminalInteractiveShell.instance(
                config=self.config,
                display_banner=False,
                profile_dir=self.profile_dir,
                ipython_dir=self.ipython_dir,
                banner1=get_banner(),
                banner2=''
            )
            self.shell.configurables.append(self)

    app = ShireIPythonApp.instance()
    app.initialize()
    app.shell.user_ns.update(user_ns)

    eru_app, _ = create_app_with_celery()
    with eru_app.app_context():
        sys.exit(app.start())
示例#3
0
def app(request):
    app, _ = create_app_with_celery()
    app.config['TESTING'] = True

    ctx = app.app_context()
    ctx.push()

    def tear_down():
        ctx.pop()

    request.addfinalizer(tear_down)
    return app
示例#4
0
def app(request):
    app, _ = create_app_with_celery()
    app.config['TESTING'] = True

    ctx = app.app_context()
    ctx.push()

    def tear_down():
        ctx.pop()

    request.addfinalizer(tear_down)
    return app
示例#5
0
def fillup_data():
    app, _ = create_app_with_celery()
    with app.app_context():
        db.drop_all()
        db.create_all()

        group = Group.create('test-group', 'test-group')
        pod = Pod.create('test-pod', 'test-pod')
        pod.assigned_to_group(group)

        r = requests.get('http://192.168.59.103:2375/info').json()
        host = Host.create(pod, '192.168.59.103:2375', r['Name'], r['ID'], r['NCPU'], r['MemTotal'])
        host.assigned_to_group(group)

        app = App.get_or_create('nbetest', 'http://git.hunantv.com/platform/nbetest.git', 'token')
        app.add_version('96cbf8c68ed214f105d9f79fa4f22f0e80e75cf3')
        app.assigned_to_group(group)
        version = app.get_version('96cbf8')

        host_cores = group.get_free_cores(pod, 2, 2)
        cores = []
        for (host, cn), coress in host_cores.iteritems():
            print host, cn, coress
            cores = coress
        print cores
        ports = host.get_free_ports(2)
        print ports
        props = {
            'entrypoint': 'web',
            'ncontainer': 2,
            'env': 'PROD',
            'cores': [c.id for c in cores],
            'ports': [p.id for p in ports],
        }
        task = Task.create(1, version, host, props)
        print task.props
        host.occupy_cores(cores)
        host.occupy_ports(ports)
        print group.get_free_cores(pod, 1, 1)
示例#6
0
 def _(*args, **kwargs):
     app, _ = create_app_with_celery()
     with app.app_context():
         return f(*args, **kwargs)
示例#7
0
#!/usr/bin/env python
# encoding: utf-8

import time
from eru.app import create_app_with_celery
from eru.models import db, Group, Pod, App

num_of_containers = int(raw_input("how many containers: "))
num_of_cores = int(raw_input("how many cores: "))
num_of_part_cores = int(raw_input("how many part_cores: "))

app, _ = create_app_with_celery()
app.config['TESTING'] = True
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://root:@localhost:3306/erutest'
ctx = app.app_context()
ctx.push()

a = App.query.first()
g = Group.query.first()
p = Pod.query.first()
v = a.versions.first()

time_1 = time.time()
host_cores = g.get_free_cores(p, num_of_containers, num_of_cores, num_of_part_cores)

time_2 = time.time()
for (host, count), cores in host_cores.iteritems():
    host.occupy_cores(cores, num_of_part_cores)
time_3 = time.time()

print len(host_cores)
示例#8
0
 def _(*args, **kwargs):
     app, _ = create_app_with_celery()
     with app.app_context():
         return f(*args, **kwargs)
示例#9
0
# coding: utf-8

import sys

from eru.app import create_app_with_celery
from eru.models import db

def flushdb(app):
    with app.app_context():
        db.drop_all()
        db.create_all()

if __name__ == '__main__':
    app, _ = create_app_with_celery()
    if app.config['MYSQL_HOST'] in ('127.0.0.1', 'localhost') or '--force' in sys.argv:
        flushdb(app)
    else:
        print 'you are not doing this on your own host,'
        print 'if sure, add --force to run this script'