vagrant-managed-servers 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Berksfile +4 -0
- data/CHANGELOG.md +4 -0
- data/Gemfile +14 -0
- data/LICENSE +8 -0
- data/README.md +142 -0
- data/Rakefile +21 -0
- data/Vagrantfile +44 -0
- data/cookbooks/apache2/CHANGELOG.md +95 -0
- data/cookbooks/apache2/CONTRIBUTING.md +257 -0
- data/cookbooks/apache2/Gemfile +10 -0
- data/cookbooks/apache2/LICENSE +201 -0
- data/cookbooks/apache2/README.md +567 -0
- data/cookbooks/apache2/attributes/default.rb +149 -0
- data/cookbooks/apache2/attributes/mod_auth_cas.rb +2 -0
- data/cookbooks/apache2/attributes/mod_auth_openid.rb +32 -0
- data/cookbooks/apache2/definitions/apache_conf.rb +26 -0
- data/cookbooks/apache2/definitions/apache_module.rb +53 -0
- data/cookbooks/apache2/definitions/apache_site.rb +43 -0
- data/cookbooks/apache2/definitions/web_app.rb +49 -0
- data/cookbooks/apache2/files/default/apache2_module_conf_generate.pl +41 -0
- data/cookbooks/apache2/files/default/tests/minitest/default_test.rb +77 -0
- data/cookbooks/apache2/files/default/tests/minitest/god_monitor_test.rb +34 -0
- data/cookbooks/apache2/files/default/tests/minitest/mod_apreq2_test.rb +19 -0
- data/cookbooks/apache2/files/default/tests/minitest/mod_auth_cas_test.rb +11 -0
- data/cookbooks/apache2/files/default/tests/minitest/mod_auth_openid_test.rb +37 -0
- data/cookbooks/apache2/files/default/tests/minitest/mod_cgi_test.rb +13 -0
- data/cookbooks/apache2/files/default/tests/minitest/mod_dav_svn_test.rb +14 -0
- data/cookbooks/apache2/files/default/tests/minitest/mod_fastcgi.rb +11 -0
- data/cookbooks/apache2/files/default/tests/minitest/mod_perl_test.rb +18 -0
- data/cookbooks/apache2/files/default/tests/minitest/mod_php5_test.rb +13 -0
- data/cookbooks/apache2/files/default/tests/minitest/mod_python_test.rb +10 -0
- data/cookbooks/apache2/files/default/tests/minitest/mod_ssl_test.rb +23 -0
- data/cookbooks/apache2/files/default/tests/minitest/support/helpers.rb +50 -0
- data/cookbooks/apache2/metadata.json +513 -0
- data/cookbooks/apache2/metadata.rb +207 -0
- data/cookbooks/apache2/recipes/default.rb +208 -0
- data/cookbooks/apache2/recipes/god_monitor.rb +33 -0
- data/cookbooks/apache2/recipes/logrotate.rb +29 -0
- data/cookbooks/apache2/recipes/mod_alias.rb +22 -0
- data/cookbooks/apache2/recipes/mod_apreq2.rb +54 -0
- data/cookbooks/apache2/recipes/mod_auth_basic.rb +20 -0
- data/cookbooks/apache2/recipes/mod_auth_cas.rb +59 -0
- data/cookbooks/apache2/recipes/mod_auth_digest.rb +20 -0
- data/cookbooks/apache2/recipes/mod_auth_openid.rb +111 -0
- data/cookbooks/apache2/recipes/mod_authn_file.rb +20 -0
- data/cookbooks/apache2/recipes/mod_authnz_ldap.rb +20 -0
- data/cookbooks/apache2/recipes/mod_authz_default.rb +20 -0
- data/cookbooks/apache2/recipes/mod_authz_groupfile.rb +20 -0
- data/cookbooks/apache2/recipes/mod_authz_host.rb +20 -0
- data/cookbooks/apache2/recipes/mod_authz_user.rb +20 -0
- data/cookbooks/apache2/recipes/mod_autoindex.rb +22 -0
- data/cookbooks/apache2/recipes/mod_cgi.rb +20 -0
- data/cookbooks/apache2/recipes/mod_dav.rb +20 -0
- data/cookbooks/apache2/recipes/mod_dav_fs.rb +21 -0
- data/cookbooks/apache2/recipes/mod_dav_svn.rb +41 -0
- data/cookbooks/apache2/recipes/mod_deflate.rb +22 -0
- data/cookbooks/apache2/recipes/mod_dir.rb +22 -0
- data/cookbooks/apache2/recipes/mod_env.rb +20 -0
- data/cookbooks/apache2/recipes/mod_expires.rb +20 -0
- data/cookbooks/apache2/recipes/mod_fastcgi.rb +26 -0
- data/cookbooks/apache2/recipes/mod_fcgid.rb +55 -0
- data/cookbooks/apache2/recipes/mod_headers.rb +20 -0
- data/cookbooks/apache2/recipes/mod_include.rb +20 -0
- data/cookbooks/apache2/recipes/mod_ldap.rb +20 -0
- data/cookbooks/apache2/recipes/mod_log_config.rb +24 -0
- data/cookbooks/apache2/recipes/mod_logio.rb +24 -0
- data/cookbooks/apache2/recipes/mod_mime.rb +22 -0
- data/cookbooks/apache2/recipes/mod_negotiation.rb +22 -0
- data/cookbooks/apache2/recipes/mod_perl.rb +44 -0
- data/cookbooks/apache2/recipes/mod_php5.rb +77 -0
- data/cookbooks/apache2/recipes/mod_proxy.rb +22 -0
- data/cookbooks/apache2/recipes/mod_proxy_ajp.rb +21 -0
- data/cookbooks/apache2/recipes/mod_proxy_balancer.rb +20 -0
- data/cookbooks/apache2/recipes/mod_proxy_connect.rb +20 -0
- data/cookbooks/apache2/recipes/mod_proxy_http.rb +20 -0
- data/cookbooks/apache2/recipes/mod_python.rb +38 -0
- data/cookbooks/apache2/recipes/mod_rewrite.rb +20 -0
- data/cookbooks/apache2/recipes/mod_setenvif.rb +22 -0
- data/cookbooks/apache2/recipes/mod_ssl.rb +46 -0
- data/cookbooks/apache2/recipes/mod_status.rb +22 -0
- data/cookbooks/apache2/recipes/mod_wsgi.rb +38 -0
- data/cookbooks/apache2/recipes/mod_xsendfile.rb +38 -0
- data/cookbooks/apache2/templates/default/a2dismod.erb +22 -0
- data/cookbooks/apache2/templates/default/a2dissite.erb +29 -0
- data/cookbooks/apache2/templates/default/a2enmod.erb +37 -0
- data/cookbooks/apache2/templates/default/a2ensite.erb +38 -0
- data/cookbooks/apache2/templates/default/apache2.conf.erb +237 -0
- data/cookbooks/apache2/templates/default/apache2.god.erb +19 -0
- data/cookbooks/apache2/templates/default/charset.erb +6 -0
- data/cookbooks/apache2/templates/default/default-site.erb +57 -0
- data/cookbooks/apache2/templates/default/mods/README +2 -0
- data/cookbooks/apache2/templates/default/mods/alias.conf.erb +24 -0
- data/cookbooks/apache2/templates/default/mods/auth_cas.conf.erb +1 -0
- data/cookbooks/apache2/templates/default/mods/auth_cas.load.erb +1 -0
- data/cookbooks/apache2/templates/default/mods/authopenid.load.erb +1 -0
- data/cookbooks/apache2/templates/default/mods/autoindex.conf.erb +101 -0
- data/cookbooks/apache2/templates/default/mods/deflate.conf.erb +16 -0
- data/cookbooks/apache2/templates/default/mods/dir.conf.erb +5 -0
- data/cookbooks/apache2/templates/default/mods/fastcgi.conf.erb +5 -0
- data/cookbooks/apache2/templates/default/mods/fcgid.conf.erb +10 -0
- data/cookbooks/apache2/templates/default/mods/mime.conf.erb +198 -0
- data/cookbooks/apache2/templates/default/mods/negotiation.conf.erb +18 -0
- data/cookbooks/apache2/templates/default/mods/php5.conf.erb +16 -0
- data/cookbooks/apache2/templates/default/mods/proxy.conf.erb +19 -0
- data/cookbooks/apache2/templates/default/mods/setenvif.conf.erb +28 -0
- data/cookbooks/apache2/templates/default/mods/ssl.conf.erb +76 -0
- data/cookbooks/apache2/templates/default/mods/status.conf.erb +26 -0
- data/cookbooks/apache2/templates/default/port_apache.erb +2 -0
- data/cookbooks/apache2/templates/default/ports.conf.erb +6 -0
- data/cookbooks/apache2/templates/default/security.erb +50 -0
- data/cookbooks/apache2/templates/default/web_app.conf.erb +43 -0
- data/cookbooks/apt/Berksfile +8 -0
- data/cookbooks/apt/CHANGELOG.md +97 -0
- data/cookbooks/apt/CONTRIBUTING +29 -0
- data/cookbooks/apt/LICENSE +201 -0
- data/cookbooks/apt/README.md +243 -0
- data/cookbooks/apt/TESTING.md +25 -0
- data/cookbooks/apt/attributes/default.rb +4 -0
- data/cookbooks/apt/files/default/apt-proxy-v2.conf +50 -0
- data/cookbooks/apt/metadata.json +1 -0
- data/cookbooks/apt/metadata.rb +30 -0
- data/cookbooks/apt/providers/preference.rb +61 -0
- data/cookbooks/apt/providers/repository.rb +132 -0
- data/cookbooks/apt/recipes/cacher-client.rb +59 -0
- data/cookbooks/apt/recipes/cacher-ng.rb +40 -0
- data/cookbooks/apt/recipes/default.rb +68 -0
- data/cookbooks/apt/resources/preference.rb +30 -0
- data/cookbooks/apt/resources/repository.rb +40 -0
- data/cookbooks/apt/templates/debian-6.0/acng.conf.erb +174 -0
- data/cookbooks/apt/templates/default/01proxy.erb +2 -0
- data/cookbooks/apt/templates/default/acng.conf.erb +276 -0
- data/cookbooks/apt/templates/ubuntu-10.04/acng.conf.erb +270 -0
- data/dummy.box +0 -0
- data/lib/vagrant-managed-servers.rb +18 -0
- data/lib/vagrant-managed-servers/action.rb +114 -0
- data/lib/vagrant-managed-servers/action/is_created.rb +18 -0
- data/lib/vagrant-managed-servers/action/is_reachable.rb +18 -0
- data/lib/vagrant-managed-servers/action/link_server.rb +31 -0
- data/lib/vagrant-managed-servers/action/message_not_reachable.rb +16 -0
- data/lib/vagrant-managed-servers/action/read_state.rb +84 -0
- data/lib/vagrant-managed-servers/action/sync_folders.rb +85 -0
- data/lib/vagrant-managed-servers/action/unlink_server.rb +30 -0
- data/lib/vagrant-managed-servers/action/warn_networks.rb +19 -0
- data/lib/vagrant-managed-servers/config.rb +28 -0
- data/lib/vagrant-managed-servers/errors.rb +19 -0
- data/lib/vagrant-managed-servers/plugin.rb +72 -0
- data/lib/vagrant-managed-servers/provider.rb +51 -0
- data/lib/vagrant-managed-servers/util/timer.rb +17 -0
- data/lib/vagrant-managed-servers/version.rb +5 -0
- data/locales/en.yml +45 -0
- data/spec/vagrant-managed-servers/config_spec.rb +28 -0
- data/vagrant-managed-servers.gemspec +56 -0
- metadata +264 -0
@@ -0,0 +1,16 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module ManagedServers
|
3
|
+
module Action
|
4
|
+
class MessageNotReachable
|
5
|
+
def initialize(app, env)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
env[:ui].info(I18n.t("vagrant_managed_servers.host_not_reachable"))
|
11
|
+
@app.call(env)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require "log4r"
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module ManagedServers
|
5
|
+
module Action
|
6
|
+
# This action reads the state of the machine and puts it in the
|
7
|
+
# `:machine_state_id` key in the environment.
|
8
|
+
class ReadState
|
9
|
+
def initialize(app, env)
|
10
|
+
@app = app
|
11
|
+
@logger = Log4r::Logger.new("vagrant_managed_servers::action::read_state")
|
12
|
+
end
|
13
|
+
|
14
|
+
def call(env)
|
15
|
+
env[:machine_state_id] = read_state(env[:machine])
|
16
|
+
@app.call(env)
|
17
|
+
end
|
18
|
+
|
19
|
+
def read_state(machine)
|
20
|
+
return :not_created if machine.id.nil?
|
21
|
+
|
22
|
+
ip_address = machine.id
|
23
|
+
=begin
|
24
|
+
if machine.communicate.ready?
|
25
|
+
@logger.info "#{ip_address} is reachable and SSH login OK"
|
26
|
+
return :reachable
|
27
|
+
else
|
28
|
+
if ssh_port_open? ip_address
|
29
|
+
@logger.info "#{ip_address} is reachable, SSH port open (but login failed)"
|
30
|
+
return :reachable
|
31
|
+
else
|
32
|
+
if is_pingable? ip_address
|
33
|
+
@logger.info "#{ip_address} is pingable (but SSH failed)"
|
34
|
+
return :reachable
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# host is not reachable at all...
|
40
|
+
return :not_reachable
|
41
|
+
=end
|
42
|
+
|
43
|
+
return machine.communicate.ready? ? :running : :not_reachable
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
def is_pingable?(ip)
|
48
|
+
if Vagrant::Util::Platform.windows?
|
49
|
+
system("ping -n 1 #{ip}")
|
50
|
+
else
|
51
|
+
system("ping -q -c 1 #{ip}")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def ssh_port_open?(ip)
|
56
|
+
is_port_open?(ip, 22)
|
57
|
+
end
|
58
|
+
|
59
|
+
#
|
60
|
+
# borrowed from http://stackoverflow.com/a/3473208/2388971
|
61
|
+
#
|
62
|
+
def is_port_open?(ip, port)
|
63
|
+
require 'socket'
|
64
|
+
s = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
|
65
|
+
sa = Socket.sockaddr_in(port, ip)
|
66
|
+
begin
|
67
|
+
s.connect_nonblock(sa)
|
68
|
+
rescue Errno::EINPROGRESS
|
69
|
+
if IO.select(nil, [s], nil, 1)
|
70
|
+
begin
|
71
|
+
s.connect_nonblock(sa)
|
72
|
+
rescue Errno::EISCONN
|
73
|
+
return true
|
74
|
+
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
|
75
|
+
return false
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
return false
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require "log4r"
|
2
|
+
|
3
|
+
require "vagrant/util/subprocess"
|
4
|
+
|
5
|
+
require "vagrant/util/scoped_hash_override"
|
6
|
+
|
7
|
+
require "vagrant/util/which"
|
8
|
+
|
9
|
+
module VagrantPlugins
|
10
|
+
module ManagedServers
|
11
|
+
module Action
|
12
|
+
# This middleware uses `rsync` to sync the folders over to the
|
13
|
+
# AWS instance.
|
14
|
+
class SyncFolders
|
15
|
+
include Vagrant::Util::ScopedHashOverride
|
16
|
+
|
17
|
+
def initialize(app, env)
|
18
|
+
@app = app
|
19
|
+
@logger = Log4r::Logger.new("vagrant_managed_servers::action::sync_folders")
|
20
|
+
end
|
21
|
+
|
22
|
+
def call(env)
|
23
|
+
@app.call(env)
|
24
|
+
|
25
|
+
ssh_info = env[:machine].ssh_info
|
26
|
+
|
27
|
+
env[:machine].config.vm.synced_folders.each do |id, data|
|
28
|
+
data = scoped_hash_override(data, :aws)
|
29
|
+
|
30
|
+
# Ignore disabled shared folders
|
31
|
+
next if data[:disabled]
|
32
|
+
|
33
|
+
unless Vagrant::Util::Which.which('rsync')
|
34
|
+
env[:ui].warn(I18n.t('vagrant_managed_servers.rsync_not_found_warning'))
|
35
|
+
break
|
36
|
+
end
|
37
|
+
|
38
|
+
hostpath = File.expand_path(data[:hostpath], env[:root_path])
|
39
|
+
guestpath = data[:guestpath]
|
40
|
+
|
41
|
+
# Make sure there is a trailing slash on the host path to
|
42
|
+
# avoid creating an additional directory with rsync
|
43
|
+
hostpath = "#{hostpath}/" if hostpath !~ /\/$/
|
44
|
+
|
45
|
+
# on windows rsync.exe requires cygdrive-style paths
|
46
|
+
if Vagrant::Util::Platform.windows?
|
47
|
+
hostpath = hostpath.gsub(/^(\w):/) { "/cygdrive/#{$1}" }
|
48
|
+
end
|
49
|
+
|
50
|
+
env[:ui].info(I18n.t("vagrant_managed_servers.rsync_folder",
|
51
|
+
:hostpath => hostpath,
|
52
|
+
:guestpath => guestpath))
|
53
|
+
|
54
|
+
# Create the guest path
|
55
|
+
env[:machine].communicate.sudo("mkdir -p '#{guestpath}'")
|
56
|
+
env[:machine].communicate.sudo(
|
57
|
+
"chown #{ssh_info[:username]} '#{guestpath}'")
|
58
|
+
|
59
|
+
# Rsync over to the guest path using the SSH info
|
60
|
+
command = [
|
61
|
+
"rsync", "--verbose", "--archive", "-z",
|
62
|
+
"--exclude", ".vagrant/",
|
63
|
+
"-e", "ssh -p #{ssh_info[:port]} -o StrictHostKeyChecking=no -i '#{ssh_info[:private_key_path]}'",
|
64
|
+
hostpath,
|
65
|
+
"#{ssh_info[:username]}@#{ssh_info[:host]}:#{guestpath}"]
|
66
|
+
|
67
|
+
# we need to fix permissions when using rsync.exe on windows, see
|
68
|
+
# http://stackoverflow.com/questions/5798807/rsync-permission-denied-created-directories-have-no-permissions
|
69
|
+
if Vagrant::Util::Platform.windows?
|
70
|
+
command.insert(1, "--chmod", "ugo=rwX")
|
71
|
+
end
|
72
|
+
|
73
|
+
r = Vagrant::Util::Subprocess.execute(*command)
|
74
|
+
if r.exit_code != 0
|
75
|
+
raise Errors::RsyncError,
|
76
|
+
:guestpath => guestpath,
|
77
|
+
:hostpath => hostpath,
|
78
|
+
:stderr => r.stderr
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require "log4r"
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module ManagedServers
|
5
|
+
module Action
|
6
|
+
# "unlink" vagrant and the managed server
|
7
|
+
class UnlinkServer
|
8
|
+
|
9
|
+
def initialize(app, env)
|
10
|
+
@app = app
|
11
|
+
@logger = Log4r::Logger.new("vagrant_managed_servers::action::unlink_server")
|
12
|
+
end
|
13
|
+
|
14
|
+
def call(env)
|
15
|
+
|
16
|
+
server = env[:machine].id
|
17
|
+
|
18
|
+
# "Unlink"
|
19
|
+
env[:ui].info(I18n.t("vagrant_managed_servers.unlinking_server", :host => server))
|
20
|
+
env[:ui].info(" -- Server: #{server}")
|
21
|
+
|
22
|
+
# set machine id to nil
|
23
|
+
env[:machine].id = nil
|
24
|
+
|
25
|
+
@app.call(env)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module ManagedServers
|
3
|
+
module Action
|
4
|
+
class WarnNetworks
|
5
|
+
def initialize(app, env)
|
6
|
+
@app = app
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
if env[:machine].config.vm.networks.length > 0
|
11
|
+
env[:ui].warn(I18n.t("vagrant_managed_servers.warn_networks"))
|
12
|
+
end
|
13
|
+
|
14
|
+
@app.call(env)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require "vagrant"
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module ManagedServers
|
5
|
+
class Config < Vagrant.plugin("2", :config)
|
6
|
+
|
7
|
+
# The IP address or hostname of the managed server.
|
8
|
+
#
|
9
|
+
# @return [String]
|
10
|
+
attr_accessor :server
|
11
|
+
|
12
|
+
def initialize()
|
13
|
+
@server = UNSET_VALUE
|
14
|
+
end
|
15
|
+
|
16
|
+
def finalize!
|
17
|
+
# server must be nil, since we can't default that
|
18
|
+
@server = nil if @server == UNSET_VALUE
|
19
|
+
end
|
20
|
+
|
21
|
+
def validate(machine)
|
22
|
+
errors = _detected_errors
|
23
|
+
errors << I18n.t("vagrant_managed_servers.config.server_required") if @server.nil?
|
24
|
+
{ "ManagedServers Provider" => errors }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "vagrant"
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module ManagedServers
|
5
|
+
module Errors
|
6
|
+
class VagrantManagedServersError < Vagrant::Errors::VagrantError
|
7
|
+
error_namespace("vagrant_managed_servers.errors")
|
8
|
+
end
|
9
|
+
|
10
|
+
class ManagedServersServerNotReachable < VagrantManagedServersError
|
11
|
+
error_key(:server_not_reachable)
|
12
|
+
end
|
13
|
+
|
14
|
+
class RsyncError < VagrantManagedServersError
|
15
|
+
error_key(:rsync_error)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
begin
|
2
|
+
require "vagrant"
|
3
|
+
rescue LoadError
|
4
|
+
raise "The Vagrant ManagedServers plugin must be run within Vagrant."
|
5
|
+
end
|
6
|
+
|
7
|
+
# This is a sanity check to make sure no one is attempting to install
|
8
|
+
# this into an early Vagrant version.
|
9
|
+
if Vagrant::VERSION < "1.2.0"
|
10
|
+
raise "The Vagrant ManagedServers plugin is only compatible with Vagrant 1.2+"
|
11
|
+
end
|
12
|
+
|
13
|
+
module VagrantPlugins
|
14
|
+
module ManagedServers
|
15
|
+
class Plugin < Vagrant.plugin("2")
|
16
|
+
name "ManagedServers"
|
17
|
+
description <<-DESC
|
18
|
+
This plugin installs a provider that allows Vagrant to interact with managed servers.
|
19
|
+
DESC
|
20
|
+
|
21
|
+
config(:managed, :provider) do
|
22
|
+
require_relative "config"
|
23
|
+
Config
|
24
|
+
end
|
25
|
+
|
26
|
+
provider(:managed, parallel: true) do
|
27
|
+
# Setup logging and i18n
|
28
|
+
setup_logging
|
29
|
+
setup_i18n
|
30
|
+
|
31
|
+
# Return the provider
|
32
|
+
require_relative "provider"
|
33
|
+
Provider
|
34
|
+
end
|
35
|
+
|
36
|
+
# This initializes the internationalization strings.
|
37
|
+
def self.setup_i18n
|
38
|
+
I18n.load_path << File.expand_path("locales/en.yml", ManagedServers.source_root)
|
39
|
+
I18n.reload!
|
40
|
+
end
|
41
|
+
|
42
|
+
# This sets up our log level to be whatever VAGRANT_LOG is.
|
43
|
+
def self.setup_logging
|
44
|
+
require "log4r"
|
45
|
+
|
46
|
+
level = nil
|
47
|
+
begin
|
48
|
+
level = Log4r.const_get(ENV["VAGRANT_LOG"].upcase)
|
49
|
+
rescue NameError
|
50
|
+
# This means that the logging constant wasn't found,
|
51
|
+
# which is fine. We just keep `level` as `nil`. But
|
52
|
+
# we tell the user.
|
53
|
+
level = nil
|
54
|
+
end
|
55
|
+
|
56
|
+
# Some constants, such as "true" resolve to booleans, so the
|
57
|
+
# above error checking doesn't catch it. This will check to make
|
58
|
+
# sure that the log level is an integer, as Log4r requires.
|
59
|
+
level = nil if !level.is_a?(Integer)
|
60
|
+
|
61
|
+
# Set the logging level on all "vagrant" namespaced
|
62
|
+
# logs as long as we have a valid level.
|
63
|
+
if level
|
64
|
+
logger = Log4r::Logger.new("vagrant_managed_servers")
|
65
|
+
logger.outputters = Log4r::Outputter.stderr
|
66
|
+
logger.level = level
|
67
|
+
logger = nil
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require "log4r"
|
2
|
+
require "vagrant"
|
3
|
+
|
4
|
+
module VagrantPlugins
|
5
|
+
module ManagedServers
|
6
|
+
class Provider < Vagrant.plugin("2", :provider)
|
7
|
+
def initialize(machine)
|
8
|
+
@machine = machine
|
9
|
+
end
|
10
|
+
|
11
|
+
def action(name)
|
12
|
+
# Attempt to get the action method from the Action class if it
|
13
|
+
# exists, otherwise return nil to show that we don't support the
|
14
|
+
# given action.
|
15
|
+
action_method = "action_#{name}"
|
16
|
+
return Action.send(action_method) if Action.respond_to?(action_method)
|
17
|
+
nil
|
18
|
+
end
|
19
|
+
|
20
|
+
# Returns the SSH info for accessing the managed server.
|
21
|
+
def ssh_info
|
22
|
+
return {
|
23
|
+
:host => @machine.provider_config.server,
|
24
|
+
:port => 22
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
def state
|
29
|
+
|
30
|
+
# Run a custom action we define called "read_state" which does
|
31
|
+
# what it says. It puts the state in the `:machine_state_id`
|
32
|
+
# key in the environment.
|
33
|
+
env = @machine.action("read_state")
|
34
|
+
|
35
|
+
state_id = env[:machine_state_id]
|
36
|
+
|
37
|
+
# Get the short and long description
|
38
|
+
short = I18n.t("vagrant_managed_servers.states.short_#{state_id}")
|
39
|
+
long = I18n.t("vagrant_managed_servers.states.long_#{state_id}")
|
40
|
+
|
41
|
+
# Return the MachineState object
|
42
|
+
Vagrant::MachineState.new(state_id, short, long)
|
43
|
+
end
|
44
|
+
|
45
|
+
def to_s
|
46
|
+
id = @machine.id.nil? ? "n/a" : @machine.id
|
47
|
+
"ManagedServers (#{id})"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module ManagedServers
|
3
|
+
module Util
|
4
|
+
class Timer
|
5
|
+
# A basic utility method that times the execution of the given
|
6
|
+
# block and returns it.
|
7
|
+
def self.time
|
8
|
+
start_time = Time.now.to_f
|
9
|
+
yield
|
10
|
+
end_time = Time.now.to_f
|
11
|
+
|
12
|
+
end_time - start_time
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/locales/en.yml
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
en:
|
2
|
+
vagrant_managed_servers:
|
3
|
+
host_not_reachable: |-
|
4
|
+
The host specified in `config.managed.server` is not reachable.
|
5
|
+
warn_networks: |-
|
6
|
+
Warning! The ManagedServers provider doesn't support any of the Vagrant
|
7
|
+
high-level network configurations (`config.vm.network`). They
|
8
|
+
will be silently ignored.
|
9
|
+
rsync_not_found_warning: |-
|
10
|
+
Warning! Folder sync disabled because the rsync binary is missing.
|
11
|
+
Make sure rsync is installed and the binary can be found in the PATH.
|
12
|
+
rsync_folder: |-
|
13
|
+
Rsyncing folder: %{hostpath} => %{guestpath}
|
14
|
+
linking_server: |-
|
15
|
+
Linking vagrant with managed server %{host}
|
16
|
+
unlinking_server: |-
|
17
|
+
Unlinking vagrant from managed server %{host}
|
18
|
+
states:
|
19
|
+
short_not_reachable: |-
|
20
|
+
not reachable
|
21
|
+
long_not_reachable: |-
|
22
|
+
The managed server is not reachable. Check if the `config.managed.server` is correct.
|
23
|
+
short_running: |-
|
24
|
+
running
|
25
|
+
long_running: |-
|
26
|
+
The managed server is running. To ssh into this machine, you can run
|
27
|
+
`vagrant ssh`. To provision the machine, you can run `vagrant provision`.
|
28
|
+
config:
|
29
|
+
server_required: |-
|
30
|
+
The IP or hostname of the server must be configured via "server"
|
31
|
+
private_key_missing: |-
|
32
|
+
The specified private key could not be found
|
33
|
+
errors:
|
34
|
+
rsync_error: |-
|
35
|
+
There was an error when attemping to rsync a shared folder.
|
36
|
+
Please inspect the error message below for more info.
|
37
|
+
|
38
|
+
Host path: %{hostpath}
|
39
|
+
Guest path: %{guestpath}
|
40
|
+
Error: %{stderr}
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
|