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 2012/02/14 14:10:54 UTC

[PATCH core] Core: Added hardware_profiles to Image model. The list of profiles should indicate compatibility for given Image with Hardware Profile

From: Michal Fojtik <mf...@redhat.com>


Signed-off-by: Michal fojtik <mf...@redhat.com>
---
 server/lib/deltacloud/drivers/ec2/ec2_driver.rb    |    7 +++++++
 server/lib/deltacloud/drivers/mock/mock_driver.rb  |    3 ++-
 .../lib/deltacloud/drivers/rhevm/rhevm_driver.rb   |    1 +
 .../deltacloud/drivers/vsphere/vsphere_driver.rb   |    5 +++--
 server/lib/deltacloud/models/image.rb              |    1 +
 server/views/images/show.xml.haml                  |    6 +++++-
 6 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
index 44db93a..6101bd2 100644
--- a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
+++ b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
@@ -791,6 +791,8 @@ module Deltacloud
             :description => image[:aws_description] || image[:aws_location],
             :owner_id => image[:aws_owner],
             :architecture => image[:aws_architecture],
+            # Credentials are not needed for EC2 driver hardware profiles:
+            :hardware_profiles => image_profiles(image),
             :state => image[:aws_state]
           )
         end
@@ -854,6 +856,11 @@ module Deltacloud
           )
         end
 
+        def image_profiles(image)
+          profiles = hardware_profiles(nil, :architecture => image[:aws_architecture])
+          profiles.reject { |p| p.name == 't1.micro' } unless image[:aws_root_device_type] == 'ebs'
+        end
+
         def convert_load_balancer(credentials, loadbalancer)
           puts loadbalancer.inspect
           realms = []
diff --git a/server/lib/deltacloud/drivers/mock/mock_driver.rb b/server/lib/deltacloud/drivers/mock/mock_driver.rb
index 1f36b36..caf14bc 100644
--- a/server/lib/deltacloud/drivers/mock/mock_driver.rb
+++ b/server/lib/deltacloud/drivers/mock/mock_driver.rb
@@ -120,7 +120,8 @@ module Deltacloud::Drivers::Mock
       else
         images = filter_on( images, :owner_id, opts )
       end
-      images.sort_by{|e| [e.owner_id,e.description]}
+      images = images.map { |i| (i.hardware_profiles = hardware_profiles(nil)) && i }
+      images.sort_by{|e| [e.owner_id, e.description]}
     end
 
     def create_image(credentials, opts={})
diff --git a/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb b/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb
index f3edee9..4713321 100644
--- a/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb
+++ b/server/lib/deltacloud/drivers/rhevm/rhevm_driver.rb
@@ -310,6 +310,7 @@ class RHEVMDriver < Deltacloud::BaseDriver
       :description => img.description,
       :owner_id => client.credentials[:username],
       :architecture => 'x86_64', # All RHEV-M VMs are x86_64
+      :hardware_profiles => hardware_profiles(nil),
       :state => img.status
     )
   end
diff --git a/server/lib/deltacloud/drivers/vsphere/vsphere_driver.rb b/server/lib/deltacloud/drivers/vsphere/vsphere_driver.rb
index 6b2ab8c..0f6d93a 100644
--- a/server/lib/deltacloud/drivers/vsphere/vsphere_driver.rb
+++ b/server/lib/deltacloud/drivers/vsphere/vsphere_driver.rb
@@ -80,7 +80,7 @@ module Deltacloud::Drivers::VSphere
     def images(credentials, opts=nil)
       cloud = new_client(credentials)
       img_arr = []
-
+      profiles = hardware_profiles(credentials)
       # Skip traversing through all instances in all datacenters when ID
       # attribute is set
       safely do
@@ -109,7 +109,8 @@ module Deltacloud::Drivers::VSphere
             :architecture => image_architecture,
             :owner_id => credentials.user,
             :description => properties[:full_name],
-            :state => image_state
+            :state => image_state,
+            :hardware_profiles => profiles
           )
         end
       end
diff --git a/server/lib/deltacloud/models/image.rb b/server/lib/deltacloud/models/image.rb
index 67f6dfb..555004e 100644
--- a/server/lib/deltacloud/models/image.rb
+++ b/server/lib/deltacloud/models/image.rb
@@ -22,6 +22,7 @@ class Image < BaseModel
   attr_accessor :description
   attr_accessor :architecture
   attr_accessor :state
+  attr_accessor :hardware_profiles
 
   alias :to_hash_original :to_hash
 
diff --git a/server/views/images/show.xml.haml b/server/views/images/show.xml.haml
index c1f5348..6f52218 100644
--- a/server/views/images/show.xml.haml
+++ b/server/views/images/show.xml.haml
@@ -1,8 +1,12 @@
 - unless defined?(partial)
   !!! XML
 %image{:href => image_url(@image.id), :id => @image.id}
-  - @image.attributes.select{ |attr| attr!=:id }.each do |attribute|
+  - @image.attributes.select{ |attr| ![:id, :hardware_profiles].include?(attr) }.each do |attribute|
     - haml_tag(attribute, :<) do
       - haml_concat @image.send(attribute)
+  - if @image.hardware_profiles
+    %hardware_profiles
+      - @image.hardware_profiles.each do |profile|
+        %hardware_profile{ :href => hardware_profile_url(profile.name), :id => profile.name, :rel => :hardware_profile }
   %actions
     %link{ :rel => 'create_instance', :method => :post, :href => "#{instances_url};image_id=#{@image.id}"}
-- 
1.7.4.4


Re: [PATCH core] Core: Added hardware_profiles to Image model. The list of profiles should indicate compatibility for given Image with Hardware Profile

