incubator-deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@apache.org
Subject svn commit: r1153087 - in /incubator/deltacloud/trunk/server: deltacloud.rb lib/deltacloud/helpers/application_helper.rb lib/deltacloud/models/instance.rb
Date Tue, 02 Aug 2011 10:06:05 GMT
Author: mfojtik
Date: Tue Aug  2 10:06:04 2011
New Revision: 1153087

URL: http://svn.apache.org/viewvc?rev=1153087&view=rev
Log:
Added address type to JSON output

Modified:
    incubator/deltacloud/trunk/server/deltacloud.rb
    incubator/deltacloud/trunk/server/lib/deltacloud/helpers/application_helper.rb
    incubator/deltacloud/trunk/server/lib/deltacloud/models/instance.rb

Modified: incubator/deltacloud/trunk/server/deltacloud.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/deltacloud.rb?rev=1153087&r1=1153086&r2=1153087&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/deltacloud.rb (original)
+++ incubator/deltacloud/trunk/server/deltacloud.rb Tue Aug  2 10:06:04 2011
@@ -23,7 +23,7 @@ require 'deltacloud/core_ext'
 require 'deltacloud/base_driver'
 require 'deltacloud/hardware_profile'
 require 'deltacloud/state_machine'
-
+require 'deltacloud/helpers'
 require 'deltacloud/models/base_model'
 require 'deltacloud/models/realm'
 require 'deltacloud/models/image'
@@ -40,5 +40,4 @@ require 'deltacloud/models/firewall'
 require 'deltacloud/models/firewall_rule'
 
 require 'deltacloud/validation'
-require 'deltacloud/helpers'
 require 'deltacloud/runner'

Modified: incubator/deltacloud/trunk/server/lib/deltacloud/helpers/application_helper.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/deltacloud/helpers/application_helper.rb?rev=1153087&r1=1153086&r2=1153087&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/deltacloud/helpers/application_helper.rb (original)
+++ incubator/deltacloud/trunk/server/lib/deltacloud/helpers/application_helper.rb Tue Aug
 2 10:06:04 2011
@@ -247,14 +247,17 @@ module ApplicationHelper
     end
   end
 
+  def address_type(address)
+    case address
+      when /^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})?$/; :ipv4
+      when /^(\S{1,2}:\S{1,2}:\S{1,2}:\S{1,2}:\S{1,2}:\S{1,2})?$/; :mac
+      else :hostname
+    end
+  end
+
   def format_address(address, opts={})
-    address_type = case address
-                    when /^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})?$/; :ipv4
-                    when /^(\S{1,2}:\S{1,2}:\S{1,2}:\S{1,2}:\S{1,2}:\S{1,2})?$/; :mac
-                    else :hostname
-                  end
     capture_haml do
-      haml_tag :address, { :type => address_type }.merge(opts) do
+      haml_tag :address, { :type => address_type(address) }.merge(opts) do
         haml_concat address
       end
     end

Modified: incubator/deltacloud/trunk/server/lib/deltacloud/models/instance.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/deltacloud/models/instance.rb?rev=1153087&r1=1153086&r2=1153087&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/deltacloud/models/instance.rb (original)
+++ incubator/deltacloud/trunk/server/lib/deltacloud/models/instance.rb Tue Aug  2 10:06:04
2011
@@ -16,6 +16,8 @@
 
 class Instance < BaseModel
 
+  include ApplicationHelper
+
   attr_accessor :owner_id
   attr_accessor :image_id
   attr_accessor :name
@@ -72,6 +74,9 @@ class Instance < BaseModel
 
   def to_hash
     h = self.to_hash_original
+    h[:public_addresses] = h[:public_addresses].collect do |address|
+      { :address => { :type => address_type(address), :value => address } }
+    end
     h[:actions] = self.actions.collect do |action|
       { :"#{action}" => {
         :method => collections[:instances].operations[action.to_sym].method,



Mime
View raw message