bool DiscoveryManager::update_drive_status(const std::string& port_uuid, const std::string& drive_uuid) const { Port port{}; try { log_debug("pnc-discovery", "Drive status update - gathering data"); port = get_manager<Port>().get_entry(port_uuid); std::string chassis_uuid = m_tools.model_tool->get_chassis_uuid(); Chassis chassis = get_manager<Chassis>().get_entry(chassis_uuid); log_debug("pnc-discovery", "Reading drive status (phys port = " << port.get_port_id() << "), twi_port = " << unsigned(port.get_twi_port()) << ", twi_channel = " << unsigned(port.get_twi_channel())); Smart smart{chassis.get_platform()}; if (m_tools.i2c_tool->get_smart(smart, port)) { attribute::Status status = m_tools.map_tool->get_status_from_smart(smart); int media_life_left = 100 - smart.fields.percentage_drive_life_used; log_debug("pnc-discovery", "Updating drive..."); m_tools.model_tool->update_drive_status(drive_uuid, status, media_life_left); } else { throw std::runtime_error("Reading smart failed"); } return true; } catch (const std::exception& e) { log_error("pnc-discovery", "Cannot read drive status for drive on port " << port.get_port_id() << ", exception: " << e.what()); return false; } }
DiscoveryManager DiscoveryManager::create(const tools::Toolset& t) { std::string chassis_uuid = t.model_tool->get_chassis_uuid(); Chassis chassis = get_manager<Chassis>().get_entry(chassis_uuid); DiscovererPtr discoverer{}; BuilderFactoryPtr factory{}; if (chassis.get_platform() == enums::PlatformType::EDK) { factory = std::make_shared<BuilderFactory>(); discoverer = std::make_shared<Discoverer>(Discoverer(chassis.get_platform(), factory)); } else if (chassis.get_platform() == enums::PlatformType::MF3) { factory = std::make_shared<BuilderFactoryMf3>(); discoverer = std::make_shared<DiscovererMf3>(factory); } else { log_error("pnc-discovery", "Not supported platform specified in the configuration"); throw std::runtime_error("Not supported platform"); } return DiscoveryManager(discoverer, t, factory); }