vagrant-hp 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +59 -59
- data/CHANGELOG.md +6 -3
- data/Gemfile +10 -10
- data/LICENSE +9 -0
- data/README.md +172 -167
- data/Rakefile +21 -21
- data/example_box/README.md +13 -13
- data/example_box/Vagrantfile +7 -7
- data/example_box/metadata.json +3 -3
- data/lib/vagrant-hp.rb +18 -18
- data/lib/vagrant-hp/action.rb +110 -110
- data/lib/vagrant-hp/action/connect_hp.rb +54 -54
- data/lib/vagrant-hp/action/create_server.rb +124 -121
- data/lib/vagrant-hp/action/delete_server.rb +30 -30
- data/lib/vagrant-hp/action/halt_server.rb +30 -30
- data/lib/vagrant-hp/action/is_created.rb +23 -23
- data/lib/vagrant-hp/action/is_running.rb +23 -23
- data/lib/vagrant-hp/action/message_already_created.rb +21 -21
- data/lib/vagrant-hp/action/message_not_created.rb +21 -21
- data/lib/vagrant-hp/action/read_ssh_info.rb +51 -51
- data/lib/vagrant-hp/action/read_state.rb +43 -43
- data/lib/vagrant-hp/action/sync_folders.rb +63 -63
- data/lib/vagrant-hp/action/timed_provision.rb +27 -27
- data/lib/vagrant-hp/action/warn_networks.rb +24 -24
- data/lib/vagrant-hp/config.rb +159 -157
- data/lib/vagrant-hp/errors.rb +24 -24
- data/lib/vagrant-hp/plugin.rb +78 -78
- data/lib/vagrant-hp/provider.rb +55 -55
- data/lib/vagrant-hp/util/timer.rb +17 -17
- data/lib/vagrant-hp/version.rb +10 -10
- data/locales/en.yml +91 -91
- data/spec/vagrant-hp/config_spec.rb +42 -42
- data/vagrant-hp.gemspec +59 -59
- metadata +4 -3
@@ -1,21 +1,21 @@
|
|
1
|
-
#
|
2
|
-
# Author:: Mohit Sethi (<mohit@sethis.in>)
|
3
|
-
# Copyright:: Copyright (c) 2013 Mohit Sethi.
|
4
|
-
#
|
5
|
-
|
6
|
-
module VagrantPlugins
|
7
|
-
module HP
|
8
|
-
module Action
|
9
|
-
class MessageAlreadyCreated
|
10
|
-
def initialize(app, env)
|
11
|
-
@app = app
|
12
|
-
end
|
13
|
-
|
14
|
-
def call(env)
|
15
|
-
env[:ui].info(I18n.t("vagrant_hp.already_created"))
|
16
|
-
@app.call(env)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
1
|
+
#
|
2
|
+
# Author:: Mohit Sethi (<mohit@sethis.in>)
|
3
|
+
# Copyright:: Copyright (c) 2013 Mohit Sethi.
|
4
|
+
#
|
5
|
+
|
6
|
+
module VagrantPlugins
|
7
|
+
module HP
|
8
|
+
module Action
|
9
|
+
class MessageAlreadyCreated
|
10
|
+
def initialize(app, env)
|
11
|
+
@app = app
|
12
|
+
end
|
13
|
+
|
14
|
+
def call(env)
|
15
|
+
env[:ui].info(I18n.t("vagrant_hp.already_created"))
|
16
|
+
@app.call(env)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -1,21 +1,21 @@
|
|
1
|
-
#
|
2
|
-
# Author:: Mohit Sethi (<mohit@sethis.in>)
|
3
|
-
# Copyright:: Copyright (c) 2013 Mohit Sethi.
|
4
|
-
#
|
5
|
-
|
6
|
-
module VagrantPlugins
|
7
|
-
module HP
|
8
|
-
module Action
|
9
|
-
class MessageNotCreated
|
10
|
-
def initialize(app, env)
|
11
|
-
@app = app
|
12
|
-
end
|
13
|
-
|
14
|
-
def call(env)
|
15
|
-
env[:ui].info(I18n.t("vagrant_hp.not_created"))
|
16
|
-
@app.call(env)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
1
|
+
#
|
2
|
+
# Author:: Mohit Sethi (<mohit@sethis.in>)
|
3
|
+
# Copyright:: Copyright (c) 2013 Mohit Sethi.
|
4
|
+
#
|
5
|
+
|
6
|
+
module VagrantPlugins
|
7
|
+
module HP
|
8
|
+
module Action
|
9
|
+
class MessageNotCreated
|
10
|
+
def initialize(app, env)
|
11
|
+
@app = app
|
12
|
+
end
|
13
|
+
|
14
|
+
def call(env)
|
15
|
+
env[:ui].info(I18n.t("vagrant_hp.not_created"))
|
16
|
+
@app.call(env)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -1,51 +1,51 @@
|
|
1
|
-
#
|
2
|
-
# Author:: Mohit Sethi (<mohit@sethis.in>)
|
3
|
-
# Copyright:: Copyright (c) 2013 Mohit Sethi.
|
4
|
-
#
|
5
|
-
|
6
|
-
require "log4r"
|
7
|
-
|
8
|
-
module VagrantPlugins
|
9
|
-
module HP
|
10
|
-
module Action
|
11
|
-
# This action reads the SSH info for the machine and puts it into the
|
12
|
-
# `:machine_ssh_info` key in the environment.
|
13
|
-
class ReadSSHInfo
|
14
|
-
def initialize(app, env)
|
15
|
-
@app = app
|
16
|
-
@logger = Log4r::Logger.new("vagrant_hp::action::read_ssh_info")
|
17
|
-
end
|
18
|
-
|
19
|
-
def call(env)
|
20
|
-
env[:machine_ssh_info] = read_ssh_info(env[:hp_compute], env[:machine])
|
21
|
-
|
22
|
-
@app.call(env)
|
23
|
-
end
|
24
|
-
|
25
|
-
def read_ssh_info(hp, machine)
|
26
|
-
return nil if machine.id.nil?
|
27
|
-
|
28
|
-
# Find the machine
|
29
|
-
server = hp.servers.get(machine.id)
|
30
|
-
if server.nil?
|
31
|
-
# The machine can't be found
|
32
|
-
@logger.info("Machine couldn't be found, assuming it got destroyed.")
|
33
|
-
machine.id = nil
|
34
|
-
return nil
|
35
|
-
end
|
36
|
-
|
37
|
-
config = machine.provider_config
|
38
|
-
|
39
|
-
# Read the DNS info
|
40
|
-
return {
|
41
|
-
# Usually there should only be one public IP
|
42
|
-
:host => server.public_ip_address,
|
43
|
-
:port => 22,
|
44
|
-
:username => config.ssh_username,
|
45
|
-
:private_key_path => config.ssh_private_key_path,
|
46
|
-
}
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
1
|
+
#
|
2
|
+
# Author:: Mohit Sethi (<mohit@sethis.in>)
|
3
|
+
# Copyright:: Copyright (c) 2013 Mohit Sethi.
|
4
|
+
#
|
5
|
+
|
6
|
+
require "log4r"
|
7
|
+
|
8
|
+
module VagrantPlugins
|
9
|
+
module HP
|
10
|
+
module Action
|
11
|
+
# This action reads the SSH info for the machine and puts it into the
|
12
|
+
# `:machine_ssh_info` key in the environment.
|
13
|
+
class ReadSSHInfo
|
14
|
+
def initialize(app, env)
|
15
|
+
@app = app
|
16
|
+
@logger = Log4r::Logger.new("vagrant_hp::action::read_ssh_info")
|
17
|
+
end
|
18
|
+
|
19
|
+
def call(env)
|
20
|
+
env[:machine_ssh_info] = read_ssh_info(env[:hp_compute], env[:machine])
|
21
|
+
|
22
|
+
@app.call(env)
|
23
|
+
end
|
24
|
+
|
25
|
+
def read_ssh_info(hp, machine)
|
26
|
+
return nil if machine.id.nil?
|
27
|
+
|
28
|
+
# Find the machine
|
29
|
+
server = hp.servers.get(machine.id)
|
30
|
+
if server.nil?
|
31
|
+
# The machine can't be found
|
32
|
+
@logger.info("Machine couldn't be found, assuming it got destroyed.")
|
33
|
+
machine.id = nil
|
34
|
+
return nil
|
35
|
+
end
|
36
|
+
|
37
|
+
config = machine.provider_config
|
38
|
+
|
39
|
+
# Read the DNS info
|
40
|
+
return {
|
41
|
+
# Usually there should only be one public IP
|
42
|
+
:host => server.public_ip_address,
|
43
|
+
:port => 22,
|
44
|
+
:username => config.ssh_username,
|
45
|
+
:private_key_path => config.ssh_private_key_path,
|
46
|
+
}
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -1,43 +1,43 @@
|
|
1
|
-
#
|
2
|
-
# Author:: Mohit Sethi (<mohit@sethis.in>)
|
3
|
-
# Copyright:: Copyright (c) 2013 Mohit Sethi.
|
4
|
-
#
|
5
|
-
|
6
|
-
require "log4r"
|
7
|
-
|
8
|
-
module VagrantPlugins
|
9
|
-
module HP
|
10
|
-
module Action
|
11
|
-
# This action reads the state of the machine and puts it in the
|
12
|
-
# `:machine_state_id` key in the environment.
|
13
|
-
class ReadState
|
14
|
-
def initialize(app, env)
|
15
|
-
@app = app
|
16
|
-
@logger = Log4r::Logger.new("vagrant_hp::action::read_state")
|
17
|
-
end
|
18
|
-
|
19
|
-
def call(env)
|
20
|
-
env[:machine_state_id] = read_state(env[:hp_compute], env[:machine])
|
21
|
-
|
22
|
-
@app.call(env)
|
23
|
-
end
|
24
|
-
|
25
|
-
def read_state(hp, machine)
|
26
|
-
return :not_created if machine.id.nil?
|
27
|
-
|
28
|
-
# Find the machine
|
29
|
-
server = hp.servers.get(machine.id)
|
30
|
-
if server.nil? || [:"shutting-down", :terminated].include?(server.state.to_sym)
|
31
|
-
# The machine can't be found
|
32
|
-
@logger.info("Machine not found or terminated, assuming it got destroyed.")
|
33
|
-
machine.id = nil
|
34
|
-
return :not_created
|
35
|
-
end
|
36
|
-
|
37
|
-
# Return the state
|
38
|
-
return server.state.to_sym
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
1
|
+
#
|
2
|
+
# Author:: Mohit Sethi (<mohit@sethis.in>)
|
3
|
+
# Copyright:: Copyright (c) 2013 Mohit Sethi.
|
4
|
+
#
|
5
|
+
|
6
|
+
require "log4r"
|
7
|
+
|
8
|
+
module VagrantPlugins
|
9
|
+
module HP
|
10
|
+
module Action
|
11
|
+
# This action reads the state of the machine and puts it in the
|
12
|
+
# `:machine_state_id` key in the environment.
|
13
|
+
class ReadState
|
14
|
+
def initialize(app, env)
|
15
|
+
@app = app
|
16
|
+
@logger = Log4r::Logger.new("vagrant_hp::action::read_state")
|
17
|
+
end
|
18
|
+
|
19
|
+
def call(env)
|
20
|
+
env[:machine_state_id] = read_state(env[:hp_compute], env[:machine])
|
21
|
+
|
22
|
+
@app.call(env)
|
23
|
+
end
|
24
|
+
|
25
|
+
def read_state(hp, machine)
|
26
|
+
return :not_created if machine.id.nil?
|
27
|
+
|
28
|
+
# Find the machine
|
29
|
+
server = hp.servers.get(machine.id)
|
30
|
+
if server.nil? || [:"shutting-down", :terminated].include?(server.state.to_sym)
|
31
|
+
# The machine can't be found
|
32
|
+
@logger.info("Machine not found or terminated, assuming it got destroyed.")
|
33
|
+
machine.id = nil
|
34
|
+
return :not_created
|
35
|
+
end
|
36
|
+
|
37
|
+
# Return the state
|
38
|
+
return server.state.to_sym
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -1,63 +1,63 @@
|
|
1
|
-
#
|
2
|
-
# Author:: Mohit Sethi (<mohit@sethis.in>)
|
3
|
-
# Copyright:: Copyright (c) 2013 Mohit Sethi.
|
4
|
-
#
|
5
|
-
|
6
|
-
require "log4r"
|
7
|
-
|
8
|
-
require "vagrant/util/subprocess"
|
9
|
-
|
10
|
-
module VagrantPlugins
|
11
|
-
module HP
|
12
|
-
module Action
|
13
|
-
# This middleware uses `rsync` to sync the folders over to the
|
14
|
-
# HP instance.
|
15
|
-
class SyncFolders
|
16
|
-
def initialize(app, env)
|
17
|
-
@app = app
|
18
|
-
@logger = Log4r::Logger.new("vagrant_hp::action::sync_folders")
|
19
|
-
end
|
20
|
-
|
21
|
-
def call(env)
|
22
|
-
@app.call(env)
|
23
|
-
|
24
|
-
ssh_info = env[:machine].ssh_info
|
25
|
-
|
26
|
-
env[:machine].config.vm.synced_folders.each do |id, data|
|
27
|
-
next if data[:hostpath] == "."
|
28
|
-
hostpath = File.expand_path(data[:hostpath], env[:root_path])
|
29
|
-
guestpath = data[:guestpath]
|
30
|
-
|
31
|
-
# Make sure there is a trailing slash on the host path to
|
32
|
-
# avoid creating an additional directory with rsync
|
33
|
-
hostpath = "#{hostpath}/" if hostpath !~ /\/$/
|
34
|
-
|
35
|
-
env[:ui].info(I18n.t("vagrant_hp.rsync_folder",
|
36
|
-
:hostpath => hostpath,
|
37
|
-
:guestpath => guestpath))
|
38
|
-
|
39
|
-
# Create the guest path
|
40
|
-
env[:machine].communicate.sudo("mkdir -p '#{guestpath}'")
|
41
|
-
env[:machine].communicate.sudo(
|
42
|
-
"chown #{ssh_info[:username]} '#{guestpath}'")
|
43
|
-
|
44
|
-
# Rsync over to the guest path using the SSH info
|
45
|
-
command = [
|
46
|
-
"rsync", "--verbose", "--archive", "-z",
|
47
|
-
"-e", "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -p #{ssh_info[:port]} -i '#{ssh_info[:private_key_path]}'",
|
48
|
-
hostpath,
|
49
|
-
"#{ssh_info[:username]}@#{ssh_info[:host]}:#{guestpath}"]
|
50
|
-
|
51
|
-
r = Vagrant::Util::Subprocess.execute(*command)
|
52
|
-
if r.exit_code != 0
|
53
|
-
raise Errors::RsyncError,
|
54
|
-
:guestpath => guestpath,
|
55
|
-
:hostpath => hostpath,
|
56
|
-
:stderr => r.stderr
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
1
|
+
#
|
2
|
+
# Author:: Mohit Sethi (<mohit@sethis.in>)
|
3
|
+
# Copyright:: Copyright (c) 2013 Mohit Sethi.
|
4
|
+
#
|
5
|
+
|
6
|
+
require "log4r"
|
7
|
+
|
8
|
+
require "vagrant/util/subprocess"
|
9
|
+
|
10
|
+
module VagrantPlugins
|
11
|
+
module HP
|
12
|
+
module Action
|
13
|
+
# This middleware uses `rsync` to sync the folders over to the
|
14
|
+
# HP instance.
|
15
|
+
class SyncFolders
|
16
|
+
def initialize(app, env)
|
17
|
+
@app = app
|
18
|
+
@logger = Log4r::Logger.new("vagrant_hp::action::sync_folders")
|
19
|
+
end
|
20
|
+
|
21
|
+
def call(env)
|
22
|
+
@app.call(env)
|
23
|
+
|
24
|
+
ssh_info = env[:machine].ssh_info
|
25
|
+
|
26
|
+
env[:machine].config.vm.synced_folders.each do |id, data|
|
27
|
+
next if data[:hostpath] == "."
|
28
|
+
hostpath = File.expand_path(data[:hostpath], env[:root_path])
|
29
|
+
guestpath = data[:guestpath]
|
30
|
+
|
31
|
+
# Make sure there is a trailing slash on the host path to
|
32
|
+
# avoid creating an additional directory with rsync
|
33
|
+
hostpath = "#{hostpath}/" if hostpath !~ /\/$/
|
34
|
+
|
35
|
+
env[:ui].info(I18n.t("vagrant_hp.rsync_folder",
|
36
|
+
:hostpath => hostpath,
|
37
|
+
:guestpath => guestpath))
|
38
|
+
|
39
|
+
# Create the guest path
|
40
|
+
env[:machine].communicate.sudo("mkdir -p '#{guestpath}'")
|
41
|
+
env[:machine].communicate.sudo(
|
42
|
+
"chown #{ssh_info[:username]} '#{guestpath}'")
|
43
|
+
|
44
|
+
# Rsync over to the guest path using the SSH info
|
45
|
+
command = [
|
46
|
+
"rsync", "--verbose", "--archive", "-z",
|
47
|
+
"-e", "ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -p #{ssh_info[:port]} -i '#{ssh_info[:private_key_path]}'",
|
48
|
+
hostpath,
|
49
|
+
"#{ssh_info[:username]}@#{ssh_info[:host]}:#{guestpath}"]
|
50
|
+
|
51
|
+
r = Vagrant::Util::Subprocess.execute(*command)
|
52
|
+
if r.exit_code != 0
|
53
|
+
raise Errors::RsyncError,
|
54
|
+
:guestpath => guestpath,
|
55
|
+
:hostpath => hostpath,
|
56
|
+
:stderr => r.stderr
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -1,27 +1,27 @@
|
|
1
|
-
#
|
2
|
-
# Author:: Mohit Sethi (<mohit@sethis.in>)
|
3
|
-
# Copyright:: Copyright (c) 2013 Mohit Sethi.
|
4
|
-
#
|
5
|
-
|
6
|
-
require "vagrant-hp/util/timer"
|
7
|
-
|
8
|
-
module VagrantPlugins
|
9
|
-
module HP
|
10
|
-
module Action
|
11
|
-
# This is the same as the builtin provision except it times the
|
12
|
-
# provisioner runs.
|
13
|
-
class TimedProvision < Vagrant::Action::Builtin::Provision
|
14
|
-
def run_provisioner(env, p)
|
15
|
-
env[:ui].info("Insde TimedProvision")
|
16
|
-
timer = Util::Timer.time do
|
17
|
-
super
|
18
|
-
end
|
19
|
-
|
20
|
-
env[:metrics] ||= {}
|
21
|
-
env[:metrics]["provisioner_times"] ||= []
|
22
|
-
env[:metrics]["provisioner_times"] << [p.class.to_s, timer]
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
1
|
+
#
|
2
|
+
# Author:: Mohit Sethi (<mohit@sethis.in>)
|
3
|
+
# Copyright:: Copyright (c) 2013 Mohit Sethi.
|
4
|
+
#
|
5
|
+
|
6
|
+
require "vagrant-hp/util/timer"
|
7
|
+
|
8
|
+
module VagrantPlugins
|
9
|
+
module HP
|
10
|
+
module Action
|
11
|
+
# This is the same as the builtin provision except it times the
|
12
|
+
# provisioner runs.
|
13
|
+
class TimedProvision < Vagrant::Action::Builtin::Provision
|
14
|
+
def run_provisioner(env, p)
|
15
|
+
env[:ui].info("Insde TimedProvision")
|
16
|
+
timer = Util::Timer.time do
|
17
|
+
super
|
18
|
+
end
|
19
|
+
|
20
|
+
env[:metrics] ||= {}
|
21
|
+
env[:metrics]["provisioner_times"] ||= []
|
22
|
+
env[:metrics]["provisioner_times"] << [p.class.to_s, timer]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|