jamie 0.1.0.alpha12 → 0.1.0.alpha13
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/jamie/driver/vagrant.rb +4 -20
- data/lib/jamie/version.rb +1 -1
- data/lib/jamie.rb +70 -15
- metadata +2 -2
data/lib/jamie/driver/vagrant.rb
CHANGED
@@ -15,15 +15,15 @@ module Jamie
|
|
15
15
|
|
16
16
|
def perform_create(instance, state)
|
17
17
|
state['name'] = instance.name
|
18
|
-
|
18
|
+
run_command "vagrant up #{state['name']} --no-provision"
|
19
19
|
end
|
20
20
|
|
21
21
|
def perform_converge(instance, state)
|
22
|
-
|
22
|
+
run_command "vagrant provision #{state['name']}"
|
23
23
|
end
|
24
24
|
|
25
25
|
def perform_destroy(instance, state)
|
26
|
-
|
26
|
+
run_command "vagrant destroy #{state['name']} -f"
|
27
27
|
state.delete('name')
|
28
28
|
end
|
29
29
|
|
@@ -34,23 +34,7 @@ module Jamie
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def ssh(ssh_args, cmd)
|
37
|
-
|
38
|
-
end
|
39
|
-
|
40
|
-
def run(cmd)
|
41
|
-
puts " [vagrant command] '#{display_cmd(cmd)}'"
|
42
|
-
sh = Mixlib::ShellOut.new(cmd, :live_stream => STDOUT,
|
43
|
-
:timeout => 60000)
|
44
|
-
sh.run_command
|
45
|
-
puts " [vagrant command] ran in #{sh.execution_time} seconds."
|
46
|
-
sh.error!
|
47
|
-
rescue Mixlib::ShellOut::ShellCommandFailed => ex
|
48
|
-
raise ActionFailed, ex.message
|
49
|
-
end
|
50
|
-
|
51
|
-
def display_cmd(cmd)
|
52
|
-
parts = cmd.partition("\n")
|
53
|
-
parts[1] == "\n" ? "#{parts[0]}..." : cmd
|
37
|
+
run_command %{vagrant ssh #{ssh_args.first} --command '#{cmd}'}
|
54
38
|
end
|
55
39
|
end
|
56
40
|
end
|
data/lib/jamie/version.rb
CHANGED
data/lib/jamie.rb
CHANGED
@@ -555,6 +555,59 @@ module Jamie
|
|
555
555
|
end
|
556
556
|
end
|
557
557
|
|
558
|
+
# Stateless utility methods used in different contexts. Essentially a mini
|
559
|
+
# PassiveSupport library.
|
560
|
+
module Util
|
561
|
+
|
562
|
+
def self.to_camel_case(str)
|
563
|
+
str.split('_').map { |w| w.capitalize }.join
|
564
|
+
end
|
565
|
+
|
566
|
+
def self.to_snake_case(str)
|
567
|
+
str.split('::').
|
568
|
+
last.
|
569
|
+
gsub(/([A-Z+])([A-Z][a-z])/, '\1_\2').
|
570
|
+
gsub(/([a-z\d])([A-Z])/, '\1_\2').
|
571
|
+
downcase
|
572
|
+
end
|
573
|
+
end
|
574
|
+
|
575
|
+
# Mixin that wraps a command shell out invocation, providing a #run_command
|
576
|
+
# method.
|
577
|
+
module ShellOut
|
578
|
+
|
579
|
+
# Wrapped exception for any interally raised shell out commands.
|
580
|
+
class ShellCommandFailed < StandardError ; end
|
581
|
+
|
582
|
+
# Executes a command in a subshell on the local running system.
|
583
|
+
#
|
584
|
+
# @param cmd [String] command to be executed locally
|
585
|
+
# @param use_sudo [TrueClass, FalseClass] whether or not to use sudo
|
586
|
+
# @param log_subject [String] used in the output or log header for clarity
|
587
|
+
# and context
|
588
|
+
def run_command(cmd, use_sudo = false, log_subject = "local")
|
589
|
+
cmd = "sudo #{cmd}" if use_sudo
|
590
|
+
subject = " [#{log_subject} command]"
|
591
|
+
|
592
|
+
$stdout.puts "#{subject} (#{display_cmd(cmd)})"
|
593
|
+
sh = Mixlib::ShellOut.new(cmd, :live_stream => $stdout, :timeout => 60000)
|
594
|
+
sh.run_command
|
595
|
+
puts "#{subject} ran in #{sh.execution_time} seconds."
|
596
|
+
sh.error!
|
597
|
+
rescue Mixlib::ShellOut::ShellCommandFailed => ex
|
598
|
+
raise ShellCommandFailed, ex.message
|
599
|
+
end
|
600
|
+
|
601
|
+
private
|
602
|
+
|
603
|
+
def display_cmd(cmd)
|
604
|
+
first_line, newline, rest = cmd.partition("\n")
|
605
|
+
last_char = cmd[cmd.size - 1]
|
606
|
+
|
607
|
+
newline == "\n" ? "#{first_line}\\n...#{last_char}" : cmd
|
608
|
+
end
|
609
|
+
end
|
610
|
+
|
558
611
|
module Driver
|
559
612
|
|
560
613
|
# Wrapped exception for any internally raised driver exceptions.
|
@@ -567,7 +620,7 @@ module Jamie
|
|
567
620
|
def self.for_plugin(plugin, config)
|
568
621
|
require "jamie/driver/#{plugin}"
|
569
622
|
|
570
|
-
klass = self.const_get(
|
623
|
+
klass = self.const_get(Util.to_camel_case(plugin))
|
571
624
|
klass.new(config)
|
572
625
|
end
|
573
626
|
|
@@ -576,6 +629,8 @@ module Jamie
|
|
576
629
|
# destroying an instance.
|
577
630
|
class Base
|
578
631
|
|
632
|
+
include ShellOut
|
633
|
+
|
579
634
|
def initialize(config)
|
580
635
|
@config = config
|
581
636
|
self.class.defaults.each do |attr, value|
|
@@ -673,6 +728,13 @@ module Jamie
|
|
673
728
|
))
|
674
729
|
end
|
675
730
|
|
731
|
+
def run_command(cmd, use_sudo = nil, log_subject = nil)
|
732
|
+
use_sudo = config['use_sudo'] if use_sudo.nil?
|
733
|
+
log_subject = Util.to_snake_case(self.class.to_s)
|
734
|
+
|
735
|
+
super(cmd, use_sudo, log_subject)
|
736
|
+
end
|
737
|
+
|
676
738
|
def self.defaults
|
677
739
|
@defaults ||= Hash.new
|
678
740
|
end
|
@@ -810,6 +872,8 @@ module Jamie
|
|
810
872
|
# instance over SSH.
|
811
873
|
class ChefDataUploader
|
812
874
|
|
875
|
+
include ShellOut
|
876
|
+
|
813
877
|
def initialize(instance, ssh_args, jamie_root, chef_home)
|
814
878
|
@instance = instance
|
815
879
|
@ssh_args = ssh_args
|
@@ -891,30 +955,21 @@ module Jamie
|
|
891
955
|
|
892
956
|
def run_berks(tmpdir)
|
893
957
|
begin
|
894
|
-
|
958
|
+
run_command "if ! command -v berks >/dev/null; then exit 1; fi"
|
895
959
|
rescue Mixlib::ShellOut::ShellCommandFailed
|
896
960
|
abort ">>>>>> Berkshelf must be installed, add it to your Gemfile."
|
897
961
|
end
|
898
|
-
|
962
|
+
run_command "berks install --path #{tmpdir}"
|
899
963
|
end
|
900
964
|
|
901
965
|
def run_librarian(tmpdir)
|
902
966
|
begin
|
903
|
-
|
967
|
+
run_command "if ! command -v librarian-chef >/dev/null; then exit 1; fi"
|
904
968
|
rescue Mixlib::ShellOut::ShellCommandFailed
|
905
969
|
abort ">>>>>> Librarian must be installed, add it to your Gemfile."
|
906
970
|
end
|
907
|
-
|
908
|
-
end
|
909
|
-
|
910
|
-
def run(cmd)
|
911
|
-
puts " [local command] '#{cmd}'"
|
912
|
-
sh = Mixlib::ShellOut.new(cmd, :live_stream => STDOUT)
|
913
|
-
sh.run_command
|
914
|
-
puts " [local command] ran in #{sh.execution_time} seconds."
|
915
|
-
sh.error!
|
916
|
-
rescue Mixlib::ShellOut::ShellCommandFailed => ex
|
917
|
-
raise ActionFailed, ex.message
|
971
|
+
run_command "librarian-chef install --path #{tmpdir}"
|
918
972
|
end
|
919
973
|
end
|
974
|
+
|
920
975
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jamie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.0.
|
4
|
+
version: 0.1.0.alpha13
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -194,7 +194,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
194
194
|
version: '0'
|
195
195
|
segments:
|
196
196
|
- 0
|
197
|
-
hash:
|
197
|
+
hash: -1363591312854279086
|
198
198
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
199
199
|
none: false
|
200
200
|
requirements:
|