desc
stringlengths
3
26.7k
decl
stringlengths
11
7.89k
bodies
stringlengths
8
553k
'Wait for response(s) to be put into the eventlet queue. Since each queue entry actually contains a list of JSON-ified responses, combine them all into a single list to return. Destroy the eventlet queue when done.'
def _wait_for_json_responses(self, num_responses=1):
if (not self.resp_queue): return responses = [] wait_time = CONF.cells.call_timeout try: for x in xrange(num_responses): json_responses = self.resp_queue.get(timeout=wait_time) responses.extend(json_responses) except queue.Empty: raise exception.CellTi...
'Send list of responses to this message. Responses passed here are JSON-ified. Targeted messages have a single response while Broadcast messages may have multiple responses. If this cell was the source of the message, these responses will be returned from self.process(). Otherwise, we will route the response to the s...
def _send_json_responses(self, json_responses, neighbor_only=False, fanout=False):
if (not self.need_response): return if self.source_is_us(): responses = [] for json_response in json_responses: responses.append(Response.from_json(json_response)) return responses direction = (((self.direction == 'up') and 'down') or 'up') response_kwargs = {...
'Send a response to this message. If the source of the request was ourselves, just return the response. It\'ll be passed back to the caller of self.process(). See DocString for _send_json_responses() as it handles most of the real work for this method. \'response\' is an instance of Response class.'
def _send_response(self, response, neighbor_only=False):
if (not self.need_response): return if self.source_is_us(): return response self._send_json_responses([response.to_json()], neighbor_only=neighbor_only)
'Take an exception as returned from sys.exc_info(), encode it in a Response, and send it.'
def _send_response_from_exception(self, exc_info):
response = Response(self.routing_path, exc_info, True) return self._send_response(response)
'Convert a message to a dictionary. Only used internally.'
def _to_dict(self):
_dict = {} for key in self.base_attrs_to_json: _dict[key] = getattr(self, key) return _dict
'Convert a message into JSON for sending to a sibling cell.'
def to_json(self):
_dict = self._to_dict() _dict['ctxt'] = _dict['ctxt'].to_dict() return jsonutils.dumps(_dict)
'Did this cell create this message?'
def source_is_us(self):
return (self.routing_path == self.our_path_part)
'Process a message. Deal with it locally and/or forward it to a sibling cell. Override in a subclass.'
def process(self):
raise NotImplementedError()
'Return the cell name for the next hop. If the next hop is the current cell, return None.'
def _get_next_hop(self):
if (self.target_cell == self.routing_path): return self.state_manager.my_cell_state target_cell = self.target_cell routing_path = self.routing_path current_hops = routing_path.count(_PATH_CELL_SEP) next_hop_num = (current_hops + 1) dest_hops = target_cell.count(_PATH_CELL_SEP) if (de...
'Process a targeted message. This is called for all cells that touch this message. If the local cell is the one that created this message, we reply directly with a Response instance. If the local cell is not the target, an eventlet queue is created and we wait for the response to show up via another thread receiving ...
def process(self):
try: next_hop = self._get_next_hop() except Exception as exc: exc_info = sys.exc_info() LOG.exception(_('Error locating next hop for message: %(exc)s'), locals()) return self._send_response_from_exception(exc_info) if next_hop.is_me: response = self....
'Set the next hops and return the number of hops. The next hops may include ourself.'
def _get_next_hops(self):
if (self.hop_count >= self.max_hop_count): return [] if (self.direction == 'down'): return self.state_manager.get_child_cells() else: return self.state_manager.get_parent_cells()
'Send a message to multiple cells.'
def _send_to_cells(self, target_cells):
for cell in target_cells: cell.send_message(self)
'Responses to broadcast messages always need to go to the neighbor cell from which we received this message. That cell aggregates the responses and makes sure to forward them to the correct source.'
def _send_json_responses(self, json_responses):
return super(_BroadcastMessage, self)._send_json_responses(json_responses, neighbor_only=True, fanout=True)
'Process a broadcast message. This is called for all cells that touch this message. The message is sent to all cells in the certain direction and the creator of this message has the option of whether or not to process it locally as well. If responses from all cells are required, each hop creates an eventlet queue and ...
def process(self):
try: next_hops = self._get_next_hops() except Exception as exc: exc_info = sys.exc_info() LOG.exception(_('Error locating next hops for message: %(exc)s'), locals()) return self._send_response_from_exception(exc_info) if (not self.need_response): if ...
'Process a response. If the target is the local cell, process the response here. Otherwise, forward it to where it needs to go.'
def process(self):
next_hop = self._get_next_hop() if next_hop.is_me: self._process_locally() return if (self.fanout is False): target_hops = self.target_cell.count(_PATH_CELL_SEP) current_hops = self.routing_path.count(_PATH_CELL_SEP) if ((current_hops + 1) == target_hops): ...
'Get task logs from the DB. The message could have directly targeted this cell, or it could have been a broadcast message. If \'host\' is not None, filter by host. If \'state\' is not None, filter by state.'
def task_log_get_all(self, message, task_name, period_beginning, period_ending, host, state):
task_logs = self.db.task_log_get_all(message.ctxt, task_name, period_beginning, period_ending, host=host, state=state) return jsonutils.to_primitive(task_logs)
'Parent cell told us to schedule new instance creation.'
def schedule_run_instance(self, message, host_sched_kwargs):
self.msg_runner.scheduler.run_instance(message, host_sched_kwargs)
'Run a method in the compute api class.'
def run_compute_api_method(self, message, method_info):
method = method_info['method'] fn = getattr(self.compute_api, method, None) if (not fn): detail = _("Unknown method '%(method)s' in compute API") raise exception.CellServiceAPIMethodNotFound(detail=(detail % locals())) args = list(method_info['method_args']) instance_u...
'A child cell told us about their capabilities.'
def update_capabilities(self, message, cell_name, capabilities):
LOG.debug(_('Received capabilities from child cell %(cell_name)s: %(capabilities)s'), locals()) self.state_manager.update_cell_capabilities(cell_name, capabilities) self.msg_runner.tell_parents_our_capabilities(message.ctxt)
'A child cell told us about their capacity.'
def update_capacities(self, message, cell_name, capacities):
LOG.debug(_('Received capacities from child cell %(cell_name)s: %(capacities)s'), locals()) self.state_manager.update_cell_capacities(cell_name, capacities) self.msg_runner.tell_parents_our_capacities(message.ctxt)
'A parent cell has told us to send our capabilities, so let\'s do so.'
def announce_capabilities(self, message):
self.msg_runner.tell_parents_our_capabilities(message.ctxt)
'A parent cell has told us to send our capacity, so let\'s do so.'
def announce_capacities(self, message):
self.msg_runner.tell_parents_our_capacities(message.ctxt)
'Return the service entry for a compute host.'
def service_get_by_compute_host(self, message, host_name):
service = self.db.service_get_by_compute_host(message.ctxt, host_name) return jsonutils.to_primitive(service)
'Proxy RPC to the given compute topic.'
def proxy_rpc_to_manager(self, message, host_name, rpc_message, topic, timeout):
self.db.service_get_by_compute_host(message.ctxt, host_name) if message.need_response: return rpc.call(message.ctxt, topic, rpc_message, timeout=timeout) rpc.cast(message.ctxt, topic, rpc_message)
'Get compute node by ID.'
def compute_node_get(self, message, compute_id):
compute_node = self.db.compute_node_get(message.ctxt, compute_id) return jsonutils.to_primitive(compute_node)
'Validate console port with child cell compute node.'
def validate_console_port(self, message, instance_uuid, console_port, console_type):
try: instance = self.db.instance_get_by_uuid(message.ctxt, instance_uuid) except exception.InstanceNotFound: with excutils.save_and_reraise_exception(): instance = {'uuid': instance_uuid} self.msg_runner.instance_destroy_at_top(message.ctxt, instance) return self.comp...
'Are we the API level?'
def _at_the_top(self):
return (not self.state_manager.get_parent_cells())
'Update an instance in the DB if we\'re a top level cell.'
def instance_update_at_top(self, message, instance, **kwargs):
if (not self._at_the_top()): return instance_uuid = instance['uuid'] items_to_remove = ['id', 'security_groups', 'volumes', 'cell_name', 'name', 'metadata'] for key in items_to_remove: instance.pop(key, None) instance['cell_name'] = _reverse_path(message.routing_path) info_cache ...
'Destroy an instance from the DB if we\'re a top level cell.'
def instance_destroy_at_top(self, message, instance, **kwargs):
if (not self._at_the_top()): return instance_uuid = instance['uuid'] LOG.debug((_('Got update to delete instance %(instance_uuid)s') % locals())) try: self.db.instance_destroy(message.ctxt, instance_uuid, update_cells=False) except exception.InstanceNotFound: p...
'Call compute API delete() or soft_delete() in every cell. This is used when the API cell doesn\'t know what cell an instance belongs to but the instance was requested to be deleted or soft-deleted. So, we\'ll run it everywhere.'
def instance_delete_everywhere(self, message, instance, delete_type, **kwargs):
LOG.debug(_('Got broadcast to %(delete_type)s delete instance'), locals(), instance=instance) if (delete_type == 'soft'): self.compute_api.soft_delete(message.ctxt, instance) else: self.compute_api.delete(message.ctxt, instance)
'Destroy an instance from the DB if we\'re a top level cell.'
def instance_fault_create_at_top(self, message, instance_fault, **kwargs):
if (not self._at_the_top()): return items_to_remove = ['id'] for key in items_to_remove: instance_fault.pop(key, None) log_str = _('Got message to create instance fault: %(instance_fault)s') LOG.debug(log_str, locals()) self.db.instance_fault_create(message.ctxt...
'Update Bandwidth usage in the DB if we\'re a top level cell.'
def bw_usage_update_at_top(self, message, bw_update_info, **kwargs):
if (not self._at_the_top()): return self.db.bw_usage_update(message.ctxt, **bw_update_info)
'Return compute nodes in this cell.'
def compute_node_get_all(self, message, hypervisor_match):
if (hypervisor_match is not None): nodes = self.db.compute_node_search_by_hypervisor(message.ctxt, hypervisor_match) else: nodes = self.db.compute_node_get_all(message.ctxt) return jsonutils.to_primitive(nodes)
'Return compute node stats from this cell.'
def compute_node_stats(self, message):
return self.db.compute_node_statistics(message.ctxt)
'Delete consoleauth tokens for an instance in API cells.'
def consoleauth_delete_tokens(self, message, instance_uuid):
if (not self._at_the_top()): return self.consoleauth_rpcapi.delete_tokens_for_instance(message.ctxt, instance_uuid)
'Message processing will call this when its determined that the message should be processed within this cell. Find the method to call based on the message type, and call it. The caller is responsible for catching exceptions and returning results to cells, if needed.'
def _process_message_locally(self, message):
methods = self.methods_by_type[message.message_type] fn = getattr(methods, message.method_name) return fn(message, **message.method_kwargs)
'Put a response into a response queue. This is called when a _ResponseMessage is processed in the cell that initiated a \'call\' to another cell.'
def _put_response(self, response_uuid, response):
resp_queue = self.response_queues.get(response_uuid) if (not resp_queue): return resp_queue.put(response)
'Set up an eventlet queue to use to wait for replies. Replies come back from the target cell as a _ResponseMessage being sent back to the source.'
def _setup_response_queue(self, message):
resp_queue = queue.Queue() self.response_queues[message.uuid] = resp_queue return resp_queue
'Stop tracking the response queue either because we\'re done receiving responses, or we\'ve timed out.'
def _cleanup_response_queue(self, message):
try: del self.response_queues[message.uuid] except KeyError: pass
'Create a ResponseMessage. This is used internally within the messaging module.'
def _create_response_message(self, ctxt, direction, target_cell, response_uuid, response_kwargs, **kwargs):
return _ResponseMessage(self, ctxt, 'parse_responses', response_kwargs, direction, target_cell, response_uuid, **kwargs)
'Turns a message in JSON format into an appropriate Message instance. This is called when cells receive a message from another cell.'
def message_from_json(self, json_message):
message_dict = jsonutils.loads(json_message) message_type = message_dict.pop('message_type') ctxt = message_dict['ctxt'] message_dict['ctxt'] = context.RequestContext.from_dict(ctxt) message_cls = _CELL_MESSAGE_TYPE_TO_MESSAGE_CLS[message_type] return message_cls(self, **message_dict)
'Tell child cells to send us capabilities. This is typically called on startup of the nova-cells service.'
def ask_children_for_capabilities(self, ctxt):
child_cells = self.state_manager.get_child_cells() for child_cell in child_cells: message = _TargetedMessage(self, ctxt, 'announce_capabilities', dict(), 'down', child_cell) message.process()
'Tell child cells to send us capacities. This is typically called on startup of the nova-cells service.'
def ask_children_for_capacities(self, ctxt):
child_cells = self.state_manager.get_child_cells() for child_cell in child_cells: message = _TargetedMessage(self, ctxt, 'announce_capacities', dict(), 'down', child_cell) message.process()
'Send our capabilities to parent cells.'
def tell_parents_our_capabilities(self, ctxt):
parent_cells = self.state_manager.get_parent_cells() if (not parent_cells): return my_cell_info = self.state_manager.get_my_state() capabs = self.state_manager.get_our_capabilities() LOG.debug(_('Updating parents with our capabilities: %(capabs)s'), locals()) for (key, val...
'Send our capacities to parent cells.'
def tell_parents_our_capacities(self, ctxt):
parent_cells = self.state_manager.get_parent_cells() if (not parent_cells): return my_cell_info = self.state_manager.get_my_state() capacities = self.state_manager.get_our_capacities() LOG.debug(_('Updating parents with our capacities: %(capacities)s'), locals()) method_kw...
'Called by the scheduler to tell a child cell to schedule a new instance for build.'
def schedule_run_instance(self, ctxt, target_cell, host_sched_kwargs):
method_kwargs = dict(host_sched_kwargs=host_sched_kwargs) message = _TargetedMessage(self, ctxt, 'schedule_run_instance', method_kwargs, 'down', target_cell) message.process()
'Call a compute API method in a specific cell.'
def run_compute_api_method(self, ctxt, cell_name, method_info, call):
message = _TargetedMessage(self, ctxt, 'run_compute_api_method', dict(method_info=method_info), 'down', cell_name, need_response=call) return message.process()
'Update an instance at the top level cell.'
def instance_update_at_top(self, ctxt, instance):
message = _BroadcastMessage(self, ctxt, 'instance_update_at_top', dict(instance=instance), 'up', run_locally=False) message.process()
'Destroy an instance at the top level cell.'
def instance_destroy_at_top(self, ctxt, instance):
message = _BroadcastMessage(self, ctxt, 'instance_destroy_at_top', dict(instance=instance), 'up', run_locally=False) message.process()
'This is used by API cell when it didn\'t know what cell an instance was in, but the instance was requested to be deleted or soft_deleted. So, we\'ll broadcast this everywhere.'
def instance_delete_everywhere(self, ctxt, instance, delete_type):
method_kwargs = dict(instance=instance, delete_type=delete_type) message = _BroadcastMessage(self, ctxt, 'instance_delete_everywhere', method_kwargs, 'down', run_locally=False) message.process()
'Create an instance fault at the top level cell.'
def instance_fault_create_at_top(self, ctxt, instance_fault):
message = _BroadcastMessage(self, ctxt, 'instance_fault_create_at_top', dict(instance_fault=instance_fault), 'up', run_locally=False) message.process()
'Update bandwidth usage at top level cell.'
def bw_usage_update_at_top(self, ctxt, bw_update_info):
message = _BroadcastMessage(self, ctxt, 'bw_usage_update_at_top', dict(bw_update_info=bw_update_info), 'up', run_locally=False) message.process()
'Force a sync of all instances, potentially by project_id, and potentially since a certain date/time.'
def sync_instances(self, ctxt, project_id, updated_since, deleted):
method_kwargs = dict(project_id=project_id, updated_since=updated_since, deleted=deleted) message = _BroadcastMessage(self, ctxt, 'sync_instances', method_kwargs, 'down', run_locally=False) message.process()
'Get task logs from the DB from all cells or a particular cell. If \'cell_name\' is None or \'\', get responses from all cells. If \'host\' is not None, filter by host. If \'state\' is not None, filter by state. Return a list of Response objects.'
def task_log_get_all(self, ctxt, cell_name, task_name, period_beginning, period_ending, host=None, state=None):
method_kwargs = dict(task_name=task_name, period_beginning=period_beginning, period_ending=period_ending, host=host, state=state) if cell_name: message = _TargetedMessage(self, ctxt, 'task_log_get_all', method_kwargs, 'down', cell_name, need_response=True) return [message.process()] message ...
'Return list of compute nodes in all child cells.'
def compute_node_get_all(self, ctxt, hypervisor_match=None):
method_kwargs = dict(hypervisor_match=hypervisor_match) message = _BroadcastMessage(self, ctxt, 'compute_node_get_all', method_kwargs, 'down', run_locally=True, need_response=True) return message.process()
'Return compute node stats from all child cells.'
def compute_node_stats(self, ctxt):
method_kwargs = dict() message = _BroadcastMessage(self, ctxt, 'compute_node_stats', method_kwargs, 'down', run_locally=True, need_response=True) return message.process()
'Return compute node entry from a specific cell by ID.'
def compute_node_get(self, ctxt, cell_name, compute_id):
method_kwargs = dict(compute_id=compute_id) message = _TargetedMessage(self, ctxt, 'compute_node_get', method_kwargs, 'down', cell_name, need_response=True) return message.process()
'Delete consoleauth tokens for an instance in API cells.'
def consoleauth_delete_tokens(self, ctxt, instance_uuid):
message = _BroadcastMessage(self, ctxt, 'consoleauth_delete_tokens', dict(instance_uuid=instance_uuid), 'up', run_locally=False) message.process()
'Validate console port with child cell compute node.'
def validate_console_port(self, ctxt, cell_name, instance_uuid, console_port, console_type):
method_kwargs = {'instance_uuid': instance_uuid, 'console_port': console_port, 'console_type': console_type} message = _TargetedMessage(self, ctxt, 'validate_console_port', method_kwargs, 'down', cell_name, need_response=True) return message.process()
'Start any consumers the driver may need.'
def start_consumers(self, msg_runner):
raise NotImplementedError()
'Stop consuming messages.'
def stop_consumers(self):
raise NotImplementedError()
'Send a message to a cell.'
def send_message_to_cell(self, cell_state, message):
raise NotImplementedError()
'Attempt to schedule instance(s). If we have no cells to try, raise exception.NoCellsAvailable'
def _run_instance(self, message, host_sched_kwargs):
ctxt = message.ctxt request_spec = host_sched_kwargs['request_spec'] cells = self._get_possible_cells() if (not cells): raise exception.NoCellsAvailable() cells = list(cells) random.shuffle(cells) target_cell = cells[0] LOG.debug(_('Scheduling with routing_path=%(routing_pa...
'Pick a cell where we should create a new instance.'
def run_instance(self, message, host_sched_kwargs):
try: for i in xrange((max(0, CONF.cells.scheduler_retries) + 1)): try: return self._run_instance(message, host_sched_kwargs) except exception.NoCellsAvailable: if (i == max(0, CONF.cells.scheduler_retries)): raise sl...
'Have the driver start its consumers for inter-cell communication. Also ask our child cells for their capacities and capabilities so we get them more quickly than just waiting for the next periodic update. Receiving the updates from the children will cause us to update our parents. If we don\'t have any children, jus...
def post_start_hook(self):
self.driver.start_consumers(self.msg_runner) ctxt = context.get_admin_context() if self.state_manager.get_child_cells(): self.msg_runner.ask_children_for_capabilities(ctxt) self.msg_runner.ask_children_for_capacities(ctxt) else: self._update_our_parents(ctxt)
'Update our parent cells with our capabilities and capacity if we\'re at the bottom of the tree.'
@manager.periodic_task def _update_our_parents(self, ctxt):
self.msg_runner.tell_parents_our_capabilities(ctxt) self.msg_runner.tell_parents_our_capacities(ctxt)
'Periodic task to send updates for a number of instances to parent cells. On every run of the periodic task, we will attempt to sync \'CONF.cells.instance_update_num_instances\' number of instances. When we get the list of instances, we shuffle them so that multiple nova-cells services aren\'t attempting to sync the sa...
@manager.periodic_task def _heal_instances(self, ctxt):
if (not self.state_manager.get_parent_cells()): return info = {'updated_list': False} def _next_instance(): try: instance = self.instances_to_heal.next() except StopIteration: if info['updated_list']: return threshold = CONF.cells.i...
'Broadcast an instance_update or instance_destroy message up to parent cells.'
def _sync_instance(self, ctxt, instance):
if instance['deleted']: self.instance_destroy_at_top(ctxt, instance) else: self.instance_update_at_top(ctxt, instance)
'Pick a cell (possibly ourselves) to build new instance(s) and forward the request accordingly.'
def schedule_run_instance(self, ctxt, host_sched_kwargs):
our_cell = self.state_manager.get_my_state() self.msg_runner.schedule_run_instance(ctxt, our_cell, host_sched_kwargs)
'Return cell information for our neighbor cells.'
def get_cell_info_for_neighbors(self, _ctxt):
return self.state_manager.get_cell_info_for_neighbors()
'Call a compute API method in a specific cell.'
def run_compute_api_method(self, ctxt, cell_name, method_info, call):
response = self.msg_runner.run_compute_api_method(ctxt, cell_name, method_info, call) if call: return response.value_or_raise()
'Update an instance at the top level cell.'
def instance_update_at_top(self, ctxt, instance):
self.msg_runner.instance_update_at_top(ctxt, instance)
'Destroy an instance at the top level cell.'
def instance_destroy_at_top(self, ctxt, instance):
self.msg_runner.instance_destroy_at_top(ctxt, instance)
'This is used by API cell when it didn\'t know what cell an instance was in, but the instance was requested to be deleted or soft_deleted. So, we\'ll broadcast this everywhere.'
def instance_delete_everywhere(self, ctxt, instance, delete_type):
self.msg_runner.instance_delete_everywhere(ctxt, instance, delete_type)
'Create an instance fault at the top level cell.'
def instance_fault_create_at_top(self, ctxt, instance_fault):
self.msg_runner.instance_fault_create_at_top(ctxt, instance_fault)
'Update bandwidth usage at top level cell.'
def bw_usage_update_at_top(self, ctxt, bw_update_info):
self.msg_runner.bw_usage_update_at_top(ctxt, bw_update_info)
'Force a sync of all instances, potentially by project_id, and potentially since a certain date/time.'
def sync_instances(self, ctxt, project_id, updated_since, deleted):
self.msg_runner.sync_instances(ctxt, project_id, updated_since, deleted)
'Return services in this cell and in all child cells.'
def service_get_all(self, ctxt, filters):
responses = self.msg_runner.service_get_all(ctxt, filters) ret_services = [] for response in responses: services = response.value_or_raise() for service in services: cells_utils.add_cell_to_service(service, response.cell_name) ret_services.append(service) return r...
'Return a service entry for a compute host in a certain cell.'
def service_get_by_compute_host(self, ctxt, host_name):
(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() cells_utils.add_cell_to_service(service, response.cell_name) return service
'Proxy an RPC message as-is to a manager.'
def proxy_rpc_to_manager(self, ctxt, topic, rpc_message, call, timeout):
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()
'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. I...
def task_log_get_all(self, ctxt, task_name, period_beginning, period_ending, host=None, state=None):
if (host is None): cell_name = None else: (cell_name, host) = cells_utils.split_cell_and_item(host) 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...
'Get a compute node by ID in a specific cell.'
def compute_node_get(self, ctxt, compute_id):
(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() cells_utils.add_cell_to_compute_node(node, cell_name) return node
'Return list of compute nodes in all cells.'
def compute_node_get_all(self, ctxt, hypervisor_match=None):
responses = self.msg_runner.compute_node_get_all(ctxt, hypervisor_match=hypervisor_match) ret_nodes = [] for response in responses: nodes = response.value_or_raise() for node in nodes: cells_utils.add_cell_to_compute_node(node, response.cell_name) ret_nodes.append(nod...
'Return compute node stats totals from all cells.'
def compute_node_stats(self, ctxt):
responses = self.msg_runner.compute_node_stats(ctxt) totals = {} for response in responses: data = response.value_or_raise() for (key, val) in data.iteritems(): totals.setdefault(key, 0) totals[key] += val return totals
'Delete consoleauth tokens for an instance in API cells.'
def consoleauth_delete_tokens(self, ctxt, instance_uuid):
self.msg_runner.consoleauth_delete_tokens(ctxt, instance_uuid)
'Validate console port with child cell compute node.'
def validate_console_port(self, ctxt, instance_uuid, console_port, console_type):
instance = self.db.instance_get_by_uuid(ctxt, instance_uuid) if (not instance['cell_name']): raise exception.InstanceUnknownCell(instance_uuid=instance_uuid) response = self.msg_runner.validate_console_port(ctxt, instance['cell_name'], instance_uuid, console_port, console_type) return response.v...
'Start an RPC consumer.'
def _start_consumer(self, dispatcher, topic):
conn = rpc.create_connection(new=True) conn.create_consumer(topic, dispatcher, fanout=False) conn.create_consumer(topic, dispatcher, fanout=True) self.rpc_connections.append(conn) conn.consume_in_thread() return conn
'Start RPC consumers. Start up 2 separate consumers for handling inter-cell communication via RPC. Both handle the same types of messages, but requests/replies are separated to solve potential deadlocks. (If we used the same queue for both, it\'s possible to exhaust the RPC thread pool while we wait for replies.. such...
def start_consumers(self, msg_runner):
topic_base = CONF.cells.rpc_driver_queue_base proxy_manager = InterCellRPCDispatcher(msg_runner) dispatcher = rpc_dispatcher.RpcDispatcher([proxy_manager]) for msg_type in msg_runner.get_message_types(): topic = ('%s.%s' % (topic_base, msg_type)) self._start_consumer(dispatcher, topic)
'Stop RPC consumers. NOTE: Currently there\'s no hooks when stopping services to have managers cleanup, so this is not currently called.'
def stop_consumers(self):
for conn in self.rpc_connections: conn.close()
'Use the IntercellRPCAPI to send a message to a cell.'
def send_message_to_cell(self, cell_state, message):
self.intercell_rpcapi.send_message_to_cell(cell_state, message)
'Turn the DB information for a cell into the parameters needed for the RPC call.'
@staticmethod def _get_server_params_for_cell(next_hop):
param_map = {'username': 'username', 'password': 'password', 'rpc_host': 'hostname', 'rpc_port': 'port', 'rpc_virtual_host': 'virtual_host'} server_params = {} for (source, target) in param_map.items(): if next_hop.db_info[source]: server_params[target] = next_hop.db_info[source] ret...
'Send a message to another cell by JSON-ifying the message and making an RPC cast to \'process_message\'. If the message says to fanout, do it. The topic that is used will be \'CONF.rpc_driver_queue_base.<message_type>\'.'
def send_message_to_cell(self, cell_state, message):
ctxt = message.ctxt json_message = message.to_json() rpc_message = self.make_msg('process_message', message=json_message) topic_base = CONF.cells.rpc_driver_queue_base topic = ('%s.%s' % (topic_base, message.message_type)) server_params = self._get_server_params_for_cell(cell_state) if messa...
'Init the Intercell RPC Dispatcher.'
def __init__(self, msg_runner):
self.msg_runner = msg_runner
'We received a message from another cell. Use the MessageRunner to turn this from JSON back into an instance of the correct Message class. Then process it!'
def process_message(self, _ctxt, message):
message = self.msg_runner.message_from_json(message) message.process()
'Update cell credentials from db.'
def update_db_info(self, cell_db_info):
self.db_info = dict([(k, v) for (k, v) in cell_db_info.iteritems() if (k != 'name')])
'Update cell capabilities for a cell.'
def update_capabilities(self, cell_metadata):
self.last_seen = timeutils.utcnow() self.capabilities = cell_metadata
'Update capacity information for a cell.'
def update_capacities(self, capacities):
self.last_seen = timeutils.utcnow() self.capacities = capacities
'Return subset of cell information for OS API use.'
def get_cell_info(self):
db_fields_to_return = ['is_parent', 'weight_scale', 'weight_offset', 'username', 'rpc_host', 'rpc_port'] cell_info = dict(name=self.name, capabilities=self.capabilities) if self.db_info: for field in db_fields_to_return: cell_info[field] = self.db_info[field] return cell_info
'Send a message to a cell. Just forward this to the driver, passing ourselves and the message as arguments.'
def send_message(self, message):
self.driver.send_message_to_cell(self, message)
'Make our cell info map match the db.'
def _refresh_cells_from_db(self, ctxt):
db_cells = self.db.cell_get_all(ctxt) db_cells_dict = dict([(cell['name'], cell) for cell in db_cells]) for cells_dict in (self.parent_cells, self.child_cells): for (cell_name, cell_info) in cells_dict.items(): is_parent = cell_info.db_info['is_parent'] db_dict = db_cells_dic...