deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@redhat.com
Subject [PATCH core] Core: Added user_name and user_description feature for images collection (DTACLOUD-122)
Date Fri, 09 Mar 2012 17:51:05 GMT
From: Michal Fojtik <mfojtik@redhat.com>

Previously all drivers that support creating images from instances
automatically accepted :name and :description parameters.
However in VSphere those parameters are ignored and resulting image
inherits name and description for instance used for creation.

This patch add two new features for :images collection, that
are set for all drivers that support image creation except VSphere.

Signed-off-by: Michal fojtik <mfojtik@redhat.com>
---
 server/lib/deltacloud/base_driver/features.rb      |   14 ++++++++++++++
 server/lib/deltacloud/drivers/ec2/ec2_driver.rb    |    2 ++
 server/lib/deltacloud/drivers/mock/mock_driver.rb  |    2 ++
 .../drivers/openstack/openstack_driver.rb          |    1 +
 .../drivers/rackspace/rackspace_driver.rb          |    5 +++--
 .../lib/deltacloud/drivers/rhevm/rhevm_driver.rb   |    3 ++-
 .../deltacloud/drivers/vsphere/vsphere_driver.rb   |    1 -
 server/lib/deltacloud/server.rb                    |    8 +++-----
 8 files changed, 27 insertions(+), 9 deletions(-)

diff --git a/server/lib/deltacloud/base_driver/features.rb b/server/lib/deltacloud/base_driver/features.rb
index af1a9c5..37e5ef0 100644
--- a/server/lib/deltacloud/base_driver/features.rb
+++ b/server/lib/deltacloud/base_driver/features.rb
@@ -160,6 +160,20 @@ module Deltacloud
       end
     end
 
+    declare_feature :images,  :user_name do
+      description "Allow specifying user name for created image"
+      operation :create do
+        param :name,  :string,  :optional,  [],  "Image name"
+      end
+    end
+
+    declare_feature :images,  :user_description do
+      description "Allow specifying user description for created image"
+      operation :create do
+        param :description, :string,  :optional,  [],  "Image description"
+      end
+    end
+
     declare_feature :instances, :user_name do
       description "Accept a user-defined name on instance creation"
       operation :create do
diff --git a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
index 52e91c2..e718971 100644
--- a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
+++ b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
@@ -42,6 +42,8 @@ module Deltacloud
         feature :instances, :firewalls
         feature :instances, :instance_count
         feature :images, :owner_id
+        feature :images, :user_name
+        feature :images, :user_description
         feature :buckets, :bucket_location
         feature :instances, :attach_snapshot
 
diff --git a/server/lib/deltacloud/drivers/mock/mock_driver.rb b/server/lib/deltacloud/drivers/mock/mock_driver.rb
index 765338d..ce77fe2 100644
--- a/server/lib/deltacloud/drivers/mock/mock_driver.rb
+++ b/server/lib/deltacloud/drivers/mock/mock_driver.rb
@@ -87,6 +87,8 @@ module Deltacloud::Drivers::Mock
     feature :instances, :user_name
     feature :instances, :user_data
     feature :instances, :authentication_key
+    feature :images, :user_name
+    feature :images, :user_description
 
     def initialize
       if ENV["DELTACLOUD_MOCK_STORAGE"]
diff --git a/server/lib/deltacloud/drivers/openstack/openstack_driver.rb b/server/lib/deltacloud/drivers/openstack/openstack_driver.rb
index 845ddee..82a2b07 100644
--- a/server/lib/deltacloud/drivers/openstack/openstack_driver.rb
+++ b/server/lib/deltacloud/drivers/openstack/openstack_driver.rb
@@ -25,6 +25,7 @@ module Deltacloud
         feature :instances, :user_name
         feature :instances, :authentication_password
         feature :instances, :user_files
+        feature :images, :user_name
 
         def supported_collections
           DEFAULT_COLLECTIONS - [ :storage_snapshots, :storage_volumes  ] #+ [ :buckets ]
diff --git a/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb b/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb
index 3779c41..feaa646 100644
--- a/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb
+++ b/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb
@@ -28,6 +28,7 @@ class RackspaceDriver < Deltacloud::BaseDriver
   feature :instances, :user_name
   feature :instances, :authentication_password
   feature :instances, :user_files
+  feature :images, :user_name
 
   def supported_collections
     DEFAULT_COLLECTIONS + [ :buckets ] - [ :storage_snapshots, :storage_volumes ]
@@ -100,8 +101,8 @@ class RackspaceDriver < Deltacloud::BaseDriver
       image = server.create_image(opts[:name])
       Image.new(
         :id => image.id.to_s,
-        :name => image.name,
-        :description => image.name,
+        :name => opts[:name] || image.name,
+        :description => opts[:description] || image.description,
         :owner_id => credentials.user,
         :state => image.status,
         :architecture => 'x86_64'
diff --git a/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb b/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb
index b350071..ac4fe72 100644
--- a/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb
+++ b/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb
@@ -32,6 +32,7 @@ class RHEVMDriver < Deltacloud::BaseDriver
   end
 
   feature :instances, :user_data
+  feature :images, :user_name
 
   USER_NAME_MAX = feature(:instances, :user_name).constraints[:max_length]
 
@@ -110,7 +111,7 @@ class RHEVMDriver < Deltacloud::BaseDriver
     end
     safely do
       new_image = client.create_template(opts[:id], :name => (opts[:name] || template_name),
-                                         :description => opts[:description])
+                                         :description => opts[:description] || template_name)
       convert_image(client, new_image)
     end
   end
diff --git a/server/lib/deltacloud/drivers/vsphere/vsphere_driver.rb b/server/lib/deltacloud/drivers/vsphere/vsphere_driver.rb
index f3aeaa5..cbcaa22 100644
--- a/server/lib/deltacloud/drivers/vsphere/vsphere_driver.rb
+++ b/server/lib/deltacloud/drivers/vsphere/vsphere_driver.rb
@@ -34,7 +34,6 @@ module Deltacloud::Drivers::VSphere
     feature :instances, :user_data
     feature :instances, :user_name
 
-
     def supported_collections
       DEFAULT_COLLECTIONS - [:storage_volumes, :storage_snapshots]
     end
diff --git a/server/lib/deltacloud/server.rb b/server/lib/deltacloud/server.rb
index 5ef3cb0..53dd705 100644
--- a/server/lib/deltacloud/server.rb
+++ b/server/lib/deltacloud/server.rb
@@ -249,14 +249,12 @@ END
   operation :create do
     description 'Create image from instance'
     with_capability :create_image
-    param :instance_id,	 :string, :required
-    param :name,	 :string, :optional
-    param :description,	 :string, :optional
+    param :instance_id, :string, :required
     control do
       @image = driver.create_image(credentials, {
-	:id => params[:instance_id],
+        :id => params[:instance_id],
         :name => params[:name],
-	:description => params[:description]
+        :description => params[:description]
       })
       status 201  # Created
       response['Location'] = image_url(@image.id)
-- 
1.7.9.1


Mime
View raw message