You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by mf...@redhat.com on 2011/02/25 12:18:03 UTC
[PATCH core] Added Image creation from Instances (EC2, Mock, GoGrid, Rackspace)
From: Michal Fojtik <mf...@redhat.com>
---
server/lib/deltacloud/base_driver/features.rb | 2 +-
server/lib/deltacloud/drivers/ec2/ec2_driver.rb | 17 +++++++++-
.../lib/deltacloud/drivers/gogrid/gogrid_driver.rb | 3 +-
.../drivers/mock/data/instances/inst0.yml | 1 +
.../drivers/mock/data/instances/inst1.yml | 1 +
.../drivers/mock/data/instances/inst2.yml | 1 +
server/lib/deltacloud/drivers/mock/mock_driver.rb | 34 +++++++++++++++++---
.../drivers/rackspace/rackspace_driver.rb | 34 ++++++++++----------
server/lib/deltacloud/models/instance.rb | 9 +++++
server/server.rb | 26 +++++++++++++++
server/views/images/new.html.haml | 14 ++++++++
server/views/instances/show.html.haml | 5 +++
12 files changed, 122 insertions(+), 25 deletions(-)
create mode 100644 server/views/images/new.html.haml
diff --git a/server/lib/deltacloud/base_driver/features.rb b/server/lib/deltacloud/base_driver/features.rb
index a276314..79e859d 100644
--- a/server/lib/deltacloud/base_driver/features.rb
+++ b/server/lib/deltacloud/base_driver/features.rb
@@ -205,7 +205,7 @@ module Deltacloud
end
declare_feature :instances, :sandboxing do
- description "Allow lanuching sandbox images"
+ description "Allow launching sandbox images"
operation :create do
param :sandbox, :string, :optional
end
diff --git a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
index d657429..e300d56 100644
--- a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
+++ b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
@@ -155,6 +155,20 @@ module Deltacloud
end
end
+ def create_image(credentials, opts={})
+ ec2 = new_client(credentials)
+ instance = instance(credentials, :id => opts[:id])
+ safely do
+ raise BackendFeatureUnsupported::new(415, 'InstanceNotEBS', 'Instance must be EBS format to create image') unless instance.ebs?
+ if not instance.state == 'RUNNING'
+ raise BackendFeatureUnsupported::new(415, 'InstanceNotRunning', 'Instance must be in running state to create image')
+ else
+ new_image_id = ec2.create_image(instance.id, opts[:name], opts[:description])
+ image(credentials, :id => new_image_id)
+ end
+ end
+ end
+
def instances(credentials, opts={})
ec2 = new_client(credentials)
inst_arr = []
@@ -610,7 +624,8 @@ module Deltacloud
:instance_profile => InstanceProfile.new(instance[:aws_instance_type]),
:realm_id => instance[:aws_availability_zone],
:private_addresses => instance[:private_dns_name],
- :public_addresses => instance[:dns_name]
+ :public_addresses => instance[:dns_name],
+ :create_image => 'ebs'.eql?(instance[:root_device_type]) and 'RUNNING'.eql?(convert_state(instance[:aws_state]))
)
end
diff --git a/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb b/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb
index 0b027bd..b769609 100644
--- a/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb
+++ b/server/lib/deltacloud/drivers/gogrid/gogrid_driver.rb
@@ -446,7 +446,8 @@ class GogridDriver < Deltacloud::BaseDriver
:public_addresses => [ instance['ip']['ip'] ],
:private_addresses => [],
:username => instance['username'],
- :password => instance['password']
+ :password => instance['password'],
+ :create_image => 'true'.eql?(instance['isSandbox'])
)
end
diff --git a/server/lib/deltacloud/drivers/mock/data/instances/inst0.yml b/server/lib/deltacloud/drivers/mock/data/instances/inst0.yml
index a5b73be..d5f9fae 100644
--- a/server/lib/deltacloud/drivers/mock/data/instances/inst0.yml
+++ b/server/lib/deltacloud/drivers/mock/data/instances/inst0.yml
@@ -14,3 +14,4 @@
:actions:
- :reboot
- :stop
+:create_image: true
diff --git a/server/lib/deltacloud/drivers/mock/data/instances/inst1.yml b/server/lib/deltacloud/drivers/mock/data/instances/inst1.yml
index 3544d40..746daa2 100644
--- a/server/lib/deltacloud/drivers/mock/data/instances/inst1.yml
+++ b/server/lib/deltacloud/drivers/mock/data/instances/inst1.yml
@@ -7,3 +7,4 @@
:realm_id: us
:instance_profile: !ruby/object:InstanceProfile
id: m1-small
+:create_image: true
diff --git a/server/lib/deltacloud/drivers/mock/data/instances/inst2.yml b/server/lib/deltacloud/drivers/mock/data/instances/inst2.yml
index 9a70cb8..662bbb9 100644
--- a/server/lib/deltacloud/drivers/mock/data/instances/inst2.yml
+++ b/server/lib/deltacloud/drivers/mock/data/instances/inst2.yml
@@ -7,3 +7,4 @@
:realm_id: us
:instance_profile: !ruby/object:InstanceProfile
id: m1-large
+:create_image: true
diff --git a/server/lib/deltacloud/drivers/mock/mock_driver.rb b/server/lib/deltacloud/drivers/mock/mock_driver.rb
index fa18d77..06de4da 100644
--- a/server/lib/deltacloud/drivers/mock/mock_driver.rb
+++ b/server/lib/deltacloud/drivers/mock/mock_driver.rb
@@ -135,6 +135,31 @@ class MockDriver < Deltacloud::BaseDriver
images.sort_by{|e| [e.owner_id,e.description]}
end
+ def create_image(credentials, opts={})
+ check_credentials(credentials)
+ ids = Dir[ "#{@storage_root}/images/*.yml" ].collect{|e| File.basename( e, ".yml" )}
+ count = 0
+ while true
+ next_id = "img#{count}"
+ break if not ids.include?(next_id)
+ count += 1
+ end
+ safely do
+ image = {
+ :name => opts[:name],
+ :owner_id => 'root',
+ :description => opts[:description],
+ :architecture => 'i386',
+ :state => 'UP'
+ }
+ File.open( "#{@storage_root}/images/#{next_id}.yml", 'w' ) do |f|
+ YAML.dump( image, f )
+ end
+ image[:id] = next_id
+ Image.new(image)
+ end
+ end
+
#
# Instances
#
@@ -171,11 +196,9 @@ class MockDriver < Deltacloud::BaseDriver
count = 0
while true
- next_id = "inst" + count.to_s
- if not ids.include?(next_id)
- break
- end
- count = count + 1
+ next_id = "inst#{count}"
+ break if not ids.include?(next_id)
+ count += 1
end
realm_id = opts[:realm_id]
@@ -197,6 +220,7 @@ class MockDriver < Deltacloud::BaseDriver
:private_addresses=>["#{image_id}.#{next_id}.private.com"],
:instance_profile => InstanceProfile.new(hwp.name, opts),
:realm_id=>realm_id,
+ :create_image=>true,
:actions=>instance_actions_for( 'RUNNING' )
}
File.open( "#{@storage_root}/instances/#{next_id}.yml", 'w' ) {|f|
diff --git a/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb b/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb
index 1851c6b..a4272e1 100644
--- a/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb
+++ b/server/lib/deltacloud/drivers/rackspace/rackspace_driver.rb
@@ -91,23 +91,21 @@ class RackspaceDriver < Deltacloud::BaseDriver
result
end
- # TODO: This action is reserved for create image from instance
- #
- #def create_image(credentials, opts={})
- # rs = new_client(credentials)
- # safely do
- # server = rs.get_server(opts[:id].to_i)
- # image = server.create_image(opts[:name])
- # Image.new(
- # :id => image.id.to_s,
- # :name => image.name,
- # :description => image.name,
- # :owner_id => credentials.user,
- # :state => image.status,
- # :architecture => 'x86_64'
- # )
- # end
- #end
+ def create_image(credentials, opts={})
+ rs = new_client(credentials)
+ safely do
+ server = rs.get_server(opts[:id].to_i)
+ image = server.create_image(opts[:name])
+ Image.new(
+ :id => image.id.to_s,
+ :name => image.name,
+ :description => image.name,
+ :owner_id => credentials.user,
+ :state => image.status,
+ :architecture => 'x86_64'
+ )
+ end
+ end
def run_on_instance(credentials, opts={})
target = instance(credentials, :id => opts[:id])
@@ -359,6 +357,7 @@ private
:password => password ? password : nil
)
inst.actions = instance_actions_for(inst.state)
+ inst.create_image = 'RUNNING'.eql?(inst.state)
inst
end
@@ -376,6 +375,7 @@ private
:public_addresses => server[:addresses][:public],
:private_addresses => server[:addresses][:private]
)
+ inst.create_image = 'RUNNING'.eql?(inst.state)
inst.actions = instance_actions_for(inst.state)
inst
end
diff --git a/server/lib/deltacloud/models/instance.rb b/server/lib/deltacloud/models/instance.rb
index 6345590..b2a1a0d 100644
--- a/server/lib/deltacloud/models/instance.rb
+++ b/server/lib/deltacloud/models/instance.rb
@@ -32,11 +32,20 @@ class Instance < BaseModel
attr_accessor :authn_error
attr_accessor :username
attr_accessor :password
+ attr_accessor :create_image
+
+ def can_create_image?
+ self.create_image
+ end
def to_s
name
end
+ def ebs?
+ return true if 'ebs'.eql?(self.root_type)
+ end
+
def hardware_profile
instance_profile
end
diff --git a/server/server.rb b/server/server.rb
index fe723c5..e146704 100644
--- a/server/server.rb
+++ b/server/server.rb
@@ -140,6 +140,13 @@ END
end
+get "/api/images/new" do
+ @instance = Instance.new( :id => params[:instance_id] )
+ respond_to do |format|
+ format.html { haml :"images/new" }
+ end
+end
+
collection :images do
description <<END
An image is a platonic form of a machine. Images are not directly executable,
@@ -165,6 +172,25 @@ 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, :optional
+ param :description, :string, :optional
+ control do
+ @image = driver.create_image(credentials, {
+ :id => params[:instance_id],
+ :name => params[:name],
+ :description => params[:description]
+ })
+ respond_to do |format|
+ format.xml { haml :"images/show" }
+ format.html { haml :"images/show" }
+ end
+ end
+ end
+
end
collection :instance_states do
diff --git a/server/views/images/new.html.haml b/server/views/images/new.html.haml
new file mode 100644
index 0000000..728fa5d
--- /dev/null
+++ b/server/views/images/new.html.haml
@@ -0,0 +1,14 @@
+%h1 Create image from #{@instance.id}
+
+%form{ :action => images_url, :method => :post, :class => :new_instance }
+ %input{ :name => :instance_id, :type => :hidden, :value => @instance.id }/
+ %p
+ %label
+ Name:
+ %input{ :name => :name, :size => 30, :type => :text }/
+ %p
+ %label
+ Description:
+ %textarea{ :name => :description, :cols => 70, :rows => 20}
+ %p
+ %input{ :type => :submit, :value => 'Create' }
diff --git a/server/views/instances/show.html.haml b/server/views/instances/show.html.haml
index 76d77ba..9fc0916 100644
--- a/server/views/instances/show.html.haml
+++ b/server/views/instances/show.html.haml
@@ -50,3 +50,8 @@
%dd
-@instance.actions.each do |action|
=link_to_action action, self.send(:"#{action}_instance_url", @instance.id), instance_action_method(action)
+ %dt
+ %dd
+ - if @instance.can_create_image?
+ =link_to_action 'Create Image', url_for("/api/images/new?instance_id=#{@instance.id}"), :get
+
--
1.7.4
Re: [PATCH core] Added Image creation from Instances (EC2, Mock,
GoGrid, Rackspace)
Posted by David Lutterkort <lu...@redhat.com>.
On Wed, 2011-03-02 at 11:06 +0100, Michal Fojtik wrote:
> On 01/03/11 17:29 -0800, David Lutterkort wrote:
> >On Fri, 2011-02-25 at 12:18 +0100, mfojtik@redhat.com wrote:
> >> From: Michal Fojtik <mf...@redhat.com>
> >
> >Looks good, a few minor things:
> >
> >git am complains about lotsa trailing whitespace.
> >
> >> diff --git a/server/lib/deltacloud/base_driver/features.rb b/server/lib/deltacloud/base_driver/features.rb
> >> index a276314..79e859d 100644
> >> --- a/server/lib/deltacloud/base_driver/features.rb
> >> +++ b/server/lib/deltacloud/base_driver/features.rb
> >> @@ -205,7 +205,7 @@ module Deltacloud
> >> end
> >>
> >> declare_feature :instances, :sandboxing do
> >> - description "Allow lanuching sandbox images"
> >> + description "Allow launching sandbox images"
> >
> >That seems to be spurious
>
> Yes, it's a typo I found when I did some testing ;-)
> I can commit this in extra patch.
Haha .. I had stared at that diff for quite some time, and didn't see
the typo in 'launch' until just now.
> >> diff --git a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
> >> index d657429..e300d56 100644
> >> --- a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
> >> +++ b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
> >> @@ -155,6 +155,20 @@ module Deltacloud
> >> end
> >> end
> >>
> >> + def create_image(credentials, opts={})
> >> + ec2 = new_client(credentials)
> >> + instance = instance(credentials, :id => opts[:id])
> >> + safely do
> >> + raise BackendFeatureUnsupported::new(415, 'InstanceNotEBS', 'Instance must be EBS format to create image') unless instance.ebs?
> >> + if not instance.state == 'RUNNING'
> >> + raise BackendFeatureUnsupported::new(415, 'InstanceNotRunning', 'Instance must be in running state to create image')
> >> + else
> >> + new_image_id = ec2.create_image(instance.id, opts[:name], opts[:description])
> >> + image(credentials, :id => new_image_id)
> >> + end
> >> + end
> >
> >Should we really replicate this business logic here ? Shouldn't we leave
> >it up to EC2 to fail the operation and then report that failure back ?
>
> Surely we can. But I through it could be better to get some 'readable'
> reason to client (mean status code) instead of throwing 500 and message
> from Amazon.
It's a tradeoff between clearer error messages and the extra lookup we
need to do for error checking. How undecipherable are the errors that
come back from EC2 ?
David
Re: [PATCH core] Added Image creation from Instances (EC2, Mock,
GoGrid, Rackspace)
Posted by Michal Fojtik <mf...@redhat.com>.
On 01/03/11 17:29 -0800, David Lutterkort wrote:
>On Fri, 2011-02-25 at 12:18 +0100, mfojtik@redhat.com wrote:
>> From: Michal Fojtik <mf...@redhat.com>
>
>Looks good, a few minor things:
>
>git am complains about lotsa trailing whitespace.
>
>> diff --git a/server/lib/deltacloud/base_driver/features.rb b/server/lib/deltacloud/base_driver/features.rb
>> index a276314..79e859d 100644
>> --- a/server/lib/deltacloud/base_driver/features.rb
>> +++ b/server/lib/deltacloud/base_driver/features.rb
>> @@ -205,7 +205,7 @@ module Deltacloud
>> end
>>
>> declare_feature :instances, :sandboxing do
>> - description "Allow lanuching sandbox images"
>> + description "Allow launching sandbox images"
>
>That seems to be spurious
Yes, it's a typo I found when I did some testing ;-)
I can commit this in extra patch.
>
>> diff --git a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
>> index d657429..e300d56 100644
>> --- a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
>> +++ b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
>> @@ -155,6 +155,20 @@ module Deltacloud
>> end
>> end
>>
>> + def create_image(credentials, opts={})
>> + ec2 = new_client(credentials)
>> + instance = instance(credentials, :id => opts[:id])
>> + safely do
>> + raise BackendFeatureUnsupported::new(415, 'InstanceNotEBS', 'Instance must be EBS format to create image') unless instance.ebs?
>> + if not instance.state == 'RUNNING'
>> + raise BackendFeatureUnsupported::new(415, 'InstanceNotRunning', 'Instance must be in running state to create image')
>> + else
>> + new_image_id = ec2.create_image(instance.id, opts[:name], opts[:description])
>> + image(credentials, :id => new_image_id)
>> + end
>> + end
>
>Should we really replicate this business logic here ? Shouldn't we leave
>it up to EC2 to fail the operation and then report that failure back ?
Surely we can. But I through it could be better to get some 'readable'
reason to client (mean status code) instead of throwing 500 and message
from Amazon.
>> diff --git a/server/lib/deltacloud/drivers/mock/mock_driver.rb b/server/lib/deltacloud/drivers/mock/mock_driver.rb
>> index fa18d77..06de4da 100644
>> --- a/server/lib/deltacloud/drivers/mock/mock_driver.rb
>> +++ b/server/lib/deltacloud/drivers/mock/mock_driver.rb
>> @@ -135,6 +135,31 @@ class MockDriver < Deltacloud::BaseDriver
>> images.sort_by{|e| [e.owner_id,e.description]}
>> end
>>
>> + def create_image(credentials, opts={})
>> + check_credentials(credentials)
>> + ids = Dir[ "#{@storage_root}/images/*.yml" ].collect{|e| File.basename( e, ".yml" )}
>> + count = 0
>> + while true
>> + next_id = "img#{count}"
>> + break if not ids.include?(next_id)
>> + count += 1
>> + end
>> + safely do
>> + image = {
>> + :name => opts[:name],
>> + :owner_id => 'root',
>> + :description => opts[:description],
>> + :architecture => 'i386',
>> + :state => 'UP'
>> + }
>> + File.open( "#{@storage_root}/images/#{next_id}.yml", 'w' ) do |f|
>> + YAML.dump( image, f )
>> + end
>> + image[:id] = next_id
>> + Image.new(image)
>> + end
>> + end
>
>It would be super-spiffy if the mock driver would report an error if the
>instance's create_image flag is false.
Good idea! Will integrate this before push.
>> @@ -171,11 +196,9 @@ class MockDriver < Deltacloud::BaseDriver
>>
>> count = 0
>> while true
>> - next_id = "inst" + count.to_s
>> - if not ids.include?(next_id)
>> - break
>> - end
>> - count = count + 1
>> + next_id = "inst#{count}"
>> + break if not ids.include?(next_id)
>> + count += 1
>
>That seems to be unrelated cleanup.
Sure, will commit this in extra patch ;-)
>
>> diff --git a/server/lib/deltacloud/models/instance.rb b/server/lib/deltacloud/models/instance.rb
>> index 6345590..b2a1a0d 100644
>> --- a/server/lib/deltacloud/models/instance.rb
>> +++ b/server/lib/deltacloud/models/instance.rb
>> @@ -32,11 +32,20 @@ class Instance < BaseModel
>> attr_accessor :authn_error
>> attr_accessor :username
>> attr_accessor :password
>> + attr_accessor :create_image
>> +
>> + def can_create_image?
>> + self.create_image
>> + end
>>
>> def to_s
>> name
>> end
>>
>> + def ebs?
>> + return true if 'ebs'.eql?(self.root_type)
>> + end
>
>It's a little icky that we have a bit of driver-specific stuff in the
>instance object. Since EC2Driver already monkey-patches Instance, maybe
>we should just stick it there, too (not that I condone wide-spread
>monkey patching ;)
Yes and I think it's not used anywhere. I have this helper in views, but
since I add 'can_create_image?' helper it's not needed anymore.
Will remove this ebs? before push.
>
>> diff --git a/server/views/instances/show.html.haml b/server/views/instances/show.html.haml
>> index 76d77ba..9fc0916 100644
>> --- a/server/views/instances/show.html.haml
>> +++ b/server/views/instances/show.html.haml
>> @@ -50,3 +50,8 @@
>> %dd
>> -@instance.actions.each do |action|
>> =link_to_action action, self.send(:"#{action}_instance_url", @instance.id), instance_action_method(action)
>> + %dt
>> + %dd
>> + - if @instance.can_create_image?
>> + =link_to_action 'Create Image', url_for("/api/images/new?instance_id=#{@instance.id}"), :get
>
>Shouldn't we also expose that in the XML ?
Definitely in actions. Good catch, thanks!
-- Michal
--
--------------------------------------------------------
Michal Fojtik, mfojtik@redhat.com
Deltacloud API: http://deltacloud.org
--------------------------------------------------------
Re: [PATCH core] Added Image creation from Instances (EC2, Mock,
GoGrid, Rackspace)
Posted by David Lutterkort <lu...@redhat.com>.
On Fri, 2011-02-25 at 12:18 +0100, mfojtik@redhat.com wrote:
> From: Michal Fojtik <mf...@redhat.com>
Looks good, a few minor things:
git am complains about lotsa trailing whitespace.
> diff --git a/server/lib/deltacloud/base_driver/features.rb b/server/lib/deltacloud/base_driver/features.rb
> index a276314..79e859d 100644
> --- a/server/lib/deltacloud/base_driver/features.rb
> +++ b/server/lib/deltacloud/base_driver/features.rb
> @@ -205,7 +205,7 @@ module Deltacloud
> end
>
> declare_feature :instances, :sandboxing do
> - description "Allow lanuching sandbox images"
> + description "Allow launching sandbox images"
That seems to be spurious
> diff --git a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
> index d657429..e300d56 100644
> --- a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
> +++ b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
> @@ -155,6 +155,20 @@ module Deltacloud
> end
> end
>
> + def create_image(credentials, opts={})
> + ec2 = new_client(credentials)
> + instance = instance(credentials, :id => opts[:id])
> + safely do
> + raise BackendFeatureUnsupported::new(415, 'InstanceNotEBS', 'Instance must be EBS format to create image') unless instance.ebs?
> + if not instance.state == 'RUNNING'
> + raise BackendFeatureUnsupported::new(415, 'InstanceNotRunning', 'Instance must be in running state to create image')
> + else
> + new_image_id = ec2.create_image(instance.id, opts[:name], opts[:description])
> + image(credentials, :id => new_image_id)
> + end
> + end
Should we really replicate this business logic here ? Shouldn't we leave
it up to EC2 to fail the operation and then report that failure back ?
> diff --git a/server/lib/deltacloud/drivers/mock/mock_driver.rb b/server/lib/deltacloud/drivers/mock/mock_driver.rb
> index fa18d77..06de4da 100644
> --- a/server/lib/deltacloud/drivers/mock/mock_driver.rb
> +++ b/server/lib/deltacloud/drivers/mock/mock_driver.rb
> @@ -135,6 +135,31 @@ class MockDriver < Deltacloud::BaseDriver
> images.sort_by{|e| [e.owner_id,e.description]}
> end
>
> + def create_image(credentials, opts={})
> + check_credentials(credentials)
> + ids = Dir[ "#{@storage_root}/images/*.yml" ].collect{|e| File.basename( e, ".yml" )}
> + count = 0
> + while true
> + next_id = "img#{count}"
> + break if not ids.include?(next_id)
> + count += 1
> + end
> + safely do
> + image = {
> + :name => opts[:name],
> + :owner_id => 'root',
> + :description => opts[:description],
> + :architecture => 'i386',
> + :state => 'UP'
> + }
> + File.open( "#{@storage_root}/images/#{next_id}.yml", 'w' ) do |f|
> + YAML.dump( image, f )
> + end
> + image[:id] = next_id
> + Image.new(image)
> + end
> + end
It would be super-spiffy if the mock driver would report an error if the
instance's create_image flag is false.
> @@ -171,11 +196,9 @@ class MockDriver < Deltacloud::BaseDriver
>
> count = 0
> while true
> - next_id = "inst" + count.to_s
> - if not ids.include?(next_id)
> - break
> - end
> - count = count + 1
> + next_id = "inst#{count}"
> + break if not ids.include?(next_id)
> + count += 1
That seems to be unrelated cleanup.
> diff --git a/server/lib/deltacloud/models/instance.rb b/server/lib/deltacloud/models/instance.rb
> index 6345590..b2a1a0d 100644
> --- a/server/lib/deltacloud/models/instance.rb
> +++ b/server/lib/deltacloud/models/instance.rb
> @@ -32,11 +32,20 @@ class Instance < BaseModel
> attr_accessor :authn_error
> attr_accessor :username
> attr_accessor :password
> + attr_accessor :create_image
> +
> + def can_create_image?
> + self.create_image
> + end
>
> def to_s
> name
> end
>
> + def ebs?
> + return true if 'ebs'.eql?(self.root_type)
> + end
It's a little icky that we have a bit of driver-specific stuff in the
instance object. Since EC2Driver already monkey-patches Instance, maybe
we should just stick it there, too (not that I condone wide-spread
monkey patching ;)
> diff --git a/server/views/instances/show.html.haml b/server/views/instances/show.html.haml
> index 76d77ba..9fc0916 100644
> --- a/server/views/instances/show.html.haml
> +++ b/server/views/instances/show.html.haml
> @@ -50,3 +50,8 @@
> %dd
> -@instance.actions.each do |action|
> =link_to_action action, self.send(:"#{action}_instance_url", @instance.id), instance_action_method(action)
> + %dt
> + %dd
> + - if @instance.can_create_image?
> + =link_to_action 'Create Image', url_for("/api/images/new?instance_id=#{@instance.id}"), :get
Shouldn't we also expose that in the XML ?
David