Class: Cisco::Vdc

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

Overview

node_utils class for vdc

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

Returns a new instance of Vdc.



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

def initialize(name, instantiate=true)
  @vdc = (name == 'default') ? Vdc.default_vdc_name : name
  create if instantiate
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

Class Method Details

.default_vdc_nameObject



47
48
49
50
51
# File 'lib/cisco_node_utils/vdc.rb', line 47

def self.default_vdc_name
  vdc = config_get('vdc', 'default_vdc_name')
  fail 'default vdc not found, platform may not support vdc' if vdc.nil?
  vdc
end

.vdc_supportObject



43
44
45
# File 'lib/cisco_node_utils/vdc.rb', line 43

def self.vdc_support
  config_get('vdc', 'vdc_support')
end

.vdcsObject



32
33
34
35
36
37
38
39
40
41
# File 'lib/cisco_node_utils/vdc.rb', line 32

def self.vdcs
  hash = {}
  vdc_list = config_get('vdc', 'all_vdcs')
  return hash if vdc_list.nil?

  vdc_list.each do |vdc_name|
    hash[vdc_name] = Vdc.new(vdc_name, false)
  end
  hash
end

Instance Method Details

#==(other) ⇒ Object



60
61
62
# File 'lib/cisco_node_utils/vdc.rb', line 60

def ==(other)
  name == other.name
end

#allocate_interfaceObject

PROPERTIES #



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

def allocate_interface
  # TBD: This property is only partially implemented because it is currently
  # only used for minitest & beaker.
  config_get('vdc', 'allocate_interface', vdc: @vdc)
end

#createObject



53
54
55
56
57
58
# File 'lib/cisco_node_utils/vdc.rb', line 53

def create
  fail ArgumentError,
       'There is currently no support for non-default VDCs' unless
    @vdc == Vdc.default_vdc_name
  # noop for 'default' vdc
end

#default_interface_membershipObject



114
115
116
# File 'lib/cisco_node_utils/vdc.rb', line 114

def default_interface_membership
  config_get_default('vdc', 'membership')
end

#default_limit_resource_module_typeObject



102
103
104
# File 'lib/cisco_node_utils/vdc.rb', line 102

def default_limit_resource_module_type
  config_get_default('vdc', 'limit_resource_module_type')
end

#interface_membershipObject



106
107
108
# File 'lib/cisco_node_utils/vdc.rb', line 106

def interface_membership
  config_get('vdc', 'membership', vdc: @vdc)
end

#interface_membership=(intf) ⇒ Object



110
111
112
# File 'lib/cisco_node_utils/vdc.rb', line 110

def interface_membership=(intf)
  config_set('vdc', 'membership', vdc: @vdc, intf: intf)
end

#limit_resource_module_typeObject



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

def limit_resource_module_type
  str = config_get('vdc', 'limit_resource_module_type', vdc: @vdc)
  str.strip! unless str.nil?
end

#limit_resource_module_type=(mods) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/cisco_node_utils/vdc.rb', line 79

def limit_resource_module_type=(mods)
  state = mods.empty? ? 'no' : ''
  begin
    # limit-resource commands are time-consuming and process in the
    # background. Back-to-back LR commands may fail if processed too
    # quickly.
    config_set('vdc', 'limit_resource_module_type',
               state: state, vdc: @vdc, mods: mods)

    # TBD: No interfaces are allocated after changing the module-type
    # so 'allocate' is needed to make this useful. Consider moving
    # this into it's own property.
    config_set('vdc', 'allocate_interface_unallocated', vdc: @vdc)

  rescue CliError => e
    count ||= 1
    if e.message[/VDC is not in active state/] && (count += 1) < 10
      retry
    end
    raise
  end
end