Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Updated plain rendering for resources

* More flexible
* Less complicated templates
  • Loading branch information...
commit 4e17b1e953c3b2d2ea42640e78d785edfcab680e 1 parent 870bf53
Boris Parak authored March 07, 2013
9  lib/occi/bin/resource_output_factory.rb
@@ -57,7 +57,14 @@ def self.resources_to_plain(occi_resources, resource_type)
57 57
         file = File.expand_path("..", __FILE__) + '/templates/' + resource_type.to_s + ".erb"
58 58
         template = ERB.new File.new(file).read
59 59
 
60  
-        template.result(binding)
  60
+        formatted_output = ""
  61
+
  62
+        occi_resources.each do |occi_resource|
  63
+          json_resource = occi_resource.as_json
  64
+          formatted_output << template.result(binding) unless json_resource.empty?
  65
+        end
  66
+
  67
+        formatted_output
61 68
       end
62 69
 
63 70
       def self.locations_to_json(url_locations, resource_type)
40  lib/occi/bin/templates/compute.erb
... ...
@@ -1,22 +1,18 @@
1  
-<%# We always get an array of OCCI::Collections %>
2  
-Available COMPUTE resources:
3  
-<% occi_resources.each do |occi_compute| %>
4  
-  <% compute = occi_compute.as_json %>
5  
-  COMPUTE resource "<%= compute.resources.first.attributes.occi.core.title %>":
6  
-    ID:       <%= compute.resources.first.attributes.occi.core.id %>
7  
-    TITLE:    <%= compute.resources.first.attributes.occi.core.title %>
8  
-    STATE:    <%= compute.resources.first.attributes.occi.compute.state %>
9  
-    LINKS:
10  
-    <% if compute.links %><% compute.links.each do |link| %>
11  
-      LINK "<%= link.attributes.occi.core.target.split("/")[1] %>":
12  
-        ID:          <%= link.attributes.occi.core.id %>
13  
-        TITLE:       <%= link.attributes.occi.core.title %>
14  
-        TARGET:      <%= link.attributes.occi.core.target %>
15  
-        <% if link.attributes.occi.networkinterface %>
16  
-        IP ADDRESS:  <%= link.attributes.occi.networkinterface.address %>
17  
-        MAC ADDRESS: <%= link.attributes.occi.networkinterface.mac %>
18  
-        <% elsif link.attributes.occi.storagelink %>
19  
-        MOUNT POINT: <%= link.attributes.occi.storagelink.deviceid %>
20  
-        <% end %>
21  
-    <% end %><% end %>
22  
-<% end %>
  1
+<%# We always get a JSON %>
  2
+COMPUTE:
  3
+  ID:       <%= json_resource.resources.first.attributes.occi.core.id %>
  4
+  TITLE:    <%= json_resource.resources.first.attributes.occi.core.title %>
  5
+  STATE:    <%= json_resource.resources.first.attributes.occi.compute.state %>
  6
+  LINKS:
  7
+  <% if json_resource.links %><% json_resource.links.each do |link| %>
  8
+    LINK "<%= link.attributes.occi.core.target.split("/")[1] %>":
  9
+      ID:          <%= link.attributes.occi.core.id %>
  10
+      TITLE:       <%= link.attributes.occi.core.title %>
  11
+      TARGET:      <%= link.attributes.occi.core.target %>
  12
+      <% if link.attributes.occi.networkinterface %>
  13
+      IP ADDRESS:  <%= link.attributes.occi.networkinterface.address %>
  14
+      MAC ADDRESS: <%= link.attributes.occi.networkinterface.mac %>
  15
+      <% elsif link.attributes.occi.storagelink %>
  16
+      MOUNT POINT: <%= link.attributes.occi.storagelink.deviceid %>
  17
+      <% end %>
  18
