Class: Cisco::InterfaceServiceVni

Inherits:
NodeUtil
  • Object
show all
Defined in:
lib/cisco_node_utils/interface_service_vni.rb

Overview

InterfaceServiceVni - node utility class for Service VNI Instance commands

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(intf, sid, instantiate = true) ⇒ InterfaceServiceVni

Returns a new instance of InterfaceServiceVni.



25
26
27
28
29
30
31
# File 'lib/cisco_node_utils/interface_service_vni.rb', line 25

def initialize(intf, sid, instantiate=true)
  @name = intf.to_s.downcase
  @sid = sid.to_s
  fail ArgumentError if @name.empty? || @sid.empty?
  set_args_keys_default
  create if instantiate
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



23
24
25
# File 'lib/cisco_node_utils/interface_service_vni.rb', line 23

def name
  @name
end

Class Method Details

.svc_vni_idsObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/cisco_node_utils/interface_service_vni.rb', line 37

def self.svc_vni_ids
  hash = {}
  intf_list = config_get('interface_service_vni', 'all_interfaces')
  return hash if intf_list.nil?

  intf_list.each do |intf|
    intf.downcase!
    svc_ids = config_get('interface_service_vni', 'all_service_vni_ids',
                         name: intf)
    next if svc_ids.nil?
    hash[intf] = {}
    svc_ids.each do |sid|
      hash[intf][sid] = InterfaceServiceVni.new(intf, sid, false)
    end
  end
  hash
end

Instance Method Details

#createObject



55
56
57
58
59
# File 'lib/cisco_node_utils/interface_service_vni.rb', line 55

def create
  Feature.vni_enable
  @set_args[:state] = ''
  config_set('interface_service_vni', 'create_destroy', @set_args)
end

#default_encapsulation_profile_vniObject



112
113
114
# File 'lib/cisco_node_utils/interface_service_vni.rb', line 112

def default_encapsulation_profile_vni
  config_get_default('interface_service_vni', 'encapsulation_profile_vni')
end

#default_shutdownObject



128
129
130
# File 'lib/cisco_node_utils/interface_service_vni.rb', line 128

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

#destroyObject



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

def destroy
  @set_args[:state] = 'no'
  config_set('interface_service_vni', 'create_destroy', @set_args)
end

#encapsulation_profile_vniObject

encapsulation_profile_vni

 cli: service instance 1 vni
        encapsulation profile vni_500_5000 default
type: 'vni_500_5000'


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

def encapsulation_profile_vni
  config_get('interface_service_vni', 'encapsulation_profile_vni',
             @get_args)
end

#encapsulation_profile_vni=(profile) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/cisco_node_utils/interface_service_vni.rb', line 93

def encapsulation_profile_vni=(profile)
  Feature.vni_enable
  state = profile.empty? ? 'no' : ''
  current = encapsulation_profile_vni

  if state[/no/]
    config_set('interface_service_vni', 'encapsulation_profile_vni',
               set_args_keys(state: state, profile: current)) unless
      current.empty?
  else
    # Remove current profile before adding a new one
    config_set('interface_service_vni', 'encapsulation_profile_vni',
               set_args_keys(state: 'no', profile: current)) unless
      current.empty?
    config_set('interface_service_vni', 'encapsulation_profile_vni',
               set_args_keys(state: state, profile: profile))
  end
end

#set_args_keys(hash = {}) ⇒ Object

rubocop:disable Style/AccessorMethodName



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

def set_args_keys(hash={})
  set_args_keys_default
  @set_args = @get_args.merge!(hash) unless hash.empty?
end

#set_args_keys_defaultObject



66
67
68
69
# File 'lib/cisco_node_utils/interface_service_vni.rb', line 66

def set_args_keys_default
  keys = { name: @name, sid: @sid }
  @get_args = @set_args = keys
end

#shutdownObject

shutdown



119
120
121
# File 'lib/cisco_node_utils/interface_service_vni.rb', line 119

def shutdown
  config_get('interface_service_vni', 'shutdown', @get_args)
end

#shutdown=(state) ⇒ Object



123
124
125
126
# File 'lib/cisco_node_utils/interface_service_vni.rb', line 123

def shutdown=(state)
  config_set('interface_service_vni', 'shutdown',
             set_args_keys(state: state ? '' : 'no'))
end

#to_sObject



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

def to_s
  "interface_service_vni #{name} #{@sid}"
end