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_vm(vm_data):
    server = Server(name=vm_data['name'],
                    image=vm_data['image'],
                    networks=vm_data['networks'],
                    region=vm_data['region'],
                    driver=vm_data['driver'],
                    flavor=vm_data['flavor'],
                    key=vm_data['key'])
    server.create()