Example #1
0
    def read_device(self, device_element):
        node_id = get_int(device_element, "id")
        name = device_element.get("name")
        model = device_element.get("type")
        node_options = NodeOptions(name, model)

        service_elements = device_element.find("services")
        if service_elements is not None:
            node_options.services = [
                x.get("name") for x in service_elements.iterchildren()
            ]

        position_element = device_element.find("position")
        if position_element is not None:
            x = get_int(position_element, "x")
            y = get_int(position_element, "y")
            if all([x, y]):
                node_options.set_position(x, y)

            lat = get_float(position_element, "lat")
            lon = get_float(position_element, "lon")
            alt = get_float(position_element, "alt")
            if all([lat, lon, alt]):
                node_options.set_location(lat, lon, alt)

        logging.info("reading node id(%s) model(%s) name(%s)", node_id, model,
                     name)
        self.session.add_node(_id=node_id, node_options=node_options)
Example #2
0
    def AddNode(self, request, context):
        logging.debug("add node: %s", request)
        session = self.get_session(request.session_id, context)

        node_proto = request.node
        node_id = node_proto.id
        node_type = node_proto.type
        if node_type is None:
            node_type = NodeTypes.DEFAULT.value
        node_type = NodeTypes(node_type)

        node_options = NodeOptions(name=node_proto.name,
                                   model=node_proto.model)
        node_options.icon = node_proto.icon
        node_options.opaque = node_proto.opaque
        node_options.services = node_proto.services

        position = node_proto.position
        node_options.set_position(position.x, position.y)
        node_options.set_location(position.lat, position.lon, position.alt)
        node = session.add_node(_type=node_type,
                                _id=node_id,
                                node_options=node_options)

        # configure emane if provided
        emane_model = node_proto.emane
        if emane_model:
            session.emane.set_model_config(node_id, emane_model)

        return core_pb2.AddNodeResponse(node_id=node.id)
Example #3
0
def add_node_data(
        node_proto: core_pb2.Node) -> Tuple[NodeTypes, int, NodeOptions]:
    """
    Convert node protobuf message to data for creating a node.

    :param node_proto: node proto message
    :return: node type, id, and options
    """
    _id = node_proto.id
    _type = node_proto.type
    if _type is None:
        _type = NodeTypes.DEFAULT.value
    _type = NodeTypes(_type)

    options = NodeOptions(name=node_proto.name, model=node_proto.model)
    options.icon = node_proto.icon
    options.opaque = node_proto.opaque
    options.image = node_proto.image
    options.services = node_proto.services
    options.config_services = node_proto.config_services
    if node_proto.emane:
        options.emane = node_proto.emane
    if node_proto.server:
        options.server = node_proto.server

    position = node_proto.position
    options.set_position(position.x, position.y)
    if node_proto.HasField("geo"):
        geo = node_proto.geo
        options.set_location(geo.lat, geo.lon, geo.alt)
    return _type, _id, options
Example #4
0
def add_node_data(node_proto):
    """
    Convert node protobuf message to data for creating a node.

    :param core_pb2.Node node_proto: node proto message
    :return: node type, id, and options
    :rtype: tuple
    """
    _id = node_proto.id
    _type = node_proto.type
    if _type is None:
        _type = NodeTypes.DEFAULT.value
    _type = NodeTypes(_type)

    options = NodeOptions(name=node_proto.name, model=node_proto.model)
    options.icon = node_proto.icon
    options.opaque = node_proto.opaque
    options.image = node_proto.image
    options.services = node_proto.services
    if node_proto.emane:
        options.emane = node_proto.emane
    if node_proto.server:
        options.server = node_proto.server

    position = node_proto.position
    options.set_position(position.x, position.y)
    options.set_location(position.lat, position.lon, position.alt)
    return _type, _id, options
Example #5
0
    def read_device(self, device_element):
        node_id = get_int(device_element, "id")
        name = device_element.get("name")
        model = device_element.get("type")
        node_options = NodeOptions(name, model)

        service_elements = device_element.find("services")
        if service_elements is not None:
            node_options.services = [x.get("name") for x in service_elements.iterchildren()]

        position_element = device_element.find("position")
        if position_element is not None:
            x = get_float(position_element, "x")
            y = get_float(position_element, "y")
            if all([x, y]):
                node_options.set_position(x, y)

            lat = get_float(position_element, "lat")
            lon = get_float(position_element, "lon")
            alt = get_float(position_element, "alt")
            if all([lat, lon, alt]):
                node_options.set_location(lat, lon, alt)

        logger.info("reading node id(%s) model(%s) name(%s)", node_id, model, name)
        self.session.add_node(_id=node_id, node_options=node_options)
Example #6
0
    def read_device(self, device_element: etree.Element) -> None:
        node_id = get_int(device_element, "id")
        name = device_element.get("name")
        model = device_element.get("type")
        icon = device_element.get("icon")
        clazz = device_element.get("class")
        image = device_element.get("image")
        options = NodeOptions(name, model, image)
        options.icon = icon

        self.save_ntwk_node_attributes(node_id, str(name), str(model))

        node_type = NodeTypes.DEFAULT
        if clazz == "docker":
            node_type = NodeTypes.DOCKER
        elif clazz == "lxc":
            node_type = NodeTypes.LXC

        service_elements = device_element.find("services")
        if service_elements is not None:
            options.services = [
                x.get("name") for x in service_elements.iterchildren()
            ]

        config_service_elements = device_element.find("configservices")
        if config_service_elements is not None:
            options.config_services = [
                x.get("name") for x in config_service_elements.iterchildren()
            ]

        position_element = device_element.find("position")
        if position_element is not None:
            x = get_float(position_element, "x")
            y = get_float(position_element, "y")
            if all([x, y]):
                options.set_position(x, y)

            lat = get_float(position_element, "lat")
            lon = get_float(position_element, "lon")
            alt = get_float(position_element, "alt")
            if all([lat, lon, alt]):
                options.set_location(lat, lon, alt)

        logging.info("reading node id(%s) model(%s) name(%s)", node_id, model,
                     name)
        self.session.add_node(_type=node_type, _id=node_id, options=options)