用于Nornir的PyEZs库和插件

nornir-pyez的Python项目详细描述


用于Nornir的PyEZ插件

插件

连接-Pyez

说明

这个插件用于利用Juniper的PyEZ和Nornir框架的强大功能,提供更快、更稳定的网络服务交付,同时简化和抽象网络库存

安装

pip install nornir-pyez==0.0.9

更新

^{pr2}$

阅读文档

https://nornir-pyez.readthedocs.io/en/latest/

用法

皮兹得到事实:

from nornir_pyez.plugins.tasks import pyez_facts
import os
from nornir import InitNornir
from nornir_utils.plugins.functions import print_result
from rich import print

script_dir = os.path.dirname(os.path.realpath(__file__))


nr = InitNornir(config_file=f"{script_dir}/config.yml")

response = nr.run(
    pyez_facts
)

# response is an AggregatedResult, which behaves like a list
# there is a response object for each device in inventory
devices = []
for dev in response:
    print(response[dev].result)

PyEZ获取配置

from nornir_pyez.plugins.tasks import pyez_get_config
import os
from nornir import InitNornir
from nornir_utils.plugins.functions import print_result
from rich import print

script_dir = os.path.dirname(os.path.realpath(__file__))


nr = InitNornir(config_file=f"{script_dir}/config.yml")

response = nr.run(
    task=pyez_get_config
)

# response is an AggregatedResult, which behaves like a list
# there is a response object for each device in inventory
devices = []
for dev in response:
    print(response[dev].result)

使用参数获取配置

from nornir_pyez.plugins.tasks import pyez_get_config
import os
from nornir import InitNornir
from nornir_utils.plugins.functions import print_result
from rich import print

script_dir = os.path.dirname(os.path.realpath(__file__))


nr = InitNornir(config_file=f"{script_dir}/config.yml")

xpath = 'interfaces/interface'
xml = '<interfaces></interfaces>'
database = 'committed'

response = nr.run(
    task=pyez_get_config, filter_xml=xpath, database=database
)

# response is an AggregatedResult, which behaves like a list
# there is a response object for each device in inventory
devices = []
for dev in response:
    print(response[dev].result)

设置文本配置

from nornir_pyez.plugins.tasks import pyez_config
import os
from nornir import InitNornir
from nornir_utils.plugins.functions import print_result
from rich import print

script_dir = os.path.dirname(os.path.realpath(__file__))


nr = InitNornir(config_file=f"{script_dir}/config.yml")

payload = """interfaces {
    lo0 {
        unit 0 {
            family inet {
                address 3.3.3.3/32;
            }
        }
    }
}
"""

response = nr.run(
    task=pyez_config, payload=payload
)

# response is an AggregatedResult, which behaves like a list
# there is a response object for each device in inventory
devices = []
for dev in response:
    print(response[dev].result)

使用XML执行Replace-Config操作的完整测试

from nornir_pyez.plugins.tasks import pyez_config, pyez_diff, pyez_commit
import os
from nornir import InitNornir
from nornir_utils.plugins.functions import print_result
from rich import print

script_dir = os.path.dirname(os.path.realpath(__file__))


nr = InitNornir(config_file=f"{script_dir}/config.yml")

xml_payload = """
<configuration>
          <interfaces>
                   <interface>
                    <name>lo0</name>
                    <unit>
                        <name>0</name>
                        <family operation="replace">
                            <inet>
                                <address>
                                    <name>3.3.3.4/32</name>
                                </address>
                            </inet>
                        </family>
                    </unit>
                </interface>
            </interfaces>
</configuration>
"""


def mega_runner(task):
    send_result = task.run(
        task=pyez_config, payload=xml_payload, data_format='xml')
    if send_result:
        diff_result = task.run(task=pyez_diff)
        if diff_result:
            task.run(task=pyez_commit)


response = nr.run(task=mega_runner)
print_result(response)

显示界面简洁

from nornir_pyez.plugins.tasks import pyez_int_terse
import os
from nornir import InitNornir
from nornir_utils.plugins.functions import print_result
from rich import print

script_dir = os.path.dirname(os.path.realpath(__file__))

nr = InitNornir(config_file=f"{script_dir}/config.yml")

response = nr.run(
    task=pyez_int_terse
)

# response is an AggregatedResult, which behaves like a list
# there is a response object for each device in inventory
devices = []
for dev in response:
    print(response[dev].result)

获取路线信息

from nornir_pyez.plugins.tasks import pyez_route_info
import os
from nornir import InitNornir
from nornir_utils.plugins.functions import print_result
from rich import print

script_dir = os.path.dirname(os.path.realpath(__file__))

nr = InitNornir(config_file=f"{script_dir}/config.yml")

response = nr.run(
    task=pyez_route_info
)

# response is an AggregatedResult, which behaves like a list
# there is a response object for each device in inventory
devices = []
for dev in response:
    print(response[dev].result)

联系人

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
我们可以使用java for loop with switch语句。。?   java如何从具有循环关系的数据集生成树?   使用s:mvcUrl标记时java Spring启动问题   javascript Wicket调色板水平滚动条在firefox中不显示   java如何清理Maven插件绑定?   java将文件从设备发送到计算机不起作用(文件被破坏)   Java GPU编程的性能   java字符串标记器问题   连接Java LDAP断开连接   java Android GridView将无法确定正确的位置   java AlarmManager在指定时间未显示toast消息   MVC中的java测试外观|断言返回类型   logcat上的java Android运行时错误   java Building Workspace在Eclipse中遇到错误   堆栈溢出尾部递归遗传算法抛出“awteventque0”java。StackOverflowerr语言   java ArrayOutOfBounds测试代码不工作   java有没有像Moodle这样流行的课程管理系统?   java如何从jsp获取xml文件作为响应