Class: Topo::Topology

Inherits:
Object
  • Object
show all
Defined in:
lib/topo/topology.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#driverObject

Returns the value of attribute driver.



24
25
26
# File 'lib/topo/topology.rb', line 24

def driver
  @driver
end

#formatObject

Returns the value of attribute format.



24
25
26
# File 'lib/topo/topology.rb', line 24

def format
  @format
end

#networkObject

Returns the value of attribute network.



24
25
26
# File 'lib/topo/topology.rb', line 24

def network
  @network
end

#nodesObject

Returns the value of attribute nodes.



24
25
26
# File 'lib/topo/topology.rb', line 24

def nodes
  @nodes
end

#provisioningObject

Returns the value of attribute provisioning.



24
25
26
# File 'lib/topo/topology.rb', line 24

def provisioning
  @provisioning
end

#raw_dataObject (readonly)

Returns the value of attribute raw_data.



25
26
27
# File 'lib/topo/topology.rb', line 25

def raw_data
  @raw_data
end

#servicesObject

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.message}"
  end
end