func getInstanceIPAddresses()

in compute/address/get_vm_address.go [27:67]


func getInstanceIPAddresses(w io.Writer, instance *computepb.Instance, addressType computepb.Address_AddressType, isIPV6 bool) []string {
	var ips []string

	if instance.GetNetworkInterfaces() == nil {
		return ips
	}

	for _, iface := range instance.GetNetworkInterfaces() {
		if isIPV6 {
			// Handle IPv6 addresses
			if addressType == computepb.Address_EXTERNAL {
				if ipv6Configs := iface.GetIpv6AccessConfigs(); ipv6Configs != nil {
					for _, ipv6Config := range ipv6Configs {
						if ipv6Config.GetType() == "DIRECT_IPV6" {
							ips = append(ips, ipv6Config.GetExternalIpv6())
						}
					}
				}
			} else if addressType == computepb.Address_INTERNAL {
				if internalIPv6 := iface.GetIpv6Address(); internalIPv6 != "" {
					ips = append(ips, internalIPv6)
				}
			}
		} else {
			// Handle IPv4 addresses
			if addressType == computepb.Address_EXTERNAL {
				for _, config := range iface.GetAccessConfigs() {
					if config.GetType() == "ONE_TO_ONE_NAT" {
						ips = append(ips, config.GetNatIP())
					}
				}
			} else if addressType == computepb.Address_INTERNAL {
				ips = append(ips, iface.GetNetworkIP())
			}
		}
	}

	fmt.Fprintf(w, "Received list of IPS: [%s]", strings.Join(ips, ", "))

	return ips
}