Add default destination setting for traceng + some checks.

This commit is contained in:
grossmj committed 2018-04-16 15:03:22 +08:00
1 parent 801547983a
commit 025441f027
4 files changed
+49 -10

No files matched your search

+32 -1
View File
@@ -59,6 +59,7 @@ class TraceNGVM(BaseNode):
self._process = None
self._started = False
self._ip_address = None
self._default_destination = None
self._destination = None
self._local_udp_tunnel = None
self._ethernet_adapter = EthernetAdapter() # one adapter with 1 Ethernet interface
@@ -115,6 +116,7 @@ class TraceNGVM(BaseNode):
return {"name": self.name,
"ip_address": self.ip_address,
"default_destination": self._default_destination,
"node_id": self.id,
"node_directory": self.working_path,
"status": self.status,
@@ -167,6 +169,30 @@ class TraceNGVM(BaseNode):
id=self.id,
ip_address=ip_address))
@property
def default_destination(self):
"""
Returns the default destination IP/host for this node.
:returns: destination IP/host
"""
return self._default_destination
@default_destination.setter
def default_destination(self, destination):
"""
Sets the destination IP/host for this node.
:param destination: destination IP/host
"""
self._default_destination = destination
log.info("{module}: {name} [{id}] set default destination to {destination}".format(module=self.manager.module_name,
name=self.name,
id=self.id,
destination=destination))
@asyncio.coroutine
def start(self, destination=None):
"""
@@ -400,10 +426,15 @@ class TraceNGVM(BaseNode):
(to be passed to subprocess.Popen())
"""
if not destination:
# use the default destination if no specific destination provided
destination = self.default_destination
if not destination:
raise TraceNGError("Please provide a host or IP address to trace")
if not self._ip_address:
if not self.ip_address:
raise TraceNGError("Please configure an IP address for this TraceNG node")
if self.ip_address == destination:
raise TraceNGError("Destination cannot be the same as the IP address")
self._destination = destination
command = [self._traceng_path()]