script.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. 'use strict';
  2. 'require view';
  3. 'require ui';
  4. 'require form';
  5. 'require uci';
  6. return view.extend({
  7. load: function() {
  8. return Promise.all([
  9. uci.load('keepalived'),
  10. ]);
  11. },
  12. renderTrackScript: function(m) {
  13. var s, o;
  14. var vrrp_scripts;
  15. vrrp_scripts = uci.sections('keepalived', 'vrrp_script');
  16. if (vrrp_scripts == '') {
  17. ui.addNotification(null, E('p', _('VRRP Scripts must be configured for Track Scripts')));
  18. }
  19. s = m.section(form.GridSection, 'track_script', _('Track Script'),
  20. _('Tracking scripts would be referenced from VRRP instances'));
  21. s.anonymous = true;
  22. s.addremove = true;
  23. s.nodescriptions = true;
  24. o = s.option(form.Value, 'name', _('Name'));
  25. o.optional = false;
  26. o.rmempty = false;
  27. o = s.option(form.ListValue, 'value', _('VRRP Script'));
  28. o.optional = false;
  29. o.rmempty = false;
  30. if (vrrp_scripts != '') {
  31. for (i = 0; i < vrrp_scripts.length; i++) {
  32. o.value(vrrp_scripts[i]['name']);
  33. }
  34. }
  35. o = s.option(form.Value, 'weight', _('Weight'));
  36. o.optional = true;
  37. o.datatype = 'and(integer, range(-253, 253))';
  38. o = s.option(form.ListValue, 'direction', _('Direction'));
  39. o.optional = true;
  40. o.default = '';
  41. o.value('reverse', _('Reverse'));
  42. o.value('noreverse', _('No Reverse'));
  43. },
  44. renderVRRPScript: function(m) {
  45. var s, o;
  46. s = m.section(form.GridSection, 'vrrp_script', _('VRRP Script'),
  47. _('Adds a script to be executed periodically. Its exit code will be recorded for all VRRP instances and sync groups which are monitoring it'));
  48. s.anonymous = true;
  49. s.addremove = true;
  50. s.nodescriptions = true;
  51. o = s.option(form.Value, 'name', _('Name'));
  52. o.optional = true;
  53. o.placeholder = 'name';
  54. o = s.option(form.FileUpload, 'script', _('Script'),
  55. _('Path of the script to execute'));
  56. o.root_directory = '/etc/keepalived/scripts';
  57. o.enable_upload = true;
  58. o.optional = true;
  59. o.datatype = 'file';
  60. o = s.option(form.Value, 'interval', _('Interval'),
  61. _('Seconds between script invocations'));
  62. o.optional = true;
  63. o.datatype = 'uinteger';
  64. o.default = 60;
  65. o = s.option(form.Value, 'weight', _('Weight'),
  66. _('Adjust script execution priority'));
  67. o.optional = true;
  68. o.datatype = 'and(integer, range(-253, 253))';
  69. o = s.option(form.Value, 'rise', _('Rise'),
  70. _('Required number of successes for OK transition'));
  71. o.optional = true;
  72. o.datatype = 'uinteger';
  73. o = s.option(form.Value, 'fail', _('Fail'),
  74. _('Required number of successes for KO transition'));
  75. o.optional = true;
  76. o.datatype = 'uinteger';
  77. },
  78. render: function() {
  79. var m;
  80. m = new form.Map('keepalived');
  81. this.renderVRRPScript(m);
  82. this.renderTrackScript(m);
  83. return m.render();
  84. }
  85. });