From: Michal Fojtik <[email protected]>
Signed-off-by: Michal fojtik <[email protected]> --- .../lib/deltacloud/helpers/application_helper.rb | 14 ++++++++++++++ server/tests/drivers/mock/instances_test.rb | 2 ++ server/views/instances/show.xml.haml | 9 +++------ tests/ec2/instances.feature | 1 + tests/ec2/step_definitions/instances_steps.rb | 7 +++++++ 5 files changed, 27 insertions(+), 6 deletions(-) diff --git a/server/lib/deltacloud/helpers/application_helper.rb b/server/lib/deltacloud/helpers/application_helper.rb index 527aac4..b837308 100644 --- a/server/lib/deltacloud/helpers/application_helper.rb +++ b/server/lib/deltacloud/helpers/application_helper.rb @@ -219,4 +219,18 @@ module ApplicationHelper end result 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_concat address + end + end + end + end diff --git a/server/tests/drivers/mock/instances_test.rb b/server/tests/drivers/mock/instances_test.rb index 3e922d3..0e97c19 100644 --- a/server/tests/drivers/mock/instances_test.rb +++ b/server/tests/drivers/mock/instances_test.rb @@ -197,10 +197,12 @@ module DeltacloudUnitTest (instance/'public_addreses').should_not == nil (instance/'public_addresses/address').to_a.size.should > 0 (instance/'public_addresses/address').first.text.should_not == "" + (instance/'public_addresses/address').first[:type].should == "hostname" (instance/'private_addresses').should_not == nil (instance/'private_addresses/address').to_a.size.should > 0 (instance/'private_addresses/address').first.text.should_not == "" + (instance/'private_addresses/address').first[:type].should == "hostname" (instance/'actions/link').to_a.size.should > 0 (instance/'actions/link').each do |link| diff --git a/server/views/instances/show.xml.haml b/server/views/instances/show.xml.haml index 5fd85fc..27f04a6 100644 --- a/server/views/instances/show.xml.haml +++ b/server/views/instances/show.xml.haml @@ -33,16 +33,13 @@ %public_addresses< - @instance.public_addresses.each do |address| - if address.class.eql?(Hash) and address[:address]!="" - %address{ :port => address[:port], :type => address[:type], :mac => address[:mac] }< - =address[:address] + =format_address(address[:address], :port => address[:port], :type => address[:type], :mac => address[:mac]) - elsif address.class.eql?(String) - %address< - =address + =format_address(address) - if @instance.private_addresses %private_addresses< - @instance.private_addresses.each do |address| - %address< - =address + =format_address(address) - if @instance.firewalls %firewalls< - @instance.firewalls.each do |firewall| diff --git a/tests/ec2/instances.feature b/tests/ec2/instances.feature index bbbfcb1..f298fd7 100644 --- a/tests/ec2/instances.feature +++ b/tests/ec2/instances.feature @@ -72,6 +72,7 @@ Feature: Managing instances | state | RUNNING | Then client should get some instances And each instance should have 'state' element set to 'RUNNING' + And each instance should have address type set to "hostname" Scenario: Get details about first instance Given URI /api/instances exists diff --git a/tests/ec2/step_definitions/instances_steps.rb b/tests/ec2/step_definitions/instances_steps.rb index 142e756..80474c9 100644 --- a/tests/ec2/step_definitions/instances_steps.rb +++ b/tests/ec2/step_definitions/instances_steps.rb @@ -64,6 +64,13 @@ Then /^this instance should be in '(.+)' state$/ do |state| output_xml.xpath('/instance/state').first.text.should == state end +Then /^each instance should have address type set to "([^"]*)"$/ do |t| + puts output_xml + output_xml.xpath('/instances/instance/public_addresses/address').first[:type].should == t + output_xml.xpath('/instances/instance/private_addresses/address').first[:type].should == t +end + + When /^client want to create a new instance$/ do end -- 1.7.4.1
