当前位置: 首页>>代码示例>>Python>>正文


Python SSHClient.run_rails_console方法代码示例

本文整理汇总了Python中utils.ssh.SSHClient.run_rails_console方法的典型用法代码示例。如果您正苦于以下问题:Python SSHClient.run_rails_console方法的具体用法?Python SSHClient.run_rails_console怎么用?Python SSHClient.run_rails_console使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在utils.ssh.SSHClient的用法示例。


在下文中一共展示了SSHClient.run_rails_console方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: add_provider

# 需要导入模块: from utils.ssh import SSHClient [as 别名]
# 或者: from utils.ssh.SSHClient import run_rails_console [as 别名]
def add_provider(provider):
    """Adds a provider via the REST API."""
    logger.vdebug('Adding Provider: {}, Type: {}'.format(provider['name'], provider['type']))

    data_dict = {
        "action": "create",
        "resources": [{
            "name": provider['name'],
            "type": provider['type'],
            "credentials": [{
                "userid": provider['credentials']['username'],
                "password": provider['credentials']['password']
            }]
        }]
    }

    if 'ip_address' in provider:
        data_dict['resources'][0]['hostname'] = provider['ip_address']

    if (provider['type'] == 'ManageIQ::Providers::Amazon::CloudManager' or
    provider['type'] == 'ManageIQ::Providers::Google::CloudManager'):
        data_dict['resources'][0]['provider_region'] = provider['provider_region']

    if 'metrics_credentials' in provider:
        data_dict['resources'][0]['credentials'].append({
            "userid": provider['metrics_credentials']['username'],
            "password": provider['metrics_credentials']['password'],
            "auth_type": "metrics"
        })
    elif 'password_credentials' in provider:
        data_dict['resources'][0]['credentials'].append({
            "userid": provider['password_credentials']['username'],
            "password": provider['password_credentials']['password'],
            "auth_type": "password"
        })
    elif 'bearer_credentials' in provider:
        data_dict['resources'][0]['credentials'].append({
            "userid": provider['bearer_credentials']['username'],
            "password": provider['bearer_credentials']['password'],
            "auth_type": "bearer"
        })
    elif 'amqp_credentials' in provider:
        data_dict['resources'][0]['credentials'].append({
            "userid": provider['amqp_credentials']['username'],
            "password": provider['amqp_credentials']['password'],
            "auth_type": "amqp"
        })
    elif 'ssh_keypair_credentials' in provider:
        data_dict['resources'][0]['credentials'].append({
            "userid": provider['ssh_keypair_credentials']['username'],
            "password": provider['ssh_keypair_credentials']['password'],
            "auth_type": "ssh_keypair"
        })

    json_data = json.dumps(data_dict)
    appliance = cfme_performance['appliance']['ip_address']
    response = requests.post("https://" + appliance + "/api/providers",
                             data=json_data,
                             auth=(cfme_performance['appliance']['rest_api']['username'],
                                   cfme_performance['appliance']['rest_api']['password']),
                             verify=False,
                             headers={"content-type": "application/json"},
                             allow_redirects=False)

    logger.debug('Added Provider: {}, Response: {}'.format(provider['name'], response))

    # Workaround for Bug: https://bugzilla.redhat.com/show_bug.cgi?id=1351253
    if provider['type'] == "ManageIQ::Providers::Microsoft::InfraManager":
        logger.debug('Running rails command for Microsoft InfraManager Workaround')
        ssh_client = SSHClient()
        command = (
            'm = ExtManagementSystem.find_by_name \'{}\';'
            'attributes = {{:security_protocol => \'{}\'}};'
            'm.update_authentication(:default => {{:userid => \'{}\', :password => \'{}\'}});'
            'm.update_attributes(attributes);'
            'm.save;'
            'm.authentication_check;'.format(provider['name'], provider['security_protocol'],
                provider['credentials']['username'].replace('\\', '\\\\'),
                provider['credentials']['password']))
        ssh_client.run_rails_console(command, timeout=None, log_less=True)

    # Workaround for Bug: https://bugzilla.redhat.com/show_bug.cgi?id=1351253
    if provider['type'] == 'ManageIQ::Providers::Openstack::CloudManager':
        logger.debug('Running rails command for Openstack CloudManager Workaround')
        ssh_client = SSHClient()
        command = (
            'e = ExtManagementSystem.find_by_name \'{}\'; '
            'attributes = {{:security_protocol => \'{}\', :port => \'{}\'}}; '
            'e.update_authentication(:default => {{:userid => \'{}\', :password => \'{}\'}}); '
            'e.update_attributes(attributes); '
            'e.save; '
            'e.authentication_check;'.format(
                provider['name'], provider['credentials']['security_protocol'],
                provider['credentials']['port'], provider['credentials']['username'],
                provider['credentials']['password']))
        if 'amqp_credentials' in provider:
            default_ip = provider['ip_address']
            default_port = provider['credentials']['port']
            default_user = provider['credentials']['username']
            default_pass = provider['credentials']['password']
#.........这里部分代码省略.........
开发者ID:MattLombana,项目名称:cfme-performance,代码行数:103,代码来源:providers.py


注:本文中的utils.ssh.SSHClient.run_rails_console方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。