def mark_todelete(cls, drive_id):
"""Marks PD for deletion. Also creates a new one PD with the same
'name' and owner, but with different physical 'drive_name'. It is
needed for possibility to fast relaunch the pod right after PD
deletion. If we will use the same physical drive name, then we have
to wait until old drive will be actually deleted.
"""
pd = cls.query.filter(cls.id == drive_id, cls.pod_id.is_(None)).first()
if not pd or pd.state == PersistentDiskStatuses.TODELETE:
return
new_drive_name = cls._increment_drive_name(pd)
old_name = pd.name
# change name for deleting PD to prevent conflict of uniques and
# to hide PD from search by name
pd.name = uuid.uuid4().hex
pd.state = PersistentDiskStatuses.TODELETE
db.session.flush()
new_pd = cls(
drive_name=new_drive_name, name=old_name, owner_id=pd.owner_id,
size=pd.size, state=PersistentDiskStatuses.DELETED
)
db.session.add(new_pd)
db.session.commit()
return new_pd
评论列表
文章目录