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

Python utils.service_is_up函数代码示例

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

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



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

示例1: test_create_share_availability_zone

    def test_create_share_availability_zone(self):
        share_id = 'fake'
        fake_share = {'id': share_id,
                      'availability_zone': 'fake:fake',
                      'size': 1}

        fake_service_1 = {'disabled': False, 'host': 'fake_host1',
                          'availability_zone': 'fake'}

        fake_service_2 = {'disabled': False, 'host': 'fake_host2',
                          'availability_zone': 'super_fake'}

        fake_result = [(fake_service_1, 0), (fake_service_2, 1)]

        fake_request_spec = {'share_id': share_id,
                             'share_properties': fake_share}

        self.mox.StubOutWithMock(utils, 'service_is_up')
        self.mox.StubOutWithMock(driver, 'share_update_db')
        self.mox.StubOutWithMock(db, 'service_get_all_share_sorted')

        db.service_get_all_share_sorted(IsA(context.RequestContext))\
            .AndReturn(fake_result)

        utils.service_is_up(fake_service_1).AndReturn(True)
        driver.share_update_db(IsA(context.RequestContext), share_id,
                               fake_service_1['host']).AndReturn(fake_share)

        self.mox.ReplayAll()
        self.driver.schedule_create_share(self.context, fake_request_spec, {})
开发者ID:aostapenko,项目名称:manila,代码行数:30,代码来源:test_scheduler.py


示例2: test_service_is_up

    def test_service_is_up(self):
        fts_func = datetime.datetime.fromtimestamp
        fake_now = 1000
        down_time = 5
        self.flags(service_down_time=down_time)
        with mock.patch.object(timeutils, 'utcnow',
                               mock.Mock(return_value=fts_func(fake_now))):

            # Up (equal)
            service = {'updated_at': fts_func(fake_now - down_time),
                       'created_at': fts_func(fake_now - down_time)}
            result = utils.service_is_up(service)
            self.assertTrue(result)
            timeutils.utcnow.assert_called_once_with()

        with mock.patch.object(timeutils, 'utcnow',
                               mock.Mock(return_value=fts_func(fake_now))):
            # Up
            service = {'updated_at': fts_func(fake_now - down_time + 1),
                       'created_at': fts_func(fake_now - down_time + 1)}
            result = utils.service_is_up(service)
            self.assertTrue(result)
            timeutils.utcnow.assert_called_once_with()

        with mock.patch.object(timeutils, 'utcnow',
                               mock.Mock(return_value=fts_func(fake_now))):
            # Down
            service = {'updated_at': fts_func(fake_now - down_time - 1),
                       'created_at': fts_func(fake_now - down_time - 1)}
            result = utils.service_is_up(service)
            self.assertFalse(result)
            timeutils.utcnow.assert_called_once_with()
开发者ID:vladiskuz,项目名称:manila,代码行数:32,代码来源:test_utils.py


示例3: test_create_share_if_two_services_up

    def test_create_share_if_two_services_up(self):
        share_id = 'fake'
        fake_share = {'id': share_id, 'size': 1}

        fake_service_1 = {'disabled': False, 'host': 'fake_host1'}

        fake_service_2 = {'disabled': False, 'host': 'fake_host2'}

        fake_result = [(fake_service_1, 2), (fake_service_2, 1)]

        self.mox.StubOutWithMock(db, 'service_get_all_share_sorted')
        self.mox.StubOutWithMock(utils, 'service_is_up')
        self.mox.StubOutWithMock(driver, 'share_update_db')

        fake_request_spec = {'share_id': share_id,
                             'share_properties': fake_share}

        db.service_get_all_share_sorted(IsA(context.RequestContext))\
            .AndReturn(fake_result)
        utils.service_is_up(IsA(dict)).AndReturn(True)
        driver.share_update_db(IsA(context.RequestContext), share_id,
                               'fake_host1').AndReturn(fake_share)
        self.mox.ReplayAll()

        self.driver.schedule_create_share(self.context, fake_request_spec, {})
开发者ID:aostapenko,项目名称:manila,代码行数:25,代码来源:test_scheduler.py


