Archiv für den Monat: Januar 2019

ARISTA bash event-handler in different VRF context

We are using an event-handler with on-startup-config write to push the configuration to our langley service which push the config in the central GIT repository.

To execute an bash command in an different vrf context use „ip netns exec ns-<VRF>“ before the command. See the example:

event-handler ARCHIVE_LANGLEY
   trigger on-startup-config
   action bash sudo ip netns exec ns-MANAGEMENT curl https://10.1.1.1/langley/put/$(hostname)/1 --upload-file /mnt/flash/startup-config

Python & ARISTA eAPI

Von ARISTA wird ein Python Paket bereitgestellt um über die eAPI mit dem Switch arbeiten zu können. Dies ist eine Qickanleitung.

pyeapi Paket installieren

pip install pyeapi

ARISTA eAPI aktivieren

Auf dem Arista Switch muss die API Schnittstelle aktiviert werden.

!
management api http-commands
   protocol http
   protocol https
    no shutdown
   !
   vrf MANAGEMENT
      no shutdown
!

Beispiel: Aktuelle running-config auslesen

#!/usr/bin/env python3

import pyeapi
import os, ssl

username = "apiuser"
password = "supersecret"
ip = "10.1.1.1"

# redhat ssl verification patch
if (not os.environ.get('PYTHONHTTPSVERIFY', '') and getattr(ssl, '_create_unverified_context', None)):
    ssl._create_default_https_context = ssl._create_unverified_context


conn = pyeapi.client.connect(
    transport='https',
    host=ip,
    username=username,
    password=password,
    port=443,
    timeout=60)

node = pyeapi.client.Node(conn)

print(node.running_config)

Beispiel: Command execute & result

#!/usr/bin/env python3

import pyeapi
import os, ssl

username = "apiuser"
password = "supersecret"
ip = "10.1.1.1"

# redhat ssl verification patch
if (not os.environ.get('PYTHONHTTPSVERIFY', '') and getattr(ssl, '_create_unverified_context', None)):
    ssl._create_default_https_context = ssl._create_unverified_context


conn = pyeapi.client.connect(
    transport='https',
    host=ip,
    username=username,
    password=password,
    port=443,
    timeout=60)

node = pyeapi.client.Node(conn)

result = node.enable(commands=["show running-config"], encoding="text")

print result[0]['result']['output']