class Construqt::Flavour::Ciscian::Result

Attributes

dialect[RW]
host[RW]
sections[RW]

Public Class Methods

compare(nu, old) click to toggle source
# File lib/construqt/flavour/ciscian/ciscian.rb, line 115
def self.compare(nu, old)
  result = Result.new(nu.host)

  nu_root=NestedSection.new("root")
  nu_root.sections.merge!(nu.sections)
  other_root=NestedSection.new("root")
  other_root.sections.merge!(old.sections)

  deltas=NestedSection.compare(nu_root, other_root)
  throw "illegal state" if deltas.length != 1
  result.sections = deltas[0].sections unless deltas[0].nil?
  result
end
new(host) click to toggle source
# File lib/construqt/flavour/ciscian/ciscian.rb, line 23
def initialize(host)
  @host = host
  @sections = {}
  throw "ciscian flavour can only be created with dialect" unless host.dialect
  require_relative "dialect_#{host.dialect}.rb"
  throw "cannot load dialect class #{host.dialect}" unless Ciscian.dialects[host.dialect]
  self.dialect=Ciscian.dialects[host.dialect].new(self)
end
normalize_section_key(key) click to toggle source
# File lib/construqt/flavour/ciscian/ciscian.rb, line 65
def self.normalize_section_key(key)
  matchdata=key.match(/^\s*(no\s+|)(.*)/)
  matchdata[2]
end
starts_with_no(key) click to toggle source
# File lib/construqt/flavour/ciscian/ciscian.rb, line 70
def self.starts_with_no(key)
  return key.match(/^\s*no\s+/)
end

Public Instance Methods

add(section, clazz=SingleValueVerb) { |sections| ... } click to toggle source
# File lib/construqt/flavour/ciscian/ciscian.rb, line 99
def add(section, clazz=SingleValueVerb)
  throw "section is nil" unless section
  section = Lines::Line.new(section, -1) unless section.kind_of?(Lines::Line)
  section_key=Result.normalize_section_key(section.to_s)

  @sections[section_key] ||= clazz.new(section_key)
  if Result.starts_with_no(section.to_s)
    @sections[section_key].no
  else
    @sections[section_key].yes
  end

  yield(@sections[section_key]) if block_given?
  @sections[section_key]
end
commit() click to toggle source
# File lib/construqt/flavour/ciscian/ciscian.rb, line 91
def commit
  self.dialect.commit
  Util.write_str(self.serialize().join("\n"), File.join(@host.name, "#{@host.fname||self.dialect.class.name}.cfg"))
  external=@host.id.interfaces.first.address
  external_ip=external.first_ipv4.nil? ? external.first_ipv6.to_s : external.first_ipv4.to_s
  DeployTemplate.write_template(@host, self.dialect.class.name, external_ip, "root", @host.password||@host.region.hosts.default_password)
end
parse(lines) click to toggle source
# File lib/construqt/flavour/ciscian/ciscian.rb, line 56
def parse(lines)
  lines = Lines.new(lines)
  while line = lines.shift
    parse_line(line, lines, self, self)
  end

  self
end
parse_line(line, lines, section, result) click to toggle source
# File lib/construqt/flavour/ciscian/ciscian.rb, line 74
def parse_line(line, lines, section, result)
  return if self.dialect.parse_line(line, lines, section, result)
  [NestedSection, SingleValueVerb].find do |clazz|
    clazz.parse_line(line, lines, section, result)
  end
end
serialize() click to toggle source
# File lib/construqt/flavour/ciscian/ciscian.rb, line 81
def serialize
  block=[]
  section_keys = self.dialect.sort_section_keys(@sections.keys)
  section_keys.each do |key|
    section = @sections[key]
    block += section.serialize
  end
  block
end