vagrant-vmpooler 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +21 -0
- data/Gemfile +15 -0
- data/LICENSE +15 -0
- data/README.md +143 -0
- data/Rakefile +22 -0
- data/example_box/Vagrantfile +22 -0
- data/example_box/dummy.box +0 -0
- data/example_box/metadata.json +3 -0
- data/example_box/readme.md +8 -0
- data/lib/vagrant-vmpooler.rb +53 -0
- data/lib/vagrant-vmpooler/action.rb +212 -0
- data/lib/vagrant-vmpooler/action/create_server.rb +103 -0
- data/lib/vagrant-vmpooler/action/delete_server.rb +50 -0
- data/lib/vagrant-vmpooler/action/hard_reboot_server.rb +24 -0
- data/lib/vagrant-vmpooler/action/is_created.rb +16 -0
- data/lib/vagrant-vmpooler/action/is_paused.rb +16 -0
- data/lib/vagrant-vmpooler/action/is_suspended.rb +16 -0
- data/lib/vagrant-vmpooler/action/message_already_created.rb +16 -0
- data/lib/vagrant-vmpooler/action/message_not_created.rb +16 -0
- data/lib/vagrant-vmpooler/action/message_server_running.rb +16 -0
- data/lib/vagrant-vmpooler/action/message_will_not_destroy.rb +16 -0
- data/lib/vagrant-vmpooler/action/pause_server.rb +24 -0
- data/lib/vagrant-vmpooler/action/read_ssh_info.rb +56 -0
- data/lib/vagrant-vmpooler/action/read_state.rb +41 -0
- data/lib/vagrant-vmpooler/action/reboot_server.rb +24 -0
- data/lib/vagrant-vmpooler/action/resume_server.rb +25 -0
- data/lib/vagrant-vmpooler/action/setup_rsync.rb +40 -0
- data/lib/vagrant-vmpooler/action/suspend_server.rb +24 -0
- data/lib/vagrant-vmpooler/action/sync_folders.rb +104 -0
- data/lib/vagrant-vmpooler/action/take_snapshot.rb +35 -0
- data/lib/vagrant-vmpooler/action/wait_for_state.rb +38 -0
- data/lib/vagrant-vmpooler/config.rb +100 -0
- data/lib/vagrant-vmpooler/errors.rb +31 -0
- data/lib/vagrant-vmpooler/plugin.rb +30 -0
- data/lib/vagrant-vmpooler/provider.rb +55 -0
- data/lib/vagrant-vmpooler/version.rb +5 -0
- data/locales/en.yml +151 -0
- data/spec/spec_helper.rb +0 -0
- data/spec/vagrant-vmpooler/config_spec.rb +44 -0
- data/vagrant-vmpooler.gemspec +23 -0
- metadata +45 -3
@@ -0,0 +1,103 @@
|
|
1
|
+
require "vmfloaty/pooler"
|
2
|
+
require "log4r"
|
3
|
+
|
4
|
+
require 'vagrant/util/retryable'
|
5
|
+
|
6
|
+
module VagrantPlugins
|
7
|
+
module Vmpooler
|
8
|
+
module Action
|
9
|
+
class CreateServer
|
10
|
+
include Vagrant::Util::Retryable
|
11
|
+
|
12
|
+
def initialize(app, env)
|
13
|
+
@app = app
|
14
|
+
@logger = Log4r::Logger.new("vagrant_vmpooler::action::create_server")
|
15
|
+
end
|
16
|
+
|
17
|
+
def call(env)
|
18
|
+
# Get the configs
|
19
|
+
provider_config = env[:machine].provider_config
|
20
|
+
|
21
|
+
token = provider_config.token
|
22
|
+
url = provider_config.url
|
23
|
+
os = provider_config.os
|
24
|
+
ttl = provider_config.ttl
|
25
|
+
disk = provider_config.disk
|
26
|
+
verbose = provider_config.verbose
|
27
|
+
|
28
|
+
if !url
|
29
|
+
raise Errors::NoURLError,
|
30
|
+
:message => "There was no provided url to connect to vmpooler with"
|
31
|
+
end
|
32
|
+
|
33
|
+
if !token
|
34
|
+
env[:ui].warn("There was no token provided. All vms will only last 2 hours.")
|
35
|
+
end
|
36
|
+
|
37
|
+
if !os
|
38
|
+
raise Errors::NoURLError,
|
39
|
+
:message => "There was no operatingystem provided"
|
40
|
+
end
|
41
|
+
|
42
|
+
# Output the settings we're going to use to the user
|
43
|
+
env[:ui].info(I18n.t("vagrant_vmpooler.launching_server"))
|
44
|
+
env[:ui].info(" -- Vmpooler URL: #{url}")
|
45
|
+
env[:ui].info(" -- Vmpooler Verbose Mode: #{verbose}")
|
46
|
+
env[:ui].info(" -- Image: #{os}")
|
47
|
+
env[:ui].info(" -- Additional TTL: #{ttl}") if ttl
|
48
|
+
env[:ui].info(" -- Additional Disk: #{disk}") if disk
|
49
|
+
|
50
|
+
# Create the server
|
51
|
+
os_arr = {}
|
52
|
+
os_arr[os] = 1
|
53
|
+
server = Pooler.retrieve(verbose, os_arr, token, url)
|
54
|
+
|
55
|
+
# Store the ID right away so we can track it
|
56
|
+
# in this case it's the hostname
|
57
|
+
if server['ok'] == false
|
58
|
+
raise Errors::GetVMError,
|
59
|
+
:message => "Could not retrieve vm from pooler:\n #{server}"
|
60
|
+
end
|
61
|
+
|
62
|
+
server_name = server[os]["hostname"]
|
63
|
+
env[:machine].id = server_name
|
64
|
+
|
65
|
+
if ttl
|
66
|
+
response_body = Pooler.modify(verbose, url, server_name, token, ttl, nil)
|
67
|
+
if response_body['ok'] == false
|
68
|
+
env[:ui].warn(I18n.t("vagrant_vmpooler.errors.failed_ttl"))
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
if disk
|
73
|
+
response_body = Pooler.disk(verbose, url, server_name, token, disk)
|
74
|
+
if response_body['ok'] == false
|
75
|
+
env[:ui].warn(I18n.t("vagrant_vmpooler.errors.failed_disk_extend"))
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
if !env[:interrupted]
|
80
|
+
# Clear the line one more time so the progress is removed
|
81
|
+
env[:ui].clear_line
|
82
|
+
|
83
|
+
# Wait for SSH to become available
|
84
|
+
env[:ui].info(I18n.t("vagrant_vmpooler.waiting_for_ssh"))
|
85
|
+
while true
|
86
|
+
begin
|
87
|
+
# If we're interrupted then just back out
|
88
|
+
break if env[:interrupted]
|
89
|
+
break if env[:machine].communicate.ready?
|
90
|
+
rescue Errno::ENETUNREACH, Errno::EHOSTUNREACH
|
91
|
+
end
|
92
|
+
sleep 2
|
93
|
+
end
|
94
|
+
|
95
|
+
env[:ui].info(I18n.t("vagrant_vmpooler.ready"))
|
96
|
+
end
|
97
|
+
|
98
|
+
@app.call(env)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'vagrant/util/retryable'
|
2
|
+
require 'timeout'
|
3
|
+
require 'vmfloaty/pooler'
|
4
|
+
|
5
|
+
require "log4r"
|
6
|
+
|
7
|
+
module VagrantPlugins
|
8
|
+
module Vmpooler
|
9
|
+
module Action
|
10
|
+
# This deletes the running server, if there is one.
|
11
|
+
class DeleteServer
|
12
|
+
include Vagrant::Util::Retryable
|
13
|
+
|
14
|
+
def initialize(app, env)
|
15
|
+
@app = app
|
16
|
+
@logger = Log4r::Logger.new("vagrant_vmpooler::action::delete_server")
|
17
|
+
end
|
18
|
+
|
19
|
+
def call(env)
|
20
|
+
machine = env[:machine]
|
21
|
+
id = machine.id
|
22
|
+
|
23
|
+
if id
|
24
|
+
provider_config = machine.provider_config
|
25
|
+
token = provider_config.token
|
26
|
+
url = provider_config.url
|
27
|
+
verbose = provider_config.verbose
|
28
|
+
|
29
|
+
env[:ui].info(I18n.t("vagrant_vmpooler.deleting_server"))
|
30
|
+
|
31
|
+
os = []
|
32
|
+
os.push(id)
|
33
|
+
response_body = Pooler.delete(verbose, url, os, token)
|
34
|
+
|
35
|
+
if response_body[id]['ok'] == false
|
36
|
+
env[:ui].info(I18n.t("vagrant_vmpooler.not_deleted"))
|
37
|
+
else
|
38
|
+
env[:ui].info(I18n.t("vagrant_vmpooler.deleted"))
|
39
|
+
env[:machine].id = nil
|
40
|
+
end
|
41
|
+
else
|
42
|
+
env[:ui].info(I18n.t("vagrant_vmpooler.not_created"))
|
43
|
+
end
|
44
|
+
|
45
|
+
@app.call(env)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require "log4r"
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module Vmpooler
|
5
|
+
module Action
|
6
|
+
# This hard reboots a running server, if there is one.
|
7
|
+
class HardRebootServer
|
8
|
+
def initialize(app, env)
|
9
|
+
@app = app
|
10
|
+
@logger = Log4r::Logger.new("vagrant_vmpooler::action::hard_reboot_server")
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(env)
|
14
|
+
if env[:machine].id
|
15
|
+
env[:ui].info(I18n.t("vagrant_vmpooler.hard_rebooting_server"))
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
@app.call(env)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Vmpooler
|
3
|
+
module Action
|
4
|
+
class MessageAlreadyCreated
|
5
|
+
def initialize(app, env)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
env[:ui].info(I18n.t("vagrant_vmpooler.already_created"))
|
11
|
+
@app.call(env)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Vmpooler
|
3
|
+
module Action
|
4
|
+
class MessageNotCreated
|
5
|
+
def initialize(app, env)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
env[:ui].info(I18n.t("vagrant_vmpooler.not_created"))
|
11
|
+
@app.call(env)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Vmpooler
|
3
|
+
module Action
|
4
|
+
class MessageServerRunning
|
5
|
+
def initialize(app, env)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
env[:ui].info(I18n.t("vagrant_vmpooler.server_running", name: env[:machine].id))
|
11
|
+
@app.call(env)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module Vmpooler
|
3
|
+
module Action
|
4
|
+
class MessageWillNotDestroy
|
5
|
+
def initialize(app, env)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
env[:ui].info(I18n.t("vagrant_vmpooler.will_not_destroy", name: env[:machine].name))
|
11
|
+
@app.call(env)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require "log4r"
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module Vmpooler
|
5
|
+
module Action
|
6
|
+
# This pauses a running server, if there is one.
|
7
|
+
class PauseServer
|
8
|
+
def initialize(app, env)
|
9
|
+
@app = app
|
10
|
+
@logger = Log4r::Logger.new("vagrant_vmpooler::action::pause_server")
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(env)
|
14
|
+
if env[:machine].id
|
15
|
+
env[:ui].info(I18n.t("vagrant_vmpooler.pausing_server"))
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
@app.call(env)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require "log4r"
|
2
|
+
require "ipaddr"
|
3
|
+
|
4
|
+
module VagrantPlugins
|
5
|
+
module Vmpooler
|
6
|
+
module Action
|
7
|
+
# This action reads the SSH info for the machine and puts it into the
|
8
|
+
# `:machine_ssh_info` key in the environment.
|
9
|
+
class ReadSSHInfo
|
10
|
+
def initialize(app, env)
|
11
|
+
@app = app
|
12
|
+
@logger = Log4r::Logger.new("vagrant_vmpooler::action::read_ssh_info")
|
13
|
+
end
|
14
|
+
|
15
|
+
def call(env)
|
16
|
+
env[:machine_ssh_info] = read_ssh_info(env[:machine])
|
17
|
+
|
18
|
+
@app.call(env)
|
19
|
+
end
|
20
|
+
|
21
|
+
def read_ssh_info(machine)
|
22
|
+
id = machine.id
|
23
|
+
return nil if id.nil?
|
24
|
+
|
25
|
+
provider_config = machine.provider_config
|
26
|
+
verbose = provider_config.verbose
|
27
|
+
url = provider_config.url
|
28
|
+
password = provider_config.password
|
29
|
+
os = provider_config.os
|
30
|
+
|
31
|
+
server = Pooler.query(verbose, url, id)
|
32
|
+
if server['ok'] == false
|
33
|
+
# The machine can't be found
|
34
|
+
@logger.info("Machine couldn't be found, assuming it got destroyed.")
|
35
|
+
machine.id = nil
|
36
|
+
return nil
|
37
|
+
else
|
38
|
+
if os =~ /win/i
|
39
|
+
username = 'Administrator'
|
40
|
+
else
|
41
|
+
username = 'root'
|
42
|
+
end
|
43
|
+
|
44
|
+
ssh_info = {
|
45
|
+
:host => id,
|
46
|
+
:username => username,
|
47
|
+
:password => password
|
48
|
+
}
|
49
|
+
ssh_info.merge! server[id]
|
50
|
+
return ssh_info
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require "log4r"
|
2
|
+
require 'vmfloaty/pooler'
|
3
|
+
|
4
|
+
module VagrantPlugins
|
5
|
+
module Vmpooler
|
6
|
+
module Action
|
7
|
+
# This action reads the state of the machine and puts it in the
|
8
|
+
# `:machine_state_id` key in the environment.
|
9
|
+
class ReadState
|
10
|
+
def initialize(app, env)
|
11
|
+
@app = app
|
12
|
+
@logger = Log4r::Logger.new("vagrant_vmpooler::action::read_state")
|
13
|
+
end
|
14
|
+
|
15
|
+
def call(env)
|
16
|
+
env[:machine_state_id] = read_state(env[:machine])
|
17
|
+
@app.call(env)
|
18
|
+
end
|
19
|
+
|
20
|
+
def read_state(machine)
|
21
|
+
id = machine.id
|
22
|
+
return :not_created if id.nil?
|
23
|
+
|
24
|
+
provider_config = machine.provider_config
|
25
|
+
verbose = provider_config.verbose
|
26
|
+
url = provider_config.url
|
27
|
+
|
28
|
+
server = Pooler.query(verbose, url, id)
|
29
|
+
if server['ok'] == false
|
30
|
+
@logger.info(I18n.t("vagrant_vmpooler.not_created"))
|
31
|
+
machine.id = nil
|
32
|
+
return :not_created
|
33
|
+
end
|
34
|
+
|
35
|
+
return :created
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require "log4r"
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module Vmpooler
|
5
|
+
module Action
|
6
|
+
# This reboots a running server, if there is one.
|
7
|
+
class RebootServer
|
8
|
+
def initialize(app, env)
|
9
|
+
@app = app
|
10
|
+
@logger = Log4r::Logger.new("vagrant_vmpooler::action::reboot_server")
|
11
|
+
end
|
12
|
+
|
13
|
+
def call(env)
|
14
|
+
if env[:machine].id
|
15
|
+
env[:ui].info(I18n.t("vagrant_vmpooler.rebooting_server"))
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
@app.call(env)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|