Skip to content

Failure if no migrationAssetId tag defined for a boot volume #27

@ansokolo-oracle

Description

@ansokolo-oracle

Script fails if no migrationAssetId tag is defined for the boot volume (if non-OCM-created boot volumes exist in the compartment)

cloudshell:~ (us-ashburn-1)$ python cleanup_volumes.py ocid1.compartment.oc1..aaaaaaaaghgayjbcjnc3qf5su3xst23d7b6orc677ltra74xerbzfk3exd7q
Traceback (most recent call last):
  File "/home/FTuozzolo/cleanup_volumes.py", line 91, in <module>
    if len(search_migration_compartments_response) == 0:
NameError: name 'search_migration_compartments_response' is not defined
FTuozzolo@cloudshell:~ (us-ashburn-1)$ python cleanup_volumes.py
No Migration compartment OCID provided.
Searching for Migration compartments.
Migraiton compartment found.
Searching for compute compartments.
Collecting boot and data volume attachments.
Collecting boot volumes in the Migration compartment.
Collecting data volumes in the Migration compartment.
Delete unattached boot volume (vanilla-instance-2025.07.31:15.58.51 (Boot Volume)) for UNKNOWN_MIGRATION_ASSET?
[Y]es or [N]o: Y
Delete unattached boot volume (vanilla-instance-2025.08.01:11.27.06 (Boot Volume)) for UNKNOWN_MIGRATION_ASSET?
[Y]es or [N]o: Y
Delete unattached boot volume (vanilla-instance-2025.08.03:19.06.02 (Boot Volume)) for UNKNOWN_MIGRATION_ASSET?
[Y]es or [N]o: Y
Delete unattached boot volume (vanilla-instance-2025.08.04:17.50.54 (Boot Volume)) for UNKNOWN_MIGRATION_ASSET?
[Y]es or [N]o: Y
Delete unattached boot volume (vanilla-instance-2025.08.05:10.39.16 (Boot Volume)) for UNKNOWN_MIGRATION_ASSET?
[Y]es or [N]o: Y
Delete unattached boot volume (vanilla-instance-2025.07.09:17.55.36 (Boot Volume)) for UNKNOWN_MIGRATION_ASSET?
[Y]es or [N]o: Y
Delete unattached data volume (I_vol-0e485793180c9530e_2025.06.23.15.00.00.545) for UE1TWISTOCITST02?
[Y]es or [N]o: Y
Delete unattached data volume (I_vol-01021dadd12b89054_2025.06.23.15.00.39.630) for UE1TWISTOCITST02?
[Y]es or [N]o: Y
Delete unattached data volume (I_vol-08a4b90e2e2939f68_2025.07.30.17.51.03.511) for MSSQLD2022UW389?
[Y]es or [N]o: Y
Delete unattached data volume (I_vol-054ec78c6dc55d87b_2025.07.30.17.51.33.721) for MSSQLD2022UW389?
[Y]es or [N]o: Y
Delete unattached data volume (I_vol-06674fcdf6e61d20b_2025.07.30.17.51.49.333) for MSSQLD2022UW389?
[Y]es or [N]o: Y
Delete unattached data volume (I_vol-0be53687190333115_2025.07.30.17.52.04.634) for MSSQLD2022UW389?
[Y]es or [N]o: Y
Delete unattached data volume (I_vol-04cd88f09fbac7889_2025.07.30.17.52.35.363) for MSSQLD2022UW389?
[Y]es or [N]o: Y
Traceback (most recent call last):
  File "/home/FTuozzolo/cleanup_volumes.py", line 205, in <module>
    migration_asset = cloud_migrations_client.get_migration_asset(migration_asset_id=data_volume.freeform_tags["migrationAssetId"]).data
  File "/usr/local/lib/python3.9/site-packages/oci/cloud_migrations/migration_client.py", line 1986, in get_migration_asset
    return retry_strategy.make_retrying_call(
  File "/usr/local/lib/python3.9/site-packages/oci/retry/retry.py", line 308, in make_retrying_call
    response = func_ref(*func_args, **func_kwargs)
  File "/usr/local/lib/python3.9/site-packages/oci/base_client.py", line 523, in call_api
    return self.request(request, allow_control_chars, operation_name, api_reference_link)
  File "/usr/local/lib/python3.9/site-packages/circuitbreaker.py", line 146, in wrapper
    return self.call(function, *args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/circuitbreaker.py", line 188, in call
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/oci/base_client.py", line 724, in request
    self.raise_service_error(request, response, service_code, message, operation_name, api_reference_link, target_service, request_endpoint, client_version, timestamp, deserialized_data)
  File "/usr/local/lib/python3.9/site-packages/oci/base_client.py", line 889, in raise_service_error
    raise exceptions.ServiceError(
oci.exceptions.ServiceError: {'target_service': 'migration', 'status': 404, 'code': 'NotAuthorizedOrNotFound', 'opc-request-id': '8E523D5134014162AA5833A97B227E56/E14815F474C9F6F70229849D55B36542/7B81AC42B4A5672E8516407DA39587EF', 'message': 'Authorization failed or requested resource not found.', 'operation_name': 'get_migration_asset', 'timestamp': '2025-08-06T21:56:14.833485+00:00', 'client_version': 'Oracle-PythonSDK/2.155.1', 'request_endpoint': 'GET https://cloudmigration.us-ashburn-1.oci.oraclecloud.com/20220919/migrationAssets/ocid1.ocbinventoryasset.oc1.iad.amaaaaaaticgf4qak2iwycptcdjwfhexf4zkjqnuegq7kvdbonr3scngmn3a', 'logging_tips': 'To get more info on the failing request, refer to https://docs.oracle.com/en-us/iaas/tools/python/latest/logging.html for ways to log the request/response details.', 'troubleshooting_tips': "See https://docs.oracle.com/iaas/Content/API/References/apierrors.htm#apierrors_404__404_notauthorizedornotfound for more information about resolving this error. Also see https://docs.oracle.com/iaas/api/#/en/ocm/20220919/MigrationAsset/GetMigrationAsset for details on this operation's requirements. If you are unable to resolve this migration issue, please contact Oracle support and provide them this full error message."}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions