vagrant-digitalocean 0.0.4 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -1
- data/Gemfile +1 -4
- data/LICENSE.txt +2 -1
- data/README.md +114 -96
- data/Rakefile +8 -10
- data/box/digital_ocean.box +0 -0
- data/lib/vagrant-digitalocean.rb +12 -4
- data/lib/vagrant-digitalocean/actions.rb +159 -0
- data/lib/vagrant-digitalocean/actions/check_state.rb +19 -0
- data/lib/vagrant-digitalocean/actions/create.rb +36 -21
- data/lib/vagrant-digitalocean/actions/destroy.rb +10 -8
- data/lib/vagrant-digitalocean/actions/modify_provision_path.rb +15 -17
- data/lib/vagrant-digitalocean/actions/power_off.rb +33 -0
- data/lib/vagrant-digitalocean/actions/power_on.rb +34 -0
- data/lib/vagrant-digitalocean/actions/rebuild.rb +9 -9
- data/lib/vagrant-digitalocean/actions/reload.rb +31 -0
- data/lib/vagrant-digitalocean/actions/setup_key.rb +56 -0
- data/lib/vagrant-digitalocean/actions/setup_provisioner.rb +26 -15
- data/lib/vagrant-digitalocean/actions/setup_sudo.rb +19 -12
- data/lib/vagrant-digitalocean/actions/setup_user.rb +25 -27
- data/lib/vagrant-digitalocean/actions/sync_folders.rb +18 -17
- data/lib/vagrant-digitalocean/commands/rebuild.rb +2 -3
- data/lib/vagrant-digitalocean/config.rb +30 -33
- data/lib/vagrant-digitalocean/errors.rb +0 -2
- data/lib/vagrant-digitalocean/helpers/client.rb +13 -15
- data/lib/vagrant-digitalocean/plugin.rb +5 -14
- data/lib/vagrant-digitalocean/provider.rb +48 -34
- data/lib/vagrant-digitalocean/version.rb +1 -1
- data/locales/en.yml +32 -40
- data/test/Vagrantfile +37 -0
- data/test/cookbooks/test/recipes/default.rb +1 -1
- data/test/scripts/provision.sh +3 -0
- data/test/test.sh +14 -0
- metadata +15 -27
- data/bin/build.sh +0 -39
- data/bin/test_run.sh +0 -15
- data/box/Vagrantfile +0 -20
- data/box/cookbooks/foo/recipes/default.rb +0 -1
- data/lib/vagrant-digitalocean/action.rb +0 -105
- data/lib/vagrant-digitalocean/actions/check_ssh_user.rb +0 -46
- data/lib/vagrant-digitalocean/actions/is_active.rb +0 -16
- data/lib/vagrant-digitalocean/actions/message_is_active.rb +0 -18
- data/lib/vagrant-digitalocean/actions/read_state.rb +0 -33
- data/lib/vagrant-digitalocean/actions/setup_ssh_key.rb +0 -60
- data/lib/vagrant-digitalocean/helpers/file.rb +0 -41
- data/lib/vagrant-digitalocean/helpers/translator.rb +0 -20
- data/scripts/chef/debian.sh +0 -5
- data/scripts/chef/redhat.sh +0 -5
- data/scripts/nfs/debian.sh +0 -4
- data/scripts/nfs/redhat.sh +0 -11
- data/scripts/sudo/redhat.sh +0 -2
- data/test/Vagrantfile.centos +0 -19
- data/test/Vagrantfile.ubuntu +0 -21
- data/test/provision.sh +0 -3
- data/test/scripts/setup_user.sh +0 -18
@@ -1,46 +0,0 @@
|
|
1
|
-
module VagrantPlugins
|
2
|
-
module DigitalOcean
|
3
|
-
module Actions
|
4
|
-
class CheckSSHUser
|
5
|
-
include Vagrant::Util::Counter
|
6
|
-
|
7
|
-
def initialize(app, env)
|
8
|
-
@app = app
|
9
|
-
@machine = env[:machine]
|
10
|
-
@translator = Helpers::Translator.new("actions.check_ssh_user")
|
11
|
-
end
|
12
|
-
|
13
|
-
def call(env)
|
14
|
-
# return if the machine is set with the default ssh username
|
15
|
-
return @app.call(env) if @machine.ssh_info()[:username] == "root"
|
16
|
-
|
17
|
-
# check if ssh username account has been provisioned
|
18
|
-
begin
|
19
|
-
tries = @machine.config.ssh.max_tries
|
20
|
-
@machine.config.ssh.max_tries = 0
|
21
|
-
@machine.communicate.execute("echo")
|
22
|
-
rescue Vagrant::Errors::SSHAuthenticationFailed
|
23
|
-
original_username = @machine.ssh_info()[:username]
|
24
|
-
@machine.provider_config.ssh_username = "root"
|
25
|
-
env[:ui].info @translator.t('fallback', {
|
26
|
-
:user => original_username
|
27
|
-
})
|
28
|
-
|
29
|
-
# TODO remove when vagrant chef provisioning defect fixed
|
30
|
-
@machine.config.ssh.username = "root"
|
31
|
-
end
|
32
|
-
|
33
|
-
@machine.config.ssh.max_tries = tries
|
34
|
-
|
35
|
-
@app.call(env)
|
36
|
-
|
37
|
-
# reset ssh username
|
38
|
-
@machine.provider_config.ssh_username = original_username
|
39
|
-
|
40
|
-
# TODO remove when vagrant chef provisioning defect fixed
|
41
|
-
@machine.config.ssh.username = original_username
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
module VagrantPlugins
|
2
|
-
module DigitalOcean
|
3
|
-
module Actions
|
4
|
-
class IsActive
|
5
|
-
def initialize(app, env)
|
6
|
-
@app = app
|
7
|
-
end
|
8
|
-
|
9
|
-
def call(env)
|
10
|
-
env[:is_active] = env[:machine].state.id == :active
|
11
|
-
@app.call(env)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
module VagrantPlugins
|
2
|
-
module DigitalOcean
|
3
|
-
module Actions
|
4
|
-
class MessageIsActive
|
5
|
-
def initialize(app, env)
|
6
|
-
@app = app
|
7
|
-
@translator = Helpers::Translator.new("actions.message_is_active")
|
8
|
-
end
|
9
|
-
|
10
|
-
def call(env)
|
11
|
-
msg = env[:is_active] ? "active" : "not_active"
|
12
|
-
env[:ui].info @translator.t(msg)
|
13
|
-
@app.call(env)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
require "vagrant-digitalocean/helpers/client"
|
2
|
-
|
3
|
-
module VagrantPlugins
|
4
|
-
module DigitalOcean
|
5
|
-
module Actions
|
6
|
-
class ReadState
|
7
|
-
include Helpers::Client
|
8
|
-
|
9
|
-
def initialize(app, env)
|
10
|
-
@app, @env = app, env
|
11
|
-
@client = client
|
12
|
-
end
|
13
|
-
|
14
|
-
def call(env)
|
15
|
-
# If we have a machine id ask the api what the state is
|
16
|
-
if env[:machine].id
|
17
|
-
droplet = @client.request("/droplets/#{env[:machine].id}")["droplet"]
|
18
|
-
|
19
|
-
env[:machine_state] = droplet
|
20
|
-
end
|
21
|
-
|
22
|
-
# no id signals that the machine hasn't yet been created
|
23
|
-
env[:machine_state] ||= {"status" => :not_created}
|
24
|
-
|
25
|
-
# TODO there has to be a better way, see UP for when
|
26
|
-
# :machine_just_created is set
|
27
|
-
env[:machine_state][:just_created] = env[:machine_just_created]
|
28
|
-
@app.call(env)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,60 +0,0 @@
|
|
1
|
-
require "vagrant-digitalocean/helpers/client"
|
2
|
-
|
3
|
-
module VagrantPlugins
|
4
|
-
module DigitalOcean
|
5
|
-
module Actions
|
6
|
-
class SetupSSHKey
|
7
|
-
include Helpers::Client
|
8
|
-
|
9
|
-
def initialize(app, env)
|
10
|
-
@app, @env = app, env
|
11
|
-
@client = client
|
12
|
-
@translator = Helpers::Translator.new("actions.setup_ssh_key")
|
13
|
-
end
|
14
|
-
|
15
|
-
# TODO check the content of the key to see if it has changed
|
16
|
-
def call(env)
|
17
|
-
ssh_key_name = env[:machine].provider_config.ssh_key_name
|
18
|
-
|
19
|
-
begin
|
20
|
-
# assigns existing ssh key id to env for use by other commands
|
21
|
-
env[:ssh_key_id] = @client
|
22
|
-
.request("/ssh_keys/")
|
23
|
-
.find_id(:ssh_keys, :name => ssh_key_name)
|
24
|
-
|
25
|
-
env[:ui].info @translator.t("existing_key", { :name => ssh_key_name })
|
26
|
-
rescue Errors::ResultMatchError
|
27
|
-
env[:ssh_key_id] = create_ssh_key(ssh_key_name, env)
|
28
|
-
end
|
29
|
-
|
30
|
-
@app.call(env)
|
31
|
-
end
|
32
|
-
|
33
|
-
private
|
34
|
-
|
35
|
-
def create_ssh_key(name, env)
|
36
|
-
# assumes public key exists on the same path as private key with .pub ext
|
37
|
-
path = env[:machine].provider_config.ssh_private_key_path
|
38
|
-
path = env[:machine].config.ssh.private_key_path if !path
|
39
|
-
path = File.expand_path("#{path}.pub", env[:machine].env.root_path)
|
40
|
-
|
41
|
-
env[:ui].info @translator.t("new_key", { :name => name, :path => path })
|
42
|
-
begin
|
43
|
-
file = File.open(path)
|
44
|
-
key = file.read
|
45
|
-
file.close
|
46
|
-
rescue
|
47
|
-
raise Errors::PublicKeyError,
|
48
|
-
:path => path
|
49
|
-
end
|
50
|
-
|
51
|
-
result = @client.request("/ssh_keys/new", {
|
52
|
-
:name => name,
|
53
|
-
:ssh_pub_key => key
|
54
|
-
})
|
55
|
-
result["ssh_key"]["id"]
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
module VagrantPlugins
|
4
|
-
module DigitalOcean
|
5
|
-
module Helpers
|
6
|
-
module File
|
7
|
-
# TODO the optional exceptions are clumsy
|
8
|
-
def read_file(relative_path, except = true)
|
9
|
-
content = ""
|
10
|
-
path = ::File.join(DigitalOcean.source_root, relative_path)
|
11
|
-
|
12
|
-
begin
|
13
|
-
::File.open(path) do |file|
|
14
|
-
content = file.read
|
15
|
-
end
|
16
|
-
rescue Errno::ENOENT => e
|
17
|
-
# ignore the missing file if except is false
|
18
|
-
raise(e) if except
|
19
|
-
end
|
20
|
-
|
21
|
-
content
|
22
|
-
end
|
23
|
-
|
24
|
-
# TODO the optional exceptions are clumsy
|
25
|
-
# read a script and match it to the guest operating system
|
26
|
-
def read_script(dir, guest, except = true)
|
27
|
-
script_dir = ::File.join("scripts", dir)
|
28
|
-
guest_name = guest.class.to_s
|
29
|
-
|
30
|
-
if guest_name =~ /Debian/ || guest_name =~ /Ubuntu/
|
31
|
-
read_file(::File.join(script_dir, "debian.sh"), except)
|
32
|
-
elsif guest_name =~ /RedHat/
|
33
|
-
read_file(::File.join(script_dir, "redhat.sh"), except)
|
34
|
-
else
|
35
|
-
raise "unsupported guest operating system" if except
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
module VagrantPlugins
|
2
|
-
module DigitalOcean
|
3
|
-
module Helpers
|
4
|
-
class Translator
|
5
|
-
def self.plugin_namespace=(val)
|
6
|
-
@@plugin_namespace = val
|
7
|
-
end
|
8
|
-
|
9
|
-
def initialize(namespace)
|
10
|
-
@namespace = namespace
|
11
|
-
end
|
12
|
-
|
13
|
-
def t(keys, opts = {})
|
14
|
-
value = I18n.t("#{@@plugin_namespace}.#{@namespace}.#{keys}", opts)
|
15
|
-
opts[:progress] == false ? value : value + "..."
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
data/scripts/chef/debian.sh
DELETED
data/scripts/chef/redhat.sh
DELETED
data/scripts/nfs/debian.sh
DELETED
data/scripts/nfs/redhat.sh
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
if (service --status-all | grep nfs); then exit 0; fi;
|
2
|
-
|
3
|
-
# install the nfs-kernel server
|
4
|
-
yum install -y nfs-utils nfs-utils-lib;
|
5
|
-
|
6
|
-
# add to startup
|
7
|
-
chkconfig nfs on;
|
8
|
-
|
9
|
-
# make sure it's on after the install
|
10
|
-
service rpcbind start;
|
11
|
-
service nfs start;
|
data/scripts/sudo/redhat.sh
DELETED
data/test/Vagrantfile.centos
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
Vagrant.configure("2") do |config|
|
2
|
-
config.vm.box = "digital_ocean"
|
3
|
-
config.ssh.private_key_path = "test_id_rsa"
|
4
|
-
|
5
|
-
config.vm.provider :digital_ocean do |vm|
|
6
|
-
vm.client_id = ENV["DO_CLIENT_ID"]
|
7
|
-
vm.api_key = ENV["DO_API_KEY"]
|
8
|
-
vm.image = "CentOS 6.3 x64"
|
9
|
-
vm.region = "New York 1"
|
10
|
-
vm.size = "512MB"
|
11
|
-
end
|
12
|
-
|
13
|
-
config.vm.provision :shell, :path => "provision.sh"
|
14
|
-
|
15
|
-
config.vm.provision :chef_solo do |chef|
|
16
|
-
chef.cookbooks_path = "cookbooks"
|
17
|
-
chef.add_recipe "test"
|
18
|
-
end
|
19
|
-
end
|
data/test/Vagrantfile.ubuntu
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
Vagrant.configure("2") do |config|
|
2
|
-
config.vm.box = "digital_ocean"
|
3
|
-
|
4
|
-
config.vm.provider :digital_ocean do |vm|
|
5
|
-
vm.client_id = ENV["DO_CLIENT_ID"]
|
6
|
-
vm.api_key = ENV["DO_API_KEY"]
|
7
|
-
vm.image = "Ubuntu 12.04 x32 Server"
|
8
|
-
vm.region = "New York 1"
|
9
|
-
vm.size = "512MB"
|
10
|
-
vm.ssh_key_name = "Test Key"
|
11
|
-
vm.ssh_private_key_path = "test_id_rsa"
|
12
|
-
vm.ssh_username = "tester"
|
13
|
-
end
|
14
|
-
|
15
|
-
config.vm.provision :shell, :path => "scripts/setup_user.sh"
|
16
|
-
|
17
|
-
config.vm.provision :chef_solo do |chef|
|
18
|
-
chef.cookbooks_path = "cookbooks"
|
19
|
-
chef.add_recipe "test"
|
20
|
-
end
|
21
|
-
end
|
data/test/provision.sh
DELETED
data/test/scripts/setup_user.sh
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
#!/bin/bash
|
2
|
-
|
3
|
-
if ! grep tester /etc/passwd; then
|
4
|
-
useradd -m -s /bin/bash tester
|
5
|
-
fi
|
6
|
-
|
7
|
-
if ! grep tester /etc/sudoers; then
|
8
|
-
echo "tester ALL=(ALL:ALL) NOPASSWD: ALL" >> /etc/sudoers
|
9
|
-
fi
|
10
|
-
|
11
|
-
mkdir -p /home/tester/.ssh
|
12
|
-
chown tester:tester /home/tester/.ssh
|
13
|
-
|
14
|
-
pub_key="ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCbFlHJ++BcXGU9b2K+jF990r16uqkKnWiK2CFS0PFvM9IJs3CoGiIlyc9UD9O4LEyeu5Rw0RdiAp9MvyUPcDUeibw3WlMCFJ53mbioAapMy5tPXmxxJH5KcN2uJKESsH/1hJv0tWfVpHQywVLcf/7HWPjDl3qEFqzwGEN+5V3XqyG+hoA4rLTLDL40G68bL/oC7ere3sz3B16U4NGdgtJZapot5gTFErFZZztql76h25Ch7isE1XAaYg6NY4z1oU8Q9Ud0sY74tDI8TF165LStb3prf1TinwaMbOyuQ1wrNU4aMzekiwazeo6LtHMnfPjweIGP01PwjZ8WkYcRF6tt digital_ocean provider test key"
|
15
|
-
|
16
|
-
if ! [ -e /home/tester/.ssh/authorized_keys ]; then
|
17
|
-
echo "${pub_key}" > /home/tester/.ssh/authorized_keys
|
18
|
-
fi
|