當前位置: 首頁>>代碼示例>>Python>>正文


Python config.SSHConfig類代碼示例

本文整理匯總了Python中paramiko.config.SSHConfig的典型用法代碼示例。如果您正苦於以下問題:Python SSHConfig類的具體用法?Python SSHConfig怎麽用?Python SSHConfig使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了SSHConfig類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: main

def main(working_dir=None):
    if working_dir is None:
        return      

    logentriesprovisioning.constants.set_working_dir(working_dir)
    logentriesprovisioning.constants.set_account_key(None)
    logentriesprovisioning.constants.set_logentries_logging()

    if working_dir is None:
        ssh_config_name = 'ssh_config'
    else:
        ssh_config_name = '%s/ssh_config'%working_dir

    env.use_ssh_config = True
    try:
        config_file = file(ssh_config_name)
    except IOError:
        pass
    else:
        config = SSHConfig()
        config.parse(config_file)
        env._ssh_config = config
        for i in range(0,len(config._config)):
            print str(i), ' - ' , config._config[i]

    list_hosts = []
    for host_config in env._ssh_config._config:
        print host_config
        if host_config['host'][0]!='*':
            list_hosts.extend(host_config['host'])

    execute(sync,hosts=list_hosts)
開發者ID:m0wfo,項目名稱:le_aws,代碼行數:32,代碼來源:sync_log.py

示例2: getSSHInfoForHost

def getSSHInfoForHost(host):
    """ Inspired by:
        http://markpasc.typepad.com/blog/2010/04/loading-ssh-config-settings-for-fabric.html """

    from os.path import expanduser
    from paramiko.config import SSHConfig

    key = None
    key_filename = None
    host = host

    def hostinfo(host, config):
        hive = config.lookup(host)
        if 'hostname' in hive:
            host = hive['hostname']
        if 'user' in hive:
            host = '%[email protected]%s' % (hive['user'], host)
        if 'port' in hive:
            host = '%s:%s' % (host, hive['port'])
        return host

    try:
        config_file = file(expanduser('~/.ssh/config'))
    except IOError:
        pass
    else:
        config = SSHConfig()
        config.parse(config_file)
        key = config.lookup(host).get('identityfile', None)
        if key != None: key_filename = expanduser(key)
        host = hostinfo(host, config)
    return key_filename, host
開發者ID:Eonblast,項目名稱:voltdb,代碼行數:32,代碼來源:fabric_ssh_config.py

示例3: _annotate_hosts_with_ssh_config_info

def _annotate_hosts_with_ssh_config_info():
    from os.path import expanduser
    from paramiko.config import SSHConfig

    def hostinfo(host, config):
        hive = config.lookup(host)
        if 'hostname' in hive:
            host = hive['hostname']
        if 'user' in hive:
            host = '%[email protected]%s' % (hive['user'], host)
        if 'port' in hive:
            host = '%s:%s' % (host, hive['port'])
        return host

    try:
        config_file = file(expanduser('~/.ssh/config'))
    except IOError:
        pass
    else:
        config = SSHConfig()
        config.parse(config_file)
        keys = [config.lookup(host).get('identityfile', None)
            for host in env.hosts]
        env.key_filename = [expanduser(key) for key in keys if key is not None]
        env.hosts = [hostinfo(host, config) for host in env.hosts]

        for role, rolehosts in env.roledefs.items():
            env.roledefs[role] = [hostinfo(host, config) for host in rolehosts]
開發者ID:yekeqiang,項目名稱:fabric_project,代碼行數:28,代碼來源:fabfile_ssh_config.py

示例4: annotate_hosts_with_ssh_config_info

def annotate_hosts_with_ssh_config_info():
    """
    Load settings from ~/.ssh/config
    NOTE: Need to define env.hosts first.
    Code from http://markpasc.typepad.com/blog/2010/04/loading-ssh-config-settings-for-fabric.html
    """
    def hostinfo(host, config):
        hive = config.lookup(host)
        if 'user' in hive:
            host = '%[email protected]%s' % (hive['user'], host)
        if 'port' in hive:
            host = '%s:%s' % (host, hive['port'])
        return host

    try:
        config_file = file(expanduser('~/.ssh/config'))
    except IOError:
        pass
    else:
        config = SSHConfig()
        config.parse(config_file)
        keys = [config.lookup(host).get('identityfile', None)
            for host in env.hosts]
        env.key_filename = [key for key in keys if key is not None]
        env.hosts = [hostinfo(host, config) for host in env.hosts]
