1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-15 12:59:06 +00:00

Allocate random names for Dynamips NIOs.

This commit is contained in:
grossmj 2015-04-12 18:14:45 -06:00
parent 78bc6e29a8
commit 443842e9b8
9 changed files with 27 additions and 127 deletions

View File

@ -20,6 +20,7 @@ Interface for FIFO NIOs.
""" """
import asyncio import asyncio
import uuid
from .nio import NIO from .nio import NIO
import logging import logging
@ -34,24 +35,12 @@ class NIOFIFO(NIO):
:param hypervisor: Dynamips hypervisor instance :param hypervisor: Dynamips hypervisor instance
""" """
_instance_count = 0
def __init__(self, hypervisor): def __init__(self, hypervisor):
# create an unique ID and name # create an unique name
nio_id = NIOFIFO._instance_count name = 'fifo-{}'.format(uuid.uuid4())
NIOFIFO._instance_count += 1
name = 'nio_fifo' + str(nio_id)
super().__init__(name, hypervisor) super().__init__(name, hypervisor)
@classmethod
def reset(cls):
"""
Reset the instance count.
"""
cls._instance_count = 0
@asyncio.coroutine @asyncio.coroutine
def create(self): def create(self):

View File

@ -20,6 +20,7 @@ Interface for generic Ethernet NIOs (PCAP library).
""" """
import asyncio import asyncio
import uuid
from .nio import NIO from .nio import NIO
import logging import logging
@ -35,25 +36,13 @@ class NIOGenericEthernet(NIO):
:param ethernet_device: Ethernet device name (e.g. eth0) :param ethernet_device: Ethernet device name (e.g. eth0)
""" """
_instance_count = 0
def __init__(self, hypervisor, ethernet_device): def __init__(self, hypervisor, ethernet_device):
# create an unique ID and name # create an unique name
nio_id = NIOGenericEthernet._instance_count name = 'generic_ethernet-{}'.format(uuid.uuid4())
NIOGenericEthernet._instance_count += 1
name = 'nio_gen_eth' + str(nio_id)
self._ethernet_device = ethernet_device self._ethernet_device = ethernet_device
super().__init__(name, hypervisor) super().__init__(name, hypervisor)
@classmethod
def reset(cls):
"""
Reset the instance count.
"""
cls._instance_count = 0
@asyncio.coroutine @asyncio.coroutine
def create(self): def create(self):

View File

@ -20,6 +20,7 @@ Interface for Linux Ethernet NIOs (Linux only).
""" """
import asyncio import asyncio
import uuid
from .nio import NIO from .nio import NIO
import logging import logging
@ -35,25 +36,12 @@ class NIOLinuxEthernet(NIO):
:param ethernet_device: Ethernet device name (e.g. eth0) :param ethernet_device: Ethernet device name (e.g. eth0)
""" """
_instance_count = 0
def __init__(self, hypervisor, ethernet_device): def __init__(self, hypervisor, ethernet_device):
# create an unique name
# create an unique ID and name name = 'linux_ethernet-{}'.format(uuid.uuid4())
nio_id = NIOLinuxEthernet._instance_count
NIOLinuxEthernet._instance_count += 1
name = 'nio_linux_eth' + str(nio_id)
self._ethernet_device = ethernet_device self._ethernet_device = ethernet_device
super().__init__(name, hypervisor) super().__init__(name, hypervisor)
@classmethod
def reset(cls):
"""
Reset the instance count.
"""
cls._instance_count = 0
@asyncio.coroutine @asyncio.coroutine
def create(self): def create(self):

View File

@ -20,6 +20,7 @@ Interface for multicast NIOs.
""" """
import asyncio import asyncio
import uuid
from .nio import NIO from .nio import NIO
import logging import logging
@ -36,27 +37,15 @@ class NIOMcast(NIO):
:param port: port for binding :param port: port for binding
""" """
_instance_count = 0
def __init__(self, hypervisor, group, port): def __init__(self, hypervisor, group, port):
# create an unique ID and name # create an unique name
nio_id = NIOMcast._instance_count name = 'mcast-{}'.format(uuid.uuid4())
NIOMcast._instance_count += 1
name = 'nio_mcast' + str(nio_id)
self._group = group self._group = group
self._port = port self._port = port
self._ttl = 1 # default TTL self._ttl = 1 # default TTL
super().__init__(name, hypervisor) super().__init__(name, hypervisor)
@classmethod
def reset(cls):
"""
Reset the instance count.
"""
cls._instance_count = 0
@asyncio.coroutine @asyncio.coroutine
def create(self): def create(self):

View File

