I am trying to get the list of all compartments
(including child compartments) in OCI Tenancy
using Python SDK
.
But the below OCI API
does not give the root compartment
details.
Is there a way to get root compartment
details via any API directly?
Below is my code:
import oci
from oci.config import from_file
from oci.signer import Signer
config = from_file()
COMPARTMENT_ID="ocid1.tenancy.oc1..a"
identity_client = oci.identity.IdentityClient(config)
list_compartments_response = identity_client.list_compartments(
compartment_id=COMPARTMENT_ID,
compartment_id_in_subtree=True)
compartmentlist = list_compartments_response.data
compartmentlist
dict does not contain the root compartment
details.
Please help.
Edit 1:
COMPARTMENT_ID
given above in the code is the root compartment ID
. I need the details of even this root compartment
in the final response of API.
list_compartments
gives details of all thesub-compartments
under a particularcompartment OCID
provided to the API.If you are providing
root compartment OCID
to this API then it will give all thecompartment
details underroot compartment
excluding theroot
.For appending the
root compartment
details, below API can be used. I am not aware of any otherOCI API
to accomplish this task.Hope this helps you.