You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltacloud.apache.org by mf...@apache.org on 2013/01/29 10:08:19 UTC
git commit: Core: Add root_type attr to Image and HardwareProfile
Updated Branches:
refs/heads/master eb76681cc -> 4bbc4e6aa
Core: Add root_type attr to Image and HardwareProfile
The new 'root_type' attribute in case of Image contains information
about the root device type. There are two possible values:
persistent - Volume or other 'persistent' storage type (EBS)
transient - Default device that is part of the Image itself (instance-store)
In case of HardwareProfile this attribute is presented as a fixed
'property' called 'root_type'. The possible values are the same as above.
The hardware profile and image root_type attributes *must* match in order
to create a new instance. In other case an HTTP 400 (Bad Request) will be
returned to client.
API-Change: Added the 'root_type' attribute to Image and HardwareProfile
Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/4bbc4e6a
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/4bbc4e6a
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/4bbc4e6a
Branch: refs/heads/master
Commit: 4bbc4e6aa6fc3073db7820397d63672f78d8f9fc
Parents: eb76681
Author: Michal Fojtik <mf...@redhat.com>
Authored: Mon Jan 28 13:39:51 2013 +0100
Committer: Michal fojtik <mf...@redhat.com>
Committed: Tue Jan 29 10:03:20 2013 +0100
----------------------------------------------------------------------
server/lib/deltacloud/collections/instances.rb | 2 +-
server/lib/deltacloud/drivers/ec2/ec2_driver.rb | 13 ++++++++++++-
server/lib/deltacloud/models/hardware_profile.rb | 4 ++++
server/lib/deltacloud/models/image.rb | 6 ++++++
server/tests/drivers/ec2/images_test.rb | 7 +++++++
server/views/images/show.html.haml | 5 ++++-
server/views/images/show.xml.haml | 1 +
server/views/instances/new.html.haml | 2 +-
8 files changed, 36 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/4bbc4e6a/server/lib/deltacloud/collections/instances.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/collections/instances.rb b/server/lib/deltacloud/collections/instances.rb
index ffdf09d..adddacf 100644
--- a/server/lib/deltacloud/collections/instances.rb
+++ b/server/lib/deltacloud/collections/instances.rb
@@ -23,7 +23,7 @@ module Deltacloud::Collections
new_route_for(:instances) do
@instance = Instance.new( { :id=>params[:id], :image_id=>params[:image_id] } )
- @image = Image.new( :id => params[:image_id] )
+ @image = driver.image(credentials, :id => params[:image_id])
@hardware_profiles = driver.hardware_profiles(credentials, :architecture => @image.architecture )
@realms = [Realm.new(:id => params[:realm_id])] if params[:realm_id]
@realms ||= driver.realms(credentials)
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/4bbc4e6a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
index 9c10ff8..cd048c9 100644
--- a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
+++ b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
@@ -53,6 +53,7 @@ module Deltacloud
memory 613
storage 160
architecture ['i386','x86_64']
+ root_type :persistent
end
define_hardware_profile('m1.small') do
@@ -938,10 +939,15 @@ module Deltacloud
:owner_id => image[:aws_owner],
:architecture => image[:aws_architecture],
:hardware_profiles => image_profiles(image, profiles),
- :state => image[:aws_state]
+ :state => image[:aws_state],
+ :root_type => convert_root_type(image[:aws_root_device_type])
)
end
+ def convert_root_type(type)
+ type == 'ebs' ? 'persistent' : 'transient'
+ end
+
def convert_instance(instance)
can_create_image = 'ebs'.eql?(instance[:root_device_type]) and 'RUNNING'.eql?(convert_state(instance[:aws_state]))
inst_profile_opts={}
@@ -1146,6 +1152,11 @@ module Deltacloud
end
exceptions do
+
+ on /root device is not supported for the instance/ do
+ status 400
+ end
+
on /(AuthFailure|InvalidAccessKeyId)/ do
status 401
end
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/4bbc4e6a/server/lib/deltacloud/models/hardware_profile.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/models/hardware_profile.rb b/server/lib/deltacloud/models/hardware_profile.rb
index 5b4aa4e..9d76a2e 100644
--- a/server/lib/deltacloud/models/hardware_profile.rb
+++ b/server/lib/deltacloud/models/hardware_profile.rb
@@ -46,11 +46,15 @@ module Deltacloud
property :architecture
property :memory
property :storage
+ property :root_type
def initialize(profile_id, &block)
@properties = {}
super(:id => profile_id)
result = instance_eval(&block) if block_given?
+ unless @properties.include? :root_type
+ root_type(:transient)
+ end
@name ||= profile_id
result
end
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/4bbc4e6a/server/lib/deltacloud/models/image.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/models/image.rb b/server/lib/deltacloud/models/image.rb
index 551d861..6359661 100644
--- a/server/lib/deltacloud/models/image.rb
+++ b/server/lib/deltacloud/models/image.rb
@@ -24,6 +24,11 @@ class Image < BaseModel
attr_accessor :state
attr_accessor :hardware_profiles
attr_accessor :creation_time
+ attr_accessor :root_type
+
+ def root_type
+ @root_type || 'transient'
+ end
def to_hash(context)
{
@@ -34,6 +39,7 @@ class Image < BaseModel
:owner => owner_id,
:architecture => architecture,
:state => state,
+ :root_type => storage_type,
:creation_time => creation_time,
:hardware_profiles => hardware_profiles.map { |p|
{ :id => p.id, :href => context.hardware_profile_url(p.id), :rel => :hardware_profile }
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/4bbc4e6a/server/tests/drivers/ec2/images_test.rb
----------------------------------------------------------------------
diff --git a/server/tests/drivers/ec2/images_test.rb b/server/tests/drivers/ec2/images_test.rb
index 857ede7..7acbd7a 100644
--- a/server/tests/drivers/ec2/images_test.rb
+++ b/server/tests/drivers/ec2/images_test.rb
@@ -45,4 +45,11 @@ describe 'Ec2Driver Images' do
@driver.image(:id => 'unknown').must_be_nil
end
+ it 'must advertise the image storage_type' do
+ VCR.insert_cassette 'test_0004_must_allow_to_retrieve_single_image'
+ @driver.image(:id => 'ami-aecd60c7').wont_be_nil
+ @driver.image(:id => 'ami-aecd60c7').storage_type.wont_be_nil
+ @driver.image(:id => 'ami-aecd60c7').storage_type.must_equal 'persistent'
+ end
+
end
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/4bbc4e6a/server/views/images/show.html.haml
----------------------------------------------------------------------
diff --git a/server/views/images/show.html.haml b/server/views/images/show.html.haml
index f12ecb4..4ee622d 100644
--- a/server/views/images/show.html.haml
+++ b/server/views/images/show.html.haml
@@ -21,11 +21,14 @@
%li{ :'data-role' => 'list-divider'} Creation Time
%li
%p{ :'data-role' => 'fieldcontain'}=@image.creation_time
+ %li{ :'data-role' => 'list-divider'} Root Device Type
+ %li
+ %p{ :'data-role' => 'fieldcontain'}=@image.root_type
%li{ :'data-role' => 'list-divider'} Architecture
%li
%p{ :'data-role' => 'fieldcontain'}=@image.architecture
- if @image.hardware_profiles
- %li{ :'data-role' => 'list-divider'} Hardware Profiles
+ %li{ :'data-role' => 'list-divider'} Compatible Hardware Profiles
%li
%div{ :'data-role' => 'controlgroup', :'data-type' => "horizontal" }
- @image.hardware_profiles.each do |hwp|
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/4bbc4e6a/server/views/images/show.xml.haml
----------------------------------------------------------------------
diff --git a/server/views/images/show.xml.haml b/server/views/images/show.xml.haml
index db33666..ac014af 100644
--- a/server/views/images/show.xml.haml
+++ b/server/views/images/show.xml.haml
@@ -13,6 +13,7 @@
%hardware_profiles
- @image.hardware_profiles.each do |profile|
%hardware_profile{ :href => hardware_profile_url(profile.id), :id => profile.id, :rel => :hardware_profile }
+ %root_type=@image.root_type
%actions
%link{ :rel => 'create_instance', :method => :post, :href => "#{instances_url};image_id=#{@image.id}"}
- if driver.respond_to? :destroy_image
http://git-wip-us.apache.org/repos/asf/deltacloud/blob/4bbc4e6a/server/views/instances/new.html.haml
----------------------------------------------------------------------
diff --git a/server/views/instances/new.html.haml b/server/views/instances/new.html.haml
index 77881ea..f6f674e 100644
--- a/server/views/instances/new.html.haml
+++ b/server/views/instances/new.html.haml
@@ -2,7 +2,7 @@
=subheader "#{@image.id}"
.hidden_content
- - @hardware_profiles.each do |profile|
+ - @image.hardware_profiles.each do |profile|
%div{ :'data-role' => :fieldcontain, :id => "hwp_properties_#{profile.name}", :class => 'property_block'}
- profile.properties.reject { |prop| prop.fixed? }.each do |prop|
%label{ :for => "#{prop.param}_#{profile.name}", :class => 'ui-input-text' }=prop.name