vagrant-registration 0.0.17 → 0.0.18

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 (61) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +4 -2
  3. data/README.md +7 -1
  4. data/lib/vagrant-registration/action.rb +10 -3
  5. data/lib/vagrant-registration/action/register.rb +12 -2
  6. data/lib/vagrant-registration/action/unregister_on_destroy.rb +56 -0
  7. data/lib/vagrant-registration/action/unregister_on_halt.rb +57 -0
  8. data/lib/vagrant-registration/config.rb +2 -0
  9. data/lib/vagrant-registration/plugin.rb +9 -4
  10. data/lib/vagrant-registration/version.rb +1 -1
  11. data/plugins/guests/redhat/cap/registration.rb +10 -0
  12. data/plugins/guests/redhat/cap/subscription_manager.rb +7 -0
  13. data/plugins/guests/redhat/plugin.rb +10 -0
  14. data/vagrant-registration-0.0.16/.gitignore +34 -0
  15. data/vagrant-registration-0.0.16/CHANGELOG.md +3 -0
  16. data/vagrant-registration-0.0.16/Gemfile +9 -0
  17. data/vagrant-registration-0.0.16/LICENSE.md +339 -0
  18. data/vagrant-registration-0.0.16/README.md +149 -0
  19. data/vagrant-registration-0.0.16/Rakefile +25 -0
  20. data/vagrant-registration-0.0.16/Vagrantfile +44 -0
  21. data/vagrant-registration-0.0.16/dummy.box +0 -0
  22. data/vagrant-registration-0.0.16/lib/vagrant-registration.rb +21 -0
  23. data/vagrant-registration-0.0.16/lib/vagrant-registration/action.rb +22 -0
  24. data/vagrant-registration-0.0.16/lib/vagrant-registration/action/register.rb +113 -0
  25. data/{lib → vagrant-registration-0.0.16/lib}/vagrant-registration/action/unregister.rb +0 -0
  26. data/vagrant-registration-0.0.16/lib/vagrant-registration/config.rb +39 -0
  27. data/vagrant-registration-0.0.16/lib/vagrant-registration/plugin.rb +74 -0
  28. data/vagrant-registration-0.0.16/lib/vagrant-registration/version.rb +5 -0
  29. data/vagrant-registration-0.0.16/plugins/guests/redhat/cap/registration.rb +72 -0
  30. data/vagrant-registration-0.0.16/plugins/guests/redhat/cap/subscription_manager.rb +63 -0
  31. data/vagrant-registration-0.0.16/plugins/guests/redhat/plugin.rb +62 -0
  32. data/vagrant-registration-0.0.16/tests/helpers.sh +128 -0
  33. data/vagrant-registration-0.0.16/tests/run.sh +59 -0
  34. data/vagrant-registration-0.0.16/tests/vagrantfiles/Vagrantfile.rhel_multi_machine +19 -0
  35. data/vagrant-registration-0.0.16/tests/vagrantfiles/Vagrantfile.rhel_wrong_credentials +14 -0
  36. data/vagrant-registration-0.0.16/vagrant-registration.gemspec +49 -0
  37. data/vagrant-registration-0.0.17/.gitignore +34 -0
  38. data/vagrant-registration-0.0.17/CHANGELOG.md +3 -0
  39. data/vagrant-registration-0.0.17/Gemfile +9 -0
  40. data/vagrant-registration-0.0.17/LICENSE.md +339 -0
  41. data/vagrant-registration-0.0.17/README.md +149 -0
  42. data/vagrant-registration-0.0.17/Rakefile +25 -0
  43. data/vagrant-registration-0.0.17/Vagrantfile +44 -0
  44. data/vagrant-registration-0.0.17/dummy.box +0 -0
  45. data/vagrant-registration-0.0.17/lib/vagrant-registration.rb +21 -0
  46. data/vagrant-registration-0.0.17/lib/vagrant-registration/action.rb +22 -0
  47. data/vagrant-registration-0.0.17/lib/vagrant-registration/action/register.rb +113 -0
  48. data/vagrant-registration-0.0.17/lib/vagrant-registration/action/unregister.rb +56 -0
  49. data/vagrant-registration-0.0.17/lib/vagrant-registration/config.rb +39 -0
  50. data/vagrant-registration-0.0.17/lib/vagrant-registration/plugin.rb +74 -0
  51. data/vagrant-registration-0.0.17/lib/vagrant-registration/version.rb +5 -0
  52. data/vagrant-registration-0.0.17/plugins/guests/redhat/cap/registration.rb +72 -0
  53. data/vagrant-registration-0.0.17/plugins/guests/redhat/cap/subscription_manager.rb +63 -0
  54. data/vagrant-registration-0.0.17/plugins/guests/redhat/plugin.rb +62 -0
  55. data/vagrant-registration-0.0.17/tests/helpers.sh +128 -0
  56. data/vagrant-registration-0.0.17/tests/run.sh +59 -0
  57. data/vagrant-registration-0.0.17/tests/vagrantfiles/Vagrantfile.rhel_multi_machine +19 -0
  58. data/vagrant-registration-0.0.17/tests/vagrantfiles/Vagrantfile.rhel_wrong_credentials +14 -0
  59. data/vagrant-registration-0.0.17/vagrant-registration.gemspec +49 -0
  60. data/vagrant-registration-0.0.17/vagrant-registration.spec +90 -0
  61. metadata +93 -45
