incubator-deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lut...@apache.org
Subject svn commit: r962040 - in /incubator/deltacloud/trunk/framework: app/controllers/ app/models/ app/views/api/ app/views/flavors/ app/views/images/ app/views/instances/ lib/converters/ lib/deltacloud/
Date Thu, 08 Jul 2010 23:18:47 GMT
Author: lutter
Date: Thu Jul  8 23:18:46 2010
New Revision: 962040

URL: http://svn.apache.org/viewvc?rev=962040&view=rev
Log:
Use app/models/**

Added:
    incubator/deltacloud/trunk/framework/app/models/base_model.rb
    incubator/deltacloud/trunk/framework/app/models/flavor.rb
    incubator/deltacloud/trunk/framework/app/models/image.rb
    incubator/deltacloud/trunk/framework/app/models/instance.rb
    incubator/deltacloud/trunk/framework/app/views/api/show.xml.haml
Removed:
    incubator/deltacloud/trunk/framework/app/views/api/show.xml.erb
Modified:
    incubator/deltacloud/trunk/framework/app/controllers/instances_controller.rb
    incubator/deltacloud/trunk/framework/app/views/flavors/index.html.erb
    incubator/deltacloud/trunk/framework/app/views/flavors/show.html.erb
    incubator/deltacloud/trunk/framework/app/views/images/index.html.erb
    incubator/deltacloud/trunk/framework/app/views/images/show.html.erb
    incubator/deltacloud/trunk/framework/app/views/instances/index.html.erb
    incubator/deltacloud/trunk/framework/app/views/instances/new.html.erb
    incubator/deltacloud/trunk/framework/app/views/instances/show.html.erb
    incubator/deltacloud/trunk/framework/lib/converters/xml_converter.rb
    incubator/deltacloud/trunk/framework/lib/deltacloud/base_driver.rb

Modified: incubator/deltacloud/trunk/framework/app/controllers/instances_controller.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/framework/app/controllers/instances_controller.rb?rev=962040&r1=962039&r2=962040&view=diff
==============================================================================
--- incubator/deltacloud/trunk/framework/app/controllers/instances_controller.rb (original)
+++ incubator/deltacloud/trunk/framework/app/controllers/instances_controller.rb Thu Jul 
8 23:18:46 2010
@@ -19,7 +19,7 @@ class InstancesController < ApplicationC
   end
 
   def show
-    @instance = driver.instance( credentials, :id => params[:id] )
+    @instance = driver.instance( credentials, :id=>params[:id] )
 
     respond_to do |format|
       format.html {
@@ -34,39 +34,39 @@ class InstancesController < ApplicationC
   end
 
   def destroy
-    driver.delete_instance( credentials, :id=> params[:id] )
+    driver.delete_instance( credentials, params[:id] )
     redirect_to :action=>:show
   end
 
   def new
-    @instance = {
+    @instance = Instance.new( {
                   :id=>params[:id],
                   :image_id=>params[:image_id],
-                } 
+                } )
     @image   = driver.image( credentials, :id => params[:image_id] )
-    puts "ARCH #{@image[:architecture]}"
-    @flavors = driver.flavors( credentials, { :architecture=>@image[:architecture] } )
+    @flavors = driver.flavors( credentials, { :architecture=>@image.architecture } )
   end
 
   def create
-
-    @image   = driver.image( credentials, :id => params[:image_id] )
+    @image   = driver.image( credentials, :id=>params[:image_id] )
+    puts @image.inspect
     respond_to do |format|
       format.html {
         if ( params[:flavor_id].nil? )
-          @flavors = driver.flavors_by_architecture( credentials, @image[:architecture] )
-          @instance = {
+          @flavors = driver.flavors_by_architecture( credentials, @image.architecture )
+          @instance = Instance.new( {
                         :id=>params[:id],
                         :image_id=>params[:image_id],
-                      } 
+                      } )
           render :action=>:new and return 
         end
-        instance = driver.create_instance( credentials, @image[:id], params[:flavor_id] )
-        redirect_to instance_url( instance[:id] )
+        instance = driver.create_instance( credentials, @image.resource_id, params[:flavor_id]
)
+        redirect_to instance_url( instance.resource_id )
       }
       format.xml {
-        instance = driver.create_instance( credentials, @image[:id], params[:flavor_id] )
-        render :xml=>convert_to_xml( :instance, instance), :status=>:created, :location=>instance_url(
instance[:id] )
+        instance = driver.create_instance( credentials, @image.resource_id, params[:flavor_id]
)
+        puts "RESULT #{instance.inspect}"
+        render :xml=>convert_to_xml( :instance, instance), :status=>:created, :location=>instance_url(
instance.resource_id )
       }
     end
   end

Added: incubator/deltacloud/trunk/framework/app/models/base_model.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/framework/app/models/base_model.rb?rev=962040&view=auto
==============================================================================
--- incubator/deltacloud/trunk/framework/app/models/base_model.rb (added)
+++ incubator/deltacloud/trunk/framework/app/models/base_model.rb Thu Jul  8 23:18:46 2010
@@ -0,0 +1,11 @@
+
+class BaseModel
+  def initialize(init=nil)
+    if ( init )
+      self.resource_id=init[:id]
+      init.each{|k,v|
+        self.send( "#{k}=", v ) if ( self.respond_to?( "#{k}=" ) )
+      }
+    end
+  end
+end

Added: incubator/deltacloud/trunk/framework/app/models/flavor.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/framework/app/models/flavor.rb?rev=962040&view=auto
==============================================================================
--- incubator/deltacloud/trunk/framework/app/models/flavor.rb (added)
+++ incubator/deltacloud/trunk/framework/app/models/flavor.rb Thu Jul  8 23:18:46 2010
@@ -0,0 +1,7 @@
+
+class Flavor < BaseModel
+  attr_accessor :resource_id
+  attr_accessor :architecture
+  attr_accessor :memory
+  attr_accessor :storage
+end

Added: incubator/deltacloud/trunk/framework/app/models/image.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/framework/app/models/image.rb?rev=962040&view=auto
==============================================================================
--- incubator/deltacloud/trunk/framework/app/models/image.rb (added)
+++ incubator/deltacloud/trunk/framework/app/models/image.rb Thu Jul  8 23:18:46 2010
@@ -0,0 +1,7 @@
+
+class Image < BaseModel
+  attr_accessor :resource_id
+  attr_accessor :owner_id
+  attr_accessor :description
+  attr_accessor :architecture
+end

Added: incubator/deltacloud/trunk/framework/app/models/instance.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/framework/app/models/instance.rb?rev=962040&view=auto
==============================================================================
--- incubator/deltacloud/trunk/framework/app/models/instance.rb (added)
+++ incubator/deltacloud/trunk/framework/app/models/instance.rb Thu Jul  8 23:18:46 2010
@@ -0,0 +1,13 @@
+
+class Instance < BaseModel
+
+  attr_accessor :resource_id
+  attr_accessor :owner_id
+  attr_accessor :image_id
+  attr_accessor :flavor_id
+  attr_accessor :state
+  attr_accessor :actions
+  attr_accessor :public_addresses
+  attr_accessor :private_addresses
+  
+end

Added: incubator/deltacloud/trunk/framework/app/views/api/show.xml.haml
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/framework/app/views/api/show.xml.haml?rev=962040&view=auto
==============================================================================
--- incubator/deltacloud/trunk/framework/app/views/api/show.xml.haml (added)
+++ incubator/deltacloud/trunk/framework/app/views/api/show.xml.haml Thu Jul  8 23:18:46 2010
@@ -0,0 +1,3 @@
+%api{ :version=>@version }
+  - for entry_point in @entry_points
+    %link{ :rel=>entry_point[0], :href=>entry_point[1] }

Modified: incubator/deltacloud/trunk/framework/app/views/flavors/index.html.erb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/framework/app/views/flavors/index.html.erb?rev=962040&r1=962039&r2=962040&view=diff
==============================================================================
--- incubator/deltacloud/trunk/framework/app/views/flavors/index.html.erb (original)
+++ incubator/deltacloud/trunk/framework/app/views/flavors/index.html.erb Thu Jul  8 23:18:46
2010
@@ -19,16 +19,16 @@
   <% for flavor in @flavors %>
     <tr>
       <td>
-        <%= link_to flavor[:id], flavor_url( flavor[:id] ) %>
+        <%= link_to flavor.resource_id, flavor_url( flavor.resource_id ) %>
       </td>
       <td>
-        <%= flavor[:architecture] %>
+        <%= flavor.architecture %>
       </td>
       <td>
-        <%= flavor[:memory] %> GB
+        <%= flavor.memory %> GB
       </td>
       <td>
-        <%= flavor[:storage] %> GB
+        <%= flavor.storage %> GB
       </td>
     </tr>
   <% end %>

Modified: incubator/deltacloud/trunk/framework/app/views/flavors/show.html.erb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/framework/app/views/flavors/show.html.erb?rev=962040&r1=962039&r2=962040&view=diff
==============================================================================
--- incubator/deltacloud/trunk/framework/app/views/flavors/show.html.erb (original)
+++ incubator/deltacloud/trunk/framework/app/views/flavors/show.html.erb Thu Jul  8 23:18:46
2010
@@ -1,4 +1,4 @@
-<h1><%= @flavor[:id] %></h1>
+<h1><%= @flavor.resource_id %></h1>
 
 <dl>
   <di>
@@ -6,7 +6,7 @@
       Architecture
     </dt>
     <dd>
-      <%= @flavor[:architecture] %>
+      <%= @flavor.architecture %>
     </dd>
   </di>
   <di>
@@ -14,7 +14,7 @@
       Memory
     </dt>
     <dd>
-      <%= @flavor[:memory] %> GB
+      <%= @flavor.memory %> GB
     </dd>
   </di>
   <di>
@@ -22,7 +22,7 @@
       Storage
     </dt>
     <dd>
-      <%= @flavor[:storage] %> GB
+      <%= @flavor.storage %> GB
     </dd>
   </di>
 </dl>

Modified: incubator/deltacloud/trunk/framework/app/views/images/index.html.erb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/framework/app/views/images/index.html.erb?rev=962040&r1=962039&r2=962040&view=diff
==============================================================================
--- incubator/deltacloud/trunk/framework/app/views/images/index.html.erb (original)
+++ incubator/deltacloud/trunk/framework/app/views/images/index.html.erb Thu Jul  8 23:18:46
2010
@@ -19,16 +19,16 @@
   <% for image in @images %>
     <tr>
       <td>
-        <%= link_to image[:id], image_url( image[:id] ) %>
+        <%= link_to image.resource_id, image_url( image.resource_id ) %>
       </td>
       <td>
-        <%= link_to image[:owner_id], images_url( :owner=>image[:owner_id] ) %>
+        <%= link_to image.owner_id, images_url( :owner=>image.owner_id ) %>
       </td>
       <td>
-        <%= image[:architecture] %>
+        <%= image.architecture %>
       </td>
       <td>
-        <%= image[:description] %>
+        <%= image.description %>
       </td>
     </tr>
   <% end %>

Modified: incubator/deltacloud/trunk/framework/app/views/images/show.html.erb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/framework/app/views/images/show.html.erb?rev=962040&r1=962039&r2=962040&view=diff
==============================================================================
--- incubator/deltacloud/trunk/framework/app/views/images/show.html.erb (original)
+++ incubator/deltacloud/trunk/framework/app/views/images/show.html.erb Thu Jul  8 23:18:46
2010
@@ -1,6 +1,6 @@
 
 <h1>Image</h1>
-<h2><%= @image[:id] %></h2>
+<h2><%= @image.resource_id %></h2>
 
 <dl>
   <di>
@@ -8,7 +8,7 @@
       Owner
     </dt>
     <dd>
-      <%= link_to @image[:owner_id], images_url( :owner=>@image[:owner_id] ) %>
+      <%= link_to @image.owner_id, images_url( :owner=>@image.owner_id ) %>
     </dd>
   </di>
   <di>
@@ -16,7 +16,7 @@
       Architecture
     </dt>
     <dd>
-      <%= @image[:architecture] %>
+      <%= @image.architecture %>
     </dd>
   </di>
   <di>
@@ -24,11 +24,11 @@
       Description
     </dt>
     <dd>
-      <%= @image[:description] %>
+      <%= @image.description %>
     </dd>
   </di>
 </dl>
   
 <div>
-  <%= link_to 'launch', new_instance_url( :image_id=>@image[:id] ) %>
+  <%= link_to 'launch', new_instance_url( :image_id=>@image.resource_id ) %>
 </div>

Modified: incubator/deltacloud/trunk/framework/app/views/instances/index.html.erb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/framework/app/views/instances/index.html.erb?rev=962040&r1=962039&r2=962040&view=diff
==============================================================================
--- incubator/deltacloud/trunk/framework/app/views/instances/index.html.erb (original)
+++ incubator/deltacloud/trunk/framework/app/views/instances/index.html.erb Thu Jul  8 23:18:46
2010
@@ -24,24 +24,24 @@
   <% for instance in @instances %>
     <tr>
       <td>
-        <%= link_to instance[:id], instance_url( instance[:id] ) %>
+        <%= link_to instance.resource_id, instance_url( instance.resource_id ) %>
       </td>
       <td>
-        <%= link_to instance[:owner_id], images_url( :owner=>instance[:owner_id] )
%>
+        <%= link_to instance.owner_id, images_url( :owner=>instance.owner_id ) %>
       </td>
       <td>
-        <%= link_to instance[:image_id], image_url( instance[:image_id] ) %>
+        <%= link_to instance.image_id, image_url( instance.image_id ) %>
       </td>
       <td>
-        <%= link_to instance[:flavor_id], flavor_url( instance[:flavor_id] ) %>
+        <%= link_to instance.flavor_id, flavor_url( instance.flavor_id ) %>
       </td>
       <td>
-        <%= instance[:state] %>
+        <%= instance.state %>
       </td>
       <td>
-        <%# instance.class.actions.each do |action| %>
-          <%#= link_to action, polymorphic_url( instance, :action=>action ), :method=>:post
%>
-        <%# end %>
+        <% instance.actions.each do |action| %>
+          <%= link_to action, self.send( "#{action}_instance_url", instance.resource_id
), :method=>:post %>
+        <% end %>
       </td>
     </tr>
   <% end %>

Modified: incubator/deltacloud/trunk/framework/app/views/instances/new.html.erb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/framework/app/views/instances/new.html.erb?rev=962040&r1=962039&r2=962040&view=diff
==============================================================================
--- incubator/deltacloud/trunk/framework/app/views/instances/new.html.erb (original)
+++ incubator/deltacloud/trunk/framework/app/views/instances/new.html.erb Thu Jul  8 23:18:46
2010
@@ -1,17 +1,17 @@
 <h1>New Instance</h1>
 
-<h2><%= @image[:id] %></h2>
-<h3><%= @image[:description] %></h3>
+<h2><%= @image.resource_id %></h2>
+<h3><%= @image.description %></h3>
 
 <% form_tag instances_url do %>
-  <%= hidden_field_tag :image_id, @instance[:image_id] %>
+  <%= hidden_field_tag :image_id, @instance.image_id %>
   <% for flavor in @flavors %>
     <div class="radio-group">
-      <label for="flavor_id_<%=flavor[:id]%>">
-        <%= radio_button_tag 'flavor_id', flavor[:id] %>
-        <%= flavor[:id] %><br/>
+      <label for="flavor_id_<%=flavor.resource_id%>">
+        <%= radio_button_tag 'flavor_id', flavor.resource_id %>
+        <%= flavor.resource_id %><br/>
         <span class="radio-group-details">
-          <%= flavor[:architecture] %>, <%= flavor[:memory] %> GB, <%= flavor[:storage]
%> GB
+          <%= flavor.architecture %>, <%= flavor.memory %> GB, <%= flavor.storage
%> GB
         </span>
       </label>
     </div>

Modified: incubator/deltacloud/trunk/framework/app/views/instances/show.html.erb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/framework/app/views/instances/show.html.erb?rev=962040&r1=962039&r2=962040&view=diff
==============================================================================
--- incubator/deltacloud/trunk/framework/app/views/instances/show.html.erb (original)
+++ incubator/deltacloud/trunk/framework/app/views/instances/show.html.erb Thu Jul  8 23:18:46
2010
@@ -1,5 +1,5 @@
 
-<h1><%= @instance[:id] %></h1>
+<h1><%= @instance.resource_id %></h1>
 
 <dl>
   <di>
@@ -7,7 +7,7 @@
       Image
     </dt>
     <dd>
-      <%= link_to @instance[:image_id], image_url( @instance[:image_id] ) %>
+      <%= link_to @instance.image_id, image_url( @instance.image_id ) %>
     </dd>
   </di>
   <di>
@@ -15,7 +15,7 @@
       Owner
     </dt>
     <dd>
-      <%= @instance[:owner_id] %>
+      <%= @instance.owner_id %>
     </dd>
   </di>
   <di>
@@ -23,7 +23,7 @@
       Flavor
     </dt>
     <dd>
-      <%= link_to @instance[:flavor_id], flavor_url( @instance[:flavor_id] ) %>
+      <%= link_to @instance.flavor_id, flavor_url( @instance.flavor_id ) %>
     </dd>
   </di>
   <di>
@@ -31,30 +31,34 @@
       State
     </dt>
     <dd>
-      <%= @instance[:state] %>
+      <%= @instance.state %>
     </dd>
   </di>
   <di>
     <dt>
-      Public Address
+      Public Addresses
     </dt>
     <dd>
-      <%= @instance[:public_address] %>
+      <% for address in  @instance.public_addresses %>
+        <div><%= address %></div>
+      <% end %>
     </dd>
   </di>
   <di>
     <dt>
-      Private Address
+      Private Addresses
     </dt>
     <dd>
-      <%= @instance[:private_address] %>
+      <% for address in  @instance.private_addresses %>
+        <div><%= address %></div>
+      <% end %>
     </dd>
   </di>
 </dl>
 
 <div>
-  <%# @instance.class.actions.each do |action| %>
-    <%#= link_to action, polymorphic_url( @instance, :action=>action ), :method=>:post
%>
-  <%# end %>
-  <%= link_to 'delete', instance_url( @instance[:id] ), :method=>:delete %>
+  <% @instance.actions.each do |action| %>
+    <%= link_to action, send( "#{action}_instance_url", @instance.resource_id ), :method=>:post
%>
+  <% end %>
+  <%= link_to 'delete', instance_url( @instance.resource_id ), :method=>:delete %>
 </div>

Modified: incubator/deltacloud/trunk/framework/lib/converters/xml_converter.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/framework/lib/converters/xml_converter.rb?rev=962040&r1=962039&r2=962040&view=diff
==============================================================================
--- incubator/deltacloud/trunk/framework/lib/converters/xml_converter.rb (original)
+++ incubator/deltacloud/trunk/framework/lib/converters/xml_converter.rb Thu Jul  8 23:18:46
2010
@@ -1,3 +1,4 @@
+require 'flavor'
 
 module Converters
 
@@ -31,39 +32,48 @@ module Converters
             convert( e, builder )
           end
         end
-      elsif ( obj.is_a?( Hash ) )
-        obj = obj.dup
-        obj_id = obj.delete(:id)
-        builder.__send__( Converters.tag_name( @type ), :href=>@link_builder.send( "#{@type}_url",
obj_id ) ) do
-          builder.id( obj_id )
-          obj.each do |k,v|
-            if ( k.to_s =~ /^(.*)_ids$/ )
-              type = $1 
-              builder.__send__( type.pluralize ) do
-                v.each do |each_id|
-                  builder.__send__( type, @link_builder.send( "#{type}_url", each_id ) )
+      else
+        puts "dump #{obj.inspect} #{obj.is_a?( Flavor )}"
+        case ( obj )
+          when Flavor
+            builder.flavor( :href=>@link_builder.send( :flavor_url,  obj.resource_id )
) {
+              builder.id( obj.resource_id )
+              builder.architecture( obj.architecture )
+              builder.memory( obj.memory )
+              builder.storage( obj.storage )
+            }
+          when Image
+            builder.image( :href=>@link_builder.send( :image_url, obj.resource_id ) )
{
+              builder.id( obj.resource_id )
+              builder.owner_id( obj.owner_id )
+              builder.description( obj.description )
+              builder.architecture( obj.architecture )
+            }
+          when Instance
+            builder.instance( :href=>@link_builder.send( :instance_url, obj.resource_id
) ) {
+              builder.id( obj.resource_id )
+              builder.owner_id( obj.owner_id )
+              builder.image( :href=>@link_builder.send( :image_url, obj.image_id ) )
+              builder.flavor( :href=>@link_builder.send( :flavor_url, obj.flavor_id )
)
+              builder.state( obj.state )
+              builder.actions {
+                if ( obj.actions )
+                  obj.actions.each do |action|
+                    builder.link( :rel=>action, :href=>@link_builder.send( "#{action}_instance_url",
obj.resource_id ) )
+                  end
                 end
-              end
-            elsif ( k.to_s =~/^(.*)_id$/ )
-              type = $1
-              url_type = Converters.url_type( $1 )
-              unless ( url_type.nil? )
-                if ( v.nil? )
-                  builder.__send__( type )
-                else
-                  builder.__send__( type, @link_builder.send( "#{url_type}_url", v ) )
-                end
-              else
-                if ( v.nil? )
-                  builder.__send__( "#{type}_id" )
-                else
-                  builder.__send__( "#{type}_id", v )
-                end
-              end
-            else
-              builder.__send__( Converters.tag_name( k ), v )
-            end
-          end
+              }
+              builder.__send__( 'public-addresses' ) {
+                obj.public_addresses.each do |address|
+                  builder.address( address )
+                end 
+              }
+              builder.__send__( 'private-addresses' ) {
+                obj.private_addresses.each do |address|
+                  builder.address( address )
+                end 
+              }
+          }
         end
       end
       return builder.target!

Modified: incubator/deltacloud/trunk/framework/lib/deltacloud/base_driver.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/framework/lib/deltacloud/base_driver.rb?rev=962040&r1=962039&r2=962040&view=diff
==============================================================================
--- incubator/deltacloud/trunk/framework/lib/deltacloud/base_driver.rb (original)
+++ incubator/deltacloud/trunk/framework/lib/deltacloud/base_driver.rb Thu Jul  8 23:18:46
2010
@@ -45,10 +45,11 @@ module DeltaCloud
       return collection if opts.nil?
       return collection if opts[attribute].nil?
       filter = opts[attribute]
+      method = ( attribute == :id ? :resource_id : attribute )
       if ( filter.is_a?( Array ) )
-        return collection.select{|e| filter.include?( e[attribute] ) }
+        return collection.select{|e| filter.include?( e.send(method) ) }
       else
-        return collection.select{|e| filter == e[attribute] }
+        return collection.select{|e| puts e.send( method ) ; filter == e.send(method) }
       end
     end
   end



Mime
View raw message