Class: Cisco::ObjectGroup

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

Overview

node_utils class for object_group

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(afi, type, name, instantiate = true) ⇒ ObjectGroup

Returns a new instance of ObjectGroup


26
27
28
29
30
31
32
33
34
35
# File 'lib/cisco_node_utils/object_group.rb', line 26

def initialize(afi, type, name, instantiate=true)
  fail TypeError unless name.is_a?(String)
  fail ArgumentError unless type[/address|port/]
  @afi = Acl.afi_cli(afi)
  @type = type
  @grp_name = name

  set_args_keys_default
  create if instantiate
end

Instance Attribute Details

#afiObject (readonly)

Returns the value of attribute afi


24
25
26
# File 'lib/cisco_node_utils/object_group.rb', line 24

def afi
  @afi
end

#grp_nameObject (readonly)

Returns the value of attribute grp_name


24
25
26
# File 'lib/cisco_node_utils/object_group.rb', line 24

def grp_name
  @grp_name
end

#typeObject (readonly)

Returns the value of attribute type


24
25
26
# File 'lib/cisco_node_utils/object_group.rb', line 24

def type
  @type
end

Class Method Details

.object_groupsObject


61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/cisco_node_utils/object_group.rb', line 61

def self.object_groups
  hash = {}
  grps = config_get('object_group', 'all_object_groups')
  return hash if grps.nil?
  grps.each do |afi, type, name|
    lafi = afi
    lafi = 'ipv4' if afi == 'ip'
    hash[lafi] ||= {}
    hash[lafi][type] ||= {}
    hash[lafi][type][name] = ObjectGroup.new(lafi, type, name, false)
  end
  hash
end

Instance Method Details

#==(other) ⇒ Object


57
58
59
# File 'lib/cisco_node_utils/object_group.rb', line 57

def ==(other)
  grp_name == other.grp_name && afi == other.afi && type == other.type
end

#createObject


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

def create
  config_set('object_group', 'create', @set_args)
end

#destroyObject


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

def destroy
  config_set('object_group', 'destroy', @set_args)
end

#set_args_keys(hash = {}) ⇒ Object

rubocop:disable Style/AccessorMethodName


44
45
46
47
# File 'lib/cisco_node_utils/object_group.rb', line 44

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

#set_args_keys_defaultObject

Helper method to delete @set_args hash keys


38
39
40
41
# File 'lib/cisco_node_utils/object_group.rb', line 38

def set_args_keys_default
  @set_args = { afi: @afi, type: @type, grp_name: @grp_name }
  @get_args = @set_args
end