OSDN Git Service

add validate network storage and storage pool "STOP" and "DELETE" method for guest...
authorkeisuke fukawa <keisuke@karesansui-project.info>
Tue, 27 Jul 2010 09:04:52 +0000 (18:04 +0900)
committerkeisuke fukawa <keisuke@karesansui-project.info>
Tue, 27 Jul 2010 09:04:52 +0000 (18:04 +0900)
karesansui/gadget/hostby1networkstorageby1status.py
karesansui/gadget/hostby1storagepoolby1.py
karesansui/gadget/hostby1storagepoolby1status.py
karesansui/lib/virt/virt.py

index 3e38f6f..738efc1 100644 (file)
@@ -148,6 +148,11 @@ class HostBy1NetworkStorageBy1Status(Rest):
                         if pool in inactive_pools:
                             inactive_used_pool.append(pool)
 
+            if status == NETWORK_STORAGE_STOP:
+                for pool in active_used_pool:
+                    if kvc.is_used_storage_pool(name=pool, active_only=True) is True:
+                        self.logger.debug("Stop iSCSI failed. Target iSCSI is used guest.")
+                        return web.badrequest("Target iSCSI is used guest.")
         finally:
             kvc.close()
 
index d36d349..f25030f 100644 (file)
@@ -138,6 +138,10 @@ class HostBy1StoragePoolBy1(Rest):
             pools_obj = kvc.get_storage_pool_UUIDString2kvn_storage_pool(uuid)
             if len(pools_obj) <= 0:
                 return web.notfound()
+
+            if kvc.is_used_storage_pool(pools_obj[0].get_storage_name()) is True:
+                self.logger.debug("Delete storage pool failed. Target storage pool is used guest.")
+                return web.badrequest("Target storage pool is used guest.")
         finally:
             kvc.close()
 
index db2c5f5..9875ed6 100644 (file)
@@ -126,7 +126,12 @@ class HostBy1StoragePoolBy1Status(Rest):
             if status == STORAGE_POOL_START:
                 storagepool_start_stop_job(self, model, pools_obj[0], 'start')
             elif status == STORAGE_POOL_STOP:
-                storagepool_start_stop_job(self, model, pools_obj[0], 'stop')
+                if kvc.is_used_storage_pool(name=pools_obj[0].get_storage_name(),
+                                            active_only=True) is True:
+                    self.logger.debug("Stop storage pool failed. Target storage pool is used guest.")
+                    return web.badrequest("Target storage pool is used guest.")
+                else:
+                    storagepool_start_stop_job(self, model, pools_obj[0], 'stop')
             else:
                 self.logger.debug("Set storage pool status failed. Unknown status type.")
                 return web.badrequest()
index e6ba868..b14b743 100644 (file)
@@ -2218,12 +2218,37 @@ class KaresansuiVirtConnection:
         mode = VIR_STORAGE_POOL_DELETE_NORMAL
         if flags is True:
             mode = VIR_STORAGE_POOL_DELETE_ZEROED
-            
+
         if self.storage_pool.delete(mode) == 0:
             return True
         else:
             return False
 
+    def is_used_storage_pool(self, name=None, active_only=False):
+        """
+        <comment-ja>
+        ストレージプールが現在利用されているか。
+        </comment-ja>
+        <comment-en>
+        TODO:
+        </comment-en>
+        """
+        if name is None:
+            return False
+
+        guests = self.list_active_guest()
+        if active_only is False:
+            guests += self.list_inactive_guest()
+
+        pools = []
+        for guest in guests:
+            pools += self.get_storage_pool_name_bydomain(guest)
+
+        if name in pools:
+            return True
+
+        return False
+
     def is_storage_volume(self, path):
         """<comment-ja>
         指定したパスがストレージボリュームに含まれているか。