diff --git a/gns3server/controller/ports/port.py b/gns3server/controller/ports/port.py index 419cc226..fb9acae8 100644 --- a/gns3server/controller/ports/port.py +++ b/gns3server/controller/ports/port.py @@ -27,6 +27,8 @@ class Port: self._port_number = port_number self._name = name self._short_name = short_name + self._adapter_type = None + self._mac_address = None self._link = None @property @@ -48,6 +50,22 @@ class Port: def port_number(self): return self._port_number + @property + def adapter_type(self): + return self._adapter_type + + @adapter_type.setter + def adapter_type(self, val): + self._adapter_type = val + + @property + def mac_address(self): + return self._mac_address + + @mac_address.setter + def mac_address(self, val): + self._mac_address = val + @property def data_link_types(self): """ @@ -81,5 +99,7 @@ class Port: "data_link_types": self.data_link_types, "port_number": self._port_number, "adapter_number": self._adapter_number, + "adapter_type": self._adapter_type, + "mac_address": self._mac_address, "link_type": self.link_type } diff --git a/gns3server/controller/ports/port_factory.py b/gns3server/controller/ports/port_factory.py index c6f5ba6b..6189de6c 100644 --- a/gns3server/controller/ports/port_factory.py +++ b/gns3server/controller/ports/port_factory.py @@ -17,6 +17,7 @@ import aiohttp +from gns3server.utils import macaddress_to_int, int_to_macaddress from .atm_port import ATMPort from .frame_relay_port import FrameRelayPort from .gigabitethernet_port import GigabitEthernetPort @@ -92,6 +93,11 @@ class StandardPortFactory: else: segment_number += 1 + port.adapter_type = custom_adapter_settings.get("adapter_type", properties.get("adapter_type", None)) + mac_address = custom_adapter_settings.get("mac_address") + if not mac_address and "mac_address" in properties: + mac_address = int_to_macaddress(macaddress_to_int(properties["mac_address"]) + adapter_number) + port.mac_address = mac_address ports.append(port) if len(ports): diff --git a/gns3server/schemas/node.py b/gns3server/schemas/node.py index f8071195..896b6f94 100644 --- a/gns3server/schemas/node.py +++ b/gns3server/schemas/node.py @@ -219,6 +219,11 @@ NODE_OBJECT_SCHEMA = { "type": "integer", "description": "Adapter slot" }, + "adapter_type": { + "description": "Adapter type", + "type": ["string", "null"], + "minLength": 1, + }, "port_number": { "type": "integer", "description": "Port slot" @@ -229,9 +234,15 @@ NODE_OBJECT_SCHEMA = { }, "data_link_types": { "type": "object", - "description": "Available PCAP type for capture", + "description": "Available PCAP types for capture", "properties": {} }, + "mac_address": { + "description": "MAC address (if available)", + "type": ["string", "null"], + "minLength": 1, + "pattern": "^([0-9a-fA-F]{2}[:]){5}([0-9a-fA-F]{2})$" + }, }, "additionalProperties": False } diff --git a/gns3server/utils/__init__.py b/gns3server/utils/__init__.py index abefda8d..06b56d0d 100644 --- a/gns3server/utils/__init__.py +++ b/gns3server/utils/__init__.py @@ -17,7 +17,6 @@ import re -import os import textwrap import posixpath