Skip to content

Commit

Permalink
Merge pull request gwdg#70 from arax/output-rendering
Browse files Browse the repository at this point in the history
Output rendering
  • Loading branch information
ffeldhaus committed Mar 7, 2013
2 parents 870bf53 + cdb195e commit 5a65ac2
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 62 deletions.
9 changes: 8 additions & 1 deletion lib/occi/bin/resource_output_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,14 @@ def self.resources_to_plain(occi_resources, resource_type)
file = File.expand_path("..", __FILE__) + '/templates/' + resource_type.to_s + ".erb"
template = ERB.new File.new(file).read

template.result(binding)
formatted_output = ""

occi_resources.each do |occi_resource|
json_resource = occi_resource.as_json
formatted_output << template.result(binding) unless json_resource.nil? || json_resource.empty?
end

formatted_output
end

def self.locations_to_json(url_locations, resource_type)
Expand Down
40 changes: 18 additions & 22 deletions lib/occi/bin/templates/compute.erb
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
<%# We always get an array of OCCI::Collections %>
Available COMPUTE resources:
<% occi_resources.each do |occi_compute| %>
<% compute = occi_compute.as_json %>
COMPUTE resource "<%= compute.resources.first.attributes.occi.core.title %>":
ID: <%= compute.resources.first.attributes.occi.core.id %>
TITLE: <%= compute.resources.first.attributes.occi.core.title %>
STATE: <%= compute.resources.first.attributes.occi.compute.state %>
LINKS:
<% if compute.links %><% compute.links.each do |link| %>
LINK "<%= link.attributes.occi.core.target.split("/")[1] %>":
ID: <%= link.attributes.occi.core.id %>
TITLE: <%= link.attributes.occi.core.title %>
TARGET: <%= link.attributes.occi.core.target %>
<% if link.attributes.occi.networkinterface %>
IP ADDRESS: <%= link.attributes.occi.networkinterface.address %>
MAC ADDRESS: <%= link.attributes.occi.networkinterface.mac %>
<% elsif link.attributes.occi.storagelink %>
MOUNT POINT: <%= link.attributes.occi.storagelink.deviceid %>
<% end %>
<% end %><% end %>
<% end %>
<%# We always get a JSON %>
COMPUTE:
ID: <%= json_resource.resources.first.attributes.occi.core.id %>
TITLE: <%= json_resource.resources.first.attributes.occi.core.title %>
STATE: <%= json_resource.resources.first.attributes.occi.compute.state %>
LINKS:
<% if json_resource.links %><% json_resource.links.each do |link| %>
LINK "<%= link.attributes.occi.core.target.split("/")[1] %>":
ID: <%= link.attributes.occi.core.id %>
TITLE: <%= link.attributes.occi.core.title %>
TARGET: <%= link.attributes.occi.core.target %>
<% if link.attributes.occi.networkinterface %>
IP ADDRESS: <%= link.attributes.occi.networkinterface.address %>
MAC ADDRESS: <%= link.attributes.occi.networkinterface.mac %>
<% elsif link.attributes.occi.storagelink %>
MOUNT POINT: <%= link.attributes.occi.storagelink.deviceid %>
<% end %>
<% end %><% end %>
20 changes: 9 additions & 11 deletions lib/occi/bin/templates/network.erb
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
<%# We always get an array of OCCI::Collections %>
Available NETWORK resources:
<% occi_resources.each do |occi_network| %>
<% network = occi_network.as_json %>
NETWORK resource "<%= network.resources.first.attributes.occi.core.title %>":
ID: <%= network.resources.first.attributes.occi.core.id %>
TITLE: <%= network.resources.first.attributes.occi.core.title %>
STATE: <%= network.resources.first.attributes.occi.network.state %>
ALLOCATION: <%= network.resources.first.attributes.occi.network.allocation %>
ADDRESS: <%= network.resources.first.attributes.occi.network.address %>
<% end %>
<%# We always get a JSON %>
NETWORK:
ID: <%= json_resource.resources.first.attributes.occi.core.id %>
TITLE: <%= json_resource.resources.first.attributes.occi.core.title %>
STATE: <%= json_resource.resources.first.attributes.occi.network.state %>
ALLOCATION: <%= json_resource.resources.first.attributes.occi.network.allocation %>
ADDRESS: <%= json_resource.resources.first.attributes.occi.network.address %>


16 changes: 7 additions & 9 deletions lib/occi/bin/templates/os_tpl.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<%# We always get an array of OCCI::Collections %>
Available OS templates:
<% occi_resources.each do |occi_os_tpl| %>
<% os_tpl = occi_os_tpl.as_json %>
OS template "os_tpl#<%= os_tpl.term %>":
TITLE: <%= os_tpl.title %>
TERM: <%= os_tpl.term %>
LOCATION: <%= os_tpl.location %>
<% end %>
<%# We always get a JSON %>
OS_TPL:
TITLE: <%= json_resource.title %>
TERM: <%= json_resource.term %>
LOCATION: <%= json_resource.location %>


16 changes: 7 additions & 9 deletions lib/occi/bin/templates/resource_tpl.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<%# We always get an array of OCCI::Collections %>
Available RESOURCE templates:
<% occi_resources.each do |occi_res_tpl| %>
<% res_tpl = occi_res_tpl.as_json %>
RESOURCE template "resource_tpl#<%= res_tpl.term %>":
TITLE: <%= res_tpl.title %>
TERM: <%= res_tpl.term %>
LOCATION: <%= res_tpl.location %>
<% end %>
<%# We always get a JSON %>
RESOURCE_TPL:
TITLE: <%= json_resource.title %>
TERM: <%= json_resource.term %>
LOCATION: <%= json_resource.location %>


18 changes: 8 additions & 10 deletions lib/occi/bin/templates/storage.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<%# We always get an array of OCCI::Collections %>
Available STORAGE resources:
<% occi_resources.each do |occi_storage| %>
<% storage = occi_storage.as_json %>
STORAGE resource "<%= storage.resources.first.attributes.occi.core.title %>":
ID: <%= storage.resources.first.attributes.occi.core.id %>
TITLE: <%= storage.resources.first.attributes.occi.core.title %>
STATE: <%= storage.resources.first.attributes.occi.storage.state%>
DESCRIPTION: <%= storage.resources.first.attributes.occi.core.summary %>
<% end %>
<%# We always get a JSON %>
STORAGE:
ID: <%= json_resource.resources.first.attributes.occi.core.id %>
TITLE: <%= json_resource.resources.first.attributes.occi.core.title %>
STATE: <%= json_resource.resources.first.attributes.occi.storage.state%>
DESCRIPTION: <%= json_resource.resources.first.attributes.occi.core.summary %>


0 comments on commit 5a65ac2

Please sign in to comment.