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

Python availability_zones.set_availability_zones函数代码示例

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

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



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

示例1: test_set_availability_zone_unicode_key

 def test_set_availability_zone_unicode_key(self):
     """Test set availability zone cache key is unicode."""
     service = self._create_service_with_topic('network', self.host)
     services = db.service_get_all(self.context)
     az.set_availability_zones(self.context, services)
     self.assertIsInstance(services[0]['host'], six.text_type)
     cached_key = az._make_cache_key(services[0]['host'])
     self.assertIsInstance(cached_key, str)
     self._destroy_service(service)
开发者ID:Juniper,项目名称:nova,代码行数:9,代码来源:test_availability_zones.py


示例2: service_get_all

    def service_get_all(self, context, filters=None, set_zones=False):
        if filters is None:
            filters = {}
        if "availability_zone" in filters:
            zone_filter = filters.pop("availability_zone")
            set_zones = True
        else:
            zone_filter = None
        services = self.cells_rpcapi.service_get_all(context, filters=filters)
        if set_zones:
            services = availability_zones.set_availability_zones(context, services)
            if zone_filter is not None:
                services = [s for s in services if s["availability_zone"] == zone_filter]
        # NOTE(johannes): Cells adds the cell path as a prefix to the id
        # to uniquely identify the service amongst all cells. Unfortunately
        # the object model makes the id an integer. Use a proxy here to
        # work around this particular problem.

        # Split out the cell path first
        cell_paths = []
        for service in services:
            cell_path, id = cells_utils.split_cell_and_item(service["id"])
            service["id"] = id
            cell_paths.append(cell_path)

        # NOTE(danms): Currently cells does not support objects as
        # return values, so just convert the db-formatted service objects
        # to new-world objects here
        services = obj_base.obj_make_list(context, objects.ServiceList(), objects.Service, services)

        # Now wrap it in the proxy with the original cell_path
        services = [ServiceProxy(s, c) for s, c in zip(services, cell_paths)]
        return services
开发者ID:humble00,项目名称:nova,代码行数:33,代码来源:cells_api.py


示例3: _describe_availability_zones_verbose

    def _describe_availability_zones_verbose(self, context, **kwargs):
        ctxt = context.elevated()
        available_zones, not_available_zones = availability_zones.get_availability_zones(ctxt)

        # Available services
        enabled_services = db.service_get_all(context, False)
        enabled_services = availability_zones.set_availability_zones(context, enabled_services)
        zone_hosts = {}
        host_services = {}
        for service in enabled_services:
            zone_hosts.setdefault(service["availability_zone"], [])
            if service["host"] not in zone_hosts[service["availability_zone"]]:
                zone_hosts[service["availability_zone"]].append(service["host"])

            host_services.setdefault(service["availability_zone"] + service["host"], [])
            host_services[service["availability_zone"] + service["host"]].append(service)

        result = []
        for zone in available_zones:
            hosts = {}
            for host in zone_hosts[zone]:
                hosts[host] = {}
                for service in host_services[zone + host]:
                    alive = self.servicegroup_api.service_is_up(service)
                    hosts[host][service["binary"]] = {
                        "available": alive,
                        "active": True != service["disabled"],
                        "updated_at": service["updated_at"],
                    }
            result.append({"zoneName": zone, "zoneState": {"available": True}, "hosts": hosts})

        for zone in not_available_zones:
            result.append({"zoneName": zone, "zoneState": {"available": False}, "hosts": None})
        return {"availabilityZoneInfo": result}
开发者ID:rconradharris,项目名称:nova,代码行数:34,代码来源:availability_zone.py


示例4: get_all

 def get_all(cls, context, disabled=None, set_zones=False):
     db_services = db.service_get_all(context, disabled=disabled)
     if set_zones:
         db_services = availability_zones.set_availability_zones(
             context, db_services)
     return base.obj_make_list(context, cls(context), objects.Service,
                               db_services)
