Last active
October 6, 2015 11:56
-
-
Save TomyLobo/f659bf9c1ed81de7be3e to your computer and use it in GitHub Desktop.
Puppet catalog to TGF graph format converter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
require 'json' | |
require 'tgf' | |
catalog_file_name = 'catalog.json' | |
graph_file_name = 'foo.tgf' | |
catalog = JSON.parse(File.read(catalog_file_name)) | |
nodes = catalog['data']['resources'] | |
edges = catalog['data']['edges'] | |
edges.map! do |entry| | |
from = entry['source'].gsub(' ', '_') | |
to = entry['target'].gsub(' ', '_') | |
TGF::Edge.new("#{from} #{to}") | |
end | |
nodes.map! do |entry| | |
label = "#{entry['type']}[#{entry['title']}]" | |
id = label.gsub(' ', '_') | |
TGF::Node.new("#{id} #{label}") | |
end | |
graph_file = File.open(graph_file_name, 'w') | |
TGF.write(graph_file, nodes, edges) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source 'https://rubygems.org' | |
gem 'tgf', '~> 1.1.0' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment