Procházet zdrojové kódy

磁盘创建页面分离完毕

James Iter před 8 roky
rodič
revize
576b346890

+ 176 - 2
api/disk.py

@@ -1,9 +1,10 @@
 #!/usr/bin/env python
 # -*- coding: utf-8 -*-
+from math import ceil
 
-
-from flask import Blueprint, request
+from flask import Blueprint, request, url_for
 import json
+import requests
 from uuid import uuid4
 import jimit as ji
 
@@ -437,3 +438,176 @@ def r_distribute_count():
     return ret
 
 
+@Utils.dumps2response
+def r_show():
+    args = list()
+
+    page = request.args.get('page', 1)
+    if page == '':
+        page = 1
+    page = int(page)
+
+    page_size = int(request.args.get('page_size', 10))
+    keyword = request.args.get('keyword', None)
+    show_area = request.args.get('show_area', 'unmount')
+    guest_uuid = request.args.get('guest_uuid', None)
+    sequence = request.args.get('sequence', None)
+    order_by = request.args.get('order_by', None)
+    order = request.args.get('order', None)
+    filters = list()
+
+    if page is not None:
+        args.append('page=' + page.__str__())
+
+    if page_size is not None:
+        args.append('page_size=' + page_size.__str__())
+
+    if keyword is not None:
+        args.append('keyword=' + keyword.__str__())
+
+    if guest_uuid is not None:
+        filters.append('guest_uuid:in:' + guest_uuid.__str__())
+        show_area = 'all'
+
+    if sequence is not None:
+        filters.append('sequence:in:' + sequence.__str__())
+        show_area = 'all'
+
+    if show_area in ['unmount', 'data_disk', 'all']:
+        if show_area == 'unmount':
+            filters.append('sequence:eq:-1')
+
+        elif show_area == 'data_disk':
+            filters.append('sequence:gt:0')
+
+        else:
+            pass
+
+    else:
+        # 与前端页面相照应,首次打开时,默认只显示未挂载的磁盘
+        filters.append('sequence:eq:-1')
+
+    if order_by is not None:
+        args.append('order_by=' + order_by)
+
+    if order is not None:
+        args.append('order=' + order)
+
+    if filters.__len__() > 0:
+        args.append('filter=' + ','.join(filters))
+
+    hosts_url = url_for('api_hosts.r_get_by_filter', _external=True)
+    disks_url = url_for('api_disks.r_get_by_filter', _external=True)
+
+    if keyword is not None:
+        disks_url = url_for('api_disks.r_content_search', _external=True)
+        # 关键字检索,不支持显示域过滤
+        show_area = 'all'
+
+    hosts_ret = requests.get(url=hosts_url, cookies=request.cookies)
+    hosts_ret = json.loads(hosts_ret.content)
+
+    hosts_mapping_by_node_id = dict()
+    for host in hosts_ret['data']:
+        hosts_mapping_by_node_id[int(host['node_id'])] = host
+
+    if args.__len__() > 0:
+        disks_url = disks_url + '?' + '&'.join(args)
+
+    disks_ret = requests.get(url=disks_url, cookies=request.cookies)
+    disks_ret = json.loads(disks_ret.content)
+
+    guests_uuid = list()
+    disks_uuid = list()
+
+    for disk in disks_ret['data']:
+        disks_uuid.append(disk['uuid'])
+
+        if disk['guest_uuid'].__len__() == 36:
+            guests_uuid.append(disk['guest_uuid'])
+
+    if guests_uuid.__len__() > 0:
+        guests, _ = Guest.get_by_filter(filter_str='uuid:in:' + ','.join(guests_uuid))
+
+        guests_uuid_mapping = dict()
+        for guest in guests:
+            guests_uuid_mapping[guest['uuid']] = guest
+
+        for i, disk in enumerate(disks_ret['data']):
+            if disk['guest_uuid'].__len__() == 36:
+                disks_ret['data'][i]['guest'] = guests_uuid_mapping[disk['guest_uuid']]
+
+    if disks_uuid.__len__() > 0:
+        snapshots_id_mapping_by_disks_uuid_url = url_for('api_snapshots.r_get_snapshots_by_disks_uuid',
+                                                         disks_uuid=','.join(disks_uuid), _external=True)
+        snapshots_id_mapping_by_disks_uuid_ret = requests.get(url=snapshots_id_mapping_by_disks_uuid_url,
+                                                              cookies=request.cookies)
+        snapshots_id_mapping_by_disks_uuid_ret = json.loads(snapshots_id_mapping_by_disks_uuid_ret.content)
+
+        snapshots_id_mapping_by_disk_uuid = dict()
+
+        for snapshot_id_mapping_by_disk_uuid in snapshots_id_mapping_by_disks_uuid_ret['data']:
+
+            disk_uuid = snapshot_id_mapping_by_disk_uuid['disk_uuid']
+            snapshot_id = snapshot_id_mapping_by_disk_uuid['snapshot_id']
+
+            if disk_uuid not in snapshots_id_mapping_by_disk_uuid:
+                snapshots_id_mapping_by_disk_uuid[disk_uuid] = list()
+
+            snapshots_id_mapping_by_disk_uuid[disk_uuid].append(snapshot_id)
+
+        for i, disk in enumerate(disks_ret['data']):
+            if disk['uuid'] in snapshots_id_mapping_by_disk_uuid:
+                disks_ret['data'][i]['snapshot'] = snapshots_id_mapping_by_disk_uuid[disk['uuid']]
+
+    config = Config()
+    config.id = 1
+    config.get()
+
+    show_on_host = False
+    if config.storage_mode == StorageMode.local.value:
+        show_on_host = True
+
+    last_page = int(ceil(disks_ret['paging']['total'] / float(page_size)))
+    page_length = 5
+    pages = list()
+    if page < int(ceil(page_length / 2.0)):
+        for i in range(1, page_length + 1):
+            pages.append(i)
+            if i == last_page or last_page == 0:
+                break
+
+    elif last_page - page < page_length / 2:
+        for i in range(last_page - page_length + 1, last_page + 1):
+            if i < 1:
+                continue
+            pages.append(i)
+
+    else:
+        for i in range(page - page_length / 2, page + int(ceil(page_length / 2.0))):
+            pages.append(i)
+            if i == last_page or last_page == 0:
+                break
+
+    ret = dict()
+    ret['state'] = ji.Common.exchange_state(20000)
+
+    ret['data'] = {
+        'disks': disks_ret['data'],
+        'hosts_mapping_by_node_id': hosts_mapping_by_node_id,
+        'order_by': order_by,
+        'order': order,
+        'show_area': show_area,
+        'config': config.__dict__,
+        'show_on_host': show_on_host,
+        'paging': disks_ret['paging'],
+        'page': page,
+        'page_size': page_size,
+        'keyword': keyword,
+        'pages': pages,
+        'last_page': last_page
+    }
+
+    return ret
+
+

