def report_neighbours(system_id, neighbours): """Report observed neighbours seen on the rack controller.""" try: rack_controller = RackController.objects.get(system_id=system_id) except RackController.DoesNotExist: raise NoSuchNode.from_system_id(system_id) else: rack_controller.report_neighbours(neighbours)
def update_node_power_state(system_id, power_state): """Update a node power state. for :py:class:`~provisioningserver.rpc.region.UpdateNodePowerState. """ try: node = Node.objects.get(system_id=system_id) except Node.DoesNotExist: raise NoSuchNode.from_system_id(system_id) node.update_power_state(power_state)
def mark_node_failed(system_id, error_description): """Mark a node as failed. for :py:class:`~provisioningserver.rpc.region.MarkNodeFailed`. """ try: node = Node.objects.get(system_id=system_id) except Node.DoesNotExist: raise NoSuchNode.from_system_id(system_id) try: node.mark_failed(comment=error_description) except exceptions.NodeStateViolation as e: raise NodeStateViolation(e)
def update_state(system_id, scope, state): """Update the state of a controller for a scope.""" try: controller = Controller.objects.get(system_id=system_id) except Controller.DoesNotExist: raise NoSuchNode.from_system_id(system_id) scope_handlers = { "versions": _update_controller_versions, } handler = scope_handlers.get(scope) if handler is None: raise NoSuchScope() handler(controller, state)
def get_time_configuration(system_id): """Get settings to use for configuring NTP for the given node. :param system_id: system_id of node. :return: See `GetTimeConfiguration`. """ try: node = Node.objects.get(system_id=system_id) except Node.DoesNotExist: raise NoSuchNode.from_system_id(system_id) else: return { "servers": ntp.get_servers_for(node), "peers": ntp.get_peers_for(node), }
def get_controller_type(system_id): """Get the type of the node specified by its system identifier. :param system_id: system_id of node. :return: See `GetControllerType`. """ try: node = Node.objects.get(system_id=system_id) except Node.DoesNotExist: raise NoSuchNode.from_system_id(system_id) else: return { "is_region": node.is_region_controller, "is_rack": node.is_rack_controller, }
def commission_node(system_id, user): """Request a `Node` with given MAC Address and return it. :param system_id: system_id of node to commission. :param user: user of the node to commission. """ try: node = Node.objects.get(system_id=system_id) except Node.DoesNotExist: raise NoSuchNode.from_system_id(system_id) try: node.start_commissioning(User.objects.get(username=user)) except Exception as e: # Cluster takes care of logging raise CommissionNodeFailed(e)