def _discover_nodes(cls, ip=None, node_id=None): # type: (Optional[str], Optional[str]) -> Dict[str, AlbaNode] """ :param ip: IP of ALBA node to retrieve :type ip: str :param node_id: ID of the ALBA node :type node_id: str :return: Dict with guid of the node mapped to the node itself :rtype: Dict[str, AlbaNode] """ nodes = {} if ip is not None: # List the requested node node = AlbaNodeController.model_volatile_node( node_id, AlbaNode.NODE_TYPES.ASD, ip) data = node.client.get_metadata() if data['_success'] is False and data[ '_error'] == 'Invalid credentials': raise HttpNotAcceptableException( error='invalid_data', error_description='Invalid credentials') if data['node_id'] != node_id: raise HttpNotAcceptableException( error='invalid_data', error_description='Unexpected node identifier. {0} vs {1}'. format(data['node_id'], node_id)) nodes[node.guid] = node else: nodes.update(AlbaNodeController.discover_nodes()) return nodes