def _get_connection(self): """Make SSH connection to the CSR. The external ncclient library is used for creating this connection. This method keeps state of any existing connections and reuses them if already connected. Also CSR1kv's interfaces (except management) are disabled by default when it is booted. So if connecting for the first time, driver will enable all other interfaces and keep that status in the `_intfs_enabled` flag. """ try: if self._csr_conn and self._csr_conn.connected: return self._csr_conn else: self._csr_conn = manager.connect(host=self._csr_host, port=self._csr_ssh_port, username=self._csr_user, password=self._csr_password, device_params={'name': "csr"}, timeout=self._timeout) if not self._intfs_enabled: self._intfs_enabled = self._enable_intfs(self._csr_conn) return self._csr_conn except Exception as e: conn_params = { 'host': self._csr_host, 'port': self._csr_ssh_port, 'user': self._csr_user, 'timeout': self._timeout, 'reason': e.message } raise cfg_exc.ConnectionException(**conn_params)
def _get_connection(self): """Make SSH connection to the IOS XE device. The external ncclient library is used for creating this connection. This method keeps state of any existing connections and reuses them if already connected. Also interfaces (except management) are typically disabled by default when it is booted. So if connecting for the first time, driver will enable all other interfaces and keep that status in the `_itfcs_enabled` flag. """ try: if self._ncc_connection and self._ncc_connection.connected: return self._ncc_connection else: # ncclient needs 'name' to be 'csr' in order to communicate # with the device in the correct way. self._ncc_connection = manager.connect( host=self._host_ip, port=self._host_ssh_port, username=self._username, password=self._password, device_params={'name': "csr"}, timeout=self._timeout) if not self._itfcs_enabled: self._itfcs_enabled = self._enable_itfcs( self._ncc_connection) return self._ncc_connection except Exception as e: conn_params = {'host': self._host_ip, 'port': self._host_ssh_port, 'user': self._username, 'timeout': self._timeout, 'reason': e.message} raise cfg_exc.ConnectionException(**conn_params)