示例4: test_service_is_up

    def test_service_is_up(self):
        fts_func = datetime.datetime.fromtimestamp
        fake_now = 1000
        down_time = 5

        self.flags(service_down_time=down_time)
        self.mox.StubOutWithMock(timeutils, 'utcnow')

        # Up (equal)
        timeutils.utcnow().AndReturn(fts_func(fake_now))
        service = {'updated_at': fts_func(fake_now - down_time),
                   'created_at': fts_func(fake_now - down_time)}
        self.mox.ReplayAll()
        result = utils.service_is_up(service)
        self.assertTrue(result)

        self.mox.ResetAll()
        # Up
        timeutils.utcnow().AndReturn(fts_func(fake_now))
        service = {'updated_at': fts_func(fake_now - down_time + 1),
                   'created_at': fts_func(fake_now - down_time + 1)}
        self.mox.ReplayAll()
        result = utils.service_is_up(service)
        self.assertTrue(result)

        self.mox.ResetAll()
        # Down
        timeutils.utcnow().AndReturn(fts_func(fake_now))
        service = {'updated_at': fts_func(fake_now - down_time - 1),
                   'created_at': fts_func(fake_now - down_time - 1)}
        self.mox.ReplayAll()
        result = utils.service_is_up(service)
        self.assertFalse(result)
开发者ID:aostapenko,项目名称:manila,代码行数:33,代码来源:test_utils.py


示例5: schedule_create_share

    def schedule_create_share(self, context, request_spec, filter_properties):
        """Picks a host that is up and has the fewest shares."""
        # TODO(rushiagr) - pick only hosts that run shares
        elevated = context.elevated()

        share_id = request_spec.get('share_id')
        snapshot_id = request_spec.get('snapshot_id')
        share_properties = request_spec.get('share_properties')
        share_size = share_properties.get('size')
        availability_zone = share_properties.get('availability_zone')

        zone, host = None, None
        if availability_zone:
            zone, _x, host = availability_zone.partition(':')
        if host and context.is_admin:
            service = db.service_get_by_args(elevated, host, CONF.share_topic)
            if not utils.service_is_up(service):
                raise exception.WillNotSchedule(host=host)
            updated_share = driver.share_update_db(context, share_id, host)
            self.share_rpcapi.create_share_instance(
                context,
                updated_share.instance,
                host,
                request_spec,
                None,
                snapshot_id=snapshot_id
            )
            return None

        results = db.service_get_all_share_sorted(elevated)
        if zone:
            results = [(service_g, gigs) for (service_g, gigs) in results
                       if service_g['availability_zone'] == zone]
        for result in results:
            (service, share_gigabytes) = result
            if share_gigabytes + share_size > CONF.max_gigabytes:
                msg = _("Not enough allocatable share gigabytes remaining")
                raise exception.NoValidHost(reason=msg)
            if utils.service_is_up(service) and not service['disabled']:
                updated_share = driver.share_update_db(context, share_id,
                                                       service['host'])
                self.share_rpcapi.create_share_instance(
                    context,
                    updated_share.instance,
                    service['host'],
                    request_spec,
                    None,
                    snapshot_id=snapshot_id)
                return None
        msg = _("Is the appropriate service running?")
        raise exception.NoValidHost(reason=msg)
开发者ID:alinbalutoiu,项目名称:manila,代码行数:51,代码来源:simple.py


示例6: hosts_up

    def hosts_up(self, context, topic):
        """Return the list of hosts that have a running service for topic."""

        services = db.service_get_all_by_topic(context, topic)
        return [service['host']
                for service in services
                if utils.service_is_up(service)]
开发者ID:aawm,项目名称:manila,代码行数:7,代码来源:driver.py


