Prevent capture on non running node

Fix https://github.com/GNS3/gns3-gui/issues/1656
This commit is contained in:
Julien Duponchelle committed 2016-11-22 16:05:57 +01:00
1 parent 31c04cc95b
commit 875051d05e
9 files changed
+158 -39

No files matched your search

+1 -1
View File
@@ -410,7 +410,7 @@ class Compute:
self._memory_usage_percent = event["memory_usage_percent"]
self._controller.notification.emit("compute.updated", self.__json__())
else:
self._controller.notification.dispatch(action, event, compute_id=self.id)
yield from self._controller.notification.dispatch(action, event, compute_id=self.id)
if self._ws:
yield from self._ws.close()
+14 -2
View File
@@ -91,6 +91,8 @@ class Link:
if len(self._nodes) == 2:
yield from self.create()
for n in self._nodes:
n["node"].add_link(self)
self._created = True
self._project.controller.notification.emit("link.created", self.__json__())
@@ -121,8 +123,8 @@ class Link:
"""
Delete the link
"""
raise NotImplementedError
for port in self._nodes:
port["node"].remove_link(self)
@asyncio.coroutine
def start_capture(self, data_link_type="DLT_EN10MB", capture_file_name=None):
@@ -173,6 +175,13 @@ class Link:
raise NotImplementedError
@asyncio.coroutine
def node_updated(self, node):
"""
Called when a node member of the link is updated
"""
raise NotImplementedError
def default_capture_file_name(self):
"""
:returns: File name for a capture on this link
@@ -214,6 +223,9 @@ class Link:
return False
return self.id == other.id
def __hash__(self):
return hash(self._id)
def __json__(self, topology_dump=False):
"""
:param topology_dump: Filter to keep only properties require for saving on disk
+22 -2
View File
@@ -59,6 +59,7 @@ class Node:
self._node_type = node_type
self._label = None
self._links = set()
self._name = None
self.name = name
self._console = None
@@ -268,6 +269,22 @@ class Node:
def first_port_name(self, val):
self._first_port_name = val
def add_link(self, link):
"""
A link is connected to the node
"""
self._links.add(link)
def remove_link(self, link):
"""
A link is connected to the node
"""
self._links.remove(link)
@property
def link(self):
return self._links
@asyncio.coroutine
def create(self):
"""
@@ -291,7 +308,7 @@ class Node:
else:
raise e
else:
self.parse_node_response(response.json)
yield from self.parse_node_response(response.json)
return True
trial += 1
@@ -328,9 +345,10 @@ class Node:
if update_compute:
data = self._node_data(properties=compute_properties)
response = yield from self.put(None, data=data)
self.parse_node_response(response.json)
yield from self.parse_node_response(response.json)
self.project.dump()
@asyncio.coroutine
def parse_node_response(self, response):
"""
Update the object with the remote node object
@@ -353,6 +371,8 @@ class Node:
else:
self._properties[key] = value
self._list_ports()
for link in self._links:
yield from link.node_updated(self)
def _node_data(self, properties=None):
"""
+3 -1
View File
@@ -17,6 +17,7 @@
import os
import aiohttp
import asyncio
from contextlib import contextmanager
from ..notification_queue import NotificationQueue
@@ -51,6 +52,7 @@ class Notification:
"""
return project.id in self._listeners and len(self._listeners[project.id]) > 0
@asyncio.coroutine
def dispatch(self, action, event, compute_id):
"""
Notification received from compute node. Send it directly
@@ -65,7 +67,7 @@ class Notification:
# Update controller node data and send the event node.updated
project = self._controller.get_project(event["project_id"])
node = project.get_node(event["node_id"])
node.parse_node_response(event)
yield from node.parse_node_response(event)
self.emit("node.updated", node.__json__())
except aiohttp.web.HTTPNotFound:
+24 -5
View File
@@ -115,6 +115,7 @@ class UDPLink(Link):
# If the node is already delete (user selected multiple element and delete all in the same time)
except aiohttp.web.HTTPNotFound:
pass
yield from super().delete()
@asyncio.coroutine
def start_capture(self, data_link_type="DLT_EN10MB", capture_file_name=None):
@@ -145,21 +146,31 @@ class UDPLink(Link):
"""
Run capture on the best candidate.
The ideal candidate is a node who support capture on controller server
The ideal candidate is a node who on controller server and always
running (capture will not be cut off)
:returns: Node where the capture should run
"""
# use the local node first to save bandwidth
ALWAYS_RUNNING_NODES_TYPE = ("cloud", "nat", "ethernet_switch", "ethernet_hub")
for node in self._nodes:
if node["node"].compute.id == "local" and node["node"].node_type not in [""]: # FIXME
if node["node"].compute.id == "local" and node["node"].node_type in ALWAYS_RUNNING_NODES_TYPE and node["node"].status == "started":
return node
for node in self._nodes:
if node["node"].node_type not in [""]: # FIXME
if node["node"].node_type in ALWAYS_RUNNING_NODES_TYPE and node["node"].status == "started":
return node
raise aiohttp.web.HTTPConflict(text="Capture is not supported for this link")
for node in self._nodes:
if node["node"].compute.id == "local" and node["node"].status == "started":
return node
for node in self._nodes:
if node["node"].node_type and node["node"].status == "started":
return node
raise aiohttp.web.HTTPConflict(text="Can not capture because no running device on this link")
@asyncio.coroutine
def read_pcap_from_source(self):
@@ -169,3 +180,11 @@ class UDPLink(Link):
if self._capture_node:
compute = self._capture_node["node"].compute
return compute.stream_file(self._project, "tmp/captures/" + self._capture_file_name)
@asyncio.coroutine
def node_updated(self, node):
"""
Called when a node member of the link is updated
"""
if self._capture_node and node == self._capture_node["node"] and node.status != "started":
yield from self.stop_capture()