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

Joe
  • 2,500
  • 1
  • 14
  • 12

1 Answers1

1

This is because you are defining the security rules fields as tuples, not as lists.

Your code:

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

Should be:

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

As the docs mention, these fields should be of type list, not type tuple.

Joe
  • 2,500
  • 1
  • 14
  • 12