Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion Scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,35 @@ These are example scripts that support the [Oracle Cloud Migrations](https://doc
# Included Scripts
|Script|Description|Environment|Last Updated|
|---|----|----|---|
|[boot_order.py](boot_order/README.md)| Modifies the boot order of disks for a VMware VM Asset.|CloudShell|27 Mar 2024|
|[modify_inventory_asset.py](modify_inventory_asset/README.md)| Modifies an Inventory Asset.|And|01 May 2025|
|[find_asset.py](find_asset/README.md)| Scans all compartments to find all Migration Assets, originated from the specific Source Asset.| CloudShell| 28 Mar 2024|
|[cleanup_volumes.py](cleanup_volumes/README.md)|Terminates unattached volumes.|CloudShell|27 Mar 2024|
|[rename_move_volumes.py](rename_move_volumes/readme.md)|Renames and moves block volumes attached to an instance.|Any OCI Config|10 Jun 2024|
|[terminate_nat_gateway](terminate_nat_gateway/README.md)|Workaround for the default Hydration Agent virtual network created by the Oracle Cloud Migrations service.|Resource Manager|12 Jun 2024|
|[SetupWorkloads.ps1](setup_workloads/README.md)|Helpful scripts for setting up a training lab.|PowerShell|18 Apr 2024|
|[SetIP.py](SetIP/README.md)|Manage the private IP address of the target Assets in a migration plan|Python|11 Nov 2024|
|[cbt.py](ChangeBlockTracking/README.md)|Check and configure Change Block Tracking for multiple VMs in vCenter|Python|9 December 2024|
# Usage

## CloudShell
```
lgabriel@cloudshell:~ (us-ashburn-1)$ git clone https://github.com/oracle-quickstart/oci-cloud-migrations.git
Cloning into 'oci-cloud-migrations'...
remote: Enumerating objects: 476, done.
remote: Counting objects: 100% (104/104), done.
remote: Compressing objects: 100% (51/51), done.
remote: Total 476 (delta 65), reused 53 (delta 53), pack-reused 372 (from 2)
Receiving objects: 100% (476/476), 1.09 MiB | 44.46 MiB/s, done.
Resolving deltas: 100% (194/194), done.

lgabriel@cloudshell:~ (us-ashburn-1)$ cd oci-cloud-migrations/

lgabriel@cloudshell:oci-cloud-migrations (us-ashburn-1)$ git checkout main
Already on 'main'
Your branch is up to date with 'origin/main'.

lgabriel@cloudshell:oci-cloud-migrations (us-ashburn-1)$ git checkout lgabriel_modify_inventory_asset
Switched to branch 'lgabriel_modify_inventory_asset'
Your branch is up to date with 'origin/lgabriel_modify_inventory_asset'.
lgabriel@cloudshell:oci-cloud-migrations (us-ashburn-1)$
```
54 changes: 0 additions & 54 deletions Scripts/boot_order/README.md

This file was deleted.

64 changes: 0 additions & 64 deletions Scripts/boot_order/boot_order.py

This file was deleted.

37 changes: 37 additions & 0 deletions Scripts/modify_inventory_asset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# modify_inventory_asset.py

## Overview
A simple script which modified an Oracle Cloud Bridge Inventory Asset.

## Usage
### View Inventory Asset Details
```
lgabriel@cloudshell:modify_inventory_asset (us-ashburn-1)$ python modify_inventory_asset.py -cs ocid1.ocbinventoryasset.oc1.iad.tjq3f5qccxmsrtl743
Inventory Asset Name: uefi-firmware
Current Firmware: UEFI
Current Disks:
['Disk Number', 'Disk Name', 'Boot Order', 'Size in MB', 'UUID']
[0, '/dev/sda1', 0, 30720, 'vol-0779b9ed400bcdb02']
```
### Select a new boot disk
```
```
### Exclude a disk
```
```
### Change compute firmware
```
lgabriel@cloudshell:modify_inventory_asset (us-ashburn-1)$ python modify_inventory_asset.py -cs ocid1.ocbinventoryasset.oc1.iad.tjq3f5qccxmsrtl743 -f efi
Inventory Asset Name: uefi-firmware
Current Firmware: UEFI
Current Disks:
['Disk Number', 'Disk Name', 'Boot Order', 'Size in MB', 'UUID']
[0, '/dev/sda1', 0, 30720, 'vol-0779b9ed400bcdb02']
Changing firmware.
Modifying AWS Timestamps.
New Inventory Details
New Firmware: efi
New Disks:
['Disk Number', 'Disk Name', 'Boot Order', 'Size in MB', 'UUID']
[0, '/dev/sda1', 0, 30720, 'vol-0779b9ed400bcdb02']
```
98 changes: 98 additions & 0 deletions Scripts/modify_inventory_asset/UniversalOCIAuth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import oci
import os

##################################################################################################
## Create signer for Authentication
## Input - config_profile and is_instance_principals and is_delegation_token and is_security_token
## Output - config and signer objects
##################################################################################################
def create_signer(config_profile, is_instance_principal, is_delegation_token, is_security_token):

## Instance Principal
if is_instance_principal:
try:
signer = oci.auth.signers.InstancePrincipalsSecurityTokenSigner()
config = {'region': signer.region, 'tenancy': signer.tenancy_id}
return config, signer

except Exception:
print("ERROR: Failed to get Instance Principal settings.")
raise SystemExit


## CloudShell - Delegation Token
elif is_delegation_token:

try:
## check if env variables OCI_CONFIG_FILE, OCI_CONFIG_PROFILE exist and use them
env_config_file = os.environ.get('OCI_CONFIG_FILE')
env_config_section = os.environ.get('OCI_CONFIG_PROFILE')

## check if file exist
if env_config_file is None or env_config_section is None:
print("*** OCI_CONFIG_FILE and OCI_CONFIG_PROFILE env variables not found, abort. ***")
raise SystemExit

config = oci.config.from_file(env_config_file, env_config_section)
delegation_token_location = config["delegation_token_file"]

with open(delegation_token_location, 'r') as delegation_token_file:
delegation_token = delegation_token_file.read().strip()
# get signer from delegation token
signer = oci.auth.signers.InstancePrincipalsDelegationTokenSigner(delegation_token=delegation_token)

return config, signer

except KeyError:
print("ERROR: Failed to get Delegation Token settings.")
raise SystemExit

except Exception:
raise

## Session Authentication - Security Token
elif is_security_token:

try:
config = oci.config.from_file(
oci.config.DEFAULT_LOCATION,
(config_profile if config_profile else oci.config.DEFAULT_PROFILE)
)
token_file = config['security_token_file']
token = None
with open(token_file, 'r') as f:
token = f.read()
private_key = oci.signer.load_private_key_from_file(config['key_file'])
#tenancy_id = config['tenancy']
signer = oci.auth.signers.SecurityTokenSigner(token, private_key)
return config, signer

except KeyError:
print("ERROR: Failed to get Security Token settings.")
raise SystemExit

except Exception:
raise

## API Key Authentication
else:
config = oci.config.from_file(
oci.config.DEFAULT_LOCATION,
(config_profile if config_profile else oci.config.DEFAULT_PROFILE)
)
try:
signer = oci.signer.Signer(
tenancy=config["tenancy"],
user=config["user"],
fingerprint=config["fingerprint"],
private_key_file_location=config.get("key_file"),
pass_phrase=oci.config.get_config_value_or_default(config, "pass_phrase"),
private_key_content=config.get("key_content")
)
except KeyError:
print("ERROR: Failed to get API Key settings.")
raise SystemExit

except Exception:
raise
return config, signer
Loading