To fetch running resources from different Oracle Cloud Infrastructure (OCI) services like instances, databases, analytics, integration, and Oracle Digital Assistant services, you can modify the script to accommodate each service’s unique API endpoints and methods. Below, I’ll provide you with an outline of how you can adapt the script to fetch running resources from these services:
Prerequisites: The basics
Ensure you have the OCI SDK for Python installed and your authentication configured. With these foundations in place, you can move to the next step.
Step 1: Authenticating with OCI
First things first, let’s establish a secure connection to your OCI tenancy using Python SDK.
import oci
# Load your OCI configuration
config = oci.config.from_file('~/.oci/config')
Step 2: Fetching Running Resources Across Various Services
For Instances:
compute_client = oci.core.ComputeClient(config)
list_instances_response = compute_client.list_instances(
config["tenancy"],
lifecycle_state=oci.core.models.Instance.LIFECYCLE_STATE_RUNNING
)
for instance in list_instances_response.data:
print("Instance Name: {}".format(instance.display_name))
print("OCID: {}".format(instance.id))
print("Availability Domain: {}".format(instance.availability_domain))
print("Public IP: {}".format(instance.public_ip))
print("Private IP: {}".format(instance.private_ip))
print("------------------------------")
For Databases:
database_client = oci.database.DatabaseClient(config)
list_databases_response = database_client.list_databases(config["tenancy"])
for database in list_databases_response.data:
if database.lifecycle_state == oci.database.models.Database.LIFECYCLE_STATE_AVAILABLE:
print("Database Name: {}".format(database.db_name))
print("OCID: {}".format(database.id))
print("DB Version: {}".format(database.db_version))
print("------------------------------")
For Analytics:
analytics_client = oci.analytics.AnalyticsClient(config)
list_analytics_instances_response = analytics_client.list_analytics_instances(config["tenancy"])
for analytics_instance in list_analytics_instances_response.data:
print("Analytics Instance Name: {}".format(analytics_instance.display_name))
print("OCID: {}".format(analytics_instance.id))
print("Capacity: {}".format(analytics_instance.capacity))
print("------------------------------")
For Integration:
integration_client = oci.integration.IntegrationInstanceClient(config)
list_integration_instances_response = integration_client.list_integration_instances(config["tenancy"])
for integration_instance in list_integration_instances_response.data:
print("Integration Instance Name: {}".format(integration_instance.display_name))
print("OCID: {}".format(integration_instance.id))
print("Is Integration Instance Running: {}".format(integration_instance.is_instance_running))
print("------------------------------")
For ODA:
oda_client = oci.oda.OdaClient(config)
list_digital_assistants_response = oda_client.list_digital_assistants(config["tenancy"])
for digital_assistant in list_digital_assistants_response.data:
print("Digital Assistant Name: {}".format(digital_assistant.display_name))
print("OCID: {}".format(digital_assistant.id))
print("Is Digital Assistant Running: {}".format(digital_assistant.lifecycle_state))
print("------------------------------")
Executing the adapted script will provide you with a detailed overview of running resources from instances, databases, analytics, integration, and Oracle Digital Assistant services within your OCI tenancy. This holistic insight allows you to proactively manage and optimize resources across various services effectively.