import json


def _get_ascend_rankfile(rank_table_file_path):
    """
    Args:
    rank_table_file_path: ascend npu rank file json
    {
        "status": "completed",
        "version": "1.0",
        "server_count": "2",
        "server_list": [
            {
                "server_id": "192.168.24.217",
                "device": [
                    {
                        "device_id": "0",
                        "device_ip": "192.1.184.23",
                        "rank_id": "0"
                    },
                    {
                        "device_id": "1",
                        "device_ip": "192.2.21.93",
                        "rank_id": "1"
                    }
                ]
            },
            {
                "server_id": "192.168.26.177",
                "device": [
                    {
                        "device_id": "0",
                        "device_ip": "192.1.94.132",
                        "rank_id": "2"
                    },
                    {
                        "device_id": "1",
                        "device_ip": "192.2.94.30",
                        "rank_id": "3"
                    }
                ]
            }
        ]
    }

    Returns:
        node_ips: node ip list
        device_count: number of npu per machine

    """
    json_data = None
    with open(rank_table_file_path) as json_file:
        json_data = json.load(json_file)

    node_ips = []
    device_count = 0
    server_list = json_data['server_list']
    for server in server_list:
        node_ips.append(server['server_id'])
        device_list = server['device']
        device_count = len(device_list)

    return node_ips, device_count