Skip to content

Commit

Permalink
Adds ability to enable IP6 on new droplets
Browse files Browse the repository at this point in the history
  • Loading branch information
petems committed Oct 23, 2015
1 parent 75f9ba9 commit e563d09
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
5 changes: 5 additions & 0 deletions lib/tugboat/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ def ssh(name=nil)
:type => :boolean,
:aliases => "-p",
:desc => "Enable private networking on the droplet"
method_option "ip6",
:type => :boolean,
:aliases => "-l",
:desc => "Enable IP6 on the droplet"
method_option "backups_enabled",
:type => :boolean,
:aliases => "-b",
Expand All @@ -168,6 +172,7 @@ def create(name)
"create_droplet_region_id" => options[:region],
"create_droplet_ssh_key_ids" => options[:keys],
"create_droplet_private_networking" => options[:private_networking],
"create_droplet_ip6" => options[:ip6],
"create_droplet_backups_enabled" => options[:backups_enabled],
"create_droplet_name" => name,
"user_quiet" => options[:quiet]
Expand Down
5 changes: 5 additions & 0 deletions lib/tugboat/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Configuration
DEFAULT_IMAGE = 'ubuntu-14-04-x64'
DEFAULT_SIZE = '512mb'
DEFAULT_SSH_KEY = ''
DEFAULT_IP6 = 'false'
DEFAULT_PRIVATE_NETWORKING = 'false'
DEFAULT_BACKUPS_ENABLED = 'false'

Expand Down Expand Up @@ -73,6 +74,10 @@ def default_ssh_key
@data['defaults'].nil? ? DEFAULT_SSH_KEY : @data['defaults']['ssh_key']
end

def default_ip6
@data['defaults'].nil? ? DEFAULT_IP6 : @data['defaults']['ip6']
end

def default_private_networking
@data['defaults'].nil? ? DEFAULT_PRIVATE_NETWORKING : @data['defaults']['private_networking']
end
Expand Down
7 changes: 6 additions & 1 deletion lib/tugboat/middleware/create_droplet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ def call(env)
droplet_private_networking = env["create_droplet_private_networking"] :
droplet_private_networking = env["config"].default_private_networking


env["create_droplet_ip6"] ?
droplet_ip6 = env["create_droplet_ip6"] :
droplet_ip6 = env["config"].default_ip6

env["create_droplet_backups_enabled"] ?
droplet_backups_enabled = env["create_droplet_backups_enabled"] :
droplet_backups_enabled = env["config"].default_backups_enabled
Expand All @@ -40,7 +45,7 @@ def call(env)
:ssh_keys => [droplet_ssh_key_id],
:private_networking => droplet_private_networking,
:backups_enabled => droplet_backups_enabled,
:ipv6 => nil,
:ipv6 => droplet_ip6,
}

response = ocean.droplet.create(create_opts)
Expand Down
17 changes: 16 additions & 1 deletion spec/cli/create_cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,23 @@

end

it "with ip6 enable args" do
stub_request(:post, "https://api.digitalocean.com/v2/droplets").
with(:body => "{\"name\":\"example.com\",\"size\":\"1gb\",\"image\":\"ubuntu-12-04-x64\",\"region\":\"nyc3\",\"ssh_keys\":[\"foo_bar_key\"],\"private_networking\":\"false\",\"backups_enabled\":\"false\",\"ipv6\":\"true\"}",
:headers => {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'Bearer foo', 'Content-Type'=>'application/json', 'User-Agent'=>'Faraday v0.9.2'}).
to_return(:status => 200, :body => fixture('create_droplet'), :headers => {})

@cli.options = @cli.options.merge(:ip6 => 'true')
@cli.create('example.com')

expect($stdout.string).to eq <<-eos
Queueing creation of droplet 'example.com'...Droplet created!
eos

end

it "doesn't create a droplet when mistyping help command" do
help_text = "Usage:\n rspec create NAME\n\nOptions:\n -s, [--size=N] # The size_id of the droplet\n -i, [--image=N] # The image_id of the droplet\n -r, [--region=N] # The region_id of the droplet\n -k, [--keys=KEYS] # A comma separated list of SSH key ids to add to the droplet\n -p, [--private-networking] # Enable private networking on the droplet\n -b, [--backups-enabled] # Enable backups on the droplet\n -q, [--quiet] \n\nCreate a droplet.\n"
help_text = "Usage:\n rspec create NAME\n\nOptions:\n -s, [--size=N] # The size_id of the droplet\n -i, [--image=N] # The image_id of the droplet\n -r, [--region=N] # The region_id of the droplet\n -k, [--keys=KEYS] # A comma separated list of SSH key ids to add to the droplet\n -p, [--private-networking] # Enable private networking on the droplet\n -l, [--ip6] # Enable IP6 on the droplet\n -b, [--backups-enabled] # Enable backups on the droplet\n -q, [--quiet] \n\nCreate a droplet.\n"

@cli.create('help')
expect($stdout.string).to eq help_text
Expand Down

0 comments on commit e563d09

Please sign in to comment.