开发者ID:rgerganov,项目名称:nova,代码行数:7,代码来源:service.py


示例5: list

 def list(self, host=None, service=None):
     """
     Show a list of all running services. Filter by host & service name.
     """
     servicegroup_api = servicegroup.API()
     ctxt = context.get_admin_context()
     now = timeutils.utcnow()
     services = db.service_get_all(ctxt)
     services = availability_zones.set_availability_zones(ctxt, services)
     if host:
         services = [s for s in services if s['host'] == host]
     if service:
         services = [s for s in services if s['binary'] == service]
     print_format = "%-16s %-36s %-16s %-10s %-5s %-10s"
     print print_format % (
                 _('Binary'),
                 _('Host'),
                 _('Zone'),
                 _('Status'),
                 _('State'),
                 _('Updated_At'))
     for svc in services:
         alive = servicegroup_api.service_is_up(svc)
         art = (alive and ":-)") or "XXX"
         active = 'enabled'
         if svc['disabled']:
             active = 'disabled'
         print print_format % (svc['binary'], svc['host'],
                               svc['availability_zone'], active, art,
                               svc['updated_at'])
开发者ID:AnyBucket,项目名称:nova,代码行数:30,代码来源:manage.py


示例6: service_get_all

    def service_get_all(self, context, filters=None, set_zones=False):
        if filters is None:
            filters = {}
        if "availability_zone" in filters:
            zone_filter = filters.pop("availability_zone")
            set_zones = True
        else:
            zone_filter = None
        services = self.cells_rpcapi.service_get_all(context, filters=filters)
        if set_zones:
            # TODO(sbauza): set_availability_zones returns flat dicts,
            # we should rather modify the RPC API to amend service_get_all by
            # adding a set_zones argument
            services = availability_zones.set_availability_zones(context, services)
            if zone_filter is not None:
                services = [s for s in services if s["availability_zone"] == zone_filter]

            # NOTE(sbauza): As services is a list of flat dicts, we need to
            # rehydrate the corresponding ServiceProxy objects
            cell_paths = []
            for service in services:
                cell_path, id = cells_utils.split_cell_and_item(service["id"])
                cell_path, host = cells_utils.split_cell_and_item(service["host"])
                service["id"] = id
                service["host"] = host
                cell_paths.append(cell_path)
            services = obj_base.obj_make_list(context, objects.ServiceList(), objects.Service, services)
            services = [cells_utils.ServiceProxy(s, c) for s, c in zip(services, cell_paths)]

        return services
开发者ID:cyx1231st,项目名称:nova,代码行数:30,代码来源:cells_api.py


示例7: test_set_availability_zone_not_compute_service

 def test_set_availability_zone_not_compute_service(self):
     """Test not compute service get right availability zone."""
     service = self._create_service_with_topic('network', self.host)
     services = db.service_get_all(self.context)
     new_service = az.set_availability_zones(self.context, services)[0]
     self.assertEqual(self.default_in_az, new_service['availability_zone'])
     self._destroy_service(service)
开发者ID:Juniper,项目名称:nova,代码行数:7,代码来源:test_availability_zones.py


示例8: index

    def index(self, req):
        """
        Return a list of all running services. Filter by host & service name.
        """
        context = req.environ['nova.context']
        authorize(context)
        now = timeutils.utcnow()
        services = db.service_get_all(context)
        services = availability_zones.set_availability_zones(context, services)

        host = ''
        if 'host' in req.GET:
            host = req.GET['host']
        service = ''
        if 'service' in req.GET:
            service = req.GET['service']
        if host:
            services = [s for s in services if s['host'] == host]
        if service:
            services = [s for s in services if s['binary'] == service]

        svcs = []
        for svc in services:
            delta = now - (svc['updated_at'] or svc['created_at'])
            alive = abs(utils.total_seconds(delta)) <= CONF.service_down_time
            art = (alive and "up") or "down"
            active = 'enabled'
            if svc['disabled']:
                active = 'disabled'
            svcs.append({"binary": svc['binary'], 'host': svc['host'],
                         'zone': svc['availability_zone'],
                         'status': active, 'state': art,
                         'updated_at': svc['updated_at']})
        return {'services': svcs}
