当前位置: 首页>>代码示例>>Python>>正文


Python junos.Device方法代码示例

本文整理汇总了Python中jnpr.junos.Device方法的典型用法代码示例。如果您正苦于以下问题:Python junos.Device方法的具体用法?Python junos.Device怎么用?Python junos.Device使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在jnpr.junos的用法示例。


在下文中一共展示了junos.Device方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from jnpr import junos [as 别名]
# 或者: from jnpr.junos import Device [as 别名]
def main():
    """Connect to Juniper device using PyEZ. Display device facts."""
    pwd = getpass()
    try:
        ip_addr = raw_input("Enter Juniper SRX IP: ")
    except NameError:
        ip_addr = input("Enter Juniper SRX IP: ")
    ip_addr = ip_addr.strip()

    juniper_srx = {
        "host": ip_addr,
        "user": "pyclass",
        "password": pwd
    }

    print("\n\nConnecting to Juniper SRX...\n")
    a_device = Device(**juniper_srx)
    a_device.open()
    pprint(a_device.facts)
    print() 
开发者ID:ktbyers,项目名称:python_course,代码行数:22,代码来源:ex3_pyez_facts.py

示例2: configure_device

# 需要导入模块: from jnpr import junos [as 别名]
# 或者: from jnpr.junos import Device [as 别名]
def configure_device(connection_params, variables):
    device_connection = Device(**connection_params)
    device_connection.open()
    # device_connection.facts_refresh()
    facts = device_connection.facts

    hostname = facts['hostname']

    config_variables = variables['devices'][hostname]

    with Config(device_connection, mode='private') as config:
        config.load(template_path='templates/candidate.conf', template_vars=config_variables, merge=True)
        print("Config diff:")
        config.pdiff()
        config.commit()
        print(f'Configuration was updated successfully on {hostname}')

    device_connection.close() 
开发者ID:dmfigol,项目名称:network-programmability-stream,代码行数:20,代码来源:example.py

示例3: main

# 需要导入模块: from jnpr import junos [as 别名]
# 或者: from jnpr.junos import Device [as 别名]
def main():
    '''
    Connect to Juniper device using PyEZ. Display device facts.
    '''
    pwd = getpass()
    ip_addr = raw_input("Enter Juniper SRX IP: ")
    ip_addr = ip_addr.strip()

    juniper_srx = {
        "host": ip_addr,
        "user": "pyclass",
        "password": pwd
    }

    print "\n\nConnecting to Juniper SRX...\n"
    a_device = Device(**juniper_srx)
    a_device.open()
    pprint(a_device.facts)
    print 
开发者ID:ktbyers,项目名称:pynet,代码行数:21,代码来源:ex1_display_facts.py

示例4: __init__

# 需要导入模块: from jnpr import junos [as 别名]
# 或者: from jnpr.junos import Device [as 别名]
def __init__(self,firewall_config):
		self.firewall_config = firewall_config
		try:
			assert self.firewall_config['privatekey']
			assert self.firewall_config['privatekeypass']
		except:
			#User password connection
			logger.info("Juniper User/Password connection.")
			self.dev = Device(host=self.firewall_config['primary'], password=self.firewall_config['pass'],\
								user=self.firewall_config['user'], port=self.firewall_config['port'], gather_facts=False)
		else:
			#RSA SSH connection
			logger.info("Juniper RSA SSH connection.")
			self.dev = Device(host=self.firewall_config['primary'], passwd=self.firewall_config['privatekeypass'],\
								ssh_private_key_file=self.firewall_config['privatekey'],user=self.firewall_config['user'],\
								port=self.firewall_config['port'], gather_facts=False)
		self.dev.open(normalize=True)
		try:
			self.dev.timeout = int(self.firewall_config['timeout']) if self.firewall_config['timeout'] else 15
		except (ValueError, KeyError):
			logger.warning("Firewall timeout is not an int, setting default value.")
			self.dev.timeout = 15
		self.primary = self.firewall_config['primary'] 
开发者ID:videlanicolas,项目名称:assimilator,代码行数:25,代码来源:Junos.py

