You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by ma...@redhat.com on 2010/08/24 19:52:00 UTC

azure blob storage driver - very early prototype with basic functions

This patch implements a very early version of the Microsoft Azure Blob Storage driver (basically this is proof of concept) - this is our first 'pure storage' driver so the only collection exposed at /api is 'containers'. Currenly you can just list blobs and containers, create and delete containers (brings this driver in line with the current functionality of s3 and cloudfiles drivers). Again, this is for comments and once all the blob work is finished I will resubmit a patch series with all changes included. 

I am using the 'waz-storage' gem to talk to azure (http://github.com/johnnyhalife/waz-storage). I also had to update the 'rest-client' gem to make this work properly - I had v.1.4.2 (our current gemspec has dependency for >= 1.4.2) but did 'sudo gem install rest-client' and got v.1.6.0.

Re: [PATCH] azure blob storage driver - very early prototype with basic functions

Posted by David Lutterkort <lu...@redhat.com>.
On Tue, 2010-08-24 at 18:52 +0100, mandreou@redhat.com wrote:
> diff --git a/server/lib/deltacloud/drivers/azure/azure_driver.rb b/server/lib/deltacloud/drivers/azure/azure_driver.rb
> new file mode 100644
> index 0000000..780e278
> --- /dev/null
> +++ b/server/lib/deltacloud/drivers/azure/azure_driver.rb
> @@ -0,0 +1,105 @@
>
> +#Windows Azure (WAZ) gem at http://github.com/johnnyhalife/waz-storage
> +require 'waz-blobs'
> +require 'deltacloud/base_driver'
> +module Deltacloud
> +  module Drivers
> +    module Azure
> +
> +class AzureDriver < Deltacloud::BaseDriver
> +
> +  def supported_collections
> +    DEFAULT_COLLECTIONS.reject! { |c| [:hardware_profiles, :images, :instances, :instance_states,
> +                                      :realms, :storage_volumes, :storage_snapshots  ].include?(c) }
> +    DEFAULT_COLLECTIONS + [:containers]
> +  end

Could just do 'def supported_collections; [:containers] end' here ;)

> +  def blobs(credentials, opts)
> +    blob_list = []
> +    unless opts['container'] then
> +      raise Deltacloud::Validation::Failure.new(Deltacloud::Validation::Param.new(["container"]), "Error - need container name to retrieve the blob list. You said container->#{opts['container']}.")
> +    end

Shouldn't this be handled by the declaration of containers in
server.rb ? In particular, since :container is part of the URL, this
method would never be called if it's not there.

Other than that, looks great.

David



[PATCH] azure blob storage driver - very early prototype with basic functions

Posted by ma...@redhat.com.
From: marios <ma...@redhat.com>

---
 .../lib/deltacloud/drivers/azure/azure_driver.rb   |  105 ++++++++++++++++++++
 server/lib/drivers.rb                              |    1 +
 2 files changed, 106 insertions(+), 0 deletions(-)
 create mode 100644 server/lib/deltacloud/drivers/azure/azure_driver.rb

diff --git a/server/lib/deltacloud/drivers/azure/azure_driver.rb b/server/lib/deltacloud/drivers/azure/azure_driver.rb
new file mode 100644
index 0000000..780e278
--- /dev/null
+++ b/server/lib/deltacloud/drivers/azure/azure_driver.rb
@@ -0,0 +1,105 @@
+#
+# Copyright (C) 2010  Red Hat, Inc.
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.  The
+# ASF licenses this file to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance with the
+# License.  You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+#Windows Azure (WAZ) gem at http://github.com/johnnyhalife/waz-storage
+require 'waz-blobs'
+require 'deltacloud/base_driver'
+module Deltacloud
+  module Drivers
+    module Azure
+
+class AzureDriver < Deltacloud::BaseDriver
+
+  def supported_collections
+    DEFAULT_COLLECTIONS.reject! { |c| [:hardware_profiles, :images, :instances, :instance_states,
+                                      :realms, :storage_volumes, :storage_snapshots  ].include?(c) }
+    DEFAULT_COLLECTIONS + [:containers]
+  end
+
+  def containers(credentials, opts)
+    containers = []
+    azure_connect(credentials)
+    WAZ::Blobs::Container.list.each do |waz_container|
+      containers << convert_container(waz_container)
+    end
+    containers = filter_on(containers, :id, opts)
+  end
+
+  def create_container(credentials, name, opts)
+    container = nil
+    azure_connect(credentials)
+    waz_container = WAZ::Blobs::Container.create(name)
+    container = convert_container(waz_container)
+    container
+  end
+
+  def delete_container(credentials, name, opts)
+    azure_connect(credentials)
+    WAZ::Blobs::Container.find(name).destroy!
+  end
+  
+  def blobs(credentials, opts)
+    blob_list = []
+    unless opts['container'] then
+      raise Deltacloud::Validation::Failure.new(Deltacloud::Validation::Param.new(["container"]), "Error - need container name to retrieve the blob list. You said container->#{opts['container']}.")
+    end
+    azure_connect(credentials)
+    the_container = WAZ::Blobs::Container.find(opts['container'])
+    the_container.blobs.each do |waz_blob|
+      blob_list << convert_blob(waz_blob)
+    end
+    blob_list = filter_on(blob_list, :id, opts)
+    blob_list
+  end
+  
+  private
+  
+  def azure_connect(credentials)
+    options = {:account_name => credentials.user, :access_key => credentials.password}
+    WAZ::Storage::Base.establish_connection!(options)
+  end
+
+  def convert_container(waz_container)
+    blob_list = []
+    waz_container.blobs.each do |blob|
+      blob_list << blob.name
+    end
+    Container.new({ :id => waz_container.name, 
+                    :name => waz_container.name,
+                    :size => blob_list.size,
+                    :blob_list => blob_list
+                  })  
+  end
+
+  def convert_blob(waz_blob)
+    url = waz_blob.url.split('/')
+    container = url[url.length-2] #FIXME
+    Blob.new({   :id => waz_blob.name,
+                 :container => container,
+                 :content_length => waz_blob.metadata[:content_length],
+                 :content_type => waz_blob.metadata[:content_type],
+                 :last_modified => waz_blob.metadata[:last_modified]
+              })
+  end
+
+
+end
+
+    end #module Azure
+  end #module Drivers
+end #module Deltacloud
diff --git a/server/lib/drivers.rb b/server/lib/drivers.rb
index 261e0c8..6e31bb7 100644
--- a/server/lib/drivers.rb
+++ b/server/lib/drivers.rb
@@ -6,6 +6,7 @@ DRIVERS = {
   :rimuhosting => { :name => "RimuHosting"},
   :opennebula => { :name => "Opennebula", :class => "OpennebulaDriver" },
   :terremark => { :name => "Terremark"},
+  :azure => { :name => "Azure" },
   :mock => { :name => "Mock" }
 }
 
-- 
1.7.2.1