開發者ID:pombredanne,項目名稱:fabricrecipes,代碼行數:25,代碼來源:common.py

示例5: ssh_config

def ssh_config(host):
    from os.path import expanduser
    from paramiko.config import SSHConfig

    def hostinfo(host, config):
        hive = config.lookup(host)
        if 'hostname' in hive:
            host = hive['hostname']
        if 'user' in hive:
            host = '%[email protected]%s' % (hive['user'], host)
        if 'port' in hive:
            host = '%s:%s' % (host, hive['port'])
        return host

    try:
        config_file = file(expanduser('~/.ssh/config'))
    except IOError:
        pass
    else:
        config = SSHConfig()
        config.parse(config_file)
        key = config.lookup(host).get('identityfile', None)
        key_filename = expanduser(key)
        
        env.key_filename = [key_filename] if key_filename else []
        return hostinfo(host, config)
開發者ID:sunlightlabs,項目名稱:regulations-scraper,代碼行數:26,代碼來源:ssh_util.py

示例6: parse_ssh_config

def parse_ssh_config(file_obj):
    """
    Provided only as a backward-compatible wrapper around L{SSHConfig}.
    """
    config = SSHConfig()
    config.parse(file_obj)
    return config
開發者ID:ufosky-server,項目名稱:MultiversePlatform,代碼行數:7,代碼來源:util.py

示例7: _clone_init_kwargs

 def _clone_init_kwargs(self, *args, **kw):
     # Parent kwargs
     kwargs = super(Config, self)._clone_init_kwargs(*args, **kw)
     # Transmit our internal SSHConfig via explicit-obj kwarg, thus
     # bypassing any file loading. (Our extension of clone() above copies
     # over other attributes as well so that the end result looks consistent
     # with reality.)
     new_config = SSHConfig()
     # TODO: as with other spots, this implies SSHConfig needs a cleaner
     # public API re: creating and updating its core data.
     new_config._config = copy.deepcopy(self.base_ssh_config._config)
     return dict(kwargs, ssh_config=new_config)
開發者ID:fabric,項目名稱:fabric,代碼行數:12,代碼來源:config.py

示例8: __init__

    def __init__(self, hostname, user = None, filename = None):
        #set defaults
        if filename == None:
            filename = os.path.expanduser('~/.ssh/config')

        #read config file
        ssh_config = SSHConfig()
        with open(filename) as config_file:
            ssh_config.parse(config_file)

        self.update(ssh_config.lookup(hostname))

        self.defaults={'port': 22, 'user': getpass.getuser(), 'hostname': hostname, 'hostkeyalias': hostname}

        if user != None:
            self['user'] = user
開發者ID:h8liu,項目名稱:cumulus,代碼行數:16,代碼來源:sftp.py

示例9: loadSshConfig

 def loadSshConfig(self):
     if self._sshConfig is None:
         self._sshConfigStr = self._vagrant.ssh_config(vm_name=self.host)
         configObj = StringIO(self._sshConfigStr)
         self._sshConfig = SSHConfig()
         # noinspection PyTypeChecker
         self._sshConfig.parse(configObj)
         self._sshHostConfig = self._sshConfig.lookup(self.host)
開發者ID:tianshangjun,項目名稱:cloudstack,代碼行數:8,代碼來源:__init__.py

