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()
def delete(uid): Server.delete(uid) return 'deleted'