Skip to content

Conversation

@codeout
Copy link
Contributor

@codeout codeout commented Oct 25, 2019

Issue: eAPI doesn't support atomic operations

When we run commands below via eAPI, we'll see an error saying "Address 172.16.0.1 is already assigned to interface Ethernet6" at L7, and L1-L6 are committed.

However, sometimes I'd like to do this as an atomic operation, where abort everything when something goes wrong.

This PR will support that behavior with introducing Node#configure_session().

1: interface Ethernet6
2:    no switchport
3:    ip address 172.16.0.1/30
4: !
5: interface Ethernet7
6:    no switchport
7:    ip address 172.16.0.1/30  ! Invalid
{
  "jsonrpc": "2.0",
  "method": "runCmds",
  "params": {
    "format": "json",
    "timestamps": false,
    "autoComplete": false,
    "expandAliases": false,
    "cmds": [
      "configure",
      "interface Ethernet6",
      "   no switchport",
      "   ip address 172.16.0.1/30",
      "interface Ethernet7",
      "   no switchport",
      "   ip address 172.16.0.1/30"
    ],
    "version": 1
  },
  "id": "EapiExplorer-1"
}

Usage

node = pyeapi.connect_to('veos01')
vlans = node.api('vlans')

node.configure_session()
vlans.create(100)  # Sends "configure session 9c27d0e8-afef-4afd-95ae-3e3200bb7a3e" and "vlan 100"

node.diff()  # Sends "configure session 9c27d0e8-afef-4afd-95ae-3e3200bb7a3e" and "show session-config diff" 
"""
=>
--- system:/running-config
+++ session:/9c27d0e8-afef-4afd-95ae-3e3200bb7a3e-session-config
@@ -32,7 +32,7 @@
 !
 clock timezone Asia/Tokyo
 !
-vlan 1000,3001-3006
+vlan 100,1000,3001-3006
 !
 interface Port-Channel1
    switchport trunk allowed vlan 3001-3003
"""

node.abort()  # Sends "configure session 9c27d0e8-afef-4afd-95ae-3e3200bb7a3e" and "abort" 
# or
node.commit() # Sends "configure session 9c27d0e8-afef-4afd-95ae-3e3200bb7a3e" and "commit" 
"""

When there is something invalid:

node = pyeapi.connect_to('veos01')
interfaces = node.api('interfaces')

if not (interfaces.configure(['interface Eth6', 'no switchport', 'ip address 172.16.0.1/30']) and \
    interfaces.configure(['interface Eth7', 'no switchport', 'ip address 172.16.0.1/30'])):
    node.abort()  # This aborts everything!!

Note

If Node#configure_session() isn't called, nothing changed in library behavior.

Test result

With vEOS below,

Software image version: 4.22.0F
Architecture:           i386
Internal build version: 4.22.0F-12170486.4220F
Internal build ID:      2c34e816-9aa7-4c63-9a32-05140aec7dbd

I haven't broken anything hopefully, and I don't see any performance impact here.

develop branch:

$ grep -A2 Ran result.develop
Ran 415 tests in 0.348s

OK
--
Ran 282 tests in 107.999s

FAILED (failures=7)

PR branch:

$ grep -A2 Ran result.pr
Ran 415 tests in 0.348s

OK
--
Ran 282 tests in 103.887s

FAILED (failures=7)

… "show session-config diff", commit() for "commit", and abort() for "abort"
@mharista mharista merged commit 052b500 into arista-eosplus:develop Feb 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants