vagrant-pe_build 0.12.0 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +24 -0
  3. data/README.markdown +152 -71
  4. data/acceptance/pe_build/pe_bootstrap_2015x_spec.rb +61 -13
  5. data/acceptance/pe_build/pe_bootstrap_3x_spec.rb +6 -3
  6. data/acceptance/pe_build/pe_bootstrap_latest_spec.rb +6 -3
  7. data/acceptance/skeletons/2015x_acceptance/Vagrantfile +25 -49
  8. data/acceptance/skeletons/pe_build/Vagrantfile +1 -1
  9. data/lib/pe_build/cap.rb +9 -0
  10. data/lib/pe_build/cap/detect_installer/base.rb +18 -0
  11. data/lib/pe_build/cap/detect_installer/posix.rb +0 -15
  12. data/lib/pe_build/cap/detect_installer/windows.rb +22 -4
  13. data/lib/pe_build/cap/facts/base.rb +119 -0
  14. data/lib/pe_build/cap/facts/debian.rb +37 -0
  15. data/lib/pe_build/cap/facts/posix.rb +36 -0
  16. data/lib/pe_build/cap/facts/redhat.rb +37 -0
  17. data/lib/pe_build/cap/facts/solaris.rb +46 -0
  18. data/lib/pe_build/cap/facts/suse.rb +38 -0
  19. data/lib/pe_build/cap/facts/ubuntu.rb +35 -0
  20. data/lib/pe_build/cap/facts/windows.rb +58 -0
  21. data/lib/pe_build/command.rb +1 -0
  22. data/lib/pe_build/command/base.rb +2 -1
  23. data/lib/pe_build/command/facts.rb +63 -0
  24. data/lib/pe_build/config.rb +1 -0
  25. data/lib/pe_build/config/pe_agent.rb +120 -0
  26. data/lib/pe_build/config_builder.rb +1 -0
  27. data/lib/pe_build/config_builder/pe_agent.rb +44 -0
  28. data/lib/pe_build/plugin.rb +44 -0
  29. data/lib/pe_build/provisioner/pe_agent.rb +262 -0
  30. data/lib/pe_build/release.rb +1 -1
  31. data/lib/pe_build/release/2015_2.rb +1 -0
  32. data/lib/pe_build/util/machine_comms.rb +51 -0
  33. data/lib/pe_build/util/pe_packaging.rb +57 -0
  34. data/lib/pe_build/version.rb +1 -1
  35. data/spec/unit/config/pe_agent_spec.rb +154 -0
  36. data/spec/unit/provisioner/pe_agent_spec.rb +101 -0
  37. data/tasks/acceptance.rake +2 -1
  38. data/templates/locales/en.yml +53 -0
  39. data/vagrant-pe_build.gemspec +4 -4
  40. data/vagrant-spec.config.example.rb +1 -1
  41. metadata +24 -5
