1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-12-25 16:28:11 +00:00
gns3-server/gns3server/compute/adapters/adapter.py

106 lines
2.5 KiB
Python
Raw Normal View History

2014-07-12 19:18:25 +00:00
# -*- coding: utf-8 -*-
#
# Copyright (C) 2014 GNS3 Technologies Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
class Adapter(object):
2015-01-20 12:24:00 +00:00
2014-07-12 19:18:25 +00:00
"""
Base class for adapters.
:param interfaces: number of interfaces supported by this adapter.
"""
def __init__(self, interfaces=1):
self._interfaces = interfaces
self._ports = {}
for port_number in range(0, interfaces):
self._ports[port_number] = None
2014-07-12 19:18:25 +00:00
def removable(self):
"""
Returns True if the adapter can be removed from a slot
and False if not.
:returns: boolean
"""
return True
def port_exists(self, port_number):
2014-07-12 19:18:25 +00:00
"""
Checks if a port exists on this adapter.
:returns: True is the port exists,
False otherwise.
"""
if port_number in self._ports:
2014-07-12 19:18:25 +00:00
return True
return False
def add_nio(self, port_number, nio):
2014-07-12 19:18:25 +00:00
"""
Adds a NIO to a port on this adapter.
:param port_number: port number (integer)
2014-07-12 19:18:25 +00:00
:param nio: NIO instance
"""
self._ports[port_number] = nio
2014-07-12 19:18:25 +00:00
def remove_nio(self, port_number):
2014-07-12 19:18:25 +00:00
"""
Removes a NIO from a port on this adapter.
:param port_number: port number (integer)
2014-07-12 19:18:25 +00:00
"""
self._ports[port_number] = None
2014-07-12 19:18:25 +00:00
def get_nio(self, port_number):
2014-07-12 19:18:25 +00:00
"""
Returns the NIO assigned to a port.
:params port_number: port number (integer)
2014-07-12 19:18:25 +00:00
:returns: NIO instance
"""
return self._ports[port_number]
2014-07-12 19:18:25 +00:00
@property
def ports(self):
"""
Returns port to NIO mapping
:returns: dictionary port -> NIO
"""
return self._ports
@property
def interfaces(self):
"""
Returns the number of interfaces supported by this adapter.
:returns: number of interfaces
"""
return self._interfaces