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.



277
278
279
280
281
282
# File 'lib/construqt/flavour/ubuntu/flavour_ubuntu_result.rb', line 277

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

Instance Method Details

#add(block) ⇒ Object



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

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

#commitObject



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

def commit
  write_s("up", @ups)
  write_s("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



288
289
290
# File 'lib/construqt/flavour/ubuntu/flavour_ubuntu_result.rb', line 288

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

#up(block) ⇒ Object



284
285
286
# File 'lib/construqt/flavour/ubuntu/flavour_ubuntu_result.rb', line 284

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

#write_s(direction, blocks) ⇒ Object



296
297
298
299
300
301
302
303
304
# File 'lib/construqt/flavour/ubuntu/flavour_ubuntu_result.rb', line 296

def write_s(direction, blocks)
  @entry.result.add(self.class, <<BLOCK, Construqt::Resources::Rights::ROOT_0755, "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")}
iptables-restore < /etc/network/iptables.cfg
ip6tables-restore < /etc/network/ip6tables.cfg
BLOCK
end