From: Michal Fojtik <[email protected]>
---
server/lib/deltacloud/drivers/ec2/ec2_driver.rb | 9 +++++++++
.../lib/deltacloud/helpers/application_helper.rb | 5 ++++-
server/server.rb | 15 +++++++++++++++
server/views/instances/index.html.haml | 2 ++
4 files changed, 30 insertions(+), 1 deletions(-)
diff --git a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
index 7436fb8..a825de6 100644
--- a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
+++ b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
@@ -145,6 +145,15 @@ module Deltacloud
img_arr.sort_by { |e| [e.owner_id, e.name] }
end
+ def create_image(credentials, opts={})
+ ec2 = new_client(credentials)
+ image_id = nil
+ safely do
+ image_id = ec2.create_image(opts[:instance_id], opts[:name])
+ end
+ image(credentials, :id => image_id)
+ end
+
def realms(credentials, opts={})
ec2 = new_client(credentials)
zone_id = opts ? opts[:id] : nil
diff --git a/server/lib/deltacloud/helpers/application_helper.rb
b/server/lib/deltacloud/helpers/application_helper.rb
index abe78bc..c73e72d 100644
--- a/server/lib/deltacloud/helpers/application_helper.rb
+++ b/server/lib/deltacloud/helpers/application_helper.rb
@@ -144,9 +144,12 @@ module ApplicationHelper
"<pem><![CDATA[#{text.strip}]]></pem>"
end
- def link_to_action(action, url, method)
+ def link_to_action(action, url, method, opts=nil)
capture_haml do
haml_tag :form, :method => :post, :action => url, :class => :link do
+ opts.each do |name, value|
+ haml_tag :input, :type => :hidden, :name => name, :value => value
+ end if opts
haml_tag :input, :type => :hidden, :name => '_method', :value => method
haml_tag :button, :type => :submit do
haml_concat action
diff --git a/server/server.rb b/server/server.rb
index a801bea..bab11a5 100644
--- a/server/server.rb
+++ b/server/server.rb
@@ -163,6 +163,21 @@ END
control { show(:image) }
end
+ operation :create do
+ description 'Create image from instance.'
+ with_capability :create_image
+ param :instance_id, :string, :required
+ param :name, :string, :required
+ control do
+ @image = driver.create_image(credentials, params)
+ respond_to do |format|
+ format.html { haml :"images/show" }
+ format.xml { haml :"images/show" }
+ format.json { convert_to_json(model, @image) }
+ end
+ end
+ end
+
end
collection :instance_states do
diff --git a/server/views/instances/index.html.haml
b/server/views/instances/index.html.haml
index d728ec5..c0aa99e 100644
--- a/server/views/instances/index.html.haml
+++ b/server/views/instances/index.html.haml
@@ -30,3 +30,5 @@
=link_to_action action, self.send(:"#{action}_instance_url",
instance.id), instance_action_method(action)
- if driver.respond_to?(:run_on_instance) and
instance.state=="RUNNING"
=link_to_action "Run command",
url_for("/api/instances/#{instance.id}/run"), :get
+ - if driver.respond_to?(:create_image) and ['RUNNING',
'STOPPPED'].include?(instance.state)
+ =link_to_action "Create image", url_for("/api/images"), :post, {
:instance_id => instance.id, :name => Time.now.to_i.to_s }
--
1.7.4