@@ -0,0 +1,46 @@
1
+ require_relative 'posix'
2
+
3
+ # Facts implementation for Solaris guests
4
+ #
5
+ # @since 0.13.0
6
+ class PEBuild::Cap::Facts::Solaris < PEBuild::Cap::Facts::POSIX
7
+
8
+ # (see PEBuild::Cap::Facts::Base#os_info)
9
+ #
10
+ # Currently returns `family` as `Solaris`.
11
+ #
12
+ # @see PEBuild::Cap::Facts::Base#os_info
13
+ def os_info
14
+ {
15
+ 'family' => 'Solaris'
16
+ }
17
+ end
18
+
19
+ # (see PEBuild::Cap::Facts::Base#release_info)
20
+ #
21
+ # Reads `/etc/release` and generates a `full` version along with a
22
+ # `major` component.
23
+ #
24
+ # @todo Capture full version string. I.E 11.2, 10u11, etc and add `minor`
25
+ # component.
26
+ #
27
+ # @see PEBuild::Cap::Facts::Base#release_info
28
+ def release_info
29
+ release_file = sudo('cat /etc/release')[:stdout]
30
+
31
+ # Cribbed from Facter 2.4.
32
+ if match = release_file.match(/\s+s(\d+)[sx]?(_u\d+)?.*(?:SPARC|X86)/)
33
+ version = match.captures.join('')
34
+ elsif match = release_file.match(/Solaris ([0-9\.]+(?:\s*[0-9\.\/]+))\s*(?:SPARC|X86)/)
35
+ version = match.captures.first
36
+ else
37
+ version = sudo('uname -v')[:stdout]
38
+ end
39
+
40
+ {
41
+ 'major' => version.scan(/\d+/).first,
42
+ 'full' => version
43
+ }
44
+ end
45
+
46
+ end
@@ -0,0 +1,38 @@
1
+ require_relative 'posix'
2
+
3
+ # Facts implementation for SUSE guests
4
+ #
5
+ # @since 0.13.0
6
+ class PEBuild::Cap::Facts::SUSE < PEBuild::Cap::Facts::POSIX
7
+
8
+ # (see PEBuild::Cap::Facts::Base#os_info)
9
+ #
10
+ # Returns `family` as `SUSE` and `name` as `SLES`.
11
+ #
12
+ # @see PEBuild::Cap::Facts::Base#os_info
13
+ def os_info
14
+ {
15
+ 'name' => 'SLES',
16
+ 'family' => 'SUSE'
17
+ }
18
+ end
19
+
20
+ # (see PEBuild::Cap::Facts::Base#release_info)
21
+ #
22
+ # Reads `/etc/SuSE-release` and generates a `full` version along with
23
+ # `major` and `minor` components.
24
+ #
25
+ # @see PEBuild::Cap::Facts::Base#release_info
26
+ def release_info
27
+ release_file = sudo('cat /etc/SuSE-release')[:stdout]
28
+ major = release_file.match(/VERSION\s*=\s*(\d+)/)[1]
29
+ minor = release_file.match(/PATCHLEVEL\s*=\s*(\d+)/)[1]
30
+
31
+ {
32
+ 'major' => major,
33
+ 'minor' => minor,
34
+ 'full' => [major, minor].join('.')
35
+ }
36
+ end
37
+
38
+ end
@@ -0,0 +1,35 @@
1
+ require_relative 'posix'
2
+
3
+ # Facts implementation for Ubuntu guests
4
+ #
5
+ # @since 0.13.0
6
+ class PEBuild::Cap::Facts::Ubuntu < PEBuild::Cap::Facts::POSIX
7
+
8
+ # (see PEBuild::Cap::Facts::Base#os_info)
9
+ #
10
+ # Returns `family` as `Debian` and `name` as `Ubuntu`.
11
+ #
12
+ # @see PEBuild::Cap::Facts::Base#os_info
13
+ def os_info
14
+ {
15
+ 'name' => 'Ubuntu',
16
+ 'family' => 'Debian'
17
+ }
18
+ end
19
+
20
+
21
+ # (see PEBuild::Cap::Facts::Base#release_info)
22
+ #
23
+ # Reads `/etc/issue` and generates a `full` version.
24
+ #
25
+ # @see PEBuild::Cap::Facts::Base#release_info
26
+ def release_info
27
+ release_file = sudo('cat /etc/issue')[:stdout]
28
+ version = release_file.match(/Ubuntu (\d{2}\.\d{2})/)[1]
29
+
30
+ {
31
+ 'full' => version
32
+ }
33
+ end
34
+
35
+ end
@@ -0,0 +1,58 @@
1
+ require_relative 'base'
2
+
3
+ # Facts implementation for Windows guests
4
+ #
5
+ # @since 0.13.0
6
+ class PEBuild::Cap::Facts::Windows < PEBuild::Cap::Facts::Base
7
+
8
+ # (see PEBuild::Cap::Facts::Base#architecture)
9
+ #
10
+ # Looks at the default pointer size for integers and returns `x86` or `x64`.
11
+ #
12
+ # @see PEBuild::Cap::Facts::Base#architecture
13
+ def architecture
14
+ sudo('if ([System.IntPtr]::Size -eq 4) { "x86" } else { "x64" }')[:stdout]
15
+ end
16
+
17
+ # (see PEBuild::Cap::Facts::Base#os_info)
18
+ #
19
+ # Currently returns `family` as `Windows`.
20
+ #
21
+ # @see PEBuild::Cap::Facts::Base#os_info
22
+ def os_info
23
+ {
24
+ 'family' => 'Windows',
25
+ }
26
+ end
27
+
28
+ # (see PEBuild::Cap::Facts::Base#release_info)
29
+ #
30
+ # Queries WMI and generates a `full` version.
31
+ #
32
+ # @see PEBuild::Cap::Facts::Base#release_info
33
+ def release_info
34
+ version = sudo('(Get-WmiObject -Class Win32_OperatingSystem).Version')[:stdout]
35
+ producttype = sudo('(Get-WmiObject -Class Win32_OperatingSystem).Producttype')[:stdout]
36
+
37
+ # Cribbed from Facter 2.4.
38
+ #
39
+ # NOTE: Currently doesn't support XP/Server 2003 or Windows 10.
40
+ name = case version
41
+ when /^6\.3/
42
+ producttype == 1 ? "8.1" : "2012 R2"
43
+ when /^6\.2/
44
+ producttype == 1 ? "8" : "2012"
45
+ when /^6\.1/
46
+ producttype == 1 ? "7" : "2008 R2"
47
+ when /^6\.0/
48
+ producttype == 1 ? "Vista" : "2008"
49
+ else
50
+ version # Default to the raw version number.
51
+ end
52
+
53
+ {
54
+ 'full' => name
55
+ }
56
+ end
57
+
58
+ end
@@ -6,5 +6,6 @@ module PEBuild
6
6
  require 'pe_build/command/base'
