Browse Source

创建磁盘兼容如单机版本

James Iter 9 năm trước cách đây
mục cha
commit
2149879429
2 tập tin đã thay đổi với 44 bổ sung2 xóa
  1. 32 0
      templates/disk_create.html
  2. 12 2
      views/disk.py

+ 32 - 0
templates/disk_create.html

@@ -37,6 +37,11 @@
             $('.add-transition').attr('class', 'add-transition');
             $('.add-transition').addClass(transAttr);
         });
+        {% if show_on_host %}
+            refresh_hosts_selectpicker($('#on_host'));
+        {% else %}
+            $('#on_host_form').remove();
+        {% endif %}
     });
 
     $(function() { "use strict";
@@ -58,6 +63,26 @@
             verticaldownclass: 'glyph-icon icon-minus'
         });
     });
+
+    function refresh_hosts_selectpicker(selectpicker) {
+        $.ajax({
+            url : '/api/hosts',
+            type : 'GET',
+            contentType: "application/json; charset=utf-8",
+            dataType: 'json',
+            error : function() {
+            },
+            success : function(data, textStatus, xhr) {
+                selectpicker.empty();
+                $.each(data.data, function(k, v) {
+                    selectpicker.append(
+                        $('<option>', {value: v['hostname'], text: v['hostname']})
+                    );
+                });
+                selectpicker.selectpicker('refresh');
+            }
+        });
+    }
 </script>
 
 <div class="container" style="padding-top: 100px;">
@@ -88,6 +113,13 @@
                             <input id="quantity" title="实例数量" class="form-control" type="text" value="1" name="quantity">
                         </div>
                     </div>
+                    <div id="on_host_form" class="form-group">
+                        <label class="col-sm-2 control-label"><span class="glyph-icon icon-desktop"></span>&nbsp;&nbsp;宿主机</label>
+                        <div class="col-sm-6">
+                            <select id="on_host" name="on_host" title="宿主机" class="selectpicker">
+                            </select>
+                        </div>
+                    </div>
                     <div class="form-group">
                         <label class="col-sm-2 control-label"><span class="glyph-icon icon-elusive-compass-circled"></span>&nbsp;&nbsp;标识</label>
                         <div class="col-sm-6">

+ 12 - 2
views/disk.py

@@ -158,11 +158,13 @@ def create():
         size = request.form.get('size')
         quantity = request.form.get('quantity')
         remark = request.form.get('remark')
+        on_host = request.form.get('on_host')
 
         payload = {
             "size": int(size),
             "quantity": int(quantity),
-            "remark": remark
+            "remark": remark,
+            "on_host": on_host
         }
 
         url = host_url + '/api/disk'
@@ -174,7 +176,15 @@ def create():
                                message='您所提交的资源正在创建中。根据所提交资源的数量,需要等待几到十几秒钟。页面将在10秒钟后自动跳转到实例列表页面!')
 
     else:
-        return render_template('disk_create.html')
+        config_url = host_url + url_for('api_config.r_get')
+        config_ret = requests.get(url=config_url)
+        config_ret = json.loads(config_ret.content)
+
+        show_on_host = False
+        if config_ret['data']['jimv_edition'] == JimVEdition.standalone.value:
+            show_on_host = True
+
+        return render_template('disk_create.html', show_on_host=show_on_host)
 
 
 def detail(uuid):