vagrant-pe_build 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. data/CHANGELOG +59 -0
  2. data/README.markdown +148 -5
  3. data/lib/pe_build.rb +5 -3
  4. data/lib/pe_build/action.rb +5 -0
  5. data/lib/pe_build/action/pe_build_dir.rb +18 -0
  6. data/lib/pe_build/archive.rb +39 -46
  7. data/lib/pe_build/cap.rb +17 -0
  8. data/lib/pe_build/cap/detect_installer/base.rb +15 -0
  9. data/lib/pe_build/cap/detect_installer/debian.rb +23 -0
  10. data/lib/pe_build/cap/detect_installer/posix.rb +73 -0
  11. data/lib/pe_build/cap/detect_installer/redhat.rb +18 -0
  12. data/lib/pe_build/cap/detect_installer/ubuntu.rb +23 -0
  13. data/lib/pe_build/cap/run_install/posix.rb +26 -0
  14. data/lib/pe_build/command.rb +6 -63
  15. data/lib/pe_build/command/base.rb +55 -0
  16. data/lib/pe_build/command/copy.rb +22 -23
  17. data/lib/pe_build/command/download.rb +4 -8
  18. data/lib/pe_build/command/list.rb +1 -6
  19. data/lib/pe_build/config/global.rb +13 -4
  20. data/lib/pe_build/config/pe_bootstrap.rb +4 -0
  21. data/lib/pe_build/idempotent.rb +1 -1
  22. data/lib/pe_build/on_machine.rb +10 -0
  23. data/lib/pe_build/plugin.rb +58 -22
  24. data/lib/pe_build/provisioner/pe_bootstrap.rb +123 -156
  25. data/lib/pe_build/provisioner/pe_bootstrap/answers_file.rb +49 -0
  26. data/lib/pe_build/release.rb +23 -0
  27. data/lib/pe_build/release/2_0.rb +25 -0
  28. data/lib/pe_build/release/2_5.rb +28 -0
  29. data/lib/pe_build/release/2_6.rb +27 -0
  30. data/lib/pe_build/release/2_7.rb +28 -0
  31. data/lib/pe_build/release/2_8.rb +35 -0
  32. data/lib/pe_build/release/3_0.rb +36 -0
  33. data/lib/pe_build/release/instance.rb +63 -0
  34. data/lib/pe_build/transfer.rb +25 -0
  35. data/lib/pe_build/transfer/file.rb +11 -9
  36. data/lib/pe_build/transfer/open_uri.rb +62 -0
  37. data/lib/pe_build/version.rb +1 -1
  38. data/templates/answers/{agent.txt.erb → agent-2.x.txt.erb} +1 -1
  39. data/templates/answers/agent-3.x.txt.erb +16 -0
  40. data/templates/answers/{master.txt.erb → master-2.x.txt.erb} +0 -0
  41. data/templates/answers/master-3.x.txt.erb +44 -0
  42. data/templates/locales/en.yml +16 -3
  43. metadata +28 -6
  44. data/lib/pe_build/transfer/uri.rb +0 -53
  45. data/templates/answers/master-existing-db.txt.erb +0 -52
