{"id":10888,"date":"2022-10-12T13:00:23","date_gmt":"2022-10-12T20:00:23","guid":{"rendered":"https:\/\/www.xh86.me\/?p=10888"},"modified":"2022-10-12T13:00:23","modified_gmt":"2022-10-12T20:00:23","slug":"ios-xe-ztp%e6%93%8d%e4%bd%9c%e6%8c%87%e5%8d%97","status":"publish","type":"post","link":"https:\/\/www.xh86.me\/?p=10888","title":{"rendered":"IOS-XE ZTP\u64cd\u4f5c\u6307\u5357"},"content":{"rendered":"<div class=\"wxsyncmain\">\n<section style=\"font-size: 16px; color: black; padding-right: 10px; padding-left: 10px; line-height: 1.6; letter-spacing: 0px; word-break: break-word; overflow-wrap: break-word; text-align: left; font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, 'PingFang SC', Cambria, Cochin, Georgia, Times, 'Times New Roman', serif;\" data-tool=\"mdnice\u7f16\u8f91\u5668\" data-website=\"https:\/\/www.mdnice.com\">\n<p style=\"padding-top: 8px; padding-bottom: 8px; margin: 5px; line-height: 1.5; letter-spacing: 0.05em; font-size: 15px; word-spacing: 0em;\" data-tool=\"mdnice\u7f16\u8f91\u5668\">\u4e00\u53f0\u7f51\u7edc\u8bbe\u5907\u4e0a\u7ebf\u4e4b\u540e\uff0c\u9700\u8981\u5148\u5b8c\u6210\u5927\u91cf\u7684\u914d\u7f6e\uff0c\u5b83\u624d\u80fd\u5f00\u59cb\u5de5\u4f5c\u3002\u901a\u5e38\u7684\u505a\u6cd5\u662f\uff0c\u5728\u8bbe\u5907\u4e0a\u7ebf\u4e4b\u524d\uff0c\u5148\u5b89\u6392\u51e0\u4f4d\u5de5\u7a0b\u5e08\uff0c\u627e\u4e00\u5757\u573a\u5730\uff0c\u628a\u6240\u6709\u8bbe\u5907\u62c6\u7bb1\u3001\u52a0\u7535\u3001\u5237\u914d\u7f6e\uff0c\u7136\u540e\u518d\u4e0a\u67b6\u3002\u8fd9\u6837\u505a\uff0c\u4e0d\u4ec5\u6d6a\u8d39\u4eba\u529b\u548c\u65f6\u95f4\uff0c\u8fd8\u5f88\u5bb9\u6613\u51fa\u9519\u3002\u901a\u8fc7\u4e00\u4e9bDay Zero Automation\u6280\u672f\u53ef\u4ee5\u5c06\u8fd9\u4e9b\u914d\u7f6e\u5de5\u4f5c\u81ea\u52a8\u5316\u5730\u5b8c\u6210\uff0c\u8282\u7701\u9879\u76ee\u5b9e\u65bd\u7684\u65f6\u95f4\uff0c\u907f\u514d\u521d\u59cb\u5316\u914d\u7f6e\u65f6\u51fa\u73b0\u4eba\u4e3a\u64cd\u4f5c\u9519\u8bef\u3002<\/p>\n<p style=\"padding-top: 8px; padding-bottom: 8px; margin: 5px; line-height: 1.5; letter-spacing: 0.05em; font-size: 15px; word-spacing: 0em;\" data-tool=\"mdnice\u7f16\u8f91\u5668\">\u4f7f\u7528IOS XE\u64cd\u4f5c\u7cfb\u7edf\u7684Cisco\u4ea4\u6362\u673a\u548c\u8def\u7531\u5668\u652f\u63013\u79cdDay0 Automation\u6280\u672f\uff1aiPXE\u3001ZTP\u548cPnP\u3002\u5176\u4e2dPnP\u4f9d\u8d56\u4e8eDNA Center\uff0c\u6210\u672c\u7a0d\u5fae\u9ad8\u4e00\u4e9b\uff0c\u4f46\u5f97\u5230\u7684\u662f\u4e00\u4e2a\u201c\u4ea4\u94a5\u5319\u5de5\u7a0b\u201d\uff0c\u7528\u6237\u57fa\u672c\u4e0a\u4e0d\u9700\u8981\u4ed8\u51fa\u6280\u672f\u6210\u672c\uff0c\u8fd8\u80fd\u591f\u5f97\u5230Software Image Management (SWIM)\u7b49\u589e\u503c\u670d\u52a1\u3002PXE\u548cZTP\u5219\u662f\u5f00\u6e90\u7684\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n<figure style=\"margin-top: 10px; margin-bottom: 10px; display: flex; flex-direction: column; justify-content: center; align-items: center;\" data-tool=\"mdnice\u7f16\u8f91\u5668\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/www.xh86.me\/wp-content\/uploads\/2022\/10\/wxsync-2022-10-5723cab38ff461e2820fba9c879c6087.jpeg'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" class=\"rich_pages wxw-img\" style=\"border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 5px; border-bottom-left-radius: 5px; display: block; margin: 20px auto; width: 85%; object-fit: contain; box-shadow: #84a1a8 0px 10px 15px; height: auto !important;\" data-original=\"https:\/\/www.xh86.me\/wp-content\/uploads\/2022\/10\/wxsync-2022-10-5723cab38ff461e2820fba9c879c6087.jpeg\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" data-ratio=\"0.43035479632063073\" data-type=\"jpeg\" data-w=\"1522\" \/><\/div><figcaption style=\"margin-top: 5px; text-align: center; color: #888888; font-size: 12px; font-family: PingFangSC-Light;\">\u56fe\u7247\u6765\u6e90\uff1ahttps:\/\/developer.cisco.com\/docs\/ios-xe\/#!day-zero-provisioning-quick-start-guide\/day-zero-automation<\/figcaption><\/figure>\n<p style=\"padding-top: 8px; padding-bottom: 8px; margin: 5px; line-height: 1.5; letter-spacing: 0.05em; font-size: 15px; word-spacing: 0em;\" data-tool=\"mdnice\u7f16\u8f91\u5668\">Catalyst 3650\/3850\/9200\/9300L\/9300\/9400\/9500\u7cfb\u5217\u4ea4\u6362\u673a\u652f\u6301iPXE\uff08\u9700\u6ee1\u8db3\u7279\u5b9a\u7684IOS XE\u7248\u672c\u8981\u6c42\uff09\u3002\u4f46\u4f7f\u7528iPXE\u6709\u4e00\u4e2a\u5f88\u91cd\u8981\u7684\u9650\u5236\uff1aCatalyst\u4ea4\u6362\u673a\u9ed8\u8ba4\u7684Boot mode\u662f\u672c\u5730\u542f\u52a8\u3002\u5982\u679c\u8981\u542f\u7528iPXE\uff0c\u9700\u8981\u5148\u5728CLI\u505a\u4e00\u4e9b\u914d\u7f6e\uff1a<\/p>\n<pre style=\"margin-top: 10px; margin-bottom: 10px; border-radius: 5px; box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;\" data-tool=\"mdnice\u7f16\u8f91\u5668\"><code style=\"overflow-x: auto; padding: 16px; color: #abb2bf; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; font-size: 12px; -webkit-overflow-scrolling: touch; padding-top: 15px; background: #282c34; border-radius: 5px;\">Device<span style=\"color: #61aeee; line-height: 26px;\">#\u00a0configure\u00a0terminal<\/span>\r\nDevice(config)<span style=\"color: #61aeee; line-height: 26px;\">#\u00a0boot\u00a0ipxe\u00a0forever\u00a0switch\u00a01<\/span>\r\nDevice(config)<span style=\"color: #61aeee; line-height: 26px;\">#\u00a0end<\/span>\r\nDevice<span style=\"color: #61aeee; line-height: 26px;\">#\u00a0copy\u00a0run\u00a0start<\/span>\r\n<\/code><\/pre>\n<p style=\"padding-top: 8px; padding-bottom: 8px; margin: 5px; line-height: 1.5; letter-spacing: 0.05em; font-size: 15px; word-spacing: 0em;\" data-tool=\"mdnice\u7f16\u8f91\u5668\">\u901a\u5e38\uff0c\u5728\u5b9e\u65bd\u4e00\u4e2a\u56ed\u533a\u7f51\u9879\u76ee\u7684\u65f6\u5019\uff0c\u5982\u679c\u6709\u6761\u4ef6\u4e3a\u6bcf\u53f0\u4ea4\u6362\u673a\u505a\u9884\u914d\u7f6e\u542f\u7528iPXE\uff0c\u8fd8\u4e0d\u5982\u76f4\u63a5\u628a\u5b8c\u6574\u7684\u914d\u7f6e\u704c\u8fdb\u53bb\u4e86\u3002\u6240\u4ee5\uff0c\u6211\u4eec\u66f4\u503e\u5411\u4e8e\u9009\u62e9ZTP\u4f5c\u4e3aCatalyst\u7f51\u7edc\u8bbe\u5907Day0 Operation\u7684\u65b9\u5f0f\uff0c\u800c\u4e0d\u662fiPXE\u3002<\/p>\n<p style=\"padding-top: 8px; padding-bottom: 8px; margin: 5px; line-height: 1.5; letter-spacing: 0.05em; font-size: 15px; word-spacing: 0em;\" data-tool=\"mdnice\u7f16\u8f91\u5668\">\u4e0b\u56fe\u662fZTP\u7684\u5de5\u4f5c\u6d41\u7a0b\u3002\u6709\u51e0\u4e2a\u5173\u952e\u8282\u70b9\uff1a<\/p>\n<ul class=\"list-paddingleft-1\" style=\"margin-top: 8px; margin-bottom: 8px; padding-left: 25px;\" data-tool=\"mdnice\u7f16\u8f91\u5668\">\n<li>\n<section style=\"margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: #010101; font-size: 15px;\">DHCP Option<\/section>\n<\/li>\n<li>\n<section style=\"margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: #010101; font-size: 15px;\">Guest Shell<\/section>\n<\/li>\n<li>\n<section style=\"margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: #010101; font-size: 15px;\">Python\u811a\u672c<\/section>\n<\/li>\n<\/ul>\n<figure style=\"margin-top: 10px; margin-bottom: 10px; display: flex; flex-direction: column; justify-content: center; align-items: center;\" data-tool=\"mdnice\u7f16\u8f91\u5668\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/www.xh86.me\/wp-content\/uploads\/2022\/10\/wxsync-2022-10-a5d88e184611812a2e33fd9ec7f3cb80.jpeg'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" class=\"rich_pages wxw-img\" style=\"border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 5px; border-bottom-left-radius: 5px; display: block; margin: 20px auto; width: 85%; object-fit: contain; box-shadow: #84a1a8 0px 10px 15px; height: auto !important;\" data-original=\"https:\/\/www.xh86.me\/wp-content\/uploads\/2022\/10\/wxsync-2022-10-a5d88e184611812a2e33fd9ec7f3cb80.jpeg\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" data-ratio=\"0.3648\" data-type=\"jpeg\" data-w=\"1875\" \/><\/div><figcaption style=\"margin-top: 5px; text-align: center; color: #888888; font-size: 12px; font-family: PingFangSC-Light;\">IOSXE ZTP\u6d41\u7a0b<\/figcaption><\/figure>\n<h3 style=\"margin-top: 30px; margin-bottom: 15px; font-weight: bold; color: #0e88eb;\" data-tool=\"mdnice\u7f16\u8f91\u5668\">DHCP Option<\/h3>\n<p style=\"padding-top: 8px; padding-bottom: 8px; margin: 5px; line-height: 1.5; letter-spacing: 0.05em; font-size: 15px; word-spacing: 0em;\" data-tool=\"mdnice\u7f16\u8f91\u5668\">DHCP Server\u901a\u8fc7DHCP Option\u6765\u544a\u8bc9DHCP Client\u4ece\u54ea\u91cc\u4e0b\u8f7dPython\u811a\u672c\u6587\u4ef6\u3002\u4e0b\u8f7d\u7684\u65b9\u5f0f\u53ef\u4ee5\u662fHTTP\uff0c\u4e5f\u53ef\u4ee5\u662fTFTP\u3002\u5982\u679c\u89c4\u5212\u4f7f\u7528HTTP Server\u63d0\u4f9b\u6587\u4ef6\u4e0b\u8f7d\uff0c\u5219\u4ec5\u7528DHCP Option 67\u4e3aDHCP Client\u63d0\u4f9b\u6587\u4ef6\u7684URL\u3002<\/p>\n<p style=\"padding-top: 8px; padding-bottom: 8px; margin: 5px; line-height: 1.5; letter-spacing: 0.05em; font-size: 15px; word-spacing: 0em;\" data-tool=\"mdnice\u7f16\u8f91\u5668\">IOS-XE\u8bbe\u5907\u914d\u7f6eDHCP Server\u548cOption 67\u7684\u547d\u4ee4\u5982\u4e0b\uff1a<\/p>\n<pre style=\"margin-top: 10px; margin-bottom: 10px; border-radius: 5px; box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;\" data-tool=\"mdnice\u7f16\u8f91\u5668\"><code style=\"overflow-x: auto; padding: 16px; color: #abb2bf; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; font-size: 12px; -webkit-overflow-scrolling: touch; padding-top: 15px; background: #282c34; border-radius: 5px;\">Device(config)<span style=\"color: #61aeee; line-height: 26px;\">#\u00a0ip\u00a0dhcp\u00a0excluded-address\u00a010.1.1.1<\/span>\r\nDevice(config)<span style=\"color: #61aeee; line-height: 26px;\">#\u00a0ip\u00a0dhcp\u00a0pool\u00a0pnp_device_pool<\/span>\r\nDevice(config-dhcp)<span style=\"color: #61aeee; line-height: 26px;\">#\u00a0network\u00a010.1.1.0\u00a0255.255.255.0<\/span>\r\nDevice(config-dhcp)<span style=\"color: #61aeee; line-height: 26px;\">#\u00a0default-router\u00a010.1.1.1\u00a0\u00a0<\/span>\r\nDevice(config-dhcp)<span style=\"color: #61aeee; line-height: 26px;\">#\u00a0option\u00a067\u00a0ascii\u00a0http:\/\/192.168.1.1:8000\/python_script.py<\/span>\r\nDevice(config-dhcp)<span style=\"color: #61aeee; line-height: 26px;\">#\u00a0end<\/span>\r\n<\/code><\/pre>\n<p style=\"padding-top: 8px; padding-bottom: 8px; margin: 5px; line-height: 1.5; letter-spacing: 0.05em; font-size: 15px; word-spacing: 0em;\" data-tool=\"mdnice\u7f16\u8f91\u5668\">Linux <code style=\"font-size: 14px; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin-right: 2px; margin-left: 2px; color: #1e6bb8; background-color: rgba(27, 31, 35, 0.05); font-family: 'Operator Mono', Consolas, Monaco, Menlo, monospace; word-break: break-all;\">dhcpd.conf<\/code>\u914d\u7f6e\u5982\u4e0b\uff1a<\/p>\n<pre style=\"margin-top: 10px; margin-bottom: 10px; border-radius: 5px; box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;\" data-tool=\"mdnice\u7f16\u8f91\u5668\"><code style=\"overflow-x: auto; padding: 16px; color: #abb2bf; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; font-size: 12px; -webkit-overflow-scrolling: touch; padding-top: 15px; background: #282c34; border-radius: 5px;\">subnet\u00a0<span style=\"color: #d19a66; line-height: 26px;\">10.1<\/span><span style=\"color: #d19a66; line-height: 26px;\">.1<\/span><span style=\"color: #d19a66; line-height: 26px;\">.0<\/span>\u00a0netmask\u00a0<span style=\"color: #d19a66; line-height: 26px;\">255.255<\/span><span style=\"color: #d19a66; line-height: 26px;\">.255<\/span><span style=\"color: #d19a66; line-height: 26px;\">.0<\/span>\u00a0{\r\n\u00a0\u00a0range\u00a0<span style=\"color: #d19a66; line-height: 26px;\">10.1<\/span><span style=\"color: #d19a66; line-height: 26px;\">.1<\/span><span style=\"color: #d19a66; line-height: 26px;\">.2<\/span>\u00a0<span style=\"color: #d19a66; line-height: 26px;\">10.1<\/span><span style=\"color: #d19a66; line-height: 26px;\">.1<\/span><span style=\"color: #d19a66; line-height: 26px;\">.255<\/span>;\r\n\u00a0\u00a0option\u00a0bootfile-name\u00a0<span style=\"color: #98c379; line-height: 26px;\">\"http:\/\/192.168.1.1:8000\/python_script.py\"<\/span>;\r\n}\r\n<\/code><\/pre>\n<p style=\"padding-top: 8px; padding-bottom: 8px; margin: 5px; line-height: 1.5; letter-spacing: 0.05em; font-size: 15px; word-spacing: 0em;\" data-tool=\"mdnice\u7f16\u8f91\u5668\">\u5982\u679c\u89c4\u5212\u4f7f\u7528TFTP Server\u63d0\u4f9b\u6587\u4ef6\u4e0b\u8f7d\uff0c\u5219\u9700\u540c\u65f6\u4f7f\u7528Option 150\u548c67\u3002\u5176\u4e2dOption 150\u7684\u4f5c\u7528\u662f\u5c06TFPT Server\u7684IP\u5730\u5740\u544a\u8bc9DHCP Client\uff1bOption 67\u7684\u4f5c\u7528\u662f\u4e3aDHCP Client\u63d0\u4f9b\u6587\u4ef6\u7684Path\u3002<\/p>\n<p style=\"padding-top: 8px; padding-bottom: 8px; margin: 5px; line-height: 1.5; letter-spacing: 0.05em; font-size: 15px; word-spacing: 0em;\" data-tool=\"mdnice\u7f16\u8f91\u5668\">IOS-XE\u8bbe\u5907\u914d\u7f6eDHCP Server\u3001Option 150\u548cOption 67\u7684\u547d\u4ee4\u5982\u4e0b\uff1a<\/p>\n<pre style=\"margin-top: 10px; margin-bottom: 10px; border-radius: 5px; box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;\" data-tool=\"mdnice\u7f16\u8f91\u5668\"><code style=\"overflow-x: auto; padding: 16px; color: #abb2bf; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; font-size: 12px; -webkit-overflow-scrolling: touch; padding-top: 15px; background: #282c34; border-radius: 5px;\">Device(config)<span style=\"color: #61aeee; line-height: 26px;\">#\u00a0ip\u00a0dhcp\u00a0excluded-address\u00a010.1.1.1<\/span>\r\nDevice(config)<span style=\"color: #61aeee; line-height: 26px;\">#\u00a0ip\u00a0dhcp\u00a0pool\u00a0pnp_device_pool<\/span>\r\nDevice(config-dhcp)<span style=\"color: #61aeee; line-height: 26px;\">#\u00a0network\u00a010.1.1.0\u00a0255.255.255.0<\/span>\r\nDevice(config-dhcp)<span style=\"color: #61aeee; line-height: 26px;\">#\u00a0default-router\u00a010.1.1.1\u00a0<\/span>\r\nDevice(config-dhcp)<span style=\"color: #61aeee; line-height: 26px;\">#\u00a0option\u00a0150\u00a0ip\u00a0192.168.1.1\u00a0<\/span>\r\nDevice(config-dhcp)<span style=\"color: #61aeee; line-height: 26px;\">#\u00a0option\u00a067\u00a0ascii\u00a0\/sample_python_dir\/python_script.py<\/span>\r\nDevice(config-dhcp)<span style=\"color: #61aeee; line-height: 26px;\">#\u00a0end<\/span>\r\n<\/code><\/pre>\n<p style=\"padding-top: 8px; padding-bottom: 8px; margin: 5px; line-height: 1.5; letter-spacing: 0.05em; font-size: 15px; word-spacing: 0em;\" data-tool=\"mdnice\u7f16\u8f91\u5668\">Linux <code style=\"font-size: 14px; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin-right: 2px; margin-left: 2px; color: #1e6bb8; background-color: rgba(27, 31, 35, 0.05); font-family: 'Operator Mono', Consolas, Monaco, Menlo, monospace; word-break: break-all;\">dhcpd.conf<\/code>\u914d\u7f6e\u5982\u4e0b\uff1a<\/p>\n<pre style=\"margin-top: 10px; margin-bottom: 10px; border-radius: 5px; box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;\" data-tool=\"mdnice\u7f16\u8f91\u5668\"><code style=\"overflow-x: auto; padding: 16px; color: #abb2bf; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; font-size: 12px; -webkit-overflow-scrolling: touch; padding-top: 15px; background: #282c34; border-radius: 5px;\">subnet\u00a0<span style=\"color: #d19a66; line-height: 26px;\">10.1<\/span><span style=\"color: #d19a66; line-height: 26px;\">.1<\/span><span style=\"color: #d19a66; line-height: 26px;\">.0<\/span>\u00a0netmask\u00a0<span style=\"color: #d19a66; line-height: 26px;\">255.255<\/span><span style=\"color: #d19a66; line-height: 26px;\">.255<\/span><span style=\"color: #d19a66; line-height: 26px;\">.0<\/span>\u00a0{\r\n\u00a0\u00a0range\u00a0<span style=\"color: #d19a66; line-height: 26px;\">10.1<\/span><span style=\"color: #d19a66; line-height: 26px;\">.1<\/span><span style=\"color: #d19a66; line-height: 26px;\">.2<\/span>\u00a0<span style=\"color: #d19a66; line-height: 26px;\">10.1<\/span><span style=\"color: #d19a66; line-height: 26px;\">.1<\/span><span style=\"color: #d19a66; line-height: 26px;\">.255<\/span>;\u00a0\r\n\u00a0\u00a0option\u00a0bootfile-name\u00a0<span style=\"color: #98c379; line-height: 26px;\">\"\/sample_python_dir\/python_script.py\"<\/span>;\r\n\u00a0\u00a0option\u00a0tftp-server-name\u00a0<span style=\"color: #98c379; line-height: 26px;\">\"192.168.1.1\"<\/span>;\u00a0\r\n}\r\n<\/code><\/pre>\n<h3 style=\"margin-top: 30px; margin-bottom: 15px; font-weight: bold; color: #0e88eb;\" data-tool=\"mdnice\u7f16\u8f91\u5668\">Guest Shell<\/h3>\n<p style=\"padding-top: 8px; padding-bottom: 8px; margin: 5px; line-height: 1.5; letter-spacing: 0.05em; font-size: 15px; word-spacing: 0em;\" data-tool=\"mdnice\u7f16\u8f91\u5668\">Guestshell\u662fCisco IOS XE\u8bbe\u5907\u5185\u7f6e\u7684\u4e00\u4e2aLinux\u73af\u5883\uff0c\u7528\u6237\u53ef\u4ee5\u81ea\u884c\u5b89\u88c5\u5e76\u8fd0\u884c\u8f6f\u4ef6\u5305\u6216\u811a\u672c\uff0c\u800c\u65e0\u9700\u62c5\u5fc3\u5bf9\u7f51\u7edc\u8bbe\u5907\u7684\u8fd0\u884c\u4f1a\u4ea7\u751f\u5f71\u54cd\uff0c\u56e0\u4e3a\u5b83\u4e0e\u5bbf\u4e3b\u673a\u662f\u89e3\u8026\u7684\u3002Guestshell\u5df2\u7ecf\u5b89\u88c5\u4e86Python\u548c\u5e38\u7528\u7684\u5e93\uff0c\u7528\u6237\u53ef\u4ee5\u4f7f\u7528<code style=\"font-size: 14px; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin-right: 2px; margin-left: 2px; color: #1e6bb8; background-color: rgba(27, 31, 35, 0.05); font-family: 'Operator Mono', Consolas, Monaco, Menlo, monospace; word-break: break-all;\">pip install<\/code>\u3001<code style=\"font-size: 14px; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin-right: 2px; margin-left: 2px; color: #1e6bb8; background-color: rgba(27, 31, 35, 0.05); font-family: 'Operator Mono', Consolas, Monaco, Menlo, monospace; word-break: break-all;\">yum install<\/code>\u6216\u8005<code style=\"font-size: 14px; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin-right: 2px; margin-left: 2px; color: #1e6bb8; background-color: rgba(27, 31, 35, 0.05); font-family: 'Operator Mono', Consolas, Monaco, Menlo, monospace; word-break: break-all;\">rpm -i<\/code>\u5b89\u88c5\u8f6f\u4ef6\u5305\u3002Python\u7248\u672c\u4e3a\uff1a<\/p>\n<ul class=\"list-paddingleft-1\" style=\"margin-top: 8px; margin-bottom: 8px; padding-left: 25px;\" data-tool=\"mdnice\u7f16\u8f91\u5668\">\n<li>\n<section style=\"margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: #010101; font-size: 15px;\">IOS XE 17.3.1\u4ee5\u524d\u7684\u7248\u672c\uff1aPython 2.7\uff0c\u9ed8\u8ba4Python V2<\/section>\n<\/li>\n<li>\n<section style=\"margin-top: 5px; margin-bottom: 5px; line-height: 26px; color: #010101; font-size: 15px;\">\u4eceIOS XE 17.1.1\u5f00\u59cb\uff1a\u652f\u6301Python 3.6\uff0c\u5e76\u4e14\u4eceIOS XE 17.3.1\u5f00\u59cb\uff0c\u9ed8\u8ba4Python V3<\/section>\n<\/li>\n<\/ul>\n<p style=\"padding-top: 8px; padding-bottom: 8px; margin: 5px; line-height: 1.5; letter-spacing: 0.05em; font-size: 15px; word-spacing: 0em;\" data-tool=\"mdnice\u7f16\u8f91\u5668\">\u5728ZTP\u7684\u5de5\u4f5c\u6d41\u7a0b\u4e2d\uff0cIOS XE\u8bbe\u5907\u9700\u8981\u4e0b\u8f7dPython\u811a\u672c\u7136\u540e\u5728Guest Shell\u91cc\u9762\u8fd0\u884c\uff0c\u5b8c\u6210\u8bbe\u5907\u7684\u5347\u7ea7\u548c\u914d\u7f6e\u5de5\u4f5c\u3002\u5230\u76ee\u524d\u4e3a\u6b62\uff0c\u9664\u4e86Catalyst 9200L\u4ee5\u5916\u7684\u6240\u6709C9K\u4ea4\u6362\u673a\u90fd\u652f\u6301Guest Shell\uff0c\u8fd9\u4e5f\u610f\u5473\u77409200L\u4ea4\u6362\u673a\u4e0d\u652f\u6301ZTP\uff0c\u4f46\u5176\u4ed6\u6240\u6709\u578b\u53f7\u7684C9K\u90fd\u53ef\u4ee5\u652f\u6301ZTP\u3002\u53e6\u5916\uff0cCatalyst 3650\u548c3850\u4e5f\u652f\u6301Guest Shell\u548cZTP\u3002<\/p>\n<h3 style=\"margin-top: 30px; margin-bottom: 15px; font-weight: bold; color: #0e88eb;\" data-tool=\"mdnice\u7f16\u8f91\u5668\">Python\u811a\u672c<\/h3>\n<pre style=\"margin-top: 10px; margin-bottom: 10px; border-radius: 5px; box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;\" data-tool=\"mdnice\u7f16\u8f91\u5668\"><code style=\"overflow-x: auto; padding: 16px; color: #abb2bf; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; font-size: 12px; -webkit-overflow-scrolling: touch; padding-top: 15px; background: #282c34; border-radius: 5px;\">git\u00a0clone\u00a0https:\/\/github.com\/jeremycohoe\/IOSXE-Zero-Touch-Provisioning.git\r\n<\/code><\/pre>\n<p style=\"padding-top: 8px; padding-bottom: 8px; margin: 5px; line-height: 1.5; letter-spacing: 0.05em; font-size: 15px; word-spacing: 0em;\" data-tool=\"mdnice\u7f16\u8f91\u5668\">Clone\u4e4b\u540e\uff0c\u628a\u91cc\u9762\u7684<code style=\"font-size: 14px; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin-right: 2px; margin-left: 2px; color: #1e6bb8; background-color: rgba(27, 31, 35, 0.05); font-family: 'Operator Mono', Consolas, Monaco, Menlo, monospace; word-break: break-all;\">ztp-advanced.py<\/code>\u7b80\u5355\u6539\u6539\u5c31\u53ef\u4ee5\u76f4\u63a5\u7528\u4e86\u3002<strong style=\"font-weight: border; color: #0e88eb;\">\u8bf7\u6ce8\u610f\uff0c\u8fd9\u662f\u4e00\u4e2aPython2\u7684\u811a\u672c\uff0c\u5982\u679c\u8bbe\u5907\u51fa\u5382\u7684IOS XE\u662f17.3.1\u6216\u8005\u66f4\u9ad8\u7248\u672c\uff0c\u9700\u8981\u5c06\u811a\u672c\u4fee\u6539\u6210Python3<\/strong>\u3002\u7a0b\u5e8f\u8fd0\u884c\u903b\u8f91\u5982\u4e0b\uff1a<\/p>\n<pre style=\"margin-top: 10px; margin-bottom: 10px; border-radius: 5px; box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;\" data-tool=\"mdnice\u7f16\u8f91\u5668\"><code style=\"overflow-x: auto; padding: 16px; color: #abb2bf; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; font-size: 12px; -webkit-overflow-scrolling: touch; padding-top: 15px; background: #282c34; border-radius: 5px;\"><span style=\"line-height: 26px;\"><span style=\"color: #c678dd; line-height: 26px;\">def<\/span>\u00a0<span style=\"color: #61aeee; line-height: 26px;\">main<\/span><span style=\"line-height: 26px;\">()<\/span>:<\/span>\r\n\u00a0\u00a0\u00a0\u00a0<span style=\"color: #5c6370; font-style: italic; line-height: 26px;\">#\u00a0\u83b7\u53d6\u8bbe\u5907\u5e8f\u5217\u53f7\uff0c\u5e76\u6307\u5b9a\u4ee5\u5e8f\u5217\u53f7\u547d\u540d\u7684Config\u6587\u4ef6<\/span>\r\n\u00a0\u00a0\u00a0\u00a0serial\u00a0=\u00a0get_serial()\r\n\u00a0\u00a0\u00a0\u00a0config_file\u00a0=\u00a0<span style=\"color: #98c379; line-height: 26px;\">\"{}.cfg\"<\/span>.format(serial)<\/code><\/pre>\n<p><span style=\"color: #5c6370; font-style: italic; line-height: 26px;\">#\u00a0\u5224\u65ad\u8bbe\u5907IOS\u7248\u672c\u662f\u5426\u662fGolden\u00a0image\uff0c\u5982\u679c\u4e0d\u662f\uff0c\u5219\u9700\u8981\u5347\u7ea7<\/span><br \/>\n<span style=\"color: #c678dd; line-height: 26px;\">if<\/span>\u00a0upgrade_required():<br \/>\n<span style=\"color: #5c6370; font-style: italic; line-height: 26px;\">#\u00a0\u68c0\u67e5Golden\u00a0image\u662f\u5426\u5df2\u7ecf\u5b58\u5728\u4e8e\u8bbe\u5907Flash<\/span><br \/>\n<span style=\"color: #c678dd; line-height: 26px;\">if<\/span>\u00a0check_file_exists(img_cat9k):<br \/>\n<span style=\"color: #5c6370; font-style: italic; line-height: 26px;\">#\u00a0\u5982\u679cFlash\u91cc\u9762\u6709image\u6587\u4ef6\uff0c\u5219\u6821\u9a8c\u5176MD5\u00a0checksum<\/span><br \/>\n<span style=\"color: #c678dd; line-height: 26px;\">if<\/span>\u00a0<span style=\"color: #c678dd; line-height: 26px;\">not<\/span>\u00a0verify_dst_image_md5(img_cat9k,\u00a0img_cat9k_md5):<br \/>\n<span style=\"color: #5c6370; font-style: italic; line-height: 26px;\">#\u00a0\u5982\u679cMD5\u00a0checksum\u6709\u8bef\uff0c\u5219\u91cd\u65b0\u4e0b\u8f7dimage<\/span><br \/>\nfile_transfer(tftp_server,\u00a0img_cat9k)<br \/>\n<span style=\"color: #c678dd; line-height: 26px;\">if<\/span>\u00a0<span style=\"color: #c678dd; line-height: 26px;\">not<\/span>\u00a0verify_dst_image_md5(img_cat9k,\u00a0img_cat9k_md5):<br \/>\n<span style=\"color: #5c6370; font-style: italic; line-height: 26px;\">#\u00a0\u5982\u679c\u91cd\u65b0\u4e0b\u8f7d\u7684image\u4ecd\u7136MD5\u00a0checksum\u6821\u9a8c\u5931\u8d25\uff0c\u5219\u6253\u5370\u9519\u8bef\uff0c\u9000\u51fa\u7a0b\u5e8f<\/span><br \/>\n<span style=\"color: #c678dd; line-height: 26px;\">raise<\/span>\u00a0ValueError(<span style=\"color: #98c379; line-height: 26px;\">&#8216;Failed\u00a0Xfer&#8217;<\/span>)<br \/>\n<span style=\"color: #c678dd; line-height: 26px;\">else<\/span>:<br \/>\n<span style=\"color: #5c6370; font-style: italic; line-height: 26px;\">#\u00a0\u5982\u679cFlash\u91cc\u9762\u6ca1\u6709image\u6587\u4ef6\uff0c\u5219\u4e0b\u8f7dimage<\/span><br \/>\nfile_transfer(tftp_server,\u00a0img_cat9k)<br \/>\n<span style=\"color: #5c6370; font-style: italic; line-height: 26px;\">#\u00a0\u5982\u679c\u4e0b\u8f7d\u7684image\u00a0MD5\u00a0checksum\u6821\u9a8c\u5931\u8d25\uff0c\u5219\u6253\u5370\u9519\u8bef\uff0c\u9000\u51fa\u7a0b\u5e8f<\/span><br \/>\n<span style=\"color: #c678dd; line-height: 26px;\">if<\/span>\u00a0<span style=\"color: #c678dd; line-height: 26px;\">not<\/span>\u00a0verify_dst_image_md5(img_cat9k,\u00a0img_cat9k_md5):<br \/>\n<span style=\"color: #c678dd; line-height: 26px;\">raise<\/span>\u00a0ValueError(<span style=\"color: #98c379; line-height: 26px;\">&#8216;XXX\u00a0Failed\u00a0Xfer\u00a0XXX&#8217;<\/span>)<\/p>\n<pre style=\"margin-top: 10px; margin-bottom: 10px; border-radius: 5px; box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;\" data-tool=\"mdnice\u7f16\u8f91\u5668\"><code style=\"overflow-x: auto; padding: 16px; color: #abb2bf; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; font-size: 12px; -webkit-overflow-scrolling: touch; padding-top: 15px; background: #282c34; border-radius: 5px;\"><\/code><\/pre>\n<p><span style=\"color: #5c6370; font-style: italic; line-height: 26px;\">#\u00a0\u7ed9\u5bbf\u4e3b\u673a\uff08\u7f51\u7edc\u8bbe\u5907\uff09\u914d\u7f6eEEM\u811a\u672c\uff0c\u7528\u4e8e\u5347\u7ea7IOS\u7248\u672c<\/span><br \/>\ndeploy_eem_upgrade_script(img_cat9k)<br \/>\n<span style=\"color: #5c6370; font-style: italic; line-height: 26px;\">#\u00a0\u5728\u5bbf\u4e3b\u673a\u4e0a\u8fd0\u884cEEM\u811a\u672c\uff0c\u5f00\u59cb\u5347\u7ea7IOS\u7248\u672c<\/span><br \/>\ncli(<span style=\"color: #98c379; line-height: 26px;\">&#8216;event\u00a0manager\u00a0run\u00a0upgrade&#8217;<\/span>)<br \/>\ntime.sleep(<span style=\"color: #d19a66; line-height: 26px;\">600<\/span>)<\/p>\n<pre style=\"margin-top: 10px; margin-bottom: 10px; border-radius: 5px; box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;\" data-tool=\"mdnice\u7f16\u8f91\u5668\"><code style=\"overflow-x: auto; padding: 16px; color: #abb2bf; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; font-size: 12px; -webkit-overflow-scrolling: touch; padding-top: 15px; background: #282c34; border-radius: 5px;\"><\/code><\/pre>\n<p><span style=\"color: #5c6370; font-style: italic; line-height: 26px;\">#\u00a0\u7ed9\u5bbf\u4e3b\u673a\u914d\u7f6eEEM\u811a\u672c\uff0c\u7528\u4e8e\u5347\u7ea7\u4e4b\u540e\u6e05\u7406inactive\u955c\u50cf\u6587\u4ef6<\/span><br \/>\ndeploy_eem_cleanup_script()<br \/>\n<span style=\"color: #5c6370; font-style: italic; line-height: 26px;\">#\u00a0\u5728\u5bbf\u4e3b\u673a\u4e0a\u8fd0\u884cEEM\u811a\u672c\uff0c\u6e05\u7406inactive\u955c\u50cf\u6587\u4ef6<\/span><br \/>\ncli(<span style=\"color: #98c379; line-height: 26px;\">&#8216;event\u00a0manager\u00a0run\u00a0cleanup&#8217;<\/span>)<br \/>\ntime.sleep(<span style=\"color: #d19a66; line-height: 26px;\">30<\/span>)<\/p>\n<p><span style=\"color: #5c6370; font-style: italic; line-height: 26px;\">#\u00a0\u68c0\u67e5\u8bbe\u5907Flash\u4e0a\u662f\u5426\u5b58\u5728\u5f85\u90e8\u7f72\u7684Config\u6587\u4ef6\uff0c\u5982\u679c\u4e0d\u5b58\u5728\uff0c\u5219\u4e0b\u8f7dConfig\u6587\u4ef6<\/span><br \/>\n<span style=\"color: #c678dd; line-height: 26px;\">if<\/span>\u00a0<span style=\"color: #c678dd; line-height: 26px;\">not<\/span>\u00a0check_file_exists(config_file):<br \/>\nfile_transfer(tftp_server,\u00a0config_file)<br \/>\ntime.sleep(<span style=\"color: #d19a66; line-height: 26px;\">10<\/span>)<br \/>\n<span style=\"color: #5c6370; font-style: italic; line-height: 26px;\">#\u00a0\u8bbe\u5907\u81ea\u5e26\u7684\u8bc1\u4e66\u90fd\u5220\u9664<\/span><br \/>\nfind_certs()<br \/>\ntime.sleep(<span style=\"color: #d19a66; line-height: 26px;\">10<\/span>)<\/p>\n<pre style=\"margin-top: 10px; margin-bottom: 10px; border-radius: 5px; box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;\" data-tool=\"mdnice\u7f16\u8f91\u5668\"><code style=\"overflow-x: auto; padding: 16px; color: #abb2bf; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; font-size: 12px; -webkit-overflow-scrolling: touch; padding-top: 15px; background: #282c34; border-radius: 5px;\"><\/code><\/pre>\n<p><span style=\"color: #c678dd; line-height: 26px;\">try<\/span>:<br \/>\n<span style=\"color: #5c6370; font-style: italic; line-height: 26px;\">#\u00a0\u5728\u7f51\u7edc\u8bbe\u5907\u4e0a\u6267\u884cconfigure\u00a0replace\u00a0xxx\u00a0force\u547d\u4ee4\uff0c\u7528Config\u6587\u4ef6\u5f3a\u884c\u66ff\u6362\u8bbe\u5907\u539f\u6709\u7684config<\/span><br \/>\nconfigure_replace(config_file)<br \/>\n<span style=\"color: #5c6370; font-style: italic; line-height: 26px;\">#\u00a0\u91cd\u65b0\u751f\u6210\u8bc1\u4e66<\/span><br \/>\nconfigure(<span style=\"color: #98c379; line-height: 26px;\">&#8216;crypto\u00a0key\u00a0generate\u00a0rsa\u00a0modulus\u00a04096&#8217;<\/span>)<br \/>\n<span style=\"color: #c678dd; line-height: 26px;\">except<\/span>\u00a0Exception\u00a0<span style=\"color: #c678dd; line-height: 26px;\">as<\/span>\u00a0e:<br \/>\n<span style=\"color: #c678dd; line-height: 26px;\">pass<\/span><\/p>\n<pre style=\"margin-top: 10px; margin-bottom: 10px; border-radius: 5px; box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;\" data-tool=\"mdnice\u7f16\u8f91\u5668\"><code style=\"overflow-x: auto; padding: 16px; color: #abb2bf; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; font-size: 12px; -webkit-overflow-scrolling: touch; padding-top: 15px; background: #282c34; border-radius: 5px;\"><\/code><\/pre>\n<h3 style=\"margin-top: 30px; margin-bottom: 15px; font-weight: bold; color: #0e88eb;\" data-tool=\"mdnice\u7f16\u8f91\u5668\">\u9879\u76ee\u5b9e\u64cd\u6d41\u7a0b<\/h3>\n<h4 style=\"margin-top: 30px; margin-bottom: 15px; font-weight: bold; font-size: 15px; color: #0e88eb;\" data-tool=\"mdnice\u7f16\u8f91\u5668\">1. \u51c6\u5907\u8bbe\u5907\u6e05\u5355\u548c\u53d8\u91cf\u8868<\/h4>\n<p style=\"padding-top: 8px; padding-bottom: 8px; margin: 5px; line-height: 1.5; letter-spacing: 0.05em; font-size: 15px; word-spacing: 0em;\" data-tool=\"mdnice\u7f16\u8f91\u5668\">\u901a\u5e38\u8bbe\u5907\u4f9b\u8d27\u5546\u53ef\u4ee5\u63d0\u4f9bExcel\u683c\u5f0f\u7684\u8bbe\u5907\u6e05\u5355\uff0c\u91cc\u9762\u5305\u542b\u5e8f\u5217\u53f7\u548c\u4ea7\u54c1\u578b\u53f7\u7b49\u4fe1\u606f\u3002\u53ef\u4ee5\u6839\u636e\u8fd9\u4e2a\u8868\u683c\u5236\u4f5c\u53d8\u91cf\u8868\u3002\u5982\u679c\u6ca1\u6709\u73b0\u6210\u7684\u8868\u683c\uff0c\u5219\u9700\u8981\u7528\u626b\u7801\u67aa\u6216\u8005\u624b\u673a\u5b89\u88c5APP\u628a\u6240\u6709\u8bbe\u5907\u7684\u6761\u5f62\u7801\u626b\u4e00\u904d\uff0c\u518d\u5bfc\u51fa\u8868\u683c\u3002<\/p>\n<p style=\"padding-top: 8px; padding-bottom: 8px; margin: 5px; line-height: 1.5; letter-spacing: 0.05em; font-size: 15px; word-spacing: 0em;\" data-tool=\"mdnice\u7f16\u8f91\u5668\">\u8868\u683c\u53ef\u4ee5\u662f<code style=\"font-size: 14px; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin-right: 2px; margin-left: 2px; color: #1e6bb8; background-color: rgba(27, 31, 35, 0.05); font-family: 'Operator Mono', Consolas, Monaco, Menlo, monospace; word-break: break-all;\">.csv<\/code>\u6216\u8005<code style=\"font-size: 14px; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin-right: 2px; margin-left: 2px; color: #1e6bb8; background-color: rgba(27, 31, 35, 0.05); font-family: 'Operator Mono', Consolas, Monaco, Menlo, monospace; word-break: break-all;\">.xls<\/code>\u7b49\u683c\u5f0f\uff0c\u53d6\u51b3\u4e8e\u4f60\u9009\u62e9\u7684Python\u5e93\u3002\u672c\u6587\u4f7f\u7528<code style=\"font-size: 14px; overflow-wrap: break-word; padding: 2px 4px; border-radius: 4px; margin-right: 2px; margin-left: 2px; color: #1e6bb8; background-color: rgba(27, 31, 35, 0.05); font-family: 'Operator Mono', Consolas, Monaco, Menlo, monospace; word-break: break-all;\">.csv<\/code>\u683c\u5f0f\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\uff0c\u6240\u6709\u63a5\u5165\u4ea4\u6362\u673a\u7684\u914d\u7f6e\u90fd\u4e00\u6837\uff0c\u53ea\u6709\u4e3b\u673a\u540d\u548c\u7ba1\u7406IP\u5730\u5740\u4e0d\u540c\u3002<\/p>\n<p style=\"padding-top: 8px; padding-bottom: 8px; margin: 5px; line-height: 1.5; letter-spacing: 0.05em; font-size: 15px; word-spacing: 0em;\" data-tool=\"mdnice\u7f16\u8f91\u5668\">\u8bf7\u6ce8\u610f\uff0c\u8868\u683c\u7684\u5217\u5934\u5c31\u662f\u53d8\u91cf\u540d\uff0c\u4e0d\u80fd\u6709\u4e2d\u6587\u5b57\u7b26\u3002<\/p>\n<pre style=\"margin-top: 10px; margin-bottom: 10px; border-radius: 5px; box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;\" data-tool=\"mdnice\u7f16\u8f91\u5668\"><code style=\"overflow-x: auto; padding: 16px; color: #abb2bf; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; font-size: 12px; -webkit-overflow-scrolling: touch; padding-top: 15px; background: #282c34; border-radius: 5px;\">pid,serial_number,asset_number,hostname,mgmt_ip,mgmt_ip_mask,mgmt_gw\r\nC9300-48T,SN11111111,ASSET11111,SZ-Campus-Floor1-1,10.1.1.1,255.255.255.0,10.1.1.255\r\nC9300-48T,SN22222222,ASSET22222,SZ-Campus-Floor2-2,10.2.2.2,255.255.255.0,10.2.2.255\r\nC9300-48T,SN33333333,ASSET33333,SZ-Campus-Floor3-3,10.3.3.3,255.255.255.0,10.3.3.255\r\n<\/code><\/pre>\n<h4 style=\"margin-top: 30px; margin-bottom: 15px; font-weight: bold; font-size: 15px; color: #0e88eb;\" data-tool=\"mdnice\u7f16\u8f91\u5668\">2. \u51c6\u5907\u914d\u7f6e\u6a21\u7248<\/h4>\n<p style=\"padding-top: 8px; padding-bottom: 8px; margin: 5px; line-height: 1.5; letter-spacing: 0.05em; font-size: 15px; word-spacing: 0em;\" data-tool=\"mdnice\u7f16\u8f91\u5668\">\u53ef\u4ee5\u53c2\u8003\u6211\u4ee5\u524d\u5199\u7684<a style=\"overflow-wrap: break-word; font-weight: bold; color: #0e88eb; border-bottom: 0px solid #ff3502; font-family: STHeitiSC-Light;\" data-linktype=\"2\">\u4f7f\u7528 Jinja2 \u6a21\u7248\u751f\u6210\u7f51\u7edc\u8bbe\u5907\u914d\u7f6e\u6587\u4ef6<\/a>\u3002\u56e0\u4e3a\u8fd9\u4e2a\u4f8b\u5b50\u53ea\u67094\u4e2a\u53d8\u91cf\uff0c\u6240\u4ee5\u5c31\u4e0d\u628aJinja\u6a21\u7248\u8d34\u51fa\u6765\u4e86\u3002<\/p>\n<h4 style=\"margin-top: 30px; margin-bottom: 15px; font-weight: bold; font-size: 15px; color: #0e88eb;\" data-tool=\"mdnice\u7f16\u8f91\u5668\">3. \u4e3a\u6bcf\u4e00\u4e2a\u5e8f\u5217\u53f7\u751f\u6210\u4e00\u4efd\u914d\u7f6e\u6587\u4ef6<\/h4>\n<p style=\"padding-top: 8px; padding-bottom: 8px; margin: 5px; line-height: 1.5; letter-spacing: 0.05em; font-size: 15px; word-spacing: 0em;\" data-tool=\"mdnice\u7f16\u8f91\u5668\">\u6839\u636eCSV\u683c\u5f0f\u7684\u53d8\u91cf\u8868\uff0c\u548cJinja\u6a21\u7248\uff0c\u5199\u4e00\u4e2aPython\u811a\u672c\uff0c\u4e3a\u6bcf\u4e00\u4e2a\u5e8f\u5217\u53f7\u751f\u6210\u4e00\u4efd\u914d\u7f6e\u6587\u4ef6\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u7b80\u5355\u7684Example\uff1a<\/p>\n<pre style=\"margin-top: 10px; margin-bottom: 10px; border-radius: 5px; box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;\" data-tool=\"mdnice\u7f16\u8f91\u5668\"><code style=\"overflow-x: auto; padding: 16px; color: #abb2bf; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; font-size: 12px; -webkit-overflow-scrolling: touch; padding-top: 15px; background: #282c34; border-radius: 5px;\"><span style=\"color: #c678dd; line-height: 26px;\">import<\/span>\u00a0jinja2\r\n<span style=\"color: #c678dd; line-height: 26px;\">from<\/span>\u00a0os\u00a0<span style=\"color: #c678dd; line-height: 26px;\">import<\/span>\u00a0mkdir,\u00a0path\r\n<span style=\"color: #c678dd; line-height: 26px;\">from<\/span>\u00a0csv\u00a0<span style=\"color: #c678dd; line-height: 26px;\">import<\/span>\u00a0DictReader<\/code><\/pre>\n<p><span style=\"color: #5c6370; font-style: italic; line-height: 26px;\">#\u00a0Global\u00a0variables<\/span><br \/>\nWORK_DIR\u00a0=\u00a0<span style=\"color: #98c379; line-height: 26px;\">&#8216;.\/&#8217;<\/span><br \/>\nOUTPUT_DIR\u00a0=\u00a0path.join(WORK_DIR,\u00a0<span style=\"color: #98c379; line-height: 26px;\">&#8216;configs&#8217;<\/span>)<br \/>\nCSV\u00a0=\u00a0path.join(WORK_DIR,\u00a0<span style=\"color: #98c379; line-height: 26px;\">&#8216;inventory.csv&#8217;<\/span>)<br \/>\nJINJA_TEMPLATE\u00a0=\u00a0path.join(WORK_DIR,\u00a0<span style=\"color: #98c379; line-height: 26px;\">&#8216;template.j2&#8217;<\/span>)<\/p>\n<pre style=\"margin-top: 10px; margin-bottom: 10px; border-radius: 5px; box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;\" data-tool=\"mdnice\u7f16\u8f91\u5668\"><code style=\"overflow-x: auto; padding: 16px; color: #abb2bf; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; font-size: 12px; -webkit-overflow-scrolling: touch; padding-top: 15px; background: #282c34; border-radius: 5px;\"><\/code><\/pre>\n<p><span style=\"color: #5c6370; font-style: italic; line-height: 26px;\">#\u00a0Create\u00a0configs\u00a0directory\u00a0if\u00a0not\u00a0created\u00a0already<\/span><br \/>\n<span style=\"line-height: 26px;\"><span style=\"color: #c678dd; line-height: 26px;\">def<\/span>\u00a0<span style=\"color: #61aeee; line-height: 26px;\">check_output_dir_exists<\/span><span style=\"line-height: 26px;\">()<\/span>:<\/span><br \/>\n<span style=\"color: #c678dd; line-height: 26px;\">if<\/span>\u00a0<span style=\"color: #c678dd; line-height: 26px;\">not<\/span>\u00a0path.exists(OUTPUT_DIR):<br \/>\nmkdir(OUTPUT_DIR)<\/p>\n<pre style=\"margin-top: 10px; margin-bottom: 10px; border-radius: 5px; box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;\" data-tool=\"mdnice\u7f16\u8f91\u5668\"><code style=\"overflow-x: auto; padding: 16px; color: #abb2bf; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; font-size: 12px; -webkit-overflow-scrolling: touch; padding-top: 15px; background: #282c34; border-radius: 5px;\"><\/code><\/pre>\n<p><span style=\"color: #5c6370; font-style: italic; line-height: 26px;\">#\u00a0Read\u00a0devices\u00a0and\u00a0vars<\/span><br \/>\n<span style=\"line-height: 26px;\"><span style=\"color: #c678dd; line-height: 26px;\">def<\/span>\u00a0<span style=\"color: #61aeee; line-height: 26px;\">get_devices<\/span><span style=\"line-height: 26px;\">(csv_file)<\/span>:<\/span><br \/>\ndevices\u00a0=\u00a0[]<br \/>\n<span style=\"color: #c678dd; line-height: 26px;\">with<\/span>\u00a0open(csv_file,\u00a0mode=<span style=\"color: #98c379; line-height: 26px;\">&#8216;r&#8217;<\/span>)\u00a0<span style=\"color: #c678dd; line-height: 26px;\">as<\/span>\u00a0f:<br \/>\nrows\u00a0=\u00a0DictReader(f)<br \/>\n<span style=\"color: #c678dd; line-height: 26px;\">for<\/span>\u00a0row\u00a0<span style=\"color: #c678dd; line-height: 26px;\">in<\/span>\u00a0rows:<br \/>\ndevices.append(row)<br \/>\n<span style=\"color: #c678dd; line-height: 26px;\">return<\/span>\u00a0devices<\/p>\n<pre style=\"margin-top: 10px; margin-bottom: 10px; border-radius: 5px; box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;\" data-tool=\"mdnice\u7f16\u8f91\u5668\"><code style=\"overflow-x: auto; padding: 16px; color: #abb2bf; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; font-size: 12px; -webkit-overflow-scrolling: touch; padding-top: 15px; background: #282c34; border-radius: 5px;\"><\/code><\/pre>\n<p><span style=\"color: #5c6370; font-style: italic; line-height: 26px;\">#\u00a0Read\u00a0jinja\u00a0template<\/span><br \/>\n<span style=\"line-height: 26px;\"><span style=\"color: #c678dd; line-height: 26px;\">def<\/span>\u00a0<span style=\"color: #61aeee; line-height: 26px;\">get_template<\/span><span style=\"line-height: 26px;\">(jinja_file)<\/span>:<\/span><br \/>\n<span style=\"color: #c678dd; line-height: 26px;\">with<\/span>\u00a0open(jinja_file,\u00a0mode=<span style=\"color: #98c379; line-height: 26px;\">&#8216;r&#8217;<\/span>)\u00a0<span style=\"color: #c678dd; line-height: 26px;\">as<\/span>\u00a0f:<br \/>\ntemplate\u00a0=\u00a0jinja2.Template(f.read())<br \/>\n<span style=\"color: #c678dd; line-height: 26px;\">return<\/span>\u00a0template<\/p>\n<pre style=\"margin-top: 10px; margin-bottom: 10px; border-radius: 5px; box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;\" data-tool=\"mdnice\u7f16\u8f91\u5668\"><code style=\"overflow-x: auto; padding: 16px; color: #abb2bf; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; font-size: 12px; -webkit-overflow-scrolling: touch; padding-top: 15px; background: #282c34; border-radius: 5px;\"><\/code><\/pre>\n<p><span style=\"color: #5c6370; font-style: italic; line-height: 26px;\">#\u00a0Generate\u00a0config\u00a0files<\/span><br \/>\n<span style=\"line-height: 26px;\"><span style=\"color: #c678dd; line-height: 26px;\">def<\/span>\u00a0<span style=\"color: #61aeee; line-height: 26px;\">generate_configs<\/span><span style=\"line-height: 26px;\">(csv_file,\u00a0jinja_file)<\/span>:<\/span><\/p>\n<pre style=\"margin-top: 10px; margin-bottom: 10px; border-radius: 5px; box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;\" data-tool=\"mdnice\u7f16\u8f91\u5668\"><code style=\"overflow-x: auto; padding: 16px; color: #abb2bf; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; font-size: 12px; -webkit-overflow-scrolling: touch; padding-top: 15px; background: #282c34; border-radius: 5px;\"><\/code><\/pre>\n<p>check_output_dir_exists()<br \/>\ndevices\u00a0=\u00a0get_devices(csv_file)<br \/>\ntemplate\u00a0=\u00a0get_template(jinja_file)<\/p>\n<pre style=\"margin-top: 10px; margin-bottom: 10px; border-radius: 5px; box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;\" data-tool=\"mdnice\u7f16\u8f91\u5668\"><code style=\"overflow-x: auto; padding: 16px; color: #abb2bf; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; font-size: 12px; -webkit-overflow-scrolling: touch; padding-top: 15px; background: #282c34; border-radius: 5px;\"><\/code><\/pre>\n<p><span style=\"color: #c678dd; line-height: 26px;\">for<\/span>\u00a0device\u00a0<span style=\"color: #c678dd; line-height: 26px;\">in<\/span>\u00a0devices:<br \/>\nserial_number\u00a0=\u00a0device[<span style=\"color: #98c379; line-height: 26px;\">&#8216;serial_number&#8217;<\/span>]<br \/>\noutput_file\u00a0=\u00a0path.join(OUTPUT_DIR,\u00a0<span style=\"color: #98c379; line-height: 26px;\">&#8216;.&#8217;<\/span>.join([serial_number,\u00a0<span style=\"color: #98c379; line-height: 26px;\">&#8216;cfg&#8217;<\/span>]))<br \/>\n<span style=\"color: #c678dd; line-height: 26px;\">with<\/span>\u00a0open(output_file,\u00a0mode=<span style=\"color: #98c379; line-height: 26px;\">&#8216;w&#8217;<\/span>,\u00a0encoding=<span style=\"color: #98c379; line-height: 26px;\">&#8216;utf-8&#8217;<\/span>)\u00a0<span style=\"color: #c678dd; line-height: 26px;\">as<\/span>\u00a0f:<br \/>\nf.write(template.render(device))<\/p>\n<pre style=\"margin-top: 10px; margin-bottom: 10px; border-radius: 5px; box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;\" data-tool=\"mdnice\u7f16\u8f91\u5668\"><code style=\"overflow-x: auto; padding: 16px; color: #abb2bf; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; font-size: 12px; -webkit-overflow-scrolling: touch; padding-top: 15px; background: #282c34; border-radius: 5px;\"><\/code><\/pre>\n<p><span style=\"color: #c678dd; line-height: 26px;\">if<\/span>\u00a0__name__\u00a0==\u00a0<span style=\"color: #98c379; line-height: 26px;\">&#8220;__main__&#8221;<\/span>:<br \/>\ngenerate_configs(CSV,\u00a0JINJA_TEMPLATE)<\/p>\n<pre style=\"margin-top: 10px; margin-bottom: 10px; border-radius: 5px; box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;\" data-tool=\"mdnice\u7f16\u8f91\u5668\"><code style=\"overflow-x: auto; padding: 16px; color: #abb2bf; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; font-size: 12px; -webkit-overflow-scrolling: touch; padding-top: 15px; background: #282c34; border-radius: 5px;\"><\/code><\/pre>\n<h4 style=\"margin-top: 30px; margin-bottom: 15px; font-weight: bold; font-size: 15px; color: #0e88eb;\" data-tool=\"mdnice\u7f16\u8f91\u5668\">4. \u51c6\u5907Guestshell Python\u811a\u672c\uff0c\u914d\u7f6eHTTP\/TFTP Server\u548cDHCP Server<\/h4>\n<p style=\"padding-top: 8px; padding-bottom: 8px; margin: 5px; line-height: 1.5; letter-spacing: 0.05em; font-size: 15px; word-spacing: 0em;\" data-tool=\"mdnice\u7f16\u8f91\u5668\">\u6309\u7167\u4e0a\u6587\u7684\u4ecb\u7ecd\uff0c\u51c6\u5907Guestshell Python\u811a\u672c\uff0c\u914d\u7f6eHTTP\/TFTP Server\u548cDHCP Server\uff0c\u628aPython\u811a\u672c\uff0c\u5b89\u88c5\u955c\u50cf\u548c\u914d\u7f6e\u6587\u4ef6\u90fd\u4e0a\u4f20\u5230HTTP\/TFTP Server\u3002<\/p>\n<p style=\"padding-top: 8px; padding-bottom: 8px; margin: 5px; line-height: 1.5; letter-spacing: 0.05em; font-size: 15px; word-spacing: 0em;\" data-tool=\"mdnice\u7f16\u8f91\u5668\">\u5bf9\u4e8e\u5e26\u5185\u7f51\u7ba1\u4e14\u7ba1\u7406VLAN ID\u4e0d\u4e3a1\u7684\u573a\u666f\uff0c\u9700\u8981\u5728\u6c47\u805a\u4ea4\u6362\u673a\u4e0a\u521b\u5efa\u4e00\u4e2aZTP\u4e13\u7528VLAN\u5e76\u914d\u7f6eNative VLAN\uff0cDHCP Relay\u6216DHCP Server\u3002\u76f8\u5e94\u5730\uff0c\u63a5\u5165\u4ea4\u6362\u673a\u7684Jinja\u914d\u7f6e\u6a21\u7248\u9700\u8981shutdown vlan1\u3002\u7136\u540e\u5c31\u53ef\u4ee5\u6267\u884cZTP\u90e8\u7f72\u4e86\u3002<\/p>\n<h4 style=\"margin-top: 30px; margin-bottom: 15px; font-weight: bold; font-size: 15px; color: #0e88eb;\" data-tool=\"mdnice\u7f16\u8f91\u5668\">5. \u590d\u6742\u573a\u666f\u7684\u6700\u4f73\u5b9e\u8df5<\/h4>\n<p style=\"padding-top: 8px; padding-bottom: 8px; margin: 5px; line-height: 1.5; letter-spacing: 0.05em; font-size: 15px; word-spacing: 0em;\" data-tool=\"mdnice\u7f16\u8f91\u5668\">\u5982\u679c\u60a8\u7684\u573a\u666f\u6bd4\u8f83\u590d\u6742\uff0c\u5efa\u8bae\u6309\u7167\u529f\u80fd\u5236\u4f5c\u591a\u4e2a\u53d8\u91cf\u8868\uff0c\u518d\u5408\u5e76\u751f\u6210\u914d\u7f6e\u6587\u4ef6\u3002\u53e6\u5916\uff0c\u5bf9\u4e8e\u8fd9\u79cd\u590d\u6742\u64cd\u4f5c\uff0c\u5efa\u8bae\u589e\u52a0\u914d\u7f6e\u6821\u9a8c\u7684\u6b65\u9aa4\u3002\u5177\u4f53\u7684\u64cd\u4f5c\u65b9\u6cd5\u53ef\u4ee5\u53c2\u8003\uff1a<\/p>\n<pre style=\"margin-top: 10px; margin-bottom: 10px; border-radius: 5px; box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;\" data-tool=\"mdnice\u7f16\u8f91\u5668\"><code style=\"overflow-x: auto; padding: 16px; color: #abb2bf; display: -webkit-box; font-family: Operator Mono, Consolas, Monaco, Menlo, monospace; font-size: 12px; -webkit-overflow-scrolling: touch; padding-top: 15px; background: #282c34; border-radius: 5px;\">git\u00a0clone\u00a0https:\/\/github.com\/Tes3awy\/Cisco-Configuration-Using-Python-Jinja-CSV.git\r\n<\/code><\/pre>\n<\/section>\n<p>&nbsp;<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u53f0\u7f51\u7edc\u8bbe\u5907\u4e0a\u7ebf\u4e4b\u540e\uff0c\u9700\u8981\u5148\u5b8c\u6210\u5927\u91cf\u7684\u914d\u7f6e\uff0c\u5b83\u624d\u80fd\u5f00\u59cb\u5de5\u4f5c\u3002\u901a\u5e38\u7684\u505a\u6cd5\u662f\uff0c\u5728\u8bbe\u5907\u4e0a\u7ebf\u4e4b\u524d\uff0c\u5148\u5b89\u6392\u51e0\u4f4d\u5de5\u7a0b\u5e08\uff0c\u627e [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8,2],"tags":[],"class_list":["post-10888","post","type-post","status-publish","format-standard","hentry","category-cisco","category-network"],"_links":{"self":[{"href":"https:\/\/www.xh86.me\/index.php?rest_route=\/wp\/v2\/posts\/10888","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xh86.me\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xh86.me\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xh86.me\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xh86.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10888"}],"version-history":[{"count":1,"href":"https:\/\/www.xh86.me\/index.php?rest_route=\/wp\/v2\/posts\/10888\/revisions"}],"predecessor-version":[{"id":10950,"href":"https:\/\/www.xh86.me\/index.php?rest_route=\/wp\/v2\/posts\/10888\/revisions\/10950"}],"wp:attachment":[{"href":"https:\/\/www.xh86.me\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10888"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xh86.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10888"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xh86.me\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10888"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}