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_compartmentsgives details of all thesub-compartmentsunder a particularcompartment OCIDprovided to the API.If you are providing
root compartment OCIDto this API then it will give all thecompartmentdetails underroot compartmentexcluding theroot.For appending the
root compartmentdetails, below API can be used. I am not aware of any otherOCI APIto accomplish this task.Hope this helps you.