+ 1 - 0
api_route_table.py

@@ -132,6 +132,7 @@ add_rule_api(disk.blueprints, '/<uuids>', api_func='disk.r_get', methods=['GET']
 add_rule_api(disk.blueprints, '', api_func='disk.r_get_by_filter', methods=['GET'])
 add_rule_api(disk.blueprints, '/_search', api_func='disk.r_content_search', methods=['GET'])
 add_rule_api(disk.blueprints, '/_distribute_count', api_func='disk.r_distribute_count', methods=['GET'])
+add_rule_api(disk.blueprints, '/_show', api_func='disk.r_show', methods=['GET'])
 
 # 日志查询
 # 系统模板操作

+ 73 - 11
templates/disk_create.html

@@ -37,11 +37,21 @@
             $('.add-transition').attr('class', 'add-transition');
             $('.add-transition').addClass(transAttr);
         });
-        {% if show_on_host %}
-            refresh_hosts_selectpicker($('#node_id'));
-        {% else %}
-            $('#on_host_form').remove();
-        {% endif %}
+
+        $.ajax({
+            url: '/api/config',
+            type : 'GET',
+            dataType: "json",
+            error : function(data, textStatus, xhr) {
+            },
+            success : function(data, textStatus, xhr) {
+                if (data['data']['storage_mode'] === 0) {
+                    refresh_hosts_selectpicker($('#node_id'));
+                } else {
+                    $('#on_host_form').remove();
+                }
+            }
+        });
 
         $('#create_disk_form').formValidation({
             framework: 'bootstrap4',
@@ -79,12 +89,13 @@
                     }
                 }
             }
