code: def connect(self, ctrl):
          
          if self.prompt:
              self.prompt_re = self.driver.make_dynamic_prompt(self.prompt)
          else:
              self.prompt_re = self.driver.prompt_re
  
          self.ctrl = ctrl
          if self.protocol.connect(self.driver):
              if self.protocol.authenticate(self.driver):
                  self.ctrl.try_read_prompt(1)
                  if not self.prompt:
                      self.prompt = self.ctrl.detect_prompt()
  
                  if self.is_target:
                      self.update_config_mode()
                      if self.mode is not None and self.mode != 'global':
                          self.last_error_msg = "Device is not in global mode. Disconnected."
                          self.chain.disconnect()
                          return False
  
                  self.prompt_re = self.driver.make_dynamic_prompt(self.prompt)
                  self.connected = True
  
                  if self.is_target is False:
                      if self.os_version is None:
                          self.update_os_version()
  
                      self.update_hostname()
                  else:
                      self._connected_to_target()
                  return True
  
          else:
              self.connected = False
              return False
docs: Connect to the device.