当前位置: 首页>>代码示例>>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;未经允许,请勿转载。