此函数将一个租户中的所有隔间提供到其终点。这里 myobject 的类型是 <class 'oci.identity.models.compartment.Compartment'> 如何将其转换为 json?这是哪种类型?在使用 json.dumps() 时,它显示类型 Compartment 不是 JSON 可序列化的。
'''
import oci
import hashlib
import uuid
import json
global finale_response,tenant_id,profile
profile="abc-profile"
tenant_id = "ocid1.tenancy.oc1.."
finale_response = []
config = oci.config.from_file(profile_name=profile)
def get_compartments(id):
identity_client = oci.identity.IdentityClient(config)
list_compartments_response = identity_client.list_compartments(compartment_id=id)
response = list_compartments_response.data
if response != []:
child_compartment_list = []
for i in range(len(response)):
compartmentId = response[i].id
myobject= response[i]
print(type(myobject))
finale_response.append({"profileName":profile,
"compartmentId":compartmentId,
"tenantId": tenant_id,
"comMetadata":myobject})
child_compartment_list.append(compartmentId)
for id in child_compartment_list:
get_compartments(id)
return finale_response
myList = get_compartments(tenant_id)
print(myList)
print(type(myList))
'''