LibclusterMesh.Parse (libcluster_mesh v0.1.0)

Copy Markdown View Source

Field-level parsing shared by the mesh status parsers.

Every mesh reports its peers in a different format, but the two fields the strategies read are read the same way everywhere: an address is only usable as a node name when it is a plain IPv4 address, and a mesh name is only a hostname up to its first dot.

Both functions accept any term. A daemon whose output does not match this library's expectations has to make a peer be skipped, not make the poll raise — the parsers promise never to raise, and that promise is only worth something if the helpers they are built from keep it too.

Summary

Functions

The hostname part of a mesh name: everything before the first dot.

Returns true when the value is a string holding a plain IPv4 address.

Functions

hostname(name)

@spec hostname(term()) :: String.t()

The hostname part of a mesh name: everything before the first dot.

Anything that is not a string becomes "", which no configured hostname prefix can match (LibclusterMesh.Config refuses an empty prefix), so a peer whose name field is missing is skipped rather than connected to under a name it does not answer to.

iex> LibclusterMesh.Parse.hostname("myapp-1.example.ts.net.")
"myapp-1"

iex> LibclusterMesh.Parse.hostname("myapp-1")
"myapp-1"

iex> LibclusterMesh.Parse.hostname(nil)
""

ipv4?(value)

@spec ipv4?(term()) :: boolean()

Returns true when the value is a string holding a plain IPv4 address.

Strict, so a prefix length or a zero-padded octet is not one — both appear in mesh output and neither is an address a node can be reached at.

iex> LibclusterMesh.Parse.ipv4?("100.64.0.2")
true

iex> LibclusterMesh.Parse.ipv4?("100.64.0.2/32")
false

iex> LibclusterMesh.Parse.ipv4?("fd00::2")
false

iex> LibclusterMesh.Parse.ipv4?(nil)
false