module PuppetX::NetDev::EosProviderMethods
EosProviderMethods
is meant to be mixed into the provider to make api methods available.
Public Instance Methods
api returns a memoized instance of the EosApi
. This method is intended to be used from providers that have mixed in the EosProviderMethods
module.
@return [PuppetX::NetDev::EosApi] api instance
# File lib/puppet_x/net_dev/eos_api.rb, line 845 def api @api ||= EosApi.new end
bandwidth_to_speed
converts a raw bandwidth integer to a Link speed
- 10m|100m|1g|10g|40g|56g|100g
-
@param [Fixnum] bandwidth The bandwdith value in bytes per second
@api public
@return [String] Link speed [10m|100m|1g|10g|40g|56g|100g]
# File lib/puppet_x/net_dev/eos_api.rb, line 858 def bandwidth_to_speed(bandwidth) if bandwidth >= 1_000_000_000 "#{(bandwidth / 1_000_000_000).to_i}g" else "#{(bandwidth / 1_000_000).to_i}m" end end
convert_speed
takes a speed value from the catalog as a string and converts it to a speed prefix suitable for the Arista API. The following table is used to perform the conversion.
10000full Disable autoneg and force 10 Gbps/full duplex operation 1000full Disable autoneg and force 1 Gbps/full duplex operation 1000half Disable autoneg and force 1 Gbps/half duplex operation 100full Disable autoneg and force 100 Mbps/full duplex operation 100gfull Disable autoneg and force 100 Gbps/full duplex operation 100half Disable autoneg and force 100 Mbps/half duplex operation 10full Disable autoneg and force 10 Mbps/full duplex operation 10half Disable autoneg and force 10 Mbps/half duplex operation 40gfull Disable autoneg and force 40 Gbps/full duplex operation
@param [String] speed The speed specified in the catalog, e.g. 1g
@api private
@return [String] The speed for the API, e.g. 1000
# File lib/puppet_x/net_dev/eos_api.rb, line 974 def convert_speed(value) speed = value.to_s if /g$/i.match(speed) && (speed.to_i > 40) speed elsif /g$/i.match(speed) (speed.to_i * 1000).to_s elsif /m$/i.match(speed) speed.to_i.to_s end end
duplex_to_value
Convert a duplex string from the API response to the provider value
@param [String] duplex The value from the API response
@api public
@return [Symbol] the value for the provider
# File lib/puppet_x/net_dev/eos_api.rb, line 875 def duplex_to_value(duplex) case duplex when 'duplexFull' then :full when 'duplexHalf' then :half else fail ArgumentError, "Unknown duplex value #{duplex.inspect}" end end
flush_speed_and_duplex
consolidates the duplex and speed settings into one API call to manage the interface speed.
@param [String] name The name of the interface, e.g. ‘Ethernet1’
# File lib/puppet_x/net_dev/eos_api.rb, line 943 def flush_speed_and_duplex(name) speed = convert_speed(@property_flush[:speed]) duplex = @property_flush[:duplex] return nil unless speed || duplex speed_out = speed ? speed : convert_speed(@property_hash[:speed]) duplex_out = duplex ? duplex.downcase : @property_hash[:duplex].to_s api.set_interface_speed(name, "#{speed_out}#{duplex_out}") end
interface_attributes
takes an attribute hash from the EOS API and maps the values to provider attributes for the network_interface type.
@param [Hash] attr_hash Interface attribute hash
@api public
@return [Hash] provider attributes suitable for merge into a provider
hash that will be passed to the provider initializer.
# File lib/puppet_x/net_dev/eos_api.rb, line 910 def interface_attributes(attr_hash) hsh = {} status = attr_hash['interfaceStatus'] hsh[:enable] = interface_status_to_enable(status) hsh[:mtu] = attr_hash['mtu'] hsh[:speed] = bandwidth_to_speed(attr_hash['bandwidth']) hsh[:duplex] = duplex_to_value(attr_hash['duplex']) hsh[:description] = attr_hash['description'] hsh end
interface_status_to_enable
maps the interfaceStatus attribute of the API response to the enable state of :true or :false
The interfaceStatus reflects realtime status so its a bit funny how it works. If interfaceStatus == ‘disabled’ then the interface is administratively disabled (ie configured to be disabled) otherwise its enabled (ie no shutdown). So in your conversion here you can just reflect if interfaceStatus == ‘disabled’ or not as the state.
@param [String] status the value of interfaceStatus returned by the API
@return [Symbol] :true or :false
# File lib/puppet_x/net_dev/eos_api.rb, line 896 def interface_status_to_enable(status) status == 'disabled' ? :false : :true end
port_channel_attributes
takes an attribute hash from the EOS API and maps the values to provider attributes for the port_channel type.
@param [Hash] attr_hash Interface attribute hash
@api public
@return [Hash] provider attributes suitable for merge into a provider
hash that will be passed to the provider initializer.
# File lib/puppet_x/net_dev/eos_api.rb, line 931 def port_channel_attributes(attr_hash) hsh = {} hsh[:speed] = bandwidth_to_speed(attr_hash['bandwidth']) hsh[:description] = attr_hash['description'] hsh end