Sfoglia il codice sorgente

disk api 接口返回,加入 device 字段;加入v0.1升级到v0.2所需的数据库更新脚本。

James Iter 8 anni fa
parent
commit
8e388e95b3
2 ha cambiato i file con 75 aggiunte e 0 eliminazioni
  1. 25 0
      api/disk.py
  2. 50 0
      misc/v0.1_to_v0.2/update.sql

+ 25 - 0
api/disk.py

@@ -224,17 +224,42 @@ def r_delete(uuids):
         return json.loads(e.message)
 
 
+def add_device(func):
+    from functools import wraps
+
+    @wraps(func)
+    def _add_device(*args, **kwargs):
+        ret = func(*args, **kwargs)
+        if ret['data'].__len__() > 0:
+            if isinstance(ret['data'], list):
+                for i, item in enumerate(ret['data']):
+                    ret['data'][i][u'device'] = u'/dev/' + dev_table[item['sequence']]
+
+            elif isinstance(ret['data'], dict):
+                ret['data'][u'device'] = u'/dev/' + dev_table[ret['data']['sequence']]
+
+            else:
+                raise json.dumps(ret)
+
+        return ret
+
+    return _add_device
+
+
 @Utils.dumps2response
+@add_device
 def r_get(uuids):
     return disk_base.get(ids=uuids, ids_rule=Rules.UUIDS.value, by_field='uuid')
 
 
 @Utils.dumps2response
+@add_device
 def r_get_by_filter():
     return disk_base.get_by_filter()
 
 
 @Utils.dumps2response
+@add_device
 def r_content_search():
     return disk_base.content_search()
 

+ 50 - 0
misc/v0.1_to_v0.2/update.sql

@@ -0,0 +1,50 @@
+
+ALTER TABLE config ADD COLUMN iops_base BIGINT UNSIGNED NOT NULL DEFAULT 0;
+ALTER TABLE config ADD COLUMN iops_pre_unit BIGINT UNSIGNED NOT NULL DEFAULT 0;
+ALTER TABLE config ADD COLUMN iops_cap BIGINT UNSIGNED NOT NULL DEFAULT 0;
+ALTER TABLE config ADD COLUMN iops_max BIGINT UNSIGNED NOT NULL DEFAULT 0;
+ALTER TABLE config ADD COLUMN iops_max_length BIGINT UNSIGNED NOT NULL DEFAULT 0;
+ALTER TABLE config ADD COLUMN bps_base BIGINT UNSIGNED NOT NULL DEFAULT 0;
+ALTER TABLE config ADD COLUMN bps_pre_unit BIGINT UNSIGNED NOT NULL DEFAULT 0;
+ALTER TABLE config ADD COLUMN bps_cap BIGINT UNSIGNED NOT NULL DEFAULT 0;
+ALTER TABLE config ADD COLUMN bps_max BIGINT UNSIGNED NOT NULL DEFAULT 0;
+ALTER TABLE config ADD COLUMN bps_max_length BIGINT UNSIGNED NOT NULL DEFAULT 0;
+
+ALTER TABLE disk ADD COLUMN iops BIGINT UNSIGNED NOT NULL DEFAULT 0;
+ALTER TABLE disk ADD COLUMN iops_rd BIGINT UNSIGNED NOT NULL DEFAULT 0;
+ALTER TABLE disk ADD COLUMN iops_wr BIGINT UNSIGNED NOT NULL DEFAULT 0;
+ALTER TABLE disk ADD COLUMN iops_max BIGINT UNSIGNED NOT NULL DEFAULT 0;
+ALTER TABLE disk ADD COLUMN iops_max_length BIGINT UNSIGNED NOT NULL DEFAULT 0;
+ALTER TABLE disk ADD COLUMN bps BIGINT UNSIGNED NOT NULL DEFAULT 0;
+ALTER TABLE disk ADD COLUMN bps_rd BIGINT UNSIGNED NOT NULL DEFAULT 0;
+ALTER TABLE disk ADD COLUMN bps_wr BIGINT UNSIGNED NOT NULL DEFAULT 0;
+ALTER TABLE disk ADD COLUMN bps_max BIGINT UNSIGNED NOT NULL DEFAULT 0;
+ALTER TABLE disk ADD COLUMN bps_max_length BIGINT UNSIGNED NOT NULL DEFAULT 0;
+
+-- 初始化 config 表中的磁盘限额参数;
+UPDATE config SET iops_base=1000, iops_pre_unit=1, iops_cap=2000, iops_max=3000, iops_max_length=20,
+    bps_base=1024 * 1024 * 200, bps_pre_unit=1024 * 1024 * 0.3, bps_cap=1024 * 1024 * 500, bps_max=1024 * 1024 * 1024,
+    bps_max_length=10;
+
+-- 更新虚拟机系统盘磁盘性能限额;
+UPDATE disk, config SET
+    disk.iops=config.iops_base, disk.iops_max=config.iops_max, disk.iops_max_length=config.iops_max_length,
+    disk.bps=config.bps_base, disk.bps_max=config.bps_max, disk.bps_max_length=config.bps_max_length
+WHERE disk.sequence=0 AND config.id=1;
+
+-- 更新小于满额的非系统盘磁盘性能限额;
+UPDATE disk, config SET
+    disk.iops=config.iops_base + config.iops_pre_unit * disk.size,
+    disk.iops_max=config.iops_max, disk.iops_max_length=config.iops_max_length,
+    disk.bps=config.bps_base + config.bps_pre_unit * disk.size,
+    disk.bps_max=config.bps_max, disk.bps_max_length=config.bps_max_length
+WHERE disk.sequence!=0 AND disk.size<=1000 AND config.id=1;
+
+-- 更新超出满额的非系统盘磁盘性能限额;
+UPDATE disk, config SET
+    disk.iops=config.iops_cap,
+    disk.iops_max=config.iops_max, disk.iops_max_length=config.iops_max_length,
+    disk.bps=config.bps_cap,
+    disk.bps_max=config.bps_max, disk.bps_max_length=config.bps_max_length
+WHERE disk.sequence!=0 AND disk.size>1000 AND config.id=1;
+