Esempio n. 1
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. 2
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. 3
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. 4
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. 5
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. 6
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. 7
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. 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 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. 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
Esempio n. 12
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. 13
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. 14
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. 15
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. 16
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. 17
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. 18
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)