• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python providers.provider_factory函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中utils.providers.provider_factory函数的典型用法代码示例。如果您正苦于以下问题:Python provider_factory函数的具体用法?Python provider_factory怎么用?Python provider_factory使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: get_mgmt_system

 def get_mgmt_system(self):
     """ Returns the mgmt_system using the :py:func:`utils.providers.provider_factory` method.
     """
     if self.provider_data is not None:
         return provider_factory(self.provider_data)
     elif self.key is not None:
         return provider_factory(self.key)
     else:
         raise ProviderHasNoKey('Provider %s has no key, so cannot get mgmt system')
开发者ID:seandst,项目名称:cfme_tests,代码行数:9,代码来源:provider.py


示例2: process_provider_vms

def process_provider_vms(provider_key, matchers, delta, vms_to_delete):
    with lock:
        print '%s processing' % provider_key
    try:
        now = datetime.datetime.now()
        provider = provider_factory(provider_key)
        for vm_name in provider.list_vm():
            if not match(matchers, vm_name):
                continue

            try:
                vm_creation_time = provider.vm_creation_time(vm_name)
            except:
                logger.error('Failed to get creation/boot time for %s on %s' % (
                    vm_name, provider_key))
                continue

            if vm_creation_time + delta < now:
                vm_delta = now - vm_creation_time
                with lock:
                    vms_to_delete[provider_key].add((vm_name, vm_delta))
        with lock:
            print '%s finished' % provider_key
    except Exception as ex:
        with lock:
            print '%s failed' % provider_key
        logger.error('failed to process vms from provider %s', provider_key)
        logger.exception(ex)
开发者ID:petrblaho,项目名称:cfme_tests,代码行数:28,代码来源:cleanup_old_vms.py


示例3: get_mgmt_system

 def get_mgmt_system(self):
     """ Returns the mgmt_system using the :py:func:`utils.providers.provider_factory` method.
     """
     if not self.key:
         raise ProviderHasNoKey("Provider %s has no key, so cannot get mgmt system")
     else:
         return provider_factory(self.key)
开发者ID:kbrock,项目名称:cfme_tests,代码行数:7,代码来源:provider.py


示例4: wait_for_provider_or_timeout

    def wait_for_provider_or_timeout(self, provider):
        '''Wait for a provider to become available or timeout trying'''
        ec, tc = wait_for(self.is_quad_icon_available,
                          [provider['name']])
        detail_pg = self.quadicon_region.selected[0].click()

        client = provider_factory(provider['request'])
        host_stats = client.stats('num_datastore',
                                  'num_host',
                                  'num_cluster')
        client.disconnect()
        wait = partial(wait_for,
                       detail_pg.do_stats_match,
                       [host_stats],
                       message="do_stats_match",
                       num_sec=180)
        try:
            ec, tc = wait()
        except TimedOutError:
            # Help him
            assert detail_pg.click_on_refresh_relationships(), "Could not refresh relationships!"
            ec, tc = wait()
        self.header.site_navigation_menu('Infrastructure'). \
            sub_navigation_menu('Providers').click()
        return
开发者ID:jkrocil,项目名称:cfme_tests,代码行数:25,代码来源:providers.py


示例5: provision_appliance

def provision_appliance(version=None, vm_name_prefix='cfme', template=None, provider_name=None):
    """Provisions fresh, unconfigured appliance of a specific version

    Note:
        Version must be mapped to template name under ``appliance_provisioning > versions``
        in ``cfme_data.yaml``.

    Args:
        version: version of appliance to provision
        vm_name_prefix: name prefix to use when deploying the appliance vm

    Returns: Unconfigured appliance; instance of :py:class:`Appliance`

    Usage:
        my_appliance = provision_appliance('5.2.1.8', 'my_tests')
        my_appliance.fix_ntp_clock()
        my_appliance.enable_internal_db()
        my_appliance.wait_for_web_ui()
        or
        my_appliance = provision_appliance('5.2.1.8', 'my_tests')
        my_appliance.configure(patch_ajax_wait=False)
        (identical outcome)
    """

    def _generate_vm_name():
        if version is not None:
            version_digits = ''.join([letter for letter in version if letter.isdigit()])
            return '{}_{}_{}'.format(vm_name_prefix, version_digits, generate_random_string())
        else:
            return '{}_{}'.format(vm_name_prefix, generate_random_string())

    if version is not None:
        templates_by_version = conf.cfme_data['appliance_provisioning']['versions']
        try:
            template_name = templates_by_version[version]
        except KeyError:
            raise ApplianceException('No template found matching version {}'.format(version))

    if template is not None:
        template_name = template

    if provider_name is None:
        provider_name = conf.cfme_data['appliance_provisioning']['provider']
    prov_data = conf.cfme_data['management_systems'][provider_name]

    provider = provider_factory(provider_name)
    vm_name = _generate_vm_name()

    deploy_args = {}
    deploy_args['vm_name'] = vm_name

    if prov_data['type'] == 'rhevm':
        deploy_args['cluster_name'] = prov_data['default_cluster']

    provider.deploy_template(template_name, **deploy_args)

    return Appliance(provider_name, vm_name)