示例10: __init__

    def __init__(self, containers_file, extra_ssh_config_file):

        with open(conf.containers_file()) as infile:
            containers = yaml.load(infile)

        self._containers = []
        self._container_default_config = {}

        self._ssh_config = SSHConfig()
        if extra_ssh_config_file is not None:
            with open(extra_ssh_config_file) as ssh_config_file:
                self._ssh_config.parse(ssh_config_file)

        self._missing_host_key_policy = AutoAddPolicy()

        for container_config in containers:
            if container_config['Host'] == '*':
                self._container_default_config = container_config
                break

        for container_config in containers:
            if container_config['Host'] == '*':
                continue

            container_host = container_config['Host']
            ssh_host_config = self._ssh_config.lookup(container_host)

            ip_address = self._get_hostname_option(container_config)

            container = {
                'Hostname': container_host,
                'Id': container_host,
                'Name': container_host,
                'Labels': {
                    'interface': container_config['Interface'],
                    'type': container_config['Type']
                },
                'State': {
                   'Running': 'running'
                },
                'NetworkSettings': {
                    'IPAddress': ip_address,
                    'MacAddress': None,
                    'Ports': None
                },
                'Config': container_config
            }
            self._containers.append(container)

        self.next_exec_id = 0
        self.ssh_connections = {}
        self.execs = {}
開發者ID:332054781,項目名稱:midonet,代碼行數:52,代碼來源:ssh.py

示例11: open_gateway

    def open_gateway(self):
        """
        Obtain a socket-like object from `gateway`.

        :returns:
            A ``direct-tcpip`` `paramiko.channel.Channel`, if `gateway` was a
            `.Connection`; or a `~paramiko.proxy.ProxyCommand`, if `gateway`
            was a string.

        .. versionadded:: 2.0
        """
        # ProxyCommand is faster to set up, so do it first.
        if isinstance(self.gateway, string_types):
            # Leverage a dummy SSHConfig to ensure %h/%p/etc are parsed.
            # TODO: use real SSH config once loading one properly is
            # implemented.
            ssh_conf = SSHConfig()
            dummy = "Host {}\n    ProxyCommand {}"
            ssh_conf.parse(StringIO(dummy.format(self.host, self.gateway)))
            return ProxyCommand(ssh_conf.lookup(self.host)["proxycommand"])
        # Handle inner-Connection gateway type here.
        # TODO: logging
        self.gateway.open()
        # TODO: expose the opened channel itself as an attribute? (another
        # possible argument for separating the two gateway types...) e.g. if
        # someone wanted to piggyback on it for other same-interpreter socket
        # needs...
        # TODO: and the inverse? allow users to supply their own socket/like
        # object they got via $WHEREEVER?
        # TODO: how best to expose timeout param? reuse general connection
        # timeout from config?
        return self.gateway.transport.open_channel(
            kind="direct-tcpip",
            dest_addr=(self.host, int(self.port)),
            # NOTE: src_addr needs to be 'empty but not None' values to
            # correctly encode into a network message. Theoretically Paramiko
            # could auto-interpret None sometime & save us the trouble.
            src_addr=("", 0),
        )
開發者ID:fabric,項目名稱:fabric,代碼行數:39,代碼來源:connection.py

示例12: main

def main(working_dir=None, cmd='', group_name='AWS'):
    """
    Main function for the module. Calls other functions according to the parameters provided.
    """
    constants.set_working_dir(working_dir)
    constants.set_account_key(None)
    constants.set_logentries_logging()
      
    if working_dir is None:
        ssh_config_name = 'ssh_config'
    else:
        ssh_config_name = '%s/ssh_config'%working_dir

    env.use_ssh_config = True
    try:
        config_file = file(ssh_config_name)
    except IOError:
        pass
    else:
        config = SSHConfig()
        config.parse(config_file)
        env._ssh_config = config

    list_hosts = []
    for host_config in env._ssh_config._config:
        host_name = host_config['host'][0]
        if host_config['host'][0]!='*':
            ssh_config = host_config['config']['hostname']
            logger.info('Found instance ssh config. instance=%s, ssh_config=%s', host_name, ssh_config)
            list_hosts.extend(host_config['host'])

    if cmd == 'deprovision':
        execute(deprovision,hosts=list_hosts)
    elif cmd == 'clean':
        execute(set_instance_host_keys,hosts=list_hosts)
        execute(remove_hosts,group_name,hosts=list_hosts)
    elif cmd == '':
        execute(sync,hosts=list_hosts)
