ソースを参照

add method to get all unused HDs of a VM

andre 4 年 前
コミット
9bfc892809
1 ファイル変更26 行追加0 行削除
  1. 26 0
      v2/models/Kvm.php

+ 26 - 0
v2/models/Kvm.php

@@ -264,6 +264,32 @@ class Kvm extends AbstractVm implements \MGProvision\Proxmox\v2\interfaces\KvmIn
         return $disks;
     }
 
+    /**
+     * @return HardDisk[]
+     */
+    public function getUnusedHardDisks()
+    {
+        $disks  = array();
+        $config = $this->config(true);
+        foreach ($config as $id => $value)
+        {
+            if (in_array($id, ['hotplug','agent']))
+            {
+                continue;
+            }
+            if(!preg_match("/unused/", $id)){
+                continue;
+            }
+            if (!preg_match('/disk/', $value))
+            {
+                continue;
+            }
+            $hdd = (new HardDisk($id, $value))->setPath("/nodes/{$this->node}/qemu/{$this->vmid}/config");
+            $disks[] = $hdd;
+        }
+        return $disks;
+    }
+
     /**
      * 
      * @return HardDisk