restful_api_python
no way to compare when less than two revisions
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
| — | restful_api_python [2014/06/18 21:17] (aktuell) – angelegt benny | ||
|---|---|---|---|
| Zeile 1: | Zeile 1: | ||
| + | ====== Erste Schritte mit der RESTful API (Python) ====== | ||
| + | Das folgende Python-Skript soll einen Einblick in die ersten Schritte mit der OmniSwitch RESTful API mittels Python zeigen. | ||
| + | |||
| + | Es wird Python benötigt um diese Schritte durchzuführen. | ||
| + | * http:// | ||
| + | |||
| + | Der interaktive Teil des Skripts fragt vom Anwender einige Informationen ab und erstellt dann automatisch eine Link-Aggregation mit den passenden Parametern. | ||
| + | |||
| + | < | ||
| + | |||
| + | ===== Beispielimplementierung mittels Python ===== | ||
| + | |||
| + | <file python omnipy.py> | ||
| + | # | ||
| + | # | ||
| + | # Benny' | ||
| + | # | ||
| + | from consumer import AOSAPI, AOSConnection | ||
| + | |||
| + | def quicklag(interactive=' | ||
| + | try: | ||
| + | api = AOSAPI(AOSConnection( | ||
| + | username = ' | ||
| + | password = ' | ||
| + | hostaddress = ' | ||
| + | #aosheaders = None, | ||
| + | debug = debugoption | ||
| + | )) | ||
| + | api.login() | ||
| + | | ||
| + | if interactive == ' | ||
| + | | ||
| + | lag = api.put(' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | }) | ||
| + | |||
| + | lag4 = api.put(' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | }) | ||
| + | | ||
| + | lag4 = api.put(' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | }) | ||
| + | pass | ||
| + | else: | ||
| + | print " | ||
| + | print " | ||
| + | print "Gib die gewuenschte LAG-ID ein: " | ||
| + | try: | ||
| + | lagid = input(" | ||
| + | except SyntaxError: | ||
| + | print " | ||
| + | # | ||
| + | except KeyboardInterrupt: | ||
| + | print " | ||
| + | # | ||
| + | print " | ||
| + | print "Gib die LAG-Size ein (2, 4, 8): " | ||
| + | try: | ||
| + | lagsize = input(" | ||
| + | except SyntaxError: | ||
| + | print " | ||
| + | # | ||
| + | except KeyboardInterrupt: | ||
| + | print " | ||
| + | # | ||
| + | print " | ||
| + | print "Gib die Ports, getrennt durch Komma als gPort ein: " | ||
| + | try: | ||
| + | lagports = input(" | ||
| + | except SyntaxError: | ||
| + | print " | ||
| + | # | ||
| + | except KeyboardInterrupt: | ||
| + | print " | ||
| + | # | ||
| + | |||
| + | for i in lagports: | ||
| + | print " | ||
| + | print " | ||
| + | print "Ok, anschnallen bitte ..." | ||
| + | print " | ||
| + | | ||
| + | lag = api.put(' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | }) | ||
| + | if api.success() == True: | ||
| + | print " | ||
| + | else: | ||
| + | print " | ||
| + | |||
| + | for i in lagports: | ||
| + | lag4 = api.put(' | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | }) | ||
| + | if api.success() == True: | ||
| + | print " | ||
| + | else: | ||
| + | print " | ||
| + | print "Alles erledigt, bitte Konfiguration auf Switch pruefen ... : | ||
| + | api.logout() | ||
| + | | ||
| + | except HTTPError, e: | ||
| + | api.logout() | ||
| + | print " | ||
| + | | ||
| + | except KeyboardInterrupt: | ||
| + | print " | ||
| + | api.logout() | ||
| + | </ | ||
| + | |||
| + | ===== Python-Skript in der Anwendung ===== | ||
| + | |||
| + | Wenn man das Python-Skript nun anwendet, kommen wir zu folgenden Ausgaben/ | ||
| + | |||
| + | * quicklag(), Erstellt eine Link-Aggregation mit hinterlegten Standardwerten | ||
| + | * quicklag(1), | ||
| + | * quicklag(1, True), Dies erzeugt zusätzliche Debugging-Meldungen | ||
| + | |||
| + | < | ||
| + | Benjamins-MacBook-Pro: | ||
| + | Python 2.7.5 (v2.7.5: | ||
| + | [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin | ||
| + | Type " | ||
| + | >>> | ||
| + | >>> | ||
| + | >>> | ||
| + | >>> | ||
| + | Willkommen zu QuickLAG v1.0 erstellt fuer den "KOMSA TecTeaming" | ||
| + | ---------------------------------------------------------- | ||
| + | Gib die gewuenschte LAG-ID ein: | ||
| + | QuickLAG-> | ||
| + | LAG-ID: 13 | ||
| + | Gib die LAG-Size ein (2, 4, 8): | ||
| + | QuickLAG-> | ||
| + | LAG-Size: 2 | ||
| + | Gib die Ports, getrennt durch Komma als gPort ein: | ||
| + | QuickLAG-> | ||
| + | LAG-Ports: 1003 | ||
| + | LAG-Ports: 1004 | ||
| + | ------- | ||
| + | Ok, anschnallen bitte ... | ||
| + | ------- | ||
| + | Linkaggregation 13 erfolgreich eingerichtet. | ||
| + | Linkaggregationsport 1003 erfolgreich eingerichtet. | ||
| + | Linkaggregationsport 1004 erfolgreich eingerichtet. | ||
| + | Alles erledigt, bitte Konfiguration auf Switch pruefen ... :) | ||
| + | >>> | ||
| + | Willkommen zu QuickLAG v1.0 erstellt fuer den "KOMSA TecTeaming" | ||
| + | ---------------------------------------------------------- | ||
| + | Gib die gewuenschte LAG-ID ein: | ||
| + | QuickLAG-> | ||
| + | LAG-ID: 13 | ||
| + | Gib die LAG-Size ein (2, 4, 8): | ||
| + | QuickLAG-> | ||
| + | LAG-Size: 2 | ||
| + | Gib die Ports, getrennt durch Komma als gPort ein: | ||
| + | QuickLAG-> | ||
| + | LAG-Ports: 1003 | ||
| + | LAG-Ports: 1004 | ||
| + | ------- | ||
| + | Ok, anschnallen bitte ... | ||
| + | ------- | ||
| + | Erstellung der Linkaggregation fehlgeschlagen: | ||
| + | Zuordnung des Ports zur Linkaggregation fehlgeschlagen: | ||
| + | Zuordnung des Ports zur Linkaggregation fehlgeschlagen: | ||
| + | Alles erledigt, bitte Konfiguration auf Switch pruefen ... :) | ||
| + | >>> | ||
| + | </ | ||
| + | |||
| + | ===== Resultierende Konfiguration auf dem OmniSwitch ===== | ||
| + | |||
| + | < | ||
| + | OmniSwitch-> | ||
| + | Fri Jul 12 13:32:58 : AAA Switch-Warning warning message: | ||
| + | +++ WARNING! Switch Access Vulnerability. | ||
| + | +++ WARNING! Admin user authentication using default password. | ||
| + | |||
| + | -> | ||
| + | -> show configuration snapshot linkagg | ||
| + | ! Link Aggregate: | ||
| + | linkagg lacp agg 12 size 2 admin-state enable | ||
| + | linkagg lacp agg 12 name " | ||
| + | linkagg lacp agg 12 actor admin-key 12 | ||
| + | linkagg lacp agg 13 size 2 admin-state enable | ||
| + | linkagg lacp agg 13 name " | ||
| + | linkagg lacp agg 13 actor admin-key 13 | ||
| + | linkagg lacp port 1/1 actor admin-key 12 | ||
| + | linkagg lacp port 1/2 actor admin-key 12 | ||
| + | linkagg lacp port 1/3 actor admin-key 13 | ||
| + | linkagg lacp port 1/4 actor admin-key 13 | ||
| + | </ | ||
restful_api_python.txt · Zuletzt geändert: von benny
