googleapis / google-cloud-python

Google Cloud Client Library for Python
https://googleapis.github.io/google-cloud-python/
Apache License 2.0
4.8k stars 1.51k forks source link

Removing the last Alias IP Range from a Network interface fails #11931

Open sschols opened 11 months ago

sschols commented 11 months ago

When trying to remove an Alias IP range from a network interface, it fails when removing the last alias IP range. The operation itself finishes successfully, but the alias ip range is still there.

It seems like when emptying the alias_ip_range property, protobuffer does not send it along the request at all, making the "backend" think it's not supposed to change the alias_ip_range property it all. But I could not find a way to avoid this behavior.

Environment details

Steps to reproduce

  1. Add an Alias IP range to a instance/network interface
  2. Get the instance via Python SDK, remove all entries from the alias_ip_range list in the network interface
  3. Submit the changed nic via a UpdateNetworkInterfaceInstanceRequest

Code example

nic.alias_ip_ranges = [a for a in alias_ips if not a.ip_cidr_range == f"{args.address}/32"]

request = compute_v1.UpdateNetworkInterfaceInstanceRequest(
    instance=instance.name,
    network_interface=nic.name,
    project=project_id,
    network_interface_resource = nic,
    zone=vm["availability_zone"]
)

operation = client.update_network_interface(request=request)

wait_for_extended_operation(operation, "IP address removal")

Stack trace

Making sure to follow these steps will guarantee the quickest resolution possible.

Thanks!

parthea commented 10 months ago

I believe this is related to a limitation in protobuf: Similar to proto2 APIs, proto3 does not track presence explicitly for repeated fields. : https://github.com/protocolbuffers/protobuf/blob/main/docs/field_presence.md

Assigning to @vchudnov-g who is investigating solutions for a similar issue. (Googlers see b/223609100)

sschols commented 10 months ago

It's been a while, do you have any updates or potential workarounds on this?

vchudnov-g commented 10 months ago

We don't have any updates yet; we're still investigating a good solution/workaround for this. We will update this issue as we progress.

B16CS006 commented 3 months ago

Is there any work around using this library itself?