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,149 @@
1
+ # vagrant-registration
2
+
3
+ vagrant-registration plugin for Vagrant allows developers to easily register their guests for updates on systems with a subscription model (like Red Hat Enterprise Linux).
4
+
5
+ This plugin would run *register* action on `vagrant up` before any provisioning and *unregister* on `vagrant halt` or `vagrant destroy`. The actions then call the registration capabilities that have to be provided for given OS.
6
+
7
+
8
+ ## Installation
9
+
10
+ Install vagrant-registration as any other Vagrant plugin:
11
+
12
+ ```shell
13
+ $ vagrant plugin install vagrant-registration
14
+ ```
15
+
16
+ If you are on Fedora, you can install the packaged version of the plugin by running:
17
+
18
+ ```shell
19
+ # dnf install vagrant-registration
20
+ ```
21
+
22
+ ## Usage
23
+
24
+ The plugin is designed in an registration-manager-agnostic way which means that plugin itself does not depend on any OS nor way of registration. vagrant-registration only calls registration capabilities for given guest, passes the configuration options to them and handles interactive registration.
25
+
26
+ That being said, this plugin currently ships only with registration capability files for RHEL's Subscription Manager. Feel free to submit others.
27
+
28
+ *Note:* This plugin is still alpha. Please help us to find and fix any bugs.
29
+
30
+ ### Plugin Configuration
31
+
32
+ - **skip**: If you wish to skip the registration process altogether, you can do so by setting a `skip` option to `true`:
33
+
34
+ ```ruby
35
+ config.registration.skip = true
36
+ ```
37
+
38
+ ### subscription-manager Configuration
39
+
40
+ vagrant-registration supports all the options of subscription-manager's register command.
41
+ You can set any option easily by setting `config.registration.OPTION_NAME = 'OPTION_VALUE'`
42
+ in your Vagrantfile (please see the subscription-manager's documentation for option
43
+ description).
44
+
45
+ Setting up the credentials can be done as follows:
46
+
47
+ ```ruby
48
+ if Vagrant.has_plugin?('vagrant-registration')
49
+ config.registration.username = 'foo'
50
+ config.registration.password = 'bar'
51
+ end
52
+
53
+ # Alternatively
54
+ if Vagrant.has_plugin?('vagrant-registration')
55
+ config.registration.org = 'foo'
56
+ config.registration.activationkey = 'bar'
57
+ end
58
+ ```
59
+
60
+ This should go, preferably, into the Vagrantfile in your Vagrant home directory
61
+ (defaults to ~/.vagrant.d), to make it available for every project. It can be
62
+ later overridden in an individual project's Vagrantfile if needed.
63
+
64
+ If you prefer not to store your username and/or password on your filesystem,
65
+ you can optionally configure vagrant-registration plugin to use environment
66
+ variables, such as:
67
+
68
+ ```ruby
69
+ config.registration.username = ENV['SUB_USERNAME']
70
+ config.registration.password = ENV['SUB_PASSWORD']
71
+ ```
72
+
73
+ If you do not provide credentials, you will be prompted for them in the "up process."
74
+
75
+ Please note the the interactive mode asks you for the preferred registration pair only.
76
+ In case of a subscription-manager, you would be ask on your username/password combination.
77
+
78
+ #### subscription-manager Default Options
79
+
80
+ - **--force**: Subscription Manager will fail if you attempt to register an already registered machine (see the man page for explanation), therefore vagrant-registration appends the `--force` flag automatically when subscribing. If you would like to disable this feature, set `force` option to `false`:
81
+
82
+ ```ruby
83
+ config.registration.force = false
84
+ ```
85
+ - **--auto-attach**: Vagrant would fail to install packages on registered RHEL system if the subscription is not attached, therefore vagrant-registration appends the
86
+ `--auto-attach` flag automatically when subscribing. To disable this option, set `auto_attach` option to `false`:
87
+
88
+
89
+ ```ruby
90
+ config.registration.auto_attach = false
91
+ ```
92
+
93
+ Note that the `auto_attach` option is set to false when using org/activationkey for registration.
94
+
95
+ #### subscription-manager Options Reference
96
+
97
+ ```ruby
98
+ # The username to subscribe with (required)
99
+ config.registration.username
100
+
101
+ # The password of the subscriber (required)
102
+ config.registration.password
103
+
104
+ # Give the hostname of the subscription service to use (required for Subscription
105
+ # Asset Manager, defaults to Customer Portal Subscription Management)
106
+ config.registration.serverurl
107
+
108
+ # Give the hostname of the content delivery server to use to receive updates
109
+ # (required for Satellite 6)
110
+ config.registration.baseurl
111
+
112
+ # Give the organization to which to join the system (required, except for
113
+ # hosted environments)
114
+ config.registration.org
115
+
116
+ # Register the system to an environment within an organization (optional)
117
+ config.registration.environment
118
+
119
+ # Name of the subscribed system (optional, defaults to hostname if unset)
120
+ config.registration.name
121
+
122
+ # Auto attach suitable subscriptions (optional, auto attach if true,
123
+ # defaults to true)
124
+ config.registration.auto_attach
125
+
126
+ # Attach existing subscriptions as part of the registration process (optional)
127
+ config.registration.activationkey
128
+
129
+ # Set the service level to use for subscriptions on that machine
130
+ # (optional, used only used with the --auto-attach)
131
+ config.registration.servicelevel
132
+
133
+ # Set the operating system minor release to use for subscriptions for
134
+ # the system (optional, used only used with the --auto-attach)
135
+ config.registration.release
136
+
137
+ # Force the registration (optional, force if true, defaults to true)
138
+ config.registration.force
139
+
140
+ # Set what type of consumer is being registered (optional, defaults to system)
141
+ config.registration.type
142
+
143
+ # Skip the registration (optional, skip if true, defaults to false)
144
+ config.registration.skip
145
+ ```
146
+
147
+ ## Acknowledgements
148
+
149
+ The project would like to make sure we thank [purpleidea](https://github.com/purpleidea/), [humaton](https://github.com/humaton/), [strzibny](https://github.com/strzibny), [scollier](https://github.com/scollier/), [puzzle](https://github.com/puzzle), [voxik](https://github.com/voxik), [lukaszachy](https://github.com/lukaszachy) and [goern](https://github.com/goern) (in no particular order) for their contributions of ideas, code and testing for this project.
@@ -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,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