summaryrefslogtreecommitdiffstats
path: root/modules-available/dnbd3
diff options
context:
space:
mode:
authorSimon Rettberg2017-11-03 13:23:47 +0100
committerSimon Rettberg2017-11-03 13:23:47 +0100
commit3ef00090daeae283e739ed147dc397681f04db77 (patch)
tree7b960e810a83709c4347375b5a1eaf05cef8dc50 /modules-available/dnbd3
parent[rebootcontrol] Move reboot function to helper class (diff)
downloadslx-admin-3ef00090daeae283e739ed147dc397681f04db77.tar.gz
slx-admin-3ef00090daeae283e739ed147dc397681f04db77.tar.xz
slx-admin-3ef00090daeae283e739ed147dc397681f04db77.zip
[dnbd3] Add reboot button for managed proxies
Diffstat (limited to 'modules-available/dnbd3')
-rw-r--r--modules-available/dnbd3/page.inc.php32
-rw-r--r--modules-available/dnbd3/templates/page-serverlist.html68
2 files changed, 98 insertions, 2 deletions
diff --git a/modules-available/dnbd3/page.inc.php b/modules-available/dnbd3/page.inc.php
index feefc75d..946df939 100644
--- a/modules-available/dnbd3/page.inc.php
+++ b/modules-available/dnbd3/page.inc.php
@@ -182,6 +182,7 @@ class Page_Dnbd3 extends Page
'list' => $servers,
'enabled' => Dnbd3::isEnabled(),
'checked_s' => Dnbd3::isEnabled() ? 'checked' : '',
+ 'rebootcontrol' => Module::isAvailable('rebootcontrol', false)
));
}
@@ -272,6 +273,8 @@ class Page_Dnbd3 extends Page
$serverId = Request::any('server', false, 'int');
}
if ($serverId === false) {
+ if (AJAX)
+ die('Missing parameter');
Message::addError('main.parameter-missing', 'server');
Util::redirect('?do=dnbd3');
}
@@ -280,6 +283,8 @@ class Page_Dnbd3 extends Page
LEFT JOIN machine m USING (machineuuid)
WHERE s.serverid = :serverId', compact('serverId'));
if ($server === false) {
+ if (AJAX)
+ die('Invalid server id');
Message::addError('server-non-existent', 'server');
Util::redirect('?do=dnbd3');
}
@@ -307,6 +312,8 @@ class Page_Dnbd3 extends Page
$this->ajaxServerTest();
} elseif ($action === 'editserver') {
$this->ajaxEditServer();
+ } elseif ($action === 'reboot') {
+ $this->ajaxReboot();
} else {
die($action . '???');
}
@@ -360,4 +367,29 @@ class Page_Dnbd3 extends Page
echo Render::parse('fragment-server-settings', $server);
}
+ private function ajaxReboot()
+ {
+ $server = $this->getServerById();
+ if (!isset($server['machineuuid'])) {
+ die('Not automatic server.');
+ }
+ if (!Module::isAvailable('rebootcontrol')) {
+ die('No rebootcontrol');
+ }
+ $uuid = $server['machineuuid'];
+ $task = RebootControl::reboot([ $uuid ]);
+ if ($task === false) {
+ die('Taskmanager unreachable');
+ }
+ $task = Taskmanager::waitComplete($task, 2000);
+ if (is_array($task) && isset($task['data']) && isset($task['data']['clientStatus']) && isset($task['data']['clientStatus'][$uuid])) {
+ $status = $task['data']['clientStatus'][$uuid];
+ if (!empty($task['data']['error'])) {
+ $status .= "\n --- \n" . $task['data']['error'];
+ }
+ die($status);
+ }
+ die('Unknown :-(');
+ }
+
}
diff --git a/modules-available/dnbd3/templates/page-serverlist.html b/modules-available/dnbd3/templates/page-serverlist.html
index 2d2ef803..1a4d8255 100644
--- a/modules-available/dnbd3/templates/page-serverlist.html
+++ b/modules-available/dnbd3/templates/page-serverlist.html
@@ -126,13 +126,20 @@
</td>
<td class="text-right">
{{#machineuuid}}
+ {{#rebootcontrol}}
+ <button class="btn btn-warning btn-xs reboot-btn" type="button" data-id="{{serverid}}"
+ data-toggle="modal" data-target="#server-reboot-modal" title="{{lang_reboot}}">
+ <span class="glyphicon glyphicon-repeat"></span>
+ </button>
+ {{/rebootcontrol}}
<button class="btn btn-default btn-xs edit-btn" type="button" data-id="{{serverid}}"
- data-toggle="modal" data-target="#server-edit-modal">
+ data-toggle="modal" data-target="#server-edit-modal" title="{{lang_settings}}">
<span class="glyphicon glyphicon-cog"></span>
</button>
{{/machineuuid}}
{{^self}}
- <button class="btn btn-danger btn-xs" name="server" value="{{serverid}}" onclick="return confirm('{{lang_wantToDelete}}')">
+ <button class="btn btn-danger btn-xs" name="server" value="{{serverid}}"
+ onclick="return confirm('{{lang_wantToDelete}}')" title="{{lang_delete}}">
<span class="glyphicon glyphicon-trash"></span>
</button>
{{/self}}
@@ -226,6 +233,28 @@
</div>
</div>
+<div id="server-reboot-modal" class="modal fade" role="dialog">
+ <div class="modal-dialog">
+ <div class="modal-content">
+ <div class="modal-header">
+ <button type="button" class="close" data-dismiss="modal">&times;</button>
+ <h4 class="modal-title"><b>{{lang_rebootProxyHeading}}</b></h4>
+ </div>
+ <div class="modal-body">
+ <p>{{lang_rebootServerText}}</p>
+ <p id="reboot-status"></p>
+ </div>
+ <div class="modal-footer text-right">
+ <button type="button" class="btn btn-default" data-dismiss="modal">{{lang_close}}</button>
+ <button id="btn-exec-reboot" type="button" class="btn btn-primary">
+ <span class="glyphicon glyphicon-repeat"></span>
+ {{lang_reboot}}
+ </button>
+ </div>
+ </div>
+ </div>
+</div>
+
<div id="add-modal" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
@@ -331,6 +360,41 @@ document.addEventListener('DOMContentLoaded', function () {
var id = $(this).data('id');
$('#server-edit-body').text('loading').load('?do=dnbd3&action=editserver&server=' + id);
});
+
+ var rebootServerId = 0;
+ $('.reboot-btn').click(function() {
+ rebootServerId = $(this).data('id');
+ $('#btn-exec-reboot').prop('disabled', false);
+ $('#reboot-status').empty();
+ });
+ $('#btn-exec-reboot').click(function() {
+ $(this).prop('disabled', true);
+ var $t = $('#reboot-status');
+ if (rebootServerId === 0) {
+ $t.text('No ID!?');
+ return;
+ }
+ $t.html('<span class="glyphicon glyphicon-refresh slx-rotation"></span>');
+ var sid = rebootServerId;
+ var query = function() {
+ $.ajax({
+ "data": {"token": TOKEN, "action": "reboot", "server": sid},
+ "method": "POST",
+ "dataType": "text",
+ "url": "?do=dnbd3"
+ }).done(function (data) {
+ $t.text(data);
+ if (data.indexOf('REBOOTING') !== -1 || data.indexOf('CONNECTING') !== -1) {
+ setTimeout(query, 5000);
+ $t.append($('<span class="glyphicon glyphicon-refresh slx-rotation"></span>'));
+ }
+ }).fail(function () {
+ $.text('Failed');
+ });
+ };
+ query();
+ rebootServerId = 0;
+ });
});
//--></script> \ No newline at end of file