Class: Puppet::Provider::PortChannel::CiscoNexus

Inherits:
ResourceApi::SimpleProvider
  • Object
show all
Defined in:
lib/puppet/provider/port_channel/cisco_nexus.rb

Overview

Implementation for the port_channel type using the Resource API.

Instance Method Summary collapse

Instance Method Details

#canonicalize(_context, resources) ⇒ Object



18
19
20
# File 'lib/puppet/provider/port_channel/cisco_nexus.rb', line 18

def canonicalize(_context, resources)
  resources
end

#create(context, name, should) ⇒ Object



86
87
88
89
# File 'lib/puppet/provider/port_channel/cisco_nexus.rb', line 86

def create(context, name, should)
  context.notice("Creating '#{name}' with #{should.inspect}")
  create_update(name, should, true)
end

#create_update(name, should, create_bool) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
# File 'lib/puppet/provider/port_channel/cisco_nexus.rb', line 74

def create_update(name, should, create_bool)
  port_channel = Cisco::InterfacePortChannel.new(name, create_bool)
  if should[:minimum_links]
    port_channel.lacp_min_links = should[:minimum_links]
  end
  return unless should[:interfaces]
  should[:interfaces].each do |i|
    interface = Cisco::InterfaceChannelGroup.interfaces[i]
    interface.channel_group_mode_set(should[:id]) if should[:id]
  end
end

#delete(context, name) ⇒ Object



96
97
98
99
100
# File 'lib/puppet/provider/port_channel/cisco_nexus.rb', line 96

def delete(context, name)
  context.notice("Deleting '#{name}'")
  port_channel = Cisco::InterfacePortChannel.new(name, false)
  port_channel.destroy
end

#get(_context, channels = nil) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/puppet/provider/port_channel/cisco_nexus.rb', line 22

def get(_context, channels=nil)
  require 'cisco_node_utils'

  interfaces = []
  @interfaces = Cisco::InterfaceChannelGroup.interfaces
  @interfaces.each do |interface_name, i|
    interface = {
      interface:     interface_name,
      channel_group: i.send(:channel_group),
    }
    interfaces.push(interface) if i.send(:channel_group)
  end

  portchannels = []
  @channels =  Cisco::InterfacePortChannel.interfaces
  if channels.nil? || channels.empty?
    @channels.each do |port_channel, port|
      portchannels << get_current_state(port_channel, port, interfaces)
    end
  else
    channels.each do |channel|
      individual_channel = @channels[channel]
      next if individual_channel.nil?
      portchannels << get_current_state(channel, individual_channel, interfaces)
    end
  end
  portchannels
end

#get_current_state(name, instance, interfaces) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/puppet/provider/port_channel/cisco_nexus.rb', line 51

def get_current_state(name, instance, interfaces)
  id_number = name[/\d+/].to_i
  interfaces_in_port = []

  interfaces.each do |interface|
    if interface[:channel_group] == id_number
      interfaces_in_port.push(interface[:interface])
    end
  end

  channel = {
    name:          name,
    minimum_links: instance.send(:lacp_min_links),
    id:            id_number,
    ensure:        'present',
  }
  unless interfaces_in_port.empty?
    channel[:interfaces] = interfaces_in_port
  end

  channel
end

#update(context, name, should) ⇒ Object



91
92
93
94
# File 'lib/puppet/provider/port_channel/cisco_nexus.rb', line 91

def update(context, name, should)
  context.notice("Updating '#{name}' with #{should.inspect}")
  create_update(name, should, false)
end