You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by fe...@gmail.com on 2011/03/21 21:06:57 UTC

[PATCH] - Added the basic feature of create storage volumes at mock driver

From: Felipe Cardoso Martins <fe...@gmail.com>

---
 server/lib/deltacloud/drivers/mock/mock_driver.rb |   38 +++++++++++++++++++++
 1 files changed, 38 insertions(+), 0 deletions(-)

diff --git a/server/lib/deltacloud/drivers/mock/mock_driver.rb b/server/lib/deltacloud/drivers/mock/mock_driver.rb
index 7d229c4..b18b5c9 100644
--- a/server/lib/deltacloud/drivers/mock/mock_driver.rb
+++ b/server/lib/deltacloud/drivers/mock/mock_driver.rb
@@ -282,6 +282,44 @@ class MockDriver < Deltacloud::BaseDriver
     volumes
   end
 
+  def create_storage_volume(credentials, opts=nil)
+    check_credentials(credentials)
+
+    ids = Dir[ "#{@storage_root}/storage_volumes/*.yml" ].collect{|e| File.basename( e, ".yml" )}
+
+    count = 0 
+    while true
+      next_id = "vol" + count.to_s
+      if not ids.include?(next_id)
+        break
+      end 
+      count = count + 1 
+    end 
+
+    opts ||= {}
+    opts[:capacity] ||= "1"
+    opts[:realm_id] ||= realms(credentials).first.id
+
+    volume = {
+      :owner_id => credentials.user,
+      :created => Time.now,
+      :state => 'AVAILABLE',
+      :capacity => opts[:capacity],
+      :realm_id => opts[:realm_id],
+      :device => '',
+      :instance_id => '',
+      :actions => [:attach, :detach, :destroy]
+     }
+
+     File.open( "#{@storage_root}/storage_volumes/#{next_id}.yml", 'w' ) {|f|
+       YAML.dump( volume, f ) 
+     }
+
+     volume[:id] = next_id
+
+     StorageVolume.new( volume )
+  end
+
   #
   # Storage Snapshots
   #
-- 
1.7.1


Re: [PATCH] - Added the basic feature of create storage volumes at mock driver

Posted by Michal Fojtik <mf...@redhat.com>.
On Mar 21, 2011, at 9:06 PM, felipe.cardoso.martins@gmail.com wrote:

> From: Felipe Cardoso Martins <fe...@gmail.com>
> 
> ---
> server/lib/deltacloud/drivers/mock/mock_driver.rb |   38 +++++++++++++++++++++
> 1 files changed, 38 insertions(+), 0 deletions(-)
> 
> diff --git a/server/lib/deltacloud/drivers/mock/mock_driver.rb b/server/lib/deltacloud/drivers/mock/mock_driver.rb
> index 7d229c4..b18b5c9 100644
> --- a/server/lib/deltacloud/drivers/mock/mock_driver.rb
> +++ b/server/lib/deltacloud/drivers/mock/mock_driver.rb
> @@ -282,6 +282,44 @@ class MockDriver < Deltacloud::BaseDriver
>     volumes
>   end
> 
> +  def create_storage_volume(credentials, opts=nil)
> +    check_credentials(credentials)
> +
> +    ids = Dir[ "#{@storage_root}/storage_volumes/*.yml" ].collect{|e| File.basename( e, ".yml" )}
> +
> +    count = 0 
> +    while true
> +      next_id = "vol" + count.to_s
> +      if not ids.include?(next_id)
> +        break
> +      end 
> +      count = count + 1 
> +    end 
> +
> +    opts ||= {}
> +    opts[:capacity] ||= "1"
> +    opts[:realm_id] ||= realms(credentials).first.id
> +
> +    volume = {
> +      :owner_id => credentials.user,
> +      :created => Time.now,
> +      :state => 'AVAILABLE',
> +      :capacity => opts[:capacity],
> +      :realm_id => opts[:realm_id],
> +      :device => '',
> +      :instance_id => '',
> +      :actions => [:attach, :detach, :destroy]
> +     }
> +
> +     File.open( "#{@storage_root}/storage_volumes/#{next_id}.yml", 'w' ) {|f|
> +       YAML.dump( volume, f ) 
> +     }
> +
> +     volume[:id] = next_id
> +
> +     StorageVolume.new( volume )
> +  end
> +

ACK. It work's for me.
Btw. Did you have send CLA signed and scanned as PDF document to secretary@apache.org?
Once you will do this, I'll commit this patch to SVN.

  -- Michal

>   #
>   # Storage Snapshots
>   #
> -- 
> 1.7.1
> 

------------------------------------------------------
Michal Fojtik, mfojtik@redhat.com
Deltacloud API: http://deltacloud.org