incubator-deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@apache.org
Subject svn commit: r1188737 - in /incubator/deltacloud/trunk/server: lib/cimi/ lib/cimi/data/collections/ lib/cimi/data/default_res/ lib/cimi/helpers/ views/cimi/machine_configurations/ views/cimi/machine_images/ views/cimi/machines/ views/cimi/volume/ views/...
Date Tue, 25 Oct 2011 15:46:19 GMT
Author: mfojtik
Date: Tue Oct 25 15:46:19 2011
New Revision: 1188737

URL: http://svn.apache.org/viewvc?rev=1188737&view=rev
Log:
cimi xml/json support for individual cimi resources

Added:
    incubator/deltacloud/trunk/server/views/cimi/machine_configurations/show.xml.haml
    incubator/deltacloud/trunk/server/views/cimi/machine_images/show.xml.haml
    incubator/deltacloud/trunk/server/views/cimi/machines/show.xml.haml
    incubator/deltacloud/trunk/server/views/cimi/volumes/
    incubator/deltacloud/trunk/server/views/cimi/volumes/show.html.haml
      - copied, changed from r1188696, incubator/deltacloud/trunk/server/views/cimi/volume/show.html.haml
    incubator/deltacloud/trunk/server/views/cimi/volumes/show.xml.haml
Removed:
    incubator/deltacloud/trunk/server/views/cimi/volume/show.html.haml
Modified:
    incubator/deltacloud/trunk/server/lib/cimi/data/collections/machine_image.col.xml
    incubator/deltacloud/trunk/server/lib/cimi/data/default_res/machine_configuration.col.xml
    incubator/deltacloud/trunk/server/lib/cimi/helpers/cmwgapp_helper.rb
    incubator/deltacloud/trunk/server/lib/cimi/server.rb

Modified: incubator/deltacloud/trunk/server/lib/cimi/data/collections/machine_image.col.xml
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/cimi/data/collections/machine_image.col.xml?rev=1188737&r1=1188736&r2=1188737&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/cimi/data/collections/machine_image.col.xml (original)
+++ incubator/deltacloud/trunk/server/lib/cimi/data/collections/machine_image.col.xml Tue
Oct 25 15:46:19 2011
@@ -1,8 +1,8 @@
 <?xml version='1.0' encoding='utf-8' ?>
 <MachineImageCollection xmlns="http://www.dmtf.org/cimi">
  <uri>machineImage</uri>
- <name>Machine Config collection </name>
- <description>The machine config collection</description>
+ <name>Machine Image collection </name>
+ <description>The machine image collection</description>
  <created>2011-09-12 11:37:28 UTC</created>
  <operation rel="add" href="/machine_images" />
 </MachineImageCollection>

Modified: incubator/deltacloud/trunk/server/lib/cimi/data/default_res/machine_configuration.col.xml
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/cimi/data/default_res/machine_configuration.col.xml?rev=1188737&r1=1188736&r2=1188737&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/cimi/data/default_res/machine_configuration.col.xml
(original)
+++ incubator/deltacloud/trunk/server/lib/cimi/data/default_res/machine_configuration.col.xml
Tue Oct 25 15:46:19 2011
@@ -10,6 +10,10 @@
     <capacity quantity="200" units="gigabyte"/>
     <guestInterface>SATA</guestInterface>
   </disk>
+  <disk>
+    <capacity quantity="100" units="gigabyte"/>
+    <guestInterface>SATA</guestInterface>
+  </disk>
   <supportsSnapshots>false</supportsSnapshots>
   <guestInterface>http://www.ibm.com</guestInterface>
   <operation rel="edit" href="/machine_configuration"/>

Modified: incubator/deltacloud/trunk/server/lib/cimi/helpers/cmwgapp_helper.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/cimi/helpers/cmwgapp_helper.rb?rev=1188737&r1=1188736&r2=1188737&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/cimi/helpers/cmwgapp_helper.rb (original)
+++ incubator/deltacloud/trunk/server/lib/cimi/helpers/cmwgapp_helper.rb Tue Oct 25 15:46:19
2011
@@ -121,7 +121,7 @@ module ApplicationHelper
     end
   end
 
-  def show_resource(resource_path, content_type)
+  def show_resource(resource_path, content_type, replace_keys = nil)
     respond_to do |format|
       format.xml do
         content_type "application/CIMI-#{content_type}+xml", :charset => 'utf-8'
@@ -139,8 +139,28 @@ module ApplicationHelper
         if hash_response.has_key?("xmlns")
           hash_response.delete "xmlns"
         end
+        if replace_keys
+          replace_key!(hash_response, replace_keys)
+        end
         hash_response.to_json
       end
     end
   end
