Class: Puppet::Provider::NetworkInterface::CiscoNexus
- Inherits:
-
Object
- Object
- Puppet::Provider::NetworkInterface::CiscoNexus
- Defined in:
- lib/puppet/provider/network_interface/cisco_nexus.rb
Overview
Copyright © 2018 Cisco and/or its affiliates.
Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. Implementation for the network_interface type using the Resource API.
Instance Method Summary collapse
- #canonicalize(_context, resources) ⇒ Object
- #convert_speed_to_type(speed) ⇒ Object
- #convert_type_to_speed(type) ⇒ Object
- #get(_context, interfaces = nil) ⇒ Object
- #get_current_state(name, interface) ⇒ Object
- #set(context, changes) ⇒ Object
- #update(_context, name, should) ⇒ Object
Instance Method Details
#canonicalize(_context, resources) ⇒ Object
16 17 18 |
# File 'lib/puppet/provider/network_interface/cisco_nexus.rb', line 16 def canonicalize(_context, resources) resources end |
#convert_speed_to_type(speed) ⇒ Object
78 79 80 81 82 83 84 85 86 87 |
# File 'lib/puppet/provider/network_interface/cisco_nexus.rb', line 78 def convert_speed_to_type(speed) case speed.to_s when '100' then '100m' when '1000' then '1g' when '10000' then '10g' when '40000' then '40g' when '100000' then '100g' else speed end end |
#convert_type_to_speed(type) ⇒ Object
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/puppet/provider/network_interface/cisco_nexus.rb', line 67 def convert_type_to_speed(type) case type.to_s when '100m' then 100 when '1g' then 1000 when '10g' then 10_000 when '40g' then 40_000 when '100g' then 100_000 else type end end |
#get(_context, interfaces = nil) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/puppet/provider/network_interface/cisco_nexus.rb', line 20 def get(_context, interfaces=nil) require 'cisco_node_utils' current_state = [] @interfaces = Cisco::Interface.interfaces if interfaces.nil? || interfaces.empty? @interfaces.each do |interface_name, interface| current_state << get_current_state(interface_name, interface) end else interfaces.each do |interface| individual_interface = @interfaces[interface] next if individual_interface.nil? current_state << get_current_state(interface, individual_interface) end end current_state end |
#get_current_state(name, interface) ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/puppet/provider/network_interface/cisco_nexus.rb', line 39 def get_current_state(name, interface) { name: name, description: interface.description, mtu: interface.mtu, speed: convert_speed_to_type(interface.speed), duplex: interface.duplex, enable: !interface.shutdown, } end |
#set(context, changes) ⇒ Object
50 51 52 53 54 |
# File 'lib/puppet/provider/network_interface/cisco_nexus.rb', line 50 def set(context, changes) changes.each do |name, change| update(context, name, change[:should]) if change[:should] != change[:is] end end |
#update(_context, name, should) ⇒ Object
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/puppet/provider/network_interface/cisco_nexus.rb', line 56 def update(_context, name, should) @interfaces = Cisco::Interface.interfaces interface = @interfaces[name] interface.shutdown = !should[:enable] if should.key? :enable interface.mtu = should[:mtu] if should.key? :mtu interface.description = should[:description] if should.key? :description interface.speed = convert_type_to_speed(should[:speed]) if should.key? :speed interface.duplex = should[:duplex] if should.key? :duplex end |