From be53827c02595b9994d56a4f39a5ff589325b27b Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 25 Apr 2022 11:45:25 +0200 Subject: [PATCH] sid in parser and inventory --- ereuse_devicehub/api/views.py | 4 ++-- ereuse_devicehub/inventory/forms.py | 4 ++-- ereuse_devicehub/parser/models.py | 2 +- ereuse_devicehub/parser/parser.py | 24 +++++++++++++----------- ereuse_devicehub/parser/schemas.py | 2 +- 5 files changed, 19 insertions(+), 17 deletions(-) diff --git a/ereuse_devicehub/api/views.py b/ereuse_devicehub/api/views.py index 57796675..2b353445 100644 --- a/ereuse_devicehub/api/views.py +++ b/ereuse_devicehub/api/views.py @@ -56,9 +56,9 @@ class InventoryView(LoginMix, SnapshotMix): except Exception as err: txt = "{}, {}".format(err.__class__, err) uuid = snapshot_json.get('uuid') - wbid = snapshot_json.get('wbid') + sid = snapshot_json.get('sid') error = SnapshotErrors( - description=txt, snapshot_uuid=uuid, severity=Severity.Error, wbid=wbid + description=txt, snapshot_uuid=uuid, severity=Severity.Error, sid=sid ) error.save(commit=True) self.response = jsonify('') diff --git a/ereuse_devicehub/inventory/forms.py b/ereuse_devicehub/inventory/forms.py index c2ca71cd..b654bec8 100644 --- a/ereuse_devicehub/inventory/forms.py +++ b/ereuse_devicehub/inventory/forms.py @@ -208,12 +208,12 @@ class UploadSnapshotForm(FlaskForm, SnapshotMix): except ValidationError as err: txt = "{}".format(err) uuid = snapshot_json.get('uuid') - wbid = snapshot_json.get('wbid') + sid = snapshot_json.get('sid') error = SnapshotErrors( description=txt, snapshot_uuid=uuid, severity=Severity.Error, - wbid=wbid, + sid=sid, ) error.save(commit=True) self.result[filename] = 'Error' diff --git a/ereuse_devicehub/parser/models.py b/ereuse_devicehub/parser/models.py index edec89af..54f02461 100644 --- a/ereuse_devicehub/parser/models.py +++ b/ereuse_devicehub/parser/models.py @@ -14,7 +14,7 @@ class SnapshotErrors(Thing): id = Column(BigInteger, Sequence('snapshot_errors_seq'), primary_key=True) description = Column(CIText(), default='', nullable=False) - wbid = Column(CIText(), nullable=True) + sid = Column(CIText(), nullable=True) severity = Column(SmallInteger, default=Severity.Info, nullable=False) snapshot_uuid = Column(UUID(as_uuid=True), nullable=False) owner_id = db.Column( diff --git a/ereuse_devicehub/parser/parser.py b/ereuse_devicehub/parser/parser.py index f1109f22..dccbb22c 100644 --- a/ereuse_devicehub/parser/parser.py +++ b/ereuse_devicehub/parser/parser.py @@ -37,7 +37,7 @@ class ParseSnapshot: "version": "14.0.0", "endTime": snapshot["timestamp"], "elapsed": 1, - "wbid": snapshot["wbid"], + "sid": snapshot["sid"], } def get_snapshot(self): @@ -317,7 +317,7 @@ class ParseSnapshotLsHw: def __init__(self, snapshot, default="n/a"): self.default = default self.uuid = snapshot.get("uuid") - self.wbid = snapshot.get("wbid") + self.sid = snapshot.get("sid") self.dmidecode_raw = snapshot["data"]["dmidecode"] self.smart = snapshot["data"]["smart"] self.hwinfo_raw = snapshot["data"]["hwinfo"] @@ -342,7 +342,7 @@ class ParseSnapshotLsHw: "version": "14.0.0", "endTime": snapshot["timestamp"], "elapsed": 1, - "wbid": snapshot["wbid"], + "sid": snapshot["sid"], } def get_snapshot(self): @@ -398,8 +398,10 @@ class ParseSnapshotLsHw: def get_ram_size(self, ram): size = ram.get("Size") if not len(size.split(" ")) == 2: - txt = "Error: Snapshot: {uuid}, tag: {wbid} have this ram Size: {size}".format( - uuid=self.uuid, size=size, wbid=self.wbid + txt = ( + "Error: Snapshot: {uuid}, tag: {sid} have this ram Size: {size}".format( + uuid=self.uuid, size=size, sid=self.sid + ) ) self.errors(txt) return 128 @@ -409,8 +411,8 @@ class ParseSnapshotLsHw: def get_ram_speed(self, ram): speed = ram.get("Speed", "100") if not len(speed.split(" ")) == 2: - txt = "Error: Snapshot: {uuid}, tag: {wbid} have this ram Speed: {speed}".format( - uuid=self.uuid, speed=speed, wbid=self.wbid + txt = "Error: Snapshot: {uuid}, tag: {sid} have this ram Speed: {speed}".format( + uuid=self.uuid, speed=speed, sid=self.sid ) self.errors(txt) return 100 @@ -444,8 +446,8 @@ class ParseSnapshotLsHw: uuid.UUID(dmi_uuid) except (ValueError, AttributeError) as err: self.errors("{}".format(err)) - txt = "Error: Snapshot: {uuid} tag: {wbid} have this uuid: {device}".format( - uuid=self.uuid, device=dmi_uuid, wbid=self.wbid + txt = "Error: Snapshot: {uuid} tag: {sid} have this uuid: {device}".format( + uuid=self.uuid, device=dmi_uuid, sid=self.sid ) self.errors(txt) dmi_uuid = None @@ -491,7 +493,7 @@ class ParseSnapshotLsHw: DataStorageInterface(interface.upper()) except ValueError as err: txt = "tag: {}, interface {} is not in DataStorageInterface Enum".format( - interface, self.wbid + interface, self.sid ) self.errors("{}".format(err)) self.errors(txt) @@ -533,6 +535,6 @@ class ParseSnapshotLsHw: logger.error(txt) self._errors.append(txt) error = SnapshotErrors( - description=txt, snapshot_uuid=self.uuid, severity=severity, wbid=self.wbid + description=txt, snapshot_uuid=self.uuid, severity=severity, sid=self.sid ) error.save() diff --git a/ereuse_devicehub/parser/schemas.py b/ereuse_devicehub/parser/schemas.py index f65f9090..5eab969c 100644 --- a/ereuse_devicehub/parser/schemas.py +++ b/ereuse_devicehub/parser/schemas.py @@ -19,7 +19,7 @@ class Snapshot_lite(Thing): version = String(required=True) schema_api = String(required=True) software = String(required=True) - wbid = String(required=True) + sid = String(required=True) type = String(required=True) timestamp = String(required=True) data = Nested(Snapshot_lite_data)