incubator-deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@redhat.com
Subject [PATCH core 4/8] CIMI: Revamped server.rb to use helpers from the new CMWG helper. Removed @dtmf_item variable and XML hacking.
Date Thu, 27 Oct 2011 11:17:24 GMT
From: Michal Fojtik <mfojtik@redhat.com>


Signed-off-by: Michal fojtik <mfojtik@redhat.com>
---
 server/lib/cimi/server.rb                          |  136 ++++++--------------
 server/views/cimi/cloudEntryPoint/index.html.haml  |    5 -
 server/views/cimi/cloudEntryPoint/index.xml.haml   |    9 --
 .../views/cimi/cloud_entry_point/index.html.haml   |    5 +
 server/views/cimi/cloud_entry_point/index.xml.haml |    9 ++
 5 files changed, 53 insertions(+), 111 deletions(-)
 delete mode 100644 server/views/cimi/cloudEntryPoint/index.html.haml
 delete mode 100644 server/views/cimi/cloudEntryPoint/index.xml.haml
 create mode 100644 server/views/cimi/cloud_entry_point/index.html.haml
 create mode 100644 server/views/cimi/cloud_entry_point/index.xml.haml

diff --git a/server/lib/cimi/server.rb b/server/lib/cimi/server.rb
index d995f34..90d2b67 100644
--- a/server/lib/cimi/server.rb
+++ b/server/lib/cimi/server.rb
@@ -15,7 +15,7 @@
 
 
 require 'cimi/helpers/dmtfdep'
-require 'cimi/helpers/cmwgapp_helper'
+require 'cimi/helpers/cmwg_helper'
 
 set :version, '0.1.0'
 
@@ -82,8 +82,8 @@ global_collection  :cloudEntryPoint do
   operation :index do
     description "list all resources of the cloud"
     control do
-      @collections = entry_points.reject { |p| p[0] == :cloudEntryPoint }
-      show_resource "cloudEntryPoint/index", "CloudEntryPoint"
+      @resources = entry_points.reject { |p| p[0] == :cloudEntryPoint }
+      render_collection :cloud_entry_point
     end
   end
 end
@@ -94,16 +94,15 @@ global_collection :machine_configurations do
   operation :index do
     description "List all machine configurations"
     control do
-      profiles = driver.hardware_profiles(credentials, nil)
-      @dmtf_col_items = []
-      if profiles
-        profiles.map do |profile|
-          new_item = { "name" => profile.name,
-            "href" => machine_configuration_url(profile.name) }
-          @dmtf_col_items.insert 0,  new_item
-        end
+      profiles = driver.hardware_profiles(credentials)
+      @resources = []
+      profiles.each do |profile|
+        @resources << {
+          :name => profile.name,
+          :href => machine_configuration_url(profile.name)
+        }
       end
-      respond_to_collection "machine_configuration.col.xml"
+      render_collection :machine_configuration
     end
   end
 
@@ -112,20 +111,7 @@ global_collection :machine_configurations do
     with_capability :hardware_profile
     param :id,          :string,    :required
     control do
-      @profile =  driver.hardware_profile(credentials, params[:id])
-      if @profile
-        #setup the default values for a machine configuration
-        resource_default = get_resource_default "machine_configuration"
-        #get the actual values from profile
-        resource_value = { "name" => @profile.name,"uri" => @profile.name,
-              "href" => machine_configuration_url(@profile.name) }
-        #mixin actual values get from profile
-        @dmtfitem = resource_default["dmtfitem"].merge resource_value
-        show_resource "machine_configurations/show", "MachineConfiguration",
-          {"property" => "properties", "disk" => "disks", "operation" => "operations"}
-      else
-        report_error(404)
-      end
+      render_resource :machine_configuration, driver.hardware_profile(credentials, params[:id])
     end
   end
 end
@@ -137,15 +123,14 @@ global_collection :machine_images do
     description "List all machine configurations"
     control do
       images = driver.send(:images, credentials, {})
-      @dmtf_col_items = []
-      if images
-        images.map do |image|
-          new_item = { "name" => image.name,
-            "href" => machine_image_url(image.id) }
-          @dmtf_col_items.insert 0,  new_item
-        end
+      @resources = []
+      images.each do |image|
+        @resources << {
+          :name => image.name,
+          :href => machine_image_url(image.id)
+        }
       end
-      respond_to_collection "machine_image.col.xml"
+      render_collection :machine_image
     end
   end
 
@@ -154,21 +139,7 @@ global_collection :machine_images do
     with_capability :image
     param :id,          :string,    :required
     control do
-      @image = driver.send(:image, credentials, { :id => params[:id]} )
-      if @image
-        #setup the default values for a machine imageion
-        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" => machine_image_url(@image.id) }
-        #mixin actual values get from the specific image
-        @dmtfitem = resource_default["dmtfitem"].merge resource_value
-        show_resource "machine_images/show", "MachineImage",
-          {"property" => "properties", "operation" => "operations"}
-      else
-        report_error(404)
-      end
+      render_resource :machine_image, driver.image(credentials, { :id => params[:id]}
)
     end
   end
 
@@ -181,15 +152,14 @@ global_collection :machines do
     description "List all machines"
     control do
       instances = driver.send(:instances, credentials, {})