@@ -0,0 +1,73 @@
1
+ # Provide an abstract base class for detecting the installer name on
2
+ # POSIX systems.
3
+ #
4
+ # @abstract
5
+ # @protected
6
+ class PEBuild::Cap::DetectInstaller::POSIX < PEBuild::Cap::DetectInstaller::Base
7
+
8
+ # @!method name
9
+ # @abstract
10
+ # @return [String] The name of the distribution
11
+
12
+ # @!method release_file
13
+ # @abstract
14
+ # @return [String] The file to use as the release file for the guest
15
+
16
+ # @!method release_file_format
17
+ # @abstract
18
+ # @return [Regexp] A regular expression with one capture that parses the distro version
19
+
20
+ # @!method supported_releases
21
+ # @abstract
22
+ # @return [Array<String>] All supported releases for the distribution
23
+
24
+
25
+ def detect
26
+ dist_version = parse_release_file
27
+
28
+ unless supported_releases.include? dist_version
29
+ raise "#{self.class.name} release #{dist_version} not supported"
30
+ end
31
+
32
+ "puppet-enterprise-#{@version}-#{name}-#{dist_version}-#{arch}.#{ext}"
33
+ end
34
+
35
+ def arch
36
+ content = ""
37
+ @machine.communicate.execute("uname -m") do |type, data|
38
+ raise "Could not run 'uname -m' on #{@machine}: got #{data}" if type == :stderr
39
+ content << data.chomp
40
+ end
41
+
42
+ content = 'i386' if content.match /i\d86/
43
+
44
+ content
45
+ end
46
+
47
+ def ext
48
+ 'tar.gz'
49
+ end
50
+
51
+ private
52
+
53
+ def release_content
54
+ content = ""
55
+
56
+ @machine.communicate.execute("cat #{release_file}") do |type, data|
57
+ raise "Could not read #{release_file} on #{@machine}: got #{data}" if type == :stderr
58
+ content << data
59
+ end
60
+
61
+ content
62
+ end
63
+
64
+ def parse_release_file
65
+ matchdata = release_content.match(release_file_format)
66
+
67
+ if matchdata.nil? or matchdata[1].nil?
68
+ raise "#{self.class.name} could not determine release value: content #{release_content.inspect} did not match #{release_file_format}"
69
+ end
70
+
71
+ matchdata[1]
72
+ end
73
+ end
@@ -0,0 +1,18 @@
1
+ class PEBuild::Cap::DetectInstaller::Redhat < PEBuild::Cap::DetectInstaller::POSIX
2
+
3
+ def name
4
+ 'el'
5
+ end
6
+
7
+ def release_file
8
+ '/etc/redhat-release'
9
+ end
10
+
11
+ def release_file_format
12
+ %r[release (\d+)\.\d+]
13
+ end
14
+
15
+ def supported_releases
16
+ %w[5 6]
17
+ end
18
+ end
@@ -0,0 +1,23 @@
1
+ class PEBuild::Cap::DetectInstaller::Ubuntu < PEBuild::Cap::DetectInstaller::POSIX
2
+
3
+ def name
4
+ 'ubuntu'
5
+ end
6
+
7
+ def release_file
8
+ '/etc/issue'
9
+ end
10
+
11
+ def release_file_format
12
+ %r[Ubuntu (\d{2}\.\d{2})]
13
+ end
14
+
15
+ def supported_releases
16
+ %w[10.04 12.04]
17
+ end
18
+
19
+ def arch
20
+ retval = super
21
+ (retval == 'x86_64') ? 'amd64' : retval
22
+ end
23
+ end
@@ -0,0 +1,26 @@
1
+ require 'pe_build/on_machine'
2
+ class PEBuild::Cap::RunInstall::POSIX
3
+
4
+ extend PEBuild::OnMachine
5
+
6
+ def self.run_install(machine, config, archive)
7
+
8
+ root = File.join('/vagrant', PEBuild::WORK_DIR)
9
+
10
+ cmd_path = []
11
+ cmd_path << root
12
+
13
+ cmd_path << archive.installer_dir
14
+ cmd_path << "puppet-enterprise-installer"
15
+
16
+ cmd = File.join(cmd_path)
17
+ answers = File.join(root, 'answers', "#{machine.name}.txt")
18
+
19
+ argv = "#{cmd} -a #{answers}"
20
+
21
+ on_machine(machine, argv)
22
+
23
+ machine.ui.info I18n.t('pebuild.provisioner.pe_bootstrap.scheduling_run')
24
+ machine.communicate.sudo("echo '/opt/puppet/bin/puppet agent -t' | at next minute")
25
+ end
26
+ end
@@ -1,68 +1,11 @@
1
1
  require 'vagrant'
2
+ require 'optparse'
2
3
 
3
4
  module PEBuild
4
- class Command < Vagrant.plugin(2, :command)
5
-
6
- def initialize(argv, env)
7
- super
8
-
9
- @main_args, @subcommand, @sub_args = split_main_and_subcommand(argv)
10
-
11
- @subcommands = Vagrant::Registry.new
12
-
13
- register_subcommands
14
- end
15
-
16
- def execute
17
- if @subcommand and (klass = @subcommands.get(@subcommand))
18
- klass.new(@argv, @env).execute
19
- elsif @subcommand
20
- raise "Unrecognized subcommand #{@subcommand}"
21
- else
22
- print_help
23
- end
24
- end
25
-
26
- private
27
-
28
- def register_subcommands
29
- @subcommands.register('copy') do
30
- require_relative 'command/copy'
31
- PEBuild::Command::Copy
32
- end
33
-
34
- @subcommands.register('download') do
35
- require_relative 'command/download'
36
- PEBuild::Command::Download
37
- end
38
-
39
- @subcommands.register('list') do
40
- require_relative 'command/list'
41
- PEBuild::Command::List
42
- end
5
+ module Command
6
+ require 'pe_build/command/base'
7
+ require 'pe_build/command/copy'
8
+ require 'pe_build/command/list'
9
+ require 'pe_build/command/download'
43
10
  end
