add uuid for old versions from form upload
This commit is contained in:
parent
e1cdd56fa0
commit
3e3a2fbd34
|
@ -260,45 +260,34 @@ class UploadSnapshotForm(SnapshotMixin, FlaskForm):
|
||||||
self.tmp_snapshots = app.config['TMP_SNAPSHOTS']
|
self.tmp_snapshots = app.config['TMP_SNAPSHOTS']
|
||||||
for filename, snapshot_json in self.snapshots:
|
for filename, snapshot_json in self.snapshots:
|
||||||
path_snapshot = save_json(snapshot_json, self.tmp_snapshots, g.user.email)
|
path_snapshot = save_json(snapshot_json, self.tmp_snapshots, g.user.email)
|
||||||
snapshot_json.pop('debug', None)
|
debug = snapshot_json.pop('debug', None)
|
||||||
version = snapshot_json.get('schema_api')
|
self.version = snapshot_json.get('schema_api')
|
||||||
uuid = snapshot_json.get('uuid')
|
self.uuid = snapshot_json.get('uuid')
|
||||||
sid = snapshot_json.get('sid')
|
self.sid = snapshot_json.get('sid')
|
||||||
software_version = snapshot_json.get('version')
|
|
||||||
if self.is_wb_lite_snapshot(version):
|
if self.is_wb_lite_snapshot(self.version):
|
||||||
self.snapshot_json = schema_lite.load(snapshot_json)
|
self.snapshot_json = schema_lite.load(snapshot_json)
|
||||||
snapshot_json = ParseSnapshotLsHw(self.snapshot_json).snapshot_json
|
snapshot_json = ParseSnapshotLsHw(self.snapshot_json).snapshot_json
|
||||||
|
else:
|
||||||
|
self.version = snapshot_json.get('version')
|
||||||
|
system_uuid = self.get_uuid(debug)
|
||||||
|
snapshot_json['device']['uuid'] = system_uuid
|
||||||
|
|
||||||
try:
|
try:
|
||||||
snapshot_json = schema.load(snapshot_json)
|
snapshot_json = schema.load(snapshot_json)
|
||||||
except ValidationError as err:
|
except ValidationError as err:
|
||||||
txt = "{}".format(err)
|
txt = "{}".format(err)
|
||||||
error = SnapshotsLog(
|
self.errors(txt=txt)
|
||||||
description=txt,
|
|
||||||
snapshot_uuid=uuid,
|
|
||||||
severity=Severity.Error,
|
|
||||||
sid=sid,
|
|
||||||
version=software_version,
|
|
||||||
)
|
|
||||||
error.save(commit=True)
|
|
||||||
self.result[filename] = 'Error'
|
self.result[filename] = 'Error'
|
||||||
continue
|
continue
|
||||||
|
|
||||||
response = self.build(snapshot_json)
|
response = self.build(snapshot_json)
|
||||||
db.session.add(response)
|
db.session.add(response)
|
||||||
devices.append(response.device)
|
devices.append(response.device)
|
||||||
snap_log = SnapshotsLog(
|
|
||||||
description='Ok',
|
|
||||||
snapshot_uuid=uuid,
|
|
||||||
severity=Severity.Info,
|
|
||||||
sid=sid,
|
|
||||||
version=software_version,
|
|
||||||
snapshot=response,
|
|
||||||
)
|
|
||||||
snap_log.save()
|
|
||||||
|
|
||||||
if hasattr(response, 'type'):
|
if hasattr(response, 'type'):
|
||||||
self.result[filename] = 'Ok'
|
self.result[filename] = 'Ok'
|
||||||
|
self.errors(txt="Ok", severity=Severity.Info, snapshot=response)
|
||||||
else:
|
else:
|
||||||
self.result[filename] = 'Error'
|
self.result[filename] = 'Error'
|
||||||
|
|
||||||
|
|
Reference in New Issue