Class: Construqt::Flavour::Ciscian::DlinkDgs15xx::Dialect

Inherits:
Object
  • Object
show all
Defined in:
lib/construqt/flavour/ciscian/dialect_dlink-dgs15xx.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(result) ⇒ Dialect

Returns a new instance of Dialect.



115
116
117
# File 'lib/construqt/flavour/ciscian/dialect_dlink-dgs15xx.rb', line 115

def initialize(result)
  @result=result
end

Class Method Details

.nameObject



111
112
113
# File 'lib/construqt/flavour/ciscian/dialect_dlink-dgs15xx.rb', line 111

def self.name
  'dlink-dgs15xx'
end

Instance Method Details

#add_bond(bond) ⇒ Object



189
190
191
192
193
194
195
# File 'lib/construqt/flavour/ciscian/dialect_dlink-dgs15xx.rb', line 189

def add_bond(bond)
  bond.interfaces.each do |iface|
    @result.add("interface #{expand_device_name(iface)}") do |section|
      section.add("channel-group", ChannelGroupVerb).add({"{+channel}" => [bond.name[2..-1]]})
    end
  end
end

#add_device(device) ⇒ Object



126
127
128
129
130
131
132
133
# File 'lib/construqt/flavour/ciscian/dialect_dlink-dgs15xx.rb', line 126

def add_device(device)
  @result.add("interface #{expand_device_name(device)}") do |section|
    section.add("flowcontrol").add("off")
    section.add("max-rcv-frame-size").add(device.delegate.mtu)
    section.add("snmp trap").add("link-status")
    section.add("switchport mode").add("trunk")
  end
end

#add_host(host) ⇒ Object



123
124
# File 'lib/construqt/flavour/ciscian/dialect_dlink-dgs15xx.rb', line 123

def add_host(host)
end

#add_vlan(vlan) ⇒ Object



197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
# File 'lib/construqt/flavour/ciscian/dialect_dlink-dgs15xx.rb', line 197

def add_vlan(vlan)
  @result.add("vlan #{vlan.delegate.vlan_id}") 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)
  end
  @result.add("interface vlan #{vlan.delegate.vlan_id}") do |section|
    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
      if vlan.delegate.address.first_ipv6
        section.add("ipv6 address").add(vlan.delegate.address.first_ipv6.to_string)
      elsif vlan.delegate.address.dhcpv6?
        section.add("ipv6 address").add("dhcp-bootp")
      end
    end
  end

  vlan_id=vlan.delegate.vlan_id
  vlan.interfaces.each do |iface|
    @result.add("interface #{expand_device_name(iface)}") do |section|
      if iface.template.is_tagged?(vlan_id)
        section.add("switchport trunk allowed vlan", Ciscian::RangeVerb).add(vlan_id)
      else
        section.add("switchport trunk native vlan").add(vlan_id)
      end
    end
  end
end

#block_end?(line) ⇒ Boolean

Returns:

  • (Boolean)


119
120
121
# File 'lib/construqt/flavour/ciscian/dialect_dlink-dgs15xx.rb', line 119

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

#clear_interface(line) ⇒ Object



135
136
137
138
139
140
# File 'lib/construqt/flavour/ciscian/dialect_dlink-dgs15xx.rb', line 135

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



169
170
171
172
173
174
175
176
177
178
# File 'lib/construqt/flavour/ciscian/dialect_dlink-dgs15xx.rb', line 169

def commit
  @result.add("snmp-server name", Ciscian::SingleValueVerb).add(@result.host.name)
  @result.host.interfaces.values.each do |iface|
    next unless iface.delegate.address
    iface.delegate.address.routes.each do |route|
      ip = route.dst.ipv6? ? "ipv6" : "ip"
      @result.add("#{ip} route #{route.dst.to_string} vlan#{iface.delegate.vlan_id} #{route.via.to_s}", Ciscian::SingleValueVerb)
    end
  end
end

#expand_device_name(device) ⇒ Object



158
159
160
161
162
163
164
165
166
167
# File 'lib/construqt/flavour/ciscian/dialect_dlink-dgs15xx.rb', line 158

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

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



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/construqt/flavour/ciscian/dialect_dlink-dgs15xx.rb', line 142

def parse_line(line, lines, section, result)
  [
    WtfEnd,
    ConfigureTerminal,
    Line,
    Comment,
    HostNameVerb,
    MtuVerb,
    SwitchPortTrunkAllowedVlan,
    ChannelGroupVerb,
    Ipv4RouteVerb
  ].find do |i|
    i.parse_line(line, lines, section, result)
  end
end