Esempio n. 1
0
    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
Esempio n. 2
0
    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
Esempio n. 3
0
    def _validate_id(req, hypervisor_id):
        """Validates that the id is a uuid for microversions that require it.

        :param req: The HTTP request object which contains the requested
            microversion information.
        :param hypervisor_id: The provided hypervisor id.
        :raises: webob.exc.HTTPBadRequest if the requested microversion is
            greater than or equal to 2.53 and the id is not a uuid.
        :raises: webob.exc.HTTPNotFound if the requested microversion is
            less than 2.53 and the id is not an integer.
        """
        expect_uuid = api_version_request.is_supported(
            req, min_version=UUID_FOR_ID_MIN_VERSION)
        if expect_uuid:
            if not uuidutils.is_uuid_like(hypervisor_id):
                msg = _('Invalid uuid %s') % hypervisor_id
                raise webob.exc.HTTPBadRequest(explanation=msg)
        else:
            # This API is supported for cells v1 and as such the id can be
            # a cell v1 delimited string, so we have to parse it first.
            if cells_utils.CELL_ITEM_SEP in str(hypervisor_id):
                hypervisor_id = cells_utils.split_cell_and_item(
                    hypervisor_id)[1]
            try:
                utils.validate_integer(hypervisor_id, 'id')
            except exception.InvalidInput:
                msg = (_("Hypervisor with ID '%s' could not be found.") %
                       hypervisor_id)
                raise webob.exc.HTTPNotFound(explanation=msg)
Esempio n. 4
0
 def compute_node_get(self, ctxt, compute_id):
     """Get a compute node by ID in a specific cell."""
     cell_name, compute_id = cells_utils.split_cell_and_item(compute_id)
     response = self.msg_runner.compute_node_get(ctxt, cell_name, compute_id)
     node = response.value_or_raise()
     node = cells_utils.add_cell_to_compute_node(node, cell_name)
     return node
Esempio n. 5
0
    def task_log_get_all(self, ctxt, task_name, period_beginning,
                         period_ending, host=None, state=None):
        """Get task logs from the DB from all cells or a particular
        cell.

        If 'host' is not None, host will be of the format 'cell!name@host',
        with '@host' being optional.  The query will be directed to the
        appropriate cell and return all task logs, or task logs matching
        the host if specified.

        'state' also may be None.  If it's not, filter by the state as well.
        """
        if host is None:
            cell_name = None
        else:
            cell_name, host = cells_utils.split_cell_and_item(host)
            # If no cell name was given, assume that the host name is the
            # cell_name and that the target is all hosts
            if cell_name is None:
                cell_name, host = host, cell_name
        responses = self.msg_runner.task_log_get_all(ctxt, cell_name,
                task_name, period_beginning, period_ending,
                host=host, state=state)
        # 1 response per cell.  Each response is a list of task log
        # entries.
        ret_task_logs = []
        for response in responses:
            task_logs = response.value_or_raise()
            for task_log in task_logs:
                cells_utils.add_cell_to_task_log(task_log,
                                                 response.cell_name)
                ret_task_logs.append(task_log)
        return ret_task_logs
Esempio n. 6
0
 def proxy_rpc_to_manager(self, ctxt, topic, rpc_message, call, timeout):
     """Proxy an RPC message as-is to a manager."""
     compute_topic = CONF.compute_topic
     cell_and_host = topic[len(compute_topic) + 1 :]
     cell_name, host_name = cells_utils.split_cell_and_item(cell_and_host)
     response = self.msg_runner.proxy_rpc_to_manager(ctxt, cell_name, host_name, topic, rpc_message, call, timeout)
     return response.value_or_raise()
Esempio n. 7
0
 def service_get_by_compute_host(self, ctxt, host_name):
     """Return a service entry for a compute host in a certain cell."""
     cell_name, host_name = cells_utils.split_cell_and_item(host_name)
     response = self.msg_runner.service_get_by_compute_host(ctxt, cell_name, host_name)
     service = response.value_or_raise()
     service = cells_utils.add_cell_to_service(service, response.cell_name)
     return service
