Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
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
Ejemplo n.º 3
0
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
Ejemplo n.º 4
0
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())
Ejemplo n.º 5
0
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
Ejemplo n.º 6
0
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
Ejemplo n.º 7
0
def delete_cluster(cluster_id):
    MongoConnection().get_cluster_collection().remove({CL_ID: cluster_id})
Ejemplo n.º 8
0
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
Ejemplo n.º 9
0
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
Ejemplo n.º 10
0
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())
Ejemplo n.º 11
0
def delete_machine(machine_id):
    MongoConnection().get_machine_collection().remove(
        {M_ID: machine_id}
    )
Ejemplo n.º 12
0
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
Ejemplo n.º 13
0
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())