vagrant-registration 0.0.11 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e3a6618588af63c7852552cbf4e5ce79ab13d36a
4
- data.tar.gz: d3199ceda69643937bab2a8ba6266948a2ac601a
3
+ metadata.gz: 7d50591b44df73fbaf5754f6a5ad19b2d42116ab
4
+ data.tar.gz: f0414f8fa9bda6a5a74cefbd96f4c6315c888cb1
5
5
  SHA512:
6
- metadata.gz: 6af730ec5035dbcc216a0996f7761c7ef42883ca1f882614911a64c07a3e3b53909edf7ab411bfbc37e54467c9cb89eb36025fb9ad10553c0200cdb68a0dddfa
7
- data.tar.gz: 1dc370d37eb666c81f4c0f0b0cd1c606a46d825e0ddf9b6593b8197e0638541453334a351e8cbc398d7a8e3a8deea34e3ed33c82dc4d76c9054f9703add13761
6
+ metadata.gz: bfac4d465549f33f0798691dc2e7569d372b3bca7a6983f6fc373854cf5268f24dc8f50c86f5b4cef30a509cbbb0f638c1bd48afedc8f5531cc996b1352fdc01
7
+ data.tar.gz: ff6e8aab4cbb1882dfe7bd62168d42f39f03c3a744fff7155258f06ae40c8eb1cfb7a71aa08c51963ab99d49758c5432b461c46baa55f6887547f7d4fd9ac13d
data/README.md CHANGED
@@ -1,14 +1,14 @@
1
1
  # vagrant-registration
2
2
 
3
- The vagrant-registration plugin supports new capabilities "register" and "unregister." The "register" event occurs during the "up" process, immediately after startup but before any provisioning (including built-in like rsync). The "unregister" event occurs during the "halt" process (which also is called during the "destroy" process) immediately before the instances goes down.
4
-
5
- This allows developers to easily register their guests that use subscription model for updates, like Red Hat Enterprise Linux.
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).
6
4
 
5
+ This plugin would run *register* action on `vagrant up` before any provisioning
6
+ and *unregister* on `vagrant halt` or `vagrant destroy`. The actions then call the registration capabilities that have to be provided for given OS.
7
7
 
8
8
 
9
9
  ## Installation
10
10
 
11
- Install as any other Vagrant plugin:
11
+ Install vagrant-registration as any other Vagrant plugin:
12
12
 
13
13
  ```ruby
14
14
  vagrant plugin install vagrant-registration
@@ -16,9 +16,20 @@ vagrant plugin install vagrant-registration
16
16
 
17
17
  ## Usage
18
18
 
19
+ 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
20
+ interactive registration.
21
+
22
+ That being said, this plugin currently ships only with registration capability files for RHEL's Subscription Manager. Feel free to submit others.
23
+
19
24
  *Note:* This plugin is still alpha. Please help us to find and fix any bugs.
20
25
 
21
- - Only RHEL Subscription Manager is currectly supported.
26
+ ### Plugin Configuration
27
+
28
+ - **skip**: If you wish to skip the registration process altogether, you can do so by setting a `skip` option to `true`:
29
+
30
+ ```ruby
31
+ config.registration.skip = true
32
+ ```
22
33
 
23
34
  ### subscription-manager Configuration
24
35
 
@@ -30,8 +41,10 @@ description).
30
41
  Setting up the credentials can be done as follows:
31
42
 
32
43
  ```ruby
33
- config.registration.username = 'foo'
34
- config.registration.password = 'bar'
44
+ if Vagrant.has_plugin?('vagrant-registration')
45
+ config.registration.username = 'foo'
46
+ config.registration.password = 'bar'
47
+ end
35
48
  ```
36
49
 
37
50
  This should go, preferably, into the Vagrantfile in your Vagrant home directory
@@ -43,22 +56,79 @@ you can optionally configure vagrant-registration plugin to use environment
43
56
  variables, such as:
44
57
 
45
58
  ```ruby
46
- config.registration.username = ENV['SUB_USERNAME']
47
- config.registration.password = ENV['SUB_PASSWORD']
59
+ config.registration.username = ENV['SUB_USERNAME']
60
+ config.registration.password = ENV['SUB_PASSWORD']
48
61
  ```
49
62
 
50
- If you do not provide credentials, you will be prompted for them in the "up process". However, this is a tentative feature because if you are launching more than one VM from one Vagrantfile, the feature acts unexepectedly (appearing to hang because the prompt for creds gets lost in the scrollback).
63
+ If you do not provide credentials, you will be prompted for them in the "up process."
64
+
65
+ #### subscription-manager Default Options
66
+
67
+ - **--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`:
68
+
69
+ ```ruby
70
+ config.registration.force = false
71
+ ```
72
+ - **--auto-attach**: Vagrant would fail to install packages on registered RHEL system if the subscription is not attached, therefore vagrant-registration appends the
73
+ `--auto-attach` flag automatically when subscribing. To disable this option, set `auto_attach` option to `false`:
51
74
 
