Class: PuppetX::Cisco::BgpUtils
- Inherits:
-
Object
- Object
- PuppetX::Cisco::BgpUtils
- Defined in:
- lib/puppet_x/cisco/cmnutils.rb
Overview
PuppetX::Cisco::BgpUtil - Common BGP methods used by BGP Types/Providers
Class Method Summary collapse
-
.dot_to_big(dot_str) ⇒ Object
Convert BGP ASN ASDOT+ to ASPLAIN.
- .process_asnum(asnum) ⇒ Object
Class Method Details
.dot_to_big(dot_str) ⇒ Object
Convert BGP ASN ASDOT+ to ASPLAIN
342 343 344 345 346 347 348 349 350 351 352 353 |
# File 'lib/puppet_x/cisco/cmnutils.rb', line 342 def self.dot_to_big(dot_str) fail ArgumentError unless dot_str.is_a? String return dot_str unless /\d+\.\d+/.match(dot_str) mask = 0b1111111111111111 high = dot_str.to_i low = 0 low_match = dot_str.match(/\.(\d+)/) low = low_match[1].to_i if low_match high_bits = (mask & high) << 16 low_bits = mask & low high_bits + low_bits end |
.process_asnum(asnum) ⇒ Object
328 329 330 331 332 333 334 335 336 337 338 339 |
# File 'lib/puppet_x/cisco/cmnutils.rb', line 328 def self.process_asnum(asnum) err_msg = "BGP asnum must be either a 'String' or an" \ " 'Integer' object" fail ArgumentError, err_msg unless asnum.is_a?(Integer) || asnum.is_a?(String) if asnum.is_a? String # Match ASDOT '1.5' or ASPLAIN '55' strings fail ArgumentError unless /^(\d+|\d+\.\d+)$/.match(asnum) asnum = dot_to_big(asnum) if /\d+\.\d+/.match(asnum) end asnum.to_i end |