config_show.html 49 KB

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