开发者ID:NetApp,项目名称:nova,代码行数:34,代码来源:services.py


示例9: _get_service_detail

    def _get_service_detail(self, svc, additional_fields, req):
        alive = self.servicegroup_api.service_is_up(svc)
        state = (alive and "up") or "down"
        active = 'enabled'
        if svc['disabled']:
            active = 'disabled'
        updated_time = self.servicegroup_api.get_updated_time(svc)

        uuid_for_id = api_version_request.is_supported(
            req, min_version=UUID_FOR_ID_MIN_VERSION)

        if 'availability_zone' not in svc:
            # The service wasn't loaded with the AZ so we need to do it here.
            # Yes this looks weird, but set_availability_zones makes a copy of
            # the list passed in and mutates the objects within it, so we have
            # to pull it back out from the resulting copied list.
            svc.availability_zone = (
                availability_zones.set_availability_zones(
                    req.environ['nova.context'],
                    [svc])[0]['availability_zone'])

        service_detail = {'binary': svc['binary'],
                          'host': svc['host'],
                          'id': svc['uuid' if uuid_for_id else 'id'],
                          'zone': svc['availability_zone'],
                          'status': active,
                          'state': state,
                          'updated_at': updated_time,
                          'disabled_reason': svc['disabled_reason']}

        for field in additional_fields:
            service_detail[field] = svc[field]

        return service_detail
开发者ID:mikalstill,项目名称:nova,代码行数:34,代码来源:services.py


示例10: test_set_availability_zone_compute_service

    def test_set_availability_zone_compute_service(self):
        """Test for compute service get right availability zone."""
        service = self._create_service_with_topic("compute", self.host)
        services = db.service_get_all(self.context)

        # The service is not add into aggregate, so confirm it is default
        # availability zone.
        new_service = az.set_availability_zones(self.context, services)[0]
        self.assertEquals(new_service["availability_zone"], self.default_az)

        # The service is added into aggregate, confirm return the aggregate
        # availability zone.
        self._add_to_aggregate(service, self.agg)
        new_service = az.set_availability_zones(self.context, services)[0]
        self.assertEquals(new_service["availability_zone"], self.availability_zone)

        self._destroy_service(service)
开发者ID:kobtea,项目名称:nova,代码行数:17,代码来源:test_availability_zones.py


示例11: test_set_availability_zone_unicode_key

 def test_set_availability_zone_unicode_key(self):
     """Test set availability zone cache key is unicode."""
     service = self._create_service_with_topic('network', self.host)
     services = db.service_get_all(self.context)
     new_service = az.set_availability_zones(self.context, services)[0]
     self.assertEqual(type(services[0]['host']), unicode)
     cached_key = az._make_cache_key(services[0]['host'])
     self.assertEqual(type(cached_key), str)
     self._destroy_service(service)
开发者ID:674009287,项目名称:nova,代码行数:9,代码来源:test_availability_zones.py


示例12: service_get_all

 def service_get_all(self, context, filters=None, set_zones=False):
     if filters is None:
         filters = {}
     if "availability_zone" in filters:
         zone_filter = filters.pop("availability_zone")
         set_zones = True
     else:
         zone_filter = None
     services = self.cells_rpcapi.service_get_all(context, filters=filters)
     if set_zones:
         services = availability_zones.set_availability_zones(context, services)
         if zone_filter is not None:
             services = [s for s in services if s["availability_zone"] == zone_filter]
     return services
开发者ID:tr3buchet,项目名称:nova,代码行数:14,代码来源:cells_api.py


