1 # Copyright (C) 2021 Wind River Systems, Inc.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 # pylint: disable=unused-argument
16 from __future__ import annotations
19 from o2common.service.unit_of_work import AbstractUnitOfWork
20 from o2ims.domain import commands, events
21 from o2ims.domain.ocloud import ResourceType
22 from o2ims.domain.subscription_obj import NotificationEventEnum
23 from o2ims.service.auditor.pserver_res_handler import is_outdated, \
26 from o2common.helper import o2logging
27 logger = o2logging.get_logger(__name__)
30 def update_pserver_port(
31 cmd: commands.UpdatePserverIfPort,
32 uow: AbstractUnitOfWork
36 p_resource = uow.resources.get(cmd.parentid)
37 # resourcepool = uow.resource_pools.get(p_resource.resourcePoolId)
39 res = uow.session.execute(
41 SELECT "resourceTypeId", "name"
43 WHERE "resourceTypeEnum" = :resource_type_enum
45 dict(resource_type_enum=stxobj.type.name)
49 res_type_name = 'pserver_if_port'
50 resourcetype_id = str(uuid.uuid3(
51 uuid.NAMESPACE_URL, res_type_name))
52 res_type = ResourceType(
54 res_type_name, stxobj.type,
55 description='A Port resource type of Physical Server')
56 dict_id = str(uuid.uuid3(
58 str(f"{res_type_name}_alarmdictionary")))
59 alarm_dictionary = uow.alarm_dictionaries.get(dict_id)
61 res_type.alarmDictionary = alarm_dictionary
62 res_type.events.append(events.ResourceTypeChanged(
63 id=res_type.resourceTypeId,
64 notificationEventType=NotificationEventEnum.CREATE,
65 updatetime=stxobj.updatetime))
66 uow.resource_types.add(res_type)
68 resourcetype_id = first['resourceTypeId']
70 resource = uow.resources.get(stxobj.id)
72 logger.info("add the port of pserver interface:" + stxobj.name
73 + " update_at: " + str(stxobj.updatetime)
74 + " id: " + str(stxobj.id)
75 + " hash: " + str(stxobj.hash))
76 localmodel = create_by(stxobj, p_resource, resourcetype_id)
77 uow.resources.add(localmodel)
79 logger.info("Add the port of pserver interface: " + stxobj.id
80 + ", name: " + stxobj.name)
83 if is_outdated(localmodel, stxobj):
84 logger.info("update port of pserver interface:" + stxobj.name
85 + " update_at: " + str(stxobj.updatetime)
86 + " id: " + str(stxobj.id)
87 + " hash: " + str(stxobj.hash))
88 update_by(localmodel, stxobj, p_resource)
89 uow.resources.update(localmodel)
91 logger.info("Update the port of pserver interface: " + stxobj.id
92 + ", name: " + stxobj.name)