Add volume resize if changed

This commit is contained in:
Joshua Boniface 2024-09-30 20:51:59 -04:00
parent 9aa32134a9
commit 235299942a
1 changed files with 40 additions and 23 deletions

View File

@ -3352,11 +3352,7 @@ def vm_worker_send_snapshot(
return False return False
# Begin send, set stages # Begin send, set stages
total_stages = ( total_stages = 2 + (3 * len(snapshot_rbdsnaps))
2
+ (2 * len(snapshot_rbdsnaps))
+ (len(snapshot_rbdsnaps) if current_destination_vm_state is None else 0)
)
current_stage += 1 current_stage += 1
update( update(
@ -3417,35 +3413,56 @@ def vm_worker_send_snapshot(
return False return False
try: try:
_ = ceph.format_bytes_fromhuman(retdata[0]["stats"]["size"]) local_volume_size = ceph.format_bytes_fromhuman(retdata[0]["stats"]["size"])
except Exception as e: except Exception as e:
error_message = f"Failed to get volume size for {rbd_name}: {e}" error_message = f"Failed to get volume size for {rbd_name}: {e}"
if destination_storage_pool is not None: if destination_storage_pool is not None:
pool = destination_storage_pool pool = destination_storage_pool
if current_destination_vm_state is None: current_stage += 1
current_stage += 1 update(
update( celery,
celery, f"Checking remote volume {rbd_name} for compliance",
f"Checking for remote volume {rbd_name}", current=current_stage,
current=current_stage, total=total_stages,
total=total_stages, )
)
# Check if the volume exists on the target # Check if the volume exists on the target
response = session.get( response = session.get(
f"{destination_api_uri}/storage/ceph/volume/{pool}/{volume}", f"{destination_api_uri}/storage/ceph/volume/{pool}/{volume}",
params=None, params=None,
data=None, data=None,
)
if response.status_code != 404 and current_destination_vm_state is None:
fail(
celery,
f"Remote storage pool {pool} already contains volume {volume}",
) )
if response.status_code != 404: return False
fail(
celery, if current_destination_vm_state is not None:
f"Remote storage pool {pool} already contains volume {volume}", try:
remote_volume_size = ceph.format_bytes_fromhuman(
response.json()[0]["stats"]["size"]
) )
except Exception as e:
error_message = f"Failed to get volume size for remote {rbd_name}: {e}"
fail(celery, error_message)
return False return False
if local_volume_size != remote_volume_size:
response = session.put(
f"{destination_api_uri}/storage/ceph/volume/{pool}/{volume}",
params={"new_size": local_volume_size, "force": True},
)
if response.status_code != 200:
fail(
celery,
"Failed to resize remote volume to match local volume",
)
return False
# Send the volume to the remote # Send the volume to the remote
cluster = rados.Rados(conffile="/etc/ceph/ceph.conf") cluster = rados.Rados(conffile="/etc/ceph/ceph.conf")
cluster.connect() cluster.connect()