开发者ID:slouderm,项目名称:cfme_tests,代码行数:57,代码来源:appliance.py


示例6: mgmt_sys_api_clients

def mgmt_sys_api_clients(mozwebqa, cfme_data):
    """Returns a list of management system api clients"""
    clients = {}
    for sys_name in cfme_data.data["management_systems"]:
        if sys_name in clients:
            # Overlapping sys_name entry in cfme_data.yaml
            logger.warning("Overriding existing entry for %s." % sys_name)
        clients[sys_name] = provider_factory(sys_name)
    return clients
开发者ID:jwadkins,项目名称:cfme_tests,代码行数:9,代码来源:mgmt_system.py


示例7: power_state_buttons

def power_state_buttons(request, current_provider):
    manager = provider_factory(current_provider)
    vm_name = request.POST["vm_name"]
    power_state = request.POST["power_state"]
    can_power_on = power_state in {Appliance.Power.SUSPENDED, Appliance.Power.OFF}
    can_power_off = power_state in {Appliance.Power.ON}
    can_suspend = power_state in {Appliance.Power.ON} and manager.can_suspend
    can_delete = power_state in {Appliance.Power.OFF}
    return render(request, 'appliances/vms/_buttons.html', locals())
开发者ID:petrblaho,项目名称:cfme_tests,代码行数:9,代码来源:views.py


示例8: __init__

    def __init__(self, provider_name, vm_name):
        """Initializes a deployed appliance VM
        """
        self.name = Appliance._default_name
        self.db_address = None

        self._provider = provider_factory(provider_name)
        self._vm_name = vm_name
        self._address = None
开发者ID:sshveta,项目名称:cfme_tests,代码行数:9,代码来源:appliance.py


示例9: wait_for_provider_or_timeout

    def wait_for_provider_or_timeout(self, provider):
        """Wait for a provider to become available or timeout trying"""
        ec, tc = wait_for(self.is_quad_icon_available, [provider["name"]])
        detail_pg = self.quadicon_region.selected[0].click()

        client = provider_factory(provider["request"])
        host_stats = client.stats("num_template")
        client.disconnect()
        ec, tc = wait_for(detail_pg.do_stats_match, [host_stats], message="do_stats_match", num_sec=300)
        return
开发者ID:jwadkins,项目名称:cfme_tests,代码行数:10,代码来源:__init__.py


示例10: call_provider

def call_provider(provider_name, action, *args):
    # Given a provider class, find the named method and call it with
    # *args. This could possibly be generalized for other CLI tools.
    provider = provider_factory(provider_name)

    try:
        call = getattr(provider, action)
    except AttributeError:
        raise Exception('Action "%s" not found' % action)
    return call(*args)
开发者ID:jwadkins,项目名称:cfme_tests,代码行数:10,代码来源:providers.py


示例11: test_validate_provider_details

    def test_validate_provider_details(self, infra_providers_pg, provider_data):
        prov_pg = infra_providers_pg
        prov_pg.select_provider(provider_data['name'])

        client = provider_factory(provider_data['request'])
        host_stats = client.stats()

        detail_pg = prov_pg.quadicon_region.selected[0].click()
        Assert.true(detail_pg.do_stats_match(host_stats),
            'Host stats should match with mgmt_system stats')
开发者ID:rlandy,项目名称:cfme_tests,代码行数:10,代码来源:test_infrastructure_providers.py


示例12: get_provider_templates

def get_provider_templates(provider_key, templates_providers, thread_lock):
    # functionalized to make it easy to farm this out to threads
    provider_mgmt = provider_factory(provider_key)
    try:
        templates = provider_mgmt.list_template()
        print provider_key, 'returned %d templates' % len(templates)
        with thread_lock:
            for template in templates:
                templates_providers[template].append(provider_key)
    except:
        print provider_key, 'failed'
开发者ID:slouderm,项目名称:cfme_tests,代码行数:11,代码来源:populate_template_tracker.py