示例13: list

    def list(self, zone=None):
        """Show a list of all physical hosts. Filter by zone.
        args: [zone]"""
        print "%-25s\t%-15s" % (_("host"), _("zone"))
        ctxt = context.get_admin_context()
        services = db.service_get_all(ctxt)
        services = availability_zones.set_availability_zones(ctxt, services)
        if zone:
            services = [s for s in services if s["availability_zone"] == zone]
        hosts = []
        for srv in services:
            if not [h for h in hosts if h["host"] == srv["host"]]:
                hosts.append(srv)

        for h in hosts:
            print "%-25s\t%-15s" % (h["host"], h["availability_zone"])
开发者ID:comstud,项目名称:nova,代码行数:16,代码来源:manage.py


示例14: _list_hosts

def _list_hosts(req):
    """Returns a summary list of hosts, optionally filtering
    by service type.
    """
    context = req.environ['nova.context']
    services = db.service_get_all(context, False)
    services = availability_zones.set_availability_zones(context, services)
    zone = ''
    if 'zone' in req.GET:
        zone = req.GET['zone']
    if zone:
        services = [s for s in services if s['availability_zone'] == zone]
    hosts = []
    for host in services:
        hosts.append({"host_name": host['host'], 'service': host['topic'],
                      'zone': host['availability_zone']})
    return hosts
开发者ID:chiehwen,项目名称:nova,代码行数:17,代码来源:hosts.py


示例15: service_get_all

    def service_get_all(self, context, filters=None, set_zones=False,
                        all_cells=False):
        """Get all services.

        Note that this is the cellsv1 variant, which means we ignore the
        "all_cells" parameter.
        """
        if filters is None:
            filters = {}
        if 'availability_zone' in filters:
            zone_filter = filters.pop('availability_zone')
            set_zones = True
        else:
            zone_filter = None
        services = self.cells_rpcapi.service_get_all(context,
                                                     filters=filters)
        if set_zones:
            # TODO(sbauza): set_availability_zones returns flat dicts,
            # we should rather modify the RPC API to amend service_get_all by
            # adding a set_zones argument
            services = availability_zones.set_availability_zones(context,
                                                                 services)
            if zone_filter is not None:
                services = [s for s in services
                            if s['availability_zone'] == zone_filter]

            # NOTE(sbauza): As services is a list of flat dicts, we need to
            # rehydrate the corresponding ServiceProxy objects
            cell_paths = []
            for service in services:
                cell_path, id = cells_utils.split_cell_and_item(service['id'])
                cell_path, host = cells_utils.split_cell_and_item(
                    service['host'])
                service['id'] = id
                service['host'] = host
                cell_paths.append(cell_path)
            services = obj_base.obj_make_list(context,
                                              objects.ServiceList(),
                                              objects.Service,
                                              services)
            services = [cells_utils.ServiceProxy(s, c)
                        for s, c in zip(services, cell_paths)]

        return services
开发者ID:andymcc,项目名称:nova,代码行数:44,代码来源:cells_api.py


示例16: _get_service_detail

    def _get_service_detail(self, svc, additional_fields, req,
                            cell_down_support=False):
        # NOTE(tssurya): The below logic returns a minimal service construct
        # consisting of only the host, binary and status fields for the compute
        # services in the down cell.
        if (cell_down_support and 'uuid' not in svc):
            return {'binary': svc.binary,
                    'host': svc.host,
                    'status': "UNKNOWN"}

        alive = self.servicegroup_api.service_is_up(svc)
        state = (alive and "up") or "down"
        active = 'enabled'
        if svc['disabled']:
            active = 'disabled'
        updated_time = self.servicegroup_api.get_updated_time(svc)

        uuid_for_id = api_version_request.is_supported(
            req, min_version=UUID_FOR_ID_MIN_VERSION)

        if 'availability_zone' not in svc:
            # The service wasn't loaded with the AZ so we need to do it here.
            # Yes this looks weird, but set_availability_zones makes a copy of
            # the list passed in and mutates the objects within it, so we have
            # to pull it back out from the resulting copied list.
            svc.availability_zone = (
                availability_zones.set_availability_zones(
                    req.environ['nova.context'],
                    [svc])[0]['availability_zone'])

        service_detail = {'binary': svc['binary'],
                          'host': svc['host'],
                          'id': svc['uuid' if uuid_for_id else 'id'],
                          'zone': svc['availability_zone'],
                          'status': active,
                          'state': state,
                          'updated_at': updated_time,
                          'disabled_reason': svc['disabled_reason']}

        for field in additional_fields:
            service_detail[field] = svc[field]

        return service_detail
