Yet another PEP 8 :)

This commit is contained in:
Julien Duponchelle committed 2015-01-20 16:37:18 +01:00
1 parent 7cf409c392
commit bbee5f90a0
106 files changed
+9 -29

No files matched your search

Whitespace-only changes.
+246
View File
@@ -0,0 +1,246 @@
# -*- 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/>.
"""
Base interface for Dynamips Network Input/Output (NIO) module ("nio").
http://github.com/GNS3/dynamips/blob/master/README.hypervisor#L451
"""
from ..dynamips_error import DynamipsError
import logging
log = logging.getLogger(__name__)
class NIO(object):
"""
Base NIO class
:param hypervisor: Dynamips hypervisor instance
"""
def __init__(self, hypervisor):
self._hypervisor = hypervisor
self._bandwidth = None # no bandwidth constraint by default
self._input_filter = None # no input filter applied by default
self._output_filter = None # no output filter applied by default
self._input_filter_options = None # no input filter options by default
self._output_filter_options = None # no output filter options by default
self._dynamips_direction = {"in": 0, "out": 1, "both": 2}
def list(self):
"""
Returns all NIOs.
:returns: NIO list
"""
return self._hypervisor.send("nio list")
def delete(self):
"""
Deletes this NIO.
"""
if self._input_filter or self._output_filter:
self.unbind_filter("both")
self._hypervisor.send("nio delete {}".format(self._name))
log.info("NIO {name} has been deleted".format(name=self._name))
def rename(self, new_name):
"""
Renames this NIO
:param new_name: new NIO name
"""
self._hypervisor.send("nio rename {name} {new_name}".format(name=self._name,
new_name=new_name))
log.info("NIO {name} renamed to {new_name}".format(name=self._name,
new_name=new_name))
self._name = new_name
def debug(self, debug):
"""
Enables/Disables debugging for this NIO.
:param debug: debug value (0 = disable, enable = 1)
"""
self._hypervisor.send("nio set_debug {name} {debug}".format(name=self._name,
debug=debug))
def bind_filter(self, direction, filter_name):
"""
Adds a packet filter to this NIO.
Filter "freq_drop" drops packets.
Filter "capture" captures packets.
:param direction: "in", "out" or "both"
:param filter_name: name of the filter to apply
"""
if direction not in self._dynamips_direction:
raise DynamipsError("Unknown direction {} to bind filter {}:".format(direction, filter_name))
dynamips_direction = self._dynamips_direction[direction]
self._hypervisor.send("nio bind_filter {name} {direction} {filter}".format(name=self._name,
direction=dynamips_direction,
filter=filter_name))
if direction == "in":
self._input_filter = filter_name
elif direction == "out":
self._output_filter = filter_name
elif direction == "both":
self._input_filter = filter_name
self._output_filter = filter_name
def unbind_filter(self, direction):
"""
Removes packet filter for this NIO.
:param direction: "in", "out" or "both"
"""
if direction not in self._dynamips_direction:
raise DynamipsError("Unknown direction {} to unbind filter:".format(direction))
dynamips_direction = self._dynamips_direction[direction]
self._hypervisor.send("nio unbind_filter {name} {direction}".format(name=self._name,
direction=dynamips_direction))
if direction == "in":
self._input_filter = None
elif direction == "out":
self._output_filter = None
elif direction == "both":
self._input_filter = None
self._output_filter = None
def setup_filter(self, direction, options):
"""
Setups a packet filter bound with this NIO.
Filter "freq_drop" has 1 argument "<frequency>". It will drop
everything with a -1 frequency, drop every Nth packet with a
positive frequency, or drop nothing.
Filter "capture" has 2 arguments "<link_type_name> <output_file>".
It will capture packets to the target output file. The link type
name is a case-insensitive DLT_ name from the PCAP library
constants with the DLT_ part removed.See http://www.tcpdump.org/linktypes.html
for a list of all available DLT values.
:param direction: "in", "out" or "both"
:param options: options for the packet filter (string)
"""
if direction not in self._dynamips_direction:
raise DynamipsError("Unknown direction {} to setup filter:".format(direction))
dynamips_direction = self._dynamips_direction[direction]
self._hypervisor.send("nio setup_filter {name} {direction} {options}".format(name=self._name,
direction=dynamips_direction,
options=options))
if direction == "in":
self._input_filter_options = options
elif direction == "out":
self._output_filter_options = options
elif direction == "both":
self._input_filter_options = options
self._output_filter_options = options
@property
def input_filter(self):
"""
Returns the input packet filter for this NIO.
:returns: tuple (filter name, filter options)
"""
return self._input_filter, self._input_filter_options
@property
def output_filter(self):
"""
Returns the output packet filter for this NIO.
:returns: tuple (filter name, filter options)
"""
return self._output_filter, self._output_filter_options
def get_stats(self):
"""
Gets statistics for this NIO.
:returns: NIO statistics (string with packets in, packets out, bytes in, bytes out)
"""
return self._hypervisor.send("nio get_stats {}".format(self._name))[0]
def reset_stats(self):
"""
Resets statistics for this NIO.
"""
self._hypervisor.send("nio reset_stats {}".format(self._name))
def set_bandwidth(self, bandwidth):
"""
Sets bandwidth constraint.
:param bandwidth: bandwidth integer value (in Kb/s)
"""
self._hypervisor.send("nio set_bandwidth {name} {bandwidth}".format(name=self._name,
bandwidth=bandwidth))
self._bandwidth = bandwidth
@property
def bandwidth(self):
"""
Returns the bandwidth constraint for this NIO.
:returns: bandwidth integer value (in Kb/s)
"""
return self._bandwidth
def __str__(self):
"""
NIO string representation.
:returns: NIO name
"""
return self._name
@property
def name(self):
"""
Returns the NIO name.
:returns: NIO name
"""
return self._name
@@ -0,0 +1,69 @@
# -*- 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/>.
"""
Interface for FIFO NIOs.
"""
from .nio import NIO
import logging
log = logging.getLogger(__name__)
class NIO_FIFO(NIO):
"""
Dynamips FIFO NIO.
:param hypervisor: Dynamips hypervisor instance
"""
_instance_count = 0
def __init__(self, hypervisor):
NIO.__init__(self, hypervisor)
# create an unique ID
self._id = NIO_FIFO._instance_count
NIO_FIFO._instance_count += 1
self._name = 'nio_fifo' + str(self._id)
self._hypervisor.send("nio create_fifo {}".format(self._name))
log.info("NIO FIFO {name} created.".format(name=self._name))
@classmethod
def reset(cls):
"""
Reset the instance count.
"""
cls._instance_count = 0
def crossconnect(self, nio):
"""
Establishes a cross-connect between this FIFO NIO and another one.
:param nio: FIFO NIO instance
"""
self._hypervisor.send("nio crossconnect_fifo {name} {nio}".format(name=self._name,
nio=nio))
log.info("NIO FIFO {name} crossconnected with {nio_name}.".format(name=self._name, nio_name=nio.name))
@@ -0,0 +1,71 @@
# -*- 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/>.
"""
Interface for generic Ethernet NIOs (PCAP library).
"""
from .nio import NIO
import logging
log = logging.getLogger(__name__)
class NIO_GenericEthernet(NIO):
"""
Dynamips generic Ethernet NIO.
:param hypervisor: Dynamips hypervisor instance
:param ethernet_device: Ethernet device name (e.g. eth0)
"""
_instance_count = 0
def __init__(self, hypervisor, ethernet_device):
NIO.__init__(self, hypervisor)
# create an unique ID
self._id = NIO_GenericEthernet._instance_count
NIO_GenericEthernet._instance_count += 1
self._name = 'nio_gen_eth' + str(self._id)
self._ethernet_device = ethernet_device
self._hypervisor.send("nio create_gen_eth {name} {eth_device}".format(name=self._name,
eth_device=ethernet_device))
log.info("NIO Generic Ethernet {name} created with device {device}".format(name=self._name,
device=ethernet_device))
@classmethod
def reset(cls):
"""
Reset the instance count.
"""
cls._instance_count = 0
@property
def ethernet_device(self):
"""
Returns the Ethernet device used by this NIO.
:returns: the Ethernet device name
"""
return self._ethernet_device
@@ -0,0 +1,71 @@
# -*- 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/>.
"""
Interface for Linux Ethernet NIOs (Linux only).
"""
from .nio import NIO
import logging
log = logging.getLogger(__name__)
class NIO_LinuxEthernet(NIO):
"""
Dynamips Linux Ethernet NIO.
:param hypervisor: Dynamips hypervisor instance
:param ethernet_device: Ethernet device name (e.g. eth0)
"""
_instance_count = 0
def __init__(self, hypervisor, ethernet_device):
NIO.__init__(self, hypervisor)
# create an unique ID
self._id = NIO_LinuxEthernet._instance_count
NIO_LinuxEthernet._instance_count += 1
self._name = 'nio_linux_eth' + str(self._id)
self._ethernet_device = ethernet_device
self._hypervisor.send("nio create_linux_eth {name} {eth_device}".format(name=self._name,
eth_device=ethernet_device))
log.info("NIO Linux Ethernet {name} created with device {device}".format(name=self._name,
device=ethernet_device))
@classmethod
def reset(cls):
"""
Reset the instance count.
"""
cls._instance_count = 0
@property
def ethernet_device(self):
"""
Returns the Ethernet device used by this NIO.
:returns: the Ethernet device name
"""
return self._ethernet_device
@@ -0,0 +1,108 @@
# -*- 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/>.
"""
Interface for multicast NIOs.
"""
from .nio import NIO
import logging
log = logging.getLogger(__name__)
class NIO_Mcast(NIO):
"""
Dynamips Linux Ethernet NIO.
:param hypervisor: Dynamips hypervisor instance
:param group: multicast group to bind
:param port: port for binding
"""
_instance_count = 0
def __init__(self, hypervisor, group, port):
NIO.__init__(self, hypervisor)
# create an unique ID
self._id = NIO_Mcast._instance_count
NIO_Mcast._instance_count += 1
self._name = 'nio_mcast' + str(self._id)
self._group = group
self._port = port
self._ttl = 1 # default TTL
self._hypervisor.send("nio create_mcast {name} {mgroup} {mport}".format(name=self._name,
mgroup=group,
mport=port))
log.info("NIO Multicast {name} created with mgroup={group}, mport={port}".format(name=self._name,
group=group,
port=port))
@classmethod
def reset(cls):
"""
Reset the instance count.
"""
cls._instance_count = 0
@property
def group(self):
"""
Returns the multicast group
:returns: multicast group address
"""
return self._group
@property
def port(self):
"""
Returns the port
:returns: port number
"""
return self._port
@property
def ttl(self):
"""
Returns the TTL associated with the multicast address.
:returns: TTL value
"""
return self._ttl
@ttl.setter
def ttl(self, ttl):
"""
Sets the TTL for the multicast address
:param ttl: TTL value
"""
self._hypervisor.send("nio set_mcast_ttl {name} {ttl}".format(name=self._name,
ttl=ttl))
self._ttl = ttl
@@ -0,0 +1,56 @@
# -*- 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/>.
"""
Interface for dummy NIOs (mostly for tests).
"""
from .nio import NIO
import logging
log = logging.getLogger(__name__)
class NIO_Null(NIO):
"""
Dynamips NULL NIO.
:param hypervisor: Dynamips hypervisor instance
"""
_instance_count = 0
def __init__(self, hypervisor):
NIO.__init__(self, hypervisor)
# create an unique ID
self._id = NIO_Null._instance_count
NIO_Null._instance_count += 1
self._name = 'nio_null' + str(self._id)
self._hypervisor.send("nio create_null {}".format(self._name))
log.info("NIO NULL {name} created.".format(name=self._name))
@classmethod
def reset(cls):
"""
Reset the instance count.
"""
cls._instance_count = 0
@@ -0,0 +1,71 @@
# -*- 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/>.
"""
Interface for TAP NIOs (UNIX based OSes only).
"""
from .nio import NIO
import logging
log = logging.getLogger(__name__)
class NIO_TAP(NIO):
"""
Dynamips TAP NIO.
:param hypervisor: Dynamips hypervisor instance
:param tap_device: TAP device name (e.g. tap0)
"""
_instance_count = 0
def __init__(self, hypervisor, tap_device):
NIO.__init__(self, hypervisor)
# create an unique ID
self._id = NIO_TAP._instance_count
NIO_TAP._instance_count += 1
self._name = 'nio_tap' + str(self._id)
self._tap_device = tap_device
self._hypervisor.send("nio create_tap {name} {tap}".format(name=self._name,
tap=tap_device))
log.info("NIO TAP {name} created with device {device}".format(name=self._name,
device=tap_device))
@classmethod
def reset(cls):
"""
Reset the instance count.
"""
cls._instance_count = 0
@property
def tap_device(self):
"""
Returns the TAP device used by this NIO.
:returns: the TAP device name
"""
return self._tap_device
@@ -0,0 +1,99 @@
# -*- 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/>.
"""
Interface for UDP NIOs.
"""
from .nio import NIO
import logging
log = logging.getLogger(__name__)
class NIO_UDP(NIO):
"""
Dynamips UDP NIO.
:param hypervisor: Dynamips hypervisor instance
:param lport: local port number
:param rhost: remote address/host
:param rport: remote port number
"""
_instance_count = 0
def __init__(self, hypervisor, lport, rhost, rport):
NIO.__init__(self, hypervisor)
# create an unique ID
self._id = NIO_UDP._instance_count
NIO_UDP._instance_count += 1
self._name = 'nio_udp' + str(self._id)
self._lport = lport
self._rhost = rhost
self._rport = rport
self._hypervisor.send("nio create_udp {name} {lport} {rhost} {rport}".format(name=self._name,
lport=lport,
rhost=rhost,
rport=rport))
log.info("NIO UDP {name} created with lport={lport}, rhost={rhost}, rport={rport}".format(name=self._name,
lport=lport,
rhost=rhost,
rport=rport))
@classmethod
def reset(cls):
"""
Reset the instance count.
"""
cls._instance_count = 0
@property
def lport(self):
"""
Returns the local port
:returns: local port number
"""
return self._lport
@property
def rhost(self):
"""
Returns the remote host
:returns: remote address/host
"""
return self._rhost
@property
def rport(self):
"""
Returns the remote port
:returns: remote port number
"""
return self._rport
@@ -0,0 +1,127 @@
# -*- 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/>.
"""
Interface for automatic UDP NIOs.
"""
from .nio import NIO
import logging
log = logging.getLogger(__name__)
class NIO_UDP_auto(NIO):
"""
Dynamips auto UDP NIO.
:param hypervisor: Dynamips hypervisor instance
:param laddr: local address
:param lport_start: start local port range
:param lport_end: end local port range
"""
_instance_count = 0
def __init__(self, hypervisor, laddr, lport_start, lport_end):
NIO.__init__(self, hypervisor)
# create an unique ID
self._id = NIO_UDP_auto._instance_count
NIO_UDP_auto._instance_count += 1
self._name = 'nio_udp_auto' + str(self._id)
self._laddr = laddr
self._lport = int(self._hypervisor.send("nio create_udp_auto {name} {laddr} {lport_start} {lport_end}".format(name=self._name,
laddr=laddr,
lport_start=lport_start,
lport_end=lport_end))[0])
log.info("NIO UDP AUTO {name} created with laddr={laddr}, lport_start={start}, lport_end={end}".format(name=self._name,
laddr=laddr,
start=lport_start,
end=lport_end))
self._raddr = None
self._rport = None
@classmethod
def reset(cls):
"""
Reset the instance count.
"""
cls._instance_count = 0
@property
def laddr(self):
"""
Returns the local address
:returns: local address
"""
return self._laddr
@property
def lport(self):
"""
Returns the local port
:returns: local port number
"""
return self._lport
@property
def raddr(self):
"""
Returns the remote address
:returns: remote address
"""
return self._raddr
@property
def rport(self):
"""
Returns the remote port
:returns: remote port number
"""
return self._rport
def connect(self, raddr, rport):
"""
Connects this NIO to a remote socket
:param raddr: remote address
:param rport: remote port number
"""
self._hypervisor.send("nio connect_udp_auto {name} {raddr} {rport}".format(name=self._name,
raddr=raddr,
rport=rport))
self._raddr = raddr
self._rport = rport
log.info("NIO UDP AUTO {name} connected to {raddr}:{rport}".format(name=self._name,
raddr=raddr,
rport=rport))
@@ -0,0 +1,85 @@
# -*- 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/>.
"""
Interface for UNIX NIOs (Unix based OSes only).
"""
from .nio import NIO
import logging
log = logging.getLogger(__name__)
class NIO_UNIX(NIO):
"""
Dynamips UNIX NIO.
:param hypervisor: Dynamips hypervisor instance
:param local_file: local UNIX socket filename
:param remote_file: remote UNIX socket filename
"""
_instance_count = 0
def __init__(self, hypervisor, local_file, remote_file):
NIO.__init__(self, hypervisor)
# create an unique ID
self._id = NIO_UNIX._instance_count
NIO_UNIX._instance_count += 1
self._name = 'nio_unix' + str(self._id)
self._local_file = local_file
self._remote_file = remote_file
self._hypervisor.send("nio create_unix {name} {local} {remote}".format(name=self._name,
local=local_file,
remote=remote_file))
log.info("NIO UNIX {name} created with local file {local} and remote file {remote}".format(name=self._name,
local=local_file,
remote=remote_file))
@classmethod
def reset(cls):
"""
Reset the instance count.
"""
cls._instance_count = 0
@property
def local_file(self):
"""
Returns the local UNIX socket.
:returns: local UNIX socket filename
"""
return self._local_file
@property
def remote_file(self):
"""
Returns the remote UNIX socket.
:returns: remote UNIX socket filename
"""
return self._remote_file
@@ -0,0 +1,85 @@
# -*- 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/>.
"""
Interface for VDE (Virtual Distributed Ethernet) NIOs (Unix based OSes only).
"""
from .nio import NIO
import logging
log = logging.getLogger(__name__)
class NIO_VDE(NIO):
"""
Dynamips VDE NIO.
:param hypervisor: Dynamips hypervisor instance
:param control_file: VDE control filename
:param local_file: VDE local filename
"""
_instance_count = 0
def __init__(self, hypervisor, control_file, local_file):
NIO.__init__(self, hypervisor)
# create an unique ID
self._id = NIO_VDE._instance_count
NIO_VDE._instance_count += 1
self._name = 'nio_vde' + str(self._id)
self._control_file = control_file
self._local_file = local_file
self._hypervisor.send("nio create_vde {name} {control} {local}".format(name=self._name,
control=control_file,
local=local_file))
log.info("NIO VDE {name} created with control={control}, local={local}".format(name=self._name,
control=control_file,
local=local_file))
@classmethod
def reset(cls):
"""
Reset the instance count.
"""
cls._instance_count = 0
@property
def control_file(self):
"""
Returns the VDE control file.
:returns: VDE control filename
"""
return self._control_file
@property
def local_file(self):
"""
Returns the VDE local file.
:returns: VDE local filename
"""
return self._local_file