[Ovirt-devel] [PATCH client 10/11] remove individual volumes from a storage pool or an entire storage pool

David Lutterkort lutter at redhat.com
Mon Jan 26 21:20:40 UTC 2009


---
 bin/ovirt                    |   25 +++++++++++++++++++++++++
 lib/ovirt/command/storage.rb |   34 ++++++++++++++++++++++++++++++++++
 2 files changed, 59 insertions(+), 0 deletions(-)

diff --git a/bin/ovirt b/bin/ovirt
index 42b7871..8c0bfcf 100755
--- a/bin/ovirt
+++ b/bin/ovirt
@@ -73,6 +73,31 @@ DESCR
       include OVirt::Command::Storage::List
       mixin :command
     end
+
+    mode 'rm' do
+      option("pool=POOL", "p") {
+        description "the ID of the pool"
+        required
+        cast :int
+      }
+      # --all, --volume and --self are mutually exclusive
+
+      # We identify storage pools and volumes by their ID
+      # - it would be much nicer if we had some sort of label
+      # for each, but that requires we change the WUI
+      option("all", "a") {
+        description "delete all volumes from the pool"
+      }
+      option("volume=VOLUME", "v") {
+        description "delete the volume with the given id"
+        cast :int
+      }
+      option("self") {
+        description "delete the pool itself and all its volumes"
+      }
+      include OVirt::Command::Storage::Remove
+      mixin :command
+    end
   end
 
   def run
diff --git a/lib/ovirt/command/storage.rb b/lib/ovirt/command/storage.rb
index 85577e9..7cbf78a 100644
--- a/lib/ovirt/command/storage.rb
+++ b/lib/ovirt/command/storage.rb
@@ -28,4 +28,38 @@ module OVirt::Command::Storage
     end
   end
 
+  module Remove
+    def execute(args)
+      pool, volume, slf, all = args.values_at 'pool', 'volume', 'self', 'all'
+
+      begin
+        pool = OVirt::StoragePool::find(pool)
+      rescue ActiveResource::ResourceNotFound
+        puts_error "error: pool #{pool} not found"
+        return
+      end
+
+      begin
+        if volume
+          vol = pool.storage_volumes.find { |vol| vol.id == volume }
+          if vol
+            vol.destroy
+          else
+            $stderr.puts "error: no volume #{volume} in pool #{pool.label}"
+            exit_status exit_failure
+          end
+        elsif all
+          pool.storage_volumes.each { |vol| vol.destroy }
+        elsif slf
+          pool.destroy
+        else
+          $stderr.puts "error: you must specify one of --volume, --all, or --self"
+          exit_status exit_failure
+        end
+      rescue ActiveResource::ForbiddenAccess => e
+        $stderr.puts OVirt::format_remote_exception("Removal denied", e)
+        exit_status exit_failure
+      end
+    end
+  end
 end
-- 
1.6.0.6




More information about the ovirt-devel mailing list