0

I am trying to automate the creation of resources in Oracle BMC. I have this python code:

import oraclebmc

config = oraclebmc.config.from_file()
network = oraclebmc.core.virtual_network_client.VirtualNetworkClient(config)

compartment_id = ...
vcn_id = ....

details = oraclebmc.core.models.CreateSecurityListDetails()
details.compartment_id = compartment_id
details.display_name = "baseline"
details.ingress_security_rules = ()
details.egress_security_rules = ()
details.vcn_id = vcn_id

network.create_security_list(details)

But when I run this code I get:

Traceback (most recent call last):
  File "deploy/cloudresources/foo.py", line 16, in <module>
    network.create_security_list(details)
  File "/Users/jwmcclai/bmcs_env/lib/python2.7/site-packages/oraclebmc/core/virtual_network_client.py", line 668, in create_security_list
    response_type="SecurityList")
  File "/lib/python2.7/site-packages/oraclebmc/base_client.py", line 124, in call_api
    body = self.sanitize_for_serialization(body)
  File "/lib/python2.7/site-packages/oraclebmc/base_client.py", line 230, in sanitize_for_serialization
    for key, val in obj_dict.items()}
  File "/lib/python2.7/site-packages/oraclebmc/base_client.py", line 230, in <dictcomp>
    for key, val in obj_dict.items()}
  File "/lib/python2.7/site-packages/oraclebmc/base_client.py", line 226, in sanitize_for_serialization
    for attr, _ in obj.swagger_types.items()
AttributeError: 'tuple' object has no attribute 'swagger_types'

I can create security lists through console and I can create other resources (VCN, instances, etc.) using the Python API. Any ideas?

Thanks

4

1 回答 1

1

这是因为您将安全规则字段定义为元组,而不是列表。

你的代码:

details.ingress_security_rules = () details.egress_security_rules = ()

应该:

details.ingress_security_rules = [] details.egress_security_rules = []

正如文档所提到的,这些字段应该是列表类型,而不是元组类型。

于 2017-06-02T21:26:29.330 回答