コード例 #1
0
 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)
コード例 #2
0
ファイル: cells_api.py プロジェクト: humble00/nova
    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
コード例 #3
0
    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}
コード例 #4
0
ファイル: service.py プロジェクト: rgerganov/nova
 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)
コード例 #5
0
ファイル: manage.py プロジェクト: AnyBucket/nova
 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'])
コード例 #6
0
ファイル: cells_api.py プロジェクト: cyx1231st/nova
    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
コード例 #7
0
 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)
コード例 #8
0
ファイル: services.py プロジェクト: NetApp/nova
    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}
コード例 #9
0
ファイル: services.py プロジェクト: mikalstill/nova
    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
コード例 #10
0
    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)
コード例 #11
0
 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)
コード例 #12
0
ファイル: cells_api.py プロジェクト: tr3buchet/nova
 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
コード例 #13
0
ファイル: manage.py プロジェクト: comstud/nova
    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"])
コード例 #14
0
ファイル: hosts.py プロジェクト: chiehwen/nova
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
コード例 #15
0
ファイル: cells_api.py プロジェクト: andymcc/nova
    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
コード例 #16
0
ファイル: services.py プロジェクト: mahak/nova
    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
コード例 #17
0
ファイル: availability_zone.py プロジェクト: B-Rich/nova-1
    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}
コード例 #18
0
ファイル: manage.py プロジェクト: comstud/nova
 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"])
コード例 #19
0
ファイル: cells_api.py プロジェクト: baoguodong/nova
 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)
コード例 #20
0
ファイル: test_services.py プロジェクト: B-Rich/nova-1
 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
コード例 #21
0
ファイル: service.py プロジェクト: niuzhenguo/nova
 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)
コード例 #22
0
ファイル: service.py プロジェクト: xzj675/nova
 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, ServiceList(), Service, db_services)
コード例 #23
0
ファイル: test_services.py プロジェクト: mnaser/nova-1
 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
コード例 #24
0
ファイル: test_services.py プロジェクト: Charu-Sharma/nova
def fake_host_api_service_get_all(context, filters=None, set_zones=False):
    if set_zones or 'availability_zone' in filters:
        return availability_zones.set_availability_zones(context,
                                                         fake_services_list)
コード例 #25
0
ファイル: test_services.py プロジェクト: bopopescu/novatest-1
def fake_host_api_service_get_all(context, filters=None, set_zones=False):
    if set_zones or 'availability_zone' in filters:
        return availability_zones.set_availability_zones(
            context, fake_services_list)