示例13: wait_for_provider_or_timeout

    def wait_for_provider_or_timeout(self, provider):
        """Wait for a provider to become available or timeout trying"""
        ec, tc = wait_for(self.is_quad_icon_available, [provider["name"]])
        detail_pg = self.quadicon_region.selected[0].click()

        client = provider_factory(provider["request"])
        host_stats = client.stats("num_datastore", "num_host", "num_cluster")
        client.disconnect()
        ec, tc = wait_for(detail_pg.do_stats_match, [host_stats], message="do_stats_match", num_sec=300)
        self.header.site_navigation_menu("Infrastructure").sub_navigation_menu("Providers").click()
        return
开发者ID:rlandy,项目名称:cfme_tests,代码行数:11,代码来源:providers.py


示例14: vm

def vm(request, setup_a_provider, rest_api):
    if "refresh" not in rest_api.collections.providers.action.all:
        pytest.skip("Refresh action is not implemented in this version")
    provider_mgmt = provider_factory(setup_a_provider.key)
    provider = rest_api.collections.providers.find_by(name=setup_a_provider.name)[0]
    vm_name = deploy_template(
        setup_a_provider.key,
        "test_rest_vm_{}".format(fauxfactory.gen_alphanumeric(length=4)))
    request.addfinalizer(lambda: provider_mgmt.delete_vm(vm_name))
    provider.action.refresh()
    wait_for(
        lambda: len(rest_api.collections.vms.find_by(name=vm_name)) > 0,
        num_sec=600, delay=5)
    return vm_name
开发者ID:seandst,项目名称:cfme_tests,代码行数:14,代码来源:test_rest.py


示例15: vm_action

def vm_action(request, current_provider):
    if not request.user.is_authenticated():
        return HttpResponse("Not authenticated", content_type="text/plain")
    try:
        provider_factory(current_provider)
    except Exception as e:
        return HttpResponse(
            "Troubles with provider {}: {}".format(current_provider, str(e)),
            content_type="text/plain")
    vm_name = request.POST["vm_name"]
    action = request.POST["action"]
    if action == "poweron":
        anyvm_power_on.delay(current_provider, vm_name)
    elif action == "poweroff":
        anyvm_power_off.delay(current_provider, vm_name)
    elif action == "suspend":
        anyvm_suspend.delay(current_provider, vm_name)
    elif action == "delete":
        anyvm_delete.delay(current_provider, vm_name)
    else:
        HttpResponse("No such action {}!".format(action), content_type="text/plain")
    logger().info("User {} initiated {} on {}@{}".format(
        request.user.username, action, vm_name, current_provider))
    return HttpResponse("Action {} was initiated".format(action), content_type="text/plain")
开发者ID:petrblaho,项目名称:cfme_tests,代码行数:24,代码来源:views.py


示例16: main

def main(*providers):
    for provider_key in list_providers('openstack'):
        print 'Checking {}'.format(provider_key)
        api = provider_factory(provider_key).api
        try:
            fips = api.floating_ips.findall(fixed_ip=None)
        except Exception:
            print 'Unable to get fips for {}:'.format(provider_key)
            print format_exc().splitlines()[-1]
            continue

        for fip in fips:
            print 'Deleting {} on {}'.format(fip.ip, provider_key)
            fip.delete()
            print fip.ip, 'deleted'
开发者ID:petrblaho,项目名称:cfme_tests,代码行数:15,代码来源:cleanup_openstack_fips.py


示例17: wait_for_provider_or_timeout

    def wait_for_provider_or_timeout(self, provider):
        '''Wait for a provider to become available or timeout trying'''
        ec, tc = wait_for(self.is_quad_icon_available,
                          [provider['name']])
        detail_pg = self.quadicon_region.selected[0].click()

        client = provider_factory(provider['request'])
        host_stats = client.stats('num_datastore',
                                  'num_host',
                                  'num_cluster')
        client.disconnect()
        ec, tc = wait_for(detail_pg.do_stats_match,
                          [host_stats],
                          message="do_stats_match",
                          num_sec=300)
        return
开发者ID:jwadkins,项目名称:cfme_tests,代码行数:16,代码来源:providers.py


示例18: test_host_provisioning

