Benutzer-Werkzeuge

Webseiten-Werkzeuge


event-action-python

Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.

Link zu dieser Vergleichsansicht

Nächste Überarbeitung
Vorhergehende Überarbeitung
event-action-python [2015/03/31 20:57] – angelegt bennyevent-action-python [2024/06/09 10:29] (aktuell) – Externe Bearbeitung 127.0.0.1
Zeile 9: Zeile 9:
 ====== Funktionsweise der "event-action" Aktion ====== ====== Funktionsweise der "event-action" Aktion ======
  
 +===== 10G/1G Link-Aggregation - Backup-Strecke aktivieren =====
 +
 +Eine Link-Aggregation mit unterschiedlichen Geschwindigkeiten ist nicht offiziell unterstützt. Dies macht aus Gründen von "Hashing" über die zur Verfügung stehenden Verbindungen auch keinen Sinn (Hashing bezieht nicht die Geschwindigkeite mit in die Entscheidung ein).
 +
 +Angenommen wir haben eine Link-Aggregation auf den Ports 1/1/1a (10G) und 1/1/1b (1G), so kann folgendes Event-Action Skript für uns die 1G Strecke immer dann aktiv schalten wenn die 10G Verbindung aus Sicht des Control-Protocol (LACP) nicht verfügbar ist. Wenn die Strecke zurückkommt, wird der 1G Port wieder ausgeschaltet.
 +Der Vorgang hat eine Wiederherstellungszeit von ca. 2 Sekunden.
 +
 +<file python link_agg_mgr.py>
 +#!/bin/python3
 +import sys
 +import os
 +import getopt
 +import json
 +
 +# Based on work by Patricio Martelo
 +# Adaption for Link-Aggregation management by Benny
 +
 +# TODO: Delete, just for tests
 +#print(sys.argv)
 +
 +# Load the data that is being sent to us
 +# -t holds the traptype
 +# -d holds the trapdata
 +try:
 +    opts, args = getopt.getopt(sys.argv[1:], "t:d:")
 +except getopt.GetoptError as err:
 +    print(error)
 +    print("%s" % sys.argv)
 +    sys.exit(2)
 +traptype = "(none)"
 +trapdata = "{}"
 +
 +# Go through the data in opts and allocate it properly
 +# traptype gets the value from -t
 +# trapdata gets the value from -d
 +for o, a in opts:
 +    if o == "-t":
 +        traptype = a
 +    elif o == "-d":
 +        trapdata = a
 +
 +# Load the data from json format into Python dictionary  
 +trapdata = json.loads(trapdata);
 +
 +if traptype == 'lnkaggAggDown':
 +    if trapdata['traplnkaggPortIfIndex'] == 1001:
 +        print('Detected 10G port leaving the aggregate, bringing up backup 1G.\n')
 +        os.system("interfaces 1/1/1b admin-state enable")
 +elif traptype == 'lnkaggAggUp':
 +    if trapdata['traplnkaggPortIfIndex'] == 1002:
 +        print('Restored the operation, running on 1G backup.\n')
 +elif traptype == 'lnkaggPortLeave':
 +    if trapdata['traplnkaggPortIfIndex'] == 1001:
 +        print('Detected 10G port leaving the aggregate, bringing up backup 1G.\n')
 +        os.system("interfaces 1/1/1b admin-state enable")
 +elif traptype == 'lnkaggPortJoin':
 +    if trapdata['traplnkaggPortIfIndex'] == 1001:
 +        print('Detected 10G port joining the aggregate, bringing down backup 1G.\n')
 +        os.system("interfaces 1/1/1b admin-state disable")
 +</file>
 +
 +Ausgabe auf der Console:
 +<code>
 +Detected 10G port leaving the aggregate, bringing up backup 1G.
 +
 +Restored the operation, running on 1G backup.
 +
 +Detected 10G port joining the aggregate, bringing down backup 1G.
 +
 +OS6900-> 
 +OS6900-> 
 +OS6900-> show linkagg port 
 +
 +Chassis/Slot/Port  Aggregate   SNMP Id   Status    Agg  Oper   Link Prim
 +-------------------+----------+--------+----------+----+-----+-----+----
 +         1/1/1A     Dynamic      1001   ATTACHED      1  UP   UP    YES
 +         1/1/1B     Dynamic      1002   CONFIGURED NONE  DOWN DOWN  UNK
 +
 +OS6900-> 
 +</code>
 +
 +Auswirkung auf den Betrieb:
 +<code>
 +64 bytes from 192.168.2.2: icmp_seq=39 ttl=64 time=0.971 ms
 +64 bytes from 192.168.2.2: icmp_seq=40 ttl=64 time=0.888 ms
 +ping: sendmsg: Network is unreachable
 +ping: sendmsg: Network is unreachable
 +64 bytes from 192.168.2.2: icmp_seq=44 ttl=64 time=12.3 ms
 +64 bytes from 192.168.2.2: icmp_seq=45 ttl=64 time=0.855 ms
 +64 bytes from 192.168.2.2: icmp_seq=46 ttl=64 time=0.880 ms
 +64 bytes from 192.168.2.2: icmp_seq=47 ttl=64 time=0.871 ms
 +64 bytes from 192.168.2.2: icmp_seq=48 ttl=64 time=0.876 ms
 +64 bytes from 192.168.2.2: icmp_seq=49 ttl=64 time=19.6 ms
 +64 bytes from 192.168.2.2: icmp_seq=50 ttl=64 time=1.36 ms
 +</code>
 +Beim Zurückschalten wurden keine Pakete verloren (1G Verbindung wird deaktiviert).
  
 ====== Tipps ====== ====== Tipps ======
  
 +===== Verwendung von Python DeBugger (pdb) im Rahmen von "event-action" nicht möglich =====
 +
 +Obwohl die Verwendung von pdb generell möglich ist, wird dies im Rahmen von event-action Skripten nicht unterstützt.
 +Dies hängt u.a. mit dem automatischen Ablauf und der maximalen Laufzeit von 60 Sekunden für diese Skripte zusammen.
 +Der Versuch erzeugt die Exception "BdbQuit".
 +
 +<file python pdb.py>
 +#!/bin/python3
 +import pdb
 +pdb.set_trace()
 +</file>
  
 ====== TODO ====== ====== TODO ======
event-action-python.1427835471.txt.gz · Zuletzt geändert: 2024/06/09 10:29 (Externe Bearbeitung)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki