示例#1
0
文件: soe.py 项目: 5growth/5gr-so
def query_ns(nsId):
    """
    Returns the information of the Network Service Instance identified by nsId.
    Parameters
    ----------
    nsId: string
        Identifier of the NS instance to terminate.
    Returns
    -------
    dict
        Information of the Network Service Instance.
    """

    if not ns_db.exists_nsId(nsId):
        # TODO create errors
        return 404
    # TODO: lines below are a stub
    status = ns_db.get_ns_status(nsId)
    vs_status = "FAILED"
    if status in ["TERMINATED", "INSTANTIATING", "TERMINATING"]:
        vs_status = "NOT_INSTANTIATED"
    elif status == "INSTANTIATED":
        vs_status = "INSTANTIATED"

    nsd_id = ns_db.get_nsdId(nsId)
    nsd_json = nsd_db.get_nsd_json(nsd_id)
    ns_name = ns_db.get_ns_name(nsId)
    ns_description = ns_db.get_ns_description(nsId)
    flavour_id = ns_db.get_ns_flavour_id(nsId)
    info = {
        "nsInstanceId": nsId,
        "nsName": ns_name,
        "description": ns_description,
        "nsdId": nsd_id,
        "flavourId": flavour_id,
        "nsState": vs_status,
    }
    #turn void the sap_info and the monitoring if the service is terminated
    if vs_status == "NOT_INSTANTIATED":
        info["sapInfo"] = []
        log_queue.put(["INFO", "hola"])
        return info

    if "sapd" in nsd_json["nsd"]:
        total_sap_info = get_ns_sap_info(nsId, nsd_json["nsd"]["sapd"])
        if total_sap_info is not None:
            info["sapInfo"] = total_sap_info

    dashboard_info = ns_db.get_dashboard_info(nsId)
    if "dashboardUrl" in dashboard_info.keys():
        info["monitoringDashboardUrl"] = dashboard_info["dashboardUrl"]

    log_queue.put(
        ["INFO",
         "query_result: %s" % dumps(info, indent=4, sort_keys=True)])
    return info
示例#2
0
def query_ns(nsId):
    """
    Returns the information of the Network Service Instance identified by nsId.
    Parameters
    ----------
    nsId: string
        Identifier of the NS instance to terminate.
    Returns
    -------
    dict
        Information of the Network Service Instance.
    """

    if not ns_db.exists_nsId(nsId):
        return 404

    status = ns_db.get_ns_status(nsId)
    nsd_id = ns_db.get_nsdId(nsId)
    nsd_json = nsd_db.get_nsd_json(nsd_id)
    ns_name = ns_db.get_ns_name(nsId)
    ns_description = ns_db.get_ns_description(nsId)
    flavour_id = ns_db.get_ns_flavour_id(nsId)
    info = {
        "nsInstanceId": nsId,
        "nsName": ns_name,
        "description": ns_description,
        "nsdId": nsd_id,
        "flavourId": flavour_id,
        "nsState": status,
    }
    if "sapd" in nsd_json["nsd"]:
        info["sapInfo"] = get_ns_sap_info(nsId, nsd_json["nsd"]["sapd"])

    query_result = {"queryNsResult": [info]}
    log_queue.put([
        "DEBUG",
        "query_result: %s" % dumps(query_result, indent=4, sort_keys=True)
    ])
    return query_result