diff --git a/zvmsdk/database.py b/zvmsdk/database.py index a868833f8..745d1f405 100755 --- a/zvmsdk/database.py +++ b/zvmsdk/database.py @@ -490,6 +490,15 @@ 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: + 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. diff --git a/zvmsdk/smtclient.py b/zvmsdk/smtclient.py index 4134bfd41..7b93ef696 100644 --- a/zvmsdk/smtclient.py +++ b/zvmsdk/smtclient.py @@ -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: @@ -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)