if ip_forwarding: response = service.instances().setIamPolicy( project=project, zone=zone, resource=instance, body={ "canIpForward": False } ).execute() print(f"IP Forwarding has been disabled for {instance}.")else: print(f"IP Forwarding is already disabled for {instance}.")
Verify that IP Forwarding has been disabled by checking the current status again:
Copy
Ask AI
response = service.instances().get(project=project, zone=zone, instance=instance).execute()ip_forwarding = response['canIpForward']if not ip_forwarding: print(f"IP Forwarding has been successfully disabled for {instance}.")else: print(f"Failed to disable IP Forwarding for {instance}.")
Note: Make sure to replace the project, zone, and instance variables with your own values.