52
- You can also skip the registration process altogether by setting a `skip` option
53
- to `true`:
54
75
 
55
76
  ```ruby
56
- config.registration.skip = true
77
+ config.registration.auto_attach = false
57
78
  ```
58
79
 
59
- *Note:* RHEL Subscription Manager will fail if you attempt to register an already registered machine (see man page for explanation). Not to slow the boot time, vagrant-registration appends the "--force" flag when subscribing. If you would like to disable this feature, set `force` option to `false`:
80
+ #### subscription-manager Options Reference
60
81
 
61
82
  ```ruby
62
- config.registration.force = false
83
+ # The username to subscribe with (required)
84
+ config.registration.username
85
+
86
+ # The password of the subscriber (required)
87
+ config.registration.password
88
+
89
+ # Give the hostname of the subscription service to use (required for Subscription
90
+ # Asset Manager, defaults to Customer Portal Subscription Management)
91
+ config.registration.serverurl
92
+
93
+ # Give the hostname of the content delivery server to use to receive updates
94
+ # (required for Satellite 6)
95
+ config.registration.baseurl
96
+
97
+ # Give the organization to which to join the system (required, except for
98
+ # hosted environments)
99
+ config.registration.org
100
+
101
+ # Register the system to an environment within an organization (optional)
102
+ config.registration.environment
103
+
104
+ # Name of the subscribed system (optional, defaults to hostname if unset)
105
+ config.registration.name
106
+
107
+ # Auto attach suitable subscriptions (optional, auto attach if true,
108
+ # defaults to true)
109
+ config.registration.auto_attach
110
+
111
+ # Attach existing subscriptions as part of the registration process (optional)
112
+ config.registration.activationkey
113
+
114
+ # Set the service level to use for subscriptions on that machine
115
+ # (optional, used only used with the --auto-attach)
116
+ config.registration.servicelevel
117
+
118
+ # Set the operating system minor release to use for subscriptions for
119
+ # the system (optional, used only used with the --auto-attach)
120
+ config.registration.release
121
+
122
+ # Force the registration (optional, force if true, defaults to true)
123
+ config.registration.force
124
+
125
+ # Set what type of consumer is being registered (optional, defaults to system)
126
+ config.registration.type
127
+
128
+ # Skip the registration (optional, skip if true, defaults to false)
129
+ config.registration.skip
63
130
  ```
64
131
 
132
+ ## Acknowledgements
133
+
134
+ 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.
data/Rakefile CHANGED
@@ -1,2 +1,8 @@
1
1
  require "bundler/gem_tasks"
2
+ require 'yard'
2
3
 
4
+ YARD::Rake::YardocTask.new do |t|
5
+ t.files = ['lib/**/*.rb', 'plugins/**/*.rb']
6
+ t.options = []
7
+ t.stats_options = ['--list-undoc']
8
+ end
@@ -5,7 +5,6 @@ module VagrantPlugins
5
5
  module Action
6
6
  # This registers the guest if the guest plugin supports it
7
7
  class Register
8
-
9
8
  def initialize(app, env)
10
9
  @app = app
11
10
  @logger = Log4r::Logger.new("vagrant_registration::action::register")
@@ -13,56 +12,92 @@ module VagrantPlugins
13
12
 
14
13
  def call(env)
15
14
  @app.call(env)
15
+
16
+ # Configuration from Vagrantfile
16
17
  config = env[:machine].config.registration
18
+ machine = env[:machine]
17
19
  guest = env[:machine].guest
18
- @logger.info("Testing for registration_register capability on ")
19
20
 
20
- if guest.capability?(:register) && guest.capability?(:subscription_manager)
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")
21
26
 
22
- unless guest.capability(:subscription_manager)
23
- config.skip=true
24
- @logger.info("subscription-manager not found on guest")
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
25
35
  end
36
+ guest.capability(:registration_register) unless config.skip
37
+ end
26
38
 
27
- unless config.skip
28
- env[:ui].info("Registering box with vagrant-registration...")
39
+ @logger.debug("Registration is skipped due to the configuration") if config.skip
40
+ end
29
41
 
30
- # Check if credentials are provided, ask user if not
31
- unless credentials_provided? config
32
- @logger.debug("credentials for registration not provided")
42
+ private
33
43
 