示例7: _update_host_state_map

    def _update_host_state_map(self, context):

        # Get resource usage across the available share nodes:
        topic = CONF.share_topic
        share_services = db.service_get_all_by_topic(context, topic)

        for service in share_services:
            host = service['host']

            # Warn about down services and remove them from host_state_map
            if not utils.service_is_up(service) or service['disabled']:
                LOG.warning(_LW("Share service is down. (host: %s).") % host)
                if self.host_state_map.pop(host, None):
                    LOG.info(_LI("Removing non-active host: %s from "
                                 "scheduler cache.") % host)
                continue

            # Create and register host_state if not in host_state_map
            capabilities = self.service_states.get(host, None)
            host_state = self.host_state_map.get(host)
            if not host_state:
                host_state = self.host_state_cls(
                    host,
                    capabilities=capabilities,
                    service=dict(six.iteritems(service)))
                self.host_state_map[host] = host_state

            # Update capabilities and attributes in host_state
            host_state.update_from_share_capability(
                capabilities, service=dict(six.iteritems(service)))
开发者ID:jkasarherou,项目名称:manila,代码行数:30,代码来源:host_manager.py


示例8: get_all_host_states_share

    def get_all_host_states_share(self, context):
        """Returns a dict of all the hosts the HostManager
          knows about. Also, each of the consumable resources in HostState
          are pre-populated and adjusted based on data in the db.

          For example:
          {'192.168.1.100': HostState(), ...}
        """

        # Get resource usage across the available share nodes:
        topic = CONF.share_topic
        share_services = db.service_get_all_by_topic(context, topic)
        for service in share_services:
            if not utils.service_is_up(service) or service['disabled']:
                LOG.warn(_("service is down or disabled."))
                continue
            host = service['host']
            capabilities = self.service_states.get(host, None)
            host_state = self.host_state_map.get(host)
            if host_state:
                # copy capabilities to host_state.capabilities
                host_state.update_capabilities(capabilities,
                                               dict(six.iteritems(service)))
            else:
                host_state = self.host_state_cls(
                    host,
                    capabilities=capabilities,
                    service=dict(six.iteritems(service)))
                self.host_state_map[host] = host_state
            # update host_state
            host_state.update_from_share_capability(capabilities)

        return self.host_state_map.itervalues()
开发者ID:mbr4v0v,项目名称:manila,代码行数:33,代码来源:host_manager.py


示例9: list

 def list(self):
     """Show a list of all manila services."""
     ctxt = context.get_admin_context()
     services = db.service_get_all(ctxt)
     print_format = "%-16s %-36s %-16s %-10s %-5s %-10s"
     print(print_format % (
         _('Binary'),
         _('Host'),
         _('Zone'),
         _('Status'),
         _('State'),
         _('Updated At'))
     )
     for svc in services:
         alive = utils.service_is_up(svc)
         art = ":-)" if alive else "XXX"
         status = 'enabled'
         if svc['disabled']:
             status = 'disabled'
         print(print_format % (
             svc['binary'],
             svc['host'].partition('.')[0],
             svc['availability_zone']['name'],
             status,
             art,
             svc['updated_at'],
         ))
开发者ID:openstack,项目名称:manila,代码行数:27,代码来源:manage.py


示例10: test_hosts_up

    def test_hosts_up(self):
        service1 = {'host': 'host1'}
        service2 = {'host': 'host2'}
        services = [service1, service2]

        self.mox.StubOutWithMock(db, 'service_get_all_by_topic')
        self.mox.StubOutWithMock(utils, 'service_is_up')

        db.service_get_all_by_topic(self.context,
                                    self.topic).AndReturn(services)
        utils.service_is_up(service1).AndReturn(False)
        utils.service_is_up(service2).AndReturn(True)

        self.mox.ReplayAll()
        result = self.driver.hosts_up(self.context, self.topic)
        self.assertEqual(result, ['host2'])
开发者ID:aostapenko,项目名称:manila,代码行数:16,代码来源:test_scheduler.py


示例11: test_create_share_availability_zone_if_service_down

    def test_create_share_availability_zone_if_service_down(self):
        share_id = 'fake'
        fake_share = {'id': share_id,
                      'availability_zone': 'fake:fake',
                      'size': 1}

        fake_request_spec = {'share_id': share_id,
                             'share_properties': fake_share}

        self.mox.StubOutWithMock(utils, 'service_is_up')
        self.mox.StubOutWithMock(db, 'service_get_by_args')

        db.service_get_by_args(IsA(context.RequestContext), 'fake',
                               'manila-share').AndReturn('fake_service')
        utils.service_is_up('fake_service').AndReturn(False)

        self.mox.ReplayAll()
        self.assertRaises(exception.WillNotSchedule,
                          self.driver.schedule_create_share,
                          self.admin_context, fake_request_spec, {})