+
+  def replace_key!(an_object, key_maps = nil)
+    if an_object.kind_of?(Hash)
+      key_maps.each do |key, value|
+        if an_object.key?(key)
+          an_object[value] = an_object.delete(key)
+        end
+      end
+      an_object.each do |key, value|
+        replace_key!(value, key_maps)
+      end
+    elsif an_object.kind_of?(Array)
+      an_object.each do |value|
+        replace_key!(value, key_maps)
+      end
+    end
+  end
 end

Modified: incubator/deltacloud/trunk/server/lib/cimi/server.rb
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/lib/cimi/server.rb?rev=1188737&r1=1188736&r2=1188737&view=diff
==============================================================================
--- incubator/deltacloud/trunk/server/lib/cimi/server.rb (original)
+++ incubator/deltacloud/trunk/server/lib/cimi/server.rb Tue Oct 25 15:46:19 2011
@@ -133,7 +133,8 @@ EOS
               "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"
+        show_resource "machine_configurations/show", "MachineConfiguration",
+          {"property" => "properties", "disk" => "disks", "operation" => "operations"}
       else
         report_error(404)
       end
@@ -179,7 +180,8 @@ EOS
           "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"
+        show_resource "machine_images/show", "MachineImage",
+          {"property" => "properties", "operation" => "operations"}
       else
         report_error(404)
       end
@@ -226,7 +228,8 @@ EOS
           "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"
+        show_resource "machines/show", "Machine",
+          {"property" => "properties", "disk" => "disks", "operation" => "operations"}
       else
         report_error(404)
       end
@@ -274,7 +277,8 @@ EOS
           "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"
+        show_resource "volumes/show", "Volume",
+          {"property" => "properties", "operation" => "operations"}
       else
         report_error(404)
       end

Added: incubator/deltacloud/trunk/server/views/cimi/machine_configurations/show.xml.haml
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/views/cimi/machine_configurations/show.xml.haml?rev=1188737&view=auto
==============================================================================
--- incubator/deltacloud/trunk/server/views/cimi/machine_configurations/show.xml.haml (added)
+++ incubator/deltacloud/trunk/server/views/cimi/machine_configurations/show.xml.haml Tue
Oct 25 15:46:19 2011
@@ -0,0 +1,27 @@
+- unless defined?(partial)
+  !!! XML
+%MachineConfiguration{ :xmlns => CMWG_NAMESPACE }
+  %uri=machine_configurations_url + "/" + @dmtfitem["uri"]
+  %name=@dmtfitem["name"]
+  %description=@dmtfitem["description"]
+  %created=@dmtfitem["created"]
+  - if @dmtfitem["property"]
+    - if @dmtfitem["property"]["name"] && @dmtfitem["property"]["content"]
+      - property_object = {"#{@dmtfitem['property']['name']}" => {"content" => @dmtfitem["property"]["content"]}}
+    - else
+      - property_object = @dmtfitem["property"]
+    - property_object.each_pair do |key, value|
+      %property{ :name => key}=value["content"]
+  %cpu=@dmtfitem["cpu"]
+  %memory{ :quantity => @dmtfitem["memory"]["quantity"], :units => @dmtfitem["memory"]["units"]
}
+  - if @dmtfitem["disk"]
+    - if @dmtfitem["disk"].kind_of?(Array)
+      - property_object = @dmtfitem["disk"]
+    - else
+      - property_object = [@dmtfitem["disk"]]
+    - property_object.each do |disk|
+      %disk
+        %capacity{ :quantity => disk["capacity"]["quantity"], :units => disk["capacity"]["units"]
}
+        %guestInterface= disk["guestInterface"]
+  %operation{ :rel => "edit", :href => machine_configurations_url + "/" + @dmtfitem["uri"]
}
+  %operation{ :rel => "delete", :href => machine_configurations_url + "/" + @dmtfitem["uri"]
}
\ No newline at end of file

Added: incubator/deltacloud/trunk/server/views/cimi/machine_images/show.xml.haml
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/views/cimi/machine_images/show.xml.haml?rev=1188737&view=auto
==============================================================================
--- incubator/deltacloud/trunk/server/views/cimi/machine_images/show.xml.haml (added)
+++ incubator/deltacloud/trunk/server/views/cimi/machine_images/show.xml.haml Tue Oct 25 15:46:19
2011
@@ -0,0 +1,17 @@
+- unless defined?(partial)
+  !!! XML
+%MachineImage{ :xmlns => CMWG_NAMESPACE }
+  %uri=machine_images_url + "/" + @dmtfitem["uri"]
+  %name=@dmtfitem["name"]
+  %description=@dmtfitem["description"]
+  %created=@dmtfitem["created"]
+  - if @dmtfitem["property"]
+    - if @dmtfitem["property"]["name"] && @dmtfitem["property"]["content"]
+      - property_object = {"#{@dmtfitem['property']['name']}" => {"content" => @dmtfitem["property"]["content"]}}
+    - else
+      - property_object = @dmtfitem["property"]
+    - property_object.each_pair do |key, value|
+      %property{ :name => key}=value["content"]
+  %imageLocation{ :href => @dmtfitem["imageLocation"]}
+  %operation{ :rel => "edit", :href => machine_images_url + "/" + @dmtfitem["uri"]
}
+  %operation{ :rel => "delete", :href => machine_images_url + "/" + @dmtfitem["uri"]
}
\ No newline at end of file

