mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-24 09:18:08 +00:00
Add default destination setting for traceng + some checks.
This commit is contained in:
parent
801547983a
commit
025441f027
@ -59,6 +59,7 @@ class TraceNGVM(BaseNode):
|
|||||||
self._process = None
|
self._process = None
|
||||||
self._started = False
|
self._started = False
|
||||||
self._ip_address = None
|
self._ip_address = None
|
||||||
|
self._default_destination = None
|
||||||
self._destination = None
|
self._destination = None
|
||||||
self._local_udp_tunnel = None
|
self._local_udp_tunnel = None
|
||||||
self._ethernet_adapter = EthernetAdapter() # one adapter with 1 Ethernet interface
|
self._ethernet_adapter = EthernetAdapter() # one adapter with 1 Ethernet interface
|
||||||
@ -115,6 +116,7 @@ class TraceNGVM(BaseNode):
|
|||||||
|
|
||||||
return {"name": self.name,
|
return {"name": self.name,
|
||||||
"ip_address": self.ip_address,
|
"ip_address": self.ip_address,
|
||||||
|
"default_destination": self._default_destination,
|
||||||
"node_id": self.id,
|
"node_id": self.id,
|
||||||
"node_directory": self.working_path,
|
"node_directory": self.working_path,
|
||||||
"status": self.status,
|
"status": self.status,
|
||||||
@ -167,6 +169,30 @@ class TraceNGVM(BaseNode):
|
|||||||
id=self.id,
|
id=self.id,
|
||||||
ip_address=ip_address))
|
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
|
@asyncio.coroutine
|
||||||
def start(self, destination=None):
|
def start(self, destination=None):
|
||||||
"""
|
"""
|
||||||
@ -400,10 +426,15 @@ class TraceNGVM(BaseNode):
|
|||||||
(to be passed to subprocess.Popen())
|
(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:
|
if not destination:
|
||||||
raise TraceNGError("Please provide a host or IP address to trace")
|
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")
|
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
|
self._destination = destination
|
||||||
command = [self._traceng_path()]
|
command = [self._traceng_path()]
|
||||||
|
@ -921,12 +921,7 @@ class Project:
|
|||||||
Start all nodes
|
Start all nodes
|
||||||
"""
|
"""
|
||||||
pool = Pool(concurrency=3)
|
pool = Pool(concurrency=3)
|
||||||
emit_warning = True
|
|
||||||
for node in self.nodes.values():
|
for node in self.nodes.values():
|
||||||
if node.node_type == "traceng" and emit_warning:
|
|
||||||
self.controller.notification.emit("log.warning", {"message": "TraceNG nodes must be started one by one"})
|
|
||||||
emit_warning = False
|
|
||||||
continue
|
|
||||||
pool.append(node.start)
|
pool.append(node.start)
|
||||||
yield from pool.join()
|
yield from pool.join()
|
||||||
|
|
||||||
|
@ -55,7 +55,8 @@ class TraceNGHandler:
|
|||||||
request.match_info["project_id"],
|
request.match_info["project_id"],
|
||||||
request.json.get("node_id"),
|
request.json.get("node_id"),
|
||||||
console=request.json.get("console"))
|
console=request.json.get("console"))
|
||||||
vm.ip_address = request.json.get("ip_address", "") # FIXME, required IP address to create node?
|
vm.ip_address = request.json.get("ip_address", "")
|
||||||
|
vm.default_destination = request.json.get("default_destination", "")
|
||||||
response.set_status(201)
|
response.set_status(201)
|
||||||
response.json(vm)
|
response.json(vm)
|
||||||
|
|
||||||
@ -99,6 +100,7 @@ class TraceNGHandler:
|
|||||||
vm = traceng_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"])
|
vm = traceng_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"])
|
||||||
vm.name = request.json.get("name", vm.name)
|
vm.name = request.json.get("name", vm.name)
|
||||||
vm.ip_address = request.json.get("ip_address", vm.ip_address)
|
vm.ip_address = request.json.get("ip_address", vm.ip_address)
|
||||||
|
vm.default_destination = request.json.get("default_destination", vm.default_destination)
|
||||||
vm.updated()
|
vm.updated()
|
||||||
response.json(vm)
|
response.json(vm)
|
||||||
|
|
||||||
@ -157,7 +159,7 @@ class TraceNGHandler:
|
|||||||
|
|
||||||
traceng_manager = TraceNG.instance()
|
traceng_manager = TraceNG.instance()
|
||||||
vm = traceng_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"])
|
vm = traceng_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"])
|
||||||
yield from vm.start(request.json["destination"])
|
yield from vm.start(request.get("destination"))
|
||||||
response.json(vm)
|
response.json(vm)
|
||||||
|
|
||||||
@Route.post(
|
@Route.post(
|
||||||
|
@ -48,6 +48,10 @@ TRACENG_CREATE_SCHEMA = {
|
|||||||
"ip_address": {
|
"ip_address": {
|
||||||
"description": "Source IP address for tracing",
|
"description": "Source IP address for tracing",
|
||||||
"type": ["string"]
|
"type": ["string"]
|
||||||
|
},
|
||||||
|
"default_destination": {
|
||||||
|
"description": "Default destination IP address or hostname for tracing",
|
||||||
|
"type": ["string"]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"additionalProperties": False,
|
"additionalProperties": False,
|
||||||
@ -77,6 +81,10 @@ TRACENG_UPDATE_SCHEMA = {
|
|||||||
"ip_address": {
|
"ip_address": {
|
||||||
"description": "Source IP address for tracing",
|
"description": "Source IP address for tracing",
|
||||||
"type": ["string"]
|
"type": ["string"]
|
||||||
|
},
|
||||||
|
"default_destination": {
|
||||||
|
"description": "Default destination IP address or hostname for tracing",
|
||||||
|
"type": ["string"]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"additionalProperties": False,
|
"additionalProperties": False,
|
||||||
@ -92,7 +100,6 @@ TRACENG_START_SCHEMA = {
|
|||||||
"type": ["string"]
|
"type": ["string"]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": ["destination"],
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TRACENG_OBJECT_SCHEMA = {
|
TRACENG_OBJECT_SCHEMA = {
|
||||||
@ -144,8 +151,12 @@ TRACENG_OBJECT_SCHEMA = {
|
|||||||
"ip_address": {
|
"ip_address": {
|
||||||
"description": "Source IP address for tracing",
|
"description": "Source IP address for tracing",
|
||||||
"type": ["string"]
|
"type": ["string"]
|
||||||
|
},
|
||||||
|
"default_destination": {
|
||||||
|
"description": "Default destination IP address or hostname for tracing",
|
||||||
|
"type": ["string"]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"additionalProperties": False,
|
"additionalProperties": False,
|
||||||
"required": ["name", "node_id", "status", "console", "console_type", "project_id", "command_line", "ip_address"]
|
"required": ["name", "node_id", "status", "console", "console_type", "project_id", "command_line", "ip_address", "default_destination"]
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user