Class: Cisco::Encapsulation

Inherits:
NodeUtil show all
Defined in:
lib/cisco_node_utils/encapsulation.rb

Overview

Encapsulation - node utility class for Encapsulation config mgmt.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from NodeUtil

client, #client, config_get, #config_get, #config_get_default, config_get_default, config_set, #config_set, #get, #ios_xr?, #nexus?, #node, node, platform, #platform, supports?, #supports?

Constructor Details

#initialize(name, instantiate = true) ⇒ Encapsulation

name: name of the encap instance instantiate: true = create encap instance



29
30
31
32
33
# File 'lib/cisco_node_utils/encapsulation.rb', line 29

def initialize(name, instantiate=true)
  fail ArgumentError unless name.length > 0
  @encap_name = name
  create if instantiate
end

Instance Attribute Details

#encap_nameObject (readonly)

Returns the value of attribute encap_name.



25
26
27
# File 'lib/cisco_node_utils/encapsulation.rb', line 25

def encap_name
  @encap_name
end

Class Method Details

.encapsObject

Create a hash of all current encap instances.



40
41
42
43
44
45
46
47
48
49
# File 'lib/cisco_node_utils/encapsulation.rb', line 40

def self.encaps
  return {} unless Feature.vni_enabled?
  instances = config_get('encapsulation', 'all_encaps')
  return {} if instances.nil?
  hash = {}
  instances.each do |name|
    hash[name] = Encapsulation.new(name, false)
  end
  hash
end

.string_to_array(string) ⇒ Object

This will expand the string to a list of bds as integers



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/cisco_node_utils/encapsulation.rb', line 52

def self.string_to_array(string)
  list = []
  narray = string.split(',')
  narray.each do |elem|
    if elem.include?('-')
      es = elem.gsub('-', '..')
      ea = es.split('..').map { |d| Integer(d) }
      er = ea[0]..ea[1]
      list << er.to_a
    else
      list << elem.to_i
    end
  end
  list.flatten
end

Instance Method Details

#createObject

Enable feature and create encap instance



69
70
71
72
# File 'lib/cisco_node_utils/encapsulation.rb', line 69

def create
  Feature.vni_enable
  config_set('encapsulation', 'create', profile: @encap_name)
end

#default_dot1q_mapObject



108
109
110
# File 'lib/cisco_node_utils/encapsulation.rb', line 108

def default_dot1q_map
  config_get_default('encapsulation', 'dot1q_map')
end

#destroyObject

Destroy an encap instance



75
76
77
# File 'lib/cisco_node_utils/encapsulation.rb', line 75

def destroy
  config_set('encapsulation', 'destroy', profile: @encap_name)
end

#dot1q_mapObject



87
88
89
90
91
92
93
94
# File 'lib/cisco_node_utils/encapsulation.rb', line 87

def dot1q_map
  result = config_get('encapsulation', 'dot1q_map', profile: @encap_name)
  return default_dot1q_map if result.empty?

  result[0] = range_summarize(result[0])
  result[1] = range_summarize(result[1])
  result
end

#dot1q_map=(map) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
# File 'lib/cisco_node_utils/encapsulation.rb', line 96

def dot1q_map=(map)
  state = ''
  if map.empty?
    state = 'no'
    map = dot1q_map
    return if map.empty?
  end
  vlans, vnis = map
  config_set('encapsulation', 'dot1q_map', profile: @encap_name,
             state: state, vlans: vlans, vnis: vnis)
end

#range_summarize(string) ⇒ Object


PROPERTIES




83
84
85
# File 'lib/cisco_node_utils/encapsulation.rb', line 83

def range_summarize(string)
  Utils.array_to_str(Encapsulation.string_to_array(string.to_s), false)
end

#to_sObject



35
36
37
# File 'lib/cisco_node_utils/encapsulation.rb', line 35

def to_s
  "Encapsulation #{encap_name}"
end