44
-
45
- def print_help
46
- cmd = 'vagrant pe-build'
47
- opts = OptionParser.new do |opts|
48
- opts.banner = "Usage: #{cmd} <command> [<args>]"
49
- opts.separator ""
50
- opts.separator "Available subcommands:"
51
-
52
- # Add the available subcommands as separators in order to print them
53
- # out as well.
54
- keys = []
55
- @subcommands.each { |key, value| keys << key.to_s }
56
-
57
- keys.sort.each do |key|
58
- opts.separator " #{key}"
59
- end
60
-
61
- opts.separator ""
62
- opts.separator "For help on any individual command run `#{cmd} COMMAND -h`"
63
- end
64
-
65
- @env.ui.info(opts.help, :prefix => false)
66
- end
67
- end
68
11
  end
@@ -0,0 +1,55 @@
1
+ require 'vagrant'
2
+
3
+ class PEBuild::Command::Base < Vagrant.plugin(2, :command)
4
+
5
+ def initialize(argv, env)
6
+ super
7
+ split_argv
8
+
9
+ @subcommands = {
10
+ 'list' => PEBuild::Command::List,
11
+ 'download' => PEBuild::Command::Download,
12
+ 'copy' => PEBuild::Command::Copy,
13
+ }
14
+ end
15
+
16
+ def execute
17
+ if @subcommand
18
+ execute_subcommand
19
+ else
20
+ print_help
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ def split_argv
27
+ @main_args, @subcommand, @sub_args = split_main_and_subcommand(@argv)
28
+ end
29
+
30
+ def execute_subcommand
31
+ if (klass = @subcommands[@subcommand])
32
+ klass.new(@argv, @env).execute
33
+ else
34
+ raise "Unrecognized subcommand #{@subcommand}"
35
+ end
36
+ end
37
+
38
+ def print_help
39
+ cmd = 'vagrant pe-build'
40
+ opts = OptionParser.new do |opts|
41
+ opts.banner = "Usage: #{cmd} <command> [<args>]"
42
+ opts.separator ""
43
+ opts.separator "Available subcommands:"
44
+
45
+ @subcommands.keys.sort.each do |key|
46
+ opts.separator " #{key}"
47
+ end
48
+
49
+ opts.separator ""
50
+ opts.separator "For help on any individual command run `#{cmd} COMMAND -h`"
51
+ end
52
+
53
+ @env.ui.info(opts.help, :prefix => false)
54
+ end
55
+ end
@@ -1,16 +1,31 @@
1
- require 'vagrant'
2
- require 'optparse'
3
1
  require 'pe_build/archive'
4
2
 
5
- module PEBuild
6
- class Command
7
- class Copy < Vagrant.plugin(2, :command)
3
+ class PEBuild::Command::Copy < Vagrant.plugin(2, :command)
4
+
5
+ def initialize(argv, env)
6
+ super
7
+ @options = {}
8
+ end
8
9
 
9
10
  def execute
11
+ argv = parse_options(parser)
12
+
13
+ filename = File.basename(argv.last)
14
+ src_dir = File.dirname(argv.last)
15
+
16
+ archive = PEBuild::Archive.new(filename, @env)
17
+ archive.version = @options[:version]
18
+
19
+ uri = URI.parse src_dir
20
+ archive.fetch(uri)
21
+
22
+ @env.ui.info "pe-build: #{archive} has been added and is ready for use!", :prefix => true
23
+ end
10
24
 
11
- options = {}
25
+ private
12
26
 
13
- parser = OptionParser.new do |o|
27
+ def parser
28
+ OptionParser.new do |o|
14
29
  o.banner = "Usage: vagrant pe-build copy path/to/installer.tar.gz"
15
30
  o.separator ''
16
31
 
@@ -18,21 +33,5 @@ class Copy < Vagrant.plugin(2, :command)
18
33
  options[:version] = val
19
34
  end
20
35
  end
21
-
22
- argv = parse_options(parser)
23
- fpath = argv.last
24
-
25
- basename = File.basename(fpath)
26
- dirname = File.dirname(fpath)
27
-
28
- #unless options[:version]
29
- # raise Vagrant::Errors::CLIInvalidUsage, :help => parser.help.chomp
30
- #end
31
-
32
- archive = PEBuild::Archive.new(fpath, @env)
33
- archive.version = options[:version]
34
- archive.copy_from(dirname)
35
36
  end
36
37
  end
