tenderloin 0.4.3 → 0.4.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/tenderloin/actions/base.rb +4 -2
- data/lib/tenderloin/actions/vm/shared_folders.rb +7 -3
- data/lib/tenderloin/actions/vm/up.rb +5 -1
- data/lib/tenderloin/cli.rb +11 -4
- data/lib/tenderloin/commands.rb +6 -4
- data/lib/tenderloin/ssh.rb +27 -1
- data/test/tenderloin/actions/vm/up_test.rb +12 -0
- metadata +1 -1
@@ -24,7 +24,8 @@ module Tenderloin
|
|
24
24
|
# documentation below.
|
25
25
|
class Base
|
26
26
|
# The {Runner runner} which is executing the action
|
27
|
-
|
27
|
+
# The {Array arguments} which are passed when executing the action
|
28
|
+
attr_reader :runner, :run_args
|
28
29
|
|
29
30
|
# Included so subclasses don't need to include it themselves.
|
30
31
|
include Tenderloin::Util
|
@@ -33,7 +34,8 @@ module Tenderloin
|
|
33
34
|
# been given to the {Runner runner}. This method can be used by subclasses
|
34
35
|
# to save any of the configuration options which are passed in.
|
35
36
|
def initialize(runner, *args)
|
36
|
-
@runner
|
37
|
+
@runner = runner
|
38
|
+
@run_args = args
|
37
39
|
end
|
38
40
|
|
39
41
|
# This method is called once per action, allowing the action
|
@@ -30,12 +30,16 @@ module Tenderloin
|
|
30
30
|
if Tenderloin.config.shared_folders.enabled
|
31
31
|
logger.info "Creating shared folders metadata..."
|
32
32
|
|
33
|
+
# Enable Shared Folders. It fails if it's already enabled.
|
34
|
+
# If it's a real error the command to add a shared folder will fail,
|
35
|
+
# so we can ignore this one.
|
36
|
+
@runner.fusion_vm.enable_shared_folders rescue nil
|
37
|
+
|
33
38
|
shared_folders.each do |name, hostpath, guestpath|
|
34
|
-
|
39
|
+
4.times do
|
35
40
|
begin
|
36
|
-
|
41
|
+
Timeout::timeout(10) {
|
37
42
|
@runner.fusion_vm.share_folder(name, File.expand_path(hostpath))
|
38
|
-
@runner.fusion_vm.enable_shared_folders
|
39
43
|
break
|
40
44
|
}
|
41
45
|
rescue Timeout::Error
|
@@ -18,7 +18,7 @@ msg
|
|
18
18
|
# of other actions in its place:
|
19
19
|
Tenderloin::Box.add(Tenderloin.config.vm.box, Tenderloin.config.vm.box_url) unless Tenderloin::Env.box
|
20
20
|
steps = [Import, SharedFolders, Boot]
|
21
|
-
steps << Provision if
|
21
|
+
steps << Provision if provision_enabled?
|
22
22
|
steps.insert(0, MoveHardDrive) if Tenderloin.config.vm.hd_location
|
23
23
|
|
24
24
|
steps.each do |action_klass|
|
@@ -51,6 +51,10 @@ msg
|
|
51
51
|
data['displayName'] = "tenderloin-" + @runner.vm_id
|
52
52
|
end
|
53
53
|
end
|
54
|
+
|
55
|
+
def provision_enabled?
|
56
|
+
Tenderloin.config.provisioning.enabled && !run_args.include?(:no_provision)
|
57
|
+
end
|
54
58
|
end
|
55
59
|
end
|
56
60
|
end
|
data/lib/tenderloin/cli.rb
CHANGED
@@ -12,10 +12,16 @@ module Tenderloin
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
desc "up [--file <tenderfile>]", "Boots the VM"
|
15
|
+
desc "up [--file <tenderfile> --no-provision]", "Boots the VM"
|
16
|
+
method_option :provision, :default => true
|
16
17
|
def up()
|
17
18
|
setup
|
18
|
-
|
19
|
+
|
20
|
+
if !options[:provision]
|
21
|
+
Tenderloin::Commands.up(:no_provision)
|
22
|
+
else
|
23
|
+
Tenderloin::Commands.up
|
24
|
+
end
|
19
25
|
end
|
20
26
|
|
21
27
|
desc "halt [--file <tenderfile>]", "Force shuts down the running VM"
|
@@ -55,10 +61,11 @@ module Tenderloin
|
|
55
61
|
Tenderloin::Commands.provision
|
56
62
|
end
|
57
63
|
|
58
|
-
desc "ssh [--file <tenderfile>]", "SSH's in to the VM"
|
64
|
+
desc "ssh [--file <tenderfile> --command <ssh command>]", "SSH's in to the VM"
|
65
|
+
method_option :command, :aliases => "-c"
|
59
66
|
def ssh()
|
60
67
|
setup
|
61
|
-
Tenderloin::Commands.ssh
|
68
|
+
Tenderloin::Commands.ssh(options[:command])
|
62
69
|
end
|
63
70
|
|
64
71
|
desc "ip [--file <tenderfile>]", "Shows the IP to access the VM"
|
data/lib/tenderloin/commands.rb
CHANGED
@@ -28,7 +28,7 @@ error
|
|
28
28
|
# the base VM, setting up shared folders, forwarded ports, etc to
|
29
29
|
# provisioning the instance with chef. {up} also starts the instance,
|
30
30
|
# running it in the background.
|
31
|
-
def up
|
31
|
+
def up(provision = nil)
|
32
32
|
Env.load!
|
33
33
|
|
34
34
|
if Env.persisted_vm
|
@@ -36,7 +36,7 @@ error
|
|
36
36
|
Env.persisted_vm.start
|
37
37
|
else
|
38
38
|
Env.require_box
|
39
|
-
VM.execute!(Actions::VM::Up)
|
39
|
+
VM.execute!(Actions::VM::Up, provision)
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
@@ -69,10 +69,12 @@ error
|
|
69
69
|
#
|
70
70
|
# This command requires that an instance already be brought up with
|
71
71
|
# `tenderloin up`.
|
72
|
-
|
72
|
+
#
|
73
|
+
# Command: shell command to run on the remote host
|
74
|
+
def ssh(command)
|
73
75
|
Env.load!
|
74
76
|
Env.require_persisted_vm
|
75
|
-
SSH.connect Env.persisted_vm.fusion_vm.ip
|
77
|
+
SSH.connect Env.persisted_vm.fusion_vm.ip, command
|
76
78
|
end
|
77
79
|
|
78
80
|
# Halts a running tenderloin instance. This forcibly halts the instance;
|
data/lib/tenderloin/ssh.rb
CHANGED
@@ -3,7 +3,33 @@ module Tenderloin
|
|
3
3
|
SCRIPT = File.join(File.dirname(__FILE__), '..', '..', 'script', 'tenderloin-ssh-expect.sh')
|
4
4
|
|
5
5
|
class << self
|
6
|
-
def connect(ip)
|
6
|
+
def connect(ip, command = nil)
|
7
|
+
if command
|
8
|
+
remote_exec(ip, command)
|
9
|
+
else
|
10
|
+
ssh_connect(ip)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def remote_exec(ip, command)
|
15
|
+
execute(ip) do |ssh|
|
16
|
+
ssh.open_channel do |channel|
|
17
|
+
channel.exec command do |ch, success|
|
18
|
+
raise "could not execute remote command: #{command}" unless success
|
19
|
+
|
20
|
+
ch.on_data do |c, data|
|
21
|
+
STDOUT.print data
|
22
|
+
end
|
23
|
+
|
24
|
+
ch.on_extended_data do |c, type, data|
|
25
|
+
STDERR.print data
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def ssh_connect(ip)
|
7
33
|
if options.keys
|
8
34
|
Kernel.exec "#{cmd_ssh_opts} #{options.username}@#{ip}"
|
9
35
|
else
|
@@ -95,4 +95,16 @@ class UpActionTest < Test::Unit::TestCase
|
|
95
95
|
@action.setup_mac_address
|
96
96
|
end
|
97
97
|
end
|
98
|
+
|
99
|
+
context "booting without provisioning" do
|
100
|
+
should "not add the provision task to the expected sequence" do
|
101
|
+
mock_vm, vm, action = mock_action(Tenderloin::Actions::VM::Up, :no_provision)
|
102
|
+
|
103
|
+
mock_config do |config|
|
104
|
+
config.chef.enabled = true
|
105
|
+
end
|
106
|
+
|
107
|
+
action.should_not be_provision_enabled
|
108
|
+
end
|
109
|
+
end
|
98
110
|
end
|