deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mandr...@redhat.com
Subject [PATCH] azure blob storage driver - very early prototype with basic functions
Date Tue, 24 Aug 2010 17:52:01 GMT
From: marios <marios@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


Mime
View raw message