config_show.html 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949
  1. {% extends theme("layout.html") %}
  2. {% block head %}
  3. {{ super() }}
  4. <style type="text/css">
  5. @media (min-width: 768px) {
  6. .form-horizontal .control-label {
  7. text-align: left;
  8. }
  9. }
  10. label>span {
  11. color: deepskyblue;
  12. }
  13. #batch_change_disk_quota_form label {
  14. padding-left: 0;
  15. padding-right: 0;
  16. }
  17. .btn,
  18. .form-group>div>div,
  19. .form-control {
  20. border-radius: 0;
  21. }
  22. .bootstrap-switch-handle-on {
  23. border-top-left-radius: 0 !important;
  24. border-bottom-left-radius: 0 !important;
  25. }
  26. </style>
  27. {% endblock head %}
  28. {% block content %}
  29. <script>
  30. $(document).ready(function() {
  31. $('body').addClass('add-transition');
  32. $('.add-page-transition').on('click', function(){
  33. var transAttr = $(this).attr('data-transition');
  34. $('.add-transition').attr('class', 'add-transition');
  35. $('.add-transition').addClass(transAttr);
  36. });
  37. $('#storage_mode').on('changed.bs.select', function (me) {
  38. if ($('#storage_mode').val() == '2' || $('#storage_mode').val() == '3') {
  39. $('#dfs_volume_label').css('display', 'unset');
  40. $('#dfs_volume').css('display', 'unset');
  41. } else {
  42. $('#dfs_volume_label').css('display', 'none');
  43. $('#dfs_volume').css('display', 'none');
  44. }
  45. });
  46. register_iops_bps_event();
  47. refresh_ip_pools();
  48. tokens_list_refresh();
  49. $('input.input-switch[name="activity"]').on('switchChange.bootstrapSwitch', function(event, state) {
  50. console.log(this); // DOM element
  51. console.log(event); // jQuery event
  52. console.log(state); // true | false
  53. if (state) {
  54. put_ip_pool_activity($(this).data('id'));
  55. }
  56. });
  57. $('#reserved_ip_modal').on('show.bs.modal', function (me) {
  58. reserved_ip_refresh();
  59. });
  60. $("#reserved_ip_input").keydown(function() {
  61. if (event.keyCode == "13") {//keyCode=13是回车键
  62. add_reserved_ip($('#reserved_ip_input').val())
  63. }
  64. });
  65. });
  66. function refresh() {
  67. window.location.reload();
  68. }
  69. function select_this(me) {
  70. $(me).parent().parent().children().removeClass('active');
  71. $(me).parent().addClass('active');
  72. $('#jimv_system_config, #quota, #ip_pool, #auxiliary, #token').css('display', 'none');
  73. if (me.id === 'quota_label') {
  74. $('#quota').css('display', 'unset');
  75. } else if (me.id === 'ip_pool_label') {
  76. $('#ip_pool').css('display', 'unset');
  77. } else if (me.id === 'token_label') {
  78. $('#token').css('display', 'unset');
  79. } else if (me.id === 'auxiliary_label') {
  80. $('#auxiliary').css('display', 'unset');
  81. } else {
  82. $('#jimv_system_config').css('display', 'unset');
  83. }
  84. }
  85. $(function() { "use strict";
  86. $("#iops_base").TouchSpin({
  87. max: 10000,
  88. min: 0,
  89. verticalbuttons: true,
  90. verticalupclass: 'glyph-icon icon-plus',
  91. verticaldownclass: 'glyph-icon icon-minus'
  92. });
  93. });
  94. $(function() { "use strict";
  95. $("#iops_pre_unit").TouchSpin({
  96. max: 100,
  97. min: 0,
  98. verticalbuttons: true,
  99. verticalupclass: 'glyph-icon icon-plus',
  100. verticaldownclass: 'glyph-icon icon-minus'
  101. });
  102. });
  103. $(function() { "use strict";
  104. $("#iops_cap").TouchSpin({
  105. max: 100000,
  106. min: 0,
  107. verticalbuttons: true,
  108. verticalupclass: 'glyph-icon icon-plus',
  109. verticaldownclass: 'glyph-icon icon-minus'
  110. });
  111. });
  112. $(function() { "use strict";
  113. $("#iops_max").TouchSpin({
  114. max: 200000,
  115. min: 0,
  116. verticalbuttons: true,
  117. verticalupclass: 'glyph-icon icon-plus',
  118. verticaldownclass: 'glyph-icon icon-minus'
  119. });
  120. });
  121. $(function() { "use strict";
  122. $("#iops_max_length").TouchSpin({
  123. max: 600,
  124. min: 0,
  125. postfix: '秒',
  126. verticalbuttons: true,
  127. verticalupclass: 'glyph-icon icon-plus',
  128. verticaldownclass: 'glyph-icon icon-minus'
  129. });
  130. });
  131. $(function() { "use strict";
  132. $("#bps_base").TouchSpin({
  133. max: 1024,
  134. min: 0,
  135. postfix: 'MiB',
  136. verticalbuttons: true,
  137. verticalupclass: 'glyph-icon icon-plus',
  138. verticaldownclass: 'glyph-icon icon-minus'
  139. });
  140. });
  141. $(function() { "use strict";
  142. $("#bps_pre_unit").TouchSpin({
  143. max: 10,
  144. min: 0,
  145. step: 0.01,
  146. decimals: 2,
  147. postfix: 'MiB',
  148. verticalbuttons: true,
  149. verticalupclass: 'glyph-icon icon-plus',
  150. verticaldownclass: 'glyph-icon icon-minus'
  151. });
  152. });
  153. $(function() { "use strict";
  154. $("#bps_cap").TouchSpin({
  155. max: 1024 * 2,
  156. min: 0,
  157. postfix: 'MiB',
  158. verticalbuttons: true,
  159. verticalupclass: 'glyph-icon icon-plus',
  160. verticaldownclass: 'glyph-icon icon-minus'
  161. });
  162. });
  163. $(function() { "use strict";
  164. $("#bps_max").TouchSpin({
  165. max: 1024 * 10,
  166. min: 0,
  167. postfix: 'MiB',
  168. verticalbuttons: true,
  169. verticalupclass: 'glyph-icon icon-plus',
  170. verticaldownclass: 'glyph-icon icon-minus'
  171. });
  172. });
  173. $(function() { "use strict";
  174. $("#bps_max_length").TouchSpin({
  175. max: 600,
  176. min: 0,
  177. postfix: '秒',
  178. verticalbuttons: true,
  179. verticalupclass: 'glyph-icon icon-plus',
  180. verticaldownclass: 'glyph-icon icon-minus'
  181. });
  182. });
  183. function register_iops_bps_event() {
  184. $('#iops').on('change', function () {
  185. $("#iops_rd").trigger("touchspin.updatesettings", {max: $('#iops').val() - $('#iops_wr').val()});
  186. $("#iops_wr").trigger("touchspin.updatesettings", {max: $('#iops').val() - $('#iops_rd').val()});
  187. });
  188. $('#iops_rd').on('change', function () {
  189. $("#iops_wr").trigger("touchspin.updatesettings", {max: $('#iops').val() - $('#iops_rd').val()});
  190. });
  191. $('#iops_wr').on('change', function () {
  192. $("#iops_rd").trigger("touchspin.updatesettings", {max: $('#iops').val() - $('#iops_wr').val()});
  193. });
  194. $('#bps').on('change', function () {
  195. $("#bps_rd").trigger("touchspin.updatesettings", {max: $('#bps').val() - $('#bps_wr').val()});
  196. $("#bps_wr").trigger("touchspin.updatesettings", {max: $('#bps').val() - $('#bps_rd').val()});
  197. });
  198. $('#bps_rd').on('change', function () {
  199. $("#bps_wr").trigger("touchspin.updatesettings", {max: $('#bps').val() - $('#bps_rd').val()});
  200. });
  201. $('#bps_wr').on('change', function () {
  202. $("#bps_rd").trigger("touchspin.updatesettings", {max: $('#bps').val() - $('#bps_wr').val()});
  203. });
  204. }
  205. function update_quota() {
  206. $.ajax({
  207. url : '/api/config/_quota',
  208. type : 'PATCH',
  209. contentType: "application/json; charset=utf-8",
  210. data : JSON.stringify({
  211. iops_base: parseInt($('#iops_base').val()),
  212. iops_pre_unit: parseInt($('#iops_pre_unit').val()),
  213. iops_cap: parseInt($('#iops_cap').val()),
  214. iops_max: parseInt($('#iops_max').val()),
  215. iops_max_length: parseInt($('#iops_max_length').val()),
  216. bps_base: parseInt($('#bps_base').val()) * 1024 * 1024,
  217. bps_pre_unit: parseFloat($('#bps_pre_unit').val()) * 1024 * 1024,
  218. bps_cap: parseInt($('#bps_cap').val()) * 1024 * 1024,
  219. bps_max: parseInt($('#bps_max').val()) * 1024 * 1024,
  220. bps_max_length: parseInt($('#bps_max_length').val()),
  221. influence_current_guest: $('#influence_current_guest').prop('checked')
  222. }),
  223. error : function() {
  224. alter_danger('性能配额更新失败!');
  225. },
  226. success : function() {
  227. alter_success('性能配额更新成功!');
  228. setTimeout(function() {
  229. refresh();
  230. }, 1000);
  231. }
  232. });
  233. }
  234. function refresh_guest_state() {
  235. $.ajax({
  236. url : '/api/guests/_refresh_guest_state',
  237. type : 'PATCH',
  238. error : function() {
  239. alter_danger('刷新虚拟机状态失败!');
  240. },
  241. success : function() {
  242. alter_success('刷新虚拟机状态成功!');
  243. setTimeout(function() {
  244. refresh();
  245. }, 1000);
  246. }
  247. });
  248. }
  249. function exchange_ip_pool_for_panel(ip_pool) {
  250. var activity_checked = '';
  251. if (ip_pool.activity > 0) {
  252. activity_checked = 'checked';
  253. }
  254. return '<div class="panel">\n' +
  255. ' <div class="panel-body">\n' +
  256. ' <form class="form-horizontal bordered-row" style="padding-left: 8%;">\n' +
  257. ' <input title="IP Pool ID" class="form-control" name="id" type="text" value="' + ip_pool.id + '" hidden>\n' +
  258. ' <div class="form-group">\n' +
  259. ' <label class="col-sm-2 control-label">起始 IP</label>\n' +
  260. ' <div class="col-sm-3">\n' +
  261. ' <input title="起始 IP" class="form-control" name="start_ip" type="text" value="' + ip_pool.start_ip + '">\n' +
  262. ' </div>\n' +
  263. ' <label class="col-sm-2 control-label">截止 IP</label>\n' +
  264. ' <div class="col-sm-3">\n' +
  265. ' <input title="截止 IP" class="form-control" name="end_ip" type="text" value="' + ip_pool.end_ip + '">\n' +
  266. ' </div>\n' +
  267. ' </div>\n' +
  268. ' <div class="form-group">\n' +
  269. ' <label class="col-sm-2 control-label">子网掩码</label>\n' +
  270. ' <div class="col-sm-3">\n' +
  271. ' <input title="子网掩码" class="form-control" name="netmask" type="text" value="' + ip_pool.netmask + '">\n' +
  272. ' </div>\n' +
  273. ' <label class="col-sm-2 control-label">网关</label>\n' +
  274. ' <div class="col-sm-3">\n' +
  275. ' <input title="网关" class="form-control" name="gateway" type="text" value="' + ip_pool.gateway + '">\n' +
  276. ' </div>\n' +
  277. ' </div>\n' +
  278. ' <div class="form-group">\n' +
  279. ' <label class="col-sm-2 control-label">DNS1</label>\n' +
  280. ' <div class="col-sm-3">\n' +
  281. ' <input title="DNS1" class="form-control" name="dns1" type="text" value="' + ip_pool.dns1 + '">\n' +
  282. ' </div>\n' +
  283. ' <label class="col-sm-2 control-label">DNS2</label>\n' +
  284. ' <div class="col-sm-3">\n' +
  285. ' <input title="DNS2" class="form-control" name="dns2" type="text" value="' + ip_pool.dns2 + '">\n' +
  286. ' </div>\n' +
  287. ' </div>\n' +
  288. ' <div class="form-group">\n' +
  289. ' <label class="col-sm-2 control-label">名称</label>\n' +
  290. ' <div class="col-sm-3">\n' +
  291. ' <input title="名称" class="form-control" name="name" type="text" value="' + ip_pool.name + '">\n' +
  292. ' </div>\n' +
  293. ' <label class="col-sm-2 control-label">备注</label>\n' +
  294. ' <div class="col-sm-3">\n' +
  295. ' <textarea title="备注" class="form-control" name="description">'+ip_pool.description+'</textarea>\n' +
  296. ' </div>\n' +
  297. ' </div>\n' +
  298. ' <div class="form-group" style="margin-bottom: 0;">\n' +
  299. ' <div class="col-sm-6">\n' +
  300. ' <input type="checkbox" name="activity" data-on-color="info" class="input-switch" data-id="' + ip_pool.id + '" ' + activity_checked + ' data-size="medium" data-on-text="活跃" data-off-text="非活跃">\n' +
  301. ' </div>\n' +
  302. ' <div class="col-sm-6">\n' +
  303. ' <div style="padding: 0; text-align: right;">\n' +
  304. ' <button type="button" class="btn btn-sm btn-primary" style="right: 10%;" data-id="' + ip_pool.id + '" onclick="update_ip_pool(this);">更新</button>\n' +
  305. ' <button type="button" class="btn btn-sm btn-danger" style="right: 4%;" data-toggle="modal" data-target="#ip_pool_delete_modal" onclick="$(\'#ip_pool_id\').val(get_ip_pool_field_value(this, \'id\'));\n' +
  306. ' $(\'#delete_instance_desc\').text(get_ip_pool_field_value(this, \'name\'))">删除</button>\n' +
  307. ' </div>\n' +
  308. ' </div>\n' +
  309. ' </div>\n' +
  310. ' </form>\n' +
  311. ' </div>\n' +
  312. '</div>';
  313. }
  314. function get_ip_pools_html() {
  315. var html = '<div class="row" style="padding: 10px 10px 10px 0; width: 100%;">\n' +
  316. ' <div class="col-sm-12" style="padding-right: 0;">\n' +
  317. ' <div class="pull-right">\n' +
  318. ' <button class="btn btn-default" onclick="window.location.reload();" style="border-radius: 0;"><span class="glyph-icon icon-elusive-arrows-cw"></span></button>\n' +
  319. ' <a class="btn btn-info" href="javascript:;" data-toggle="modal" data-target="#add_ip_pool_modal" style="border-radius: 0; padding-left: 40px; padding-right: 40px;">添加 IP 池</a>\n' +
  320. ' <a class="btn btn-black" href="javascript:;" data-toggle="modal" data-target="#reserved_ip_modal" style="border-radius: 0; padding-left: 40px; padding-right: 40px; color: white;">保留 IP</a>\n' +
  321. ' </div>\n' +
  322. ' </div>\n' +
  323. '</div>';
  324. $.ajax({
  325. url : '/api/ip_pools',
  326. type : 'GET',
  327. contentType: "application/json; charset=utf-8",
  328. dataType: 'json',
  329. async: false,
  330. error : function() {
  331. },
  332. success : function(data, textStatus, xhr) {
  333. $.each(data.data, function(k, v) {
  334. html += exchange_ip_pool_for_panel(v);
  335. });
  336. }
  337. });
  338. return html
  339. }
  340. function refresh_ip_pools() {
  341. var html = get_ip_pools_html();
  342. $('#ip_pool').append(html);
  343. }
  344. function get_ip_pool_field_value(me, name) {
  345. return $(me).parent().parent().parent().parent().serializeArray().filter(
  346. function(field) {return field.name == name})[0].value;
  347. }
  348. function update_ip_pool(me) {
  349. var id = get_ip_pool_field_value(me, 'id');
  350. var start_ip = get_ip_pool_field_value(me, 'start_ip');
  351. var end_ip = get_ip_pool_field_value(me, 'end_ip');
  352. var netmask = get_ip_pool_field_value(me, 'netmask');
  353. var gateway = get_ip_pool_field_value(me, 'gateway');
  354. var dns1 = get_ip_pool_field_value(me, 'dns1');
  355. var dns2 = get_ip_pool_field_value(me, 'dns2');
  356. var name = get_ip_pool_field_value(me, 'name');
  357. var description = get_ip_pool_field_value(me, 'description');
  358. var data = {
  359. start_ip: start_ip,
  360. end_ip: end_ip,
  361. netmask: netmask,
  362. gateway: gateway,
  363. dns1: dns1,
  364. dns2: dns2,
  365. name: name,
  366. description: description
  367. };
  368. $.ajax({
  369. url : '/api/ip_pools/' + String(id),
  370. type : 'PATCH',
  371. contentType: "application/json; charset=utf-8",
  372. async: false,
  373. dataType: "json",
  374. data : JSON.stringify(data),
  375. error : function(data, textStatus, xhr) {
  376. alter_danger(data.responseText);
  377. alter_warning('更新 IP 池失败!');
  378. },
  379. success : function(data, textStatus, xhr) {
  380. alter_success('更新 IP 池成功!');
  381. }
  382. });
  383. setTimeout(function() {
  384. window.location.reload();
  385. }, 3000);
  386. }
  387. function create_ip_pool(me) {
  388. $('#add_ip_pool_modal').modal('hide');
  389. var start_ip = get_ip_pool_field_value(me, 'start_ip');
  390. var end_ip = get_ip_pool_field_value(me, 'end_ip');
  391. var netmask = get_ip_pool_field_value(me, 'netmask');
  392. var gateway = get_ip_pool_field_value(me, 'gateway');
  393. var dns1 = get_ip_pool_field_value(me, 'dns1');
  394. var dns2 = get_ip_pool_field_value(me, 'dns2');
  395. var name = get_ip_pool_field_value(me, 'name');
  396. var description = get_ip_pool_field_value(me, 'description');
  397. var activity = $('#activity').prop('checked');
  398. var data = {
  399. start_ip: start_ip,
  400. end_ip: end_ip,
  401. netmask: netmask,
  402. gateway: gateway,
  403. dns1: dns1,
  404. dns2: dns2,
  405. name: name,
  406. description: description,
  407. activity: activity
  408. };
  409. $.ajax({
  410. url : '/api/ip_pool',
  411. type : 'POST',
  412. contentType: "application/json; charset=utf-8",
  413. async: false,
  414. dataType: "json",
  415. data : JSON.stringify(data),
  416. error : function(data, textStatus, xhr) {
  417. alter_danger(data.responseText);
  418. alter_warning('添加 IP 池失败!');
  419. },
  420. success : function(data, textStatus, xhr) {
  421. alter_success('您所提交的 IP 池已创建。页面将在3秒钟后自动跳转到 IP 池列表页面!');
  422. }
  423. });
  424. setTimeout(function() {
  425. window.location.reload();
  426. }, 3000);
  427. }
  428. function put_ip_pool_activity(id) {
  429. $.ajax({
  430. url : '/api/ip_pool/' + String(id),
  431. type : 'PUT',
  432. async: false,
  433. dataType: "json",
  434. error : function(data, textStatus, xhr) {
  435. alter_danger(data.responseText);
  436. alter_warning('IP 池激活失败!');
  437. },
  438. success : function(data, textStatus, xhr) {
  439. alter_success('IP 池激活成功!');
  440. }
  441. });
  442. setTimeout(function() {
  443. window.location.reload();
  444. }, 3000);
  445. }
  446. function ip_pool_delete_at(me) {
  447. var ip_pool_id = $('#ip_pool_id').val();
  448. ip_pool_remove(ip_pool_id);
  449. $('#ip_pool_delete_modal').modal('hide');
  450. }
  451. function ip_pool_remove(id) {
  452. $.ajax({
  453. url : '/api/ip_pools/' + id,
  454. type : 'DELETE',
  455. contentType: "application/json; charset=utf-8",
  456. error : function() {
  457. alter_danger('IP 池删除指令发送失败!');
  458. },
  459. success : function() {
  460. alter_success('IP 池删除指令发送成功!');
  461. setTimeout(function() {
  462. refresh();
  463. }, 1000);
  464. }
  465. });
  466. }
  467. function row_onmouseover(me) {
  468. $(me).find(".delete_reserved_ip_trigger").css('display','inline-flex');
  469. }
  470. function row_onmouseout(me) {
  471. $(me).find(".delete_reserved_ip_trigger").css('display','none');
  472. }
  473. function add_reserved_ip(ip) {
  474. $.ajax({
  475. url : '/api/reserved_ip',
  476. type : 'POST',
  477. contentType: "application/json; charset=utf-8",
  478. async: false,
  479. dataType: "json",
  480. data : JSON.stringify({ip: ip}),
  481. error : function(data, textStatus, xhr) {
  482. alter_danger(data.responseText);
  483. alter_warning('添加保留 IP 失败!');
  484. },
  485. success : function(data, textStatus, xhr) {
  486. var html = '<tr role="row" data-id="' + data['data']['id'] + '" class="odd" onmouseover="row_onmouseover(this);" onmouseout="row_onmouseout(this);">\n' +
  487. ' <td class="text-center">\n' +
  488. data['data']['ip'] +
  489. ' <div style="display: inline;">\n' +
  490. ' <a href="javascript:;" class="delete_reserved_ip_trigger" style="display: none; float: right;">\n' +
  491. ' <span onclick="reserved_ip_delete(this);" class="glyph-icon icon-iconic-cancel" style="width: 20px; height: 20px; margin-left: 10px; border-radius: 0; color: indianred;"></span>\n' +
  492. ' </a>\n' +
  493. ' </div>\n' +
  494. ' </td>\n' +
  495. '</tr>';
  496. $('#reserved_ip_table tbody').append(html);
  497. alter_success('添加保留 IP 成功!');
  498. }
  499. });
  500. }
  501. function reserved_ip_refresh() {
  502. $.ajax({
  503. url : '/api/reserved_ips',
  504. type : 'GET',
  505. contentType: "application/json; charset=utf-8",
  506. dataType: 'json',
  507. async: false,
  508. error : function() {
  509. },
  510. success : function(data, textStatus, xhr) {
  511. var html = NaN;
  512. $('#reserved_ip_table tbody').empty();
  513. $.each(data.data, function(k, v) {
  514. html = '<tr role="row" data-id="' + v['id'] + '" class="odd" onmouseover="row_onmouseover(this);" onmouseout="row_onmouseout(this);">\n' +
  515. ' <td class="text-center">\n' +
  516. v['ip'] +
  517. ' <div style="display: inline;">\n' +
  518. ' <a href="javascript:;" class="delete_reserved_ip_trigger" style="display: none; float: right;">\n' +
  519. ' <span onclick="reserved_ip_delete(this);" class="glyph-icon icon-iconic-cancel" style="width: 20px; height: 20px; margin-left: 10px; border-radius: 0; color: indianred;"></span>\n' +
  520. ' </a>\n' +
  521. ' </div>\n' +
  522. ' </td>\n' +
  523. '</tr>';
  524. $('#reserved_ip_table tbody').append(html);
  525. });
  526. }
  527. });
  528. }
  529. function reserved_ip_delete(me) {
  530. var id = $(me).parent().parent().parent().parent().data('id');
  531. $.ajax({
  532. url : '/api/reserved_ips/' + id,
  533. type : 'DELETE',
  534. contentType: "application/json; charset=utf-8",
  535. async: false,
  536. error : function(data, textStatus, xhr) {
  537. alter_danger(data.responseText);
  538. alter_warning('添加保留 IP 失败!');
  539. },
  540. success : function(data, textStatus, xhr) {
  541. $('#reserved_ip_table tbody tr[data-id="' +id + '"]').remove()
  542. alter_success('删除保留 IP 成功!');
  543. }
  544. });
  545. }
  546. function tokens_list_refresh() {
  547. $.ajax({
  548. url : '/api/tokens',
  549. type : 'GET',
  550. contentType: "application/json; charset=utf-8",
  551. dataType: 'json',
  552. async: false,
  553. error : function() {
  554. },
  555. success : function(data, textStatus, xhr) {
  556. var html = NaN;
  557. $('#tokens_list_table tbody').empty();
  558. $.each(data.data, function(k, v) {
  559. html = '<tr role="row" class="odd">\n' +
  560. ' <td class="text-center">' + v['token'] + '</td>\n' +
  561. ' <td class="text-center">' + v['ttl'] + '</td>\n' +
  562. ' <td class="text-center">' + v['expire'] + '</td>\n' +
  563. '</tr>';
  564. $('#tokens_list_table tbody').append(html);
  565. });
  566. }
  567. });
  568. }
  569. function add_token() {
  570. $.ajax({
  571. url : '/api/token',
  572. type : 'POST',
  573. contentType: "application/json; charset=utf-8",
  574. async: false,
  575. error : function(data, textStatus, xhr) {
  576. alter_danger(data.responseText);
  577. alter_warning('添加 Token 失败!');
  578. },
  579. success : function(data, textStatus, xhr) {
  580. tokens_list_refresh();
  581. alter_success('添加 Token 成功!');
  582. }
  583. });
  584. }
  585. </script>
  586. <div class="panel">
  587. <div class="panel-body">
  588. <ul class="nav nav-tabs mrg25B">
  589. <li class="active"><a href="javascript:;" onclick="select_this(this);" id="jimv_system_config_label">JimV 系统配置</a></li>
  590. <li><a href="javascript:;" onclick="select_this(this);" id="ip_pool_label">IP 池</a></li>
  591. <li><a href="javascript:;" onclick="select_this(this);" id="quota_label">性能配额</a></li>
  592. <li><a href="javascript:;" onclick="select_this(this);" id="token_label">Token</a></li>
  593. <li><a href="javascript:;" onclick="select_this(this);" id="auxiliary_label">辅助</a></li>
  594. </ul>
  595. <div id="jimv_system_config" class="example-box-wrapper">
  596. <form class="form-horizontal bordered-row" style="padding-left: 8%;">
  597. <div class="form-group">
  598. <label class="col-sm-2 control-label">网桥(业务网络)</label>
  599. <div class="col-sm-3">
  600. <input title="Guest 业务网络" class="form-control" name="vm_network" type="text" disabled value="{{ config.vm_network }}">
  601. </div>
  602. <label class="col-sm-2 control-label">网桥(管理网络)</label>
  603. <div class="col-sm-3">
  604. <input title="Guest 管理网络" class="form-control" name="vm_manage_network" type="text" disabled value="{{ config.vm_manage_network }}">
  605. </div>
  606. </div>
  607. <div class="form-group">
  608. <label class="col-sm-2 control-label">虚拟机磁盘存储模式</label>
  609. <div class="col-sm-3">
  610. <select id="storage_mode" title="虚拟机磁盘存储模式" class="selectpicker" name="storage_mode" data-width="100%" disabled>
  611. <option {% if config.storage_mode == 0 %}selected{% endif %} value="0">本地存储</option>
  612. <option {% if config.storage_mode == 1 %}selected{% endif %} value="1" data-subtext="NFS">挂载共享</option>
  613. <option {% if config.storage_mode == 2 %}selected{% endif %} value="2">Ceph</option>
  614. <option {% if config.storage_mode == 3 %}selected{% endif %} value="3">GlusterFS</option>
  615. </select>
  616. </div>
  617. <label id="dfs_volume_label" class="col-sm-2 control-label" style="display: {% if config.storage_mode in [3] %}unset{% else %}none{% endif %};">分布式文件系统存储卷</label>
  618. <div class="col-sm-3">
  619. <input id="dfs_volume" title="分布式文件系统存储卷" class="form-control" name="dfs_volume" type="text" style="display: {% if config.storage_mode in [3] %}unset{% else %}none{% endif %};" disabled value="{{ config.dfs_volume }}">
  620. </div>
  621. </div>
  622. <div class="form-group">
  623. <label class="col-sm-2 control-label">虚拟机磁盘存放路径</label>
  624. <div class="col-sm-3">
  625. <input title="虚拟机磁盘存放路径" class="form-control" name="storage_path" type="text" disabled value="{{ config.storage_path }}">
  626. </div>
  627. </div>
  628. </form>
  629. </div>
  630. <div id="quota" class="example-box-wrapper" style="display: none;">
  631. <form class="form-horizontal bordered-row" style="padding-left: 8%;">
  632. <div class="form-group" style="margin-bottom: 0;">
  633. <label class="col-sm-2 control-label">
  634. <span class="glyph-icon icon-exchange" style="transform: rotate(90deg); display: inline-flex;"></span>
  635. &nbsp;&nbsp;IOPS 基准值
  636. </label>
  637. <div class="col-sm-3">
  638. <input id="iops_base" title="IOPS 基准值" class="form-control" type="text" value="{{ config.iops_base }}" name="iops_base">
  639. </div>
  640. <span class="col-sm-1"></span>
  641. <label class="col-sm-2 control-label"><span class="glyph-icon icon-openid"></span>&nbsp;&nbsp;BPS 基准值</label>
  642. <div class="col-sm-3">
  643. <input id="bps_base" title="BPS 基准值" class="form-control" type="text" value="{{ (config.bps_base / 1024 / 1024) | int }}" name="bps_base">
  644. </div>
  645. <span class="col-sm-1"></span>
  646. </div>
  647. <div class="form-group" style="margin-bottom: 0;">
  648. <label class="col-sm-2 control-label">
  649. <span class="glyph-icon icon-exchange" style="transform: rotate(90deg); display: inline-flex;"></span>
  650. &nbsp;&nbsp;IOPS/GiB 增益
  651. </label>
  652. <div class="col-sm-3">
  653. <input id="iops_pre_unit" title="IOPS/GiB 增益" class="form-control" type="text" value="{{ config.iops_pre_unit }}" name="iops_pre_unit">
  654. </div>
  655. <span class="col-sm-1"></span>
  656. <label class="col-sm-2 control-label"><span class="glyph-icon icon-openid"></span>&nbsp;&nbsp;BPS/GiB 增益</label>
  657. <div class="col-sm-3">
  658. <input id="bps_pre_unit" title="BPS/GiB 增益 (MiB)" class="form-control" type="text" value="{{ '%0.2f'|format(config.bps_pre_unit / 1024 / 1024) }}" name="bps_pre_unit">
  659. </div>
  660. <span class="col-sm-1"></span>
  661. </div>
  662. <div class="form-group" style="margin-bottom: 0;">
  663. <label class="col-sm-2 control-label">
  664. <span class="glyph-icon icon-exchange" style="transform: rotate(90deg); display: inline-flex;"></span>
  665. &nbsp;&nbsp;IOPS 增益上限
  666. </label>
  667. <div class="col-sm-3">
  668. <input id="iops_cap" title="IOPS 增益上限" class="form-control" type="text" value="{{ config.iops_cap }}" name="iops_cap">
  669. </div>
  670. <span class="col-sm-1"></span>
  671. <label class="col-sm-2 control-label"><span class="glyph-icon icon-openid"></span>&nbsp;&nbsp;BPS 增益上限</label>
  672. <div class="col-sm-3">
  673. <input id="bps_cap" title="BPS 增益上限 (MiB)" class="form-control" type="text" value="{{ (config.bps_cap / 1024 / 1024) | int }}" name="bps_cap">
  674. </div>
  675. <span class="col-sm-1"></span>
  676. </div>
  677. <div class="form-group" style="margin-bottom: 0;">
  678. <label class="col-sm-2 control-label">
  679. <span class="glyph-icon icon-exchange" style="transform: rotate(90deg); display: inline-flex;"></span>
  680. <span class="glyph-icon icon-bitbucket" style="margin-left: -4px;"></span>
  681. &nbsp;&nbsp;IOPS 桶宽
  682. </label>
  683. <div class="col-sm-3">
  684. <input id="iops_max" title="IOPS 桶宽" class="form-control" type="text" value="{{ config.iops_max }}" name="iops_max">
  685. </div>
  686. <span class="col-sm-1"></span>
  687. <label class="col-sm-2 control-label"><span class="glyph-icon icon-openid"></span><span class="glyph-icon icon-bitbucket"></span>&nbsp;&nbsp;BPS 桶宽</label>
  688. <div class="col-sm-3">
  689. <input id="bps_max" title="BPS 桶宽 (MiB)" class="form-control" type="text" value="{{ (config.bps_max / 1024 / 1024) | int }}" name="bps_max">
  690. </div>
  691. <span class="col-sm-1"></span>
  692. </div>
  693. <div class="form-group" style="margin-bottom: 0;">
  694. <label class="col-sm-2 control-label">
  695. <span class="glyph-icon icon-exchange" style="transform: rotate(90deg); display: inline-flex;"></span>
  696. <span class="glyph-icon icon-bitbucket" style="margin-left: -4px;"></span>
  697. &nbsp;&nbsp;IOPS 桶高
  698. </label>
  699. <div class="col-sm-3">
  700. <input id="iops_max_length" title="IOPS 桶高 (秒)" class="form-control" type="text" value="{{ config.iops_max_length }}" name="iops_max_length">
  701. </div>
  702. <span class="col-sm-1"></span>
  703. <label class="col-sm-2 control-label"><span class="glyph-icon icon-openid"></span><span class="glyph-icon icon-bitbucket"></span>&nbsp;&nbsp;BPS 桶高</label>
  704. <div class="col-sm-3">
  705. <input id="bps_max_length" title="BPS 桶高 (秒)" class="form-control" type="text" value="{{ config.bps_max_length }}" name="bps_max_length">
  706. </div>
  707. <span class="col-sm-1"></span>
  708. </div>
  709. <div class="form-group" style="margin-bottom: 0;">
  710. <div class="col-sm-6">
  711. <label>
  712. <input id="influence_current_guest" type="checkbox" name="influence_current_guest">
  713. 同时更新已存在的实例
  714. </label>
  715. </div>
  716. <div class="col-sm-6">
  717. <div style="padding: 0; text-align: right;">
  718. <button type="button" class="btn btn-sm btn-primary" style="right: 10%;" onclick="update_quota();">更新</button>
  719. </div>
  720. </div>
  721. </div>
  722. </form>
  723. </div>
  724. <div id="ip_pool" class="example-box-wrapper" style="display: none;">
  725. </div>
  726. <div id="token" class="example-box-wrapper" style="display: none;">
  727. <div class="row" style="padding: 10px 10px 10px 0; width: 100%;">
  728. <div class="col-sm-12" style="padding-right: 0;">
  729. <div class="pull-right">
  730. <button class="btn btn-default" onclick="window.location.reload();" style="border-radius: 0;"><span class="glyph-icon icon-elusive-arrows-cw"></span></button>
  731. <a class="btn btn-info" href="javascript:;" onclick="add_token();" style="border-radius: 0; padding-left: 40px; padding-right: 40px;">添加 Token</a>
  732. </div>
  733. </div>
  734. </div>
  735. <table id="tokens_list_table" class="table table-bordered table-hover" cellspacing="0" width="100%" role="grid" style="width: 100%;">
  736. <thead>
  737. <tr role="row">
  738. <th class="text-center">Token</th>
  739. <th class="text-center">TTL</th>
  740. <th class="text-center">逾期时间</th>
  741. </tr>
  742. </thead>
  743. <tbody>
  744. </tbody>
  745. </table>
  746. </div>
  747. <div id="auxiliary" class="example-box-wrapper" style="display: none;">
  748. <form class="form-horizontal bordered-row" style="padding-left: 8%;">
  749. <div class="form-group" style="margin-bottom: 0;">
  750. <div class="col-sm-3">
  751. <button type="button" class="btn btn-primary" onclick="refresh_guest_state();">刷新虚拟机状态</button>
  752. </div>
  753. </div>
  754. </form>
  755. </div>
  756. </div>
  757. </div>
  758. <input id="ip_pool_id" title="IP Pool ID" class="form-control" name="ip_pool_id" hidden>
  759. <div class="modal" id="add_ip_pool_modal" tabindex="-1" role="dialog" style="margin-top: 100px;">
  760. <div class="modal-dialog modal-lg">
  761. <div class="modal-content">
  762. <div class="modal-header">
  763. <h4 class="modal-title">添加 IP 池:</h4>
  764. </div>
  765. <div class="panel">
  766. <div class="panel-body">
  767. <form class="form-horizontal bordered-row" style="padding-left: 16%;">
  768. <div class="form-group">
  769. <label class="col-sm-2 control-label">起始 IP</label>
  770. <div class="col-sm-3">
  771. <input title="起始 IP" class="form-control" name="start_ip" type="text">
  772. </div>
  773. <label class="col-sm-2 control-label">截止 IP</label>
  774. <div class="col-sm-3">
  775. <input title="截止 IP" class="form-control" name="end_ip" type="text">
  776. </div>
  777. </div>
  778. <div class="form-group">
  779. <label class="col-sm-2 control-label">子网掩码</label>
  780. <div class="col-sm-3">
  781. <input title="子网掩码" class="form-control" name="netmask" type="text">
  782. </div>
  783. <label class="col-sm-2 control-label">网关</label>
  784. <div class="col-sm-3">
  785. <input title="网关" class="form-control" name="gateway" type="text">
  786. </div>
  787. </div>
  788. <div class="form-group">
  789. <label class="col-sm-2 control-label">DNS1</label>
  790. <div class="col-sm-3">
  791. <input title="DNS1" class="form-control" name="dns1" type="text">
  792. </div>
  793. <label class="col-sm-2 control-label">DNS2</label>
  794. <div class="col-sm-3">
  795. <input title="DNS2" class="form-control" name="dns2" type="text">
  796. </div>
  797. </div>
  798. <div class="form-group">
  799. <label class="col-sm-2 control-label">名称</label>
  800. <div class="col-sm-3">
  801. <input title="名称" class="form-control" name="name" type="text">
  802. </div>
  803. <label class="col-sm-2 control-label">备注</label>
  804. <div class="col-sm-3">
  805. <textarea title="备注" class="form-control" name="description"></textarea>
  806. </div>
  807. </div>
  808. <div class="form-group" style="margin-bottom: 0;">
  809. <div class="col-sm-6">
  810. <div class="checkbox checkbox-info">
  811. <label>
  812. <input id="activity" name="activity" type="checkbox" checked class="custom-checkbox">
  813. 设为默认
  814. </label>
  815. </div>
  816. </div>
  817. <div class="col-sm-6">
  818. <div style="padding: 0; text-align: right;">
  819. <button type="button" class="btn btn-sm btn-primary" style="right: 20%;" onclick="create_ip_pool(this);">创建</button>
  820. <button type="button" class="btn btn-sm btn-default" style="right: 10%;" data-dismiss="modal">取消</button>
  821. </div>
  822. </div>
  823. </div>
  824. </form>
  825. </div>
  826. </div>
  827. </div>
  828. </div>
  829. </div>
  830. <div class="modal" id="ip_pool_delete_modal" tabindex="-1" role="dialog" style="margin-top: 100px;">
  831. <div class="modal-dialog">
  832. <div class="modal-content">
  833. <div class="modal-header">
  834. <h4 class="modal-title">删除 IP 池:</h4>
  835. </div>
  836. <div class="modal-body">
  837. <p>您确定要删除该 IP 池吗?</p>
  838. <h3 style="color: orangered;" id="delete_instance_desc"></h3>
  839. </div>
  840. <div class="modal-footer">
  841. <button type="button" class="btn btn-sm btn-primary" onclick="ip_pool_delete_at();">确定</button>
  842. <button type="button" class="btn btn-sm btn-default" data-dismiss="modal">取消</button>
  843. </div>
  844. </div>
  845. </div>
  846. </div>
  847. <div class="modal" id="reserved_ip_modal" tabindex="-1" role="dialog" style="margin-top: 100px;">
  848. <div class="modal-dialog modal-sm">
  849. <div class="modal-content">
  850. <div class="modal-header">
  851. <h4 class="modal-title">保留 IP:</h4>
  852. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  853. <span aria-hidden="true">&times;</span>
  854. </button>
  855. </div>
  856. <div class="modal-body" style="padding-top: 0; padding-bottom: 0;">
  857. <div class="example-box-wrapper">
  858. <form id="reserved_ip_form" class="form-horizontal bordered-row" action="javascript:;">
  859. <div class="form-group">
  860. <div class="col-sm-1"></div>
  861. <div class="col-sm-10" style="height: 300px; overflow: auto;">
  862. <table id="reserved_ip_table" class="table table-bordered table-hover" cellspacing="0" width="100%" role="grid"
  863. style="width: 100%; margin-bottom: 0;">
  864. <tbody></tbody>
  865. </table>
  866. </div>
  867. <div class="col-sm-1"></div>
  868. </div>
  869. <div class="form-group">
  870. <div class="col-sm-1"></div>
  871. <div class="col-sm-10">
  872. <input id="reserved_ip_input" class="form-control" style="text-align: center;" type="text" placeholder="将要保留的 IP">
  873. </div>
  874. <div class="col-sm-1"></div>
  875. </div>
  876. </form>
  877. </div>
  878. </div>
  879. </div>
  880. </div>
  881. </div>
  882. {% endblock content %}