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 support for floating IP #284

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ The following attributes are available to further configure the provider:
* A boolean flag indicating whether to enable IPv6
- `provider.region`
* A string representing the region to create the new Droplet in. It defaults to `nyc2`. List available regions with the `vagrant digitalocean-list regions $DIGITAL_OCEAN_TOKEN` command.
- `provider.floating_ip`
* Automatically assigns a DigitalOcean [Floating IP](https://www.digitalocean.com/docs/networking/floating-ips/) to a Droplet after it is created.
- `provider.size`
* A string representing the size to use when creating a new Droplet (e.g. `1gb`). It defaults to `512mb`. List available sizes with the `vagrant digitalocean-list sizes $DIGITAL_OCEAN_TOKEN` command.
- `provider.private_networking`
Expand Down
8 changes: 8 additions & 0 deletions lib/vagrant-digitalocean/actions/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ def call(env)
# assign the machine id for reference in other commands
@machine.id = result['droplet']['id'].to_s

# assign a specific floating IP to this droplet
if @machine.provider_config.floating_ip
result = @client.post("/v2/floating_ips/#{@machine.provider_config.floating_ip}/actions", {
:type => 'assign',
:droplet_id => @machine.id,
Copy link

@bbros-dev bbros-dev Feb 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a hanging , here that likely is preventing this from running. @kwakwaversal?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't code in Ruby (I quickly knocked this up to serve a purpose), but my understanding is that a trailing comma is purely stylistic and doesn't affect the functionality of the code.

I have added a trailing comma out of habit (to reduce line noise in MRs) but I'm using this same code on my box to provision digital ocean containers without a problem.

I think this repo might be stale. If I had feedback to tell me to drop the comma I will, but until then it will continue to knock at the PR door.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're still here! We've been working on partnering with DigitalOcean to get this plugin up-to-date with their product suite. Until then, there will be some delay on features like this.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack. I couldn't get this fix to work for me, so likely needs some closer scrutiny.
What did work was a curl script in the provisioning stage - but without DO's input it'll be painful working out a robust solution.

})
end

# refresh droplet state with provider and output ip address
droplet = Provider.droplet(@machine, :refresh => true)
public_network = droplet['networks']['v4'].find { |network| network['type'] == 'public' }
Expand Down
3 changes: 3 additions & 0 deletions lib/vagrant-digitalocean/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Config < Vagrant.plugin('2', :config)
attr_accessor :monitoring
attr_accessor :tags
attr_accessor :volumes
attr_accessor :floating_ip

alias_method :setup?, :setup

Expand All @@ -33,6 +34,7 @@ def initialize
@monitoring = UNSET_VALUE
@tags = UNSET_VALUE
@volumes = UNSET_VALUE
@floating_ip = UNSET_VALUE
end

def finalize!
Expand All @@ -50,6 +52,7 @@ def finalize!
@monitoring = false if @monitoring == UNSET_VALUE
@tags = nil if @tags == UNSET_VALUE
@volumes = nil if @volumes == UNSET_VALUE
@floating_ip = nil if @floating_ip == UNSET_VALUE
end

def validate(machine)
Expand Down