37
- end
38
- end
@@ -1,10 +1,6 @@
1
- require 'vagrant'
2
- require 'optparse'
3
1
  require 'pe_build/archive'
4
2
 
5
- module PEBuild
6
- class Command
7
- class Download < Vagrant.plugin(2, :command)
3
+ class PEBuild::Command::Download < Vagrant.plugin(2, :command)
8
4
 
9
5
  def execute
10
6
 
@@ -30,10 +26,10 @@ class Download < Vagrant.plugin(2, :command)
30
26
  raise Vagrant::Errors::CLIInvalidUsage, :help => parser.help.chomp
31
27
  end
32
28
 
29
+ uri = URI.parse(options[:dir])
30
+
33
31
  archive = PEBuild::Archive.new(filename, @env)
34
32
  archive.version = options[:version]
35
- archive.download_from(options[:dir])
33
+ archive.fetch(options[:dir])
36
34
  end
37
35
  end
38
- end
39
- end
@@ -1,9 +1,6 @@
1
- require 'vagrant'
2
1
  require 'pe_build/archive_collection'
3
2
 
4
- module PEBuild
5
- class Command
6
- class List < Vagrant.plugin(2, :command)
3
+ class PEBuild::Command::List < Vagrant.plugin(2, :command)
7
4
  def execute
8
5
  archive_dir = PEBuild.archive_directory(@env)
9
6
 
@@ -18,5 +15,3 @@ class List < Vagrant.plugin(2, :command)
18
15
  end
19
16
  end
20
17
  end
21
- end
22
- end
@@ -2,6 +2,7 @@ require 'uri'
2
2
  require 'vagrant'
3
3
 
4
4
  require 'pe_build/config_default'
5
+ require 'pe_build/transfer'
5
6
 
6
7
  module PEBuild
7
8
  module Config
@@ -45,7 +46,8 @@ class Global < Vagrant.plugin('2', :config)
45
46
  include PEBuild::ConfigDefault
46
47
 
47
48
  def finalize!
48
- set_default :@suffix, 'all'
49
+ set_default :@suffix, :detect
50
+
49
51
  #set_default :@version, DEFAULT_PE_VERSION
50
52
 
51
53
  set_default :@download_root, nil
@@ -66,9 +68,16 @@ class Global < Vagrant.plugin('2', :config)
66
68
  errors << "version only accepts a string, got #{@version.class}"
67
69
  end
68
70
 
69
- uri = URI.parse(@download_root) rescue nil
70
- unless @download_root == UNSET_VALUE or @download_root.nil? or File.directory?(File.expand_path(@download_root)) or uri.kind_of? (URI::HTTP||URI::HTTPS) or uri.kind_of? URI::FTP
71
- errors << "download_root must be valid URL or present local file path, got #{@download_root}"
71
+ if @download_root and @download_root != UNSET_VALUE
72
+ begin
73
+ uri = URI.parse(@download_root)
74
+
75
+ if PEBuild::Transfer::IMPLEMENTATIONS[uri.scheme].nil?
76
+ errors << "No handlers available for URI scheme #{uri.scheme}"
77
+ end
78
+ rescue URI::InvalidURIError
79
+ errors << 'download_root must be a valid URL or nil'
80
+ end
72
81
  end
73
82
 
74
83
  {"PE Build global config" => errors}
@@ -77,6 +77,10 @@ class PEBootstrap < PEBuild::Config::Global
77
77
  def validate(machine)
78
78
  h = super
79
79
 
80
+ unless @step.empty?
81
+ machine.ui.warn "pe_bootstrap: explicit steps are deprecated and will be removed soon."
82
+ end
83
+
80
84
  errors = []
81
85
  if @version == UNSET_VALUE and global_config_from(machine).pe_build.version == UNSET_VALUE
82
86
  errors << "Version must be set on provisioner when unset globally"
@@ -7,7 +7,7 @@ module Idempotent
7
7
  desc ||= fpath
8
8
 
9
9
  if File.exist? fpath
10
- @env.ui.warn "#{desc} is already present.", :prefix => true
10
+ @logger.info "#{desc} is already present."
11
11
  else
12
12
  yield
13
13
  end
@@ -0,0 +1,10 @@
1
+ module PEBuild
2
+ module OnMachine
3
+ def on_machine(machine, cmd)
4
+ machine.communicate.sudo(cmd) do |type, data|
5
+ color = (type == :stdout) ? :green : :red
6
+ machine.ui.info(data.chomp, :color => color, :prefix => true)
7
+ end
8
+ end
9
+ end
10
+ end