7
7
  require 'pe_build/command/copy'
8
8
  require 'pe_build/command/list'
9
+ require 'pe_build/command/facts'
9
10
  end
10
11
  end
@@ -3,7 +3,7 @@ require 'vagrant'
3
3
  class PEBuild::Command::Base < Vagrant.plugin(2, :command)
4
4
 
5
5
  def self.synopsis
6
- 'list and download PE installers'
6
+ 'Commands related to PE Installation'
7
7
  end
8
8
 
9
9
  def initialize(argv, env)
@@ -13,6 +13,7 @@ class PEBuild::Command::Base < Vagrant.plugin(2, :command)
13
13
  @subcommands = {
14
14
  'list' => PEBuild::Command::List,
15
15
  'copy' => PEBuild::Command::Copy,
16
+ 'facts' => PEBuild::Command::Facts,
16
17
  }
17
18
  end
18
19
 
@@ -0,0 +1,63 @@
1
+ require 'json'
2
+
3
+ class PEBuild::Command::Facts < Vagrant.plugin(2, :command)
4
+
5
+ def self.synopsis
6
+ 'Load facts from running VMs'
7
+ end
8
+
9
+ def execute
10
+ argv = parse_options(parser)
11
+ argv.shift # Remove 'facts' subcommand.
12
+
13
+ running = @env.active_machines.map do |name, provider|
14
+ @env.machine(name, provider)
15
+ end.select do |vm|
16
+ begin
17
+ vm.communicate.ready?
18
+ rescue Vagrant::Errors::VagrantError
19
+ # WinRM will raise an error if the VM isn't running instead of
20
+ # returning false (GH-6356).
21
+ false
22
+ end
23
+ end
24
+
25
+ # Filter the list of VMs for inspection down to just those passed on the
26
+ # command line. Warn if the user passed a VM that was not running.
27
+ unless argv.empty?
28
+ running_vms = running.map {|vm| vm.name.to_s}
29
+ argv.each do |name|
30
+ @env.ui.warn I18n.t('pebuild.command.facts.vm_not_running', :vm_name => name) unless running_vms.include? name
31
+ end
32
+
33
+ running.select! {|vm| argv.include? vm.name.to_s}
34
+ end
35
+
36
+ running.each do |vm|
37
+ facts = vm.guest.capability(:pebuild_facts)
38
+
39
+ @env.ui.machine('guest-facts', facts, {:target => vm.name.to_s})
40
+ @env.ui.info(JSON.pretty_generate(facts))
41
+ end
42
+
43
+ return 0
44
+ end
45
+
46
+ private
47
+
48
+ def parser
49
+ OptionParser.new do |o|
50
+ o.banner = <<-BANNER
51
+ Usage: vagrant pe-build facts [vm-name]
52
+ BANNER
53
+
54
+ o.separator ''
55
+
56
+ o.on('-h', '--help', 'Display this help') do
57
+ puts o
58
+ exit(0)
59
+ end
60
+ end
61
+ end
62
+
63
+ end
@@ -4,5 +4,6 @@ module PEBuild
4
4
  module Config
