Exemple #1
0
def list_services_workers(**_):
    """
    List number of workers for each services in the system.
    
    Variables:
    None
    
    Arguments:
    None
    
    Data Block:
    None
    
    Result example:
    {"MY SERVICE": 1, ... } # Dictionary of services and number of workers
    """
    services = {s["name"]: 0 for s in STORAGE.list_services() if s['enabled']}
    profiles = STORAGE.get_profiles_dict(
        list(
            set([
                p["_yz_rk"] for p in STORAGE.stream_search(
                    "profile", "_yz_rk:*", fl="_yz_rk")
            ])))
    used_profiles = {
        n['mac_address']: n['profile']
        for n in STORAGE.get_nodes(STORAGE.list_node_keys())
        if n['profile'] != ""
    }

    for _mac, used_p in used_profiles.iteritems():
        if used_p in profiles:
            for srv, cfg in profiles[used_p]["services"].iteritems():
                if srv in services:
                    services[srv] += cfg["workers"]

            for srv, cfg in profiles[used_p]["virtual_machines"].iteritems():
                if srv in services:
                    vm = STORAGE.get_virtualmachine(srv)
                    if not vm:
                        continue
                    services[srv] += vm['num_workers'] * cfg['num_instances']

    return make_api_response(services, err=[profiles, used_profiles, services])
Exemple #2
0
def get_system_configuration_overview(**_):
    """
    Display a system configuration overview.
    
    Variables:
    None
    
    Arguments:
    None
    
    Data Block:
    None
    
    Result example:
    {
     "errors": {          # Errors in the current config 
       "profiles": [],      # Profiles in error
       "services": [] },    # Services in error
     "services": {        # Services overview
       "SRV_NAME": {        # Single service overview 
         "enabled": True,     # is enabled?
         "profiles" : [],     # profiles referencing it
         "queue": 0,          # items in queue
         "workers": 1 },      # number of workers
       ...,} 
    }
    """
    errors = {"services": [], "profiles": []}
    services = {
        s["name"]: {
            "workers": 0,
            "enabled": s["enabled"],
            "profiles": [],
            "queue": 0
        }
        for s in STORAGE.list_services()
    }
    profiles = STORAGE.get_profiles_dict(
        list(
            set([
                p["_yz_rk"] for p in STORAGE.stream_search(
                    "profile", "_yz_rk:*", fl="_yz_rk")
            ])))
    used_profiles = {
        n['mac_address']: n['profile']
        for n in STORAGE.get_nodes(STORAGE.list_node_keys())
        if n['profile'] != ""
    }

    for mac, used_p in used_profiles.iteritems():
        if profiles.has_key(used_p):
            for srv, cfg in profiles[used_p]["services"].iteritems():
                if not services.has_key(srv):
                    errors["services"].append({
                        "service": srv,
                        "profile": used_p
                    })
                    continue
                services[srv]["workers"] += cfg["workers"]
                if used_p not in services[srv]["profiles"]:
                    services[srv]["profiles"].append(used_p)

            for srv, cfg in profiles[used_p]["virtual_machines"].iteritems():
                if not services.has_key(srv):
                    errors["services"].append({
                        "service": srv,
                        "profile": used_p
                    })
                    continue

                vm = STORAGE.get_virtualmachine(srv)
                if not vm:
                    errors["services"].append({
                        "service": srv,
                        "profile": used_p
                    })
                    continue

                services[srv][
                    "workers"] += vm['num_workers'] * cfg['num_instances']
                if used_p not in services[srv]["profiles"]:
                    services[srv]["profiles"].append(used_p)
        else:
            errors["profiles"].append({"profile": used_p, "mac": mac})

    for srv in services:
        services[srv]["queue"] = get_service_queue_length(srv)

    return make_api_response({"services": services, "errors": errors})