def test_host_provisioning(infra_hosts_pg, host_provisioning_data, cfme_data, server_roles):

    prov_request_data = host_provisioning_data['provision_request']
    provider_data = cfme_data['management_systems'][prov_request_data['provider']]
    infra_hosts_pg = infra_hosts_pg.header.site_navigation_menu('Infrastructure')\
                                          .sub_navigation_menu('Hosts').click()
    infra_hosts_pg.select_host(host_provisioning_data['host']['name'])
    prov_pg = infra_hosts_pg.click_provision_host()
    tab_buttons = prov_pg.tabbutton_region

    fill_in_request(prov_request_data, provider_data, host_provisioning_data, tab_buttons)
    requests_pg = prov_pg.click_on_submit()

    Assert.equal(requests_pg.flash.message,
                 "Host Request was Submitted, you will be notified when your Hosts are ready",
                 "Flash message should inform of pending notification")
    requests_pg.wait_for_request_status('Last 7 Days', 'Ok', 30)

    infra_hosts_pg = requests_pg.header.site_navigation_menu('Infrastructure')\
                                       .sub_navigation_menu('Hosts').click()
    host_pg = infra_hosts_pg.click_host(host_provisioning_data['host']['name'])
    Assert.equal(host_pg.provider, provider_data['name'],
                 "Provider name does not match")
    Assert.equal(host_pg.cluster, prov_request_data['environment']['cluster'],
                 "Cluster does not match")

    ds_pg = host_pg.click_on_datastores()
    datastores = [ds.title for ds in ds_pg.quadicon_region.quadicons]
    Assert.true(set(prov_request_data['environment']['datastores']).issubset(set(datastores)),
                "Datastores are missing some members")

    mgmt_system = provider_factory(prov_request_data['provider'])
    mgmt_system.remove_host_from_cluster(host_provisioning_data['host']['ipaddress'])

    creds = ds_pg.testsetup.credentials[host_provisioning_data['host']['ipmi_credentials']]
    ipmi = IPMI(host_provisioning_data['host']['ipmi_address'],
                creds['username'], creds['password'], 'lanplus')
    ipmi.power_off()

    infra_hosts_pg = ds_pg.header.site_navigation_menu('Infrastructure')\
                                 .sub_navigation_menu('Hosts').click()
    infra_hosts_pg.select_host(host_provisioning_data['host']['name'])
    infra_hosts_pg.click_remove_host()
    wait_for(lambda func, host: not func(host),
             [infra_hosts_pg.check_host_and_refresh, host_provisioning_data['host']['name']],
             message="wait for host delete")
开发者ID:jkrocil,项目名称:cfme_tests,代码行数:46,代码来源:test_host_provisioning.py


示例19: main

def main(*providers):
    for provider_key in providers:
        print "Cleaning up", provider_key
        api = provider_factory(provider_key).capi
        try:
            volumes = api.volumes.findall(attachments=[])
        except Exception as e:
            print "Connect to provider failed:", provider_key, type(e).__name__, str(e)
            continue

        for volume in volumes:
            if iso8601.parse_date(volume.created_at) < (datetime.now(tz=local_tz) - GRACE_TIME):
                print "Deleting", volume.id
                try:
                    volume.delete()
                except Exception as e:
                    print "Delete failed:", type(e).__name__, str(e)
开发者ID:petrblaho,项目名称:cfme_tests,代码行数:17,代码来源:cleanup_openstack_volumes.py


示例20: cleanup_vms

def cleanup_vms(texts, max_hours=24, providers=None, prompt=True):
    providers = providers or list_all_providers()
    delta = datetime.timedelta(hours=int(max_hours))
    vms_to_delete = defaultdict(set)
    thread_queue = []
    # precompile regexes
    matchers = [re.compile(text) for text in texts]

    for provider_key in providers:
        thread = Thread(target=process_provider_vms,
            args=(provider_key, matchers, delta, vms_to_delete))
        # Mark as daemon thread for easy-mode KeyboardInterrupt handling
        thread.daemon = True
        thread_queue.append(thread)
        thread.start()

    # Join the queued calls
    for thread in thread_queue:
        thread.join()

    for provider_key, vm_set in vms_to_delete.items():
        print '%s:' % provider_key
        for vm_name, vm_delta in vm_set:
            days, hours = vm_delta.days, vm_delta.seconds / 3600
            print ' %s is %d days, %s hours old' % (vm_name, days, hours)

    if vms_to_delete and prompt:
        yesno = raw_input('Delete these VMs? [y/N]: ')
        if str(yesno).lower() != 'y':
            print 'Exiting.'
            return 0

    if not vms_to_delete:
        print 'No VMs to delete.'

    for provider_key, vm_set in vms_to_delete.items():
        provider = provider_factory(provider_key)
        for vm_name, __ in vm_set:
            print 'Deleting %s on %s' % (vm_name, provider_key)
            try:
                provider.delete_vm(vm_name)
            except Exception as ex:
                print 'Failed to delete %s on %s' % (vm_name, provider_key)
                logger.exception(ex)
开发者ID:petrblaho,项目名称:cfme_tests,代码行数:44,代码来源:cleanup_old_vms.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python providers.setup_a_provider函数代码示例发布时间:2022-05-26
下一篇:
Python providers.list_providers函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap