def get_board_devices(rack_id, board_id=None): """ Query a specific rack or board and provide the active devices on the found board(s). Args: rack_id (str): the id of the rack to scan. board_id (str): the board id to scan. if the upper byte is 0x80 then all boards will be scanned. Returns: Active devices, numbers and types from the queried board(s). Raises: Returns a 500 error if the scan command fails. """ # if there is no board_id, we are doing a scan on a rack. # FIXME: since scan by the rack is not supported yet, (v 1.3) we will # determine the rack results by filtering on the 'scanall' results. if board_id is None: scanall = scan_all() data = json.loads(scanall.data) for rack in data['racks']: if rack['rack_id'] == rack_id: return make_json_response({'racks': [rack]}) raise SynseException('No rack found with id: {}'.format(rack_id)) board_id = check_valid_board(board_id) # first, attempt to get the info from the scan cache. _cache = get_scan_cache() if _cache: _cache = _filter_cache_meta(_cache) for rack in _cache['racks']: if rack['rack_id'] == rack_id: for board in rack['boards']: if int(board['board_id'], 16) == board_id: return make_json_response({ 'racks': [{ 'rack_id': rack['rack_id'], 'ip_addresses': rack.get('ip_addresses', []), 'hostnames': rack.get('hostnames', []), 'boards': [board] }] }) break cmd = current_app.config['CMD_FACTORY'].get_scan_command({ _s_.RACK_ID: rack_id, _s_.BOARD_ID: board_id }) device = get_device_instance(board_id) response = device.handle(cmd) return make_json_response(response.get_response_data())
def get_board_version(rack_id, board_id): """ Get the version information for the specified board. Args: rack_id (str): the rack id associated with the board. board_id (str): the board id to get version for. Returns: The version of the hardware and firmware for the given board. Raises: Returns a 500 error if the version command fails. """ board_id = check_valid_board(board_id) cmd = current_app.config['CMD_FACTORY'].get_version_command({ _s_.RACK_ID: rack_id, _s_.BOARD_ID: board_id }) device = get_device_instance(board_id) response = device.handle(cmd) return make_json_response(response.get_response_data())
def device_location(rack_id, board_id=None, device_id=None): # pylint: disable=unused-argument """ Get the location of a device. This command is supported for PLC. Other devicebus types (IPMI, Redfish, SNMP, RS485, I2C) are not supported, so 'unknown' is returned. Args: rack_id (str): the id of the rack where the target board resides board_id (str): the board id to get location for. non-PLC boards are not supported. device_id (str): the device id to get location for. non-PLC devices are not supported. Returns: The location of device, if known. Raises: Returns a 500 error if the location command fails. """ if device_id is not None: (board_id, device_id) = check_valid_board_and_device(board_id, device_id) if device_id > 0xFFFF: raise SynseException('Device number must be <= 0xFFFF') else: board_id = check_valid_board(board_id) try: # add validation on the board by finding its device instance. if this # is not a valid board, we raise an exception, as there is no valid # location for it get_device_instance(board_id) except Exception as e: raise e # physical (rack) location is not yet implemented in v1 physical_location = { _s_.LOC_HORIZONTAL: _s_.LOC_UNKNOWN, _s_.LOC_VERTICAL: _s_.LOC_UNKNOWN, _s_.LOC_DEPTH: _s_.LOC_UNKNOWN } if device_id is not None: return make_json_response({ _s_.PHYSICAL_LOC: physical_location, _s_.CHASSIS_LOC: get_chassis_location(device_id) }) return make_json_response({_s_.PHYSICAL_LOC: physical_location})
def test_002_check_valid_board(self): """ Test validating that board ids are correct. """ board_id = utils.check_valid_board('ffffffff') self.assertEqual(board_id, 0xffffffff)
def test_006_check_valid_board(self): """ Test validating that board ids are correct. """ board_id = utils.check_valid_board('10.1.10.1') self.assertEqual(board_id, '10.1.10.1')
def test_005_check_valid_board(self): """ Test validating that board ids are correct. """ board_id = utils.check_valid_board('not a hex string') self.assertEqual(board_id, 'not a hex string')
def test_004_check_valid_board(self): """ Test validating that board ids are correct. """ with self.assertRaises(ValueError): utils.check_valid_board('-1')