Exemple #1
0
 def __init__(self, hostname, configpath=None, dry_run=False):
     ssh_config = SSHConfig()
     if not hostname:
         print(red('"hostname" must be defined'))
         sys.exit(1)
     parsed = self.parse_host(hostname)
     hostname = parsed.get('hostname')
     username = parsed.get('username')
     if configpath:
         if not isinstance(configpath, (list, tuple)):
             configpath = [configpath]
         for path in configpath:
             self._load_config(path, hostname)
     with (Path.home() / '.ssh/config').open() as fd:
         ssh_config.parse(fd)
     ssh_config = ssh_config.lookup(hostname)
     self.dry_run = dry_run
     self.hostname = config.hostname or ssh_config['hostname']
     self.username = (username or config.username
                      or ssh_config.get('user', getuser()))
     self.formatter = Formatter()
     self.key_filenames = []
     if config.key_filename:
         self.key_filenames.append(config.key_filename)
     if 'identityfile' in ssh_config:
         self.key_filenames.extend(ssh_config['identityfile'])
     self.sudo = ''
     self.cd = None
     self.screen = None
     self.env = {}
     self._sftp = None
     self.proxy_command = ssh_config.get('proxycommand',
                                         config.proxy_command)
     self.open()
Exemple #2
0
 def __init__(self, hostname, configpath=None):
     ssh_config = SSHConfig()
     if not hostname:
         print(red('"hostname" must be defined'))
         sys.exit(1)
     parsed = self.parse_host(hostname)
     hostname = parsed.get('hostname')
     username = parsed.get('username')
     if configpath:
         if not isinstance(configpath, (list, tuple)):
             configpath = [configpath]
         for path in configpath:
             self._load_config(path, hostname)
     with (Path.home() / '.ssh/config').open() as fd:
         ssh_config.parse(fd)
     ssh_config = ssh_config.lookup(hostname)
     self.hostname = ssh_config['hostname']
     self.username = username or ssh_config.get('user', getuser())
     self.open()
     self.formatter = Formatter()
     self.sudo = ''
     self.cd = None
     self.screen = None
     self.env = {}
     self._sftp = None