/usr/share/doc/python-ncclient/examples/request-reboot.py is in python-ncclient 0.4.7-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | #!/usr/bin/env python
from ncclient import manager
import time
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)
result = conn.reboot()
reboot_nodes = result.xpath('request-reboot-results/request-reboot-status')
if reboot_nodes:
reboot_time = result.xpath('request-reboot-results/request-reboot-status/@reboot-time')[0]
if 'Shutdown NOW' in reboot_nodes[0].text:
print 'Rebooted at:', time.ctime(int(reboot_time))
if __name__ == '__main__':
connect('router', 830, 'netconf', 'juniper!')
|