cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
200
Views
5
Helpful
4
Replies
Highlighted
Cisco Employee

Fetch SSH host keys in the python part of a service?

I know how to do fetch of ssh host keys for a device from NSO CLI or using RESTCONF API.

Is it possible to do fetch of ssh host keys from within the python part of a service, i.e. in the myService/python/myService/main.py?

Looking at this one: https://community.cisco.com/t5/nso-developer-hub-discussions/ssh-fetch-host-keys-is-this-function-code-visible/td-p/3425348

But was still unable to figure out how to do it.

 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Cisco Employee

You typically do not want to have any device interactions during the critical part of a transaction. Best is to capture the error in the northbound system and do a separate API call to request the keys.

View solution in original post

4 REPLIES 4
Highlighted
Cisco Employee

Hi bfinnema,

You can fetch the value as follows

dev = root.devices.device['ios-dev0']
list(dev.ssh.host_key)[0].show_fingerprint().value

Thanks,

Kiran Kumar

Highlighted
Cisco Employee

You typically do not want to have any device interactions during the critical part of a transaction. Best is to capture the error in the northbound system and do a separate API call to request the keys.

View solution in original post

Highlighted
Cisco Employee

Hi Kiran,

Thank you for the response. This assumes that I have already fetched the host keys and just want to view them. Because I have not done that, I get "IndexError: list index out of range".

What I want to do is fetch the host keys from the device. I have this status of the device:

admin@ncs# devices device asr9001 check-sync
result error
info Failed to authenticate towards device asr9001: Unknown SSH host key

I know I can fetch host keys using CLI like this:

admin@ncs(config)# devices device asr9001 ssh fetch-host-keys

But I want to do it within the python part of a service. How can I do that?

 

Kind Regards

/Bo

Highlighted
Cisco Employee

It's straight  fwd, and I have update the output possibility in the above link which u shared.

dev = root.devices.device['asr9001']
output = dev.ssh.fetch_host_keys()
# I have pasted the yang for output possibility in the link u shared
# based on output you can take steps accordingly