Class: Topo::Topology
- Inherits:
-
Object
- Object
- Topo::Topology
- Defined in:
- lib/topo/topology.rb
Instance Attribute Summary collapse
-
#driver ⇒ Object
Returns the value of attribute driver.
-
#format ⇒ Object
Returns the value of attribute format.
-
#network ⇒ Object
Returns the value of attribute network.
-
#nodes ⇒ Object
Returns the value of attribute nodes.
-
#provisioning ⇒ Object
Returns the value of attribute provisioning.
-
#raw_data ⇒ Object
readonly
Returns the value of attribute raw_data.
-
#services ⇒ Object
Returns the value of attribute services.
Instance Method Summary collapse
-
#initialize(raw_data) ⇒ Topology
constructor
A new instance of Topology.
- #parse_node(node) ⇒ Object
- #to_file(file) ⇒ Object
Constructor Details
#initialize(raw_data) ⇒ Topology
Returns a new instance of Topology.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/topo/topology.rb', line 27 def initialize(raw_data) @raw_data = raw_data data = Marshal.load(Marshal.dump(raw_data)) @provisioning = data['provisioning'] || {} if @provisioning['driver'] @driver = @provisioning['driver'].split(":",2)[0] else @driver = "default" end @nodes = data['nodes'] || [] @services = data['services'] || [] @network = data['network'] || [] @nodes.each do |node| parse_node node end end |
Instance Attribute Details
#driver ⇒ Object
Returns the value of attribute driver.
24 25 26 |
# File 'lib/topo/topology.rb', line 24 def driver @driver end |
#format ⇒ Object
Returns the value of attribute format.
24 25 26 |
# File 'lib/topo/topology.rb', line 24 def format @format end |
#network ⇒ Object
Returns the value of attribute network.
24 25 26 |
# File 'lib/topo/topology.rb', line 24 def network @network end |
#nodes ⇒ Object
Returns the value of attribute nodes.
24 25 26 |
# File 'lib/topo/topology.rb', line 24 def nodes @nodes end |
#provisioning ⇒ Object
Returns the value of attribute provisioning.
24 25 26 |
# File 'lib/topo/topology.rb', line 24 def provisioning @provisioning end |
#raw_data ⇒ Object (readonly)
Returns the value of attribute raw_data.
25 26 27 |
# File 'lib/topo/topology.rb', line 25 def raw_data @raw_data end |
#services ⇒ Object
Returns the value of attribute services.
24 25 26 |
# File 'lib/topo/topology.rb', line 24 def services @services end |
Instance Method Details
#parse_node(node) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/topo/topology.rb', line 46 def parse_node(node) node['attributes'] = node['normal'] if node['normal'] node['attributes'] ||= {} node['lazy_attributes'] ||= {} end |
#to_file(file) ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/topo/topology.rb', line 53 def to_file(file) begin File.open(file, 'w') { |f| f.write(JSON.pretty_generate(@raw_data)) } rescue => e STDERR.puts "ERROR: Cannot write to topology export file #{file} - #{e.}" end end |