瀏覽代碼

修正带宽限制,tc可控最大值问题

James Iter 8 年之前
父節點
當前提交
2ab6a66251
共有 3 個文件被更改,包括 34 次插入5 次删除
  1. 12 0
      api/guest.py
  2. 3 2
      docs/todo.md
  3. 19 3
      static/utils.js

+ 12 - 0
api/guest.py

@@ -158,6 +158,12 @@ def r_create():
             ret['state'] = ji.Common.exchange_state(41203)
             raise ji.PreviewingError(json.dumps(ret, ensure_ascii=False))
 
+        # http://man7.org/linux/man-pages/man8/tc.8.html
+        # 如果带宽大于 tc 所控最大速率,则置其为无限带宽
+        # 34359738360 等于 tc 最大可控字节速率,换算出的比特位
+        if bandwidth > 34359738360:
+            bandwidth = 0
+
         quantity = request.json.get('quantity')
 
         while quantity:
@@ -1141,6 +1147,12 @@ def r_allocate_bandwidth(uuids, bandwidth, bandwidth_unit):
             ret['state'] = ji.Common.exchange_state(41203)
             raise ji.PreviewingError(json.dumps(ret, ensure_ascii=False))
 
+        # http://man7.org/linux/man-pages/man8/tc.8.html
+        # 如果带宽大于 tc 所控最大速率,则置其为无限带宽
+        # 34359738360 等于 tc 最大可控字节速率,换算出的比特位
+        if bandwidth > 34359738360:
+            bandwidth = 0
+
         guest = Guest()
 
         # 检测所指定的 UUDIs 实例都存在

+ 3 - 2
docs/todo.md

@@ -54,6 +54,7 @@
 - [x] 取消单独的初始化密码操作,合并入具体的操作系统初始化操作中
 - [x] 修复 Guest 对模板对象的依赖。bug 表现为,当依赖的模板项被删除后,虚拟机实例列表会出现 500 错误
 - [x] 实现网络流量限速
+- [x] 根据计算节点 CPU 是否支持 VT-X,来确定虚拟机是使用 KVM 还是 QEMU
 - [ ] 考虑开辟一个单独的消息处理线程。所有业务消息都塞到进程中的队列内,由该线程统一处理。这样可以更好的处理数据库重连问题。
 - [ ] 实现 CentOS 7 单机版一建安装脚本(包括全新的数据库安装、配置、部署)
 - [ ] 实现磁盘联动机制。即当删除宿主机时,相随的所有磁盘一并删除
@@ -82,8 +83,8 @@
 - [ ] 通过 QemuGuestAgent 实现 Guest 的内存使用率监控
 - [ ] 实现通过 JimV-C 修改主机名(当前为备注的地方),同步到具体 Guest 上
 - [ ] 修正创建虚拟机时,VNC 端口不够用时的 bug。创建失败时,需要返还对应的 IP 与 VNC 端口资源
-- [ ] 根据计算节点 CPU 是否支持 VT-X,来确定虚拟机是使用 KVM 还是 QEMU
 - [ ] 修复在大磁盘虚拟机创建快照时,等待时间过长的问题
 - [ ] IP 地址池管理功能。对 IP 池中的 IP 有查看、添加、禁用、解禁等功能
-- [ ] 安装脚本加入中国本土仓库
+- [x] 安装脚本加入中国本土仓库
+- [ ] 对某个 Guest 进行快照操作时,禁止对该镜像做其它快照方面的操作
 

+ 19 - 3
static/utils.js

@@ -119,6 +119,17 @@ RandomPassword.prototype.trim = function(s) {
 };
 
 function render_bandwidth_slider(bandwidth_slider ,action, bandwidth_unit) {
+    var values_with_gbps = [
+        0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
+        11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
+        21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
+        31, 32, 33, 34, 35
+    ];
+    var values_p_with_gbps = [
+        0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
+        11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
+        21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
+        31, 32, 33, 34, '∞'];
 
     if (action === 'create') {
         bandwidth_slider.ionRangeSlider({
@@ -138,14 +149,19 @@ function render_bandwidth_slider(bandwidth_slider ,action, bandwidth_unit) {
         if (bandwidth_unit === 'g') {
             bandwitdh_slider_instance.update({
                 min: 0,
-                max: 100,
+                max: 35,
                 from: 1,
                 from_min: 1,
-                from_max: 100,
+                from_max: 35,
                 step: 1,
                 grid: true,
-                grid_num: 10,
+                grid_num: 7,
                 postfix: ' Gbps'
+                // values: values_with_gbps,
+                // prettify: function (n) {
+                //     var ind = values_with_gbps.indexOf(n);
+                //     return values_p_with_gbps[ind];
+                // }
             });
 
         } else if (bandwidth_unit === 'm') {