@@ -0,0 +1,25 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'yard'
3
+
4
+ # Documentation
5
+ YARD::Rake::YardocTask.new do |t|
6
+ t.files = ['lib/**/*.rb', 'plugins/**/*.rb']
7
+ t.options = []
8
+ t.stats_options = ['--list-undoc']
9
+ end
10
+
11
+ task :clean do
12
+ `rm -rf pkg`
13
+ end
14
+
15
+ # Compare latest release with current git head
16
+ require 'rubygems/comparator'
17
+ task compare: [:clean, :build] do
18
+ git_version = VagrantPlugins::Registration::VERSION
19
+ options = {}
20
+ options[:output] = 'pkg'
21
+ options[:keep_all] = true
22
+ comparator = Gem::Comparator.new(options)
23
+ comparator.compare_versions('vagrant-registration', ['_', git_version])
24
+ comparator.print_results
25
+ end
@@ -0,0 +1,44 @@
1
+ # BEING USED FOR TESTING, REMOVE BEFORE RELEASE
2
+ #
3
+ # -*- mode: ruby -*-
4
+ # vi: set ft=ruby :
5
+
6
+ Vagrant.configure('2') do |config|
7
+ # Example configuration of new VM..
8
+ config.vm.define :default do |vagrant_host|
9
+ # Box name
10
+ vagrant_host.vm.box = 'rhel-7.0'
11
+
12
+ # Domain Specific Options
13
+ vagrant_host.vm.provider :libvirt do |domain|
14
+ domain.memory = 2048
15
+ domain.cpus = 1
16
+ end
17
+
18
+ config.vm.synced_folder './', '/vagrant', type: 'rsync'
19
+
20
+ # vagrant_host.vm.network :private_network,
21
+ # :libvirt__network_name => 'either_nat'
22
+
23
+ end
24
+
25
+ # config.vm.provision "ansible" do |ansible|
26
+ # ansible.playbook = "playbook.yml"
27
+ # ansible.extra_vars = "vagrant-config.yml"
28
+ # end
29
+
30
+ # config.vm.provision "ansible" do |ansible|
31
+ # ansible.playbook = "playbook.yml"
32
+ # ansible.extra_vars = "vagrant-config.yml"
33
+ # ansible.sudo = "true"
34
+ # end
35
+
36
+ # Options for libvirt vagrant provider.
37
+ config.vm.provider :libvirt do |libvirt|
38
+ libvirt.driver = 'kvm'
39
+ libvirt.connect_via_ssh = false
40
+ libvirt.username = 'root'
41
+ libvirt.storage_pool_name = 'mnt_vms'
42
+ end
43
+ end
44
+
@@ -0,0 +1,21 @@
1
+ require "pathname"
2
+
3
+ require "vagrant-registration/plugin"
4
+
5
+ module VagrantPlugins
6
+ module Registration
7
+ lib_path = Pathname.new(File.expand_path("../vagrant-registration", __FILE__))
8
+ autoload :Action, lib_path.join("action")
9
+ #autoload :Errors, lib_path.join("errors")
10
+
11
+ # This returns the path to the source of this plugin.
12
+ #
13
+ # @return [Pathname]
14
+ def self.source_root
15
+ @source_root ||= Pathname.new(File.expand_path("../../", __FILE__))
16
+ end
17
+
18
+ # Temporally load the extra capability files for Red Hat
19
+ load(File.join(self.source_root, 'plugins/guests/redhat/plugin.rb'))
20
+ end
21
+ end
@@ -0,0 +1,22 @@
1
+ module VagrantPlugins
2
+ module Registration
3
+ module Action
4
+
5
+ def self.action_register
6
+ Vagrant::Action::Builder.new.tap do |b|
7
+ b.use Register
8
+ end
9
+ end
10
+
11
+ def self.action_unregister
12
+ Vagrant::Action::Builder.new.tap do |b|
13
+ b.use Unregister
14
+ end
15
+ end
16
+
17
+ action_root = Pathname.new(File.expand_path("../action", __FILE__))
18
+ autoload :Register, action_root.join("register")
19
+ autoload :Unregister, action_root.join("unregister")
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,113 @@
1
+ require "log4r"
2
+
3
+ module VagrantPlugins
4
+ module Registration
5
+ module Action
6
+ # This registers the guest if the guest plugin supports it
7
+ class Register
8
+ def initialize(app, env)
9
+ @app = app
10
+ @logger = Log4r::Logger.new("vagrant_registration::action::register")
11
+ end
12
+
13
+ def call(env)
14
+ @app.call(env)
15
+
16
+ # Configuration from Vagrantfile
17
+ config = env[:machine].config.registration
18
+ machine = env[:machine]
19
+ guest = env[:machine].guest
20
+
21
+ if capabilities_provided?(guest) && manager_installed?(guest) && !config.skip
22
+ env[:ui].info("Registering box with vagrant-registration...")
23
+
24
+ unless credentials_provided? machine
25
+ @logger.debug("Credentials for registration not provided")
26
+
27
+ # Offer to register ATM or skip
28
+ register_now = env[:ui].ask("Would you like to register the system now (default: yes)? [y|n] ")
29
+
30
+ if register_now == 'n'
31
+ config.skip = true
32
+ else
33
+ config = register_on_screen(machine, env[:ui])
34
+ end
35
+ end
36
+ guest.capability(:registration_register) unless config.skip
37
+ end
38
+
39
+ @logger.debug("Registration is skipped due to the configuration") if config.skip
40
+ end
41
+
42
+ private
43
+
44
+ # Check if registration capabilities are available
45
+ def capabilities_provided?(guest)
46
+ if guest.capability?(:registration_register) && guest.capability?(:registration_manager_installed)
47
+ true
48
+ else
49
+ @logger.debug("Registration is skipped due to the missing guest capability")
50
+ false
51
+ end
52
+ end
53
+
54
+ # Check if selected registration manager is installed
55
+ def manager_installed?(guest)
56
+ if guest.capability(:registration_manager_installed)
57
+ true
58
+ else
59
+ @logger.debug("Registration manager not found on guest")
60
+ false
61
+ end
62
+ end
63
+
64
+ # Fetch required credentials for selected manager
65
+ def credentials_required(machine)
66
+ if machine.guest.capability?(:registration_credentials)
67
+ machine.guest.capability(:registration_credentials)
68
+ else
69
+ []
70
+ end
71
+ end
72
+
73
+ # Secret options for selected manager
74
+ def secrets(machine)
75
+ if machine.guest.capability?(:registration_secrets)
76
+ machine.guest.capability(:registration_secrets)
77
+ else
78
+ []
79
+ end
80
+ end
81
+
82
+ # Check if required credentials has been provided in Vagrantfile
83
+ #
84
+ # Checks if at least one of the registration options is able to
85
+ # register.
86
+ def credentials_provided?(machine)
87
+ provided = true
88
+ credentials_required(machine).each do |registration_option|
89
+ provided = true
90
+ registration_option.each do |value|
91
+ provided = false unless machine.config.registration.send value
92
+ end
93
+ break if provided
94
+ end
95
+ provided ? true : false
96
+ end
97
+
98
+ # Ask user on required credentials and return them,
99
+ # skip options that are provided by Vagrantfile
100
+ def register_on_screen(machine, ui)
101
+ credentials_required(machine)[0].each do |option|
102
+ unless machine.config.registration.send(option)
103
+ echo = !(secrets(machine).include? option)
104
+ response = ui.ask("#{option}: ", echo: echo)
105
+ machine.config.registration.send("#{option.to_s}=".to_sym, response)
106
+ end
107
+ end
108
+ machine.config.registration
109
+ end
110
+ end
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,56 @@
1
+ require "log4r"
2
+
3
+ module VagrantPlugins
4
+ module Registration
5
+ module Action
6
+ # This unregisters the guest if the guest has registration capability
7
+ class Unregister
8
+ def initialize(app, env)
9
+ @app = app
10
+ @logger = Log4r::Logger.new("vagrant_registration::action::unregister")
11
+ end
12
+
13
+ def call(env)
14
+ config = env[:machine].config.registration
15
+ guest = env[:machine].guest
16
+
17
+ if capabilities_provided?(guest) && manager_installed?(guest) && !config.skip
18
+ env[:ui].info("Unregistering box with vagrant-registration...")
19
+ guest.capability(:registration_unregister)
20
+ end
21
+
22
+ @logger.debug("Unregistration is skipped due to the configuration") if config.skip
23
+ @app.call(env)
24
+
25
+ # Guest might not be available after halting, so log the exception and continue
26
+ rescue => e
27
+ @logger.info(e)
28
+ @logger.debug("Guest is not available, ignore unregistration")
29
+ @app.call(env)
30
+ end
31
+
32
+ private
33
+
34
+ # Check if registration capabilities are available
35
+ def capabilities_provided?(guest)
36
+ if guest.capability?(:registration_unregister) && guest.capability?(:registration_manager_installed)
37
+ true
38
+ else
39
+ @logger.debug("Unregistration is skipped due to the missing guest capability")
40
+ false
41
+ end
42
+ end
43
+
44
+ # Check if selected registration manager is installed
45
+ def manager_installed?(guest)
46
+ if guest.capability(:registration_manager_installed)
47
+ true
48
+ else
49
+ @logger.debug("Registration manager not found on guest")
50
+ false
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,39 @@
1
+ require "vagrant"
2
+ require "ostruct"
3
+
4
+ module VagrantPlugins
5
+ module Registration
6
+ class Config < Vagrant.plugin("2", :config)
7
+ def initialize(region_specific=false)
8
+ @conf = UNSET_VALUE
9
+ @logger = Log4r::Logger.new("vagrant_registration::config")
10
+ end
11
+
12
+ def finalize!
13
+ get_config
14
+ @conf.skip = false unless @conf.skip
15
+ @logger.info "Final registration configuration: #{@conf.inspect}"
16
+ end
17
+
18
+ def method_missing(method_sym, *arguments, &block)
19
+ get_config
20
+ command = "@conf.#{method_sym} #{adjust_arguments(arguments)}"
21
+ @logger.info "Evaluating registration configuration: #{command}"
22
+ eval command
23
+ end
24
+
25
+ private
26
+
27
+ # Don't set @conf to OpenStruct in initialize
28
+ # to preserve config hierarchy
29
+ def get_config
30
+ @conf = OpenStruct.new if @conf == UNSET_VALUE
31
+ end
32
+
33
+ def adjust_arguments(args)
34
+ return '' if args.size < 1
35
+ args.map{|a| a.is_a?(String) ? "'#{a}'" : a}.join(',')
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,74 @@
1
+ begin
2
+ require 'vagrant'
3
+ rescue LoadError
4
+ raise 'The vagrant-registration plugin must be run within Vagrant.'
5
+ end
6
+
7
+ # This is a sanity check to make sure no one is attempting to install
8
+ # this into an early Vagrant version.
9
+ if Vagrant::VERSION < "1.2.0"
10
+ raise "The Vagrant RHEL plugin is only compatible with Vagrant 1.2+"
11
+ end
12
+
13
+ module VagrantPlugins
14
+ module Registration
15
+ class Plugin < Vagrant.plugin("2")
16
+ class << self
17
+ def register(hook)
18
+ setup_logging
19
+ hook.after(::Vagrant::Action::Builtin::SyncedFolders,
20
+ VagrantPlugins::Registration::Action.action_register)
21
+ end
22
+
23
+ def unregister(hook)
24
+ setup_logging
25
+ hook.prepend(VagrantPlugins::Registration::Action.action_unregister)
26
+ end
27
+ end
28
+
29
+ name "Registration"
30
+ description <<-DESC
31
+ This plugin adds register and unregister functionality to Vagrant Guests that
32
+ support the capability
33
+ DESC
34
+
35
+ action_hook(:registration_register, :machine_action_up, &method(:register))
36
+ action_hook(:registration_register, :machine_action_provision, &method(:register))
37
+ action_hook(:registration_unregister, :machine_action_halt, &method(:unregister))
38
+ action_hook(:registration_unregister, :machine_action_destroy, &method(:unregister))
39
+
40
+ config(:registration) do
41
+ setup_logging
42
+ require_relative 'config'
43
+ Config
44
+ end
45
+
46
+ # This sets up our log level to be whatever VAGRANT_LOG is
47
+ # for loggers prepended with 'vagrant_registration'
48
+ def self.setup_logging
49
+ require 'log4r'
50
+ level = nil
51
+ begin
52
+ level = Log4r.const_get(ENV['VAGRANT_LOG'].upcase)
53
+ rescue NameError
54
+ # This means that the logging constant wasn't found,
55
+ # which is fine. We just keep `level` as `nil`. But
56
+ # we tell the user.
57
+ level = nil
58
+ end
59
+ # Some constants, such as "true" resolve to booleans, so the
60
+ # above error checking doesn't catch it. This will check to make
61
+ # sure that the log level is an integer, as Log4r requires.
62
+ level = nil if !level.is_a?(Integer)
63
+ # Set the logging level on all "vagrant" namespaced
64
+ # logs as long as we have a valid level.
65
+ if level
66
+ logger = Log4r::Logger.new('vagrant_registration')
67
+ logger.outputters = Log4r::Outputter.stderr
68
+ logger.level = level
69
+ logger = nil
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,5 @@
1
+ module VagrantPlugins
2
+ module Registration
3
+ VERSION = "0.0.17"
4
+ end
5
+ end
@@ -0,0 +1,72 @@
1
+ module VagrantPlugins
2
+ module GuestRedHat
3
+ module Cap
4
+ # This provides registration capabilities for vagrant-registration
5
+ #
6
+ # As we might support more registration options (managers), this
7
+ # just calls the capabilities of the selected registration manager
8
+ # (from config.registration.manager).
9
+ class Registration
10
+ # Register the given machine
11
+ def self.registration_register(machine)
12
+ cap = "#{self.registration_manager(machine).to_s}_register".to_sym
13
+ if machine.guest.capability?(cap)
14
+ machine.guest.capability(cap, machine.config.registration)
15
+ else
16
+ false
17
+ end
18
+ end
19
+
20
+ # Unregister the given machine
21
+ def self.registration_unregister(machine)
22
+ cap = "#{self.registration_manager(machine).to_s}_unregister".to_sym
23
+ if machine.guest.capability?(cap)
24
+ machine.guest.capability(cap)
25
+ else
26
+ false
27
+ end
28
+ end
29
+
30
+ # Check that the machine has the selected registration manager installed
31
+ def self.registration_manager_installed(machine)
32
+ cap = "#{self.registration_manager(machine).to_s}".to_sym
33
+ if machine.guest.capability?(cap)
34
+ machine.guest.capability(cap)
35
+ else
36
+ false
37
+ end
38
+ end
39
+
40
+ # Required configuration options of the registration manager
41
+ #
42
+ # This is array of arrays of all possible registration combinations.
43
+ # First one is the default used in interactive mode.
44
+ #
45
+ # e.g. [[:username, :password]]
46
+ def self.registration_credentials(machine)
47
+ cap = "#{self.registration_manager(machine).to_s}_credentials".to_sym
48
+ if machine.guest.capability?(cap)
49
+ machine.guest.capability(cap)
50
+ else
51
+ []
52
+ end
53
+ end
54
+
55
+ # Return secret options for the registration manager
56
+ def self.registration_secrets(machine)
57
+ cap = "#{self.registration_manager(machine).to_s}_secrets".to_sym
58
+ if machine.guest.capability?(cap)
59
+ machine.guest.capability(cap)
60
+ else
61
+ []
62
+ end
63
+ end
64
+
65
+ # Return selected registration manager or default
66
+ def self.registration_manager(machine)
67
+ (machine.config.registration.manager || 'subscription_manager').to_sym
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end