34
- # Offer to register ATM or skip
35
- register_now = env[:ui].ask("Would you like to register the system now (default: yes)? [y|n] ")
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
+ return false
51
+ end
52
+ end
36
53
 
37
- if register_now == 'n'
38
- config.skip = true
39
- # Accept anything else as default
40
- else
41
- config.username, config.password = register_on_screen(env[:ui])
42
- end
43
- end
44
- @logger.info("Registration is forced") if config.force
45
- result = guest.capability(:register) unless config.skip
46
- else
47
- @logger.debug("registration skipped due to configuration")
48
- end
54
+ # Check if selected registration manager is installed
55
+ def manager_installed?(guest)
56
+ if guest.capability(:registration_manager_installed)
57
+ true
49
58
  else
50
- @logger.debug("registration skipped due to missing guest capability")
59
+ @logger.debug("Registration manager not found on guest")
60
+ false
51
61
  end
52
62
  end
53
63
 
54
- private
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
55
81
 
56
- # Ask user on username/password and return them
57
- def register_on_screen(ui)
58
- username = ui.ask("Subscriber username: ")
59
- password = ui.ask("Subscriber password: ", echo: false)
60
- [username, password]
82
+ # Check if required credentials has been provided in Vagrantfile
83
+ def credentials_provided?(machine)
84
+ credentials_required(machine).each do |option|
85
+ return false unless machine.config.registration.send option
86
+ end
87
+ true
61
88
  end
62
89
 
63
- # Check if username and password has been provided in Vagrantfile
64
- def credentials_provided?(config)
65
- config.username && config.password
90
+ # Ask user on required credentials and return them,
91
+ # skip options that are provided by Vagrantfile
92
+ def register_on_screen(machine, ui)
93
+ credentials_required(machine).each do |option|
94
+ unless machine.config.registration.send(option)
95
+ echo = !(secrets(machine).include? option)
96
+ response = ui.ask("#{option}: ", echo: echo)
97
+ machine.config.registration.send("#{option.to_s}=".to_sym, response)
98
+ end
99
+ end
100
+ machine.config.registration
66
101
  end
67
102
  end
68
103
  end
@@ -3,38 +3,53 @@ require "log4r"
3
3
  module VagrantPlugins
4
4
  module Registration
5
5
  module Action
6
- # This unregisters the guest if the guest plugin supports it
6
+ # This unregisters the guest if the guest has registration capability
7
7
  class Unregister
8
-
9
8
  def initialize(app, env)
10
9
  @app = app
11
10
  @logger = Log4r::Logger.new("vagrant_registration::action::unregister")
12
11
  end
13
12
 
14
13
  def call(env)
14
+ config = env[:machine].config.registration
15
15
  guest = env[:machine].guest
16
16
 
17
- if guest.capability?(:unregister) && guest.capability?(:subscription_manager)
18
- if !env[:machine].config.registration.skip
19
- env[:ui].info("Unregistering box with vagrant-registration...")
20
- @logger.info("registration_unregister capability exists on ")
21
- result = guest.capability(:unregister)
22
- @logger.info("called registration_unregister capability on ")
23
- else
24
- @logger.debug("unregistration is skipped due to configuration")
25
- end
26
- else
27
- @logger.debug("unregistration is skipped due to missing guest capability")
17
+ if capabilities_provided?(guest) && manager_installed?(guest) && !config.skip
18
+ env[:ui].info("Unregistering box with vagrant-registration...")
19
+ guest.capability(:registration_unregister)
28
20
  end
29
21
 
22
+ @logger.debug("Unregistration is skipped due to the configuration") if config.skip
30
23
  @app.call(env)
31
24
 
32
25
  # Guest might not be available after halting, so log the exception and continue
33
26
  rescue => e
34
27
  @logger.info(e)
35
- @logger.debug("guest is not available, ignore unregistration")
28
+ @logger.debug("Guest is not available, ignore unregistration")
36
29
  @app.call(env)
37
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
+ return 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
38
53
  end
39
54
  end
40
55
  end
@@ -1,122 +1,31 @@
1
1
  require "vagrant"
2
+ require "ostruct"
2
3
 
3
4
  module VagrantPlugins
4
5
  module Registration
5
6
  class Config < Vagrant.plugin("2", :config)
