deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject git commit: CIMI: Adds database support for VolumeTemplate (create)
Date Thu, 10 Jan 2013 13:10:34 GMT
Updated Branches:
  refs/heads/master 04e3142cc -> 1773ecc93


CIMI: Adds database support for VolumeTemplate (create)


Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/1773ecc9
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/1773ecc9
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/1773ecc9

Branch: refs/heads/master
Commit: 1773ecc930216df0baa588a42ead7c7e94e76986
Parents: 04e3142
Author: marios <marios@redhat.com>
Authored: Thu Jan 10 12:28:09 2013 +0200
Committer: marios <marios@redhat.com>
Committed: Thu Jan 10 15:08:31 2013 +0200

----------------------------------------------------------------------
 server/lib/cimi/collections/volume_templates.rb |   69 +++++++++++++++++
 server/lib/cimi/models/volume_template.rb       |   71 ++++++++++++++++++
 server/lib/db.rb                                |    1 +
 server/lib/db/provider.rb                       |    5 +
 server/lib/db/volume_template.rb                |   12 +++
 5 files changed, 158 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/1773ecc9/server/lib/cimi/collections/volume_templates.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/collections/volume_templates.rb b/server/lib/cimi/collections/volume_templates.rb
new file mode 100644
index 0000000..6ba7a62
--- /dev/null
+++ b/server/lib/cimi/collections/volume_templates.rb
@@ -0,0 +1,69 @@
+# 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.
+
+module CIMI::Collections
+  class VolumeTemplates < Base
+
+    set :capability, lambda { |m| driver.respond_to? m }
+
+    collection :volume_templates do
+
+      operation :index, :with_capability => :storage_volumes do
+        description "Retrieve the Volume Template Collection"
+        control do
+          volume_template = VolumeTemplate.list(self).filter_by(params['$select'])
+          respond_to do |format|
+            format.xml { volume_template.to_xml }
+            format.json { volume_template.to_json }
+          end
+        end
+      end
+
+      operation :show, :with_capability => :storage_volume do
+        description "Get a specific VolumeTemplate"
+        control do
+          volume_template = VolumeTemplate.find(params[:id], self)
+          respond_to do |format|
+            format.xml { volume_template.to_xml }
+            format.json { volume_template.json }
+          end
+        end
+      end
+
+      operation :create, :with_capability => :create_storage_volume do
+        description "Create new VolumeTemplate"
+        control do
+          content_type = grab_content_type(request.content_type, request.body)
+          new_template = CIMI::Model::VolumeTemplate.create(request.body.read, self, content_type)
+          headers_for_create new_template
+          respond_to do |format|
+            format.json { new_template.to_json }
+            format.xml { new_template.to_xml }
+          end
+        end
+      end
+
+      operation :destroy, :with_capability => :destroy_storage_volume do
+        description "Delete a specified VolumeTemplate"
+        control do
+          CIMI::Model::VolumeTemplate.delete!(params[:id], self)
+          no_content_with_status(200)
+        end
+      end
+
+    end
+
+  end
+end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/1773ecc9/server/lib/cimi/models/volume_template.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/volume_template.rb b/server/lib/cimi/models/volume_template.rb
index b2ac323..f40a300 100644
--- a/server/lib/cimi/models/volume_template.rb
+++ b/server/lib/cimi/models/volume_template.rb
@@ -19,7 +19,78 @@ class CIMI::Model::VolumeTemplate < CIMI::Model::Base
 
   href :volume_config
   href :volume_image
+
+  array :meter_templates do
+  end
+
+  href :event_log_template
+
   array :operations do
     scalar :rel, :href
   end
