Esempio n. 1
0
def get_topology():  # noqa: E501
    """Return a topology with lists of node names and link ids

     # noqa: E501


    :rtype: Topology
    """

    topology = Topology()
    topology.nodes = [node["id"] for node in topo.get("nodes")]
    topology.links = [link["id"] for link in topo.get("links")]

    return topology
Esempio n. 2
0
def get_link(id):  # noqa: E501
    """get a link

     # noqa: E501

    :param id: The id of the link
    :type id: str

    :rtype: Link
    """
    raw_links = topo.get("links")
    if raw_links is None:
        abort(404)

    for link in raw_links:
        if str(link["id"]) == id:
            return Link(
                id=link["id"],
                node1_id=link["node1_id"],
                node2_id=link["node2_id"],
                delay_us=link["delay_us"],
                max_bw_mbps=link["max_bw_mbps"]
            )

    abort(404)
Esempio n. 3
0
def get_link_between_nodes(node1_id, node2_id):  # noqa: E501
    """get detailed information of a link between two specific nodes

     # noqa: E501

    :param node1_id: The id of the first node in the link
    :type node1_id: str
    :param node2_id: The id of the second node in the link
    :type node2_id: str

    :rtype: Link
    """
    raw_links = topo.get("links")
    if raw_links is None:
        abort(404)

    for link in raw_links:
        if ((str(link["node1_id"]) == node1_id and str(link["node2_id"]) == node2_id) or
                (str(link["node1_id"]) == node2_id and str(link["node2_id"]) == node1_id)
            ):
            return Link(
                id=link["id"],
                node1_id=node1_id,
                node2_id=node2_id,
                delay_us=link["delay_us"],
                max_bw_mbps=link["max_bw_mbps"]
            )

    abort(404)
Esempio n. 4
0
def get_nodes():  # noqa: E501
    """get a list of nodes

     # noqa: E501


    :rtype: List[Node]
    """
    raw_nodes = openstack_client.get_compute_data("/os-hypervisors/detail")
    # node_names = [raw_node["hypervisor_hostname"] for raw_node in raw_nodes.get("hypervisors")]
    raw_nodes = raw_nodes.get("hypervisors")
    if raw_nodes is None:
        abort(404)
    nodes = []
    # for node_name in node_names:
    #     nodes.append(get_node(node_name))
    for topo_node in topo.get("nodes"):
        ip = None
        n_cores = None
        ram_mb = None
        n_cores_free = None
        ram_free_mb = None
        status = None
        core_freq_mhz = topo_node.get("core_freq_MHz")
        ram_freq_mhz = topo_node.get("ram_freq_MHz")

        if topo_node["type"] == "compute":
            for raw_node in raw_nodes:
                if topo_node["id"] == raw_node["hypervisor_hostname"]:
                    ip=raw_node["host_ip"]
                    n_cores=raw_node["vcpus"]
                    ram_mb=raw_node["memory_mb"]
                    status=raw_node["status"]
                    n_cores_free=raw_node["vcpus"] - raw_node["vcpus_used"]
                    ram_free_mb=raw_node["free_ram_mb"]
                    break

        node = Node(
                # in some case, we need to use compute node name,
                # thus we use node name (hostname) as the node id
                id=topo_node["id"],
                name=topo_node["id"],
                type=topo_node["type"],
                ip=ip,
                n_cores=n_cores,
                core_freq_mhz=core_freq_mhz,
                ram_mb=ram_mb,
                ram_freq_mhz=ram_freq_mhz,
                status=status,
                n_cores_free=n_cores_free,
                ram_free_mb=ram_free_mb,
            )

        nodes.append(node)

    return nodes
Esempio n. 5
0
def get_links():  # noqa: E501
    """get list of link

     # noqa: E501


    :rtype: List[Link]
    """
    raw_links = topo.get("links")
    if raw_links is None:
        return None

    links = []
    for link in raw_links:
        links.append(
            Link(
                    id=link["id"],
                    node1_id=link["node1_id"],
                    node2_id=link["node2_id"],
                    delay_us=link["delay_us"],
                    max_bw_mbps=link["max_bw_mbps"]
                )
            )
    return links