On Oct 25, 2011, at 5:33 PM, email4t...@gmail.com wrote:

ACK.

  -- Michal


> From: Tong Li <liton...@us.ibm.com>
> 
> ---
> .../cimi/data/collections/machine_image.col.xml    |    4 +-
> .../data/default_res/machine_configuration.col.xml |    4 +
> server/lib/cimi/helpers/cmwgapp_helper.rb          |   22 ++++++-
> server/lib/cimi/server.rb                          |   12 ++-
> .../cimi/machine_configurations/show.xml.haml      |   27 ++++++++
> server/views/cimi/machine_images/show.xml.haml     |   17 +++++
> server/views/cimi/machines/show.xml.haml           |   28 ++++++++
> server/views/cimi/volume/show.html.haml            |   68 --------------------
> server/views/cimi/volumes/show.html.haml           |   68 ++++++++++++++++++++
> server/views/cimi/volumes/show.xml.haml            |   17 +++++
> 10 files changed, 192 insertions(+), 75 deletions(-)
> create mode 100644 server/views/cimi/machine_configurations/show.xml.haml
> create mode 100644 server/views/cimi/machine_images/show.xml.haml
> create mode 100644 server/views/cimi/machines/show.xml.haml
> delete mode 100644 server/views/cimi/volume/show.html.haml
> create mode 100644 server/views/cimi/volumes/show.html.haml
> create mode 100644 server/views/cimi/volumes/show.xml.haml
> 
> diff --git a/server/lib/cimi/data/collections/machine_image.col.xml 
> b/server/lib/cimi/data/collections/machine_image.col.xml
> index 2c27075..c4be389 100644
> --- a/server/lib/cimi/data/collections/machine_image.col.xml
> +++ b/server/lib/cimi/data/collections/machine_image.col.xml
> @@ -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>
> diff --git a/server/lib/cimi/data/default_res/machine_configuration.col.xml 
> b/server/lib/cimi/data/default_res/machine_configuration.col.xml
> index 564b378..db91861 100644
> --- a/server/lib/cimi/data/default_res/machine_configuration.col.xml
> +++ b/server/lib/cimi/data/default_res/machine_configuration.col.xml
> @@ -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"/>
> diff --git a/server/lib/cimi/helpers/cmwgapp_helper.rb 
> b/server/lib/cimi/helpers/cmwgapp_helper.rb
> index a3f91b4..3ab42ac 100644
> --- a/server/lib/cimi/helpers/cmwgapp_helper.rb
> +++ b/server/lib/cimi/helpers/cmwgapp_helper.rb
> @@ -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
> diff --git a/server/lib/cimi/server.rb b/server/lib/cimi/server.rb
> index 3defeff..17285bd 100644
> --- a/server/lib/cimi/server.rb
> +++ b/server/lib/cimi/server.rb
> @@ -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
> diff --git a/server/views/cimi/machine_configurations/show.xml.haml 
> b/server/views/cimi/machine_configurations/show.xml.haml
> new file mode 100644
> index 0000000..c337fe1
> --- /dev/null
> +++ b/server/views/cimi/machine_configurations/show.xml.haml
> @@ -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
> diff --git a/server/views/cimi/machine_images/show.xml.haml 
> b/server/views/cimi/machine_images/show.xml.haml
> new file mode 100644
> index 0000000..a00713c
> --- /dev/null
> +++ b/server/views/cimi/machine_images/show.xml.haml
> @@ -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
> diff --git a/server/views/cimi/machines/show.xml.haml 
> b/server/views/cimi/machines/show.xml.haml
> new file mode 100644
> index 0000000..c699b19
> --- /dev/null
> +++ b/server/views/cimi/machines/show.xml.haml
> @@ -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
> diff --git a/server/views/cimi/volume/show.html.haml 
> b/server/views/cimi/volume/show.html.haml
> deleted file mode 100644
> index 0e7b20b..0000000
> --- a/server/views/cimi/volume/show.html.haml
> +++ /dev/null
> @@ -1,68 +0,0 @@
> -%h1 View/Edit volume
> -
> -%form{ :action => volumes_url }
> -  %input{ :name => :id, :type => :hidden, :value => @dmtfitem["uri"] }/
> -  %input{ :name => :xmlRootNode, :type => :hidden, :value => @xml_root_node 
> }/
> -  %input{ :name => :refreshURI, :type => :hidden, :value => volumes_url }/
> -  %p
> -    %label
> -      Name:
> -  %p
> -    %input{ :name => :name, :size => 50, :value => @dmtfitem["name"], :style 
> => "width:50%;" }
> -    %input{ :name => :created, :type => :hidden, :size => 50, :value => 
> @dmtfitem["created"] }
> -  %p
> -  %br
> -    %label
> -      Description:
> -  %p
> -    %textarea{ :name => :description, :cols => 50, :rows => 4, :style => 
> "width:50%;" } #{@dmtfitem['description']}
> -  %p
> -  %br
> -    %label
> -      Properties:
> -  %p
> -    %table{ :style => "width:50%;", :id => "propertyTable"}
> -      - if @dmtfitem["property"]
> -        - if @dmtfitem["property"]["name"] && 
> @dmtfitem["property"]["content"]
> -          - property_object = {"#{@dmtfitem['property']['name']}" => 
> {"content" => @dmtfitem["property"]["content"]}}
> -        - else
> -          - property_object = @dmtfitem["property"]
> -
> -        - iter = -1
> -        - property_object.each_pair do |key, value|
> -          - iter += 1
> -          %tr
> -            %td
> -              %input{ :name => "param_name_" + iter.to_s, :size => 30, 
> :value => key }
> -            %td
> -              %input{ :name => "param_value_" + iter.to_s, :size => 30, 
> :value => value["content"] }
> -            %td
> -              %input{ :type => :button, :value => "Remove", :onClick => 
> "return removeProperty(this)" }
> -    %input{ :type => :button, :name => "commit", :value => "Add new 
> property", :onClick => "return AddNewPproperty('propertyTable')" }
> -  %p
> -  %br
> -    %label
> -      Capacity:
> -  %p
> -    %input{ :name => :capacity_quantity, :size => 20, :value => 
> @dmtfitem["capacity"]["quantity"], :style => "width:10%;" } 
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
> -    %input{ :name => :capacity_units, :size => 20, :value => 
> @dmtfitem["capacity"]["units"], :style => "width:10%;" }
> -  %br
> -  %label
> -    EntityMetadata:
> -  %br
> -
> -:javascript
> -  function fixupXml(theNode) {
> -    var xmlData = "<?xml version='1.0' encoding='utf-8' ?>";
> -    xmlData += "<" + $(theNode.form).attr("xmlRootNode").value + " 
> xmlns='http://www.dmtf.org/cimi'>";
> -    xmlData += getStandardData(theNode);
> -    xmlData += "<cpu>" + $(theNode.form).attr("cpu").value + "</cpu>";
> -    xmlData += "<memory quantity='" + 
> $(theNode.form).attr("memory_quantity").value + "' units='";
> -    xmlData += $(theNode.form).attr("memory_units").value + "' />"
> -
> -    var index=0;
> -
> -    xmlData += "</" + $(theNode.form).attr("xmlRootNode").value + ">";
> -
> -    return xmlData;
> -  }
> \ No newline at end of file
> diff --git a/server/views/cimi/volumes/show.html.haml 
> b/server/views/cimi/volumes/show.html.haml
> new file mode 100644
> index 0000000..0e7b20b
> --- /dev/null
> +++ b/server/views/cimi/volumes/show.html.haml
> @@ -0,0 +1,68 @@
> +%h1 View/Edit volume
> +
> +%form{ :action => volumes_url }
> +  %input{ :name => :id, :type => :hidden, :value => @dmtfitem["uri"] }/
> +  %input{ :name => :xmlRootNode, :type => :hidden, :value => @xml_root_node 
> }/
> +  %input{ :name => :refreshURI, :type => :hidden, :value => volumes_url }/
> +  %p
> +    %label
> +      Name:
> +  %p
> +    %input{ :name => :name, :size => 50, :value => @dmtfitem["name"], :style 
> => "width:50%;" }
> +    %input{ :name => :created, :type => :hidden, :size => 50, :value => 
> @dmtfitem["created"] }
> +  %p
> +  %br
> +    %label
> +      Description:
> +  %p
> +    %textarea{ :name => :description, :cols => 50, :rows => 4, :style => 
> "width:50%;" } #{@dmtfitem['description']}
> +  %p
> +  %br
> +    %label
> +      Properties:
> +  %p
> +    %table{ :style => "width:50%;", :id => "propertyTable"}
> +      - if @dmtfitem["property"]
> +        - if @dmtfitem["property"]["name"] && 
> @dmtfitem["property"]["content"]
> +          - property_object = {"#{@dmtfitem['property']['name']}" => 
> {"content" => @dmtfitem["property"]["content"]}}
> +        - else
> +          - property_object = @dmtfitem["property"]
> +
> +        - iter = -1
> +        - property_object.each_pair do |key, value|
> +          - iter += 1
> +          %tr
> +            %td
> +              %input{ :name => "param_name_" + iter.to_s, :size => 30, 
> :value => key }
> +            %td
> +              %input{ :name => "param_value_" + iter.to_s, :size => 30, 
> :value => value["content"] }
> +            %td
> +              %input{ :type => :button, :value => "Remove", :onClick => 
> "return removeProperty(this)" }
> +    %input{ :type => :button, :name => "commit", :value => "Add new 
> property", :onClick => "return AddNewPproperty('propertyTable')" }
> +  %p
> +  %br
> +    %label
> +      Capacity:
> +  %p
> +    %input{ :name => :capacity_quantity, :size => 20, :value => 
> @dmtfitem["capacity"]["quantity"], :style => "width:10%;" } 
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
> +    %input{ :name => :capacity_units, :size => 20, :value => 
> @dmtfitem["capacity"]["units"], :style => "width:10%;" }
> +  %br
> +  %label
> +    EntityMetadata:
> +  %br
> +
> +:javascript
> +  function fixupXml(theNode) {
> +    var xmlData = "<?xml version='1.0' encoding='utf-8' ?>";
> +    xmlData += "<" + $(theNode.form).attr("xmlRootNode").value + " 
> xmlns='http://www.dmtf.org/cimi'>";
> +    xmlData += getStandardData(theNode);
> +    xmlData += "<cpu>" + $(theNode.form).attr("cpu").value + "</cpu>";
> +    xmlData += "<memory quantity='" + 
> $(theNode.form).attr("memory_quantity").value + "' units='";
> +    xmlData += $(theNode.form).attr("memory_units").value + "' />"
> +
> +    var index=0;
> +
> +    xmlData += "</" + $(theNode.form).attr("xmlRootNode").value + ">";
> +
> +    return xmlData;
> +  }
> \ No newline at end of file
> diff --git a/server/views/cimi/volumes/show.xml.haml 
> b/server/views/cimi/volumes/show.xml.haml
> new file mode 100644
> index 0000000..30ef2c2
> --- /dev/null
> +++ b/server/views/cimi/volumes/show.xml.haml
> @@ -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
> -- 
> 1.7.4.1
> 

Reply via email to