How to use the pyeapi.client function in pyeapi

To help you get started, we’ve selected a few pyeapi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github arista-eosplus / pyeapi / test / unit / test_client.py View on Github external
def test_node_returns_cached_model(self):
        node = pyeapi.client.Node(None)
        node._model = '7777'
        self.assertEqual(node.model, '7777')
github arista-eosplus / pyeapi / test / unit / test_client.py View on Github external
def test_connections_property(self):
        conf = get_fixture('eapi.conf')
        pyeapi.client.load_config(conf)
        connections = ['test1', 'test2', 'localhost']
        result = pyeapi.client.config.connections
        self.assertEqual(sorted(connections), sorted(result))
github arista-eosplus / pyeapi / test / unit / test_client.py View on Github external
def test_connect_return_node_enablepwd(self):
        transport = Mock()
        with patch.dict(pyeapi.client.TRANSPORTS, {'https': transport}):
            conf = get_fixture('eapi.conf')
            pyeapi.client.load_config(filename=conf)
            node = pyeapi.client.connect(host='192.168.1.16', username='eapi',
                                         password='password', port=None,
                                         timeout=60, enablepwd='enablepwd',
                                         return_node=True)
            kwargs = dict(host='192.168.1.16', username='eapi',
                          password='password', port=None, key_file=None,
                          cert_file=None, ca_file=None, timeout=60)
            transport.assert_called_once_with(**kwargs)
            self.assertEqual(node._enablepwd, 'enablepwd')
github ktbyers / pyplus_course / class6 / exercises / ex2b_reusable_func.py View on Github external
def main():

    devices = yaml_load_devices()
    password = os.getenv("PYNET_PASSWORD") if os.getenv("PYNET_PASSWORD") else getpass()

    for name, device_dict in devices.items():
        device_dict["password"] = password
        connection = pyeapi.client.connect(**device_dict)
        device = pyeapi.client.Node(connection)
        output = device.enable("show ip arp")
        arp_list = output[0]["result"]["ipV4Neighbors"]
        output_printer(arp_list)
github napalm-automation / napalm / napalm / eos / eos.py View on Github external
def open(self):
        """Implementation of NAPALM method open."""
        try:
            connection = self.transport_class(
                host=self.hostname,
                username=self.username,
                password=self.password,
                timeout=self.timeout,
                **self.eapi_kwargs
            )

            if self.device is None:
                self.device = pyeapi.client.Node(connection, enablepwd=self.enablepwd)
            # does not raise an Exception if unusable

            # let's try to run a very simple command
            self.device.run_commands(["show clock"], encoding="text")
        except ConnectionError as ce:
            # and this is raised either if device not avaiable
            # either if HTTP(S) agent is not enabled
            # show management api http-commands
            raise ConnectionException(str(ce))
github napalm-automation / napalm / vagrant / provision.py View on Github external
def provision_eos(port, username, password):
    connection = pyeapi.client.connect(
        transport="https",
        host="localhost",
        username="vagrant",
        password="vagrant",
        port=port,
    )
    device = pyeapi.client.Node(connection)

    commands = list()
    commands.append("configure session")
    commands.append("rollback clean-config")

    with open("../eos/initial.conf", "r") as f:
        lines = f.readlines()

    for line in lines:
        line = line.strip()
        if line == "":
            continue
        if line.startswith("!"):
            continue
        commands.append(line)
github saltstack / salt / salt / modules / arista_pyeapi.py View on Github external
def _prepare_connection(**kwargs):
    '''
    Prepare the connection with the remote network device, and clean up the key
    value pairs, removing the args used for the connection init.
    '''
    pyeapi_kwargs = __salt__['config.get']('pyeapi', {})
    pyeapi_kwargs.update(kwargs)  # merge the CLI args with the opts/pillar
    init_kwargs, fun_kwargs = __utils__['args.prepare_kwargs'](pyeapi_kwargs, PYEAPI_INIT_KWARGS)
    if 'transport' not in init_kwargs:
        init_kwargs['transport'] = 'https'
    conn = pyeapi.client.connect(**init_kwargs)
    node = pyeapi.client.Node(conn, enablepwd=init_kwargs.get('enablepwd'))
    return node, fun_kwargs
github ktbyers / pyplus_course / class6 / exercises / ex2a_yaml_inventory.py View on Github external
def main():

    devices = yaml_load_devices()
    password = os.getenv("PYNET_PASSWORD") if os.getenv("PYNET_PASSWORD") else getpass()

    for name, device_dict in devices.items():
        device_dict["password"] = password
        connection = pyeapi.client.connect(**device_dict)
        device = pyeapi.client.Node(connection)
        output = device.enable("show ip arp")

        print()
        print("-" * 40)
        arp_list = output[0]["result"]["ipV4Neighbors"]
        for arp_entry in arp_list:
            mac_address = arp_entry["hwAddress"]
            ip_address = arp_entry["address"]
            print("{:^15}{:^5}{:^15}".format(ip_address, "-->", mac_address))
        print("-" * 40)
        print()
github napalm-automation / napalm / napalm / eos / eos.py View on Github external
def _process_optional_args(self, optional_args):
        # Define locking method
        self.lock_disable = optional_args.get("lock_disable", False)

        self.enablepwd = optional_args.pop("enable_password", "")
        self.eos_autoComplete = optional_args.pop("eos_autoComplete", None)
        # eos_transport is there for backwards compatibility, transport is the preferred method
        transport = optional_args.get(
            "transport", optional_args.get("eos_transport", "https")
        )
        try:
            self.transport_class = pyeapi.client.TRANSPORTS[transport]
        except KeyError:
            raise ConnectionException("Unknown transport: {}".format(self.transport))
        init_args = inspect.getfullargspec(self.transport_class.__init__)[0]

        init_args.pop(0)  # Remove "self"
        init_args.append("enforce_verification")  # Not an arg for unknown reason

        filter_args = ["host", "username", "password", "timeout", "lock_disable"]

        self.eapi_kwargs = {
            k: v
            for k, v in optional_args.items()
            if k in init_args and k not in filter_args
        }