Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def connect(host, port, user, password):
conn = manager.connect(host=host,
port=port,
username=user,
password=password,
timeout=60,
device_params={'name': 'junos'},
hostkey_verify=False)
conn.lock()
root = new_ele('config')
configuration = sub_ele(root, 'configuration')
system = sub_ele(configuration, 'system')
location = sub_ele(system, 'location')
sub_ele(location, 'building').text = "Main Campus, A"
sub_ele(location, 'floor').text = "5"
sub_ele(location, 'rack').text = "27"
edit_config_result = conn.edit_config(config=root)
logging.info(edit_config_result)
validate_result = conn.validate()
logging.info(validate_result)
compare_config_result = conn.compare_configuration()
logging.info(compare_config_result)
conn.commit()
port=port,
username=user,
password=password,
timeout=60,
device_params={'name': 'junos'},
hostkey_verify=False)
conn.lock()
root = new_ele('config')
configuration = sub_ele(root, 'configuration')
system = sub_ele(configuration, 'system')
location = sub_ele(system, 'location')
sub_ele(location, 'building').text = "Main Campus, A"
sub_ele(location, 'floor').text = "5"
sub_ele(location, 'rack').text = "27"
edit_config_result = conn.edit_config(config=root)
logging.info(edit_config_result)
validate_result = conn.validate()
logging.info(validate_result)
compare_config_result = conn.compare_configuration()
logging.info(compare_config_result)
conn.commit()
conn.unlock()
conn.close_session()
def commit(self, confirmed=False, check=False, timeout=None, comment=None, synchronize=False, at_time=None):
"""Commit the candidate configuration as the device's new current configuration.
Depends on the `:candidate` capability.
A confirmed commit (i.e. if *confirmed* is `True`) is reverted if there is no
followup commit within the *timeout* interval. If no timeout is specified the
confirm timeout defaults to 600 seconds (10 minutes).
A confirming commit may have the *confirmed* parameter but this is not required.
Depends on the `:confirmed-commit` capability.
:confirmed: whether this is a confirmed commit
:timeout: specifies the confirm timeout in seconds
"""
obj = new_ele('commit-configuration')
if confirmed:
sub_ele(obj, 'confirmed')
if check:
sub_ele(obj, 'check')
if synchronize:
sub_ele(obj, 'synchronize')
if at_time:
subele = sub_ele(obj, 'at-time')
subele.text = str(at_time)
if comment:
subele = sub_ele(obj, 'log')
subele.text = str(comment)
if timeout:
subele = sub_ele(obj, 'confirm-timeout')
subele.text = str(timeout)
return self.rpc(obj)
conn = manager.connect(host=host,
port=port,
username=user,
password=password,
timeout=60,
device_params={'name': 'junos'},
hostkey_verify=False)
conn.lock()
root = new_ele('config')
configuration = sub_ele(root, 'configuration')
system = sub_ele(configuration, 'system')
location = sub_ele(system, 'location')
sub_ele(location, 'building').text = "Main Campus, A"
sub_ele(location, 'floor').text = "5"
sub_ele(location, 'rack').text = "27"
edit_config_result = conn.edit_config(config=root)
logging.info(edit_config_result)
validate_result = conn.validate()
logging.info(validate_result)
compare_config_result = conn.compare_configuration()
logging.info(compare_config_result)
conn.commit()
conn.unlock()
conn.close_session()
def parseChild (parent, part):
for key, value in part.iteritems():
if isinstance(value, dict):
node = sub_ele(parent, key)
# Need to go deeper -> recursion
parseChild(node, value)
elif value is not None:
node = sub_ele(parent, key)
node.text = str(value)
:param check: Check correctness of syntax
:param timeout: specifies the confirm timeout in seconds
:param comment: Message to write to commit log
:param synchronize: Synchronize commit on remote peers
:param at_time: Time at which to activate configuration changes
:return: Received rpc response from remote host
"""
obj = new_ele('commit-configuration')
if confirmed:
sub_ele(obj, 'confirmed')
if check:
sub_ele(obj, 'check')
if synchronize:
sub_ele(obj, 'synchronize')
if at_time:
subele = sub_ele(obj, 'at-time')
subele.text = str(at_time)
if comment:
subele = sub_ele(obj, 'log')
subele.text = str(comment)
if timeout:
subele = sub_ele(obj, 'confirm-timeout')
subele.text = str(timeout)
return self.rpc(obj)
def parseChild (parent, part):
for key, value in part.iteritems():
if isinstance(value, dict):
node = sub_ele(parent, key)
# Need to go deeper -> recursion
parseChild(node, value)
elif value is not None:
node = sub_ele(parent, key)
node.text = str(value)
def query(self, *args):
filter_node = new_ele("filter")
conf = sub_ele(filter_node, "configuration")
for arg in args:
conf.append(arg())
return self.netconf.get_config(source="candidate" if self.in_transaction else "running", filter=filter_node)
Depends on the `:confirmed-commit` capability.
:confirmed: whether this is a confirmed commit
:timeout: specifies the confirm timeout in seconds
"""
obj = new_ele('commit-configuration')
if confirmed:
sub_ele(obj, 'confirmed')
if check:
sub_ele(obj, 'check')
if synchronize:
sub_ele(obj, 'synchronize')
if at_time:
subele = sub_ele(obj, 'at-time')
subele.text = str(at_time)
if comment:
subele = sub_ele(obj, 'log')
subele.text = str(comment)
if timeout:
subele = sub_ele(obj, 'confirm-timeout')
subele.text = str(timeout)
return self.rpc(obj)