incubator-deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@apache.org
Subject svn commit: r1154881 - in /incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rhevm: rhevm_client.rb rhevm_driver.rb
Date Mon, 08 Aug 2011 09:14:23 GMT
Author: mfojtik
Date: Mon Aug  8 09:14:23 2011
New Revision: 1154881

URL: http://svn.apache.org/viewvc?rev=1154881&view=rev
Log:
RHEVM: Added create_image from instance

Modified:
    incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rhevm/rhevm_client.rb
    incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb

Modified: incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rhevm/rhevm_client.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rhevm/rhevm_client.rb?rev=1154881&r1=1154880&r2=1154881&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rhevm/rhevm_client.rb (original)
+++ incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rhevm/rhevm_client.rb Mon Aug
 8 09:14:23 2011
@@ -74,6 +74,28 @@ module RHEVM
       RHEVM::VM::new(self, Nokogiri::XML(vm).root)
     end
 
+    def create_template(vm_id, opts={})
+      opts ||= {}
+      puts vm_id
+      puts opts.inspect
+      builder = Nokogiri::XML::Builder.new do
+        template_ {
+          name opts[:name]
+          description opts[:description]
+          vm(:id => vm_id)
+        }
+      end
+      headers = opts[:headers] || {}
+      headers.merge!({
+        :content_type => 'application/xml',
+        :accept => 'application/xml',
+      })
+      headers.merge!(auth_header)
+      template = RHEVM::client(@api_entrypoint)["/templates"].post(Nokogiri::XML(builder.to_xml).root.to_s,
headers)
+      puts template
+      RHEVM::Template::new(self, Nokogiri::XML(template).root)
+    end
+
     def templates(opts={})
       headers = {
         :accept => "application/xml"

Modified: incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb?rev=1154881&r1=1154880&r2=1154881&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb (original)
+++ incubator/deltacloud/trunk/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb Mon Aug
 8 09:14:23 2011
@@ -103,6 +103,20 @@ class RHEVMDriver < Deltacloud::BaseDriv
     img_arr.sort_by{|e| [e.owner_id, e.name]}
   end
 
+  def create_image(credentials, opts={})
+    client = new_client(credentials)
+    unless opts[:name]
+      instance = instances(credentials, :id => opts[:id])
+      raise "ERROR: Unknown instance ID"
+      template_name = "#{instance.first.name}-template"
+    end
+    safely do
+      new_image = client.create_template(opts[:id], :name => (opts[:name] || template_name),
+                                         :description => opts[:description])
+      convert_image(client, new_image)
+    end
+  end
+
   def instances(credentials, opts={})
     client = new_client(credentials)
     inst_arr = []
@@ -227,7 +241,8 @@ class RHEVMDriver < Deltacloud::BaseDriv
       :hardware_profile_id => profile.id,
       :actions=>instance_actions_for( state ),
       :public_addresses => public_addresses,
-      :private_addresses => []
+      :private_addresses => [],
+      :create_image => true
     )
   end
 
@@ -300,6 +315,10 @@ class RHEVMDriver < Deltacloud::BaseDriv
       status 500
     end
 
+    on /ERROR:(.*)/ do
+      status 500
+    end
+
     on /Parameter name/ do
       status 400
     end



Mime
View raw message