load json from snapshot schemas

This commit is contained in:
Cayo Puigdefabregas 2022-04-07 21:01:56 +02:00
parent 128140d4a8
commit d729b55f26
1 changed files with 8 additions and 1 deletions

View File

@ -8,6 +8,7 @@ from dmidecode import DMIParse
from ereuse_devicehub.parser import base2 from ereuse_devicehub.parser import base2
from ereuse_devicehub.parser.computer import Computer from ereuse_devicehub.parser.computer import Computer
from ereuse_devicehub.parser.models import SnapshotErrors from ereuse_devicehub.parser.models import SnapshotErrors
from ereuse_devicehub.resources.action.schemas import Snapshot
from ereuse_devicehub.resources.enums import Severity from ereuse_devicehub.resources.enums import Severity
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -40,6 +41,9 @@ class ParseSnapshot:
"wbid": snapshot["wbid"], "wbid": snapshot["wbid"],
} }
def get_snapshot(self):
return Snapshot().load(self.snapshot_json)
def set_basic_datas(self): def set_basic_datas(self):
self.device['manufacturer'] = self.dmi.manufacturer() self.device['manufacturer'] = self.dmi.manufacturer()
self.device['model'] = self.dmi.model() self.device['model'] = self.dmi.model()
@ -336,17 +340,20 @@ class ParseSnapshotLsHw:
self.set_components() self.set_components()
self.snapshot_json = { self.snapshot_json = {
"type": "Snapshot",
"device": self.device, "device": self.device,
"software": "Workbench", "software": "Workbench",
"components": self.components, "components": self.components,
"uuid": snapshot['uuid'], "uuid": snapshot['uuid'],
"type": snapshot['type'],
"version": snapshot["version"], "version": snapshot["version"],
"endTime": snapshot["timestamp"], "endTime": snapshot["timestamp"],
"elapsed": 1, "elapsed": 1,
"wbid": snapshot["wbid"], "wbid": snapshot["wbid"],
} }
def get_snapshot(self):
return Snapshot().load(self.snapshot_json)
def parse_hwinfo(self): def parse_hwinfo(self):
hw_blocks = self.hwinfo_raw.split("\n\n") hw_blocks = self.hwinfo_raw.split("\n\n")
return [x.split("\n") for x in hw_blocks] return [x.split("\n") for x in hw_blocks]