Class: Construqt::Flavour::Ciscian::Hp2510g
- Inherits:
-
Object
- Object
- Construqt::Flavour::Ciscian::Hp2510g
- Defined in:
- lib/construqt/flavour/ciscian/dialect_hp-2510g.rb
Defined Under Namespace
Class Method Summary collapse
Instance Method Summary collapse
- #add_bond(bond) ⇒ Object
- #add_device(device) ⇒ Object
- #add_host(host) ⇒ Object
- #add_vlan(vlan) ⇒ Object
- #block_end?(line) ⇒ Boolean
- #clear_interface(line) ⇒ Object
- #commit ⇒ Object
- #expand_device_name(device, map = { "po" => "Trk%s", "ge" => "ethernet %s" }) ⇒ Object
- #expand_vlan_device_name(device) ⇒ Object
-
#initialize(result) ⇒ Hp2510g
constructor
A new instance of Hp2510g.
- #is_virtual?(line) ⇒ Boolean
- #parse_line(line, lines, section, result) ⇒ Object
- #rate_higher(prefix, a, b) ⇒ Object
- #sort_section_keys(keys) ⇒ Object
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
.name ⇒ Object
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
81 82 83 84 |
# File 'lib/construqt/flavour/ciscian/dialect_hp-2510g.rb', line 81 def add_bond(bond) @result.add("trunk", TrunkVerb).add("{+ports}" => bond.interfaces.map{|i| i.delegate.number }, "{*channel}" => bond.delegate.number, "{=mode}"=>"LACP") @result.add("spanning-tree #{(bond)} priority 4") end |
#add_device(device) ⇒ Object
78 79 |
# File 'lib/construqt/flavour/ciscian/dialect_hp-2510g.rb', line 78 def add_device(device) end |
#add_host(host) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/construqt/flavour/ciscian/dialect_hp-2510g.rb', line 51 def add_host(host) @result.add("hostname").add(@result.host.name).quotes @result.add("max-vlans").add(64) @result.add("snmp-server community \"public\"") #enable ssh per default @result.add("ip ssh") @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}") end end if host.delegate.sntp @result.add("sntp server").add(host.delegate.sntp) @result.add("timesync sntp") @result.add("sntp unicast") end if host.delegate.logging @result.add("logging").add(host.delegate.logging) end end |
#add_vlan(vlan) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/construqt/flavour/ciscian/dialect_hp-2510g.rb', line 86 def add_vlan(vlan) @result.add("vlan #{vlan.delegate.vlan_id}", NestedSection) 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").add(vlan.delegate.description).quotes section.add("jumbo") vlan.interfaces.each do |port| range=nil if port.template.is_tagged?(vlan.vlan_id) range=section.add("tagged", Tagged) range.add("{+ports}" => [(port)]) elsif port.template.is_untagged?(vlan.vlan_id) range=section.add("tagged", Tagged) range.add("{+uports}" => [(port)]) elsif port.template.is_nountagged?(vlan.vlan_id) range=section.add("tagged", Tagged) range.add("{-uports}" => [(port)]) end end if vlan.delegate.address if vlan.delegate.address.first_ipv4 section.add("ip address").add(vlan.delegate.address.first_ipv4.to_s + " " + vlan.delegate.address.first_ipv4.netmask) elsif vlan.delegate.address.dhcpv4? section.add("ip address").add("dhcp-bootp") end end if vlan.delegate.igmp section.add("ip igmp") end end end |
#block_end?(line) ⇒ Boolean
138 139 140 |
# File 'lib/construqt/flavour/ciscian/dialect_hp-2510g.rb', line 138 def block_end?(line) ['end','exit'].include?(line.strip) end |
#clear_interface(line) ⇒ Object
127 128 129 130 131 132 |
# File 'lib/construqt/flavour/ciscian/dialect_hp-2510g.rb', line 127 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 |
#commit ⇒ Object
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
44 45 46 47 48 49 |
# File 'lib/construqt/flavour/ciscian/dialect_hp-2510g.rb', line 44 def (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
40 41 42 |
# File 'lib/construqt/flavour/ciscian/dialect_hp-2510g.rb', line 40 def (device) (device, { "po" => "Trk%s", "ge" => "%s" }) end |
#is_virtual?(line) ⇒ Boolean
134 135 136 |
# File 'lib/construqt/flavour/ciscian/dialect_hp-2510g.rb', line 134 def is_virtual?(line) line.include?("vlan") end |
#parse_line(line, lines, section, result) ⇒ Object
120 121 122 123 124 125 |
# File 'lib/construqt/flavour/ciscian/dialect_hp-2510g.rb', line 120 def parse_line(line, lines, section, result) [TrunkVerb, Tagged ].find do |i| i.parse_line(line, lines, section, result) end end |
#rate_higher(prefix, a, b) ⇒ Object
36 37 38 |
# File 'lib/construqt/flavour/ciscian/dialect_hp-2510g.rb', line 36 def rate_higher(prefix, a, b) return a.start_with?(prefix) ^ b.start_with?(prefix) ? (a.start_with?(prefix) ? -1 : 1) : 0 end |
#sort_section_keys(keys) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/construqt/flavour/ciscian/dialect_hp-2510g.rb', line 16 def sort_section_keys(keys) return keys.sort do |a,b| a = a.to_s b = b.to_s match_a=/^(.*[^\d])(\d+)$/.match(a)||[nil,a,1] match_b=/^(.*[^\d])(\d+)$/.match(b)||[nil,b,1] #puts match_a, match_b, a, b ret=0 ret = rate_higher("hostname", match_a[1], match_b[1]) if ret==0 ret = rate_higher("snmp", match_a[1], match_b[1]) if ret==0 ret = rate_higher("trunk", match_a[1], match_b[1]) if ret==0 ret = rate_higher("max-vlans", match_a[1], match_b[1]) if ret==0 ret = rate_higher("vlan", match_a[1], match_b[1]) if ret==0 ret = rate_higher("vlan", match_a[1], match_b[1]) if ret==0 ret = match_a[1]<=>match_b[1] if ret==0 ret = match_a[2].to_i<=>match_b[2].to_i if ret==0 ret end end |