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 2011/11/02 15:05:32 UTC

[PATCH core 4/4] Core: Updated views to support InstanceAddress. Get rid of address type guessing and formating

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


Signed-off-by: Michal fojtik <mf...@redhat.com>
---
 .../lib/deltacloud/helpers/application_helper.rb   |   25 --------------------
 server/views/instances/show.html.haml              |    4 +-
 server/views/instances/show.xml.haml               |   11 +++-----
 3 files changed, 6 insertions(+), 34 deletions(-)

diff --git a/server/lib/deltacloud/helpers/application_helper.rb b/server/lib/deltacloud/helpers/application_helper.rb
index 859129a..d44f108 100644
--- a/server/lib/deltacloud/helpers/application_helper.rb
+++ b/server/lib/deltacloud/helpers/application_helper.rb
@@ -248,31 +248,6 @@ module ApplicationHelper
     end
   end
 
-  # FIXME: It would be cleaner if we stored the type of address explicitly in
-  # public_addresses instead of guessing it; especially since now a RHEV-M
-  # vnc address in theory could look like type ipv4.
-  #
-  # Instead of pushing just the address onto public_addresses, we should
-  # just push a pair [type, address], i.e. [:vnc, "172.16.0.1"] or a hash
-  # { :vnc => "172.16.0.1" }
-  #
-  def address_type(address)
-    case address
-      when /^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})?$/; :ipv4
-      when /^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:[\-\d]+)$/; :vnc
-      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={})
-    capture_haml do
-      haml_tag :address, { :type => address_type(address) }.merge(opts) do
-        haml_concat address
-      end
-    end
-  end
-
   def translate_error_code(code)
     case code
       when 400; { :message => "Bad Request" }
diff --git a/server/views/instances/show.html.haml b/server/views/instances/show.html.haml
index 63286e8..6891f1b 100644
--- a/server/views/instances/show.html.haml
+++ b/server/views/instances/show.html.haml
@@ -28,10 +28,10 @@
         default
     %li{ :'data-role' => 'list-divider'} Public addresses
     %li
-      %p{ :'data-role' => 'fieldcontain'}=@instance.public_addresses.map.join(',')
+      %p{ :'data-role' => 'fieldcontain'}=@instance.public_addresses.join(',')
     %li{ :'data-role' => 'list-divider'} Private addresses
     %li
-      %p{ :'data-role' => 'fieldcontain'}=@instance.private_addresses.map.join(',')
+      %p{ :'data-role' => 'fieldcontain'}=@instance.private_addresses.join(',')
     - if @instance.password or @instance.keyname
       %li{ :'data-role' => 'list-divider'} Authentication
     - if @instance.password
diff --git a/server/views/instances/show.xml.haml b/server/views/instances/show.xml.haml
index ab60fb7..5b929f4 100644
--- a/server/views/instances/show.xml.haml
+++ b/server/views/instances/show.xml.haml
@@ -31,15 +31,12 @@
       =@instance.launch_time
   - if @instance.public_addresses
     %public_addresses<
-      - @instance.public_addresses.each do |address|
-        - if address.class.eql?(Hash) and address[:address]!=""
-          =format_address(address[:address], :port => address[:port], :type => address[:type], :mac => address[:mac])
-        - elsif address.class.eql?(String)
-          =format_address(address)
+      - @instance.public_addresses.each do |a|
+        %address{ :type => a.address_type, :port => a.port }=a.address
   - if @instance.private_addresses
     %private_addresses<
-      - @instance.private_addresses.each do |address|
-        =format_address(address)
+      - @instance.private_addresses.each do |a|
+        %address{ :type => a.address_type, :port => a.port }=a.address
   - if @instance.firewalls
     %firewalls<
       - @instance.firewalls.each do |firewall|
-- 
1.7.4.4