示例5: myfunc

# 需要导入模块: from jnpr import junos [as 别名]
# 或者: from jnpr.junos import Device [as 别名]
def myfunc(*args):

    devices = args[0]["devices"]
    username = args[0]["username"][0]
    secret = args[0]["password"][0]
    hosts = args[0]["hosts"]

    arpinfo = {}
    for device in devices:
        dev, port = device.split(":")

        handle = Device(host=dev, port=port, user=username, passwd=secret)
        handle.open()
        devname = handle.rpc.get_system_information().find('host-name').text


        for host in hosts:
            arptable = handle.rpc.get_arp_table_information(hostname=str(host))
            for intname in arptable.findall("./arp-table-entry/interface-name"):
                if devname in arpinfo:
                    arpinfo[devname].append(intname.text.strip())
                else:
                    arpinfo[devname] = [intname.text.strip()]

    out(arpinfo) 
开发者ID:nre-learning,项目名称:nrelabs-curriculum,代码行数:27,代码来源:get-interface-from-arp-ip.py

示例6: main

# 需要导入模块: from jnpr import junos [as 别名]
# 或者: from jnpr.junos import Device [as 别名]
def main():
    """Use Juniper PyEZ and direct RPC to retrieve the XML for 'show version' from the SRX."""
    pwd = getpass()
    try:
        ip_addr = raw_input("Enter Juniper SRX IP: ")
    except NameError:
        ip_addr = input("Enter Juniper SRX IP: ")
    ip_addr = ip_addr.strip()

    juniper_srx = {
        "host": ip_addr,
        "user": "pyclass",
        "password": pwd
    }

    print("\n\nConnecting to Juniper SRX...\n")
    a_device = Device(**juniper_srx)
    a_device.open()

    # show version | display xml rpc
    # get-software-information
    show_version = a_device.rpc.get_software_information()
    print()
    print("Print show version XML out as a string (retrieved via PyEZ RPC):")
    print("-" * 20)
    print(etree.tostring(show_version, pretty_print=True).decode())
    model = show_version.xpath("product-model")[0].text
    print()
    print("-" * 20)
    print("SRX Model: {}".format(model))
    print() 
开发者ID:ktbyers,项目名称:python_course,代码行数:33,代码来源:ex7_rpc_show_version.py

示例7: main

# 需要导入模块: from jnpr import junos [as 别名]
# 或者: from jnpr.junos import Device [as 别名]
def main():
    '''
    Connect to Juniper device using PyEZ. Display the routing table.
    '''
    pwd = getpass()
    try:
        ip_addr = raw_input("Enter Juniper SRX IP: ")
    except NameError:
        ip_addr = input("Enter Juniper SRX IP: ")
    ip_addr = ip_addr.strip()

    juniper_srx = {
        "host": ip_addr,
        "user": "pyclass",
        "password": pwd
    }

    print("\n\nConnecting to Juniper SRX...\n")
    a_device = Device(**juniper_srx)
    a_device.open()

    routes = RouteTable(a_device)
    routes.get()

    print("\nJuniper SRX Routing Table: ")
    for a_route, route_attr in routes.items():
        print("\n" + a_route)
        for attr_desc, attr_value in route_attr:
            print("  {} {}".format(attr_desc, attr_value))

    print("\n") 
开发者ID:ktbyers,项目名称:python_course,代码行数:33,代码来源:ex5_pyez_routes.py

示例8: main