Added: incubator/deltacloud/trunk/server/views/cimi/machines/show.xml.haml
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/views/cimi/machines/show.xml.haml?rev=1188737&view=auto
==============================================================================
--- incubator/deltacloud/trunk/server/views/cimi/machines/show.xml.haml (added)
+++ incubator/deltacloud/trunk/server/views/cimi/machines/show.xml.haml Tue Oct 25 15:46:19
2011
@@ -0,0 +1,28 @@
+- unless defined?(partial)
+  !!! XML
+%Machine{ :xmlns => CMWG_NAMESPACE }
+  %uri=machines_url + "/" + @dmtfitem["uri"]
+  %name=@dmtfitem["name"]
+  %description=@dmtfitem["description"]
+  %created=@dmtfitem["created"]
+  - if @dmtfitem["property"]
+    - if @dmtfitem["property"]["name"] && @dmtfitem["property"]["content"]
+      - property_object = {"#{@dmtfitem['property']['name']}" => {"content" => @dmtfitem["property"]["content"]}}
+    - else
+      - property_object = @dmtfitem["property"]
+    - property_object.each_pair do |key, value|
+      %property{ :name => key}=value["content"]
+  %status=@dmtfitem["status"]
+  %cpu=@dmtfitem["cpu"]
+  %memory{ :quantity => @dmtfitem["memory"]["quantity"], :units => @dmtfitem["memory"]["units"]
}
+  - if @dmtfitem["disk"]
+    - if @dmtfitem["disk"].kind_of?(Array)
+      - property_object = @dmtfitem["disk"]
+    - else
+      - property_object = [@dmtfitem["disk"]]
+    - property_object.each do |disk|
+      %disk
+        %capacity{ :quantity => disk["capacity"]["quantity"], :units => disk["capacity"]["units"]
}
+        %guestInterface= disk["guestInterface"]
+  %operation{ :rel => "edit", :href => machines_url + "/" + @dmtfitem["uri"] }
+  %operation{ :rel => "delete", :href => machines_url + "/" + @dmtfitem["uri"] }
\ No newline at end of file

Copied: incubator/deltacloud/trunk/server/views/cimi/volumes/show.html.haml (from r1188696,
incubator/deltacloud/trunk/server/views/cimi/volume/show.html.haml)
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/views/cimi/volumes/show.html.haml?p2=incubator/deltacloud/trunk/server/views/cimi/volumes/show.html.haml&p1=incubator/deltacloud/trunk/server/views/cimi/volume/show.html.haml&r1=1188696&r2=1188737&rev=1188737&view=diff
==============================================================================
    (empty)

Added: incubator/deltacloud/trunk/server/views/cimi/volumes/show.xml.haml
URL: http://svn.apache.org/viewvc/incubator/deltacloud/trunk/server/views/cimi/volumes/show.xml.haml?rev=1188737&view=auto
==============================================================================
--- incubator/deltacloud/trunk/server/views/cimi/volumes/show.xml.haml (added)
+++ incubator/deltacloud/trunk/server/views/cimi/volumes/show.xml.haml Tue Oct 25 15:46:19
2011
@@ -0,0 +1,17 @@
+- unless defined?(partial)
+  !!! XML
+%Volume{ :xmlns => CMWG_NAMESPACE }
+  %uri=volumes_url + "/" + @dmtfitem["uri"]
+  %name=@dmtfitem["name"]
+  %description=@dmtfitem["description"]
+  %created=@dmtfitem["created"]
+  - if @dmtfitem["property"]
+    - if @dmtfitem["property"]["name"] && @dmtfitem["property"]["content"]
+      - property_object = {"#{@dmtfitem['property']['name']}" => {"content" => @dmtfitem["property"]["content"]}}
+    - else
+      - property_object = @dmtfitem["property"]
+    - property_object.each_pair do |key, value|
+      %property{ :name => key}=value["content"]
+  %capacity{ :quantity => @dmtfitem["capacity"]["quantity"], :units => @dmtfitem["capacity"]["units"]}
+  %operation{ :rel => "edit", :href => volumes_url + "/" + @dmtfitem["uri"] }
+  %operation{ :rel => "delete", :href => volumes_url + "/" + @dmtfitem["uri"] }
\ No newline at end of file



Mime
View raw message