Procházet zdrojové kódy

虚拟机磁盘限额支持更新操作

James Iter před 8 roky
rodič
revize
f871b99d16
3 změnil soubory, kde provedl 48 přidání a 12 odebrání
  1. binární
      .DS_Store
  2. 44 12
      api/disk.py
  3. 4 0
      models/rules.py

binární
.DS_Store


+ 44 - 12
api/disk.py

@@ -285,6 +285,16 @@ def r_update(uuids):
             Rules.IOPS.value
         )
 
+    if 'iops_rd' in request.json:
+        args_rules.append(
+            Rules.IOPS_RD.value
+        )
+
+    if 'iops_wr' in request.json:
+        args_rules.append(
+            Rules.IOPS_WR.value
+        )
+
     if 'iops_max' in request.json:
         args_rules.append(
             Rules.IOPS_MAX.value
@@ -300,6 +310,16 @@ def r_update(uuids):
             Rules.BPS.value
         )
 
+    if 'bps_rd' in request.json:
+        args_rules.append(
+            Rules.BPS_RD.value
+        )
+
+    if 'bps_wr' in request.json:
+        args_rules.append(
+            Rules.BPS_WR.value
+        )
+
     if 'bps_max' in request.json:
         args_rules.append(
             Rules.BPS_MAX.value
@@ -315,6 +335,13 @@ def r_update(uuids):
 
     request.json['uuids'] = uuids
 
+    need_update_quota = False
+    need_update_quota_parameters = ['iops', 'iops_rd', 'iops_wr', 'iops_max', 'iops_max_length',
+                                    'bps', 'bps_rd', 'bps_wr', 'bps_max', 'bps_max_length']
+
+    if filter(lambda p: p in request.json, need_update_quota_parameters).__len__() > 0:
+        need_update_quota = True
+
     try:
         ji.Check.previewing(args_rules, request.json)
 
@@ -342,23 +369,28 @@ def r_update(uuids):
             disk.update()
             disk.get()
 
-            if disk.sequence >= 0:
+            if disk.sequence >= 0 and need_update_quota:
                 message = {
                     '_object': 'disk',
                     'action': 'quota',
+                    'uuid': disk.uuid,
                     'guest_uuid': disk.guest_uuid,
                     'hostname': disk.on_host,
-                    'sequence': disk.sequence,
-                    'iops': disk.iops,
-                    'iops_rd': disk.iops_rd,
-                    'iops_wr': disk.iops_wr,
-                    'iops_max': disk.iops_max,
-                    'iops_max_length': disk.iops_max_length,
-                    'bps': disk.bps,
-                    'bps_rd': disk.bps_rd,
-                    'bps_wr': disk.bps_wr,
-                    'bps_max': disk.bps_max,
-                    'bps_max_length': disk.bps_max_length
+                    'disks': [
+                        {
+                            'sequence': disk.sequence,
+                            'iops': disk.iops,
+                            'iops_rd': disk.iops_rd,
+                            'iops_wr': disk.iops_wr,
+                            'iops_max': disk.iops_max,
+                            'iops_max_length': disk.iops_max_length,
+                            'bps': disk.bps,
+                            'bps_rd': disk.bps_rd,
+                            'bps_wr': disk.bps_wr,
+                            'bps_max': disk.bps_max,
+                            'bps_max_length': disk.bps_max_length
+                        }
+                    ]
                 }
 
                 Guest.emit_instruction(message=json.dumps(message))

+ 4 - 0
models/rules.py

@@ -75,7 +75,11 @@ class Rules(Enum):
     DISK_SIZE_STR = (REG_NUMBER, 'size')
     DISK_ON_HOST = (basestring, 'on_host', (1, 128))
     IOPS = (int, 'iops')
+    IOPS_RD = (int, 'iops_rd')
+    IOPS_WR = (int, 'iops_wr')
     BPS = (int, 'bps')
+    BPS_RD = (int, 'bps_rd')
+    BPS_WR = (int, 'bps_wr')
 
     REMARK = (basestring, 'remark')
     USE_FOR = (int, 'use_for')