# 需要导入模块: from jnpr import junos [as 别名]
# 或者: from jnpr.junos import Device [as 别名]
def main():
    '''
    Connect to Juniper device using PyEZ. Display operational state and pkts_in, pkts_out for all
    of the interfaces.
    '''
    pwd = getpass()
    try:
        ip_addr = raw_input("Enter Juniper SRX IP: ")
    except NameError:
        ip_addr = input("Enter Juniper SRX IP: ")
    ip_addr = ip_addr.strip()

    juniper_srx = {
        "host": ip_addr,
        "user": "pyclass",
        "password": pwd
    }

    print("\n\nConnecting to Juniper SRX...\n")
    a_device = Device(**juniper_srx)
    a_device.open()

    eth_ports = EthPortTable(a_device)
    eth_ports.get()

    print("{:>15} {:>12} {:>12} {:>12}".format("INTF", "OPER STATE", "IN PACKETS", "OUT PACKETS"))
    for intf, eth_stats in eth_ports.items():
        eth_stats = dict(eth_stats)
        oper_state = eth_stats['oper']
        pkts_in = eth_stats['rx_packets']
        pkts_out = eth_stats['tx_packets']
        print("{:>15} {:>12} {:>12} {:>12}".format(intf, oper_state, pkts_in, pkts_out))
    print() 
开发者ID:ktbyers,项目名称:python_course,代码行数:35,代码来源:ex4_pyez_eth.py

示例9: do_something

# 需要导入模块: from jnpr import junos [as 别名]
# 或者: from jnpr.junos import Device [as 别名]
def do_something(params):
    device_connection = Device(**params)
    device_connection.open()
    # device_connection.facts_refresh()
    facts = device_connection.facts

    # response_xml_element = device_connection.rpc.get_software_information(normalize=True)
    # print(etree.tostring(response_xml_element))
    # pprint(facts)


    print("{0} {1} {0}".format('=' * 37, facts['hostname']))

    routing_table = RouteTable(device_connection)
    routing_table.get()
    print("RIB:")
    for prefix in routing_table:
        print(f"Destination : {prefix.key}\n"
              f"Via: {prefix.via}\n"
              f"Nexthop: {prefix.nexthop}\n"
              f"Protocol: {prefix.protocol}\n\n")

    print("{}".format('=' * 80))

    arp_table = ArpTable(device_connection)
    arp_table.get()
    print("ARP table:")
    for entry in arp_table:
        print(f"IP : {entry.ip_address}\n"
              f"MAC: {entry.mac_address}\n"
              f"Interface: {entry.interface_name}\n\n")


    device_connection.close()
    # return facts 
开发者ID:dmfigol,项目名称:network-programmability-stream,代码行数:37,代码来源:example.py

示例10: enable_interface

# 需要导入模块: from jnpr import junos [as 别名]
# 或者: from jnpr.junos import Device [as 别名]
def enable_interface(int, **kwargs):
	junos_details = get_junos_details(kwargs['device_id'])
	junos_host = junos_details['host']
	junos_user = junos_details['authentication']['password']['username']
	# junos_password = junos_details['authentication']['password']['password']
	junos_password = 'Juniper!1'
	device=Device(host=junos_host, user=junos_user, password=junos_password)
	device.open()
	cfg=Config(device)
	my_template = Template('delete interfaces {{ interface }} disable')
	cfg.load(my_template.render(interface = int), format='set')
	cfg.commit()
	device.close() 
开发者ID:ksator,项目名称:junos_monitoring_with_healthbot,代码行数:15,代码来源:enable_a_disabled_interface.py

示例11: check_connected

# 需要导入模块: from jnpr import junos [as 别名]
# 或者: from jnpr.junos import Device [as 别名]
def check_connected(device):
    print("\n\n")
    if device.connected:
        print(f"Device {device.hostname} is connected!")
    else:
        print(f"Device {device.hostname} failed to connect :(.")
        # If device is *not* connected; exit script
        sys.exit(1) 
开发者ID:ktbyers,项目名称:pyplus_course,代码行数:10,代码来源:ex2_jnpr_tables.py

示例12: main

# 需要导入模块: from jnpr import junos [as 别名]
# 或者: from jnpr.junos import Device [as 别名]
def main():
    '''
    Connect to Juniper device using PyEZ. Display the routing table.
    '''
    pwd = getpass()
    ip_addr = raw_input("Enter Juniper SRX IP: ")
    ip_addr = ip_addr.strip()

    juniper_srx = {
        "host": ip_addr,
        "user": "pyclass",
        "password": pwd
    }

    print "\n\nConnecting to Juniper SRX...\n"
    a_device = Device(**juniper_srx)
    a_device.open()

    routes = RouteTable(a_device)
    routes.get()

    print "\nJuniper SRX Routing Table: "
    for a_route, route_attr in routes.items():
        print "\n" + a_route
        for attr_desc, attr_value in route_attr:
            print "  {} {}".format(attr_desc, attr_value)

    print "\n" 
