guest_create.html 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. {% extends "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. .btn,
  14. .form-group>div>div,
  15. .form-control {
  16. border-radius: 0;
  17. }
  18. .btn-ability {
  19. margin-right: 16px;
  20. height: 50px;
  21. padding: 8px 50px;
  22. margin-bottom: 30px;
  23. }
  24. .btn-ability-line {
  25. }
  26. </style>
  27. {% endblock head %}
  28. {% block body %}
  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. $('#create_guest_form').formValidation({
  38. framework: 'bootstrap4',
  39. icon: {
  40. valid: 'fa fa-check',
  41. invalid: 'fa fa-times',
  42. validating: 'fa fa-refresh'
  43. },
  44. // Since the Bootstrap Button hides the radio and checkbox
  45. // We exclude the disabled elements only
  46. excluded: ':disabled',
  47. locale: 'zh_CN',
  48. fields: {
  49. ability: {
  50. validators: {
  51. notEmpty: {
  52. }
  53. }
  54. },
  55. os_template_image_id: {
  56. validators: {
  57. notEmpty: {
  58. }
  59. }
  60. },
  61. quantity: {
  62. validators: {
  63. between: {
  64. min: 1,
  65. max: 20
  66. }
  67. }
  68. },
  69. password: {
  70. validators: {
  71. identical: {
  72. field: 'confirm_password'
  73. },
  74. stringLength: {
  75. max: 128
  76. }
  77. }
  78. },
  79. confirm_password: {
  80. validators: {
  81. identical: {
  82. field: 'password'
  83. }
  84. }
  85. },
  86. remark: {
  87. validators: {
  88. stringLength: {
  89. max: 64
  90. }
  91. }
  92. }
  93. }
  94. })
  95. .on('success.field.fv', function(e, data) {
  96. if (data.fv.getInvalidFields().length > 0) { // There is invalid field
  97. data.fv.disableSubmitButtons(true);
  98. }
  99. });
  100. refresh_os_template_image_id_selectpicker($('#os_template_image_id'));
  101. refresh_ssh_keys_checkboxer($('#ssh_keys_id_div'));
  102. $('#bandwidth_unit').on('changed.bs.select', function (me) {
  103. render_bandwidth_slider($("#bandwidth"), 'update', $('#bandwidth_unit').val())
  104. });
  105. render_bandwidth_slider($("#bandwidth"), 'create', 'm');
  106. });
  107. function get_os_templates_profile_mapping_by_id() {
  108. var os_templates_profile_mapping_by_id = {};
  109. $.ajax({
  110. url : '/api/os_templates_profile',
  111. type : 'GET',
  112. contentType: "application/json; charset=utf-8",
  113. dataType: 'json',
  114. async: false,
  115. error : function() {
  116. },
  117. success : function(data, textStatus, xhr) {
  118. $.each(data.data, function(k, v) {
  119. os_templates_profile_mapping_by_id[v['id']] = v;
  120. });
  121. }
  122. });
  123. return os_templates_profile_mapping_by_id;
  124. }
  125. function refresh_os_template_image_id_selectpicker(selectpicker) {
  126. $.ajax({
  127. url : '/api/os_templates_image?filter=active:eq:1',
  128. type : 'GET',
  129. contentType: "application/json; charset=utf-8",
  130. dataType: 'json',
  131. async: false,
  132. error : function() {
  133. },
  134. success : function(data, textStatus, xhr) {
  135. var os_templates_profile_mapping_by_id = get_os_templates_profile_mapping_by_id();
  136. selectpicker.empty();
  137. $.each(data.data, function(k, v) {
  138. if (v['logo'] === "") {
  139. v['logo'] = os_templates_profile_mapping_by_id[v['os_template_profile_id']].icon;
  140. }
  141. selectpicker.append(
  142. $('<option>', {value: v['id'], text: '\xa0\xa0' + v['label'], 'data-icon': v['logo']})
  143. );
  144. });
  145. selectpicker.selectpicker('refresh');
  146. }
  147. });
  148. }
  149. function refresh_ssh_keys_checkboxer(checkboxer) {
  150. $.ajax({
  151. url : '/api/ssh_keys',
  152. type : 'GET',
  153. contentType: "application/json; charset=utf-8",
  154. dataType: 'json',
  155. async: false,
  156. error : function() {
  157. },
  158. success : function(data, textStatus, xhr) {
  159. checkboxer.empty();
  160. $.each(data.data, function(k, v) {
  161. checkboxer.append(
  162. '<label class="checkbox-inline"><input type="checkbox" name="ssh_keys_id" value="' + v['id'] + '">' + v['label'] + '</label>'
  163. );
  164. });
  165. }
  166. });
  167. }
  168. $(function() { "use strict";
  169. $("#quantity").TouchSpin({
  170. max: 20,
  171. min: 1,
  172. verticalbuttons: true,
  173. verticalupclass: 'glyph-icon icon-plus',
  174. verticaldownclass: 'glyph-icon icon-minus'
  175. });
  176. });
  177. function allocation_by_random_click_handler(me) {
  178. if ($(me).prop('checked')) {
  179. $('#create_guest_form').formValidation('removeField', 'node_id');
  180. $('#node_id').parent().parent().css('display', 'none');
  181. } else {
  182. $('#create_guest_form').formValidation('addField', 'node_id', {validators: {notEmpty: {}}});
  183. $('#node_id').parent().parent().css('display', 'unset');
  184. }
  185. }
  186. </script>
  187. <div class="container" style="padding-top: 100px;">
  188. <div class="panel">
  189. <div class="panel-body">
  190. <h3 class="title-hero" style="display: inline;">
  191. 创建实例
  192. </h3>
  193. <a href="/guests" class="btn btn-xs btn-default add-page-transition" data-transition="pt-page-moveFromLeft-init" style="margin-bottom: 4px; margin-left: 10px;">
  194. <span class="glyph-icon icon-separator" style="transform: rotateY(-180deg);">
  195. <i class="glyph-icon icon-level-up"></i>
  196. </span>
  197. <span class="button-content">
  198. 返回虚拟机列表
  199. </span>
  200. </a>
  201. <div class="example-box-wrapper">
  202. <form id="create_guest_form" class="form-horizontal bordered-row" action="/guests/create" method="post">
  203. <div class="form-group">
  204. <label class="col-sm-2 control-label"><span class="glyph-icon icon-elusive-gauge"></span>&nbsp;&nbsp;运算能力</label>
  205. <div class="col-sm-10">
  206. <div class="btn-ability-line" data-toggle="buttons">
  207. <label class="btn btn-default btn-ability">
  208. <input title="1 CPU 1GB Memory" name="ability" type="radio" value="1c1g">1&nbsp;&nbsp;核&nbsp;&nbsp;1&nbsp;&nbsp;GB
  209. </label>
  210. <label class="btn btn-default btn-ability">
  211. <input title="1 CPU 2GB Memory" name="ability" type="radio" value="1c2g">1&nbsp;&nbsp;核&nbsp;&nbsp;2&nbsp;&nbsp;GB
  212. </label>
  213. <label class="btn btn-default btn-ability">
  214. <input title="2 CPU 2GB Memory" name="ability" type="radio" value="2c2g">2&nbsp;&nbsp;核&nbsp;&nbsp;2&nbsp;&nbsp;GB
  215. </label>
  216. <label class="btn btn-default btn-ability">
  217. <input title="2 CPU 4GB Memory" name="ability" type="radio" value="2c4g">2&nbsp;&nbsp;核&nbsp;&nbsp;4&nbsp;&nbsp;GB
  218. </label>
  219. <label class="btn btn-default btn-ability">
  220. <input title="4 CPU 4GB Memory" name="ability" type="radio" value="4c4g">4&nbsp;&nbsp;核&nbsp;&nbsp;4&nbsp;&nbsp;GB
  221. </label>
  222. <label class="btn btn-default btn-ability">
  223. <input title="4 CPU 8GB Memory" name="ability" type="radio" value="4c8g">4&nbsp;&nbsp;核&nbsp;&nbsp;8&nbsp;&nbsp;GB
  224. </label>
  225. <label class="btn btn-default btn-ability">
  226. <input title="8 CPU 8GB Memory" name="ability" type="radio" value="8c8g">8&nbsp;&nbsp;核&nbsp;&nbsp;8&nbsp;&nbsp;GB
  227. </label>
  228. <label class="btn btn-default btn-ability">
  229. <input title="8 CPU 16GB Memory" name="ability" type="radio" value="8c16g">8&nbsp;&nbsp;核&nbsp;&nbsp;16GB
  230. </label>
  231. <label class="btn btn-default btn-ability">
  232. <input title="1 CPU 16GB Memory" name="ability" type="radio" value="1c16g">1&nbsp;&nbsp;核&nbsp;&nbsp;16GB
  233. </label>
  234. <label class="btn btn-default btn-ability">
  235. <input title="4 CPU 32GB Memory" name="ability" type="radio" value="4c32g">4&nbsp;&nbsp;核&nbsp;&nbsp;32GB
  236. </label>
  237. <label class="btn btn-default btn-ability">
  238. <input title="4 CPU 64GB Memory" name="ability" type="radio" value="4c64g">4&nbsp;&nbsp;核&nbsp;&nbsp;64GB
  239. </label>
  240. <label class="btn btn-default btn-ability">
  241. <input title="8 CPU 64GB Memory" name="ability" type="radio" value="8c64g">8&nbsp;&nbsp;核&nbsp;&nbsp;64GB
  242. </label>
  243. <label class="btn btn-default btn-ability">
  244. <input title="16 CPU 16GB Memory" name="ability" type="radio" value="16c16g">16核&nbsp;&nbsp;16GB
  245. </label>
  246. <label class="btn btn-default btn-ability">
  247. <input title="24 CPU 24GB Memory" name="ability" type="radio" value="24c24g">24核&nbsp;&nbsp;24GB
  248. </label>
  249. <label class="btn btn-default btn-ability">
  250. <input title="32 CPU 32GB Memory" name="ability" type="radio" value="32c32g">32核&nbsp;&nbsp;32GB
  251. </label>
  252. <label class="btn btn-default btn-ability">
  253. <input title="64 CPU 64GB Memory" name="ability" type="radio" value="64c64g">64核&nbsp;&nbsp;64GB
  254. </label>
  255. </div>
  256. </div>
  257. </div>
  258. <div class="form-group">
  259. <label class="col-sm-2 control-label"><span class="glyph-icon icon-elusive-inbox-alt"></span>&nbsp;&nbsp;系统模板</label>
  260. <div class="col-sm-6">
  261. <select id="os_template_image_id" name="os_template_image_id" title="请选择系统模板..." class="selectpicker" data-width="100%">
  262. </select>
  263. </div>
  264. </div>
  265. <div class="form-group">
  266. <label class="col-sm-2 control-label"><span class="glyph-icon icon-elusive-th-list"></span>&nbsp;&nbsp;数量</label>
  267. <div class="col-sm-6">
  268. <input id="quantity" title="实例数量" class="form-control" type="text" value="1" name="quantity">
  269. </div>
  270. </div>
  271. <div class="form-group">
  272. <label class="col-sm-2 control-label"><span class="glyph-icon icon-elusive-compass-circled"></span>&nbsp;&nbsp;标识&密码</label>
  273. <div class="col-sm-6">
  274. <div class="row form-group">
  275. <label class="col-sm-2 control-label">登录密码:</label>
  276. <div class="col-sm-6">
  277. <input type="password" name="password" title="实例密码" class="form-control" id="password" placeholder="如不填写,系统自动生成16位随机密码">
  278. </div>
  279. </div>
  280. <div class="row form-group">
  281. <label class="col-sm-2 control-label">确认密码:</label>
  282. <div class="col-sm-6">
  283. <input type="password" name="confirm_password" title="确认实例密码" class="form-control" id="confirm_password">
  284. </div>
  285. </div>
  286. <div style="height: 10px;"></div>
  287. <div class="row form-group">
  288. <label class="col-sm-2 control-label">实例名称:</label>
  289. <div class="col-sm-6">
  290. <input id="remark" name="remark" type="text" title="实例名称" class="form-control" placeholder="如不填写,系统自动默认生成">
  291. </div>
  292. </div>
  293. </div>
  294. </div>
  295. <div class="form-group">
  296. <label class="col-sm-2 control-label"><span class="glyph-icon icon-signal"></span>&nbsp;&nbsp;带宽</label>
  297. <div class="col-sm-7">
  298. <input id="bandwidth" title="带宽" type="text" name="bandwidth">
  299. </div>
  300. <div class="col-sm-1" style="bottom: -10px;">
  301. <select id="bandwidth_unit" name="bandwidth_unit" title="单位..." class="selectpicker" data-width="120%">
  302. <option value="k">&nbsp;&nbsp;Kbps</option>
  303. <option value="m" selected>&nbsp;&nbsp;Mbps</option>
  304. <option value="g">&nbsp;&nbsp;Gbps</option>
  305. </select>
  306. </div>
  307. </div>
  308. <div class="form-group">
  309. <label class="col-sm-2 control-label"><span class="glyph-icon icon-key"></span>&nbsp;&nbsp;SSH-KEY</label>
  310. <div class="col-sm-6" id="ssh_keys_id_div">
  311. <label class="checkbox-inline">
  312. <input type="checkbox" name="ssh_keys_id" value="option1">
  313. Checkbox 1
  314. </label>
  315. <label class="checkbox-inline">
  316. <input type="checkbox" name="ssh_keys_id" value="option2">
  317. Checkbox 2
  318. </label>
  319. </div>
  320. </div>
  321. <div class="form-group">
  322. <label class="col-sm-2 control-label"><span class="glyph-icon icon-elusive-shuffle"></span>&nbsp;&nbsp;创建模式</label>
  323. <div class="col-sm-6">
  324. <div class="row form-group">
  325. <label class="col-sm-2 control-label">随机分配:</label>
  326. <div class="col-sm-6">
  327. <input onclick="allocation_by_random_click_handler(this);" type="checkbox" name="allocation_by_random" title="随机分配" class="form-control" id="allocation_by_random" checked>
  328. </div>
  329. </div>
  330. <div class="row form-group" style="display: none;">
  331. <select id="node_id" name="node_id" title="请选择计算节点..." class="selectpicker" data-width="100%">
  332. {% for item in hosts_ret.data %}
  333. <option value="{{ item.node_id }}" data-icon="{{ item.icon }}">&nbsp;&nbsp;{{ item.hostname }}</option>
  334. {% endfor %}
  335. </select>
  336. </div>
  337. </div>
  338. </div>
  339. <div class="form-group">
  340. <label class="col-sm-2 control-label"></label>
  341. <div class="col-sm-3 pull-right">
  342. <button type="submit" class="btn btn-blue-alt" style="width: 180px; height: 40px; font-size: 16px;" disabled>创建</button>
  343. </div>
  344. </div>
  345. </form>
  346. </div>
  347. </div>
  348. </div>
  349. </div>
  350. {% endblock body %}