-
Notifications
You must be signed in to change notification settings - Fork 389
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #243 from attila123/examples_juniper_various_impro…
…vements examples/juniper various improvements (issue #236 plus more):
- Loading branch information
Showing
27 changed files
with
511 additions
and
354 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,37 @@ | ||
#!/usr/bin/env python | ||
import logging | ||
import sys | ||
|
||
from ncclient import manager | ||
|
||
|
||
def connect(host, port, user, password): | ||
conn = manager.connect(host=host, | ||
port=port, | ||
username=user, | ||
password=password, | ||
timeout=10, | ||
device_params = {'name':'junos'}, | ||
hostkey_verify=False) | ||
|
||
print 'show system users' | ||
print '*' * 30 | ||
port=port, | ||
username=user, | ||
password=password, | ||
timeout=60, | ||
device_params={'name': 'junos'}, | ||
hostkey_verify=False) | ||
|
||
logging.info('show system users') | ||
logging.info('*' * 30) | ||
result = conn.command(command='show system users', format='text') | ||
print result.tostring | ||
logging.info(result) | ||
|
||
print 'show version' | ||
print '*' * 30 | ||
logging.info('show version') | ||
logging.info('*' * 30) | ||
result = conn.command('show version', format='text') | ||
print result.xpath('output')[0].text | ||
logging.info(result.xpath('output')[0].text) | ||
|
||
print 'bgp summary' | ||
print '*' * 30 | ||
logging.info('bgp summary') | ||
logging.info('*' * 30) | ||
result = conn.command('show bgp summary') | ||
print result.tostring | ||
logging.info(result) | ||
|
||
|
||
if __name__ == '__main__': | ||
LOG_FORMAT = '%(asctime)s %(levelname)s %(filename)s:%(lineno)d %(message)s' | ||
logging.basicConfig(stream=sys.stdout, level=logging.INFO, format=LOG_FORMAT) | ||
|
||
connect('router', '22', 'netconf', 'juniper!') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,25 @@ | ||
#!/usr/bin/env python | ||
import logging | ||
|
||
from ncclient import manager | ||
from ncclient.xml_ import * | ||
|
||
import time | ||
|
||
def connect(host, port, user, password, source): | ||
def connect(host, port, user, password): | ||
conn = manager.connect(host=host, | ||
port=port, | ||
username=user, | ||
password=password, | ||
timeout=10, | ||
device_params = {'name':'junos'}, | ||
hostkey_verify=False) | ||
port=port, | ||
username=user, | ||
password=password, | ||
timeout=60, | ||
device_params={'name': 'junos'}, | ||
hostkey_verify=False) | ||
|
||
compare_config_result = conn.compare_configuration(rollback=3) | ||
logging.info(compare_config_result) | ||
|
||
compare_config = conn.compare_configuration(rollback=3) | ||
print compare_config.tostring | ||
|
||
if __name__ == '__main__': | ||
connect('router', 830, 'netconf', 'juniper!', 'candidate') | ||
LOG_FORMAT = '%(asctime)s %(levelname)s %(filename)s:%(lineno)d %(message)s' | ||
logging.basicConfig(stream=sys.stdout, level=logging.INFO, format=LOG_FORMAT) | ||
|
||
connect('router', 830, 'netconf', 'juniper!') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,41 @@ | ||
#!/usr/bin/env python | ||
import logging | ||
|
||
from ncclient import manager | ||
from ncclient.xml_ import * | ||
|
||
def connect(host, port, user, password, source): | ||
|
||
def connect(host, port, user, password): | ||
conn = manager.connect(host=host, | ||
port=port, | ||
username=user, | ||
password=password, | ||
timeout=10, | ||
device_params = {'name':'junos'}, | ||
hostkey_verify=False) | ||
port=port, | ||
username=user, | ||
password=password, | ||
timeout=60, | ||
device_params={'name': 'junos'}, | ||
hostkey_verify=False) | ||
|
||
template = """<system><scripts><commit><file delete="delete"><name>test.slax</name></file></commit></scripts></system>""" | ||
template = """<system><scripts><commit> | ||
<file delete="delete"><name>test.slax</name></file> | ||
</commit></scripts></system>""" | ||
|
||
conn.lock() | ||
config = to_ele(template) | ||
send_config = conn.load_configuration(config=config) | ||
print send_config.tostring | ||
load_config_result = conn.load_configuration(config=config) | ||
logging.info(load_config_result) | ||
|
||
check_config = conn.validate() | ||
print check_config.tostring | ||
validate_result = conn.validate() | ||
logging.info(validate_result) | ||
|
||
compare_config = conn.compare_configuration() | ||
print compare_config.tostring | ||
compare_config_result = conn.compare_configuration() | ||
logging.info(compare_config_result) | ||
|
||
conn.commit() | ||
conn.unlock() | ||
conn.close_session() | ||
|
||
|
||
if __name__ == '__main__': | ||
connect('router', 830, 'netconf', 'juniper!', 'candidate') | ||
LOG_FORMAT = '%(asctime)s %(levelname)s %(filename)s:%(lineno)d %(message)s' | ||
logging.basicConfig(stream=sys.stdout, level=logging.INFO, format=LOG_FORMAT) | ||
|
||
connect('router', 830, 'netconf', 'juniper!') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,48 @@ | ||
#!/usr/bin/env python | ||
import sys | ||
|
||
import logging | ||
|
||
from ncclient import manager | ||
|
||
def connect(host, user, password): | ||
|
||
def connect(host, port, user, password): | ||
conn = manager.connect(host=host, | ||
username=user, | ||
password=password, | ||
timeout=10, | ||
device_params = {'name':'junos'}, | ||
hostkey_verify=False) | ||
port=port, | ||
username=user, | ||
password=password, | ||
timeout=60, | ||
device_params={'name': 'junos'}, | ||
hostkey_verify=False) | ||
|
||
conn.lock() | ||
|
||
# configuration as a string | ||
send_config = conn.load_configuration(action='set', config='set system host-name foo') | ||
load_config_result = conn.load_configuration(action='set', config='set system host-name foo') | ||
logging.info(load_config_result) | ||
|
||
# configuration as a list | ||
location = [] | ||
location.append('set system location building "Main Campus, C"') | ||
location.append('set system location floor 15') | ||
location.append('set system location rack 1117') | ||
|
||
send_config = conn.load_configuration(action='set', config=location) | ||
print send_config.tostring | ||
load_config_result = conn.load_configuration(action='set', config=location) | ||
logging.info(load_config_result) | ||
|
||
check_config = conn.validate() | ||
print check_config.tostring | ||
validate_result = conn.validate() | ||
logging.info(validate_result) | ||
|
||
compare_config = conn.compare_configuration() | ||
print compare_config.tostring | ||
compare_config_result = conn.compare_configuration() | ||
logging.info(compare_config_result) | ||
|
||
conn.commit() | ||
conn.unlock() | ||
conn.close_session() | ||
|
||
|
||
if __name__ == '__main__': | ||
connect('router', 'netconf', 'juniper!') | ||
LOG_FORMAT = '%(asctime)s %(levelname)s %(filename)s:%(lineno)d %(message)s' | ||
logging.basicConfig(stream=sys.stdout, level=logging.INFO, format=LOG_FORMAT) | ||
|
||
connect('router', '22', 'netconf', 'juniper!') |
Oops, something went wrong.