我正在尝试通过 API 调用获取资源或实例的生命周期状态。
有通过分组进行的 API 调用,但我找不到单个 API 调用来获取生命周期状态。我在这里错过了什么还是走错了路?
有什么建议可以在一次 API 调用中获取所有资源生命周期状态吗?
见过不同的 API 调用,例如
list_categories
,这里是代码:
list_categories_response = optimizer_client.list_categories(
compartment_id='ocid1.tenancy.oc1..aaaaaaaau2ommhsjq2vocet4e6nz3p76gefajqcjjxrj2x2ovvllexyey7ja',
compartment_id_in_subtree=True,
include_organization=True,
sort_order="ASC",
sort_by="NAME",
lifecycle_state="DELETED",
)
这是我收到的错误:
self.raise_transient_service_error(request, response, service_code, message, operation_name, api_reference_link, target_service, request_endpoint, client_version, timestamp, deserialized_data)
File "/home/ubuntu/.local/lib/python3.8/site-packages/oci/base_client.py", line 892, in raise_transient_service_error
raise exceptions.TransientServiceError(
oci.exceptions.TransientServiceError: {'target_service': 'optimizer', 'status': 500, 'code': 'InternalError', 'opc-request-id': '5EB910E3EB1B4493B4ED444AB0A28DF3/66BA242702176FFB8B1DEB08DCA2D9F9/A2BEC1E908F38A745C4E79555C630313', 'message': 'Internal error occurred', 'operation_name': 'list_categories', 'timestamp': '2023-12-14T04:27:31.668993+00:00', 'client_version': 'Oracle-PythonSDK/2.118.0', 'request_endpoint': 'GET https://optimizer.ap-hyderabad-1.oci.oraclecloud.com/20200606/categories', 'logging_tips': 'To get more info on the failing request, refer to https://docs.oracle.com/en-us/iaas/tools/python/latest/logging.html for ways to log the request/response details.', 'troubleshooting_tips': "See https://docs.oracle.com/iaas/Content/API/References/apierrors.htm#apierrors_500__500_internalerror for more information about resolving this error. Also see https://docs.oracle.com/iaas/api/#/en/advisor/20200606/CategorySummary/ListCategories for details on this operation's requirements. If you are unable to resolve this optimizer issue, please contact Oracle support and provide them this full error message."}
ubuntu@ubuntu-Latitu
有几种方法可以做到这一点,但如果您只有少量实例,最好是使用搜索服务。
来自 CLI:
$ oci search resource structured-search --query-text 'query instance resources'
结果将是所有计算实例及其生命周期状态(生命周期状态)的列表
"display-name": "instance90210",
"freeform-tags": {},
"identifier": "ocid1.instance.oc1.iad.XXX",
"identity-context": {},
"lifecycle-state": "Stopped",
"resource-type": "Instance",