Posted by Michal Fojtik <mf...@redhat.com>.
On Feb 14, 2012, at 5:21 PM, marios@redhat.com wrote:

> ACK(ish) - some thoughts:
> 
> On 14/02/12 15:10, mfojtik@redhat.com wrote:
>> From: Michal Fojtik <mf...@redhat.com>
>> 
>> 
>> Signed-off-by: Michal fojtik <mf...@redhat.com>
>> ---
>> server/lib/deltacloud/drivers/ec2/ec2_driver.rb    |    7 +++++++
> 6 files changed, 19 insertions(+), 4 deletions(-)
>> 
>> diff --git a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
>> index 44db93a..6101bd2 100644
>> --- a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
>> +++ b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
>> @@ -791,6 +791,8 @@ module Deltacloud
>>             :description => image[:aws_description] || image[:aws_location],
>>             :owner_id => image[:aws_owner],
>>             :architecture => image[:aws_architecture],
>> +            # Credentials are not needed for EC2 driver hardware profiles:
>> +            :hardware_profiles => image_profiles(image),
>>             :state => image[:aws_state]
>>           )
>>         end
>> @@ -854,6 +856,11 @@ module Deltacloud
>>           )
>>         end
>> 
>> +        def image_profiles(image)
>> +          profiles = hardware_profiles(nil, :architecture => image[:aws_architecture])
>> +          profiles.reject { |p| p.name == 't1.micro' } unless image[:aws_root_device_type] == 'ebs'
>> +        end
> 
> This is the 'safest' way to do it but it seems very costly - for every
> image get a list of hw_profiles; we already know that the list of images
> is pretty large (and based on recent conversations we might make this
> even larger for listing e.g. all images in the worst case).

I agree, I'll rework it in way where I pass hardware_profiles as parameter
to image_profiles. I did not noticed any delay, maybe because the hardware_profiles
are defined statically so there is no additional overheat by querying EC2.

But fair point.

> Right now the above is just 'filtering' on i386 vs x86_64 (i.e.
> architecture). So can't we just assemble a hash of {i386=>[profiles],
> x86_64=>profiles} once and use that for all images?

Agree. Will be fixed in rev-2.

> I understand that the point is eventually to enable the 'new' profiles
> for the high performance computing. I just spent some time looking at
> aws API looking for something in e.g. DescribeImage that would tell us
> if an image is 'high performance compatible' - i.e. you can use the
> 'new' hardware profiles to solve
> https://issues.apache.org/jira/browse/DTACLOUD-144 . Is this information
> available in the fields you added in the AWS pull request
> https://github.com/appoxy/aws/pull/106 ? If not, I don't know how are we
> going to extend this code to handle jira DTACLOUD_144

Yes, you're right. I double checked DescribeImages and there is no way how to
know if the image is HPC or not (maybe from the image id/name, I need to look).

Right now this patch will just tell you if you can use t1.micro HWP for launching
the image, which according to Aeolus guys would be very useful.

  -- michal

------------------------------------------------------
Michal Fojtik, mfojtik@redhat.com
Deltacloud API: http://deltacloud.org


Re: [PATCH core] Core: Added hardware_profiles to Image model. The list of profiles should indicate compatibility for given Image with Hardware Profile

Posted by "marios@redhat.com" <ma...@redhat.com>.
ACK(ish) - some thoughts:

On 14/02/12 15:10, mfojtik@redhat.com wrote:
> From: Michal Fojtik <mf...@redhat.com>
> 
> 
> Signed-off-by: Michal fojtik <mf...@redhat.com>
> ---
>  server/lib/deltacloud/drivers/ec2/ec2_driver.rb    |    7 +++++++
 6 files changed, 19 insertions(+), 4 deletions(-)
> 
> diff --git a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
> index 44db93a..6101bd2 100644
> --- a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
> +++ b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
> @@ -791,6 +791,8 @@ module Deltacloud
>              :description => image[:aws_description] || image[:aws_location],
>              :owner_id => image[:aws_owner],
>              :architecture => image[:aws_architecture],
> +            # Credentials are not needed for EC2 driver hardware profiles:
> +            :hardware_profiles => image_profiles(image),
>              :state => image[:aws_state]
>            )
>          end
> @@ -854,6 +856,11 @@ module Deltacloud
>            )
>          end
>  
> +        def image_profiles(image)
> +          profiles = hardware_profiles(nil, :architecture => image[:aws_architecture])
> +          profiles.reject { |p| p.name == 't1.micro' } unless image[:aws_root_device_type] == 'ebs'
> +        end

This is the 'safest' way to do it but it seems very costly - for every
image get a list of hw_profiles; we already know that the list of images
is pretty large (and based on recent conversations we might make this
even larger for listing e.g. all images in the worst case).

Right now the above is just 'filtering' on i386 vs x86_64 (i.e.
architecture). So can't we just assemble a hash of {i386=>[profiles],
x86_64=>profiles} once and use that for all images?

I understand that the point is eventually to enable the 'new' profiles
for the high performance computing. I just spent some time looking at
aws API looking for something in e.g. DescribeImage that would tell us
if an image is 'high performance compatible' - i.e. you can use the
'new' hardware profiles to solve
https://issues.apache.org/jira/browse/DTACLOUD-144 . Is this information
available in the fields you added in the AWS pull request
https://github.com/appoxy/aws/pull/106 ? If not, I don't know how are we
going to extend this code to handle jira DTACLOUD_144

> diff --git a/server/views/images/show.xml.haml b/server/views/images/show.xml.haml
> index c1f5348..6f52218 100644
> --- a/server/views/images/show.xml.haml
> +++ b/server/views/images/show.xml.haml
> @@ -1,8 +1,12 @@

+ show.html.haml


marios