+
+  def self.find(id, context)
+   if id==:all
+     if context.driver.respond_to? :volume_templates
+       context.driver.volume_templates(context.credentials, {:env=>context})
+     else
+       Deltacloud::Database::VolumeTemplate.all(
+         'provider.driver' => driver_symbol.to_s,
+         'provider.url' => current_provider
+       ).map { |t| from_db(t, context) }
+      end
+    else
+     if context.driver.respond_to? :volume_template
+       context.driver.volume_template(context.credentials, id, :env=>context)
+     else
+       template = Deltacloud::Database::VolumeTemplate.first(
+         'provider.driver' => driver_symbol.to_s,
+         'provider.url' => current_provider,
+         :id => id
+       )
+       raise CIMI::Model::NotFound unless template
+       from_db(template, context)
+     end
+    end
+  end
+
+  def self.create(body, context, type)
+    input = (type == :xml)? XmlSimple.xml_in(body, {"ForceArray"=>false,"NormaliseSpace"=>2})
: JSON.parse(body)
+    input['property'] ||= []
+    vol_image = input['volumeImage']['href'] if input['volumeImage']
+    new_template = current_db.volume_templates.new(
+      :name => input['name'],
+      :description => input['description'],
+      :volume_config => input['volumeConfig']['href'],
+      :volume_image => vol_image,
+      :ent_properties => input['property'].inject({}) { |r, p| r[p['key']]=p['content'];
r },
+      :be_kind => 'volume_template',
+      :be_id => ''
+    )
+    new_template.save!
+    from_db(new_template, context)
+  end
+
+  def self.delete!(id, context)
+    current_db.volume_templates.first(:id => id).destroy
+  end
+
+private
+
+  def self.from_db(model, context)
+    self.new(
+      :id => context.volume_template_url(model.id),
+      :name => model.name,
+      :description => model.description,
+      :volume_config => {:href => model.volume_config},
+      :volume_image => {:href => model.volume_image},
+      :property => model.ent_properties,
+      :operations => [
+        { :href => context.destroy_volume_template_url(model.id), :rel => 'http://schemas.dmtf.org/cimi/1/action/delete'
}
+      ]
+    )
+  end
+
+
+
 end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/1773ecc9/server/lib/db.rb
----------------------------------------------------------------------
diff --git a/server/lib/db.rb b/server/lib/db.rb
index f359664..567b356 100644
--- a/server/lib/db.rb
+++ b/server/lib/db.rb
@@ -11,6 +11,7 @@ module Deltacloud
     require_relative './db/machine_template'
     require_relative './db/address_template'
     require_relative './db/volume_configuration'
+    require_relative './db/volume_template'
   end
 
   DATABASE_LOCATION = ENV['DATABASE_LOCATION'] || File.join('/', 'var', 'tmp', "deltacloud-mock-#{ENV['USER']}",
'db.sqlite')

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/1773ecc9/server/lib/db/provider.rb
----------------------------------------------------------------------
diff --git a/server/lib/db/provider.rb b/server/lib/db/provider.rb
index 310d007..e8ca4f5 100644
--- a/server/lib/db/provider.rb
+++ b/server/lib/db/provider.rb
@@ -12,6 +12,7 @@ module Deltacloud
       has n, :machine_templates
       has n, :address_templates
       has n, :volume_configurations
+      has n, :volume_templates
 
       # This is a workaround for strange bug in Fedora MRI:
       #
@@ -27,6 +28,10 @@ module Deltacloud
         VolumeConfiguration.all(:provider_id => self.id)
       end
 
+      def volume_templates
+        VolumeTemplate.all(:provider_id => self.id)
+      end
+
       def entities
         Entity.all(:provider_id => self.id)
       end

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/1773ecc9/server/lib/db/volume_template.rb
----------------------------------------------------------------------
diff --git a/server/lib/db/volume_template.rb b/server/lib/db/volume_template.rb
new file mode 100644
index 0000000..8658b8b
--- /dev/null
+++ b/server/lib/db/volume_template.rb
@@ -0,0 +1,12 @@
+module Deltacloud
+  module Database
+
+    class VolumeTemplate < Entity
+      belongs_to :provider
+
+      property :volume_config, String
+      property :volume_image, String
+    end
+
+  end
+end


Mime
View raw message