Ejemplo n.º 1
0
def add_to_cluster(cluster):
    cluster = db.clusters.find_one({'_id': ObjectId(cluster)})
    manager = None
    for vm in cluster['vms']:
        if vm['role'] == 'manager':
            manager = vm

    server = Server(
        name='scaled_vm',
        image='Ubuntu-16-04',
        networks=['ece1548-net'],
        region='CORE',
        driver='openstack',
        flavor='m1.small',
        key='swascale_key'
        )
    server.create()
    manager = Server(_id=manager['_id'])
    server.swarm_join_worker(manager)
    cluster['vms'].append({
        '_id': str(server.uid),
        'role': 'worker'
    })
    cluster = db.clusters.update_one({'_id': cluster['_id']}, {
        '$set': {
            'vms': cluster['vms']
        }
    })

    update_targets()
Ejemplo n.º 2
0
def create():
    targets = []
    vm_manager = None
    for vm in request.json.get('vms'):
        if vm['role'] == 'manager':
            vm_manager = vm
            break
    server = Server(_id=vm_manager['_id'])
    server.swarm_init()
    targets.append(server.ips[server.networks[0]][0]['addr'] + ':' +
                   cfg.prometheus['PROMETHEUS_PORT'])

    for vm in request.json.get('vms'):
        if vm['_id'] != vm_manager['_id']:
            if vm['role'] == 'manager':
                manager = Server(_id=vm['_id'])
                manager.swarm_join_manager(server)
                targets.append(manager.ips[manager.networks[0]][0]['addr'] +
                               ':' + cfg.prometheus['PROMETHEUS_PORT'])
            elif vm['role'] == 'worker':
                worker = Server(_id=vm['_id'])
                worker.swarm_join_worker(server)
                targets.append(worker.ips[worker.networks[0]][0]['addr'] +
                               ':' + cfg.prometheus['PROMETHEUS_PORT'])
    cluster = db.clusters.insert({'vms': request.json.get('vms')})
    add_cluster_id.delay(targets, str(cluster))

    return 'created'
Ejemplo n.º 3
0
def create():
    targets = []
    vm_manager = None
    for vm in request.json.get('vms'):
        if vm['role'] == 'manager':
            vm_manager = vm
            break
    server = Server(_id=vm_manager['_id'])
    server.swarm_init()
    targets.append(server.ips[server.networks[0]][0]['addr'] + ':' +
                   cfg.prometheus['PROMETHEUS_PORT'])

    for vm in request.json.get('vms'):
        if vm['_id'] != vm_manager['_id']:
            if vm['role'] == 'manager':
                manager = Server(_id=vm['_id'])
                manager.swarm_join_manager(server)
                targets.append(manager.ips[manager.networks[0]][0]['addr'] +
                               ':' + cfg.prometheus['PROMETHEUS_PORT'])
            elif vm['role'] == 'worker':
                worker = Server(_id=vm['_id'])
                worker.swarm_join_worker(server)
                targets.append(worker.ips[worker.networks[0]][0]['addr'] +
                               ':' + cfg.prometheus['PROMETHEUS_PORT'])
    cluster = db.clusters.insert({'vms': request.json.get('vms')})
    if 'up' in request.get_json():
        rule = request.json.get('up')
        direction = 'up'
        db.clusters.update_one({'_id': cluster}, {
            '$set': {'up': request.json.get('up')}
            })

    if 'down' in request.get_json():
        rule = request.json.get('down')
        direction = 'down'
        db.clusters.update_one({'_id': cluster}, {
            '$set': {'down': request.json.get('down')}
            })

    add_cluster_id.delay(targets, str(cluster))

    return 'created'