provider/packet/packet_discover.go
func (p *Provider) Addrs(args map[string]string, l *log.Logger) ([]string, error) {
	authToken := argsOrEnv(args, "auth_token", "PACKET_AUTH_TOKEN")
	projectID := argsOrEnv(args, "project", "PACKET_PROJECT")
	packetURL := argsOrEnv(args, "url", "PACKET_URL")
	addressType := args["address_type"]
	packetFacilities := args["facility"]
	packetTags := args["tag"]

	if addressType != "private_v4" && addressType != "public_v4" && addressType != "public_v6" {
		l.Printf("[INFO] discover-packet: Address type %s is not supported. Valid values are {private_v4,public_v4,public_v6}. Falling back to 'private_v4'", addressType)
		addressType = "private_v4"
	}

	includeFacilities := includeArgs(packetFacilities)
	includeTags := includeArgs(packetTags)

	c, err := client(p.userAgent, packetURL, authToken)
	if err != nil {
		return nil, fmt.Errorf("discover-packet: Initializing Packet client failed: %s", err)
	}

	var devices []packngo.Device

	if projectID == "" {
		return nil, fmt.Errorf("discover-packet: 'project' parameter must be provider")
	}

	devices, _, err = c.Devices.List(projectID, nil)
	if err != nil {
		return nil, fmt.Errorf("discover-packet: Fetching Packet devices failed: %s", err)
	}

	var addrs []string
	for _, d := range devices {

		if len(includeFacilities) > 0 && !Include(includeFacilities, d.Facility.Code) {
			continue
		}

		if len(includeTags) > 0 && !Any(d.Tags, func(v string) bool { return Include(includeTags, v) }) {
			continue
		}

		addressFamily := 4
		if addressType == "public_v6" {
			addressFamily = 6
		}
		for _, n := range d.Network {

			if (n.Public == (addressType == "public_v4" || addressType == "public_v6")) && n.AddressFamily == addressFamily {
				addrs = append(addrs, n.Address)
			}
		}
	}
	return addrs, nil
}
func (p *Provider) Addrs(args map[string]string, l *log.Logger) ([]string, error) {
	authToken := argsOrEnv(args, "auth_token", "PACKET_AUTH_TOKEN")
	projectID := argsOrEnv(args, "project", "PACKET_PROJECT")
	packetURL := argsOrEnv(args, "url", "PACKET_URL")
	addressType := args["address_type"]
	packetFacilities := args["facility"]
	packetTags := args["tag"]

	if addressType != "private_v4" && addressType != "public_v4" && addressType != "public_v6" {
		l.Printf("[INFO] discover-packet: Address type %s is not supported. Valid values are {private_v4,public_v4,public_v6}. Falling back to 'private_v4'", addressType)
		addressType = "private_v4"
	}

	includeFacilities := includeArgs(packetFacilities)
	includeTags := includeArgs(packetTags)

	c, err := client(p.userAgent, packetURL, authToken)
	if err != nil {
		return nil, fmt.Errorf("discover-packet: Initializing Packet client failed: %s", err)
	}

	var devices []packngo.Device

	if projectID == "" {
		return nil, fmt.Errorf("discover-packet: 'project' parameter must be provider")
	}

	devices, _, err = c.Devices.List(projectID, nil)
	if err != nil {
		return nil, fmt.Errorf("discover-packet: Fetching Packet devices failed: %s", err)
	}

	var addrs []string
	for _, d := range devices {

		if len(includeFacilities) > 0 && !Include(includeFacilities, d.Facility.Code) {
			continue
		}

		if len(includeTags) > 0 && !Any(d.Tags, func(v string) bool { return Include(includeTags, v) }) {
			continue
		}

		addressFamily := 4
		if addressType == "public_v6" {
			addressFamily = 6
		}
		for _, n := range d.Network {

			if (n.Public == (addressType == "public_v4" || addressType == "public_v6")) && n.AddressFamily == addressFamily {
				addrs = append(addrs, n.Address)
			}
		}
	}
	return addrs, nil
}
func ( p * Provider ) Addrs ( args map [ string ] string , l * log . Logger ) ( [ ] string , error ) { authToken := argsOrEnv ( args , " " , " " ) projectID := argsOrEnv ( args , " " , " " ) packetURL := argsOrEnv ( args , " " , " " ) addressType := args [ " " ] packetFacilities := args [ " " ] packetTags := args [ " " ] if addressType != " " && addressType != " " && addressType != " " { l . Printf ( " " , addressType ) addressType = " " } includeFacilities := includeArgs ( packetFacilities ) includeTags := includeArgs ( packetTags ) c , err := client ( p . userAgent , packetURL , authToken ) if err != nil { return nil , fmt . Errorf ( " " , err ) } var devices [ ] packngo . Device if projectID == " " { return nil , fmt . Errorf ( " " ) } devices , _ , err = c . Devices . List ( projectID , nil ) if err != nil { return nil , fmt . Errorf ( " " , err ) } var addrs [ ] string for _ , d := range devices { if len ( includeFacilities ) > 0 && ! Include ( includeFacilities , d . Facility . Code ) { continue } if len ( includeTags ) > 0 && ! Any ( d . Tags , func ( v string ) bool { return Include ( includeTags , v ) } ) { continue } addressFamily := 4 if addressType == " " { addressFamily = 6 } for _ , n := range d . Network { if ( n . Public == ( addressType == " " || addressType == " " ) ) && n . AddressFamily == addressFamily { addrs = append ( addrs , n . Address ) } } } return addrs , nil }
// Addrs function
Addrs function