Esempio n. 8
0
    def get_host_uptime(self, ctxt, host_name):
        """Return host uptime for a compute host in a certain cell

        :param host_name: fully qualified hostname. It should be in format of
         parent!child@host_id
        """
        cell_name, host_name = cells_utils.split_cell_and_item(host_name)
        response = self.msg_runner.get_host_uptime(ctxt, cell_name, host_name)
        return response.value_or_raise()
Esempio n. 9
0
    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
Esempio n. 10
0
    def test_split_cell_and_item(self):
        path = 'australia', 'queensland', 'gold_coast'
        cell = cells_utils._PATH_CELL_SEP.join(path)
        item = 'host_5'
        together = cells_utils.cell_with_item(cell, item)
        self.assertEqual(cells_utils._CELL_ITEM_SEP.join([cell, item]),
                         together)

        # Test normal usage
        result_cell, result_item = cells_utils.split_cell_and_item(together)
        self.assertEqual(cell, result_cell)
        self.assertEqual(item, result_item)

        # Test with no cell
        cell = None
        together = cells_utils.cell_with_item(cell, item)
        self.assertEqual(item, together)
        result_cell, result_item = cells_utils.split_cell_and_item(together)
        self.assertEqual(cell, result_cell)
        self.assertEqual(item, result_item)
Esempio n. 11
0
 def instance_get_all_by_host(self, context, host_name):
     """Get all instances by host.  Host might have a cell prepended
     to it, so we'll need to strip it out.  We don't need to proxy
     this call to cells, as we have instance information here in
     the API cell.
     """
     cell_name, host_name = cells_utils.split_cell_and_item(host_name)
     instances = super(HostAPI, self).instance_get_all_by_host(context, host_name)
     if cell_name:
         instances = [i for i in instances if i["cell_name"] == cell_name]
     return instances
    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
Esempio n. 13
0
    def service_get_by_compute_host(self, context, host_name):
        try:
            db_service = self.cells_rpcapi.service_get_by_compute_host(
                context, host_name)
        except exception.CellRoutingInconsistency:
            raise exception.ComputeHostNotFound(host=host_name)

        # NOTE(danms): Currently cells does not support objects as
        # return values, so just convert the db-formatted service objects
        # to new-world objects here

        # NOTE(dheeraj): Use ServiceProxy here too. See johannes'
        # note on service_get_all
        if db_service:
            # NOTE(alaski): Creation of the Service object involves creating
            # a ComputeNode object in this case.  This will fail because with
            # cells the 'id' is a string of the format 'region!child@1' but
            # the object expects the 'id' to be an int.
            if 'compute_node' in db_service:
                # NOTE(alaski): compute_node is a list that should have one
                # item in it, except in the case of Ironic.  But the Service
                # object only uses the first compute_node for its relationship
                # so we only need to pull the first one here.
                db_compute = db_service['compute_node'][0]
                comp_cell_path, comp_id = cells_utils.split_cell_and_item(
                    db_compute['id'])
                db_compute['id'] = comp_id

            cell_path, _id = cells_utils.split_cell_and_item(db_service['id'])
            db_service['id'] = _id
            ser_obj = objects.Service._from_db_object(context,
                                                      objects.Service(),
                                                      db_service)
            compute_proxy = None
            if 'compute_node' in db_service:
                compute_proxy = ComputeNodeProxy(ser_obj.compute_node,
                                                 comp_cell_path)

            return ServiceProxy(ser_obj, cell_path, compute_node=compute_proxy)
Esempio n. 14
0
 def instance_get_all_by_host(self, context, host_name):
     """Get all instances by host.  Host might have a cell prepended
     to it, so we'll need to strip it out.  We don't need to proxy
     this call to cells, as we have instance information here in
     the API cell.
     """
     cell_name, host_name = cells_utils.split_cell_and_item(host_name)
     instances = super(HostAPI, self).instance_get_all_by_host(context,
                                                               host_name)
     if cell_name:
         instances = [i for i in instances
                      if i['cell_name'] == cell_name]
     return instances
