Closed dgarros closed 8 years ago
@dgarros: Is dev object defined in your python file. Looks like it is getting string instead of Device object.
dev should be object of PyEz Device class, and it should have established connection with device.
from jnpr.junos import Device
dev_obj = Device(host='10.209.1.1', user='foo', password='bar')
dev_obj.open()
I tried with this file:
from jnpr.jsnapy import SnapAdmin
from pprint import pprint
from jnpr.junos import Device
dev_obj = Device(host='10.209.16.204', user='demo', password='demo123')
dev_obj.open()
js = SnapAdmin()
config_file = "/Users/jpriyal/Desktop/developement/demo/module_demo/demo_snapcheck.yml"
# can pass device object
# it will not create new connection with device
snapchk = js.snapcheck(config_file, "snap", dev=dev_obj)
for val in snapchk:
print "Tested on", val.device
print "Final result: ", val.result
print "Total passed: ", val.no_passed
print "Total failed:", val.no_failed
pprint(dict(val.test_details))
It is working fine:
Tested on 10.209.16.204
Final result: Passed
Total passed: 1
Total failed: 0
{'show version': [{'actual_node_value': ['junos',
'jbase',
'jplatform',
'jweb',
'jruntime',
'jdocs',
'jservices-aacl',
'jservices-alg',
'jservices-appid',
'jservices-bgf',
'jservices-cpcd',
'jservices-hcm',
'jservices-idp',
..........,
'jpfe-common',
'jroute'],
'node_name': '//package-information/name',
'result': True,
'testoperation': 'exists',
'xpath': '//software-information'}]}
(venv)sh-3.2#
(venv)sh-3.2#
(venv)sh-3.2#
Hi Yes dev is a pyez object in my case
try:
dev = Device(m_args['host'],
user=m_args['user'],
password=m_args['passwd'],
port=m_args['port'],
gather_facts=False).open()
except Exception as err:
msg = 'Unable to connect to {0}: {1}'.format(args['host'], str(err))
logging.error(msg)
module.fail_json(msg=msg)
# --- UNREACHABLE ---
Please can you share the content of your config file demo_snapcheck.yml
?
Thanks
Its the same file that you are using:
(venv)sh-3.2# cat demo_snapcheck.yml
tests:
- test_exists.yml
Thanks Any idea why it's not working for me right now ?
Where is supposed to be store the first "snap", I couldn't find it in /etc/jsnapy/snapshots Thanks
As my logic get hit at https://github.com/Juniper/jsnapy/blob/5ea8b1b6a7b8a747a8153027715554f7e40e5378/lib/jnpr/jsnapy/jsnapy.py#L820 Can you check if below return True for you isinstance(dev, Device)
@Jainpriyal
If you want to give it a try yourself I uploaded the module I'm working on here Be careful, I hardcoded the path to the file inside the module right now for troubleshooting
And you can find my ansible project here
Playbook : https://git.juniper.net/jdi-tme/lab-evpn-vxlan/blob/jsnapy/pb.jsnapy.yaml Tests file : https://git.juniper.net/jdi-tme/lab-evpn-vxlan/tree/jsnapy/jsnap_tests
Let me know if you have questions
Manage to make it work, thanks for your help
Hi
I'm trying to create a module jsnapy for ansible and I'm facing an issue I'm following this doc : https://github.com/Juniper/jsnapy/wiki/4.-Module
I prefer to initiate the ssh connection outside of Jsnapy and pass the object to the module. Also I called
js.snap
andjs.check
independently.Snap is not reporting an error but I do not see where is the snapshot being save locally And I get an error regarding the syntax of the configuration file for
js.check
Please do you have an example of configuration file for
js.snap
&js.check
when the device object is provided and when we don't want to use the database.I looked here https://github.com/Juniper/jsnapy/tree/master/lib/jnpr/jsnapy/samples but all config_* file include hosts information which doesn't apply in my case.
Here is my code
Below my configuration file and my test file