开发者ID:mahak,项目名称:nova,代码行数:43,代码来源:services.py


示例17: _describe_availability_zones_verbose

    def _describe_availability_zones_verbose(self, context, **kwargs):
        ctxt = context.elevated()
        available_zones, not_available_zones = \
            availability_zones.get_availability_zones(ctxt)

        # Available services
        enabled_services = db.service_get_all(context, False)
        enabled_services = availability_zones.set_availability_zones(context,
                enabled_services)
        zone_hosts = {}
        host_services = {}
        for service in enabled_services:
            zone_hosts.setdefault(service['availability_zone'], [])
            if service['host'] not in zone_hosts[service['availability_zone']]:
                zone_hosts[service['availability_zone']].append(
                    service['host'])

            host_services.setdefault(service['availability_zone'] +
                    service['host'], [])
            host_services[service['availability_zone'] + service['host']].\
                    append(service)

        result = []
        for zone in available_zones:
            hosts = {}
            for host in zone_hosts.get(zone, []):
                hosts[host] = {}
                for service in host_services[zone + host]:
                    alive = self.servicegroup_api.service_is_up(service)
                    hosts[host][service['binary']] = {'available': alive,
                                      'active': True != service['disabled'],
                                      'updated_at': service['updated_at']}
            result.append({'zone_name': zone,
                           'zone_state': {'available': True},
                           "hosts": hosts})

        for zone in not_available_zones:
            result.append({'zone_name': zone,
                           'zone_state': {'available': False},
                           "hosts": None})
        return {'availability_zone_info': result}
开发者ID:B-Rich,项目名称:nova-1,代码行数:41,代码来源:availability_zone.py


示例18: service_get_all

 def service_get_all(self, context, filters=None, set_zones=False):
     if filters is None:
         filters = {}
     if 'availability_zone' in filters:
         zone_filter = filters.pop('availability_zone')
         set_zones = True
     else:
         zone_filter = None
     services = self.cells_rpcapi.service_get_all(context,
                                                  filters=filters)
     if set_zones:
         services = availability_zones.set_availability_zones(context,
                                                              services)
         if zone_filter is not None:
             services = [s for s in services
                         if s['availability_zone'] == zone_filter]
     # NOTE(danms): Currently cells does not support objects as
     # return values, so just convert the db-formatted service objects
     # to new-world objects here
     return obj_base.obj_make_list(context,
                                   service_obj.ServiceList(),
                                   service_obj.Service,
                                   services)
开发者ID:baoguodong,项目名称:nova,代码行数:23,代码来源:cells_api.py


示例19: service_get_all

 def service_get_all(context, filters=None, set_zones=False):
     if set_zones or 'availability_zone' in filters:
         return availability_zones.set_availability_zones(context,
                                                          services)
     return services
开发者ID:B-Rich,项目名称:nova-1,代码行数:5,代码来源:test_services.py


示例20: get_all

 def get_all(cls, context, disabled=None, set_zones=False):
     db_services = db.service_get_all(context, disabled=disabled)
     if set_zones:
         db_services = availability_zones.set_availability_zones(
             context, db_services)
     return _make_list(context, ServiceList(), Service, db_services)
开发者ID:niuzhenguo,项目名称:nova,代码行数:6,代码来源:service.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python block_device.get_device_letter函数代码示例发布时间:2022-05-27
下一篇:
Python availability_zones.reset_cache函数代码示例发布时间: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