Esempio n. 15
0
    def service_get_by_compute_host(self, context, host_name):
        try:
            db_service = self.cells_rpcapi.service_get_by_compute_host(context,
                    host_name)
        except exception.CellRoutingInconsistency:
            raise exception.ComputeHostNotFound(host=host_name)

        # NOTE(danms): Currently cells does not support objects as
        # return values, so just convert the db-formatted service objects
        # to new-world objects here

        # NOTE(dheeraj): Use ServiceProxy here too. See johannes'
        # note on service_get_all
        if db_service:
            # NOTE(alaski): Creation of the Service object involves creating
            # a ComputeNode object in this case.  This will fail because with
            # cells the 'id' is a string of the format 'region!child@1' but
            # the object expects the 'id' to be an int.
            if 'compute_node' in db_service:
                # NOTE(alaski): compute_node is a list that should have one
                # item in it, except in the case of Ironic.  But the Service
                # object only uses the first compute_node for its relationship
                # so we only need to pull the first one here.
                db_compute = db_service['compute_node'][0]
                comp_cell_path, comp_id = cells_utils.split_cell_and_item(
                        db_compute['id'])
                db_compute['id'] = comp_id

            cell_path, _id = cells_utils.split_cell_and_item(db_service['id'])
            db_service['id'] = _id
            ser_obj = objects.Service._from_db_object(context,
                                                      objects.Service(),
                                                      db_service)
            compute_proxy = None
            if 'compute_node' in db_service:
                compute_proxy = ComputeNodeProxy(ser_obj.compute_node,
                        comp_cell_path)

            return ServiceProxy(ser_obj, cell_path, compute_node=compute_proxy)
Esempio n. 16
0
    def service_update(self, ctxt, host_name, binary, params_to_update):
        """Used to enable/disable a service. For compute services, setting to
        disabled stops new builds arriving on that host.

        :param host_name: the name of the host machine that the service is
                          running
        :param binary: The name of the executable that the service runs as
        :param params_to_update: eg. {'disabled': True}
        :returns: the service reference
        """
        cell_name, host_name = cells_utils.split_cell_and_item(host_name)
        response = self.msg_runner.service_update(ctxt, cell_name, host_name, binary, params_to_update)
        service = response.value_or_raise()
        service = cells_utils.add_cell_to_service(service, response.cell_name)
        return service
Esempio n. 17
0
    def service_update(self, ctxt, host_name, binary, params_to_update):
        """Used to enable/disable a service. For compute services, setting to
        disabled stops new builds arriving on that host.

        :param host_name: the name of the host machine that the service is
                          running
        :param binary: The name of the executable that the service runs as
        :param params_to_update: eg. {'disabled': True}
        :returns: the service reference
        """
        cell_name, host_name = cells_utils.split_cell_and_item(host_name)
        response = self.msg_runner.service_update(
            ctxt, cell_name, host_name, binary, params_to_update)
        service = response.value_or_raise()
        service = cells_utils.add_cell_to_service(service, response.cell_name)
        return service
Esempio n. 18
0
    def service_get_by_compute_host(self, context, host_name):
        db_service = self.cells_rpcapi.service_get_by_compute_host(context,
                                                                   host_name)
        # NOTE(danms): Currently cells does not support objects as
        # return values, so just convert the db-formatted service objects
        # to new-world objects here

        # NOTE(dheeraj): Use ServiceProxy here too. See johannes'
        # note on service_get_all
        if db_service:
            cell_path, _id = cells_utils.split_cell_and_item(db_service['id'])
            db_service['id'] = _id
            ser_obj = objects.Service._from_db_object(context,
                                                      objects.Service(),
                                                      db_service)
            return ServiceProxy(ser_obj, cell_path)
