Exemplo n.º 1
0
def delete(cluster_id):
    cluster = db.clusters.find_one({'_id': ObjectId(cluster_id)})
    for vm in cluster['vms']:
        vm = Server(_id=vm['_id'])
        vm.swarm_leave()

    delete_cluster_id.delay(cluster_id)
    delete_rule.delay(cluster_id)
    db.clusters.remove({'_id': ObjectId(cluster_id)})
    return 'cluster removed'
Exemplo n.º 2
0
def remove_from_cluster(cluster):
    cluster = db.clusters.find_one({'_id': ObjectId(cluster)})
    worker = None
    for vm in cluster['vms']:
        if vm['role'] == 'worker':
            worker = vm
            break

    if worker is not None:
        cluster['vms'].remove(worker)
        worker = Server(_id=worker['_id'])
        worker.swarm_leave()
        Server.delete(worker.uid)

        cluster = db.clusters.update_one({'_id': cluster['_id']}, {
            '$set': {
                'vms': cluster['vms']
            }
        })

        update_targets()