Esempio n. 1
0
def change_plan_status(plan_name, new_state, plan_type = ""):
    """
        Turn plan on and off.
    """
    plans_collection = tingDB_service.get_config_collection("plans")

    if plan_type == "":
        # We get the type ourselves
        plan_cursor = plans_collection.find({"plan_name": plan_name})
        plan_type = plan_cursor[0]["type"]

    doc_col = plan_composer.get_collection_name_for_plan_type(plan_type)

    if new_state == "online":
        ret_data = start_plan(plan_name, doc_col)
    elif new_state == "offline":
        ret_data = stop_plan(plan_name, doc_col)
    else:
        return False

    if ret_data != "":
        plans_collection.update({"plan_name": plan_name},
                                {"$set": {"status": new_state}})

    return True
Esempio n. 2
0
def __get_server_for_plan(plan):
    """
        Get server descriptor from plan descriptor.
    """
    plan_name = plan["_id"]
    plan_type = plan["type"]
    col_name = plan_composer.get_collection_name_for_plan_type(plan_type)
    servers_collection = tingDB_service.get_config_collection(col_name)

    server_cursor = servers_collection.find({"_id": plan_name})
    return server_cursor[0]