You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
How can we retrieve the cost of child tenancies using the OCI Python SDK and the Usage API? #763
How can we retrieve the costs of child tenancies using the OCI Python SDK and the Usage API.
Suppose I have four child tenancies, each associated with a single parent tenancy. I need to fetch the costs of those child tenancies with parent tenancies using Usage API calls. @adizohar, can you guide me on how to achieve this?.
I need to retrieve the root tenancy instance details in OCI. I have created three instances and want to fetch their metadata, along with details of child tenancies that I’ve also created.
Ideally, I want to use the same API to retrieve information from both the root tenancy and its child tenancies—not just instance data, but also any associated resources and their metrics.
If it's not possible with a single API, please suggest the best approach or combination of APIs to achieve this. @adizohar
import oci
config=oci.config.from_file()
compute_client = oci.core.ComputeClient(config)
# Get the list of compartments
identity_client = oci.identity.IdentityClient(config)
compartment_response = identity_client.list_compartments(compartment_id=config["tenancy"])
detached_count = 0
# Iterate over each compartment and retrieve the volume details for each region
for compartment in compartment_response.data:
compartment_id = compartment.id
# Get the list of regions
region_response = identity_client.list_region_subscriptions(tenancy_id=config['tenancy'])
# Iterate over each region and retrieve the volume details
for region in region_response.data:
region_name = region.region_name
#List instances in the current compartment
instance_response = compute_client.list_instances(compartment_id=compartment_id).data
for instance in instance_response:
print(instance)
Activity
adizohar commentedon May 2, 2025
You should use tenantName or TenantId as group field
Check my code at https://github.com/oracle/oci-python-sdk/blob/master/examples/showusage
You can also check the documentation - https://docs.oracle.com/en-us/iaas/Content/Billing/Concepts/costanalysisoverview.htm#cost_analysis_using_the_api
Gopichand-Heeddata commentedon May 3, 2025
Thankyou @adizohar , i ll check
Gopichand-Heeddata commentedon May 3, 2025
I need to retrieve the root tenancy instance details in OCI. I have created three instances and want to fetch their metadata, along with details of child tenancies that I’ve also created.
Ideally, I want to use the same API to retrieve information from both the root tenancy and its child tenancies—not just instance data, but also any associated resources and their metrics.
If it's not possible with a single API, please suggest the best approach or combination of APIs to achieve this.
@adizohar
adizohar commentedon May 3, 2025
Hi Gopi, Please open new issue for new question, and don't forget to close the issue once answered.
You cannot query different tenants with same API, you will need to authenticate to each separately
You can see how I extract all the information (per tenant) with my showoci script - https://github.com/oracle/oci-python-sdk/tree/master/examples/showoci