event-action-python
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
Nächste Überarbeitung | Vorhergehende Überarbeitung | ||
event-action-python [2015/03/31 20:57] – angelegt benny | event-action-python [2024/06/09 10:29] (aktuell) – Externe Bearbeitung 127.0.0.1 | ||
---|---|---|---|
Zeile 9: | Zeile 9: | ||
====== Funktionsweise der " | ====== Funktionsweise der " | ||
+ | ===== 10G/1G Link-Aggregation - Backup-Strecke aktivieren ===== | ||
+ | |||
+ | Eine Link-Aggregation mit unterschiedlichen Geschwindigkeiten ist nicht offiziell unterstützt. Dies macht aus Gründen von " | ||
+ | |||
+ | 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, | ||
+ | Der Vorgang hat eine Wiederherstellungszeit von ca. 2 Sekunden. | ||
+ | |||
+ | <file python link_agg_mgr.py> | ||
+ | # | ||
+ | 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 | ||
+ | # | ||
+ | |||
+ | # 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: | ||
+ | except getopt.GetoptError as err: | ||
+ | print(error) | ||
+ | print(" | ||
+ | sys.exit(2) | ||
+ | traptype = " | ||
+ | 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 == " | ||
+ | traptype = a | ||
+ | elif o == " | ||
+ | trapdata = a | ||
+ | |||
+ | # Load the data from json format into Python dictionary | ||
+ | trapdata = json.loads(trapdata); | ||
+ | |||
+ | if traptype == ' | ||
+ | if trapdata[' | ||
+ | print(' | ||
+ | os.system(" | ||
+ | elif traptype == ' | ||
+ | if trapdata[' | ||
+ | print(' | ||
+ | elif traptype == ' | ||
+ | if trapdata[' | ||
+ | print(' | ||
+ | os.system(" | ||
+ | elif traptype == ' | ||
+ | if trapdata[' | ||
+ | print(' | ||
+ | os.system(" | ||
+ | </ | ||
+ | |||
+ | Ausgabe auf der Console: | ||
+ | < | ||
+ | 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/ | ||
+ | -------------------+----------+--------+----------+----+-----+-----+---- | ||
+ | | ||
+ | | ||
+ | |||
+ | OS6900-> | ||
+ | </ | ||
+ | |||
+ | Auswirkung auf den Betrieb: | ||
+ | < | ||
+ | 64 bytes from 192.168.2.2: | ||
+ | 64 bytes from 192.168.2.2: | ||
+ | ping: sendmsg: Network is unreachable | ||
+ | ping: sendmsg: Network is unreachable | ||
+ | 64 bytes from 192.168.2.2: | ||
+ | 64 bytes from 192.168.2.2: | ||
+ | 64 bytes from 192.168.2.2: | ||
+ | 64 bytes from 192.168.2.2: | ||
+ | 64 bytes from 192.168.2.2: | ||
+ | 64 bytes from 192.168.2.2: | ||
+ | 64 bytes from 192.168.2.2: | ||
+ | </ | ||
+ | Beim Zurückschalten wurden keine Pakete verloren (1G Verbindung wird deaktiviert). | ||
====== Tipps ====== | ====== Tipps ====== | ||
+ | ===== Verwendung von Python DeBugger (pdb) im Rahmen von " | ||
+ | |||
+ | 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 " | ||
+ | |||
+ | <file python pdb.py> | ||
+ | # | ||
+ | import pdb | ||
+ | pdb.set_trace() | ||
+ | </ | ||
====== TODO ====== | ====== TODO ====== |
event-action-python.1427835471.txt.gz · Zuletzt geändert: 2024/06/09 10:29 (Externe Bearbeitung)