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


Python config.Config方法代码示例

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


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

示例1: configure_device

# 需要导入模块: from jnpr.junos.utils import config [as 别名]
# 或者: from jnpr.junos.utils.config import Config [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

示例2: cleanup_routes

# 需要导入模块: from jnpr.junos.utils import config [as 别名]
# 或者: from jnpr.junos.utils.config import Config [as 别名]
def cleanup_routes(dev):
    """Remove the static routes that were added in this exercise."""
    # Create Config object
    cfg = Config(dev)
    cfg.lock()
    # Use set format to delete previously created static routes
    cfg.load(
        "delete routing-options static route 203.0.113.5/32", format="set", merge=True
    )
    cfg.load(
        "delete routing-options static route 203.0.113.200/32", format="set", merge=True
    )
    print()
    print("Cleaning up routes that were added in this exercise.")
    print("\n\n")
    if cfg.diff() is not None:
        cfg.commit()
    cfg.unlock() 
开发者ID:ktbyers,项目名称:pyplus_course,代码行数:20,代码来源:ex4_jnpr_cfg_routes.py

示例3: enable_interface

# 需要导入模块: from jnpr.junos.utils import config [as 别名]
# 或者: from jnpr.junos.utils.config import Config [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

示例4: add_config

# 需要导入模块: from jnpr.junos.utils import config [as 别名]
# 或者: from jnpr.junos.utils.config import Config [as 别名]
def add_config(router,interface,mtu,**kwargs):
    r = requests.get('http://api_server:9000/api/v1/device/%s/' % router, verify=False)
    device_info = r.json()
    hostname = device_info['host']
    userid = device_info['authentication']['password']['username']
    password = device_info['authentication']['password']['password']
    dev = Device(host=hostname, user=userid, password=password, normalize=True)
    dev.open()
    cu = Config(dev)
    data = "set interfaces %s mtu %s" % (interface,mtu)
    cu.load(data, format='set')
    cu.commit()
    dev.close() 
开发者ID:ksator,项目名称:junos_monitoring_with_healthbot,代码行数:15,代码来源:change-mtu-config.py

示例5: config_from_file

# 需要导入模块: from jnpr.junos.utils import config [as 别名]
# 或者: from jnpr.junos.utils.config import Config [as 别名]
def config_from_file(path, dev, merge=True):
    """Function to load config from file and commit it to a device."""
    # Create Config object
    cfg = Config(dev)
    cfg.lock()
    # Load configuration from file; default to merge operation
    cfg.load(path=path, format="text", merge=merge)
    if cfg.diff() is not None:
        cfg.commit()
    cfg.unlock() 
开发者ID:ktbyers,项目名称:pyplus_course,代码行数:12,代码来源:ex4_jnpr_cfg_routes.py

示例6: main

# 需要导入模块: from jnpr.junos.utils import config [as 别名]
# 或者: from jnpr.junos.utils.config import Config [as 别名]
def main():
    '''
    Exercise using Juniper's PyEZ to make changes to device in various ways
    '''
    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()

    cfg = Config(a_device)

    print("Setting hostname using set notation")
    cfg.load("set system host-name test1", format="set", merge=True)

    print("Current config differences: ")
    print(cfg.diff())

    print("Performing rollback")
    cfg.rollback(0)

    print("\nSetting hostname using {} notation (external file)")
    cfg.load(path="load_hostname.conf", format="text", merge=True)

    print("Current config differences: ")
    print(cfg.diff())

    print("Performing commit")
    cfg.commit()

    print("\nSetting hostname using XML (external file)")
    cfg.load(path="load_hostname.xml", format="xml", merge=True)

    print("Current config differences: ")
    print(cfg.diff())

    print("Performing commit")
    cfg.commit()
    print() 
开发者ID:ktbyers,项目名称:python_course,代码行数:52,代码来源:ex6_pyez_change_hostname.py

示例7: main

# 需要导入模块: from jnpr.junos.utils import config [as 别名]
# 或者: from jnpr.junos.utils.config import Config [as 别名]
def main():
    '''
    Exercise using Juniper's PyEZ to make changes to device in various ways
    '''
    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()

    cfg = Config(a_device)

    print "Setting hostname using set notation"
    cfg.load("set system host-name test1", format="set", merge=True)

    print "Current config differences: "
    print cfg.diff()

    print "Performing rollback"
    cfg.rollback(0)

    print "\nSetting hostname using {} notation (external file)"
    cfg.load(path="load_hostname.conf", format="text", merge=True)

    print "Current config differences: "
    print cfg.diff()

    print "Performing commit"
    cfg.commit()

    print "\nSetting hostname using XML (external file)"
    cfg.load(path="load_hostname.xml", format="xml", merge=True)

    print "Current config differences: "
    print cfg.diff()

    print "Performing commit"
    cfg.commit()
    print 
开发者ID:ktbyers,项目名称:pynet,代码行数:49,代码来源:ex4_change_hostname.py

示例8: post

# 需要导入模块: from jnpr.junos.utils import config [as 别名]
# 或者: from jnpr.junos.utils.config import Config [as 别名]
def post(self,comment):
		if not self.dev.connected:
			logger.error("{0}: Firewall timed out or incorrect device credentials.".format(self.firewall_config['name']))
			return {'error' : 'Could not connect to device.'}, 504
		else:
			logger.info("{0}: Connected successfully.".format(self.firewall_config['name']))
		self.dev.bind(cu=Config)
		try:	
			#self.dev.cu.lock()
			pass
		except LockError:
			logger.error("Configuration locked.")
			self.dev.close()
			return {'error' : 'Could not lock configuration.'}, 504
		else:
			logger.info("Locked configuration.")
		try:
			if comment:
				self.dev.cu.commit(comment=comment)
			else:
				self.dev.cu.commit()
		except CommitError:
			logger.error("Unable to commit.")
			try:
				logger.info("Unlocking configuration...")
				#self.dev.cu.unlock()
				pass
			except UnlockError:
				logger.error("Unable to unlock configuration: {0}".format(str(err)))
				return {'error' : 'Unable to commit and unlock configuration.'}, 504
			else:
				logger.info("Configuration unlocked.")
				return {'error' : 'Unable to commit.'}, 504
		else:
			logger.info("Configuration commited successfully.")
			logger.info("Unlocking configuration...")
			try:
				#self.dev.cu.unlock()
				pass
			except UnlockError:
				logger.error("Unable to unlock configuration: {0}".format(str(err)))
				return {'error' : 'Configuration commited but cannot unlock configuration.'}, 504
			else:
				logger.info("Configuration unlocked.")
				return {'commit' : 'success'}
		finally:
			logger.info("Closing connection...")
			self.dev.close() 
开发者ID:videlanicolas,项目名称:assimilator,代码行数:50,代码来源:Junos.py


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