oracle / oracle/oci-python-sdk

How can we retrieve the cost of child tenancies using the OCI Python SDK and the Usage API?

Open
#763 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
474
Forks
321
Avg merge
23m
Merged PRs (30d)
4

Description

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?.

import oci

config = oci.config.from_file()
tenant_id = config['tenancy']
time_usage_started = "2024-04-01T00:00:00Z"
time_usage_ended = "2024-04-21T00:00:00Z"
lis=[]
usage_client = oci.usage_api.UsageapiClient(config,timeout=(10,3000))

requestSummarizedUsagesDetails = oci.usage_api.models.RequestSummarizedUsagesDetails(
    tenant_id=tenant_id,
    granularity='DAILY',
    query_type='USAGE',
    group_by=[ 'resourceId','service','compartmentName'],
    time_usage_started=time_usage_started,
    time_usage_ended=time_usage_ended,
    compartment_depth=2
)
# CUSTOM_RETRY_STRATEGY = RetryStrategyBuilder().add_max_attempts(max_attempts=8) \
#     .add_total_elapsed_time(total_elapsed_time_seconds=25000) \
#     .add_service_error_check(service_error_retry_config=retry_checkers.RETRYABLE_STATUSES_AND_CODES,
#                              service_error_retry_on_any_5xx=True) \
#     .get_retry_strategy()

# Retrieve summarized usage data
request_summarized_usages = usage_client.request_summarized_usages(
    requestSummarizedUsagesDetails,
    retry_strategy=oci.retry.DEFAULT_RETRY_STRATEGY
)

for item in request_summarized_usages.data.items:
    print(len(item.resource_id))

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue contains a Python example using oci.usage_api.UsageapiClient and request_summarized_usages, but names no repository file or test. Start by reviewing the Usage API request and tenancy parameters shown in the example. Done would require a clear, verified explanation or documentation of how to retrieve child-tenancy costs from the parent tenancy.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, cloud
Issue type
Documentation
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.