Module: PuppetX::NetDev::EosProviderMethods

Defined in:
lib/puppet_x/net_dev/eos_api.rb

Overview

EosProviderMethods is meant to be mixed into the provider to make api methods available.

Instance Method Summary collapse

Instance Method Details

#apiPuppetX::NetDev::EosApi

api returns a memoized instance of the EosApi. This method is intended to be used from providers that have mixed in the EosProviderMethods module.

Returns:



845
846
847
# File 'lib/puppet_x/net_dev/eos_api.rb', line 845

def api
  @api ||= EosApi.new
end

#bandwidth_to_speed(bandwidth) ⇒ String

bandwidth_to_speed converts a raw bandwidth integer to a Link speed

10m|100m|1g|10g|40g|56g|100g

Parameters:

  • bandwidth (Fixnum)

    The bandwdith value in bytes per second

Returns:

  • (String)

    Link speed [10m|100m|1g|10g|40g|56g|100g]



858
859
860
861
862
863
864
# 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(value) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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

Parameters:

  • speed (String)

    The speed specified in the catalog, e.g. 1g

Returns:

  • (String)

    The speed for the API, e.g. 1000



974
975
976
977
978
979
980
981
982
983
# 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(duplex) ⇒ Symbol

duplex_to_value Convert a duplex string from the API response to the provider value

Parameters:

  • duplex (String)

    The value from the API response

Returns:

  • (Symbol)

    the value for the provider



875
876
877
878
879
880
881
# 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(name) ⇒ Object

flush_speed_and_duplex consolidates the duplex and speed settings into one API call to manage the interface speed.

Parameters:

  • name (String)

    The name of the interface, e.g. ‘Ethernet1’



943
944
945
946
947
948
949
950
951
952
# 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(attr_hash) ⇒ Hash

interface_attributes takes an attribute hash from the EOS API and maps the values to provider attributes for the network_interface type.

Parameters:

  • attr_hash (Hash)

    Interface attribute hash

Returns:

  • (Hash)

    provider attributes suitable for merge into a provider hash that will be passed to the provider initializer.



910
911
912
913
914
915
916
917
918
919
# 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(status) ⇒ Symbol

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.

Parameters:

  • status (String)

    the value of interfaceStatus returned by the API

Returns:

  • (Symbol)

    :true or :false



896
897
898
# 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(attr_hash) ⇒ Hash

port_channel_attributes takes an attribute hash from the EOS API and maps the values to provider attributes for the port_channel type.

Parameters:

  • attr_hash (Hash)

    Interface attribute hash

Returns:

  • (Hash)

    provider attributes suitable for merge into a provider hash that will be passed to the provider initializer.



931
932
933
934
935
936
# 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