开发者ID:ktbyers,项目名称:pynet,代码行数:30,代码来源:ex3_route_table.py

示例13: main

# 需要导入模块: from jnpr import junos [as 别名]
# 或者: from jnpr.junos import Device [as 别名]
def main():
    '''
    Connect to Juniper device using PyEZ. Display operational state and pkts_in, pkts_out for all
    of the interfaces.
    '''
    pwd = getpass()
    ip_addr = raw_input("Enter Juniper SRX IP: ")
    ip_addr = ip_addr.strip()

    juniper_srx = {
        "host": ip_addr,
        "user": "pyclass",
        "password": pwd
    }

    print "\n\nConnecting to Juniper SRX...\n"
    a_device = Device(**juniper_srx)
    a_device.open()

    eth_ports = EthPortTable(a_device)
    eth_ports.get()

    print "{:>15} {:>12} {:>12} {:>12}".format("INTF", "OPER STATE", "IN PACKETS", "OUT PACKETS")
    for intf, eth_stats in eth_ports.items():
        eth_stats = dict(eth_stats)
        oper_state = eth_stats['oper']
        pkts_in = eth_stats['rx_packets']
        pkts_out = eth_stats['tx_packets']
        print "{:>15} {:>12} {:>12} {:>12}".format(intf, oper_state, pkts_in, pkts_out)
    print 
开发者ID:ktbyers,项目名称:pynet,代码行数:32,代码来源:ex2_eth_stats.py

示例14: setUp

# 需要导入模块: from jnpr import junos [as 别名]
# 或者: from jnpr.junos import Device [as 别名]
def setUp(self):
        self.dev = Device(
            host='127.0.0.1', user='root', password='Juniper', port='2222'
        )
        self.dev.open() 
开发者ID:Mierdin,项目名称:nwkauto,代码行数:7,代码来源:pyez_unittest.py

示例15: mocked_device

# 需要导入模块: from jnpr import junos [as 别名]
# 或者: from jnpr.junos import Device [as 别名]
def mocked_device(rpc_reply_dict, mock_connect):
    """Juniper PyEZ Device Fixture"""
    def mock_manager(*args, **kwargs):
        if 'device_params' in kwargs:
            # open connection
            device_params = kwargs['device_params']
            device_handler = make_device_handler(device_params)
            session = SSHSession(device_handler)
            return Manager(session, device_handler)
        elif args:
            # rpc request
            rpc_request = args[0].tag
            rpc_command = str(args[0].text)
            rpc_command = rpc_command.strip()
            rpc_command = rpc_command.replace(" ", "_")
            if rpc_request in rpc_reply_dict:
                xml = rpc_reply_dict[rpc_request]
            elif 'dir' in rpc_reply_dict:
                fname = os.path.join(rpc_reply_dict['dir'], 'rpc-reply', rpc_command, rpc_request + '.xml')
                with open(fname, 'r') as f:
                    xml = f.read()
            else:
                _rpc_reply_dict['dir']
                fname = os.path.join(os.path.dirname(__file__), 'rpc-reply', rpc_command, rpc_request + '.xml')
                with open(fname, 'r') as f:
                    xml = f.read()
            rpc_reply = NCElement(xml, dev._conn._device_handler.transform_reply())
            return rpc_reply
    mock_connect.side_effect = mock_manager
    dev = Device(host='1.1.1.1', user='juniper', gather_facts=False)
    dev.open()
    dev._conn.rpc = MagicMock(side_effect=mock_manager)
    dev.close = MagicMock()
    return dev 
开发者ID:Juniper,项目名称:open-nti,代码行数:36,代码来源:pyez_mock.py


注:本文中的jnpr.junos.Device方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。