اس سبق کے بعد آپ EEM applets لکھ سکیں گے، Python سے device output پڑھ سکیں گے، اور NETCONF/RESTCONF XML/JSON examples کے ساتھ سمجھ جائیں گے۔
Is lesson ke baad aap EEM applets likh sakenge, Python se device output parh sakenge, aur NETCONF/RESTCONF XML/JSON examples ke saath samajh jayenge.
After this lesson you will be able to write EEM applets, read device output with Python, and understand NETCONF/RESTCONF with XML/JSON examples.
Automation ایسا ہے جیسے اسسٹنٹ کو تربیت دینا — کام ایک بار کر کے دکھایا (EEM)، پھر وہ ہمیشہ خود کرے گا۔ NETCONF/RESTCONF ایک formal instruction form ہے (XML/JSON) تاکہ زبان سے commands چلانے کی بجائے۔
Automation aisa hai jaise assistant ko tarbiyat dena — kaam ek baar kar ke dikhaya (EEM), phir wo hamesha khud karega. NETCONF/RESTCONF ek formal instruction form hai (XML/JSON) taake zaban se commands chillane ki bajaye.
Automation is like training an assistant — you do the job once while they watch (EEM), then they handle it forever. NETCONF/RESTCONF is a formal instruction form (XML/JSON) instead of shouting commands.
کوئی بھی router جس میں EEM support ہو۔ Python اور NETCONF کے حصوں کے لیے Linux box لیں جس میں ncclient اور requests libraries installed ہوں۔
Koi bhi router jis mein EEM support ho. Python aur NETCONF ke hisson ke liye Linux box lein jis mein ncclient aur requests libraries installed hon.
Any router with EEM support. For Python and NETCONF parts, use a Linux box with the ncclient and requests libraries installed.
EEM applet: روز رات 2 بجے config کا backup خود بخود لیں۔ $h hostname variable ہے۔
EEM applet: roz raat 2 baje config ka backup khud-ba-khud lein. $h hostname variable hai.
EEM applet: automatically back up the config every night at 2 AM. $h is the hostname variable.
event manager applet BACKUP-CONFIGevent timer cron cron-entry "0 2 * * *"action 1.0 cli command "enable"action 2.0 cli command "copy running-config tftp://10.1.1.1/$h.cfg"show event manager policy activeEvent-driven EEM: جب کوئی interface down ہو تو فوری diagnostics چلائیں — دستی ردعمل سے تیز۔
Event-driven EEM: jab koi interface down ho to fori diagnostics chalayein — dasti rad-e-amal se tez.
Event-driven EEM: when any interface goes down, run diagnostics immediately — faster than manual reaction.
event manager applet IF-DOWN-ALERTevent syslog pattern "Line protocol on Interface.*changed state to down"action 1.0 cli command "enable"action 2.0 cli command "show ip interface brief | include down"Python کی بنیاد: device output کو فائل سے پڑھیں اور regex سے hostname نکالیں۔ اصل outputs کو 'show run | redirect' سے فائل میں save کریں۔
Python ki bunyaad: device output ko file se parhen aur regex se hostname nikalen. Asli outputs ko 'show run | redirect' se file mein save karein.
Python basics: read saved device output and extract the hostname with regex. Save real outputs to files with 'show run | redirect'.
import reoutput = open('show_run.txt').read()for m in re.findall(r'^hostname (\S+)', output, re.M): print('Hostname:', m)آگے بڑھیں: routing-table output کو (protocol، prefix) کی list میں تبدیل کریں — automated compliance checks کی بنیاد۔
Aage barhein: routing-table output ko (protocol, prefix) ki list mein tabdeel karein — automated compliance checks ki bunyaad.
Go further: parse routing-table output into a list of (protocol, prefix) tuples — the basis of automated compliance checks.
import retext = open('show_ip_route.txt').read()routes = re.findall(r'^(\S+)\s+(\d+\.\d+\.\d+\.\d+/\d+)', text, re.M)print(len(routes), 'routes found')NETCONF کا تصور: device SSH port 830 پر XML بولتا ہے۔ get-config running config کو structured XML کے طور پر پڑھتا ہے — screen-scraping کی ضرورت ختم۔
NETCONF ka tasawwur: device SSH port 830 par XML bolta hai. get-config running config ko structured XML ke tor par parhta hai — screen-scraping ki zaroorat khatam.
NETCONF concept: the device speaks XML over SSH port 830. get-config reads the running config as structured XML — no more screen-scraping.
netconfssh 10.0.0.1 -p 830XML مثال: get-config request۔ JSON مثال: وہی hostname RESTCONF format میں۔ دونوں ایک ہی بات کہتے ہیں — shape YANG طے کرتا ہے۔
XML example: get-config request. JSON example: wahi hostname RESTCONF format mein. Dono ek hi baat kehte hain — shape YANG tay karta hai.
XML example: a get-config request. JSON example: the same hostname expressed in RESTCONF format. Both say the same thing — YANG defines the shape.
<rpc><get-config><source><running/></source></get-config></rpc>{"Cisco-IOS-XE-native:hostname": "R1"}RESTCONF کا تصور: ایک سادہ HTTPS GET hostname JSON کے طور پر دیتی ہے۔ حفاظت سے automate کریں — production میں ہمیشہ verify=True اور اصل certificates۔
RESTCONF ka tasawwur: ek saadi HTTPS GET hostname JSON ke tor par deti hai. Hifazat se automate karein — production mein hamesha verify=True aur asli certificates.
RESTCONF concept: a simple HTTPS GET returns the hostname as JSON. Automate safely — always use verify=True with real certificates in production.
import requestsrequests.get('https://10.0.0.1/restconf/data/Cisco-IOS-XE-native:native/hostname', verify=False).json()یقین کریں کہ applet schedule پر چلتی ہے، Python saved outputs سے درست data نکالتا ہے، اور آپ بتا سکتے ہیں NETCONF کب اور RESTCONF کب استعمال کرنا ہے۔
Yaqeen karein ke applet schedule par chalti hai, Python saved outputs se durust data nikalta hai, aur aap bata sakte hain NETCONF kab aur RESTCONF kab use karna hai.
Confirm the applet runs on schedule, Python extracts data correctly from saved outputs, and you can explain when to use NETCONF vs RESTCONF.
show event manager policy activeshow event manager history events