我尝试使用python脚本并面对TypeError,为OCI中的特定计算示例添加标记(freefrom_tag

pn9klfpd  于 2022-12-14  发布在  Python
关注(0)|答案(1)|浏览(81)

请查找错误****更新卷响应=核心客户端.更新示例(示例ID=i.ID,更新示例详细信息= oci.核心.模型.更新示例详细信息(freeform_tags))类型错误:UpdateInstanceDetails.init()采用1个位置参数,但给出了2个

core_client = oci.core.compute_client.ComputeClient(config)
core_client.base_client.set_region('us-phoenix-1')
vol=oci.core.BlockstorageClient(config)
# Send the request to service, there are more available parameters to send in the request
lista = core_client.list_instances(compartment_id=compartment_id,lifecycle_state="STOPPED")

for i in lista.data:
    inst=core_client.get_instance(instance_id=i.id)
    #print(inst.data)
    update_volume_response = core_client.update_instance(update_instance_details = oci.core.models.UpdateInstanceDetails(freefrom_tag={"shutdown": "no"}))
    print(update_volume_response) 
    break
rhfm7lfc

rhfm7lfc1#

更新示例API要求将instanceId作为必需参数,但您的代码中似乎缺少该参数。然后,您可以提供freeform_tags(而不是freefrom_tag)作为可选属性。
API参考-https://docs.oracle.com/en-us/iaas/api/#/en/iaas/20160918/Instance/UpdateInstance
下面是对我有效的示例:

core_client = oci.core.compute_client.ComputeClient(config)
core_client.base_client.set_region('us-phoenix-1')
# Send the request to service, there are more available parameters to send in the request
lista = core_client.list_instances(compartment_id=compartment_id,lifecycle_state="STOPPED")

for i in lista.data:
  update_instance_response = core_client.update_instance(
  instance_id=i.id,
  update_instance_details=oci.core.models.UpdateInstanceDetails(
        freeform_tags={
        'shutdown': 'no'})
   )
   break

希望有帮助。

相关问题