Class: Construqt::Flavour::Ciscian::Hp2510g

Inherits:
Object
  • Object
show all
Defined in:
lib/construqt/flavour/ciscian/dialect_hp-2510g.rb

Defined Under Namespace

Classes: Tagged, TrunkVerb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(result) ⇒ Hp2510g

Returns a new instance of Hp2510g.



9
10
11
# File 'lib/construqt/flavour/ciscian/dialect_hp-2510g.rb', line 9

def initialize(result)
  @result=result
end

Class Method Details

.nameObject



5
6
7
# File 'lib/construqt/flavour/ciscian/dialect_hp-2510g.rb', line 5

def self.name
  'hp-2510g'
end

Instance Method Details

#add_bond(bond) ⇒ Object



42
43
44
45
# File 'lib/construqt/flavour/ciscian/dialect_hp-2510g.rb', line 42

def add_bond(bond)
  @result.add("trunk", TrunkVerb).add("{+ports}" => bond.interfaces.map{|i| i.delegate.number }, "{*channel}" => bond.delegate.number)
  @result.add("spanning-tree #{expand_vlan_device_name(bond)} priority 4")
end

#add_device(device) ⇒ Object



39
40
# File 'lib/construqt/flavour/ciscian/dialect_hp-2510g.rb', line 39

def add_device(device)
end

#add_host(host) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/construqt/flavour/ciscian/dialect_hp-2510g.rb', line 27

def add_host(host)
  @result.add("hostname", Ciscian::SingleValueVerb).add(@result.host.name)
  @result.add("max-vlans", Ciscian::SingleValueVerb).add(64)
  @result.add("snmp-server community \"public\" Unrestricted", Ciscian::SingleValueVerb)
  @result.host.interfaces.values.each do |iface|
    next unless iface.delegate.address
    iface.delegate.address.routes.each do |route|
      @result.add("ip route #{route.dst.to_s} #{route.dst.netmask} #{route.via.to_s}", Ciscian::SingleValueVerb)
    end
  end
end

#add_vlan(vlan) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/construqt/flavour/ciscian/dialect_hp-2510g.rb', line 47

def add_vlan(vlan)
  @result.add("vlan #{vlan.delegate.vlan_id} jumbo") do |section|
    next unless vlan.delegate.description && !vlan.delegate.description.empty?
    throw "vlan name too long, max 32 chars" if vlan.delegate.description.length > 32
    section.add("name", Ciscian::SingleValueVerb).add(vlan.delegate.description)
    vlan.interfaces.each do |port|

      section.add({
                    true => "tagged",
                    false => "untagged"
      }[port.template.is_tagged?(vlan.vlan_id)], Ciscian::RangeVerb).add(expand_vlan_device_name(port))
    end

    if vlan.delegate.address
      if vlan.delegate.address.first_ipv4
        section.add("ip address").add(vlan.delegate.address.first_ipv4.to_string)
      elsif vlan.delegate.address.dhcpv4?
        section.add("ip address").add("dhcp-bootp")
      end
    end
  end
end

#block_end?(line) ⇒ Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/construqt/flavour/ciscian/dialect_hp-2510g.rb', line 84

def block_end?(line)
  ['end','exit'].include?(line.strip)
end

#clear_interface(line) ⇒ Object



77
78
79
80
81
82
# File 'lib/construqt/flavour/ciscian/dialect_hp-2510g.rb', line 77

def clear_interface(line)
  line.to_s.split(/\s+/).map do |i|
    split = /^([^0-9]+)([0-9].*)$/.match(i)
    split ? split[1..-1] : i
  end.flatten.join(' ')
end

#commitObject



13
14
# File 'lib/construqt/flavour/ciscian/dialect_hp-2510g.rb', line 13

def commit
end

#expand_device_name(device, map = { "po" => "Trk%s", "ge" => "ethernet %s" }) ⇒ Object



20
21
22
23
24
25
# File 'lib/construqt/flavour/ciscian/dialect_hp-2510g.rb', line 20

def expand_device_name(device, map={ "po" => "Trk%s", "ge" => "ethernet %s" })
  return device.delegate.dev_name if device.delegate.dev_name
  pattern = map[device.name[0..1]]
  throw "device not expandable #{device.name}" unless pattern
  pattern%device.name[2..-1]
end

#expand_vlan_device_name(device) ⇒ Object



16
17
18
# File 'lib/construqt/flavour/ciscian/dialect_hp-2510g.rb', line 16

def expand_vlan_device_name(device)
  expand_device_name(device, { "po" => "Trk%s", "ge" => "%s" })
end

#parse_line(line, lines, section, result) ⇒ Object



70
71
72
73
74
75
# File 'lib/construqt/flavour/ciscian/dialect_hp-2510g.rb', line 70

def parse_line(line, lines, section, result)
  [TrunkVerb, Tagged
  ].find do |i|
    i.parse_line(line, lines, section, result)
  end
end