开发者ID:aostapenko,项目名称:manila,代码行数:20,代码来源:test_scheduler.py


示例12: test_create_share_availability_zone_on_host

    def test_create_share_availability_zone_on_host(self):
        share_id = 'fake'
        fake_share = {'id': share_id,
                      'availability_zone': 'fake:fake',
                      'size': 1}

        fake_request_spec = {'share_id': share_id,
                             'share_properties': fake_share}

        self.mox.StubOutWithMock(utils, 'service_is_up')
        self.mox.StubOutWithMock(db, 'service_get_by_args')
        self.mox.StubOutWithMock(driver, 'share_update_db')

        db.service_get_by_args(IsA(context.RequestContext), 'fake',
                               'manila-share').AndReturn('fake_service')
        utils.service_is_up('fake_service').AndReturn(True)
        driver.share_update_db(IsA(context.RequestContext), share_id,
                               'fake').AndReturn(fake_share)

        self.mox.ReplayAll()
        self.driver.schedule_create_share(self.admin_context,
                                          fake_request_spec, {})
开发者ID:aostapenko,项目名称:manila,代码行数:22,代码来源:test_scheduler.py


示例13: list

 def list(self):
     """Show a list of all manila services."""
     ctxt = context.get_admin_context()
     services = db.service_get_all(ctxt)
     print_format = "%-16s %-36s %-16s %-10s %-5s %-10s"
     print(print_format % (_("Binary"), _("Host"), _("Zone"), _("Status"), _("State"), _("Updated At")))
     for svc in services:
         alive = utils.service_is_up(svc)
         art = ":-)" if alive else "XXX"
         status = "enabled"
         if svc["disabled"]:
             status = "disabled"
         print(
             print_format
             % (
                 svc["binary"],
                 svc["host"].partition(".")[0],
                 svc["availability_zone"]["name"],
                 status,
                 art,
                 svc["updated_at"],
             )
         )
开发者ID:ajarr,项目名称:manila,代码行数:23,代码来源:manage.py


示例14: schedule_create_share

    def schedule_create_share(self, context, request_spec, filter_properties):
        """Picks a host that is up and has the fewest shares."""
        # TODO(rushiagr) - pick only hosts that run shares
        elevated = context.elevated()

        share_id = request_spec.get('share_id')
        snapshot_id = request_spec.get('snapshot_id')
        share_properties = request_spec.get('share_properties')
        share_size = share_properties.get('size')

        instance_properties = request_spec.get('share_instance_properties', {})
        availability_zone_id = instance_properties.get('availability_zone_id')

        results = db.service_get_all_share_sorted(elevated)
        if availability_zone_id:
            results = [(service_g, gigs) for (service_g, gigs) in results
                       if (service_g['availability_zone_id']
                           == availability_zone_id)]
        for result in results:
            (service, share_gigabytes) = result
            if share_gigabytes + share_size > CONF.max_gigabytes:
                msg = _("Not enough allocatable share gigabytes remaining")
                raise exception.NoValidHost(reason=msg)
            if utils.service_is_up(service) and not service['disabled']:
                updated_share = base.share_update_db(context,
                                                     share_id,
                                                     service['host'])
                self.share_rpcapi.create_share_instance(
                    context,
                    updated_share.instance,
                    service['host'],
                    request_spec,
                    None,
                    snapshot_id=snapshot_id)
                return None
        msg = _("Is the appropriate service running?")
        raise exception.NoValidHost(reason=msg)
开发者ID:ISCAS-VDI,项目名称:manila-base,代码行数:37,代码来源:simple.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python version.version_string函数代码示例发布时间:2022-05-27
下一篇:
Python utils.last_completed_audit_period函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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