Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 4 commits
  • 6 files changed
  • 0 commit comments
  • 2 contributors
9 lib/occi/bin/resource_output_factory.rb
View
@@ -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)
40 lib/occi/bin/templates/compute.erb
View
@@ -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 lib/occi/bin/templates/network.erb
View
@@ -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 lib/occi/bin/templates/os_tpl.erb
View
@@ -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 lib/occi/bin/templates/resource_tpl.erb
View
@@ -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 lib/occi/bin/templates/storage.erb
View
@@ -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 %>
+
+

No commit comments for this range

Something went wrong with that request. Please try again.