blob: 6f2c9563e10e5d1fb2aaf3643bd819b908cc57ba [file] [log] [blame]
Chris Sides2ab73412024-10-15 16:04:11 -05001/*
2// Copyright (c) 2024 Hewlett Packard Enterprise
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15*/
16
17#include "machine_context.hpp"
18
19#include <filesystem>
20#include <fstream>
21
22void MachineContext::populateFromDeviceTree()
23{
24 std::string nodeVal;
25 std::ifstream vpdStream(nodeBasePath + std::string("model"));
26 if (vpdStream && std::getline(vpdStream, nodeVal))
27 {
28 MachineContext::Asset::model(nodeVal);
29 vpdStream.close();
30 }
31
32 vpdStream.open(nodeBasePath + std::string("serial-number"));
33 if (vpdStream && std::getline(vpdStream, nodeVal))
34 {
35 MachineContext::Asset::serial_number(nodeVal);
36 vpdStream.close();
37 }
38};
39
40bool MachineContext::keyNodeExists()
41{
42 std::filesystem::path nodePath{nodeBasePath + std::string("model")};
43
44 return std::filesystem::exists(nodePath);
45};