Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Utilizing ncclient bind_addr parameter #1279

Closed
elinewman12 opened this issue Nov 2, 2023 · 6 comments
Closed

Utilizing ncclient bind_addr parameter #1279

elinewman12 opened this issue Nov 2, 2023 · 6 comments
Assignees

Comments

@elinewman12
Copy link

Why does the current version of Junos not use the bind_addr optional parameter for providing a source address to bind when connecting Device objects? It would be an easy fix and at least my current team would heavily benefit from this addition. I had to create a fork from our currently used version of Junos (5 years old) but we couldn't upgrade to the latest version either way due to the lack of this feature.

@chidanandpujar
Copy link
Collaborator

Hi @elinewman12
Thanks,
we are analyzing the ncclient options - https://github.com/ncclient/ncclient/blob/master/ncclient/transport/ssh.py#L206

Thanks

@elinewman12
Copy link
Author

elinewman12 commented Nov 7, 2023

@chidanandpujar I implemented the change on a fork but it uses version 2.3.0. So far, testing has proven successful with the use of bind_addr

@chidanandpujar
Copy link
Collaborator

HI @elinewman12
Thanks for the information .
Latest PyEZ release is 2.6.8 , I will check the feasibility and update you .

Thanks

@dineshbaburam91
Copy link
Collaborator

@elinewman12 Could you please provide more information on use case of the "bind_addr" argument in the ncclient code?
To validate and add testcases in junos-eznc

@rado120p
Copy link

I concur with the OP, it would be useful to be able to pass the "bind_addr" parameter when instantiating the Device object.
There are situations where the script is executed from a host which may have multiple IP addresses but only some of them may be reachable from the target device. The "bind_addr" parameter in ncclient's connect function allows specifying the desired source IP address that is used to initiate the TCP connection.

I've personally ended up creating fork of junos-eznc device.py (version 2.7.0) so that it accepts the bind_addr parameter and then passes it to the ncclient's "connect" function.

class Device(_Connection):

    def __init__(self, *vargs, **kvargs):
    <omitted>
        self._bind_addr = kvargs.get("bind_addr", None)


    def open(self, *vargs, **kvargs):
    <omitted>

            # open connection using ncclient transport
            self._conn = netconf_ssh.connect(
                host=self._hostname,
                port=self._port,
                sock_fd=self._sock_fd,
                username=self._auth_user,
                password=self._auth_password,
                hostkey_verify=False,
                key_filename=self._ssh_private_key_file,
                allow_agent=allow_agent,
                look_for_keys=look_for_keys,
                ssh_config=self._sshconf_lkup(),
                timeout=self._conn_open_timeout,
                bind_addr=self._bind_addr, <<----- 
                device_params={
                    "name": "junos",
                    "local": self.__class__.ON_JUNOS,
                    "use_filter": self._use_filter,
                },
            )

@dineshbaburam91 dineshbaburam91 self-assigned this Oct 14, 2024
@dineshbaburam91
Copy link
Collaborator

Fixed #1340

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants