incubator-deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lut...@redhat.com
Subject [PATCH 4/7] cimi: do not hardcode toplevel URL, instead use api_url_for
Date Mon, 10 Oct 2011 23:16:39 GMT
From: David Lutterkort <lutter@redhat.com>


Signed-off-by: David Lutterkort <lutter@redhat.com>
---
 server/lib/cimi/helpers/dmtfdep.rb                 |    1 -
 server/lib/cimi/server.rb                          |   21 ++++++++-----------
 server/views/cimi/cloudEntryPoint/index.html.haml  |    9 +++----
 server/views/cimi/cloudEntryPoint/index.xml.haml   |    4 +-
 server/views/cimi/collection/index.html.haml       |    4 +-
 server/views/cimi/machine/show.html.haml           |    4 +-
 .../cimi/machine_configuration/show.html.haml      |    4 +-
 server/views/cimi/machine_image/show.html.haml     |    4 +-
 server/views/cimi/volume/show.html.haml            |    4 +-
 9 files changed, 25 insertions(+), 30 deletions(-)

diff --git a/server/lib/cimi/helpers/dmtfdep.rb b/server/lib/cimi/helpers/dmtfdep.rb
index 2063d4f..95f9b94 100644
--- a/server/lib/cimi/helpers/dmtfdep.rb
+++ b/server/lib/cimi/helpers/dmtfdep.rb
@@ -64,7 +64,6 @@ require 'sinatra/sinatra_verbose'
 
 #The following section defines all the global variables needed for the implementation.
 
-HOST_API_PATH="http://#{ENV["API_HOST"]}:#{ENV["API_PORT"]}/api"
 CMWG_NAMESPACE = "http://www.dmtf.org/cimi"
 XS_NAMESPACE = "http://www.w3.org/2001/XMLSchema"
 HEADER_API_VERSION = "1.0"
diff --git a/server/lib/cimi/server.rb b/server/lib/cimi/server.rb
index f8d721d..92e4d43 100644
--- a/server/lib/cimi/server.rb
+++ b/server/lib/cimi/server.rb
@@ -71,9 +71,6 @@ error do
   report_error
 end
 
-#spill out the root of the application when the application starts
-puts "application root URL:" + HOST_API_PATH
-
 get "#{settings.root_url}\/?" do
   if params[:force_auth]
     return [401, 'Authentication failed'] unless driver.valid_credentials?(credentials)
@@ -90,7 +87,7 @@ EOS
   operation :index do
     description "list all resources of the cloud"
     control do
-      @all_apis = CIMI_RESOURCES
+      @collections = entry_points.reject { |p| p[0] == :cloudEntryPoint }
       show_resource "cloudEntryPoint/index", "CloudEntryPoint"
     end
   end
@@ -110,7 +107,7 @@ EOS
       @dmtf_col_items = []
       if profiles
         profiles.map do |profile|
-          new_item = { "name" => profile.name, "href" => HOST_API_PATH + "/machine_configuration/"
+ profile.name }
+          new_item = { "name" => profile.name, "href" => api_url_for("/machine_configuration/"
+ profile.name) }
           @dmtf_col_items.insert 0,  new_item
         end
       end
@@ -129,7 +126,7 @@ EOS
         resource_default = get_resource_default "machine_configuration"
         #get the actual values from profile
         resource_value = { "name" => @profile.name,"uri" => @profile.name,
-              "href" => HOST_API_PATH + "/machine_configuration/" + @profile.name }
+              "href" => api_url_for("/machine_configuration/" + @profile.name) }
         #mixin actual values get from profile
         @dmtfitem = resource_default["dmtfitem"].merge resource_value
         show_resource "machine_configuration/show", "MachineConfiguration"
@@ -154,7 +151,7 @@ EOS
       @dmtf_col_items = []
       if images
         images.map do |image|
-          new_item = { "name" => image.name,"href" => HOST_API_PATH + "/machine_image/"
+ image.id }
+          new_item = { "name" => image.name,"href" => api_url_for("/machine_image/"
+ image.id) }
           @dmtf_col_items.insert 0,  new_item
         end
       end
@@ -173,7 +170,7 @@ EOS
         resource_default = get_resource_default "machine_image"
         #get the actual values from image
         resource_value = { "name" => @image.name,"description" => @image.description,
-             "uri" => @image.id,"href" => HOST_API_PATH + "/machine_image/" + @image.id
}
+             "uri" => @image.id,"href" => api_url_for("/machine_image/" + @image.id)
}
         #mixin actual values get from the specific image
         @dmtfitem = resource_default["dmtfitem"].merge resource_value
         show_resource "machine_image/show", "MachineImage"
