1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-13 20:08:55 +00:00

Returns the ports' adapter types and mac addresses when available.

This commit is contained in:
grossmj 2018-04-06 13:19:17 +07:00
parent adc2f69d5d
commit 7622c10cc9
4 changed files with 38 additions and 2 deletions

View File

@ -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
}

View File

@ -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):

View File

@ -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
}

View File

@ -17,7 +17,6 @@
import re
import os
import textwrap
import posixpath