Class: Construqt::Flavour::Ubuntu::EtcNetworkInterfaces::Entry::Lines

Inherits:
Object
  • Object
show all
Defined in:
lib/construqt/flavour/ubuntu/flavour_ubuntu_result.rb

Instance Method Summary collapse

Constructor Details

#initialize(entry) ⇒ Lines

Returns a new instance of Lines.



289
290
291
292
293
294
# File 'lib/construqt/flavour/ubuntu/flavour_ubuntu_result.rb', line 289

def initialize(entry)
  @entry = entry
  @lines = []
  @ups = []
  @downs = []
end

Instance Method Details

#add(block) ⇒ Object



304
305
306
# File 'lib/construqt/flavour/ubuntu/flavour_ubuntu_result.rb', line 304

def add(block)
  @lines += block.each_line.map{|i| i.strip }.select{|i| !i.empty? }
end

#commitObject



318
319
320
321
322
323
324
325
326
327
328
329
# File 'lib/construqt/flavour/ubuntu/flavour_ubuntu_result.rb', line 318

def commit
  write_s(@entry.iface.class.name, "up", @ups)
  write_s(@entry.iface.class.name, "down", @downs)
  sections = @lines.inject({}) {|r, line| key = line.split(/\s+/).first; r[key] ||= []; r[key] << line; r }
  sections.keys.sort.map do |key|
    if sections[key]
      sections[key].map{|j| "  #{j}" }
    else
      nil
    end
  end.compact.flatten.join("\n")+"\n\n"
end

#down(block) ⇒ Object



300
301
302
# File 'lib/construqt/flavour/ubuntu/flavour_ubuntu_result.rb', line 300

def down(block)
  @downs += block.each_line.map{|i| i.strip }.select{|i| !i.empty? }
end

#up(block) ⇒ Object



296
297
298
# File 'lib/construqt/flavour/ubuntu/flavour_ubuntu_result.rb', line 296

def up(block)
  @ups += block.each_line.map{|i| i.strip }.select{|i| !i.empty? }
end

#write_s(component, direction, blocks) ⇒ Object



308
309
310
311
312
313
314
315
316
# File 'lib/construqt/flavour/ubuntu/flavour_ubuntu_result.rb', line 308

def write_s(component, direction, blocks)
  @entry.result.add(self.class, <<BLOCK, Construqt::Resources::Rights.root_0755(component), "etc", "network", "#{@entry.header.get_interface_name}-#{direction}.iface")
#!/bin/bash
exec > >(logger -t "#{@entry.header.get_interface_name}-#{direction}") 2>&1
#{blocks.join("\n")}
BLOCK
#iptables-restore < /etc/network/iptables.cfg
#ip6tables-restore < /etc/network/ip6tables.cfg
end