This script automates the creation of a custom Windows image ("custom image") in Oracle Cloud Infrastructure (OCI).
- If the script is executed with the
--skip_check_custom_imageflag, it creates the custom image. - If the script is executed without the
--skip_check_custom_imageflag:- It checks for an existing custom image with the appropriate tag before continuing.
- If such a tagged image exists with matching OS type and firmware exists, the creation step is skipped.
- If no tagged image exists, it creates the required custom image.
- It verifies the existence of the
CloudMigrationstag namespace and theOcmCustomImagetag key. If tag key is missing, the tag key is created. - An empty file is uploaded to the specified bucket.
- A custom compute image is created using the empty file object from the previous step.
- The custom image capabilities are updated.
- The object created in step 4 is deleted as part of the cleanup.
- Python 3.8+
- Oracle Cloud Infrastructure (OCI) account
- Setup session token: https://docs.oracle.com/en-us/iaas/Content/API/SDKDocs/clitoken.htm
- Clone or download the script.
- Install dependencies:
pip install -r requirements.txt
- NOTE: Ensure to create session token before running this script, Session token's maximum validity is 1 hr. This scrit can take 10-20 min to execute.
- Run below command for usage of script
python create_custom_image.py -h
python create_custom_image.py -h
usage: create_custom_image.py [-h] --compartment_id COMPARTMENT_ID [--config_file CONFIG_FILE] [--config_profile CONFIG_PROFILE]
[--os_version {Server 2022 standard,Server 2022 datacenter,Server 2019 standard,Server 2019 datacenter,Server 2016 datacenter,Server 2016 standard,Server 2012 r2 datacenter,Server 2012 r2 standard,Server 2012 datacenter,Server 2012 standard,Server 2008 r2 datacenter,Server 2008 r2 enterprise,Server 2008 r2 standard}]
--firmware {UEFI_64,BIOS} --bucket_name BUCKET_NAME [--skip_check_custom_image]
OCI Custom Windows Image Automation Script
options:
-h, --help show this help message and exit
--compartment_id COMPARTMENT_ID
Migration compartment ID.
--config_file CONFIG_FILE
--config_profile CONFIG_PROFILE
--os_version {Server 2022 standard,Server 2022 datacenter,Server 2019 standard,Server 2019 datacenter,Server 2016 datacenter,Server 2016 standard,Server 2012 r2 datacenter,Server 2012 r2 standard,Server 2012 datacenter,Server 2012 standard,Server 2008 r2 datacenter,Server 2008 r2 enterprise,Server 2008 r2 standard}
Windows OS version for the custom image.
--firmware {UEFI_64,BIOS}
Firmware type for the custom image.
--bucket_name BUCKET_NAME
Bucket Name used while creating custom zero byte custom image.
--skip_check_custom_image
Skip the check for a custom image and always create a new one
- Custom Image
- Empty file object
- Empty file object created for the import are deleted after the image is created.
- If the script completes successfully, that object should no longer exist.
This script is provided for experimental purposes only and should not be used in production. It is provided to assist your development or administration efforts and provided “AS IS” and is NOT supported by Oracle Corporation. The script has been tested in a test environment and appears to work as intended. You should always run new scripts on a test environment and validate and modify the same as per your requirements before using on your application environment.


