Class: Cisco::Vrf

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

Overview

Vrf - node utility class for VRF configuration management

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) ⇒ Vrf

Returns a new instance of Vrf.



27
28
29
30
31
# File 'lib/cisco_node_utils/vrf.rb', line 27

def initialize(name, instantiate=true)
  fail TypeError unless name.is_a?(String)
  @name = name.downcase.strip
  create if instantiate
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

Class Method Details

.vrfsObject



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/cisco_node_utils/vrf.rb', line 37

def self.vrfs
  hash = {}
  vrf_list = config_get('vrf', 'all_vrfs')
  return hash if vrf_list.nil?

  vrf_list.each do |id|
    id = id.downcase.strip
    hash[id] = Vrf.new(id, false)
  end
  hash
end

Instance Method Details

#createObject



49
50
51
# File 'lib/cisco_node_utils/vrf.rb', line 49

def create
  config_set('vrf', 'create', vrf: @name)
end

#default_descriptionObject



72
73
74
# File 'lib/cisco_node_utils/vrf.rb', line 72

def default_description
  config_get_default('vrf', 'description')
end

#default_mhost_ipv4_default_interfaceObject



84
85
86
# File 'lib/cisco_node_utils/vrf.rb', line 84

def default_mhost_ipv4_default_interface
  config_get_default('vrf', 'mhost_default_interface')
end

#default_mhost_ipv6_default_interfaceObject



96
97
98
# File 'lib/cisco_node_utils/vrf.rb', line 96

def default_mhost_ipv6_default_interface
  config_get_default('vrf', 'mhost_default_interface')
end

#default_remote_route_filteringObject



117
118
119
# File 'lib/cisco_node_utils/vrf.rb', line 117

def default_remote_route_filtering
  config_get_default('vrf', 'remote_route_filtering')
end

#default_route_distinguisherObject



158
159
160
# File 'lib/cisco_node_utils/vrf.rb', line 158

def default_route_distinguisher
  config_get_default('vrf', 'route_distinguisher')
end

#default_shutdownObject



130
131
132
# File 'lib/cisco_node_utils/vrf.rb', line 130

def default_shutdown
  config_get_default('vrf', 'shutdown')
end

#default_vniObject



174
175
176
# File 'lib/cisco_node_utils/vrf.rb', line 174

def default_vni
  config_get_default('vrf', 'vni')
end

#default_vpn_idObject



188
189
190
# File 'lib/cisco_node_utils/vrf.rb', line 188

def default_vpn_id
  config_get_default('vrf', 'vpn_id')
end

#descriptionObject

PROPERTIES #



61
62
63
# File 'lib/cisco_node_utils/vrf.rb', line 61

def description
  config_get('vrf', 'description', vrf: @name)
end

#description=(desc) ⇒ Object



65
66
67
68
69
70
# File 'lib/cisco_node_utils/vrf.rb', line 65

def description=(desc)
  fail TypeError unless desc.is_a?(String)
  desc.strip!
  no_cmd = desc.empty? ? 'no' : ''
  config_set('vrf', 'description', vrf: @name, state: no_cmd, desc: desc)
end

#destroyObject



53
54
55
# File 'lib/cisco_node_utils/vrf.rb', line 53

def destroy
  config_set('vrf', 'destroy', vrf: @name)
end

#mhost_default_interface_setter_helper(afi, val) ⇒ Object



100
101
102
103
104
105
# File 'lib/cisco_node_utils/vrf.rb', line 100

def mhost_default_interface_setter_helper(afi, val)
  val.strip!
  no_cmd = val.empty? ? 'no' : ''
  config_set('vrf', 'mhost_default_interface', vrf: @name,
             state: no_cmd, afi: afi, intf: val)
end

#mhost_ipv4_default_interfaceObject



76
77
78
# File 'lib/cisco_node_utils/vrf.rb', line 76

def mhost_ipv4_default_interface
  config_get('vrf', 'mhost_default_interface', vrf: @name, afi: 'ipv4')
end

#mhost_ipv4_default_interface=(val) ⇒ Object



