mirror of
https://github.com/GNS3/gns3-server.git
synced 2024-11-17 09:14:52 +02:00
77 lines
2.0 KiB
Python
77 lines
2.0 KiB
Python
|
# -*- coding: utf-8 -*-
|
||
|
#
|
||
|
# Copyright (C) 2013 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/>.
|
||
|
|
||
|
"""
|
||
|
Hub object that uses the Bridge interface to create a hub with ports.
|
||
|
"""
|
||
|
|
||
|
from __future__ import unicode_literals
|
||
|
from .bridge import Bridge
|
||
|
from ..dynamips_error import DynamipsError
|
||
|
|
||
|
|
||
|
class Hub(Bridge):
|
||
|
"""
|
||
|
Dynamips hub (based on Bridge)
|
||
|
|
||
|
:param hypervisor: Dynamips hypervisor object
|
||
|
:param name: name for this hub
|
||
|
"""
|
||
|
|
||
|
def __init__(self, hypervisor, name):
|
||
|
|
||
|
Bridge.__init__(self, hypervisor, name)
|
||
|
self._mapping = {}
|
||
|
|
||
|
@property
|
||
|
def mapping(self):
|
||
|
"""
|
||
|
Returns port mapping
|
||
|
|
||
|
:returns: mapping list
|
||
|
"""
|
||
|
|
||
|
return self._mapping
|
||
|
|
||
|
def add_nio(self, nio, port):
|
||
|
"""
|
||
|
Adds a NIO as new port on this hub.
|
||
|
|
||
|
:param nio: NIO object to add
|
||
|
:param port: port to allocate for the NIO
|
||
|
"""
|
||
|
|
||
|
if port in self._mapping:
|
||
|
raise DynamipsError("Port {} isn't free".format(port))
|
||
|
|
||
|
Bridge.add_nio(self, nio)
|
||
|
self._mapping[port] = nio
|
||
|
|
||
|
def remove_nio(self, port):
|
||
|
"""
|
||
|
Removes the specified NIO as member of this hub.
|
||
|
|
||
|
:param port: allocated port
|
||
|
"""
|
||
|
|
||
|
if port not in self._mapping:
|
||
|
raise DynamipsError("Port {} is not allocated".format(port))
|
||
|
|
||
|
nio = self._mapping[port]
|
||
|
Bridge.remove_nio(self, nio)
|
||
|
del self._mapping[port]
|