def get_machine_record(machine_id): machine_rec = MongoConnection().get_machine_collection().find_one( {M_ID: machine_id} ) if machine_rec is not None: machine_rec.pop('_id') return machine_rec
def get_machine_record_by_name(cluster_id, name): machine_rec = MongoConnection().get_machine_collection().find_one( {CL_ID: cluster_id, M_NAME: name} ) if machine_rec is not None: machine_rec.pop('_id') return machine_rec
def get_all_clusters(): cluster_recs = MongoConnection().get_cluster_collection().find({}) result = [] for cluster_rec in cluster_recs: cluster_rec.pop('_id') result.append(cluster_rec) return result
def modify_status(machine_id, state, machine_obj=None): if machine_obj is None: machine_rec = get_machine_record(machine_id) machine = load_machine(machine_rec) else: machine = machine_obj machine.state = state MongoConnection().get_machine_collection().replace_one({M_ID: machine_id}, machine.json())
def get_machines_in_cluster(cluster_id): machine_recs = MongoConnection().get_machine_collection().find( {CL_ID: cluster_id} ) result = [] for machine_rec in machine_recs: machine_rec.pop('_id') result.append(machine_rec) return result
def get_cluster_record(cluster_id): cluster_rec = MongoConnection().get_cluster_collection().find_one( {CL_ID: cluster_id}) cluster_rec.pop('_id') return cluster_rec
def delete_cluster(cluster_id): MongoConnection().get_cluster_collection().remove({CL_ID: cluster_id})
def create_cluster(name, region): new_cluster = Cluster(name, region) cluster_record = new_cluster.json() MongoConnection().get_cluster_collection().insert_one(cluster_record) return new_cluster.cluster_id
def get_cluster_by_name(cluster_name): cluster_rec = MongoConnection().get_cluster_collection().find_one( {CL_NAME: cluster_name}) if cluster_rec is not None: cluster_rec.pop('_id') return cluster_rec
def add_machine_tag(machine_id, tag): machine_rec = get_machine_record(machine_id) machine = load_machine(machine_rec) if tag not in machine.tags: machine.tags.append(tag) MongoConnection().get_machine_collection().replace_one({M_ID: machine_id}, machine.json())
def delete_machine(machine_id): MongoConnection().get_machine_collection().remove( {M_ID: machine_id} )
def create_machine(cluster_id, name, ip, instance_type, tags): new_machine = Machine(cluster_id, name, ip, instance_type, tags) machine_rec = new_machine.json() MongoConnection().get_machine_collection().insert_one(machine_rec) return new_machine.machine_id
def remove_machine_tags(machine_id, tag): machine_rec = get_machine_record(machine_id) machine = load_machine(machine_rec) machine.tags = [mtag for mtag in machine.tags if mtag != tag] MongoConnection().get_machine_collection().replace_one({M_ID: machine_id}, machine.json())