@ -20,6 +20,7 @@ Interface for dummy NIOs (mostly for tests).
""" """
import asyncio import asyncio
import uuid
from .nio import NIO from .nio import NIO
import logging import logging
@ -34,24 +35,12 @@ class NIONull(NIO):
:param hypervisor: Dynamips hypervisor instance :param hypervisor: Dynamips hypervisor instance
""" """
_instance_count = 0
def __init__(self, hypervisor): def __init__(self, hypervisor):
# create an unique ID and name # create an unique name
nio_id = NIONull._instance_count name = 'null-{}'.format(uuid.uuid4())
NIONull._instance_count += 1
name = 'nio_null' + str(nio_id)
super().__init__(name, hypervisor) super().__init__(name, hypervisor)
@classmethod
def reset(cls):
"""
Reset the instance count.
"""
cls._instance_count = 0
@asyncio.coroutine @asyncio.coroutine
def create(self): def create(self):

View File

@ -20,6 +20,7 @@ Interface for TAP NIOs (UNIX based OSes only).
""" """
import asyncio import asyncio
import uuid
from .nio import NIO from .nio import NIO
import logging import logging
@ -35,25 +36,13 @@ class NIOTAP(NIO):
:param tap_device: TAP device name (e.g. tap0) :param tap_device: TAP device name (e.g. tap0)
""" """
_instance_count = 0
def __init__(self, hypervisor, tap_device): def __init__(self, hypervisor, tap_device):
# create an unique ID and name # create an unique name
nio_id = NIOTAP._instance_count name = 'tap-{}'.format(uuid.uuid4())
NIOTAP._instance_count += 1
name = 'nio_tap' + str(nio_id)
self._tap_device = tap_device self._tap_device = tap_device
super().__init__(name, hypervisor) super().__init__(name, hypervisor)
@classmethod
def reset(cls):
"""
Reset the instance count.
"""
cls._instance_count = 0
@asyncio.coroutine @asyncio.coroutine
def create(self): def create(self):

View File

@ -20,6 +20,7 @@ Interface for UDP NIOs.
""" """
import asyncio import asyncio
import uuid
from .nio import NIO from .nio import NIO
import logging import logging
@ -37,27 +38,15 @@ class NIOUDP(NIO):
:param rport: remote port number :param rport: remote port number
""" """
_instance_count = 0
def __init__(self, hypervisor, lport, rhost, rport): def __init__(self, hypervisor, lport, rhost, rport):
# create an unique ID and name # create an unique name
nio_id = NIOUDP._instance_count name = 'udp-{}'.format(uuid.uuid4())
NIOUDP._instance_count += 1
name = 'nio_udp' + str(nio_id)
self._lport = lport self._lport = lport
self._rhost = rhost self._rhost = rhost
self._rport = rport self._rport = rport
super().__init__(name, hypervisor) super().__init__(name, hypervisor)
@classmethod
def reset(cls):
"""
Reset the instance count.
"""
cls._instance_count = 0
@asyncio.coroutine @asyncio.coroutine
def create(self): def create(self):

View File

@ -20,6 +20,7 @@ Interface for UNIX NIOs (Unix based OSes only).
""" """
import asyncio import asyncio
import uuid
from .nio import NIO from .nio import NIO
import logging import logging
@ -36,26 +37,14 @@ class NIOUNIX(NIO):
:param remote_file: remote UNIX socket filename :param remote_file: remote UNIX socket filename
""" """
_instance_count = 0
def __init__(self, hypervisor, local_file, remote_file): def __init__(self, hypervisor, local_file, remote_file):
# create an unique ID and name # create an unique name
nio_id = NIOUNIX._instance_count name = 'unix-{}'.format(uuid.uuid4())
NIOUNIX._instance_count += 1
name = 'nio_unix' + str(nio_id)
self._local_file = local_file self._local_file = local_file
self._remote_file = remote_file self._remote_file = remote_file
super().__init__(name, hypervisor) super().__init__(name, hypervisor)
@classmethod
def reset(cls):
"""
Reset the instance count.
"""
cls._instance_count = 0
@asyncio.coroutine @asyncio.coroutine
def create(self): def create(self):

View File

@ -20,6 +20,7 @@ Interface for VDE (Virtual Distributed Ethernet) NIOs (Unix based OSes only).
""" """
import asyncio import asyncio
import uuid
from .nio import NIO from .nio import NIO
import logging import logging
@ -36,26 +37,14 @@ class NIOVDE(NIO):
:param local_file: VDE local filename :param local_file: VDE local filename
""" """
_instance_count = 0
def __init__(self, hypervisor, control_file, local_file): def __init__(self, hypervisor, control_file, local_file):
# create an unique ID and name # create an unique name
nio_id = NIOVDE._instance_count name = 'vde-{}'.format(uuid.uuid4())
NIOVDE._instance_count += 1
name = 'nio_vde' + str(nio_id)
self._control_file = control_file self._control_file = control_file
self._local_file = local_file self._local_file = local_file
super().__init__(name, hypervisor) super().__init__(name, hypervisor)
@classmethod
def reset(cls):
"""
Reset the instance count.
"""
cls._instance_count = 0
@asyncio.coroutine @asyncio.coroutine
def create(self): def create(self):