-      @dmtf_col_items = []
-      if instances
-        instances.map do |instance|
-          new_item = { "name" => instance.name,
-            "href" => machine_url(instance.id) }
-          @dmtf_col_items.insert 0,  new_item
-        end
+      @resources = []
+      instances.each do |instance|
+        @resources << {
+          :name => instance.name,
+          :href => machine_url(instance.id)
+        }
       end
-      respond_to_collection "machine.col.xml"
+      render_collection :machine
     end
   end
 
@@ -198,21 +168,9 @@ global_collection :machines do
     with_capability :instance
     param :id,          :string,    :required
     control do
-      @machine = driver.send(:instance, credentials, { :id => params[:id]} )
-      if @machine
-        #setup the default values for a machine imageion
-        resource_default = get_resource_default "machine"
-        #get the actual values from image
-        resource_value = { "name" => @machine.name,
-          "status" => @machine.state, "uri" => @machine.id,
-          "href" => machine_url(@machine.id) }
-        #mixin actual values get from the specific image
-        @dmtfitem = resource_default["dmtfitem"].merge resource_value
-        show_resource "machines/show", "Machine",
-          {"property" => "properties", "disk" => "disks", "operation" => "operations"}
-      else
-        report_error(404)
-      end
+      instance = driver.send(:instance, credentials, { :id => params[:id]} )
+      profile = driver.send(:hardware_profile, credentials, instance.instance_profile.id)
+      render_resource :machine, instance, { :profile => profile }
     end
   end
 
@@ -224,16 +182,15 @@ global_collection :volumes do
   operation :index do
     description "List all volumes"
     control do
-      instances = driver.send(:storage_volumes, credentials, {})
-      @dmtf_col_items = []
-      if instances
-        instances.map do |instance|
-          new_item = { "name" => instance.id,
-            "href" => volume_url(instance.id) }
-          @dmtf_col_items.insert 0,  new_item
-        end
+      volumes = driver.send(:storage_volumes, credentials, {})
+      @resources = []
+      volumes.each do |volume|
+        @resources << {
+          :name => volume.name,
+          :href => machine_url(volume.id)
+        }
       end
-      respond_to_collection "volume.col.xml"
+      render_collection :volume
     end
   end
 
@@ -242,22 +199,7 @@ global_collection :volumes do
     with_capability :storage_volume
     param :id,          :string,    :required
     control do
-      @volume = driver.send(:storage_volume, credentials, { :id => params[:id]} )
-      if @volume
-        #setup the default values for a machine imageion
-        resource_default = get_resource_default "volume"
-        #get the actual values from image
-        resource_value = { "name" => @volume.id,
-          "status" => @volume.state, "uri" => @volume.id,
-          "href" => volume_url(@volume.id),
-          "capacity" => { "quantity" => @volume.capacity, "units" => "gigabyte"}
}
-        #mixin actual values get from the specific image
-        @dmtfitem = resource_default["dmtfitem"].merge resource_value
-        show_resource "volumes/show", "Volume",
-          {"property" => "properties", "operation" => "operations"}
-      else
-        report_error(404)
-      end
+      render_resource :volume, driver.send(:storage_volume, credentials, { :id => params[:id]}
)
     end
   end
 
diff --git a/server/views/cimi/cloudEntryPoint/index.html.haml b/server/views/cimi/cloudEntryPoint/index.html.haml
deleted file mode 100644
index 76f147b..0000000
--- a/server/views/cimi/cloudEntryPoint/index.html.haml
+++ /dev/null
@@ -1,5 +0,0 @@
-
-- @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
deleted file mode 100644
index 784b931..0000000
--- a/server/views/cimi/cloudEntryPoint/index.xml.haml
+++ /dev/null
@@ -1,9 +0,0 @@
-!!!XML
-%CloudEntryPoint{ :xmlns => CMWG_NAMESPACE }
-  %uri= api_url_for("/cloudEntryPoint")
-  %name cloud entry point
-  %description cloud entry point
-  %created= Time.new.getutc.to_s
-  - @collections.each do |api|
-    - res_name = api[0].to_s.camelize(:lower_case_first_letter)
-    = "<#{res_name} href=\"#{api[1]}\"/>"
diff --git a/server/views/cimi/cloud_entry_point/index.html.haml b/server/views/cimi/cloud_entry_point/index.html.haml
new file mode 100644
index 0000000..5375bd0
--- /dev/null
+++ b/server/views/cimi/cloud_entry_point/index.html.haml
@@ -0,0 +1,5 @@
+
+- @resources.each do |p|
+  - name, path = p
+  = link_to name.to_s.capitalize, path
+  %br/
diff --git a/server/views/cimi/cloud_entry_point/index.xml.haml b/server/views/cimi/cloud_entry_point/index.xml.haml
new file mode 100644
index 0000000..8555a4b
--- /dev/null
+++ b/server/views/cimi/cloud_entry_point/index.xml.haml
@@ -0,0 +1,9 @@
+!!!XML
+%CloudEntryPoint{ :xmlns => CMWG_NAMESPACE }
+  %uri= api_url_for("/cloudEntryPoint")
+  %name cloud entry point
+  %description cloud entry point
+  %created= Time.new.getutc.to_s
+  - @resources.each do |api|
+    - res_name = api[0].to_s.camelize(:lower_case_first_letter)
+    = "<#{res_name} href=\"#{api[1]}\"/>"
-- 
1.7.4.4


Mime
View raw message