--- /dev/null
+# Copyright (C) 2022 Wind River Systems, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from flask_restx import fields
+import json
+
+from o2common.helper import o2logging
+logger = o2logging.get_logger(__name__)
+
+
+class Json2Dict(fields.Raw):
+
+ def format(self, value):
+ value2 = None
+ try:
+ value2 = json.loads(value) if value else None
+ except Exception as ex:
+ logger.warning(
+ f"Failed to loads json string: {value}, exception: {str(ex)}")
+ value2 = value
+ return value2
Column("name", String(255)),
Column("globalAssetId", String(255)),
Column("parentId", String(255)),
- Column("description", String(255)),
- Column("elements", Text())
- # Column("extensions", String(1024))
+ Column("description", String()),
+ Column("elements", Text()),
+ Column("extensions", String())
)
deploymentmanager = Table(
def __init__(self, resourceId: str, resourceTypeId: str,
resourcePoolId: str, name: str, parentId: str = '',
gAssetId: str = '', elements: str = '',
- description: str = '') -> None:
+ description: str = '', extensions: str = '') -> None:
super().__init__()
self.resourceId = resourceId
self.description = description
self.globalAssetId = gAssetId
self.resourcePoolId = resourcePoolId
self.elements = elements
- self.extensions = []
+ self.extensions = extensions
self.name = name
self.parentId = parentId
# pylint: disable=unused-argument
from __future__ import annotations
import uuid
-# import json
+import json
from o2ims.domain import commands, events
from o2ims.domain.stx_object import StxGenericModel
resourcepool_id = parent.resourcePoolId
parent_id = parent.resourceId
gAssetId = '' # TODO: global ID
- description = "%s : An Accelerator resource of the physical server"\
- % stxobj.name
+ # description = "%s : An Accelerator resource of the physical server"\
+ # % stxobj.name
+ content = json.loads(stxobj.content)
+ selected_keys = [
+ "name", "pdevice", "pciaddr", "pvendor_id", "pvendor",
+ "pclass_id", "pclass", "psvendor", "psdevice",
+ "sriov_totalvfs", "sriov_numvfs", "numa_node"
+ ]
+ filtered = dict(
+ filter(lambda item: item[0] in selected_keys, content.items()))
+ extensions = json.dumps(filtered)
+ description = ";".join([f"{k}:{v}" for k, v in filtered.items()])
resource = Resource(stxobj.id, resourcetype_id, resourcepool_id,
stxobj.name, parent_id, gAssetId, stxobj.content,
- description)
+ description, extensions)
resource.createtime = stxobj.createtime
resource.updatetime = stxobj.updatetime
resource.hash = stxobj.hash
from flask_restx import fields
from o2ims.views.api_ns import api_ims_inventory as api_ims_inventory_v1
+from o2common.views.flask_restx_fields import Json2Dict
class OcloudDTO:
'parentId': fields.String,
'description': fields.String,
# 'elements': fields.String,
- 'extensions': fields.String
+ # 'extensions': fields.String
+ 'extensions': Json2Dict(attribute='extensions')
+ # 'extensions': fields.Raw(attribute='extensions')
},
mask='{resourceId,resourcePoolId,resourceTypeId,description,parentId}'
)
'parentId': fields.String,
'description': fields.String,
# 'elements': fields.String,
- 'extensions': fields.String
+ # 'extensions': fields.String
+ 'extensions': Json2Dict(attribute='extensions')
+ # 'extensions': fields.Raw(attribute='extensions')
}
if iteration_number:
resource_json_mapping['elements'] = fields.List(