+  <% end %><% end %>
18  lib/occi/bin/templates/network.erb
... ...
@@ -1,11 +1,7 @@
1  
-<%# We always get an array of OCCI::Collections %>
2  
-Available NETWORK resources:
3  
-<% occi_resources.each do |occi_network| %>
4  
-  <% network = occi_network.as_json %>
5  
-  NETWORK resource "<%= network.resources.first.attributes.occi.core.title %>":
6  
-    ID:           <%= network.resources.first.attributes.occi.core.id %>
7  
-    TITLE:        <%= network.resources.first.attributes.occi.core.title %>
8  
-    STATE:        <%= network.resources.first.attributes.occi.network.state %>
9  
-    ALLOCATION:   <%= network.resources.first.attributes.occi.network.allocation %>
10  
-    ADDRESS:      <%= network.resources.first.attributes.occi.network.address %>
11  
-<% end %>
  1
+<%# We always get a JSON %>
  2
+NETWORK:
  3
+  ID:           <%= json_resource.resources.first.attributes.occi.core.id %>
  4
+  TITLE:        <%= json_resource.resources.first.attributes.occi.core.title %>
  5
+  STATE:        <%= json_resource.resources.first.attributes.occi.network.state %>
  6
+  ALLOCATION:   <%= json_resource.resources.first.attributes.occi.network.allocation %>
  7
+  ADDRESS:      <%= json_resource.resources.first.attributes.occi.network.address %>
14  lib/occi/bin/templates/os_tpl.erb
... ...
@@ -1,9 +1,5 @@
1  
-<%# We always get an array of OCCI::Collections %>
2  
-Available OS templates:
3  
-<% occi_resources.each do |occi_os_tpl| %>
4  
-  <% os_tpl = occi_os_tpl.as_json %>
5  
-  OS template "os_tpl#<%= os_tpl.term %>":
6  
-    TITLE:        <%= os_tpl.title %>
7  
-    TERM:         <%= os_tpl.term %>
8  
-    LOCATION:     <%= os_tpl.location %>
9  
-<% end %>
  1
+<%# We always get a JSON %>
  2
+OS_TPL:
  3
+  TITLE:        <%= json_resource.title %>
  4
+  TERM:         <%= json_resource.term %>
  5
+  LOCATION:     <%= json_resource.location %>
14  lib/occi/bin/templates/resource_tpl.erb
... ...
@@ -1,9 +1,5 @@
1  
-<%# We always get an array of OCCI::Collections %>
2  
-Available RESOURCE templates:
3  
-<% occi_resources.each do |occi_res_tpl| %>
4  
-  <% res_tpl = occi_res_tpl.as_json %>
5  
-  RESOURCE template "resource_tpl#<%= res_tpl.term %>":
6  
-    TITLE:        <%= res_tpl.title %>
7  
-    TERM:         <%= res_tpl.term %>
8  
-    LOCATION:     <%= res_tpl.location %>
9  
-<% end %>
  1
+<%# We always get a JSON %>
  2
+RESOURCE_TPL:
  3
+  TITLE:        <%= json_resource.title %>
  4
+  TERM:         <%= json_resource.term %>
  5
+  LOCATION:     <%= json_resource.location %>
16  lib/occi/bin/templates/storage.erb
... ...
@@ -1,10 +1,6 @@
1  
-<%# We always get an array of OCCI::Collections %>
2  
-Available STORAGE resources:
3  
-<% occi_resources.each do |occi_storage| %>
4  
-  <% storage = occi_storage.as_json %>
5  
-  STORAGE resource "<%= storage.resources.first.attributes.occi.core.title %>":
6  
-    ID:           <%= storage.resources.first.attributes.occi.core.id %>
7  
-    TITLE:        <%= storage.resources.first.attributes.occi.core.title %>
8  
-    STATE:        <%= storage.resources.first.attributes.occi.storage.state%>
9  
-    DESCRIPTION:  <%= storage.resources.first.attributes.occi.core.summary %>
10  
-<% end %>
  1
+<%# We always get a JSON %>
  2
+STORAGE:
  3
+  ID:           <%= storage.resources.first.attributes.occi.core.id %>
  4
+  TITLE:        <%= storage.resources.first.attributes.occi.core.title %>
  5
+  STATE:        <%= storage.resources.first.attributes.occi.storage.state%>
  6
+  DESCRIPTION:  <%= storage.resources.first.attributes.occi.core.summary %>

0 notes on commit 4e17b1e

Please sign in to comment.
Something went wrong with that request. Please try again.