Example #1
0
def get_executer_data(query, recursive=False, include_unattached=False):
    from app.models import Project, Datacenter, Group, Host

    host_fields = list(Host.FIELDS)
    group_fields = list(Group.FIELDS)

    if recursive:
        host_fields += ["all_tags", "all_custom_fields"]
        group_fields += ["all_tags", "all_custom_fields"]

    projects = Project.find(query)
    projects = cursor_to_list(projects)
    project_ids = [x["_id"] for x in projects]

    groups = Group.find({"project_id": {"$in": project_ids}})
    groups = cursor_to_list(groups, fields=group_fields)
    group_ids = [x["_id"] for x in groups]

    if include_unattached:
        hosts = Host.find({})
    else:
        hosts = Host.find({"group_id": {"$in": group_ids}})
    hosts = cursor_to_list(hosts, fields=host_fields)

    datacenters = Datacenter.find({})
    datacenters = cursor_to_list(datacenters)
    return {
        "datacenters": datacenters,
        "projects": projects,
        "groups": groups,
        "hosts": hosts
    }
Example #2
0
def executer_data():
    from app.models import Project, Datacenter, Group, Host
    if "projects" not in request.values:
        return json_response(
            {
                "errors":
                ["'projects' parameter is required for executer_data handler"]
            }, 400)
    project_names = request.values["projects"].split(",")

    projects = Project.find({"name": {"$in": project_names}})
    projects = cursor_to_list(projects)
    project_ids = [x["_id"] for x in projects]

    groups = Group.find({"project_id": {"$in": project_ids}})
    groups = cursor_to_list(groups)
    group_ids = [x["_id"] for x in groups]

    hosts = Host.find({"group_id": {"$in": group_ids}})
    hosts = cursor_to_list(hosts)

    datacenters = Datacenter.find({})
    datacenters = cursor_to_list(datacenters)

    results = {
        "datacenters": datacenters,
        "projects": projects,
        "groups": groups,
        "hosts": hosts
    }
    return json_response({"data": results})
Example #3
0
def show(datacenter_id=None):
    from app.models import Datacenter
    if datacenter_id is None:
        query = {}
        if "_filter" in request.values:
            name_filter = request.values["_filter"]
            if len(name_filter) >= 2:
                query["name"] = {"$regex": "^%s" % name_filter}
        datacenters = Datacenter.find(query)
    else:
        datacenter_id = resolve_id(datacenter_id)
        datacenters = Datacenter.find(
            {"$or": [{
                "_id": datacenter_id
            }, {
                "name": datacenter_id
            }]})
        if datacenters.count() == 0:
            return json_response({"errors": ["Datacenter not found"]}, 404)
    data = paginated_data(datacenters.sort("name"))
    return json_response(data)