6
- # The username to subscribe with (required)
7
- #
8
- # @return [String]
9
- attr_accessor :username
10
- attr_accessor :subscriber_username # to stay backwards compatible
11
-
12
- # The password of the subscriber (required)
13
- #
14
- # @return [String]
15
- attr_accessor :password
16
- attr_accessor :subscriber_password # to stay backwards compatible
17
-
18
- # Give the hostname of the subscription service to use (required for Subscription
19
- # Asset Manager, defaults to Customer Portal Subscription Management)
20
- #
21
- # @return [String]
22
- attr_accessor :serverurl
23
-
24
- # Give the hostname of the content delivery server to use to receive updates
25
- # (required for Satellite 6)
26
- #
27
- # @return [String]
28
- attr_accessor :baseurl
29
-
30
- # Give the organization to which to join the system (required, except for
31
- # hosted environments)
32
- #
33
- # @return [String]
34
- attr_accessor :org
35
-
36
- # Register the system to an environment within an organization (optional)
37
- #
38
- # @return [String]
39
- attr_accessor :environment
40
-
41
- # Name of the subscribed system (optional, defaults to hostname if unset)
42
- #
43
- # @return [String]
44
- attr_accessor :name
45
-
46
- # Auto attach suitable subscriptions (optional, auto attach if true)
47
- #
48
- # @return [Bool]
49
- attr_accessor :auto_attach
50
-
51
- # Attach existing subscriptions as part of the registration process (optional)
52
- #
53
- # @return [String]
54
- attr_accessor :activationkey
55
-
56
- # Set the service level to use for subscriptions on that machine
57
- # (optional, used only used with the --auto-attach)
58
- #
59
- # @return [String]
60
- attr_accessor :servicelevel
61
-
62
- # Set the operating system minor release to use for subscriptions for
63
- # the system (optional, used only used with the --auto-attach)
64
- #
65
- # @return [String]
66
- attr_accessor :release
67
-
68
- # Force the registration (optional, force if true, defaults to true)
69
- #
70
- # @return [Bool]
71
- attr_accessor :force
72
-
73
- # Set what type of consumer is being registered (optional, defaults to system)
74
- #
75
- # @return [String]
76
- attr_accessor :type
77
-
78
- # Skip the registration (optional, skip if true, defaults to false)
79
- #
80
- # @return [Bool]
81
- attr_accessor :skip
82
-
83
7
  def initialize(region_specific=false)
84
- @username = UNSET_VALUE
85
- @subscriber_username = UNSET_VALUE
86
- @password = UNSET_VALUE
87
- @subscriber_password = UNSET_VALUE
88
- @serverurl = UNSET_VALUE
89
- @baseurl = UNSET_VALUE
90
- @org = UNSET_VALUE
91
- @environment = UNSET_VALUE
92
- @name = UNSET_VALUE
93
- @auto_attach = true
94
- @activationkey = UNSET_VALUE
95
- @servicelevel = UNSET_VALUE
96
- @release = UNSET_VALUE
97
- @force = true
98
- @type = UNSET_VALUE
99
- @skip = UNSET_VALUE
8
+ @conf = OpenStruct.new
9
+ @logger = Log4r::Logger.new("vagrant_registration::config")
100
10
  end
101
11
 
102
12
  def finalize!
103
- @username = @subscriber_username if @username == UNSET_VALUE
104
- @password = @subscriber_password if @password == UNSET_VALUE
105
- @username = nil if @username == UNSET_VALUE
106
- @password = nil if @password == UNSET_VALUE
107
- @serverurl = nil if @serverurl = UNSET_VALUE
108
- @baseurl = nil if @baseurl = UNSET_VALUE
109
- @org = nil if @org = UNSET_VALUE
110
- @environment = nil if @environment = UNSET_VALUE
111
- @name = nil if @name == UNSET_VALUE
112
- @auto_attach = true if @auto_attach == UNSET_VALUE
113
- @activationkey = nil if @activationkey = UNSET_VALUE
114
- @servicelevel = nil if @servicelevel = UNSET_VALUE
115
- @release = nil if @release = UNSET_VALUE
116
- @force = true if @force == UNSET_VALUE
117
- @type = nil if @type == UNSET_VALUE
118
- @skip = false if @skip == UNSET_VALUE
13
+ @conf.skip = false unless @conf.skip
14
+ @logger.info "Final registration configuration: #{@conf.inspect}"
119
15
  end
16
+
17
+ def method_missing(method_sym, *arguments, &block)
18
+ command = "@conf.#{method_sym} #{adjust_arguments(arguments)}"
19
+ @logger.info "Evaluating registration configuration: #{command}"
20
+ eval command
21
+ end
22
+
23
+ private
24
+
25
+ def adjust_arguments(args)
26
+ return '' if args.size < 1
27
+ args.map{|a| a.is_a?(String) ? "'#{a}'" : a}.join(',')
28
+ end
120
29
  end
121
30
  end
122
31
  end