New server subcommand on test API
Tests if a host/port combination is reachable via server_reachable.
This commit is contained in:
1 parent
01b3b8a0e0
commit
9c3d7bbbc3
4 files changed
+177
-5
No files matched your search
@@ -243,7 +243,8 @@ def _logout(user):
|
||||
def utilTestPath():
|
||||
valid_commands = dict(
|
||||
path=["path"],
|
||||
url=["url"]
|
||||
url=["url"],
|
||||
server=["host", "port"]
|
||||
)
|
||||
|
||||
command, data, response = get_json_command_from_request(request, valid_commands)
|
||||
@@ -336,7 +337,7 @@ def utilTestPath():
|
||||
try:
|
||||
timeout = float(data["timeout"])
|
||||
except:
|
||||
return make_response("{!r} is not a valid value for timeout (must be int or float)".format(data["timeout"]))
|
||||
return make_response("{!r} is not a valid value for timeout (must be int or float)".format(data["timeout"]), 400)
|
||||
|
||||
if "status" in data:
|
||||
request_status = data["status"]
|
||||
@@ -383,5 +384,33 @@ def utilTestPath():
|
||||
headers=dict(response.headers),
|
||||
content=content
|
||||
)
|
||||
|
||||
return jsonify(**result)
|
||||
|
||||
elif command == "server":
|
||||
host = data["host"]
|
||||
try:
|
||||
port = int(data["port"])
|
||||
except:
|
||||
return make_response("{!r} is not a valid value for port (must be int)".format(data["port"]), 400)
|
||||
|
||||
timeout = 3.05
|
||||
if "timeout" in data:
|
||||
try:
|
||||
timeout = float(data["timeout"])
|
||||
except:
|
||||
return make_response("{!r} is not a valid value for timeout (must be int or float)".format(data["timeout"]), 400)
|
||||
|
||||
protocol = data.get("protocol", "tcp")
|
||||
if protocol not in ("tcp", "udp"):
|
||||
return make_response("{!r} is not a valid value for protocol, must be tcp or udp".format(protocol), 400)
|
||||
|
||||
from octoprint.util import server_reachable
|
||||
reachable = server_reachable(host, port, timeout=timeout, proto=protocol)
|
||||
|
||||
result = dict(host=host,
|
||||
port=port,
|
||||
protocol=protocol,
|
||||
result=reachable)
|
||||
|
||||
return jsonify(**result)
|
||||
|
||||
@@ -45,6 +45,16 @@
|
||||
return this.test("url", data, opts);
|
||||
};
|
||||
|
||||
OctoPrintUtilClient.prototype.testServer = function(host, port, additional, opts) {
|
||||
additional = additional || {};
|
||||
|
||||
var data = $.extend({}, additional);
|
||||
data.host = host;
|
||||
data.port = port;
|
||||
|
||||
return this.test("server", data, opts);
|
||||
};
|
||||
|
||||
OctoPrintClient.registerComponent("util", OctoPrintUtilClient);
|
||||
return OctoPrintUtilClient;
|
||||
});
|
||||
Reference in new issue
Block a user