Azure-sdk-for-python: TypeError while creating VirtualNetworkGateway

Created on 16 Sep 2016  路  7Comments  路  Source: Azure/azure-sdk-for-python

I'm getting "TypeError: 'PublicIPAddress' object is not iterable" while creating VirtualNetworkGateway. Here is the stacktrace.

  File "/Users/azure-test/virtualenv_osx/lib/python2.7/site-packages/azure/mgmt/network/operations/virtual_network_gateways_operations.py", line 97, in create_or_update
    body_content = self._serialize.body(parameters, 'VirtualNetworkGateway')
  File "/Users/azure-test/virtualenv_osx/lib/python2.7/site-packages/msrest/serialization.py", line 303, in body
    data = _convert_to_datatype(data, data_type, self.dependencies)
  File "/Users/azure-test/virtualenv_osx/lib/python2.7/site-packages/msrest/serialization.py", line 171, in _convert_to_datatype
    getattr(data, attr), map['type'], localtypes))
  File "/Users/azure-test/virtualenv_osx/lib/python2.7/site-packages/msrest/serialization.py", line 150, in _convert_to_datatype
    param, data_type[1:-1], localtypes) for param in data
  File "/Users/azure-test/virtualenv_osx/lib/python2.7/site-packages/msrest/serialization.py", line 171, in _convert_to_datatype
    getattr(data, attr), map['type'], localtypes))
  File "/Users/azure-test/virtualenv_osx/lib/python2.7/site-packages/msrest/serialization.py", line 164, in _convert_to_datatype
    localtypes) for key in data
TypeError: 'PublicIPAddress' object is not iterable

Changing the following line in azure/mgmt/network/models/virtual_network_gateway_ip_configuration.py seems to resolve the issue.

from

'public_ip_address': {'key': 'properties.publicIPAddress', 'type': 'SubResource'},

to

'public_ip_address': {'key': 'properties.publicIPAddress', 'type': 'PublicIPAddress'},
ARM Service Attention bug

All 7 comments

Hi @prburgu
Thank you for the feedback!
@annatisch could you check if this is an Autorest issue? Otherwise open a RestAPI issue?

@lmazuel,
This is potentially an issue in dict->model conversion for serialization... though I'm having some trouble tracking it. Or at least it's this method that's tripping up... but I don't think the model is generated incorrectly. At least, this type syntax is used for quite a few clients presently without (apparent) problems.

@prburgu - When making this call, are you instantiating each model class explicitly? Or are you using a combination of models and dictionaries when building the request object?
Would it also be possible to see an approximation of the object you passed into the create command?

I'm making the call by instantiating each model class explicitly, something like this. The create_public_ip() makes the call to public_ip_addresses.create_or_update() and gets the result.

                    VirtualNetworkGateway(
                        ip_configurations=[
                            VirtualNetworkGatewayIPConfiguration(
                                public_ip_address=self.create_public_ip(),
                                subnet=self.get_subnet("GatewaySubnet"),
                                name=self.config.virtual_network_name)
                            ],
                        location="location",
                        gateway_type=VirtualNetworkGatewayType.vpn,
                        vpn_type=VpnType.route_based,
                        sku=VirtualNetworkGatewaySku(
                            name=VirtualNetworkGatewaySkuName.high_performance,
                            tier=VirtualNetworkGatewaySkuTier.high_performance)
                   )

@prburgu, @lmazuel,
okay - looking at that and inspecting the client, I've changed my mind and think this might be related to the spec. I will post an issue there for clarification and update this issue based on the feedback :)

Any update on this?

Hi @prburgu
Sorry for the late answer.... I was finally able to create a unit test for VN Gateway to test your issue.

public_ip_address is taking only an id, it's why a SubResource is used. Assuming self.create_public_ip() is returning a PublicIPAddress instance (you didn't share this code), your preceding code should look like this:

    public_ip_address = self.create_public_ip()
    subnet = self.get_subnet("GatewaySubnet")
    ip_configurations=[
           VirtualNetworkGatewayIPConfiguration(
               public_ip_address=SubResource(public_ip_address.id),
               subnet=SubResource(subnet.id),
               name=self.config.virtual_network_name
           )
    ]

Thanks @lmazuel. That fixed the problem.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

AmudhaPalani picture AmudhaPalani  路  4Comments

shreyasmoolya09 picture shreyasmoolya09  路  3Comments

Korijn picture Korijn  路  3Comments

Fajkowsky picture Fajkowsky  路  4Comments

smereczynski picture smereczynski  路  4Comments