From 443842e9b8cfa292c28e809a6d7577d46a352f7b Mon Sep 17 00:00:00 2001 From: grossmj Date: Sun, 12 Apr 2015 18:14:45 -0600 Subject: [PATCH] Allocate random names for Dynamips NIOs. --- gns3server/modules/dynamips/nios/nio_fifo.py | 17 +++-------------- .../dynamips/nios/nio_generic_ethernet.py | 17 +++-------------- .../dynamips/nios/nio_linux_ethernet.py | 18 +++--------------- gns3server/modules/dynamips/nios/nio_mcast.py | 17 +++-------------- gns3server/modules/dynamips/nios/nio_null.py | 17 +++-------------- gns3server/modules/dynamips/nios/nio_tap.py | 17 +++-------------- gns3server/modules/dynamips/nios/nio_udp.py | 17 +++-------------- gns3server/modules/dynamips/nios/nio_unix.py | 17 +++-------------- gns3server/modules/dynamips/nios/nio_vde.py | 17 +++-------------- 9 files changed, 27 insertions(+), 127 deletions(-) diff --git a/gns3server/modules/dynamips/nios/nio_fifo.py b/gns3server/modules/dynamips/nios/nio_fifo.py index f1d763fc..9e7695a2 100644 --- a/gns3server/modules/dynamips/nios/nio_fifo.py +++ b/gns3server/modules/dynamips/nios/nio_fifo.py @@ -20,6 +20,7 @@ Interface for FIFO NIOs. """ import asyncio +import uuid from .nio import NIO import logging @@ -34,24 +35,12 @@ class NIOFIFO(NIO): :param hypervisor: Dynamips hypervisor instance """ - _instance_count = 0 - def __init__(self, hypervisor): - # create an unique ID and name - nio_id = NIOFIFO._instance_count - NIOFIFO._instance_count += 1 - name = 'nio_fifo' + str(nio_id) + # create an unique name + name = 'fifo-{}'.format(uuid.uuid4()) super().__init__(name, hypervisor) - @classmethod - def reset(cls): - """ - Reset the instance count. - """ - - cls._instance_count = 0 - @asyncio.coroutine def create(self): diff --git a/gns3server/modules/dynamips/nios/nio_generic_ethernet.py b/gns3server/modules/dynamips/nios/nio_generic_ethernet.py index dcc13bae..870ecb13 100644 --- a/gns3server/modules/dynamips/nios/nio_generic_ethernet.py +++ b/gns3server/modules/dynamips/nios/nio_generic_ethernet.py @@ -20,6 +20,7 @@ Interface for generic Ethernet NIOs (PCAP library). """ import asyncio +import uuid from .nio import NIO import logging @@ -35,25 +36,13 @@ class NIOGenericEthernet(NIO): :param ethernet_device: Ethernet device name (e.g. eth0) """ - _instance_count = 0 - def __init__(self, hypervisor, ethernet_device): - # create an unique ID and name - nio_id = NIOGenericEthernet._instance_count - NIOGenericEthernet._instance_count += 1 - name = 'nio_gen_eth' + str(nio_id) + # create an unique name + name = 'generic_ethernet-{}'.format(uuid.uuid4()) self._ethernet_device = ethernet_device super().__init__(name, hypervisor) - @classmethod - def reset(cls): - """ - Reset the instance count. - """ - - cls._instance_count = 0 - @asyncio.coroutine def create(self): diff --git a/gns3server/modules/dynamips/nios/nio_linux_ethernet.py b/gns3server/modules/dynamips/nios/nio_linux_ethernet.py index 500123b5..cf96f4af 100644 --- a/gns3server/modules/dynamips/nios/nio_linux_ethernet.py +++ b/gns3server/modules/dynamips/nios/nio_linux_ethernet.py @@ -20,6 +20,7 @@ Interface for Linux Ethernet NIOs (Linux only). """ import asyncio +import uuid from .nio import NIO import logging @@ -35,25 +36,12 @@ class NIOLinuxEthernet(NIO): :param ethernet_device: Ethernet device name (e.g. eth0) """ - _instance_count = 0 - def __init__(self, hypervisor, ethernet_device): - - # create an unique ID and name - nio_id = NIOLinuxEthernet._instance_count - NIOLinuxEthernet._instance_count += 1 - name = 'nio_linux_eth' + str(nio_id) + # create an unique name + name = 'linux_ethernet-{}'.format(uuid.uuid4()) self._ethernet_device = ethernet_device super().__init__(name, hypervisor) - @classmethod - def reset(cls): - """ - Reset the instance count. - """ - - cls._instance_count = 0 - @asyncio.coroutine def create(self): diff --git a/gns3server/modules/dynamips/nios/nio_mcast.py b/gns3server/modules/dynamips/nios/nio_mcast.py index f59dc280..4ea47dc2 100644 --- a/gns3server/modules/dynamips/nios/nio_mcast.py +++ b/gns3server/modules/dynamips/nios/nio_mcast.py @@ -20,6 +20,7 @@ Interface for multicast NIOs. """ import asyncio +import uuid from .nio import NIO import logging @@ -36,27 +37,15 @@ class NIOMcast(NIO): :param port: port for binding """ - _instance_count = 0 - def __init__(self, hypervisor, group, port): - # create an unique ID and name - nio_id = NIOMcast._instance_count - NIOMcast._instance_count += 1 - name = 'nio_mcast' + str(nio_id) + # create an unique name + name = 'mcast-{}'.format(uuid.uuid4()) self._group = group self._port = port self._ttl = 1 # default TTL super().__init__(name, hypervisor) - @classmethod - def reset(cls): - """ - Reset the instance count. - """ - - cls._instance_count = 0 - @asyncio.coroutine def create(self): diff --git a/gns3server/modules/dynamips/nios/nio_null.py b/gns3server/modules/dynamips/nios/nio_null.py index 4d46137c..174dd032 100644 --- a/gns3server/modules/dynamips/nios/nio_null.py +++ b/gns3server/modules/dynamips/nios/nio_null.py @@ -20,6 +20,7 @@ Interface for dummy NIOs (mostly for tests). """ import asyncio +import uuid from .nio import NIO import logging @@ -34,24 +35,12 @@ class NIONull(NIO): :param hypervisor: Dynamips hypervisor instance """ - _instance_count = 0 - def __init__(self, hypervisor): - # create an unique ID and name - nio_id = NIONull._instance_count - NIONull._instance_count += 1 - name = 'nio_null' + str(nio_id) + # create an unique name + name = 'null-{}'.format(uuid.uuid4()) super().__init__(name, hypervisor) - @classmethod - def reset(cls): - """ - Reset the instance count. - """ - - cls._instance_count = 0 - @asyncio.coroutine def create(self): diff --git a/gns3server/modules/dynamips/nios/nio_tap.py b/gns3server/modules/dynamips/nios/nio_tap.py index b4bd172f..20fdaeaa 100644 --- a/gns3server/modules/dynamips/nios/nio_tap.py +++ b/gns3server/modules/dynamips/nios/nio_tap.py @@ -20,6 +20,7 @@ Interface for TAP NIOs (UNIX based OSes only). """ import asyncio +import uuid from .nio import NIO import logging @@ -35,25 +36,13 @@ class NIOTAP(NIO): :param tap_device: TAP device name (e.g. tap0) """ - _instance_count = 0 - def __init__(self, hypervisor, tap_device): - # create an unique ID and name - nio_id = NIOTAP._instance_count - NIOTAP._instance_count += 1 - name = 'nio_tap' + str(nio_id) + # create an unique name + name = 'tap-{}'.format(uuid.uuid4()) self._tap_device = tap_device super().__init__(name, hypervisor) - @classmethod - def reset(cls): - """ - Reset the instance count. - """ - - cls._instance_count = 0 - @asyncio.coroutine def create(self): diff --git a/gns3server/modules/dynamips/nios/nio_udp.py b/gns3server/modules/dynamips/nios/nio_udp.py index eeb15e32..c7c2b656 100644 --- a/gns3server/modules/dynamips/nios/nio_udp.py +++ b/gns3server/modules/dynamips/nios/nio_udp.py @@ -20,6 +20,7 @@ Interface for UDP NIOs. """ import asyncio +import uuid from .nio import NIO import logging @@ -37,27 +38,15 @@ class NIOUDP(NIO): :param rport: remote port number """ - _instance_count = 0 - def __init__(self, hypervisor, lport, rhost, rport): - # create an unique ID and name - nio_id = NIOUDP._instance_count - NIOUDP._instance_count += 1 - name = 'nio_udp' + str(nio_id) + # create an unique name + name = 'udp-{}'.format(uuid.uuid4()) self._lport = lport self._rhost = rhost self._rport = rport super().__init__(name, hypervisor) - @classmethod - def reset(cls): - """ - Reset the instance count. - """ - - cls._instance_count = 0 - @asyncio.coroutine def create(self): diff --git a/gns3server/modules/dynamips/nios/nio_unix.py b/gns3server/modules/dynamips/nios/nio_unix.py index 45fa41c0..048572a4 100644 --- a/gns3server/modules/dynamips/nios/nio_unix.py +++ b/gns3server/modules/dynamips/nios/nio_unix.py @@ -20,6 +20,7 @@ Interface for UNIX NIOs (Unix based OSes only). """ import asyncio +import uuid from .nio import NIO import logging @@ -36,26 +37,14 @@ class NIOUNIX(NIO): :param remote_file: remote UNIX socket filename """ - _instance_count = 0 - def __init__(self, hypervisor, local_file, remote_file): - # create an unique ID and name - nio_id = NIOUNIX._instance_count - NIOUNIX._instance_count += 1 - name = 'nio_unix' + str(nio_id) + # create an unique name + name = 'unix-{}'.format(uuid.uuid4()) self._local_file = local_file self._remote_file = remote_file super().__init__(name, hypervisor) - @classmethod - def reset(cls): - """ - Reset the instance count. - """ - - cls._instance_count = 0 - @asyncio.coroutine def create(self): diff --git a/gns3server/modules/dynamips/nios/nio_vde.py b/gns3server/modules/dynamips/nios/nio_vde.py index 17a85524..6ac04259 100644 --- a/gns3server/modules/dynamips/nios/nio_vde.py +++ b/gns3server/modules/dynamips/nios/nio_vde.py @@ -20,6 +20,7 @@ Interface for VDE (Virtual Distributed Ethernet) NIOs (Unix based OSes only). """ import asyncio +import uuid from .nio import NIO import logging @@ -36,26 +37,14 @@ class NIOVDE(NIO): :param local_file: VDE local filename """ - _instance_count = 0 - def __init__(self, hypervisor, control_file, local_file): - # create an unique ID and name - nio_id = NIOVDE._instance_count - NIOVDE._instance_count += 1 - name = 'nio_vde' + str(nio_id) + # create an unique name + name = 'vde-{}'.format(uuid.uuid4()) self._control_file = control_file self._local_file = local_file super().__init__(name, hypervisor) - @classmethod - def reset(cls): - """ - Reset the instance count. - """ - - cls._instance_count = 0 - @asyncio.coroutine def create(self):