Class: Rbeapi::Api::PortchannelInterface
- Inherits:
-
BaseInterface
- Object
- Entity
- BaseInterface
- Rbeapi::Api::PortchannelInterface
- Defined in:
- lib/rbeapi/api/interfaces.rb
Constant Summary collapse
- DEFAULT_LACP_FALLBACK =
'disabled'- DEFAULT_LACP_MODE =
'on'- DEFAULT_MIN_LINKS =
'0'
Constants inherited from BaseInterface
BaseInterface::DEFAULT_INTF_DESCRIPTION
Instance Attribute Summary
Attributes inherited from Entity
Instance Method Summary collapse
-
#add_member(name, member) ⇒ Boolean
add_member adds the interface specified in member to the port-channel interface specified by name in the nodes running-configuration.
-
#get(name) ⇒ nil, Hash<Symbol, Object>
get returns the specified port-channel interface configuration from the nodes running configuration as a resource hash.
-
#remove_member(name, member) ⇒ Boolean
remove_member removes the interface specified in member from the port-channel interface specified by name in the nodes running-configuration.
-
#set_lacp_fallback(name, opts = {}) ⇒ Boolean
set_lacp_fallback configures the lacp fallback mode for the port-channel interface.
-
#set_lacp_mode(name, mode) ⇒ Boolean
set_lacp_mode configures the lacp mode on the port-channel interface by configuring the lacp mode value for each member interface.
-
#set_lacp_timeout(name, opts = {}) ⇒ Boolean
set_lacp_timeout configures the lacp fallback timeou for the port-channel interface.
-
#set_members(name, members) ⇒ Boolean
set_members configures the set of physical interfaces that comprise the logical port-channel interface.
-
#set_minimum_links(name, opts = {}) ⇒ Boolean
set_minimum_links configures the minimum physical links up required to consider the logical portchannel interface operationally up.
Methods inherited from BaseInterface
#create, #default, #delete, #set_description, #set_shutdown
Methods inherited from Entity
#configure, #get_block, #initialize, instance
Constructor Details
This class inherits a constructor from Rbeapi::Api::Entity
Instance Method Details
#add_member(name, member) ⇒ Boolean
add_member adds the interface specified in member to the port-channel interface specified by name in the nodes running-configuration. If the port-channel interface does not already exist, it will be created.
897 898 899 900 901 |
# File 'lib/rbeapi/api/interfaces.rb', line 897 def add_member(name, member) lacp = parse_lacp_mode(name)[:lacp_mode] grpid = /(\d+)/.match(name)[0] configure ["interface #{member}", "channel-group #{grpid} mode #{lacp}"] end |
#get(name) ⇒ nil, Hash<Symbol, Object>
get returns the specified port-channel interface configuration from the nodes running configuration as a resource hash. The resource hash returned extends the BaseInterface resource hash, sets the type value to portchannel and adds the portchannel specific attributes
684 685 686 687 688 689 690 691 692 693 694 695 |
# File 'lib/rbeapi/api/interfaces.rb', line 684 def get(name) config = get_block("^interface #{name}") return nil unless config response = super(name) response[:type] = 'portchannel' response.merge!(parse_members(name)) response.merge!(parse_lacp_mode(name)) response.merge!(parse_minimum_links(config)) response.merge!(parse_lacp_fallback(config)) response.merge!(parse_lacp_timeout(config)) response end |
#remove_member(name, member) ⇒ Boolean
remove_member removes the interface specified in member from the port-channel interface specified by name in the nodes running-configuration.
921 922 923 924 |
# File 'lib/rbeapi/api/interfaces.rb', line 921 def remove_member(name, member) grpid = /(\d+)/.match(name)[0] configure ["interface #{member}", "no channel-group #{grpid}"] end |
#set_lacp_fallback(name, opts = {}) ⇒ Boolean
set_lacp_fallback configures the lacp fallback mode for the port-channel interface. If no value is provided, lacp fallback is configured using the no keyword argument. If the default option is specified and set to true, the lacp fallback value is configured using the default keyword. The default keyword takes precedence over the value keyword if both options are provided.
992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 |
# File 'lib/rbeapi/api/interfaces.rb', line 992 def set_lacp_fallback(name, opts = {}) value = opts[:value] default = opts.fetch(:default, false) cmds = ["interface #{name}"] case default when true cmds << 'default port-channel lacp fallback' when false if [nil, 'disabled'].include?(value) cmds << 'no port-channel lacp fallback' else cmds << "port-channel lacp fallback #{value}" end end configure(cmds) end |
#set_lacp_mode(name, mode) ⇒ Boolean
set_lacp_mode configures the lacp mode on the port-channel interface by configuring the lacp mode value for each member interface. This method will find all member interfaces for a port-channel and reconfigure them using the mode argument.
947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 |
# File 'lib/rbeapi/api/interfaces.rb', line 947 def set_lacp_mode(name, mode) return false unless %w(on passive active).include?(mode) grpid = /(\d+)/.match(name)[0] remove_commands = [] add_commands = [] parse_members(name)[:members].each do |member| remove_commands << "interface #{member}" remove_commands << "no channel-group #{grpid}" add_commands << "interface #{member}" add_commands << "channel-group #{grpid} mode #{mode}" end configure remove_commands + add_commands end |
#set_lacp_timeout(name, opts = {}) ⇒ Boolean
set_lacp_timeout configures the lacp fallback timeou for the port-channel interface. If no value is provided, lacp fallback timeout is configured using the no keyword argument. If the default option is specified and set to true, the lacp fallback timeout value is configured using the default keyword. The default keyword takes precedence over the value keyword if both options are provided.
1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 |
# File 'lib/rbeapi/api/interfaces.rb', line 1039 def set_lacp_timeout(name, opts = {}) value = opts[:value] default = opts.fetch(:default, false) cmds = ["interface #{name}"] case default when true cmds << 'default port-channel lacp fallback timeout' when false cmds << (value ? "port-channel lacp fallback timeout #{value}" : \ 'no port-channel lacp fallback timeout') end configure(cmds) end |
#set_members(name, members) ⇒ Boolean
set_members configures the set of physical interfaces that comprise the logical port-channel interface. The members value passed should be an array of physical interface names that comprise the port-channel interface. This method will add and remove individual members as required to sync the provided members array
860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 |
# File 'lib/rbeapi/api/interfaces.rb', line 860 def set_members(name, members) current_members = Set.new parse_members(name)[:members] members = Set.new members # remove members from the current port-channel interface current_members.difference(members).each do |intf| result = remove_member(name, intf) return false unless result end # add new member interfaces to the port-channel members.difference(current_members).each do |intf| result = add_member(name, intf) return false unless result end return true end |
#set_minimum_links(name, opts = {}) ⇒ Boolean
set_minimum_links configures the minimum physical links up required to consider the logical portchannel interface operationally up. If no value is provided then the minimum-links is configured using the no keyword argument. If the default keyword argument is provided and set to true, the minimum-links value is defaulted using the default keyword. The default keyword takes precedence over the value keyword argument if both are provided.
827 828 829 830 831 832 833 834 835 836 837 838 839 840 |
# File 'lib/rbeapi/api/interfaces.rb', line 827 def set_minimum_links(name, opts = {}) value = opts[:value] default = opts.fetch(:default, false) cmds = ["interface #{name}"] case default when true cmds << 'default port-channel min-links' when false cmds << (value ? "port-channel min-links #{value}" : \ 'no port-channel min-links') end configure(cmds) end |