| Alexander Hansen | 4e1142d | 2025-07-25 17:07:27 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: Apache-2.0 | 
 | 2 | // SPDX-FileCopyrightText: Copyright 2024 Hewlett Packard Enterprise | 
| Chris Sides | 2ab7341 | 2024-10-15 16:04:11 -0500 | [diff] [blame] | 3 |  | 
 | 4 | #include "machine_context.hpp" | 
 | 5 |  | 
 | 6 | #include <filesystem> | 
 | 7 | #include <fstream> | 
 | 8 |  | 
 | 9 | void MachineContext::populateFromDeviceTree() | 
 | 10 | { | 
 | 11 |     std::string nodeVal; | 
 | 12 |     std::ifstream vpdStream(nodeBasePath + std::string("model")); | 
 | 13 |     if (vpdStream && std::getline(vpdStream, nodeVal)) | 
 | 14 |     { | 
 | 15 |         MachineContext::Asset::model(nodeVal); | 
 | 16 |         vpdStream.close(); | 
 | 17 |     } | 
 | 18 |  | 
 | 19 |     vpdStream.open(nodeBasePath + std::string("serial-number")); | 
 | 20 |     if (vpdStream && std::getline(vpdStream, nodeVal)) | 
 | 21 |     { | 
 | 22 |         MachineContext::Asset::serial_number(nodeVal); | 
 | 23 |         vpdStream.close(); | 
 | 24 |     } | 
 | 25 | }; | 
 | 26 |  | 
 | 27 | bool MachineContext::keyNodeExists() | 
 | 28 | { | 
 | 29 |     std::filesystem::path nodePath{nodeBasePath + std::string("model")}; | 
 | 30 |  | 
 | 31 |     return std::filesystem::exists(nodePath); | 
 | 32 | }; |