@@ -199,7 +196,7 @@ EOS
       @dmtf_col_items = []
       if instances
         instances.map do |instance|
-          new_item = { "name" => instance.name, "href" => HOST_API_PATH + "/machine/"
+ instance.id }
+          new_item = { "name" => instance.name, "href" => api_url_for("/machine/" +
instance.id) }
           @dmtf_col_items.insert 0,  new_item
         end
       end
@@ -218,7 +215,7 @@ EOS
         resource_default = get_resource_default "machine"
         #get the actual values from image
         resource_value = { "name" => @machine.name,"status" => @machine.state, "uri"
=> @machine.id,
-              "href" => HOST_API_PATH + "/machine/" + @machine.id }
+              "href" => api_url_for("/machine/" + @machine.id) }
         #mixin actual values get from the specific image
         @dmtfitem = resource_default["dmtfitem"].merge resource_value
         show_resource "machine/show", "Machine"
@@ -244,7 +241,7 @@ EOS
       @dmtf_col_items = []
       if instances
         instances.map do |instance|
-          new_item = { "name" => instance.id, "href" => HOST_API_PATH + "/volume/"
+ instance.id }
+          new_item = { "name" => instance.id, "href" => api_url_for("/volume/" + instance.id)
}
           @dmtf_col_items.insert 0,  new_item
         end
       end
@@ -263,7 +260,7 @@ EOS
         resource_default = get_resource_default "volume"
         #get the actual values from image
         resource_value = { "name" => @volume.id,"status" => @volume.state, "uri" =>
@volume.id,
-              "href" => HOST_API_PATH + "/volume/" + @volume.id,
+              "href" => api_url_for("/volume/" + @volume.id),
               "capacity" => { "quantity" => @volume.capacity, "units" => "gigabyte"}
}
         #mixin actual values get from the specific image
         @dmtfitem = resource_default["dmtfitem"].merge resource_value
diff --git a/server/views/cimi/cloudEntryPoint/index.html.haml b/server/views/cimi/cloudEntryPoint/index.html.haml
index 8645d78..76f147b 100644
--- a/server/views/cimi/cloudEntryPoint/index.html.haml
+++ b/server/views/cimi/cloudEntryPoint/index.html.haml
@@ -1,6 +1,5 @@
 
-- @all_apis.each do |api|
-  - if api != :cloudEntryPoint
-    - display_name = api.to_s.pluralize.gsub(/[A-Z]/, ' \0')
-    - path_name = api.to_s.gsub(/[A-Z]/, '_\0').downcase
-    %a{ :href => '/cimi/'+path_name }= display_name.capitalize + '<br/>'
\ No newline at end of file
+- @collections.each do |p|
+  - name, path = p
+  = link_to name.to_s.capitalize, path
+  %br/
diff --git a/server/views/cimi/cloudEntryPoint/index.xml.haml b/server/views/cimi/cloudEntryPoint/index.xml.haml
index 4643a8c..a8f0fce 100644
--- a/server/views/cimi/cloudEntryPoint/index.xml.haml
+++ b/server/views/cimi/cloudEntryPoint/index.xml.haml
@@ -1,10 +1,10 @@
 !!!XML
 %CloudEntryPoint{ :xmlns => CMWG_NAMESPACE }
-  %uri=HOST_API_PATH + "/cloudEntryPoint"
+  %uri= api_url_for("/cloudEntryPoint")
   %name cloud entry point
   %description cloud entry point
   %created= Time.new.getutc.to_s
   - @all_apis.each do |api|
     - if api != :cloudEntryPoint
       - path_name = api.to_s.gsub(/[A-Z]/, '_\0').downcase
-      = "<#{api.to_s.pluralize} href=\"#{HOST_API_PATH + "/" + path_name}\"/>"
\ No newline at end of file
+      = "<#{api.to_s.pluralize} href=\"#{api_url_for(path_name)}\"/>"
\ No newline at end of file
diff --git a/server/views/cimi/collection/index.html.haml b/server/views/cimi/collection/index.html.haml
index ae747ab..0860f5f 100644
--- a/server/views/cimi/collection/index.html.haml
+++ b/server/views/cimi/collection/index.html.haml
@@ -2,7 +2,7 @@
 - new_name = new_name.gsub(/[A-Z]/, ' \0')
 %h1 #{new_name.capitalize}
 
