mirror of
https://github.com/GNS3/gns3-server
synced 2024-12-02 21:28:10 +00:00
Fix If cloud interface is down the project doesn't open
Fix https://github.com/GNS3/gns3-gui/issues/1751
This commit is contained in:
parent
69d8ed5636
commit
82c99418b4
@ -81,7 +81,7 @@ class Cloud(BaseNode):
|
|||||||
"project_id": self.project.id,
|
"project_id": self.project.id,
|
||||||
"ports_mapping": self._ports_mapping,
|
"ports_mapping": self._ports_mapping,
|
||||||
"interfaces": host_interfaces,
|
"interfaces": host_interfaces,
|
||||||
"status": "started"}
|
"status": self.status}
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def ports_mapping(self):
|
def ports_mapping(self):
|
||||||
@ -118,9 +118,23 @@ class Cloud(BaseNode):
|
|||||||
Creates this cloud.
|
Creates this cloud.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
yield from self._start_ubridge()
|
yield from self.start()
|
||||||
log.info('Cloud "{name}" [{id}] has been created'.format(name=self._name, id=self._id))
|
log.info('Cloud "{name}" [{id}] has been created'.format(name=self._name, id=self._id))
|
||||||
|
|
||||||
|
@asyncio.coroutine
|
||||||
|
def start(self):
|
||||||
|
if self.status != "started":
|
||||||
|
if self._ubridge_hypervisor and self._ubridge_hypervisor.is_running():
|
||||||
|
yield from self._stop_ubridge()
|
||||||
|
yield from self._start_ubridge()
|
||||||
|
for port_number in self._nios:
|
||||||
|
if self._nios[port_number]:
|
||||||
|
try:
|
||||||
|
yield from self._add_ubridge_connection(self._nios[port_number], port_number)
|
||||||
|
except (UbridgeError, NodeError) as e:
|
||||||
|
self.status = "stopped"
|
||||||
|
raise e
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def close(self):
|
def close(self):
|
||||||
"""
|
"""
|
||||||
@ -280,18 +294,17 @@ class Cloud(BaseNode):
|
|||||||
port=port_number))
|
port=port_number))
|
||||||
self._nios[port_number] = nio
|
self._nios[port_number] = nio
|
||||||
try:
|
try:
|
||||||
|
yield from self.start()
|
||||||
yield from self._add_ubridge_connection(nio, port_number)
|
yield from self._add_ubridge_connection(nio, port_number)
|
||||||
except NodeError as e:
|
except NodeError as e:
|
||||||
del self._nios[port_number]
|
self.project.emit("log.error", {"message": str(e)})
|
||||||
raise e
|
yield from self._stop_ubridge()
|
||||||
|
self.status = "stopped"
|
||||||
# Cleanup stuff
|
# Cleanup stuff
|
||||||
except UbridgeError as e:
|
except UbridgeError as e:
|
||||||
try:
|
self.project.emit("log.error", {"message": str(e)})
|
||||||
self._delete_ubridge_connection(port_number)
|
yield from self._stop_ubridge()
|
||||||
except UbridgeError:
|
self.status = "stopped"
|
||||||
pass
|
|
||||||
del self._nios[port_number]
|
|
||||||
raise e
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def _delete_ubridge_connection(self, port_number):
|
def _delete_ubridge_connection(self, port_number):
|
||||||
@ -327,7 +340,9 @@ class Cloud(BaseNode):
|
|||||||
port=port_number))
|
port=port_number))
|
||||||
|
|
||||||
del self._nios[port_number]
|
del self._nios[port_number]
|
||||||
|
if self._ubridge_hypervisor and self._ubridge_hypervisor.is_running():
|
||||||
yield from self._delete_ubridge_connection(port_number)
|
yield from self._delete_ubridge_connection(port_number)
|
||||||
|
yield from self.start()
|
||||||
return nio
|
return nio
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
|
@ -135,7 +135,8 @@ class CloudHandler:
|
|||||||
description="Start a cloud")
|
description="Start a cloud")
|
||||||
def start(request, response):
|
def start(request, response):
|
||||||
|
|
||||||
Builtin.instance().get_node(request.match_info["node_id"], project_id=request.match_info["project_id"])
|
node = Builtin.instance().get_node(request.match_info["node_id"], project_id=request.match_info["project_id"])
|
||||||
|
yield from node.start()
|
||||||
response.set_status(204)
|
response.set_status(204)
|
||||||
|
|
||||||
@Route.post(
|
@Route.post(
|
||||||
|
@ -43,7 +43,7 @@ def test_json_with_ports(on_gns3vm, project):
|
|||||||
"name": "cloud1",
|
"name": "cloud1",
|
||||||
"node_id": cloud.id,
|
"node_id": cloud.id,
|
||||||
"project_id": project.id,
|
"project_id": project.id,
|
||||||
"status": "started",
|
"status": "stopped",
|
||||||
"ports_mapping": [
|
"ports_mapping": [
|
||||||
{
|
{
|
||||||
"interface": "virbr0",
|
"interface": "virbr0",
|
||||||
@ -69,7 +69,7 @@ def test_json_without_ports(on_gns3vm, project):
|
|||||||
"name": "cloud1",
|
"name": "cloud1",
|
||||||
"node_id": cloud.id,
|
"node_id": cloud.id,
|
||||||
"project_id": project.id,
|
"project_id": project.id,
|
||||||
"status": "started",
|
"status": "stopped",
|
||||||
"ports_mapping": [
|
"ports_mapping": [
|
||||||
{
|
{
|
||||||
"interface": "eth0",
|
"interface": "eth0",
|
||||||
@ -141,6 +141,7 @@ def test_linux_ethernet_raw_add_nio(linux_platform, project, async_run, nio):
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
cloud = Cloud("cloud1", str(uuid.uuid4()), project, MagicMock(), ports=ports)
|
cloud = Cloud("cloud1", str(uuid.uuid4()), project, MagicMock(), ports=ports)
|
||||||
|
cloud.status = "started"
|
||||||
|
|
||||||
with asyncio_patch("gns3server.compute.builtin.nodes.cloud.Cloud._ubridge_send") as ubridge_mock:
|
with asyncio_patch("gns3server.compute.builtin.nodes.cloud.Cloud._ubridge_send") as ubridge_mock:
|
||||||
with patch("gns3server.compute.builtin.nodes.cloud.Cloud._interfaces", return_value=[{"name": "eth0"}]):
|
with patch("gns3server.compute.builtin.nodes.cloud.Cloud._interfaces", return_value=[{"name": "eth0"}]):
|
||||||
@ -167,6 +168,7 @@ def test_linux_ethernet_raw_add_nio_bridge(linux_platform, project, async_run, n
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
cloud = Cloud("cloud1", str(uuid.uuid4()), project, MagicMock(), ports=ports)
|
cloud = Cloud("cloud1", str(uuid.uuid4()), project, MagicMock(), ports=ports)
|
||||||
|
cloud.status = "started"
|
||||||
|
|
||||||
with asyncio_patch("gns3server.compute.builtin.nodes.cloud.Cloud._ubridge_send") as ubridge_mock:
|
with asyncio_patch("gns3server.compute.builtin.nodes.cloud.Cloud._ubridge_send") as ubridge_mock:
|
||||||
with patch("gns3server.compute.builtin.nodes.cloud.Cloud._interfaces", return_value=[{"name": "bridge0"}]):
|
with patch("gns3server.compute.builtin.nodes.cloud.Cloud._interfaces", return_value=[{"name": "bridge0"}]):
|
||||||
|
@ -54,7 +54,7 @@ def test_cloud_get(http_compute, project, vm):
|
|||||||
assert response.route == "/projects/{project_id}/cloud/nodes/{node_id}"
|
assert response.route == "/projects/{project_id}/cloud/nodes/{node_id}"
|
||||||
assert response.json["name"] == "Cloud 1"
|
assert response.json["name"] == "Cloud 1"
|
||||||
assert response.json["project_id"] == project.id
|
assert response.json["project_id"] == project.id
|
||||||
assert response.json["status"] == "started"
|
assert response.json["status"] == "stopped"
|
||||||
|
|
||||||
|
|
||||||
def test_cloud_nio_create_udp(http_compute, vm):
|
def test_cloud_nio_create_udp(http_compute, vm):
|
||||||
|
Loading…
Reference in New Issue
Block a user