المقدمة
يوضح هذا المستند كيفية إستخدام بعض إستدعاءات API المتوفرة في vManage وكيف يمكنك تكييفها لتشغيلها باستخدام برنامج نصي.
المشكلة
المعلومات التي يمكنك طلبها من vManage ليست دائما سهلة التجميع إذا كان التغشية تحتوي على مئات أو آلاف من موجهات Cisco Edge.
مثال:
أكثر الطرق بساطة للحصول على تكوين جار لموجه Cisco Edge الواحد هو التنقل إلى التكوين > الأجهزة > قائمة حافة الشبكة انقر فوق الشكل البيضاوي (...) وتشغيل التكوين. ثم يجب تحديد جميع التكوين ونسخه وحفظه في ملف آخر مثل تنسيق txt. ومع ذلك، تظهر المشكلة عندما تريد الحصول على تكوين العديد من موجهات Cisco Edge مما يجعل هذه المهمة مرهقة ويستهلك الكثير من الوقت.


نظرة عامة على إستدعاء واجهة برمجة التطبيقات
هذا الإجراء هو مثال على كيفية إستخدام إستدعاء API بسيط للحصول على جميع المعلومات المطلوبة.
الخطوة 1.
قم بتسجيل الدخول إلى vManage كأمر عادي باستخدام عنوان URL أو عنوان IP.