-        })
-        .on('success.field.fv', function(e, data) {
+        }).on('success.field.fv', function(e, data) {
             if (data.fv.getInvalidFields().length > 0) {    // There is invalid field
                 data.fv.disableSubmitButtons(true);
             }
-        })
+        }).on('success.form.fv', function (e, data) {
+            create();
+        });
     });
 
     $(function() { "use strict";
@@ -126,8 +137,59 @@
             }
         });
     }
-</script>
 
+    function create() {
+        var data = {
+            size: parseInt($('#size').val()),
+            quantity: parseInt($('#quantity').val()),
+            remark: $('#remark').val(),
+            node_id: $('#node_id').val()
+        };
+
+        var go_back_url = '/disks';
+
+        $.ajax({
+            url : '/api/disk',
+            type : 'POST',
+            contentType: "application/json; charset=utf-8",
+            async: false,
+            dataType: "json",
+            data : JSON.stringify(data),
+            error : function(data, textStatus, xhr) {
+                alter_warning('创建磁盘失败!');
+                alter_danger(data.responseText);
+            },
+            success : function(data, textStatus, xhr) {
+                alter_success('您所提交的资源正在创建中。根据所提交资源的大小,需要等待几到十几秒钟。页面将在3秒钟后自动跳转到实例列表页面!');
+
+                $.ajax({
+                    url: '/api/disks?filter=sequence:eq:-1',
+                    type : 'GET',
+                    dataType: "json",
+                    error : function(data, textStatus, xhr) {
+                    },
+                    success : function(data, textStatus, xhr) {
+                        var page_size = 10;
+                        var last_page = Math.ceil(data['paging']['total'] / page_size);
+                        go_back_url = "/disks?page_size=" + page_size + "&page=" + last_page;
+                    }
+                });
+            }
+        });
+
+        setTimeout(function() {
+            window.location.href=go_back_url;
+        }, 3000);
+    }
+</script>
+<div id="page-content-wrapper">
+    <div id="alert-success-tip" class="alert alert-success alert-top">
+    </div>
+    <div id="alert-warning-tip" class="alert alert-warning alert-top">
+    </div>
+    <div id="alert-danger-tip" class="alert alert-danger alert-top">
+    </div>
+</div>
 <div class="container" style="padding-top: 100px;">
     <div class="panel">
         <div class="panel-body">
@@ -143,7 +205,7 @@
                 </span>
             </a>
             <div class="example-box-wrapper">
-                <form id="create_disk_form" class="form-horizontal bordered-row" action="/disks/create" method="post">
+                <form id="create_disk_form" class="form-horizontal bordered-row" action="javascript:;">
                     <div class="form-group">
                         <label class="col-sm-2 control-label"><span class="glyph-icon icon-elusive-hdd"></span>&nbsp;&nbsp;磁盘大小 (GB)</label>
                         <div class="col-sm-6">
@@ -178,7 +240,7 @@
                     <div class="form-group">
                         <label class="col-sm-2 control-label"></label>
                         <div class="col-sm-3 pull-right">