5
5
  require 'pe_build/config/global'
6
6
  require 'pe_build/config/pe_bootstrap'
7
+ require 'pe_build/config/pe_agent'
7
8
  end
8
9
  end
@@ -0,0 +1,120 @@
1
+ # Configuration for PE Agent provisioners
2
+ #
3
+ # @since 0.13.0
4
+ class PEBuild::Config::PEAgent < Vagrant.plugin('2', :config)
5
+ # The minimum PE Version supported by this provisioner.
6
+ MINIMUM_VERSION = '2015.2.0'
7
+
8
+ # @!attribute [rw] autosign
9
+ # If true, and {#master_vm} is set, the agent's certificate will be signed
10
+ # on the master VM.
11
+ #
12
+ # @return [true, false] Defaults to `true` if {#master_vm} is set,
13
+ # otherwise `false`.
14
+ attr_accessor :autosign
15
+
16
+ # @!attribute [rw] autopurge
17
+ # If true, and {#master_vm} is set, the agent's certificate and data will
18
+ # be purged from the master VM if the agent is destroyed by Vagrant.
19
+ #
20
+ # @return [true, false] Defaults to `true` if {#master_vm} is set,
21
+ # otherwise `false`.
22
+ attr_accessor :autopurge
23
+
24
+ # @!attribute master
25
+ # @return [String] The DNS hostname of the Puppet master for this node.
26
+ # If {#master_vm} is set, the hostname of that machine will be used
27
+ # as a default.
28
+ attr_accessor :master
29
+
30
+ # @!attribute master_vm
31
+ # @return [String] The name of a Vagrant VM to use as the master.
32
+ attr_accessor :master_vm
33
+
34
+ # @!attribute version
35
+ # @return [String] The version of PE to install. May be either a version
36
+ # string of the form `x.y.x[-optional-arbitrary-stuff]` or the string
37
+ # `current`. Defaults to `current`.
38
+ attr_accessor :version
39
+
40
+ def initialize
41
+ @autosign = UNSET_VALUE
42
+ @autopurge = UNSET_VALUE
43
+ @master = UNSET_VALUE
44
+ @master_vm = UNSET_VALUE
45
+ @version = UNSET_VALUE
46
+ end
47
+
48
+ def finalize!
49
+ @master = nil if @master == UNSET_VALUE
50
+ @master_vm = nil if @master_vm == UNSET_VALUE
51
+ @autosign = (not @master_vm.nil?) if @autosign == UNSET_VALUE
52
+ @autopurge = (not @master_vm.nil?) if @autopurge == UNSET_VALUE
53
+ @version = 'current' if @version == UNSET_VALUE
54
+ end
55
+
56
+ def validate(machine)
57
+ errors = _detected_errors
58
+
59
+ if @master.nil? && @master_vm.nil?
60
+ errors << I18n.t('pebuild.config.pe_agent.errors.no_master')
61
+ end
62
+
63
+ validate_master_vm!(errors, machine)
64
+ validate_version!(errors, machine)
65
+
66
+ {'pe_agent provisioner' => errors}
67
+ end
68
+
69
+ private
70
+
71
+ def validate_master_vm!(errors, machine)
72
+ if (not @master_vm.nil?) && (not machine.env.machine_names.include?(@master_vm.intern))
73
+ errors << I18n.t(
74
+ 'pebuild.config.pe_agent.errors.master_vm_not_defined',
75
+ :vm_name => @master_vm
76
+ )
77
+ end
78
+
79
+ if @autosign && @master_vm.nil?
80
+ errors << I18n.t(
81
+ 'pebuild.config.pe_agent.errors.master_vm_required',
82
+ :setting => 'autosign'
83
+ )
84
+ end
85
+
86
+ if @autopurge && @master_vm.nil?
87
+ errors << I18n.t(
88
+ 'pebuild.config.pe_agent.errors.master_vm_required',
89
+ :setting => 'autopurge'
90
+ )
91
+ end
92
+ end
93
+
94
+ def validate_version!(errors, machine)
95
+ pe_version_regex = %r[\d+\.\d+\.\d+[\w-]*]
96
+
97
+ if @version.kind_of? String
98
+ return if version == 'current'
99
+ if version.match(pe_version_regex)
100
+ unless PEBuild::Util::VersionString.compare(@version, MINIMUM_VERSION) > 0
101
+ errors << I18n.t(
102
+ 'pebuild.config.pe_agent.errors.version_too_old',
103
+ :version => @version,
104
+ :minimum_version => MINIMUM_VERSION
105
+ )
106
+ end
107
+
108
+ return
109
+ end
110
+ end
111
+
112
+ # If we end up here, the version was not a string that matched 'current' or
113
+ # the regex. Mutate the error array.
114
+ errors << I18n.t(
115
+ 'pebuild.config.pe_agent.errors.malformed_version',
116
+ :version => @version,
117
+ :version_class => @version.class
118
+ )
119
+ end
120
+ end
@@ -2,5 +2,6 @@ module PEBuild
2
2
  module ConfigBuilder
