{"id":328692,"date":"2022-01-27T21:00:08","date_gmt":"2022-01-27T21:00:08","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=328692"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=328692","title":{"rendered":"<span>\u041c\u043e\u0439 \u0434\u0440\u0443\u0433 Netmiko. \u0427\u0430\u0441\u0442\u044c 2: \u0422\u0440\u0438 \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u044f Python-\u0441\u043a\u0440\u0438\u043f\u0442\u0430<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u044e \u043a\u043e\u0432\u044b\u0440\u044f\u0442\u044c \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0430\u0446\u0438\u044e \u0440\u0443\u0442\u0438\u043d\u044b \u043d\u0430 \u0441\u0435\u0442\u0438 \u0438\u0437 Huawei \u043a\u043e\u043c\u043c\u0443\u0442\u0430\u0442\u043e\u0440\u043e\u0432. \u041d\u0430 \u044d\u0442\u043e\u0442 \u0440\u0430\u0437 \u0438\u0437\u044b\u0441\u043a\u0430\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u043b\u0438 \u0441\u043e\u043a\u0440\u0430\u0442\u0438\u0442\u044c \u043a\u043e\u0434 \u0432 3 \u0440\u0430\u0437\u0430, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e: \u0445\u043e\u0441\u0442\u044b \u0438 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u043f\u0435\u0440\u0435\u043d\u0435\u0441\u0435\u043d\u044b \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u0444\u0430\u0439\u043b\u044b, \u043f\u0430\u0440\u043e\u043b\u044c \u0438 \u0438\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0432 \u043e\u0442\u043a\u0440\u044b\u0442\u043e\u043c \u0442\u0435\u043a\u0441\u0442\u0435. \u0415\u0441\u0442\u044c <a href=\"https:\/\/forum.huawei.com\/enterprise\/ru\/forum.php?mod=viewthread&amp;tid=818375\">\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u044f<\/a> \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0441\u043a\u0440\u0438\u043f\u0442\u0430. <\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"\/img\/image-loader.svg\" height=\"800\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b45\/9c5\/733\/b459c57332f54302293c7fc12aced43e.gif\" data-width=\"1200\"\/><figcaption><\/figcaption><\/figure>\n<p>\u042f \u043b\u0443\u0447\u0448\u0435 \u0432\u043e\u0441\u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e \u0432\u0435\u0449\u0438 \u0432\u0438\u0437\u0443\u0430\u043b\u044c\u043d\u043e, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043b \u0437\u0430\u0434\u0430\u0447\u0443 \u043f\u043e \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u043a\u0440\u0438\u043f\u0442\u0430 \u0432 \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u0432\u0438\u0434\u0435 (\u0441\u043c. \u043d\u0438\u0436\u0435) &#8212; \u0430 \u0438\u043c\u0435\u043d\u043d\u043e \u043e\u0442\u0440\u0430\u0437\u0438\u043b \u0442\u0440\u0438 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u0437\u0430\u0434\u0430\u0447\u0438:<\/p>\n<p>1.\u00a0\u00a0\u00a0\u00a0 \u041f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c inventory \u0444\u0430\u0439\u043b, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0438\u0442\u044c ip-\u0430\u0434\u0440\u0435\u0441\u0430 \u0432\u0441\u0435\u0445 \u0441\u0435\u0442\u0435\u0432\u044b\u0445 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432, \u0430 \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0438\u0437 \u043d\u0438\u0445.<\/p>\n<p>2.\u00a0\u00a0\u00a0\u00a0 \u041f\u0435\u0440\u0435\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0444\u0430\u0439\u043b \u0438 \u0442\u0430\u043a \u0436\u0435, \u043a\u0430\u043a \u0438 inventory \u0444\u0430\u0439\u043b \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438.<\/p>\n<p>3.\u00a0\u00a0\u00a0\u00a0 \u0418\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043e\u0442 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043f\u0430\u0440\u043e\u043b\u044f \u0438 \u0438\u043c\u0435\u043d\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432 \u0441\u043a\u0440\u0438\u043f\u0442\u0435.<\/p>\n<p>\u042f \u0442\u0430\u043a\u0436\u0435 \u0443\u0431\u0440\u0430\u043b \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0432\u0435\u0440\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 (\u0418\u0445, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u043c\u043e\u0436\u043d\u043e \u0438 \u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c, \u0438 \u043e\u043d\u0438 \u0431\u0443\u0434\u0443\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0438\u0437 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430, \u043d\u043e \u0434\u043b\u044f \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0435\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u043e\u043d\u0438 \u043d\u0435 \u043d\u0443\u0436\u043d\u044b).<\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"\/img\/image-loader.svg\" height=\"1711\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/091\/50d\/2e5\/09150d2e5804ea1926b41dd216fd7926.png\" data-width=\"1306\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0412 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438 \u043a \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c\u0443 \u043f\u043e\u0441\u0442\u0443 <a href=\"https:\/\/habr.com\/ru\/company\/huawei\/blog\/594229\/\">\u00ab\u041c\u043e\u0439 \u0434\u0440\u0443\u0433 Netmiko\u00bb<\/a> \u043f\u043e\u044f\u0432\u0438\u043b\u0441\u044f \u0432\u043e\u043f\u0440\u043e\u0441 \u043e\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f <a href=\"https:\/\/habr.com\/ru\/company\/huawei\/blog\/594229\/comments\/#comment_23920403\">anders_i<\/a> \u043e \u0442\u043e\u043c, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u043e\u0436\u043d\u043e \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u043a\u0440\u0438\u043f\u0442:<\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"\/img\/image-loader.svg\" height=\"309\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/4c8\/856\/d74\/4c8856d74470591350353938220abc9a.png\" data-width=\"1531\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0422\u043e\u0433\u0434\u0430 \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b 4 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0445 CloudEngine Huawei \u0432 eNSP. \u041d\u0430 \u044d\u0442\u043e\u0442 \u0440\u0430\u0437 \u044f \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u043b \u0440\u0430\u0441\u0448\u0438\u0440\u0438\u0442\u044c \u0438\u0445 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043d\u0430\u0441\u0442\u043e\u043b\u044c\u043a\u043e, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0445\u0432\u0430\u0442\u0438\u0442 \u043c\u043e\u0449\u043d\u043e\u0441\u0442\u0438 Huawei MateBook X Pro 2021. <\/p>\n<p>\u0418 \u0440\u0430\u0441\u0448\u0438\u0440\u0438\u0442\u044c \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u0434\u043e 8-\u043c\u0438. 9-\u044b\u0439 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c\u0441\u044f \u043e\u0442\u043a\u0430\u0437\u0430\u043b\u0441\u044f, \u043e\u043a\u043a\u0443\u043f\u0430\u0446\u0438\u044f 16GB \u041e\u0417\u0423 \u0441\u043e\u0441\u0442\u0430\u0432\u0438\u043b\u0430 80%.<\/p>\n<p>\u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u0430\u044f \u0442\u043e\u043f\u043e\u043b\u043e\u0433\u0438\u044f \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"\/img\/image-loader.svg\" height=\"881\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b4f\/445\/40b\/b4f44540b7bb7e4c7784632c025a7786.png\" data-width=\"1486\"\/><figcaption><\/figcaption><\/figure>\n<p><strong>1.\u0421\u043e\u0437\u0434\u0430\u044e \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0439 \u0444\u0430\u0439\u043b<\/strong><\/p>\n<p>\u042f \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0438\u0442\u0430\u044e \u0440\u0435\u0434\u0430\u043a\u0442\u043e\u0440 Nano (\u043a\u0442\u043e-\u0442\u043e \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0438\u0442\u0430\u0435\u0442 Vim):<\/p>\n<p><strong>nano switch_file_config<\/strong><\/p>\n<p>\u0412 \u0444\u0430\u0439\u043b\u0435 \u043f\u0440\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e \u0432\u0441\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0438\u0437 \u043f\u0440\u043e\u0448\u043b\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430 (\u043a\u043e\u043c\u0430\u043d\u0434\u044b \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043b\u044e\u0431\u044b\u043c\u0438 \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043d\u0443\u0436\u0434) \u0431\u0435\u0437 \u043f\u0440\u043e\u0431\u0435\u043b\u043e\u0432\/\u043e\u0442\u0441\u0442\u0443\u043f\u043e\u0432. <strong>\u0412\u0430\u0436\u043d\u043e<\/strong> \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u0443 <strong>return<\/strong> \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439 \u0441\u0442\u0440\u043e\u043a\u043e\u0439. \u041a\u0430\u043a \u044f \u043f\u043e\u043d\u044f\u043b, \u0435\u0435 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430 \u2013 \u043f\u0440\u0438 \u043f\u0440\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u043d\u0438\u0438 \u043a\u043e\u043c\u0430\u043d\u0434 \u0432 \u0441\u0430\u043c\u043e\u043c \u0441\u043a\u0440\u0438\u043f\u043a\u0435 \u043c\u043e\u0434\u0443\u043b\u044c Netmiko \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0435\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442 \u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442 SSH-\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435. \u0411\u0435\u0437 <strong>return<\/strong> \u0441\u043a\u0440\u0438\u043f\u0442 \u043d\u0435 \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442.<\/p>\n<p>\u0421\u043f\u0438\u0441\u043e\u043a \u043a\u043e\u043c\u0430\u043d\u0434, \u043f\u0435\u0440\u0435\u043d\u0435\u0441\u0435\u043d\u043d\u044b\u0435 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0444\u0430\u0439\u043b:<\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"\/img\/image-loader.svg\" height=\"332\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/8c6\/dda\/7b9\/8c6dda7b9839d134b2bef1f3a2c2d6c9.png\" data-width=\"1262\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0432\u0435\u0441\u044c \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0439 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"python\">    for n in range (300,302):         print (\"Creating VLAN \" + str(n))         config_commands = [                           'vlan ' + str(n),                           'desc NETMIKO_VLAN ' + str(n),                           'Commit'         ]         output = ssh_connect.send_config_set(config_commands)      output = ssh_connect.send_config_set(         [         'interface range GE 1\/0\/9 GE 1\/0\/10',         'port trunk allow-pass vlan 300 301',         'commit'         ]     )<\/code><\/pre>\n<p>\u0421\u043e\u043a\u0440\u0430\u0449\u0430\u044e \u0434\u043e:<\/p>\n<pre><code class=\"python\">with open('switch_file_config') as f:     config_lines = f.read().splitlines() print (config_lines)<\/code><\/pre>\n<p>\u0438 \u043c\u0435\u043d\u044f\u044e \u0441\u0442\u0440\u043e\u0447\u043a\u0443:<\/p>\n<pre><code class=\"python\">    output = ssh_connect.send_config_set(config_lines)<\/code><\/pre>\n<p>Python \u0444\u0443\u043d\u043a\u0446\u0438\u044f <strong>open<\/strong> \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u0442 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0439 \u0444\u0430\u0439\u043b, \u0447\u0438\u0442\u0430\u0435\u0442 \u0435\u0433\u043e, \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u044f \u043d\u0430 \u043b\u0438\u043d\u0438\u0438 (\u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u0443\u044f) <strong>f.read().splitlines()<\/strong> \u0438 \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u043d\u0430 \u044d\u043a\u0440\u0430\u043d <strong>print(config_lines).<\/strong> \u041c\u043e\u0434\u0443\u043b\u044c Netmiko <strong>send_config_set<\/strong> \u0442\u0435\u043f\u0435\u0440\u044c \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f \u043a \u044d\u0442\u043e\u043c\u0443 \u0444\u0430\u0439\u043b\u0443 <strong>(config_lines)<\/strong>, \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0438\u0437 \u043d\u0435\u0433\u043e.<\/p>\n<p>\u00a0<\/p>\n<p><strong>2.\u0421\u043e\u0437\u0434\u0430\u044e inventory-\u0444\u0430\u0439\u043b \u0441 IP-\u0430\u0434\u0440\u0435\u0441\u0430\u043c\u0438 \u043a\u043e\u043c\u043c\u0443\u0442\u0430\u0442\u043e\u0440\u043e\u0432:<\/strong><\/p>\n<p>\u041d\u0430\u0447\u0438\u043d\u0430\u044e \u0441 \u0442\u043e\u0433\u043e \u0436\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0444\u0430\u0439\u043b\u0430 \u0432 \u0440\u0435\u0434\u0430\u043a\u0442\u043e\u0440\u0435 Nano:<\/p>\n<p><strong>nano myswitches<\/strong><\/p>\n<p>\u042d\u0442\u043e \u0444\u0430\u0439\u043b \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0441\u043f\u0438\u0441\u043e\u043a (list) IP-\u0430\u0434\u0440\u0435\u0441\u043e\u0432 \u043a\u043e\u043c\u043c\u0443\u0442\u0430\u0442\u043e\u0440\u043e\u0432:<\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"\/img\/image-loader.svg\" height=\"240\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/f17\/f93\/573\/f17f93573594af10023cc48a233881d2.png\" data-width=\"1234\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0417\u0434\u0435\u0441\u044c \u0433\u043b\u0430\u0432\u043d\u043e\u0435 &#8212; \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u043f\u0440\u043e\u0431\u0435\u043b\u043e\u0432. <\/p>\n<p>\u0421\u043e\u0445\u0440\u0430\u043d\u044f\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439 Ctr+X.<\/p>\n<p>\u0414\u043b\u044f \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u0442\u0435\u0441\u0442\u0430 \u044f \u0441\u043e\u0437\u0434\u0430\u043b python-\u0444\u0430\u0439\u043b, \u043d\u0430\u0437\u0432\u0430\u043b \u0435\u0433\u043e openfile.py.<\/p>\n<p>\u041f\u0440\u043e\u043f\u0438\u0441\u0430\u043b \u0432 \u043d\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0441\u043a\u0440\u0438\u043f\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0442\u044c \u0444\u0430\u0439\u043b \u0441 IP-\u0430\u0434\u0440\u0435\u0441\u0430\u043c\u0438 \u0438 \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c \u0438\u0445 \u043d\u0430 \u044d\u043a\u0440\u0430\u043d:<\/p>\n<pre><code class=\"python\">f = open ('myswitches')  for IP in f:     print (IP)<\/code><\/pre>\n<p>\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u043b \u0435\u0433\u043e:<\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"\/img\/image-loader.svg\" height=\"378\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/cdb\/963\/e2a\/cdb963e2a47d625d0a217953312aed81.png\" data-width=\"1055\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u043d\u043e, \u043f\u0435\u0440\u0432\u0430\u044f \u0441\u0442\u0440\u043e\u0447\u043a\u0430 \u043e\u0441\u0442\u0430\u043b\u0430\u0441\u044c \u043f\u0443\u0441\u0442\u043e\u0439, \u0430 \u0437\u043d\u0430\u0447\u0438\u0442 \u0434\u043b\u044f Python \u043e\u043d\u0430 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u043a\u0430\u043a [\u2018 \u2019,]. \u041f\u0440\u0438 \u043f\u043e\u043f\u044b\u0442\u043a\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0442\u0430\u043a\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430 Python \u0432\u044b\u0434\u0430\u0441\u0442 \u043e\u0448\u0438\u0431\u043a\u0443, \u0447\u0442\u043e \u043d\u0435 \u0441\u043c\u043e\u0433 \u0441\u0432\u044f\u0437\u0430\u0442\u044c\u0441\u044f \u0441 \u0430\u0434\u0440\u0435\u0441\u043e\u043c \u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0443\u0441\u0442\u044b\u0445 \u0441\u0442\u0440\u043e\u043a \u043b\u0443\u0447\u0448\u0435 \u043d\u0435 \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u0442\u044c.<\/p>\n<p>\u042f \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u043b \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 4 CE-\u043a\u043e\u043c\u043c\u0443\u0442\u0430\u0442\u043e\u0440\u0430 \u0432 eNSP, \u0434\u0430\u0432 \u0438\u043c IP-\u0430\u0434\u0440\u0435\u0441\u0430 \u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0432 SSH-\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435:<\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"\/img\/image-loader.svg\" height=\"317\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/31d\/23a\/c23\/31d23ac2373e172bfda8661532cd3ece.png\" data-width=\"1224\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0441\u043e\u043a\u0440\u0430\u0449\u0430\u044e \u0432\u0435\u0441\u044c \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0439 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"python\">CE_1_BORDER = {     'device_type': 'huawei',     'ip':   '7.7.7.1',     'username': 'vasyo1',     'password': '@ghjcnjnF358986' }  CE_2 = {     'device_type': 'huawei',     'ip':   '7.7.7.2',     'username': 'vasyo1',     'password': '@ghjcnjnF358986' }  CE_3 = {     'device_type': 'huawei',     'ip':   '7.7.7.3',     'username': 'vasyo1',     'password': '@ghjcnjnF358986'         }  CE_4 = {     'device_type': 'huawei',     'ip':   '7.7.7.4',     'username': 'vasyo1',     'password': '@ghjcnjnF358986' }  all_devices = [CE_1_BORDER, CE_2, CE_3, CE_4]  for device in all_devices:     ssh_connect = ConnectHandler(**device)<\/code><\/pre>\n<p>\u0414\u043e:<\/p>\n<pre><code class=\"python\">with open('myswitches') as f:     ip_lines = f.read().splitlines() print (ip_lines)  for device in ip_lines:     ip_address_of_device = device     CE = {         'device_type': 'huawei',         'ip':   ip_address_of_device,         'username': username,         'password': password     }      ssh_connect = ConnectHandler(**CE)     output = ssh_connect.send_config_set(config_lines)<\/code><\/pre>\n<p>\u0421 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441\u043e\u043c \u043e\u0442\u043a\u0440\u044b\u0442\u0438\u044f \u0444\u0430\u0439\u043b\u0430 \u0432\u0441\u0435 \u043f\u043e\u043d\u044f\u0442\u043d\u043e.<\/p>\n<p>\u0412 \u0441\u043b\u043e\u0432\u0430\u0440\u0435 Netmiko \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u043f\u0440\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e IP-\u0430\u0434\u0440\u0435\u0441. \u0412\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u043a\u043e\u0434 \u0431\u0443\u0434\u0435\u043c \u043e\u0431\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f \u0437\u0430 IP-\u0430\u0434\u0440\u0435\u0441\u0430\u043c\u0438 \u043a \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 <strong>ip_address_of_device<\/strong>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0440\u0430\u0432\u043d\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 <strong>device<\/strong>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0447\u0430\u0441\u0442\u044c\u044e \u0446\u0438\u043a\u043b\u0430 (loop)<strong> for<\/strong>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0447\u0438\u0442\u0430\u0435\u0442 <strong>ip_lines<\/strong>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0435\u0439 IP-\u0430\u0434\u0440\u0435\u0441\u0430 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432 \u0432 \u0444\u0430\u0439\u043b\u0435 <strong>\u00abmyswitches\u00bb.<\/strong><\/p>\n<p><strong>3.\u0423\u0434\u0430\u043b\u044f\u044e \u043f\u0430\u0440\u043e\u043b\u044c \u0438 \u0438\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438\u0437 \u0441\u043a\u0440\u0438\u043f\u0442\u0430<\/strong><\/p>\n<p>\u041d\u0435\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0438\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438 \u043f\u0430\u0440\u043e\u043b\u044c, \u0447\u0442\u043e \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f, clear text:<\/p>\n<pre><code class=\"python\">    CE = {         'device_type': 'huawei',         'ip':   ip_address_of_device,         'username': 'vasyo1',         'password': '@ghjcnjnF358986'     }<\/code><\/pre>\n<p>\u0412\u0440\u044f\u0434 \u043b\u0438 \u0432 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438 \u0442\u0430\u043a\u043e\u0435 \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u043e.<\/p>\n<p>\u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u0443\u0434\u0430\u043b\u044e \u0438\u0445 \u0438\u0437 \u0441\u043a\u0440\u0438\u043f\u0442\u0430, \u0437\u0430\u043c\u0435\u043d\u0438\u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c\u0438: \u043f\u0435\u0440\u0435\u0434\u0435\u043b\u0430\u044e \u0441\u043a\u0440\u0438\u043f\u0442 \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u0441\u043a\u0440\u0438\u043f\u0442 \u0432\u044b\u0432\u0435\u043b \u043d\u0430 \u044d\u043a\u0440\u0430\u043d \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0432\u0432\u043e\u0434\u0430 \u0438\u043c\u0435\u043d\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0430 \u043f\u043e\u0441\u043b\u0435 \u0432\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043b \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e <strong>input()<\/strong>. \u0424\u0443\u043d\u043a\u0446\u0438\u044f <strong>input() <\/strong>\u0434\u043b\u044f \u0432\u0435\u0440\u0441\u0438\u0438 Python 2.x \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f <strong>raw_input().<\/strong><\/p>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044e \u00a0<strong>getpass()<\/strong> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u0434\u043b\u044f \u0432\u0432\u043e\u0434\u0430 \u043f\u0430\u0440\u043e\u043b\u044f.<\/p>\n<pre><code class=\"python\">username = input('Enter your SSH username: ') password = getpass()<\/code><\/pre>\n<p>\u0412 \u0441\u043b\u043e\u0432\u0430\u0440\u0435 \u0438\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438 \u043f\u0430\u0440\u043e\u043b\u044c \u0437\u0430\u043c\u0435\u043d\u044f\u044e \u043d\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435:<\/p>\n<pre><code class=\"python\">    CE = {         'device_type': 'huawei',         'ip':   ip_address_of_device,         'username': username,         'password': password     }<\/code><\/pre>\n<p>\u0412 \u0438\u0442\u043e\u0433\u0435 \u044f \u043f\u043e\u043b\u0443\u0447\u0438\u043b \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u043d\u044b\u0439 \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u043a\u0440\u0430\u0442\u0438\u043b\u0441\u044f \u0441 63 \u0441\u0442\u0440\u043e\u043a \u0434\u043e 28 \u0438 \u0441\u0442\u0430\u043b \u0431\u043e\u043b\u0435\u0435 \u0430\u0434\u0430\u043f\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c \u0434\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0439 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0439 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435. \u0412\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043e\u043d \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043e\u0431\u0440\u0430\u0437\u043e\u043c (\u0437\u0430\u043f\u0443\u0441\u043a \u0441\u043a\u0440\u0438\u043f\u0442\u0430 \u043d\u0430 \u0432\u0438\u0434\u0435\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c <a href=\"https:\/\/forum.huawei.com\/enterprise\/ru\/forum.php?mod=viewthread&amp;tid=818375\">\u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435<\/a> Huawei \u0424\u043e\u0440\u0443\u043c\u0430 ICT Club):<\/p>\n<pre><code class=\"python\">from getpass import getpass from netmiko import ConnectHandler  username = input('Enter your SSH username: ') password = getpass()  with open('switch_file_config') as f:     config_lines = f.read().splitlines() print (config_lines)  with open('myswitches') as f:     ip_lines = f.read().splitlines() print (ip_lines)  for device in ip_lines:     ip_address_of_device = device     CE = {         'device_type': 'huawei',         'ip':   ip_address_of_device,         'username': username,         'password': password     }      ssh_connect = ConnectHandler(**CE)     output = ssh_connect.send_config_set(config_lines)     print(f\"\\n\\n-------------- CE_{CE['ip']} --------------\")     print(output)     print(\"-------------------- End -------------------\")<\/code><\/pre>\n<p>\u041b\u0438\u0442\u0435\u0440\u0430\u0442\u0443\u0440\u0430:<\/p>\n<p><a href=\"https:\/\/stackoverflow.com\/questions\/5563089\/raw-input-function-in-python\">https:\/\/stackoverflow.com\/questions\/5563089\/raw-input-function-in-python<\/a><\/p>\n<p><a href=\"https:\/\/pynet.twb-tech.com\/blog\/automation\/netmiko.html\">https:\/\/pynet.twb-tech.com\/blog\/automation\/netmiko.html<\/a><\/p>\n<p><a href=\"https:\/\/pyneng.readthedocs.io\/en\/latest\/book\/18_ssh_telnet\/netmiko.html\">https:\/\/pyneng.readthedocs.io\/en\/latest\/book\/18_ssh_telnet\/netmiko.html<\/a><\/p>\n<p><a href=\"https:\/\/github.com\/ktbyers\/netmiko\">https:\/\/github.com\/ktbyers\/netmiko<\/a><\/p>\n<p><a href=\"https:\/\/github.com\/ktbyers\/netmiko\/blob\/master\/netmiko\/ssh_dispatcher.py\">https:\/\/github.com\/ktbyers\/netmiko\/blob\/master\/netmiko\/ssh_dispatcher.py<\/a><\/p>\n<p>Udemy.com &#8212; Python Network Programming for Network Engineers (Python 3) (David Bombal)<\/p>\n<p><a href=\"https:\/\/www.pythoncentral.io\/pythons-range-function-explained\/\">https:\/\/www.pythoncentral.io\/pythons-range-function-explained<\/a><\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/company\/huawei\/blog\/648127\/\"> https:\/\/habr.com\/ru\/company\/huawei\/blog\/648127\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u044e \u043a\u043e\u0432\u044b\u0440\u044f\u0442\u044c \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0430\u0446\u0438\u044e \u0440\u0443\u0442\u0438\u043d\u044b \u043d\u0430 \u0441\u0435\u0442\u0438 \u0438\u0437 Huawei \u043a\u043e\u043c\u043c\u0443\u0442\u0430\u0442\u043e\u0440\u043e\u0432. \u041d\u0430 \u044d\u0442\u043e\u0442 \u0440\u0430\u0437 \u0438\u0437\u044b\u0441\u043a\u0430\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u043b\u0438 \u0441\u043e\u043a\u0440\u0430\u0442\u0438\u0442\u044c \u043a\u043e\u0434 \u0432 3 \u0440\u0430\u0437\u0430, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e: \u0445\u043e\u0441\u0442\u044b \u0438 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u043f\u0435\u0440\u0435\u043d\u0435\u0441\u0435\u043d\u044b \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u0444\u0430\u0439\u043b\u044b, \u043f\u0430\u0440\u043e\u043b\u044c \u0438 \u0438\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0432 \u043e\u0442\u043a\u0440\u044b\u0442\u043e\u043c \u0442\u0435\u043a\u0441\u0442\u0435. \u0415\u0441\u0442\u044c <a href=\"https:\/\/forum.huawei.com\/enterprise\/ru\/forum.php?mod=viewthread&amp;tid=818375\">\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u044f<\/a> \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0441\u043a\u0440\u0438\u043f\u0442\u0430. <\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u042f \u043b\u0443\u0447\u0448\u0435 \u0432\u043e\u0441\u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e \u0432\u0435\u0449\u0438 \u0432\u0438\u0437\u0443\u0430\u043b\u044c\u043d\u043e, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043b \u0437\u0430\u0434\u0430\u0447\u0443 \u043f\u043e \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u043a\u0440\u0438\u043f\u0442\u0430 \u0432 \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u0432\u0438\u0434\u0435 (\u0441\u043c. \u043d\u0438\u0436\u0435) &#8212; \u0430 \u0438\u043c\u0435\u043d\u043d\u043e \u043e\u0442\u0440\u0430\u0437\u0438\u043b \u0442\u0440\u0438 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u0437\u0430\u0434\u0430\u0447\u0438:<\/p>\n<p>1.\u00a0\u00a0\u00a0\u00a0 \u041f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c inventory \u0444\u0430\u0439\u043b, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0438\u0442\u044c ip-\u0430\u0434\u0440\u0435\u0441\u0430 \u0432\u0441\u0435\u0445 \u0441\u0435\u0442\u0435\u0432\u044b\u0445 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432, \u0430 \u043d\u0435 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0438\u0437 \u043d\u0438\u0445.<\/p>\n<p>2.\u00a0\u00a0\u00a0\u00a0 \u041f\u0435\u0440\u0435\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0444\u0430\u0439\u043b \u0438 \u0442\u0430\u043a \u0436\u0435, \u043a\u0430\u043a \u0438 inventory \u0444\u0430\u0439\u043b \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u0438.<\/p>\n<p>3.\u00a0\u00a0\u00a0\u00a0 \u0418\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043e\u0442 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043f\u0430\u0440\u043e\u043b\u044f \u0438 \u0438\u043c\u0435\u043d\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432 \u0441\u043a\u0440\u0438\u043f\u0442\u0435.<\/p>\n<p>\u042f \u0442\u0430\u043a\u0436\u0435 \u0443\u0431\u0440\u0430\u043b \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0432\u0435\u0440\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 (\u0418\u0445, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u043c\u043e\u0436\u043d\u043e \u0438 \u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c, \u0438 \u043e\u043d\u0438 \u0431\u0443\u0434\u0443\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0438\u0437 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430, \u043d\u043e \u0434\u043b\u044f \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0435\u0439 \u0437\u0430\u0434\u0430\u0447\u0438 \u043e\u043d\u0438 \u043d\u0435 \u043d\u0443\u0436\u043d\u044b).<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0412 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438 \u043a \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c\u0443 \u043f\u043e\u0441\u0442\u0443 <a href=\"https:\/\/habr.com\/ru\/company\/huawei\/blog\/594229\/\">\u00ab\u041c\u043e\u0439 \u0434\u0440\u0443\u0433 Netmiko\u00bb<\/a> \u043f\u043e\u044f\u0432\u0438\u043b\u0441\u044f \u0432\u043e\u043f\u0440\u043e\u0441 \u043e\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f <a href=\"https:\/\/habr.com\/ru\/company\/huawei\/blog\/594229\/comments\/#comment_23920403\">anders_i<\/a> \u043e \u0442\u043e\u043c, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u043e\u0436\u043d\u043e \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u043a\u0440\u0438\u043f\u0442:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0422\u043e\u0433\u0434\u0430 \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b 4 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0445 CloudEngine Huawei \u0432 eNSP. \u041d\u0430 \u044d\u0442\u043e\u0442 \u0440\u0430\u0437 \u044f \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u043b \u0440\u0430\u0441\u0448\u0438\u0440\u0438\u0442\u044c \u0438\u0445 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043d\u0430\u0441\u0442\u043e\u043b\u044c\u043a\u043e, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0445\u0432\u0430\u0442\u0438\u0442 \u043c\u043e\u0449\u043d\u043e\u0441\u0442\u0438 Huawei MateBook X Pro 2021. <\/p>\n<p>\u0418 \u0440\u0430\u0441\u0448\u0438\u0440\u0438\u0442\u044c \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u0434\u043e 8-\u043c\u0438. 9-\u044b\u0439 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c\u0441\u044f \u043e\u0442\u043a\u0430\u0437\u0430\u043b\u0441\u044f, \u043e\u043a\u043a\u0443\u043f\u0430\u0446\u0438\u044f 16GB \u041e\u0417\u0423 \u0441\u043e\u0441\u0442\u0430\u0432\u0438\u043b\u0430 80%.<\/p>\n<p>\u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u0430\u044f \u0442\u043e\u043f\u043e\u043b\u043e\u0433\u0438\u044f \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p><strong>1.\u0421\u043e\u0437\u0434\u0430\u044e \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0439 \u0444\u0430\u0439\u043b<\/strong><\/p>\n<p>\u042f \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0438\u0442\u0430\u044e \u0440\u0435\u0434\u0430\u043a\u0442\u043e\u0440 Nano (\u043a\u0442\u043e-\u0442\u043e \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0438\u0442\u0430\u0435\u0442 Vim):<\/p>\n<p><strong>nano switch_file_config<\/strong><\/p>\n<p>\u0412 \u0444\u0430\u0439\u043b\u0435 \u043f\u0440\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e \u0432\u0441\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0438\u0437 \u043f\u0440\u043e\u0448\u043b\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430 (\u043a\u043e\u043c\u0430\u043d\u0434\u044b \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043b\u044e\u0431\u044b\u043c\u0438 \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043d\u0443\u0436\u0434) \u0431\u0435\u0437 \u043f\u0440\u043e\u0431\u0435\u043b\u043e\u0432\/\u043e\u0442\u0441\u0442\u0443\u043f\u043e\u0432. <strong>\u0412\u0430\u0436\u043d\u043e<\/strong> \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u0443 <strong>return<\/strong> \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0439 \u0441\u0442\u0440\u043e\u043a\u043e\u0439. \u041a\u0430\u043a \u044f \u043f\u043e\u043d\u044f\u043b, \u0435\u0435 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430 \u2013 \u043f\u0440\u0438 \u043f\u0440\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u043d\u0438\u0438 \u043a\u043e\u043c\u0430\u043d\u0434 \u0432 \u0441\u0430\u043c\u043e\u043c \u0441\u043a\u0440\u0438\u043f\u043a\u0435 \u043c\u043e\u0434\u0443\u043b\u044c Netmiko \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0435\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442 \u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442 SSH-\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435. \u0411\u0435\u0437 <strong>return<\/strong> \u0441\u043a\u0440\u0438\u043f\u0442 \u043d\u0435 \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442.<\/p>\n<p>\u0421\u043f\u0438\u0441\u043e\u043a \u043a\u043e\u043c\u0430\u043d\u0434, \u043f\u0435\u0440\u0435\u043d\u0435\u0441\u0435\u043d\u043d\u044b\u0435 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0444\u0430\u0439\u043b:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0432\u0435\u0441\u044c \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0439 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"python\">    for n in range (300,302):         print (\"Creating VLAN \" + str(n))         config_commands = [                           'vlan ' + str(n),                           'desc NETMIKO_VLAN ' + str(n),                           'Commit'         ]         output = ssh_connect.send_config_set(config_commands)      output = ssh_connect.send_config_set(         [         'interface range GE 1\/0\/9 GE 1\/0\/10',         'port trunk allow-pass vlan 300 301',         'commit'         ]     )<\/code><\/pre>\n<p>\u0421\u043e\u043a\u0440\u0430\u0449\u0430\u044e \u0434\u043e:<\/p>\n<pre><code class=\"python\">with open('switch_file_config') as f:     config_lines = f.read().splitlines() print (config_lines)<\/code><\/pre>\n<p>\u0438 \u043c\u0435\u043d\u044f\u044e \u0441\u0442\u0440\u043e\u0447\u043a\u0443:<\/p>\n<pre><code class=\"python\">    output = ssh_connect.send_config_set(config_lines)<\/code><\/pre>\n<p>Python \u0444\u0443\u043d\u043a\u0446\u0438\u044f <strong>open<\/strong> \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u0442 \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0439 \u0444\u0430\u0439\u043b, \u0447\u0438\u0442\u0430\u0435\u0442 \u0435\u0433\u043e, \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u044f \u043d\u0430 \u043b\u0438\u043d\u0438\u0438 (\u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u0443\u044f) <strong>f.read().splitlines()<\/strong> \u0438 \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u043d\u0430 \u044d\u043a\u0440\u0430\u043d <strong>print(config_lines).<\/strong> \u041c\u043e\u0434\u0443\u043b\u044c Netmiko <strong>send_config_set<\/strong> \u0442\u0435\u043f\u0435\u0440\u044c \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f \u043a \u044d\u0442\u043e\u043c\u0443 \u0444\u0430\u0439\u043b\u0443 <strong>(config_lines)<\/strong>, \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0438\u0437 \u043d\u0435\u0433\u043e.<\/p>\n<p>\u00a0<\/p>\n<p><strong>2.\u0421\u043e\u0437\u0434\u0430\u044e inventory-\u0444\u0430\u0439\u043b \u0441 IP-\u0430\u0434\u0440\u0435\u0441\u0430\u043c\u0438 \u043a\u043e\u043c\u043c\u0443\u0442\u0430\u0442\u043e\u0440\u043e\u0432:<\/strong><\/p>\n<p>\u041d\u0430\u0447\u0438\u043d\u0430\u044e \u0441 \u0442\u043e\u0433\u043e \u0436\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0444\u0430\u0439\u043b\u0430 \u0432 \u0440\u0435\u0434\u0430\u043a\u0442\u043e\u0440\u0435 Nano:<\/p>\n<p><strong>nano myswitches<\/strong><\/p>\n<p>\u042d\u0442\u043e \u0444\u0430\u0439\u043b \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0441\u043f\u0438\u0441\u043e\u043a (list) IP-\u0430\u0434\u0440\u0435\u0441\u043e\u0432 \u043a\u043e\u043c\u043c\u0443\u0442\u0430\u0442\u043e\u0440\u043e\u0432:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0417\u0434\u0435\u0441\u044c \u0433\u043b\u0430\u0432\u043d\u043e\u0435 &#8212; \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u043f\u0440\u043e\u0431\u0435\u043b\u043e\u0432. <\/p>\n<p>\u0421\u043e\u0445\u0440\u0430\u043d\u044f\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439 Ctr+X.<\/p>\n<p>\u0414\u043b\u044f \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u0442\u0435\u0441\u0442\u0430 \u044f \u0441\u043e\u0437\u0434\u0430\u043b python-\u0444\u0430\u0439\u043b, \u043d\u0430\u0437\u0432\u0430\u043b \u0435\u0433\u043e openfile.py.<\/p>\n<p>\u041f\u0440\u043e\u043f\u0438\u0441\u0430\u043b \u0432 \u043d\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0441\u043a\u0440\u0438\u043f\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0442\u044c \u0444\u0430\u0439\u043b \u0441 IP-\u0430\u0434\u0440\u0435\u0441\u0430\u043c\u0438 \u0438 \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c \u0438\u0445 \u043d\u0430 \u044d\u043a\u0440\u0430\u043d:<\/p>\n<pre><code class=\"python\">f = open ('myswitches')  for IP in f:     print (IP)<\/code><\/pre>\n<p>\u0417\u0430\u043f\u0443\u0441\u0442\u0438\u043b \u0435\u0433\u043e:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u043d\u043e, \u043f\u0435\u0440\u0432\u0430\u044f \u0441\u0442\u0440\u043e\u0447\u043a\u0430 \u043e\u0441\u0442\u0430\u043b\u0430\u0441\u044c \u043f\u0443\u0441\u0442\u043e\u0439, \u0430 \u0437\u043d\u0430\u0447\u0438\u0442 \u0434\u043b\u044f Python \u043e\u043d\u0430 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u043a\u0430\u043a [\u2018 \u2019,]. \u041f\u0440\u0438 \u043f\u043e\u043f\u044b\u0442\u043a\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0442\u0430\u043a\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430 Python \u0432\u044b\u0434\u0430\u0441\u0442 \u043e\u0448\u0438\u0431\u043a\u0443, \u0447\u0442\u043e \u043d\u0435 \u0441\u043c\u043e\u0433 \u0441\u0432\u044f\u0437\u0430\u0442\u044c\u0441\u044f \u0441 \u0430\u0434\u0440\u0435\u0441\u043e\u043c \u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0443\u0441\u0442\u044b\u0445 \u0441\u0442\u0440\u043e\u043a \u043b\u0443\u0447\u0448\u0435 \u043d\u0435 \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u0442\u044c.<\/p>\n<p>\u042f \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u043b \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 4 CE-\u043a\u043e\u043c\u043c\u0443\u0442\u0430\u0442\u043e\u0440\u0430 \u0432 eNSP, \u0434\u0430\u0432 \u0438\u043c IP-\u0430\u0434\u0440\u0435\u0441\u0430 \u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0432 SSH-\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0441\u043e\u043a\u0440\u0430\u0449\u0430\u044e \u0432\u0435\u0441\u044c \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0439 \u043a\u043e\u0434:<\/p>\n<pre><code class=\"python\">CE_1_BORDER = {     'device_type': 'huawei',     'ip':   '7.7.7.1',     'username': 'vasyo1',     'password': '@ghjcnjnF358986' }  CE_2 = {     'device_type': 'huawei',     'ip':   '7.7.7.2',     'username': 'vasyo1',     'password': '@ghjcnjnF358986' }  CE_3 = {     'device_type': 'huawei',     'ip':   '7.7.7.3',     'username': 'vasyo1',     'password': '@ghjcnjnF358986'         }  CE_4 = {     'device_type': 'huawei',     'ip':   '7.7.7.4',     'username': 'vasyo1',     'password': '@ghjcnjnF358986' }  all_devices = [CE_1_BORDER, CE_2, CE_3, CE_4]  for device in all_devices:     ssh_connect = ConnectHandler(**device)<\/code><\/pre>\n<p>\u0414\u043e:<\/p>\n<pre><code class=\"python\">with open('myswitches') as f:     ip_lines = f.read().splitlines() print (ip_lines)  for device in ip_lines:     ip_address_of_device = device     CE = {         'device_type': 'huawei',         'ip':   ip_address_of_device,         'username': username,         'password': password     }      ssh_connect = ConnectHandler(**CE)     output = ssh_connect.send_config_set(config_lines)<\/code><\/pre>\n<p>\u0421 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441\u043e\u043c \u043e\u0442\u043a\u0440\u044b\u0442\u0438\u044f \u0444\u0430\u0439\u043b\u0430 \u0432\u0441\u0435 \u043f\u043e\u043d\u044f\u0442\u043d\u043e.<\/p>\n<p>\u0412 \u0441\u043b\u043e\u0432\u0430\u0440\u0435 Netmiko \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u043f\u0440\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e IP-\u0430\u0434\u0440\u0435\u0441. \u0412\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u043a\u043e\u0434 \u0431\u0443\u0434\u0435\u043c \u043e\u0431\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f \u0437\u0430 IP-\u0430\u0434\u0440\u0435\u0441\u0430\u043c\u0438 \u043a \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 <strong>ip_address_of_device<\/strong>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0440\u0430\u0432\u043d\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 <strong>device<\/strong>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0447\u0430\u0441\u0442\u044c\u044e \u0446\u0438\u043a\u043b\u0430 (loop)<strong> for<\/strong>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0447\u0438\u0442\u0430\u0435\u0442 <strong>ip_lines<\/strong>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0435\u0439 IP-\u0430\u0434\u0440\u0435\u0441\u0430 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432 \u0432 \u0444\u0430\u0439\u043b\u0435 <strong>\u00abmyswitches\u00bb.<\/strong><\/p>\n<p><strong>3.\u0423\u0434\u0430\u043b\u044f\u044e \u043f\u0430\u0440\u043e\u043b\u044c \u0438 \u0438\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438\u0437 \u0441\u043a\u0440\u0438\u043f\u0442\u0430<\/strong><\/p>\n<p>\u041d\u0435\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0438\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438 \u043f\u0430\u0440\u043e\u043b\u044c, \u0447\u0442\u043e \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f, clear text:<\/p>\n<pre><code class=\"python\">    CE = {         'device_type': 'huawei',         'ip':   ip_address_of_device,         'username': 'vasyo1',         'password': '@ghjcnjnF358986'     }<\/code><\/pre>\n<p>\u0412\u0440\u044f\u0434 \u043b\u0438 \u0432 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0439 \u0441\u0435\u0442\u0438 \u0442\u0430\u043a\u043e\u0435 \u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c\u043e.<\/p>\n<p>\u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u0443\u0434\u0430\u043b\u044e \u0438\u0445 \u0438\u0437 \u0441\u043a\u0440\u0438\u043f\u0442\u0430, \u0437\u0430\u043c\u0435\u043d\u0438\u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c\u0438: \u043f\u0435\u0440\u0435\u0434\u0435\u043b\u0430\u044e \u0441\u043a\u0440\u0438\u043f\u0442 \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u0441\u043a\u0440\u0438\u043f\u0442 \u0432\u044b\u0432\u0435\u043b \u043d\u0430 \u044d\u043a\u0440\u0430\u043d \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0432\u0432\u043e\u0434\u0430 \u0438\u043c\u0435\u043d\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0430 \u043f\u043e\u0441\u043b\u0435 \u0432\u0432\u0435\u0434\u0435\u043d\u043d\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043b \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e <strong>input()<\/strong>. \u0424\u0443\u043d\u043a\u0446\u0438\u044f <strong>input() <\/strong>\u0434\u043b\u044f \u0432\u0435\u0440\u0441\u0438\u0438 Python 2.x \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f <strong>raw_input().<\/strong><\/p>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044e \u00a0<strong>getpass()<\/strong> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u0434\u043b\u044f \u0432\u0432\u043e\u0434\u0430 \u043f\u0430\u0440\u043e\u043b\u044f.<\/p>\n<pre><code class=\"python\">username = input('Enter your SSH username: ') password = getpass()<\/code><\/pre>\n<p>\u0412 \u0441\u043b\u043e\u0432\u0430\u0440\u0435 \u0438\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438 \u043f\u0430\u0440\u043e\u043b\u044c \u0437\u0430\u043c\u0435\u043d\u044f\u044e \u043d\u0430 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435:<\/p>\n<pre><code class=\"python\">    CE = {         'device_type': 'huawei',         'ip':   ip_address_of_device,         'username': username,         'password': password     }<\/code><\/pre>\n<p>\u0412 \u0438\u0442\u043e\u0433\u0435 \u044f \u043f\u043e\u043b\u0443\u0447\u0438\u043b \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u043d\u044b\u0439 \u043a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u043a\u0440\u0430\u0442\u0438\u043b\u0441\u044f \u0441 63 \u0441\u0442\u0440\u043e\u043a \u0434\u043e 28 \u0438 \u0441\u0442\u0430\u043b \u0431\u043e\u043b\u0435\u0435 \u0430\u0434\u0430\u043f\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c \u0434\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0439 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0439 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435. \u0412\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043e\u043d \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043e\u0431\u0440\u0430\u0437\u043e\u043c (\u0437\u0430\u043f\u0443\u0441\u043a \u0441\u043a\u0440\u0438\u043f\u0442\u0430 \u043d\u0430 \u0432\u0438\u0434\u0435\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c <a href=\"https:\/\/forum.huawei.com\/enterprise\/ru\/forum.php?mod=viewthread&amp;tid=818375\">\u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435<\/a> Huawei \u0424\u043e\u0440\u0443\u043c\u0430 ICT Club):<\/p>\n<pre><code class=\"python\">from getpass import getpass from netmiko import ConnectHandler  username = input('Enter your SSH username: ') password = getpass()  with open('switch_file_config') as f:     config_lines = f.read().splitlines() print (config_lines)  with open('myswitches') as f:     ip_lines = f.read().splitlines() print (ip_lines)  for device in ip_lines:     ip_address_of_device = device     CE = {         'device_type': 'huawei',         'ip':   ip_address_of_device,         'username': username,         'password': password     }      ssh_connect = ConnectHandler(**CE)     output = ssh_connect.send_config_set(config_lines)     print(f\"\\n\\n-------------- CE_{CE['ip']} --------------\")     print(output)     print(\"-------------------- End -------------------\")<\/code><\/pre>\n<p>\u041b\u0438\u0442\u0435\u0440\u0430\u0442\u0443\u0440\u0430:<\/p>\n<p><a href=\"https:\/\/stackoverflow.com\/questions\/5563089\/raw-input-function-in-python\">https:\/\/stackoverflow.com\/questions\/5563089\/raw-input-function-in-python<\/a><\/p>\n<p><a href=\"https:\/\/pynet.twb-tech.com\/blog\/automation\/netmiko.html\">https:\/\/pynet.twb-tech.com\/blog\/automation\/netmiko.html<\/a><\/p>\n<p><a href=\"https:\/\/pyneng.readthedocs.io\/en\/latest\/book\/18_ssh_telnet\/netmiko.html\">https:\/\/pyneng.readthedocs.io\/en\/latest\/book\/18_ssh_telnet\/netmiko.html<\/a><\/p>\n<p><a href=\"https:\/\/github.com\/ktbyers\/netmiko\">https:\/\/github.com\/ktbyers\/netmiko<\/a><\/p>\n<p><a href=\"https:\/\/github.com\/ktbyers\/netmiko\/blob\/master\/netmiko\/ssh_dispatcher.py\">https:\/\/github.com\/ktbyers\/netmiko\/blob\/master\/netmiko\/ssh_dispatcher.py<\/a><\/p>\n<p>Udemy.com &#8212; Python Network Programming for Network Engineers (Python 3) (David Bombal)<\/p>\n<p><a href=\"https:\/\/www.pythoncentral.io\/pythons-range-function-explained\/\">https:\/\/www.pythoncentral.io\/pythons-range-function-explained<\/a><\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/company\/huawei\/blog\/648127\/\"> https:\/\/habr.com\/ru\/company\/huawei\/blog\/648127\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-328692","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/328692","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=328692"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/328692\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=328692"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=328692"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=328692"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}