-                            <button type="submit" class="btn btn-blue-alt" style="width: 180px; height: 40px; font-size: 16px;">创建</button>
+                            <button id="create_disk_form_button" type="submit" class="btn btn-blue-alt" style="width: 180px; height: 40px; font-size: 16px;">创建</button>
                         </div>
                     </div>
                 </form>

+ 19 - 19
templates/disks_show.html

@@ -462,7 +462,7 @@
 
     $(function() { "use strict";
         $("#iops").TouchSpin({
-            max: {{ config_ret.data.iops_cap }},
+            max: {{ config.iops_cap }},
             min: 0,
             verticalbuttons: true,
             verticalupclass: 'glyph-icon icon-plus',
@@ -472,7 +472,7 @@
 
     $(function() { "use strict";
         $("#iops_rd").TouchSpin({
-            max: {{ config_ret.data.iops_cap }},
+            max: {{ config.iops_cap }},
             min: 0,
             verticalbuttons: true,
             verticalupclass: 'glyph-icon icon-plus',
@@ -482,7 +482,7 @@
 
     $(function() { "use strict";
         $("#iops_wr").TouchSpin({
-            max: {{ config_ret.data.iops_cap }},
+            max: {{ config.iops_cap }},
             min: 0,
             verticalbuttons: true,
             verticalupclass: 'glyph-icon icon-plus',
@@ -492,7 +492,7 @@
 
     $(function() { "use strict";
         $("#iops_max").TouchSpin({
-            max: {{ config_ret.data.iops_max }},
+            max: {{ config.iops_max }},
             min: 0,
             verticalbuttons: true,
             verticalupclass: 'glyph-icon icon-plus',
@@ -502,7 +502,7 @@
 
     $(function() { "use strict";
         $("#iops_max_length").TouchSpin({
-            max: {{ config_ret.data.iops_max_length }},
+            max: {{ config.iops_max_length }},
             min: 0,
             postfix: '秒',
             verticalbuttons: true,
@@ -513,7 +513,7 @@
 
     $(function() { "use strict";
         $("#bps").TouchSpin({
-            max: {{ (config_ret.data.bps_cap / 1024 / 1024) | int }},
+            max: {{ (config.bps_cap / 1024 / 1024) | int }},
             min: 0,
             postfix: 'MiB',
             verticalbuttons: true,
@@ -524,7 +524,7 @@
 
     $(function() { "use strict";
         $("#bps_rd").TouchSpin({
-            max: {{ (config_ret.data.bps_cap / 1024 / 1024) | int }},
+            max: {{ (config.bps_cap / 1024 / 1024) | int }},
             min: 0,
             postfix: 'MiB',
             verticalbuttons: true,
@@ -535,7 +535,7 @@
 
     $(function() { "use strict";
         $("#bps_wr").TouchSpin({
-            max: {{ (config_ret.data.bps_cap / 1024 / 1024) | int }},
+            max: {{ (config.bps_cap / 1024 / 1024) | int }},
             min: 0,
             postfix: 'MiB',
             verticalbuttons: true,
@@ -546,7 +546,7 @@
 
     $(function() { "use strict";
         $("#bps_max").TouchSpin({
-            max: {{ (config_ret.data.bps_max / 1024 / 1024) | int }},
+            max: {{ (config.bps_max / 1024 / 1024) | int }},
             min: 0,
             postfix: 'MiB',
             verticalbuttons: true,
@@ -557,7 +557,7 @@
 
     $(function() { "use strict";
         $("#bps_max_length").TouchSpin({
-            max: {{ config_ret.data.bps_max_length }},
+            max: {{ config.bps_max_length }},
             min: 0,
             postfix: '秒',
             verticalbuttons: true,
@@ -638,7 +638,7 @@
                 </tr>
                 </thead>
                 <tbody>
-                {% for item in disks_ret.data %}
+                {% for item in disks %}
                 <tr role="row" class="odd" onmouseover="row_onmouseover(this);" onmouseout="row_onmouseout(this);">
                     <td style="display: none;">{{ item.uuid }}</td>
                     <td><input title="选中" type="checkbox"></td>
@@ -666,7 +666,7 @@
                         {{ item.guest.label }}/{{ item.guest.remark }}
                     {% endif %}</a>
                     </td>
-                    <td style="{% if not show_on_host %}display: none;{% endif %}">{{ hosts_mapping_by_node_id[item.node_id].hostname }}</td>
+                    <td style="{% if not show_on_host %}display: none;{% endif %}">{{ hosts_mapping_by_node_id[item.node_id | string].hostname }}</td>
                     <td style="display: none;">{{ item.node_id }}</td>
                     <td>
                         {% if item.sequence == 0 %}
@@ -725,7 +725,7 @@
                                     <button class="btn btn-default btn-shortcut disabled" data-toggle="modal" data-target="#batch_change_disk_quota_modal">变更配额</button>
                                 </div>
                                 <div class="col-sm-3" style="font-size: 12px; padding-top: 5px; text-align: right;">
-                                    共有{{ disks_ret.paging.total }}条,每页显示:
+                                    共有{{ paging.total }}条,每页显示:
                                     <select id="page_size" name="datatable-row-highlight_length" title="page_size" class="form-control" style="height: 22px; vertical-align: baseline;">
                                         <option value="10" {% if page_size == 10 %} selected {% endif %}>10</option>
                                         <option value="20" {% if page_size == 20 %} selected {% endif %}>20</option>
@@ -865,12 +865,12 @@
                             &nbsp;&nbsp;IOPS
                         </label>
                         <div class="col-sm-3">
-                            <input id="iops" title="IOPS" class="form-control" type="text" value="{{ config_ret.data.iops_base }}" name="iops">
+                            <input id="iops" title="IOPS" class="form-control" type="text" value="{{ config.iops_base }}" name="iops">
                         </div>
                         <span class="col-sm-1"></span>
                         <label class="col-sm-2 control-label"><span class="glyph-icon icon-openid"></span>&nbsp;&nbsp;BPS</label>
                         <div class="col-sm-3">
-                            <input id="bps" title="BPS" class="form-control" type="text" value="{{ (config_ret.data.bps_base / 1024 / 1024) | int }}" name="bps">
+                            <input id="bps" title="BPS" class="form-control" type="text" value="{{ (config.bps_base / 1024 / 1024) | int }}" name="bps">
                         </div>
                         <span class="col-sm-1"></span>
                     </div>
@@ -911,12 +911,12 @@
                             &nbsp;&nbsp;IOPS 桶宽
                         </label>
                         <div class="col-sm-3">
-                            <input id="iops_max" title="IOPS 桶宽" class="form-control" type="text" value="{{ config_ret.data.iops_max }}" name="iops_max">
+                            <input id="iops_max" title="IOPS 桶宽" class="form-control" type="text" value="{{ config.iops_max }}" name="iops_max">
                         </div>
                         <span class="col-sm-1"></span>
                         <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>
                         <div class="col-sm-3">
-                            <input id="bps_max" title="BPS 桶宽" class="form-control" type="text" value="{{ (config_ret.data.bps_max / 1024 / 1024) | int }}" name="bps_max">
+                            <input id="bps_max" title="BPS 桶宽" class="form-control" type="text" value="{{ (config.bps_max / 1024 / 1024) | int }}" name="bps_max">
                         </div>
                         <span class="col-sm-1"></span>
                     </div>
@@ -927,12 +927,12 @@
                             &nbsp;&nbsp;IOPS 桶高
                         </label>
                         <div class="col-sm-3">
-                            <input id="iops_max_length" title="IOPS 桶高" class="form-control" type="text" value="{{ config_ret.data.iops_max_length }}" name="iops_max_length">
+                            <input id="iops_max_length" title="IOPS 桶高" class="form-control" type="text" value="{{ config.iops_max_length }}" name="iops_max_length">
                         </div>
                         <span class="col-sm-1"></span>
                         <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>
                         <div class="col-sm-3">
-                            <input id="bps_max_length" title="BPS 桶高" class="form-control" type="text" value="{{ config_ret.data.bps_max_length }}" name="bps_max_length">
+                            <input id="bps_max_length" title="BPS 桶高" class="form-control" type="text" value="{{ config.bps_max_length }}" name="bps_max_length">
                         </div>
                         <span class="col-sm-1"></span>
                     </div>

+ 5 - 5
templates/guest_create.html

@@ -185,17 +185,17 @@
     }
 
     function create() {
-        var adjust_ability_value = $('#create_guest_form input:radio[name="ability"]:checked').val();
+        var ability_value = $('#create_guest_form input:radio[name="ability"]:checked').val();
 
-        adjust_ability_value = adjust_ability_value.match(/^(\d+)c(\d+)g$/i);
+        ability_value = ability_value.match(/^(\d+)c(\d+)g$/i);
 
-        if (adjust_ability_value === null) {
+        if (ability_value === null) {
             alter_danger('指定的配置取值有误!');
             return
         }
 
-        var cpu = adjust_ability_value[1];
-        var memory = adjust_ability_value[2];
+        var cpu = ability_value[1];
+        var memory = ability_value[2];
 
         var data = {
             cpu: parseInt(cpu),

+ 17 - 187
views/disk.py

@@ -29,200 +29,30 @@ blueprints = Blueprint(
 
 
 def show():
-    args = list()
+    url = url_for('api_disks.r_show', _external=True)
+    if request.args.__len__() >= 1:
+        args = list()
 
-    page = request.args.get('page', 1)
-    if page == '':
-        page = 1
-    page = int(page)
+        for k, v in request.args.items():
+            args.append('='.join([k, v]))
 
-    page_size = int(request.args.get('page_size', 10))
-    keyword = request.args.get('keyword', None)
-    show_area = request.args.get('show_area', 'unmount')
-    guest_uuid = request.args.get('guest_uuid', None)
-    sequence = request.args.get('sequence', None)
-    order_by = request.args.get('order_by', None)
-    order = request.args.get('order', None)
-    filters = list()
-    resource_path = request.path
+        url += '?' + '&'.join(args)
 
-    if page is not None:
-        args.append('page=' + page.__str__())
+    ret = requests.get(url=url, cookies=request.cookies)
+    ret = json.loads(ret.content)
 
-    if page_size is not None:
-        args.append('page_size=' + page_size.__str__())
-
-    if keyword is not None:
-        args.append('keyword=' + keyword.__str__())
-
-    if guest_uuid is not None:
-        filters.append('guest_uuid:in:' + guest_uuid.__str__())
-        show_area = 'all'
-
-    if sequence is not None:
-        filters.append('sequence:in:' + sequence.__str__())
-        show_area = 'all'
-
-    if show_area in ['unmount', 'data_disk', 'all']:
-        if show_area == 'unmount':
-            filters.append('sequence:eq:-1')
-
-        elif show_area == 'data_disk':
-            filters.append('sequence:gt:0')
-
-        else:
-            pass
-
-    else:
-        # 与前端页面相照应,首次打开时,默认只显示未挂载的磁盘
-        filters.append('sequence:eq:-1')
-
-    if order_by is not None:
-        args.append('order_by=' + order_by)
-
-    if order is not None:
-        args.append('order=' + order)
-
-    if filters.__len__() > 0:
-        args.append('filter=' + ','.join(filters))
-
-    host_url = request.host_url.rstrip('/')
-
-    hosts_url = host_url + url_for('api_hosts.r_get_by_filter')
-    disks_url = host_url + url_for('api_disks.r_get_by_filter')
-    config_url = host_url + url_for('api_config.r_get')
-
-    if keyword is not None:
-        disks_url = host_url + url_for('api_disks.r_content_search')
-        # 关键字检索,不支持显示域过滤
-        show_area = 'all'
-
-    hosts_ret = requests.get(url=hosts_url, cookies=request.cookies)
-    hosts_ret = json.loads(hosts_ret.content)
-
-    hosts_mapping_by_node_id = dict()
-    for host in hosts_ret['data']:
-        hosts_mapping_by_node_id[int(host['node_id'])] = host
-
-    if args.__len__() > 0:
-        disks_url = disks_url + '?' + '&'.join(args)
-
-    disks_ret = requests.get(url=disks_url, cookies=request.cookies)
-    disks_ret = json.loads(disks_ret.content)
-
-    guests_uuid = list()
-    disks_uuid = list()
-
-    for disk in disks_ret['data']:
-        disks_uuid.append(disk['uuid'])
-
-        if disk['guest_uuid'].__len__() == 36:
-            guests_uuid.append(disk['guest_uuid'])
-
-    if guests_uuid.__len__() > 0:
-        guests_url = host_url + url_for('api_guests.r_get_by_filter', filter='uuid:in:' + ','.join(guests_uuid))
-        guests_ret = requests.get(url=guests_url, cookies=request.cookies)
-        guests_ret = json.loads(guests_ret.content)
-
-        guests_uuid_mapping = dict()
-        for guest in guests_ret['data']:
-            guests_uuid_mapping[guest['uuid']] = guest
-
-        for i, disk in enumerate(disks_ret['data']):
-            if disk['guest_uuid'].__len__() == 36:
-                disks_ret['data'][i]['guest'] = guests_uuid_mapping[disk['guest_uuid']]
-
-    if disks_uuid.__len__() > 0:
-        snapshots_id_mapping_by_disks_uuid_url = host_url + url_for('api_snapshots.r_get_snapshots_by_disks_uuid',
-                                                                    disks_uuid=','.join(disks_uuid))
-        snapshots_id_mapping_by_disks_uuid_ret = requests.get(url=snapshots_id_mapping_by_disks_uuid_url,
-                                                              cookies=request.cookies)
-        snapshots_id_mapping_by_disks_uuid_ret = json.loads(snapshots_id_mapping_by_disks_uuid_ret.content)
-
-        snapshots_id_mapping_by_disk_uuid = dict()
-
-        for snapshot_id_mapping_by_disk_uuid in snapshots_id_mapping_by_disks_uuid_ret['data']:
-
-            disk_uuid = snapshot_id_mapping_by_disk_uuid['disk_uuid']
-            snapshot_id = snapshot_id_mapping_by_disk_uuid['snapshot_id']
-
-            if disk_uuid not in snapshots_id_mapping_by_disk_uuid:
-                snapshots_id_mapping_by_disk_uuid[disk_uuid] = list()
-
-            snapshots_id_mapping_by_disk_uuid[disk_uuid].append(snapshot_id)
-
-        for i, disk in enumerate(disks_ret['data']):
-            if disk['uuid'] in snapshots_id_mapping_by_disk_uuid:
-                disks_ret['data'][i]['snapshot'] = snapshots_id_mapping_by_disk_uuid[disk['uuid']]
-
-    config_ret = requests.get(url=config_url, cookies=request.cookies)
-    config_ret = json.loads(config_ret.content)
-
-    show_on_host = False
-    if config_ret['data']['storage_mode'] == StorageMode.local.value:
-        show_on_host = True
-
-    last_page = int(ceil(disks_ret['paging']['total'] / float(page_size)))
-    page_length = 5
-    pages = list()
-    if page < int(ceil(page_length / 2.0)):
-        for i in range(1, page_length + 1):
-            pages.append(i)
-            if i == last_page or last_page == 0:
-                break
-
-    elif last_page - page < page_length / 2:
-        for i in range(last_page - page_length + 1, last_page + 1):
-            if i < 1:
-                continue
-            pages.append(i)
-
-    else:
-        for i in range(page - page_length / 2, page + int(ceil(page_length / 2.0))):
-            pages.append(i)
-            if i == last_page or last_page == 0:
-                break
-
-    return render_template('disks_show.html', disks_ret=disks_ret, resource_path=resource_path,
-                           hosts_mapping_by_node_id=hosts_mapping_by_node_id,
-                           page=page, page_size=page_size, keyword=keyword, pages=pages, order_by=order_by, order=order,
-                           last_page=last_page, show_area=show_area, config_ret=config_ret, show_on_host=show_on_host)
+    return render_template('disks_show.html', disks=ret['data']['disks'],
+                           resource_path=request.path,
+                           hosts_mapping_by_node_id=ret['data']['hosts_mapping_by_node_id'],
+                           page=ret['data']['page'], page_size=ret['data']['page_size'], keyword=ret['data']['keyword'],
+                           pages=ret['data']['pages'], order_by=ret['data']['order_by'], order=ret['data']['order'],
+                           last_page=ret['data']['last_page'], paging=ret['data']['paging'],
+                           show_area=ret['data']['show_area'], config=ret['data']['config'],
+                           show_on_host=ret['data']['show_on_host'])
 
 
 def create():
-    host_url = request.host_url.rstrip('/')
-
-    if request.method == 'POST':
-        size = request.form.get('size')
-        quantity = request.form.get('quantity')
-        remark = request.form.get('remark')
-        node_id = request.form.get('node_id')
-
-        payload = {
-            "size": int(size),
-            "quantity": int(quantity),
-            "remark": remark,
-            "node_id": node_id
-        }
-
-        url = host_url + '/api/disk'
-        headers = {'content-type': 'application/json'}
-        r = requests.post(url, data=json.dumps(payload), headers=headers, cookies=request.cookies)
-        j_r = json.loads(r.content)
-        return render_template('success.html', go_back_url='/disks', timeout=10000, title='提交成功',
-                               message_title='创建实例的请求已被接受',
-                               message='您所提交的资源正在创建中。根据所提交资源的数量,需要等待几到十几秒钟。页面将在10秒钟后自动跳转到实例列表页面!')
-
-    else:
-        config_url = host_url + url_for('api_config.r_get')
-        config_ret = requests.get(url=config_url, cookies=request.cookies)
-        config_ret = json.loads(config_ret.content)
-
-        show_on_host = False
-        if config_ret['data']['storage_mode'] == StorageMode.local.value:
-            show_on_host = True
-
-        return render_template('disk_create.html', show_on_host=show_on_host)
+    return render_template('disk_create.html')
 
 
 def detail(uuid):

+ 8 - 0
views/guest.py

@@ -68,3 +68,11 @@ def detail(uuid):
                            hosts_mapping_by_node_id=guest_detail_ret['data']['hosts_mapping_by_node_id'],
                            disks=guest_detail_ret['data']['disks'], config=guest_detail_ret['data']['config'])
 
+
+def create():
+        hosts_url = url_for('api_hosts.r_get_by_filter', alive=True, _external=True)
+        hosts_ret = requests.get(url=hosts_url, cookies=request.cookies)
+        hosts_ret = json.loads(hosts_ret.content)
+
+        return render_template('guest_create.html', hosts_ret=hosts_ret)
+

+ 1 - 0
views_route_table.py

@@ -32,6 +32,7 @@ add_rule_views(misc.blueprint, 'reset_password/<token>', views_func='misc.reset_
 add_rule_views(dashboard.blueprint, '', views_func='dashboard.show', methods=['GET'])
 
 add_rule_views(guest.blueprints, '', views_func='guest.show', methods=['GET'])
+add_rule_views(guest.blueprints, '/create', views_func='guest.create', methods=['GET'])
 add_rule_views(guest.blueprint, '/vnc/<uuid>', views_func='guest.vnc', methods=['GET'])
 add_rule_views(guest.blueprint, '/detail/<uuid>', views_func='guest.detail', methods=['GET'])