Skip to content

Commit

Permalink
fix(api): check rack u slot
Browse files Browse the repository at this point in the history
  • Loading branch information
pycook committed Nov 27, 2024
1 parent 464b9d5 commit 5aff5d7
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions cmdb-api/api/lib/cmdb/dcim/rack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))):
Expand Down Expand Up @@ -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)

0 comments on commit 5aff5d7

Please sign in to comment.