Esempio n. 19
0
    def service_get_by_compute_host(self, context, host_name):
        db_service = self.cells_rpcapi.service_get_by_compute_host(
            context, host_name)
        # NOTE(danms): Currently cells does not support objects as
        # return values, so just convert the db-formatted service objects
        # to new-world objects here

        # NOTE(dheeraj): Use ServiceProxy here too. See johannes'
        # note on service_get_all
        if db_service:
            cell_path, _id = cells_utils.split_cell_and_item(db_service['id'])
            db_service['id'] = _id
            ser_obj = objects.Service._from_db_object(context,
                                                      objects.Service(),
                                                      db_service)
            return ServiceProxy(ser_obj, cell_path)
    def task_log_get_all(self,
                         ctxt,
                         task_name,
                         period_beginning,
                         period_ending,
                         host=None,
                         state=None):
        """Get task logs from the DB from all cells or a particular
        cell.

        If 'host' is not None, host will be of the format 'cell!name@host',
        with '@host' being optional.  The query will be directed to the
        appropriate cell and return all task logs, or task logs matching
        the host if specified.

        'state' also may be None.  If it's not, filter by the state as well.
        """
        if host is None:
            cell_name = None
        else:
            result = cells_utils.split_cell_and_item(host)
            cell_name = result[0]
            if len(result) > 1:
                host = result[1]
            else:
                host = None
        responses = self.msg_runner.task_log_get_all(ctxt,
                                                     cell_name,
                                                     task_name,
                                                     period_beginning,
                                                     period_ending,
                                                     host=host,
                                                     state=state)
        # 1 response per cell.  Each response is a list of task log
        # entries.
        ret_task_logs = []
        for response in responses:
            task_logs = response.value_or_raise()
            for task_log in task_logs:
                cells_utils.add_cell_to_task_log(task_log, response.cell_name)
                ret_task_logs.append(task_log)
        return ret_task_logs
Esempio n. 21
0
    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,
                                          service_obj.ServiceList(),
                                          service_obj.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
Esempio n. 22
0
    def service_update(self, context, host_name, binary, params_to_update):
        """Used to enable/disable a service. For compute services, setting to
        disabled stops new builds arriving on that host.

        :param host_name: the name of the host machine that the service is
                          running
        :param binary: The name of the executable that the service runs as
        :param params_to_update: eg. {'disabled': True}
        """
        db_service = self.cells_rpcapi.service_update(
            context, host_name, binary, params_to_update)
        # NOTE(danms): Currently cells does not support objects as
        # return values, so just convert the db-formatted service objects
        # to new-world objects here

        # NOTE(dheeraj): Use ServiceProxy here too. See johannes'
        # note on service_get_all
        if db_service:
            cell_path, _id = cells_utils.split_cell_and_item(db_service['id'])
            db_service['id'] = _id
            ser_obj = objects.Service._from_db_object(context,
                                                      objects.Service(),
                                                      db_service)
            return ServiceProxy(ser_obj, cell_path)
Esempio n. 23
0
    def service_update(self, context, host_name, binary, params_to_update):
        """Used to enable/disable a service. For compute services, setting to
        disabled stops new builds arriving on that host.

        :param host_name: the name of the host machine that the service is
                          running
        :param binary: The name of the executable that the service runs as
        :param params_to_update: eg. {'disabled': True}
        """
        db_service = self.cells_rpcapi.service_update(
            context, host_name, binary, params_to_update)
        # NOTE(danms): Currently cells does not support objects as
        # return values, so just convert the db-formatted service objects
        # to new-world objects here

        # NOTE(dheeraj): Use ServiceProxy here too. See johannes'
        # note on service_get_all
        if db_service:
            cell_path, _id = cells_utils.split_cell_and_item(db_service['id'])
            db_service['id'] = _id
            ser_obj = objects.Service._from_db_object(context,
                                                      objects.Service(),
                                                      db_service)
            return ServiceProxy(ser_obj, cell_path)
Esempio n. 24
0
 def evacuate(self, context, instance, host, *args, **kwargs):
     """Evacuate the given instance with the provided attributes."""
     if host:
         cell_path, host = cells_utils.split_cell_and_item(host)
     self._cast_to_cells(context, instance, 'evacuate',
             host, *args, **kwargs)
Esempio n. 25
0
 def service_delete(self, ctxt, cell_service_id):
     """Deletes the specified service."""
     cell_name, service_id = cells_utils.split_cell_and_item(
         cell_service_id)
     self.msg_runner.service_delete(ctxt, cell_name, service_id)
Esempio n. 26
0
 def service_delete(self, ctxt, cell_service_id):
     """Deletes the specified service."""
     cell_name, service_id = cells_utils.split_cell_and_item(
         cell_service_id)
     self.msg_runner.service_delete(ctxt, cell_name, service_id)
Esempio n. 27
0
 def evacuate(self, context, instance, host, *args, **kwargs):
     """Evacuate the given instance with the provided attributes."""
     if host:
         cell_path, host = cells_utils.split_cell_and_item(host)
     self._cast_to_cells(context, instance, 'evacuate', host, *args,
                         **kwargs)