blob: f936cebbee5e53976a51b055635bcd5199302201 [file] [log] [blame]
Alexander Hansen4e1142d2025-07-25 17:07:27 +02001// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright 2024 Hewlett Packard Enterprise
Chris Sides2ab73412024-10-15 16:04:11 -05003
4#include "machine_context.hpp"
5
6#include <filesystem>
7#include <fstream>
8
9void 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
27bool MachineContext::keyNodeExists()
28{
29 std::filesystem::path nodePath{nodeBasePath + std::string("model")};
30
31 return std::filesystem::exists(nodePath);
32};