Skip to content

Commit

Permalink
Reset FCP assignements of deleted VM
Browse files Browse the repository at this point in the history
Signed-off-by: Eric Bischoff <[email protected]>
  • Loading branch information
Bischoff committed Nov 23, 2024
1 parent 2ecb039 commit 6832cfe
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
10 changes: 10 additions & 0 deletions zvmsdk/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,16 @@ def bulk_update_state_in_fcp_table(self, fcp_id_list: list,
conn.executemany("UPDATE fcp set state=? "
"WHERE fcp_id=?", data_to_update)

def reset_fcps_of_assigner(self, userid):
"""Reset fcp records for a given assigner."""
with get_fcp_conn() as conn:
LOG.debug("HERE")
conn.execute("UPDATE fcp SET assigner_id='', reserved=0, "
"connections=0, tmpl_id='' WHERE assigner_id=?",
(userid,))
LOG.debug("FCP records for user %s are reset in "
"fcp table" % userid)

def get_all_fcps_of_assigner(self, assigner_id=None):
"""Get dict of all fcp records of specified assigner.
If assigner is None, will get all fcp records.
Expand Down
7 changes: 5 additions & 2 deletions zvmsdk/smtclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def __init__(self):
self._NetDbOperator = database.NetworkDbOperator()
self._GuestDbOperator = database.GuestDbOperator()
self._ImageDbOperator = database.ImageDbOperator()
self._FCPDbOperator = database.FCPDbOperator()

def _request(self, requestData):
try:
Expand Down Expand Up @@ -2564,8 +2565,10 @@ def delete_vm(self, userid):
with zvmutils.log_and_reraise_sdkbase_error(action):
self._NetDbOperator.switch_delete_record_for_userid(userid)

# TODO: cleanup db record from volume table
pass
# cleanup db records from FCP table
action = "delete FCP records for user %s" % userid
with zvmutils.log_and_reraise_sdkbase_error(action):
self._FCPDbOperator.reset_fcps_of_assigner(userid)

# cleanup persistent folder for guest
self._pathutils.remove_guest_path(userid)
Expand Down

0 comments on commit 6832cfe

Please sign in to comment.