80
81
82
# File 'lib/cisco_node_utils/vrf.rb', line 80

def mhost_ipv4_default_interface=(val)
  mhost_default_interface_setter_helper('ipv4', val)
end

#mhost_ipv6_default_interfaceObject



88
89
90
# File 'lib/cisco_node_utils/vrf.rb', line 88

def mhost_ipv6_default_interface
  config_get('vrf', 'mhost_default_interface', vrf: @name, afi: 'ipv6')
end

#mhost_ipv6_default_interface=(val) ⇒ Object



92
93
94
# File 'lib/cisco_node_utils/vrf.rb', line 92

def mhost_ipv6_default_interface=(val)
  mhost_default_interface_setter_helper('ipv6', val)
end

#remote_route_filteringObject



107
108
109
# File 'lib/cisco_node_utils/vrf.rb', line 107

def remote_route_filtering
  config_get('vrf', 'remote_route_filtering', vrf: @name)
end

#remote_route_filtering=(val) ⇒ Object



111
112
113
114
115
# File 'lib/cisco_node_utils/vrf.rb', line 111

def remote_route_filtering=(val)
  no_cmd = val ? 'no' : ''
  config_set('vrf', 'remote_route_filtering', vrf: @name,
             state: no_cmd, remote_route_filtering: val)
end

#route_distinguisherObject

route_distinguisher Note that this property is supported by both bgp and vrf providers.



136
137
138
# File 'lib/cisco_node_utils/vrf.rb', line 136

def route_distinguisher
  config_get('vrf', 'route_distinguisher', vrf: @name)
end

#route_distinguisher=(rd) ⇒ Object



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/cisco_node_utils/vrf.rb', line 140

def route_distinguisher=(rd)
  # feature bgp and nv overlay required for rd cli in NXOS
  if platform == :nexus
    Feature.bgp_enable
    Feature.nv_overlay_enable if Feature.nv_overlay_supported?
    Feature.nv_overlay_evpn_enable if Feature.nv_overlay_evpn_supported?
  end
  if rd == default_route_distinguisher
    state = 'no'
    # I2 images require an rd for removal
    rd = route_distinguisher
    return if rd.to_s.empty?
  else
    state = ''
  end
  config_set('vrf', 'route_distinguisher', state: state, vrf: @name, rd: rd)
end

#shutdownObject



121
122
123
# File 'lib/cisco_node_utils/vrf.rb', line 121

def shutdown
  config_get('vrf', 'shutdown', vrf: @name)
end

#shutdown=(val) ⇒ Object



125
126
127
128
# File 'lib/cisco_node_utils/vrf.rb', line 125

def shutdown=(val)
  no_cmd = (val) ? '' : 'no'
  config_set('vrf', 'shutdown', vrf: @name, state: no_cmd)
end

#to_sObject



33
34
35
# File 'lib/cisco_node_utils/vrf.rb', line 33

def to_s
  "VRF #{@name}"
end

#vniObject

Vni (Getter/Setter/Default)



163
164
165
# File 'lib/cisco_node_utils/vrf.rb', line 163

def vni
  config_get('vrf', 'vni', vrf: @name)
end

#vni=(id) ⇒ Object



167
168
169
170
171
172
# File 'lib/cisco_node_utils/vrf.rb', line 167

def vni=(id)
  Feature.vn_segment_vlan_based_enable if platform == :nexus
  no_cmd = (id) ? '' : 'no'
  id = (id) ? id : vni
  config_set('vrf', 'vni', vrf: @name, state: no_cmd, id: id)
end

#vpn_idObject



178
179
180
# File 'lib/cisco_node_utils/vrf.rb', line 178

def vpn_id
  config_get('vrf', 'vpn_id', vrf: @name)
end

#vpn_id=(val) ⇒ Object



182
183
184
185
186
# File 'lib/cisco_node_utils/vrf.rb', line 182

def vpn_id=(val)
  val.strip!
  no_cmd = val.empty? ? 'no' : ''
  config_set('vrf', 'vpn_id', vrf: @name, state: no_cmd, vpnid: val)
end