def introspect(clients, **workflow_input): """Introspect Baremetal Nodes Run the tripleo.baremetal.v1.introspect Mistral workflow. """ workflow_client = clients.workflow_engine tripleoclients = clients.tripleoclient print("Waiting for introspection to finish...") with tripleoclients.messaging_websocket() as ws: execution = base.start_workflow(workflow_client, 'tripleo.baremetal.v1.introspect', workflow_input={ 'node_uuids': workflow_input['node_uuids'], 'run_validations': workflow_input['run_validations'] }) for payload in base.wait_for_messages(workflow_client, ws, execution): if 'message' in payload: print(payload['message']) if payload['status'] != 'SUCCESS': raise exceptions.IntrospectionError( "Introspection completed with errors:\n%s" % '\n'.join(msg for msg in payload['message'] if msg))
def introspect(clients, **workflow_input): """Introspect Baremetal Nodes Run the tripleo.baremetal.v1.introspect Mistral workflow. """ workflow_client = clients.workflow_engine tripleoclients = clients.tripleoclient queue_name = workflow_input['queue_name'] execution = workflow_client.executions.create( 'tripleo.baremetal.v1.introspect', workflow_input={ 'node_uuids': workflow_input['node_uuids'], 'queue_name': queue_name }) print("Waiting for introspection to finish...") with tripleoclients.messaging_websocket(queue_name) as ws: payload = ws.wait_for_message(execution.id) if payload['status'] == 'SUCCESS': print('Successfully introspected all nodes.') else: raise exceptions.IntrospectionError( "Introspection completed with errors:\n%s" % '\n'.join(msg for msg in payload['message'] if msg)) print("Introspection completed.")
def introspect_manageable_nodes(clients, **workflow_input): """Introspect all manageable nodes Run the tripleo.baremetal.v1.introspect_manageable_nodes Mistral workflow. """ workflow_client = clients.workflow_engine tripleoclients = clients.tripleoclient queue_name = workflow_input['queue_name'] execution = base.start_workflow( workflow_client, 'tripleo.baremetal.v1.introspect_manageable_nodes', workflow_input={ "queue_name": queue_name, }) print("Waiting for introspection to finish...") errors = [] successful_node_uuids = set() with tripleoclients.messaging_websocket(queue_name) as ws: payload = ws.wait_for_message(execution.id) if payload['status'] == 'SUCCESS': introspected_nodes = payload['introspected_nodes'] or {} for node_uuid, status in introspected_nodes.items(): if status['error'] is None: print(("Introspection for UUID {0} finished " "successfully.").format(node_uuid)) successful_node_uuids.add(node_uuid) else: print(("Introspection for UUID {0} finished with error" ": {1}").format(node_uuid, status['error'])) errors.append("%s: %s" % (node_uuid, status['error'])) if not introspected_nodes: print("No nodes in manageable state found for introspection.") else: raise exceptions.IntrospectionError( 'Exception introspecting nodes: {}'.format(payload['message'])) if errors: raise exceptions.IntrospectionError( "Introspection completed with errors:\n%s" % '\n'.join(errors)) print("Introspection completed.")
def take_action(self, parsed_args): self.log.debug("take_action(%s)" % parsed_args) client = self.app.client_manager.baremetal inspector_client = self.app.client_manager.baremetal_introspection node_uuids = [] print("Setting nodes for introspection to manageable...") self.log.debug("Moving available/enroll nodes to manageable state.") available_nodes = utils.nodes_in_states(client, ("available", "enroll")) for uuid in utils.set_nodes_state(client, available_nodes, 'manage', 'manageable'): self.log.debug("Node {0} has been set to manageable.".format(uuid)) manageable_nodes = utils.nodes_in_states(client, ("manageable", )) for node in manageable_nodes: node_uuids.append(node.uuid) print("Starting introspection of node: {0}".format(node.uuid)) inspector_client.introspect(node.uuid) print("Waiting for introspection to finish...") errors = [] successful_node_uuids = set() results = inspector_client.wait_for_finish(node_uuids) for uuid, status in results.items(): if status['error'] is None: print( "Introspection for UUID {0} finished successfully.".format( uuid)) successful_node_uuids.add(uuid) else: print("Introspection for UUID {0} finished with error: {1}". format(uuid, status['error'])) errors.append("%s: %s" % (uuid, status['error'])) print("Setting manageable nodes to available...") self.log.debug("Moving manageable nodes to available state.") successful_nodes = [ n for n in manageable_nodes if n.uuid in successful_node_uuids ] for uuid in utils.set_nodes_state(client, successful_nodes, 'provide', 'available', skipped_states=("available", "active")): print("Node {0} has been set to available.".format(uuid)) if errors: raise exceptions.IntrospectionError( "Introspection completed with errors:\n%s" % '\n'.join(errors)) else: print("Introspection completed.")
def introspect_manageable_nodes(clients, **workflow_input): """Introspect all manageable nodes Run the tripleo.baremetal.v1.introspect_manageable_nodes Mistral workflow. """ workflow_client = clients.workflow_engine tripleoclients = clients.tripleoclient print("Waiting for introspection to finish...") errors = [] with tripleoclients.messaging_websocket() as ws: execution = base.start_workflow( workflow_client, 'tripleo.baremetal.v1.introspect_manageable_nodes', workflow_input={ 'run_validations': workflow_input['run_validations'], 'concurrency': workflow_input.get('concurrency', 20) }) for payload in base.wait_for_messages(workflow_client, ws, execution): if 'message' in payload: print(payload['message']) if payload['status'] == 'SUCCESS': introspected_nodes = payload['introspected_nodes'] or {} for node_uuid, status in introspected_nodes.items(): if status['error'] is not None: errors.append("%s: %s" % (node_uuid, status['error'])) else: raise exceptions.IntrospectionError( 'Exception introspecting nodes: {}'.format(payload['message'])) if errors: raise exceptions.IntrospectionError( "Introspection completed with errors:\n%s" % '\n'.join(errors)) print("Introspection completed.")
def take_action(self, parsed_args): self.log.debug("take_action(%s)" % parsed_args) client = self.app.client_manager.baremetal inspector_client = self.app.client_manager.baremetal_introspection node_uuids = [] print("Setting nodes for introspection to manageable...") self.log.debug("Moving available/enroll nodes to manageable state.") available_nodes = utils.nodes_in_states(client, ("available", "enroll")) for uuid in utils.set_nodes_state(client, available_nodes, 'manage', 'manageable'): self.log.debug("Node {0} has been set to manageable.".format(uuid)) manageable_nodes = utils.nodes_in_states(client, ("manageable", )) for node in manageable_nodes: node_uuids.append(node.uuid) print("Starting introspection of node: {0}".format(node.uuid)) inspector_client.introspect(node.uuid) # NOTE(dtantsur): PXE firmware on virtual machines misbehaves when # a lot of nodes start DHCPing simultaneously: it ignores NACK from # DHCP server, tries to get the same address, then times out. Work # around it by using sleep, anyway introspection takes much longer. time.sleep(5) print("Waiting for introspection to finish...") errors = [] successful_node_uuids = set() for uuid, status in utils.wait_for_node_introspection( inspector_client, node_uuids): if status['error'] is None: print( "Introspection for UUID {0} finished successfully.".format( uuid)) successful_node_uuids.add(uuid) else: print("Introspection for UUID {0} finished with error: {1}". format(uuid, status['error'])) errors.append("%s: %s" % (uuid, status['error'])) print("Setting manageable nodes to available...") self.log.debug("Moving manageable nodes to available state.") successful_nodes = [ n for n in manageable_nodes if n.uuid in successful_node_uuids ] for uuid in utils.set_nodes_state(client, successful_nodes, 'provide', 'available', skipped_states=("available", "active")): print("Node {0} has been set to available.".format(uuid)) if errors: raise exceptions.IntrospectionError( "Introspection completed with errors:\n%s" % '\n'.join(errors)) else: print("Introspection completed.")