Class: Rbeapi::Api::VarpInterfaces
- Defined in:
- lib/rbeapi/api/varp.rb
Instance Attribute Summary
Attributes inherited from Entity
Instance Method Summary collapse
- #add_address(name, value) ⇒ Object
-
#get(name) ⇒ nil, Hash<String, String>
Returns a single VARP interface configuration.
-
#getall ⇒ nil, Hash<String, String>
Returns the collection of MLAG interfaces as a hash index by the interface name.
- #remove_address(name, value) ⇒ Object
-
#set_addresses(name, opts = {}) ⇒ Boolean
Creates a new MLAG interface with the specified mlag id.
Methods inherited from Entity
#configure, #get_block, #initialize, instance
Constructor Details
This class inherits a constructor from Rbeapi::Api::Entity
Instance Method Details
#add_address(name, value) ⇒ Object
171 172 173 |
# File 'lib/rbeapi/api/varp.rb', line 171 def add_address(name, value) configure(["interface #{name}", "ip virtual-router address #{value}"]) end |
#get(name) ⇒ nil, Hash<String, String>
Returns a single VARP interface configuration
Example
{
"name": <string>,
"addresses": array<string>
}
113 114 115 116 117 118 |
# File 'lib/rbeapi/api/varp.rb', line 113 def get(name) config = get_block("^interface #{name}") return nil unless config addrs = config.scan(/(?<=\s{3}ip\svirtual-router\saddress\s).+$/) { 'addresses' => addrs } end |
#getall ⇒ nil, Hash<String, String>
Returns the collection of MLAG interfaces as a hash index by the interface name
Example
{
<name>: {...},
<name>: {...}
}
133 134 135 136 137 138 139 |
# File 'lib/rbeapi/api/varp.rb', line 133 def getall interfaces = config.scan(/(?<=^interface\s)(Vl.+)$/) interfaces.first.each_with_object({}) do |name, resp| data = get(name) resp[name] = data if data end end |
#remove_address(name, value) ⇒ Object
175 176 177 178 |
# File 'lib/rbeapi/api/varp.rb', line 175 def remove_address(name, value) configure(["interface #{name}", "no ip virtual-router address #{value}"]) end |
#set_addresses(name, opts = {}) ⇒ Boolean
Creates a new MLAG interface with the specified mlag id
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/rbeapi/api/varp.rb', line 151 def set_addresses(name, opts = {}) value = opts[:value] default = opts[:default] || false case default when true return configure('default ip virtual-router address') when false get(name)['addresses'].each do |addr| result = remove_address(name, addr) return result unless result end value.each do |addr| result = add_address(name, addr) return result unless result end end return true end |