From 5aff5d728d936b32ed1995ef6b7ea97a544e1e26 Mon Sep 17 00:00:00 2001 From: pycook Date: Wed, 27 Nov 2024 15:39:53 +0800 Subject: [PATCH] fix(api): check rack u slot --- cmdb-api/api/lib/cmdb/dcim/rack.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/cmdb-api/api/lib/cmdb/dcim/rack.py b/cmdb-api/api/lib/cmdb/dcim/rack.py index 93066004..4d9586c2 100644 --- a/cmdb-api/api/lib/cmdb/dcim/rack.py +++ b/cmdb-api/api/lib/cmdb/dcim/rack.py @@ -112,11 +112,14 @@ def check_u_slot(self): u_slot_sets.append(set(range(u_start, u_start + u_count))) if len(u_slot_sets) > 1: + u_slot_abnormal = False for a, b in itertools.combinations(u_slot_sets, 2): - u_slot_abnormal = bool(a.intersection(b)) - if u_slot_abnormal != rack.get(RackBuiltinAttributes.U_SLOT_ABNORMAL): - payload = {RackBuiltinAttributes.U_SLOT_ABNORMAL: u_slot_abnormal} - CIManager().update(rack['_id'], **payload) + if a.intersection(b): + u_slot_abnormal = True + break + if u_slot_abnormal != rack.get(RackBuiltinAttributes.U_SLOT_ABNORMAL): + payload = {RackBuiltinAttributes.U_SLOT_ABNORMAL: u_slot_abnormal} + CIManager().update(rack['_id'], **payload) def add_device(self, rack_id, device_id, u_start, u_count=None): with (redis_lock.Lock(rd.r, "DCIM_RACK_OPERATE_{}".format(rack_id))): @@ -177,3 +180,4 @@ def migrate_device(self, rack_id, device_id, to_rack_id, to_u_start): OperateHistoryManager().add(operate_type=OperateTypeEnum.REMOVE_DEVICE, rack_id=rack_id, ci_id=device_id) OperateHistoryManager().add(operate_type=OperateTypeEnum.ADD_DEVICE, rack_id=to_rack_id, ci_id=device_id) +