開發者ID:StephenHynes7,項目名稱:le_aws,代碼行數:38,代碼來源:sync_log.py

示例13: annotate_from_sshconfig

def annotate_from_sshconfig(env):
    """
    Adds support for reading the host names, users and ports from ~/ssh/config

    Replaces the hosts defined in ssh config with actual host names, so that Fabric
    can take the advantage from it

    .. IMPORTANT:: This does not support /etc/ssh/ssh_config yet!

    """
    from os.path import expanduser
    from paramiko.config import SSHConfig

    def hostinfo(host, config):
        hive = config.lookup(host)
        if "hostname" in hive:
            host = hive["hostname"]
        if "user" in hive:
            host = "%[email protected]%s" % (hive["user"], host)
        if "port" in hive:
            host = "%s:%s" % (host, hive["port"])
        return host

    # Look for user config, if found, parse it and update roledefs. Otherwise just ignore it (it is not required at all)
    try:
        config_file = file(expanduser("~/.ssh/config"))
    except IOError:
        pass
    else:
        config = SSHConfig()
        config.parse(config_file)
        keys = [config.lookup(host).get("identityfile", None) for host in api.env.hosts]
        env.key_filename = [expanduser(key) for key in keys if key is not None]
        env.hosts = [hostinfo(host, config) for host in env.hosts]

        for role, rolehosts in env.roledefs.items():
            env.roledefs[role] = [hostinfo(host, config) for host in rolehosts]
開發者ID:nagyistoce,項目名稱:trac-multiproject,代碼行數:37,代碼來源:base.py

示例14: _annotate_hosts_with_ssh_config_info

def _annotate_hosts_with_ssh_config_info(path):
    from os.path import expanduser
    from paramiko.config import SSHConfig

    def hostinfo(host, config):
        hive = config.lookup(host)
        # if 'hostname' in hive:
           # host = hive['hostname']
        if 'user' in hive:
            host = '%[email protected]%s' % (hive['user'], host)
        if 'port' in hive:
            host = '%s:%s' % (host, hive['port'])
        #print 'hive',hive
        #print 'host',host
        return host

    try:
        config_file = file(expanduser(path))
    except IOError:
        pass
    else:
        config = SSHConfig()
        config.parse(config_file)

        # add hosts from ssh config to env.host & sort + unique
        env.hosts.extend([h for h in config.get_hostnames() if len(h) > 1])
        env.hosts = sorted(set(env.hosts))

        keys = [config.lookup(host).get('identityfile', None) for host in env.hosts]
        # flatten
        keys = [item for sublist in keys  if sublist is not None for item in sublist]
        env.key_filename = [expanduser(key) for key in keys if key is not None]
        env.hosts = [hostinfo(host, config) for host in env.hosts]

        for role, rolehosts in env.roledefs.items():
            env.roledefs[role] = [hostinfo(host, config) for host in rolehosts]
開發者ID:epcim,項目名稱:fabfile,代碼行數:36,代碼來源:__init__.py

示例15: _annotate_hosts_with_ssh_config_info

    def _annotate_hosts_with_ssh_config_info():
        from os.path import expanduser
        from paramiko.config import SSHConfig

        def hostinfo(host, config):
            hive = config.lookup(host)
            if "hostname" in hive:
                host = hive["hostname"]
            if "user" in hive:
                host = "%[email protected]%s" % (hive["user"], host)
            if "port" in hive:
                host = "%s:%s" % (host, hive["port"])
            return host

        try:
            config_file = file(expanduser("~/.ssh/config"))
        except IOError:
            pass
        else:
            config = SSHConfig()
            config.parse(config_file)
            keys = [config.lookup(host).get("identityfile", None) for host in env.hosts]
            env.key_filename = [expanduser(key) for key in keys if key is not None]
            env.hosts = [hostinfo(host, config) for host in env.hosts]
開發者ID:bennomadic,項目名稱:django-coop,代碼行數:24,代碼來源:fabfile.py


注:本文中的paramiko.config.SSHConfig類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。