Compute IDLE PC via controller

Fix #1234
This commit is contained in:
Julien Duponchelle committed 2016-05-19 16:22:15 +02:00
1 parent 00f80f54e8
commit 672a617102
7 files changed
+128 -16

No files matched your search

+12 -12
View File
@@ -157,12 +157,12 @@ class Compute:
return response.content
@asyncio.coroutine
def http_query(self, method, path, data=None):
def http_query(self, method, path, data=None, **kwargs):
if not self._connected:
yield from self._connect()
if not self._connected:
raise aiohttp.web.HTTPConflict(text="The server {} is not a GNS3 server".format(self._id))
response = yield from self._run_http_query(method, path, data=data)
response = yield from self._run_http_query(method, path, data=data, **kwargs)
return response
@asyncio.coroutine
@@ -202,8 +202,8 @@ class Compute:
return "{}://{}:{}/v2/compute{}".format(self._protocol, self._host, self._port, path)
@asyncio.coroutine
def _run_http_query(self, method, path, data=None):
with aiohttp.Timeout(10):
def _run_http_query(self, method, path, data=None, timeout=10):
with aiohttp.Timeout(timeout):
url = self._getUrl(path)
headers = {'content-type': 'application/json'}
if data == {}:
@@ -243,19 +243,19 @@ class Compute:
return response
@asyncio.coroutine
def get(self, path):
return (yield from self.http_query("GET", path))
def get(self, path, **kwargs):
return (yield from self.http_query("GET", path, **kwargs))
@asyncio.coroutine
def post(self, path, data={}):
response = yield from self.http_query("POST", path, data)
def post(self, path, data={}, **kwargs):
response = yield from self.http_query("POST", path, data, **kwargs)
return response
@asyncio.coroutine
def put(self, path, data={}):
response = yield from self.http_query("PUT", path, data)
def put(self, path, data={}, **kwargs):
response = yield from self.http_query("PUT", path, data, **kwargs)
return response
@asyncio.coroutine
def delete(self, path):
return (yield from self.http_query("DELETE", path))
def delete(self, path, **kwargs):
return (yield from self.http_query("DELETE", path, **kwargs))
+17 -2
View File
@@ -147,7 +147,7 @@ class Node:
self._console_type = value
elif key == "name":
self._name = value
elif key in ["node_id", "project_id"]:
elif key in ["node_id", "project_id", "console_host"]:
pass
else:
self._properties[key] = value
@@ -166,7 +166,7 @@ class Node:
# None properties are not be send. Because it can mean the emulator doesn't support it
for key in list(data.keys()):
if data[key] is None:
if data[key] is None or key in ["console_host"]:
del data[key]
return data
@@ -236,6 +236,20 @@ class Node:
else:
return (yield from self._compute.delete("/projects/{}/{}/nodes/{}{}".format(self._project.id, self._node_type, self._id, path)))
@asyncio.coroutine
def dynamips_auto_idlepc(self):
"""
Compute the idle PC for a dynamips node
"""
return (yield from self._compute.get("/projects/{}/{}/nodes/{}/auto_idlepc".format(self._project.id, self._node_type, self._id), timeout=240)).json
@asyncio.coroutine
def dynamips_idlepc_proposals(self):
"""
Compute a list of potential idle PC
"""
return (yield from self._compute.get("/projects/{}/{}/nodes/{}/idlepc_proposals".format(self._project.id, self._node_type, self._id), timeout=240)).json
def __repr__(self):
return "<gns3server.controller.Node {} {}>".format(self._node_type, self._name)
@@ -248,6 +262,7 @@ class Node:
"node_directory": self._node_directory,
"name": self._name,
"console": self._console,
"console_host": self._compute.host,
"console_type": self._console_type,
"command_line": self._command_line,
"properties": self._properties,