الخطوة 2.
افتح مستعرض تبويب جديد ثم انسخ عنوان URL الخاص ب vManage ولصقه ثم قم بإضافة اللاحقة /apidocs (https://172.18.121.103:15256/apidocs).

الخطوة 3.
في مربع البحث، اكتب مراقبة - تفاصيل الجهاز.

الخطوة 4.
للحصول على تكوين جهاز واحد، يجب تجربة إستدعاء واجهة برمجة التطبيقات (API) /device/config.

الخطوة 5.
أدخل system-ip لأحد موجهات Cisco Edge وقم بتشغيل إستدعاء واجهة برمجة التطبيقات (API).


إستخدام Curl في برنامج نصي
خيار أفضل هو إستخدام إستدعاء واجهة برمجة تطبيقات في برنامج نصي لإنشاء ملفات تكوين لموجهات Cisco Edge.
الخطوة 1.
أولا، في سطر أوامر shell أو CLI، قم بإنشاء مجلد يتم فيه تخزين جميع ملفات النسخ الاحتياطي.
lufrias@LUFRIAS-M-P9Q2 Desktop % mkdir Backup_cedges
lufrias@LUFRIAS-M-P9Q2 Desktop % cd Backup_cedges
lufrias@LUFRIAS-M-P9Q2 Backup_cedges % pwd
/Users/lufrias/Desktop/Backup_cedges
lufrias@LUFRIAS-M-P9Q2 Backup_cedges %
الخطوة 2.
قم بإنشاء ملف .txt باستخدام جميع عناوين IP الخاصة بالنظام لموجهات Cisco Edge التي يلزم إجراء النسخ الاحتياطي عليها. قائمة عناوين IP الخاصة بالنظام التي يمكنك الحصول عليها من ملف vManage وتصدير CSV.
يلزم تسمية الملف باسم System-IPs.txt وحفظه في نفس الدليل الذي تم إنشاؤه مسبقا (Backup_cedges).


الخطوة 3.
تأكد من حفظ الملف.
lufrias@LUFRIAS-M-P9Q2 Backup_cedges % ls -l
total 8
-rw-r--r--@ 1 lufrias staff 77 Aug 27 12:20 System-IPs.txt
lufrias@LUFRIAS-M-P9Q2 Backup_cedges %
الخطوة 4.
قم بالمتابعة لإنشاء البرنامج النصي. من الممكن إستخدام 6or any notepad، فقط أحرص على حفظه بتنسيق .sh.
#!/bin/bash
#Define your variables
echo "Please type vManage URL in following format"
echo "https://172.18.121.103:15256 or https://vmanage.cisco.com"
read VMANAGE
echo "Please enter username to access vmanage"
read USER
echo "Password:"
read PASSWORD
#DEFINING THE API CALLS TO LOGIN AND BODY
security_url="$VMANAGE/j_security_check"
credentials="j_username=$USER&j_password=$PASSWORD"
#EXECUTE THE API CALL TO LOGIN TO THE VMANAGE.
curl --request POST --silent --insecure -c cookies.txt --url $security_url --data $credentials
#EXECUTE THE API CALL TO GET A TOKEN
TOKEN=$(curl "$VMANAGE/dataservice/client/token" -X GET -b cookies.txt -s --insecure)
arr_csv=()
while IFS= read -r line
do
arr_csv+=("$line")
curl --insecure -b cookies.txt -H "accept: text/plain" -H "X-XSRF-TOKEN: $TOKEN" -X GET "$VMANAGE/dataservice/device/config?deviceId="$line > $line.txt
echo $line
done < System-IPs.txt
echo "Running config was collected from following System_IPs:"
index=0
for record in "${arr_csv[@]}"
do
echo "Record at index-${index} : $record"
((index++))
done
curl "$VMANAGE/logout" -b cookies.txt --silent --insecure -H "X-XSRF-TOKEN: $TOKEN"
echo "Check files, if they are empty or with message "Bad request" check user and password"
الخطوة 5.
تغيير امتياز الملف بحيث يمكن تشغيله.
lufrias@LUFRIAS-M-P9Q2 Backup_cedges % ls -l
total 16
-rw-r--r--@ 1 lufrias staff 77 Aug 27 12:20 System-IPs.txt
-rw-r--r-- 1 lufrias staff 1174 Aug 27 12:47 config_backup_script.sh
lufrias@LUFRIAS-M-P9Q2 Backup_cedges %
lufrias@LUFRIAS-M-P9Q2 Backup_cedges %
lufrias@LUFRIAS-M-P9Q2 Backup_cedges % chmod +x config_backup_script.sh
lufrias@LUFRIAS-M-P9Q2 Backup_cedges %
lufrias@LUFRIAS-M-P9Q2 Backup_cedges % ls -l
total 16
-rw-r--r--@ 1 lufrias staff 77 Aug 27 12:20 System-IPs.txt
-rwxr-xr-x 1 lufrias staff 1174 Aug 27 12:47 config_backup_script.sh
lufrias@LUFRIAS-M-P9Q2 Backup_cedges %
الخطوة 6.
قم بتشغيل البرنامج النصي باستخدام الأمر /.config_backup_script.sh. ضع في الاعتبار أن هذا الأمر يستغرق بعض الوقت لاكماله وفقا لكمية الأجهزة.
lufrias@LUFRIAS-M-P9Q2 Backup_cedges % ./config_backup_script.sh
Please type vManage URL in following format
https://172.18.121.103:15256 or https://vmanage.cisco.com
https://172.18.121.103:15256
Please enter username to access vmanage
admin
Password:
qwerty1234Q
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 7238 0 7238 0 0 1133 0 --:--:-- 0:00:06 --:--:-- 1761
10.10.10.1
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 7218 0 7218 0 0 1799 0 --:--:-- 0:00:04 --:--:-- 1800
20.20.20.1
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 7225 0 7225 0 0 1978 0 --:--:-- 0:00:03 --:--:-- 1978
30.30.30.1
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 7225 0 7225 0 0 1491 0 --:--:-- 0:00:04 --:--:-- 2031
40.40.40.1
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 7225 0 7225 0 0 2717 0 --:--:-- 0:00:02 --:--:-- 2718
50.50.50.1
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 7225 0 7225 0 0 1610 0 --:--:-- 0:00:04 --:--:-- 1641
60.60.60.1
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 7225 0 7225 0 0 1668 0 --:--:-- 0:00:04 --:--:-- 1668
70.70.70.1
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 40 0 40 0 0 108 0 --:--:-- --:--:-- --:--:-- 107
80.80.80.1
Running config was collected from following System_IPs:
Record at index-0 : 10.10.10.1
Record at index-1 : 20.20.20.1
Record at index-2 : 30.30.30.1
Record at index-3 : 40.40.40.1
Record at index-4 : 50.50.50.1
Record at index-5 : 60.60.60.1
Record at index-6 : 70.70.70.1
Record at index-7 : 80.80.80.1
ErrorMethod Not AllowedCheck files, if they are empty or with message Bad request check user and password
lufrias@LUFRIAS-M-P9Q2 Backup_cedges %
الخطوة 7.
أخيرا، تحقق من وجود الملفات باستخدام الأمر ls -l.
lufrias@LUFRIAS-M-P9Q2 Backup_cedges % ls -l
total 152
-rw-r--r-- 1 lufrias staff 7238 Sep 11 10:06 10.10.10.1.txt
-rw-r--r-- 1 lufrias staff 7218 Sep 11 10:06 20.20.20.1.txt
-rw-r--r-- 1 lufrias staff 7225 Sep 11 10:06 30.30.30.1.txt
-rw-r--r-- 1 lufrias staff 7225 Sep 11 10:06 40.40.40.1.txt
-rw-r--r-- 1 lufrias staff 7225 Sep 11 10:06 50.50.50.1.txt
-rw-r--r-- 1 lufrias staff 7225 Sep 11 10:06 60.60.60.1.txt
-rw-r--r-- 1 lufrias staff 7225 Sep 11 10:07 70.70.70.1.txt
-rw-r--r-- 1 lufrias staff 40 Sep 11 10:07 80.80.80.1.txt
-rw-r--r--@ 1 lufrias staff 88 Sep 10 11:48 System-IPs.txt
-rwxr-xr-x 1 lufrias staff 1352 Sep 11 09:49 config_backup_script.sh
-rw-r--r-- 1 lufrias staff 288 Sep 11 10:06 cookies.txt
lufrias@LUFRIAS-M-P9Q2 Backup_cedges %
تحقق من ملف التكوين.
lufrias@LUFRIAS-M-P9Q2 Backup_cedges % more 10.10.10.1.txt
system
system-ip 10.10.10.1
overlay-id 1
site-id 101
no transport-gateway enable
port-offset 0
control-session-pps 300
admin-tech-on-failure
sp-organization-name CISCORTPLAB
organization-name CISCORTPLAB
port-hop
track-transport
track-default-gateway
console-baud-rate 9600
no on-demand enable
on-demand idle-timeout 10
vbond 192.168.51.117 port 12346
إذا كانت الملفات فارغة أو تحتوي على رسالة خطأ "طلب سيئ"، فالرجاء التحقق من اسم مستخدم المصادقة وكلمة المرور.
lufrias@LUFRIAS-M-P9Q2 Backup_cedges % more 30.30.30.1.txt
Bad Request
lufrias@LUFRIAS-M-P9Q2 Backup_cedges %
إذا أظهر الملف "لم يتم العثور على جهاز ل IP للنظام" فهذا يعني أن IP للنظام غير موجود في vManage. يجب تصحيح System-IPs.txt وحذف System-IP الخطأ.
lufrias@LUFRIAS-M-P9Q2 Backup_cedges % more 80.80.80.1.txt
No device found for system IP 80.80.80.1
lufrias@LUFRIAS-M-P9Q2 Backup_cedges %