-%form{ :action => HOST_API_PATH + "/collection/" + @dmtfitem["uri"] }
+%form{ :action => api_url_for("/collection/" + @dmtfitem["uri"]) }
   %input{ :name => :id, :type => :hidden, :value => @dmtfitem["uri"] }/
   %input{ :name => :xmlRootNode, :type => :hidden, :value => @xml_root_node }/
   %p
@@ -28,7 +28,7 @@
         - iter += 1
         %br
         %label
-          = operation["rel"].capitalize + ":&nbsp;" + HOST_API_PATH + operation["href"]
+          = operation["rel"].capitalize + ":&nbsp;" + api_url_for(operation["href"])
           %input{ :name => "operation_"+iter.to_s, :oper_type => operation["rel"],
:type => :hidden, :value => operation["href"] }
   %br
 %p
diff --git a/server/views/cimi/machine/show.html.haml b/server/views/cimi/machine/show.html.haml
index 07eb358..5945c6a 100644
--- a/server/views/cimi/machine/show.html.haml
+++ b/server/views/cimi/machine/show.html.haml
@@ -1,9 +1,9 @@
 %h1 View/Edit machine
 
-%form{ :action => HOST_API_PATH + "/machine" }
+%form{ :action => api_url_for("/machine") }
   %input{ :name => :id, :type => :hidden, :value => @dmtfitem["uri"] }/
   %input{ :name => :xmlRootNode, :type => :hidden, :value => @xml_root_node }/
-  %input{ :name => :refreshURI, :type => :hidden, :value => HOST_API_PATH + "/machine"
}/
+  %input{ :name => :refreshURI, :type => :hidden, :value => api_url_for("/machine")
}/
   %p
     %label
       Name:
diff --git a/server/views/cimi/machine_configuration/show.html.haml b/server/views/cimi/machine_configuration/show.html.haml
index cb0fbe7..7db4b5b 100644
--- a/server/views/cimi/machine_configuration/show.html.haml
+++ b/server/views/cimi/machine_configuration/show.html.haml
@@ -1,9 +1,9 @@
 %h1 View/Edit machine configuration
 
-%form{ :action => HOST_API_PATH + "/machineConfiguration" }
+%form{ :action => api_url_for("/machineConfiguration") }
   %input{ :name => :id, :type => :hidden, :value => @dmtfitem["uri"] }/
   %input{ :name => :xmlRootNode, :type => :hidden, :value => @xml_root_node }/
-  %input{ :name => :refreshURI, :type => :hidden, :value => HOST_API_PATH + "/collection/machineConfiguration"
}/
+  %input{ :name => :refreshURI, :type => :hidden, :value => api_url_for("/collection/machineConfiguration")
}/
   %p
     %label
       Name:
diff --git a/server/views/cimi/machine_image/show.html.haml b/server/views/cimi/machine_image/show.html.haml
index 5fdbca8..3ab9e5f 100644
--- a/server/views/cimi/machine_image/show.html.haml
+++ b/server/views/cimi/machine_image/show.html.haml
@@ -1,9 +1,9 @@
 %h1 View/Edit machine image
 
-%form{ :action => HOST_API_PATH + "/machineImage" }
+%form{ :action => api_url_for("/machineImage") }
   %input{ :name => :id, :type => :hidden, :value => @dmtfitem["uri"] }/
   %input{ :name => :xmlRootNode, :type => :hidden, :value => @xml_root_node }/
-  %input{ :name => :refreshURI, :type => :hidden, :value => HOST_API_PATH + "/collection/machineImage"
}/
+  %input{ :name => :refreshURI, :type => :hidden, :value => api_url_for("/collection/machineImage")
}/
   %p
     %label
       Name:
diff --git a/server/views/cimi/volume/show.html.haml b/server/views/cimi/volume/show.html.haml
index 9c688ab..2dcf1e8 100644
--- a/server/views/cimi/volume/show.html.haml
+++ b/server/views/cimi/volume/show.html.haml
@@ -1,9 +1,9 @@
 %h1 View/Edit volume
 
-%form{ :action => HOST_API_PATH + "/volume" }
+%form{ :action => api_url_for("/volume") }
   %input{ :name => :id, :type => :hidden, :value => @dmtfitem["uri"] }/
   %input{ :name => :xmlRootNode, :type => :hidden, :value => @xml_root_node }/
-  %input{ :name => :refreshURI, :type => :hidden, :value => HOST_API_PATH + "/volume"
}/
+  %input{ :name => :refreshURI, :type => :hidden, :value => api_url_for("/volume")
}/
   %p
     %label
       Name:
-- 
1.7.6


Mime
View raw message