Class: HybridPlatformsConductor::Topographer::Plugins::Json
- Inherits:
-
HybridPlatformsConductor::Topographer::Plugin
- Object
- HybridPlatformsConductor::Topographer::Plugin
- HybridPlatformsConductor::Topographer::Plugins::Json
- Defined in:
- lib/hybrid_platforms_conductor/topographer/plugins/json.rb
Overview
Output in Graphviz format
Instance Method Summary collapse
-
#write_graph(file_name) ⇒ Object
Output the nodes graph in a file [API] - This method is mandatory.
Methods inherited from HybridPlatformsConductor::Topographer::Plugin
Constructor Details
This class inherits a constructor from HybridPlatformsConductor::Topographer::Plugin
Instance Method Details
#write_graph(file_name) ⇒ Object
Output the nodes graph in a file
- API
-
This method is mandatory.
-
- Parameters
-
file_name (String): The file name for output
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/hybrid_platforms_conductor/topographer/plugins/json.rb', line 17 def write_graph(file_name) # Build the JSON json = { nodes: [], links: [], } @topographer.nodes_graph.sort.each do |node_name, node_info| node_json = { id: node_name, description: "#{@topographer.title_for(node_name)} - #{@topographer.description_for(node_name)}", group: group_for(node_name), } node_json[:includes] = node_info[:includes] if @topographer.is_node_cluster?(node_name) json[:nodes] << node_json node_info[:connections].each do |connected_node_name, labels| json[:links] << { source: node_name, target: connected_node_name, value: 1, labels: labels.sort } end end File.write(file_name, JSON.pretty_generate(json)) end |