Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to configure ip_to_nodename function #17

Merged
merged 1 commit into from
May 3, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions lib/strategy/tags.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ defmodule ClusterEC2.Strategy.Tags do
strategy: #{__MODULE__},
config: [
ec2_tagname: "mytag",
ec2_tagvalue: "tagvalue"
app_prefix: "app"
ip_type: :private
ec2_tagvalue: "tagvalue",
app_prefix: "app",
ip_to_nodename: &my_nodename_func/2,
ip_type: :private,
polling_interval: 10_000]]]

## Configuration Options
Expand All @@ -25,6 +26,7 @@ defmodule ClusterEC2.Strategy.Tags do
| `:ec2_tagvalue` | no | Can be passed a static value (string), a 0-arity function, or a 1-arity function (which will be passed the value of `:ec2_tagname` at invocation). |
| `:app_prefix` | no | Will be prepended to the node's private IP address to create the node name. |
| `:ip_type` | no | One of :private or :public, defaults to :private |
| `:ip_to_nodename` | no | defaults to `app_prefix@ip` but can be used to override the nodename |
| `:polling_interval` | no | Number of milliseconds to wait between polls to the EC2 api. Defaults to 5_000 |
"""

Expand Down Expand Up @@ -123,6 +125,7 @@ defmodule ClusterEC2.Strategy.Tags do
tag_name = Keyword.fetch!(config, :ec2_tagname)
tag_value = Keyword.get(config, :ec2_tagvalue, &local_instance_tag_value(&1, instance_id, region))
app_prefix = Keyword.get(config, :app_prefix, "app")
ip_to_nodename = Keyword.get(config, :ip_to_nodename, &ip_to_nodename/2)

cond do
tag_name != nil and tag_value != nil and app_prefix != nil and instance_id != "" and region != "" ->
Expand All @@ -136,7 +139,7 @@ defmodule ClusterEC2.Strategy.Tags do
resp =
body
|> SweetXml.xpath(ip_xpath(Keyword.get(config, :ip_type, :private)))
|> ip_to_nodename(app_prefix)
|> ip_to_nodename.(app_prefix)

{:ok, MapSet.new(resp)}

Expand Down