ACK

also consider including this small patch to add hardware profile display
for images/show.html.haml:

>From 4e7c15c039d3f973b676e440eba15dd60316000a Mon Sep 17 00:00:00 2001
From: marios <[email protected]>
Date: Wed, 15 Feb 2012 12:00:08 +0200
Subject: [PATCH 2/2] Adds hardware_profiles view to image html


Signed-off-by: marios <[email protected]>
---
 server/views/images/show.html.haml |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/server/views/images/show.html.haml
b/server/views/images/show.html.haml
index bbdc9e5..482633c 100644
--- a/server/views/images/show.html.haml
+++ b/server/views/images/show.html.haml
@@ -20,6 +20,11 @@
     %li{ :'data-role' => 'list-divider'} Architecture
     %li
       %p{ :'data-role' => 'fieldcontain'}[email protected]
+    %li{ :'data-role' => 'list-divider'} Hardware Profiles
+    %li
+      %div{ :'data-role' => 'controlgroup', :'data-type' => "horizontal" }
+        - @image.hardware_profiles.each do |hwp|
+          %a{ :href => api_url_for("hardware_profiles/#{hwp.name}"),
:'data-role' => "button", :'data-ajax' => 'false'} #{hwp.name}
     %li{ :'data-role' => 'list-divider'} Actions
     %li
       %div{ :'data-role' => 'controlgroup', :'data-type' => "horizontal" }
-- 
1.7.6.5


On 15/02/12 11:35, [email protected] wrote:
> From: Michal Fojtik <[email protected]>
> 
> 
> Signed-off-by: Michal fojtik <[email protected]>
> ---
>  server/lib/deltacloud/drivers/ec2/ec2_driver.rb    |   17 ++++++++++++++---
>  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, 26 insertions(+), 7 deletions(-)
> 
> diff --git a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb 
> b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
> index 44db93a..4569056 100644
> --- a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
> +++ b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
> @@ -132,10 +132,11 @@ module Deltacloud
>            ec2 = new_client(credentials)
>            img_arr = []
>            opts ||= {}
> +          profiles = hardware_profiles(nil)
>            if opts[:id]
>              safely do
>                img_arr = ec2.describe_images([opts[:id]]).collect do |image|
> -                convert_image(image)
> +                convert_image(image, profiles)
>                end
>              end
>              return img_arr
> @@ -143,7 +144,7 @@ module Deltacloud
>            owner_id = opts[:owner_id] || default_image_owner
>            safely do
>              img_arr = ec2.describe_images_by_owner([owner_id], 
> default_image_type).collect do |image|
> -              convert_image(image)
> +              convert_image(image, profiles)
>              end
>            end
>            img_arr = filter_on( img_arr, :architecture, opts )
> @@ -783,7 +784,7 @@ module Deltacloud
>            )
>          end
>  
> -        def convert_image(image)
> +        def convert_image(image, profiles)
>            # There is not support for 'name' for now
>            Image.new(
>              :id => image[:aws_id],
> @@ -791,6 +792,7 @@ module Deltacloud
>              :description => image[:aws_description] || image[:aws_location],
>              :owner_id => image[:aws_owner],
>              :architecture => image[:aws_architecture],
> +            :hardware_profiles => image_profiles(image, profiles),
>              :state => image[:aws_state]
>            )
>          end
> @@ -854,6 +856,15 @@ module Deltacloud
>            )
>          end
>  
> +        def image_profiles(image, profiles)
> +          profiles = filter_hardware_profiles(profiles, :architecture => 
> image[:aws_architecture])
> +          if image[:aws_root_device_type] != 'ebs'
> +            profiles.reject { |p| p.name == 't1.micro' }
> +          else
> +            profiles
> +          end
> +        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}"}

Reply via email to