3
3
  require 'pe_build/config_builder/global'
4
4
  require 'pe_build/config_builder/pe_bootstrap'
5
+ require 'pe_build/config_builder/pe_agent'
5
6
  end
6
7
  end
@@ -0,0 +1,44 @@
1
+ require 'config_builder/model'
2
+
3
+ # @since 0.13.0
4
+ class PEBuild::ConfigBuilder::PEAgent < ::ConfigBuilder::Model::Base
5
+ # @!attribute [rw] autosign
6
+ # If true, and {#master_vm} is set, the agent's certificate will be signed
7
+ # on the master VM.
8
+ #
9
+ # @return [true, false] Defaults to `true` if {#master_vm} is set,
10
+ # otherwise `false`.
11
+ def_model_attribute :autosign
12
+ # @!attribute [rw] autopurge
13
+ # If true, and {#master_vm} is set, the agent's certificate and data will
14
+ # be purged from the master VM if the agent is destroyed by Vagrant.
15
+ #
16
+ # @return [true, false] Defaults to `true` if {#master_vm} is set,
17
+ # otherwise `false`.
18
+ def_model_attribute :autopurge
19
+ # @!attribute master
20
+ # @return [String] The DNS hostname of the Puppet master for this node.
21
+ def_model_attribute :master
22
+ # @!attribute master_vm
23
+ # @return [String] The name of a Vagrant VM to use as the master.
24
+ def_model_attribute :master_vm
25
+ # @!attribute version
26
+ # @return [String] The version of PE to install. May be either a version
27
+ # string of the form `x.y.x[-optional-arbitrary-stuff]` or the string
28
+ # `current`. Defaults to `current`.
29
+ def_model_attribute :version
30
+
31
+ def to_proc
32
+ Proc.new do |vm_config|
33
+ vm_config.provision :pe_agent do |config|
34
+ with_attr(:autosign) {|val| config.autosign = val }
35
+ with_attr(:autopurge) {|val| config.autopurge = val }
36
+ with_attr(:master) {|val| config.master = val }
37
+ with_attr(:master_vm) {|val| config.master_vm = val }
38
+ with_attr(:version) {|val| config.version = val }
39
+ end
40
+ end
41
+ end
42
+
43
+ ::ConfigBuilder::Model::Provisioner.register('pe_agent', self)
44
+ end