Ejemplo n.º 1
0
Archivo: api.py Proyecto: doanac/cya
def container_create():
    name = request.json.pop("name")
    request.json["requested_by"] = g.user.nickname
    container_requests.create(name, request.json)
    resp = jsonify({})
    resp.status_code = 202
    return resp
Ejemplo n.º 2
0
Archivo: api.py Proyecto: doanac/cya
def container_create():
    name = request.json.pop('name')
    request.json['requested_by'] = g.user.nickname
    container_requests.create(name, request.json)
    resp = jsonify({})
    resp.status_code = 202
    return resp
Ejemplo n.º 3
0
 def test_enlisted(self):
     """The scheduler ignores hosts not enlisted"""
     self.host1.ping()
     self.host1.update({'enlisted': False})
     self.host1 = hosts.get(self.host1.name)
     container_requests.create('container_foo', self.container_data)
     container_requests.handle(self.host1)
     self.assertEqual(1, container_requests.count())
     self.assertEqual(0, self.host1.containers.count())
Ejemplo n.º 4
0
 def test_one_online(self):
     """The scheduler finds one host online"""
     self.host1.ping()
     container_requests.create('container_foo', self.container_data)
     container_requests.handle(self.host1)
     self.assertEqual(0, container_requests.count())
     containers = list(self.host1.containers.list())
     self.assertEqual(1, len(containers))
     self.assertEqual('container_foo', containers[0])
Ejemplo n.º 5
0
    def test_mem_total(self):
        """Ensure we honor max_containers"""
        self.host1.ping()
        self.host1.update({'max_containers': 1, 'mem_total': 6})
        self.host2.ping()
        self.host2.update({'max_containers': 1, 'mem_total': 5})
        self.host1 = hosts.get(self.host1.name)

        # create one container, it should go to host1 (more memory)
        container_requests.create('container_foo', self.container_data)
        container_requests.handle(self.host1)
        self.assertEqual(0, container_requests.count())
        self.assertEqual(1, self.host1.containers.count())
Ejemplo n.º 6
0
    def test_max_containers(self):
        """Ensure we honor max_containers"""
        self.host1.ping()
        self.host1.update({'max_containers': 1})
        self.host1 = hosts.get(self.host1.name)

        # create one container
        container_requests.create('container_foo', self.container_data)
        container_requests.handle(self.host1)
        self.assertEqual(0, container_requests.count())
        self.assertEqual(1, self.host1.containers.count())

        # create 2nd container, will stay stuck in queued
        container_requests.create('container_foo', self.container_data)
        container_requests.handle(self.host1)
        self.assertEqual(1, container_requests.count())
        self.assertEqual(1, self.host1.containers.count())
Ejemplo n.º 7
0
def ui_create_container():
    if g.user is None or 'openid' not in session:
        flash('You must be logged in to create a container')
        return redirect(url_for('login'))

    if request.method == 'POST':
        template, release = request.form['container-type'].split(':')
        data = {
            'requested_by': g.user.nickname,
            'state': 'QUEUED',
            'date_requested': int(time.time()),
            'template': template,
            'release': release,
            'max_memory': int(request.form['max-memory']) * 1000000000,
            'containermounts': [],
        }
        init_script = request.form['init-script'].replace('\r', '')
        if init_script:
            data['initscripts'] = [{'name': 'init', 'content': init_script}]

        print("ANDY", data)
        for x in request.form.keys():
            if x[:3] == 'ss_':
                directory = request.form[x]
                if directory:
                    ss = shared_storage.get(x[3:])
                    data['containermounts'].append({
                        'name': ss.name,
                        'type': ss.type,
                        'source': ss.source,
                        'directory': directory,
                    })
        container_requests.create(request.form['name'], data)
        flash('Container requested')
        return redirect(url_for('index'))

    ss = [shared_storage.get(x) for x in shared_storage.list()]
    scripts = g.user.to_dict()['initscripts']
    return render_template('create_container.html',
                           common_init_scripts=settings.INIT_SCRIPTS,
                           user_scripts=scripts,
                           shared_storage=ss,
                           container_types=settings.CONTAINER_TYPES)
Ejemplo n.º 8
0
Archivo: ui.py Proyecto: doanac/cya
def ui_create_container():
    if g.user is None or 'openid' not in session:
        flash('You must be logged in to create a container')
        return redirect(url_for('login'))

    if request.method == 'POST':
        template, release = request.form['container-type'].split(':')
        data = {
            'requested_by': g.user.nickname,
            'state': 'QUEUED',
            'date_requested': int(time.time()),
            'template': template,
            'release': release,
            'max_memory': int(request.form['max-memory']) * 1000000000,
            'containermounts': [],
        }
        init_script = request.form['init-script'].replace('\r', '')
        if init_script:
            data['initscripts'] = [{'name': 'init', 'content': init_script}]

        print("ANDY", data)
        for x in request.form.keys():
            if x[:3] == 'ss_':
                directory = request.form[x]
                if directory:
                    ss = shared_storage.get(x[3:])
                    data['containermounts'].append({
                        'name': ss.name,
                        'type': ss.type,
                        'source': ss.source,
                        'directory': directory,
                    })
        container_requests.create(request.form['name'], data)
        flash('Container requested')
        return redirect(url_for('index'))

    ss = [shared_storage.get(x) for x in shared_storage.list()]
    scripts = g.user.to_dict()['initscripts']
    return render_template('create_container.html',
                           common_init_scripts=settings.INIT_SCRIPTS,
                           user_scripts=scripts, shared_storage=ss,
                           container_types=settings.CONTAINER_TYPES)
Ejemplo n.º 9
0
 def test_offline(self):
     """The scheduler is okay if everything is offline"""
     container_requests.create('container_foo', self.container_data)
     container_requests.handle(self.host1)
     self.assertEqual(1, container_requests.count())