vagrant-registration 1.0.1 → 1.1.0

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: daf310c73794a9dbf36ef3eecd1d3457edf2a5af
4
- data.tar.gz: c4f40d9651904ff77e04a94885cb9a8ae18ab5ca
3
+ metadata.gz: f3faa5f60610d751ab605780b28956d11a6af323
4
+ data.tar.gz: 0bef59c99cefb7dc5156b4d80ca841e0a82fe696
5
5
  SHA512:
6
- metadata.gz: a714e119ea6fa6ed2f9696f9f211e9f140783efa74084914a0c3258168384726c70cd3e5cbbeaabaa3945d95adbd6ae7f5b3fecaec0459924579d40d7bd254b5
7
- data.tar.gz: bca6392dfa46d9220d85224b18b770f0c1a65bb5426ba09bb7ed94ac4200468606d399f256a72cf0ad02336347ca1bc38f803b913a87a4dcc735234270a8330d
6
+ metadata.gz: 3a39cf4efff1c4af5a311439120d816034d649d9fba5e77f1fd28a5ab736627ed149e86b60f635c0425514f5ecd02cdbdfda88d3ef84ef7cbc6b75f32c3f0256
7
+ data.tar.gz: 6c65312f483594fc0bffa7e540c91b5a1ad0e84acbf375cb70c30397f0c45e4fd717a32624f63377a09c566a89ee739008233a378126816e68e8dc36b3f7be0e
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.1.0
4
+
5
+ - Print warning if specifically selected manager is not available
6
+ - Support running alongside vagrant-vbguest, issue #40
7
+ - Support rhn_register manager
8
+ - Fix: Handle various types of configuration option values, issue #48
9
+ - Fix: Hide password on registration failure, issue #47
10
+
11
+ ## 1.0.1
12
+
13
+ - Fix: Set repo_ca_cert option in /etc/rhsm/rhsm.conf after uploading a certificate
14
+
3
15
  ## 1.0.0
4
16
 
5
17
  - Support providing a CA certificate via `config.registration.ca_cert` option
data/Gemfile CHANGED
@@ -1,13 +1,13 @@
1
- source "https://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
5
  group :development do
6
- gem "vagrant", git: "https://github.com/mitchellh/vagrant.git"
7
- gem "gem-compare"
8
- gem "rake"
6
+ gem 'vagrant', git: 'https://github.com/mitchellh/vagrant.git'
7
+ gem 'gem-compare'
8
+ gem 'rake'
9
9
  end
10
10
 
11
11
  group :plugins do
12
- gem "vagrant-registration", path: "."
12
+ gem 'vagrant-registration', path: '.'
13
13
  end
data/README.md CHANGED
@@ -23,7 +23,7 @@ If you are on Fedora, you can install the packaged version of the plugin by runn
23
23
 
24
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
25
 
26
- That being said, this plugin currently ships only with registration capability files for RHEL's Subscription Manager. Feel free to submit others.
26
+ That being said, this plugin currently ships only with registration capability files for RHEL's Subscription Manager and `rhn_register`. Feel free to submit others.
27
27
 
28
28
  To configure the plugin, always include the configuration options mentioned in this file within the following configuration block in your Vagrantfile.
29
29
 
@@ -47,12 +47,13 @@ end
47
47
  config.registration.unregister_on_halt = false
48
48
  ```
49
49
 
50
- ### subscription-manager Configuration
50
+ - **manager** selects the registration manager provider. By default the plugin will use the `subscription_manager` manager, you can however change that by setting the option to a different manager:
51
51
 
52
- vagrant-registration supports all the options of subscription-manager's register command.
53
- You can set any option easily by setting `config.registration.OPTION_NAME = 'OPTION_VALUE'`
54
- in your Vagrantfile (please see the subscription-manager's documentation for option
55
- description).
52
+ ```ruby
53
+ config.registration.manager = 'subscription_manager'
54
+ ```
55
+
56
+ ### Credentials Configuration
56
57
 
57
58
  Setting up the credentials can be done as follows:
58
59
 
@@ -63,7 +64,7 @@ Vagrant.configure('2') do |config|
63
64
  config.registration.username = 'foo'
64
65
  config.registration.password = 'bar'
65
66
  end
66
-
67
+
67
68
  # Alternatively
68
69
  if Vagrant.has_plugin?('vagrant-registration')
69
70
  config.registration.org = 'foo'
@@ -92,8 +93,30 @@ end
92
93
 
93
94
  If you do not provide credentials, you will be prompted for them in the "up process."
94
95
 
95
- Please note the the interactive mode asks you for the preferred registration pair only.
96
- In case of a subscription-manager, you would be ask on your username/password combination.
96
+ Please note the the interactive mode asks you for the preferred registration pair only
97
+ of the configured manager.
98
+
99
+ ### subscription-manager Configuration
100
+
101
+ vagrant-registration will use the `subscription_manager` manager by default or can be explicitly configured by setting the `manager` option to `subscription_manager`:
102
+
103
+ ```ruby
104
+ Vagrant.configure('2') do |config|
105
+ ...
106
+ if Vagrant.has_plugin?('vagrant-registration')
107
+ config.registration.manager = 'subscription_manager'
108
+ end
109
+ ...
110
+ end
111
+ ```
112
+
113
+ In case of `subscription_manager` manager for the preferred registration pair,
114
+ you would be ask on your username/password combination.
115
+
116
+ vagrant-registration supports all the options of subscription-manager's register command.
117
+ You can set any option easily by setting `config.registration.OPTION_NAME = 'OPTION_VALUE'`
118
+ in your Vagrantfile (please see the subscription-manager's documentation for option
119
+ description).
97
120
 
98
121
  #### subscription-manager Default Options
99
122
 
@@ -102,10 +125,10 @@ In case of a subscription-manager, you would be ask on your username/password co
102
125
  ```ruby
103
126
  config.registration.force = false
104
127
  ```
128
+
105
129
  - **--auto-attach**: Vagrant would fail to install packages on registered RHEL system if the subscription is not attached, therefore vagrant-registration appends the
106
130
  `--auto-attach` flag automatically when subscribing. To disable this option, set `auto_attach` option to `false`:
107
131
 
108
-
109
132
  ```ruby
110
133
  config.registration.auto_attach = false
111
134
  ```
@@ -168,21 +191,125 @@ Note that the `auto_attach` option is set to false when using org/activationkey
168
191
  config.registration.skip
169
192
  ```
170
193
 
194
+ ### rhn-register Configuration
195
+
196
+ vagrant-registration will use the `rhn_register` manager only if explicitly configured by setting the `manager` option to `rhn_register`:
197
+
198
+ ```ruby
199
+ Vagrant.configure('2') do |config|
200
+ ...
201
+ if Vagrant.has_plugin?('vagrant-registration')
202
+ config.registration.manager = 'rhn_register'
203
+ end
204
+ ...
205
+ end
206
+ ```
207
+
208
+ In case of a `rhn_register` manager, the preferred registration pair is the username/password/serverurl combination.
209
+
210
+ vagrant-registration supports most of the options of rhnreg_ks's command. You can set any option easily by setting `config.registration.OPTION_NAME = 'OPTION_VALUE'` in your Vagrantfile (please see the `rhnreg_ks`'s documentation for option description).
211
+
212
+ `rhn_register` manager reuses the naming of `subscription-manager`'s command options where possible.
213
+
214
+ #### rhn-register Default Options
215
+
216
+ - **--force**: `rhnreg_ks` command 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`:
217
+
218
+ ```ruby
219
+ config.registration.force = false
220
+ ```
221
+
222
+ #### rhn-register Options Reference
223
+
224
+ ```ruby
225
+ # The username to register the system with under Spacewalk Server, Red Hat Satellite or
226
+ # Red Hat Network Classic. This can be an existing Spacewalk, Red Hat Satellite or
227
+ # Red Hat Network Classic username, or a new user‐name.
228
+ config.registration.username
229
+
230
+ # The password associated with the username specified with the `--username` option.
231
+ # This is an unencrypted password.
232
+ config.registration.password
233
+
234
+ # Give the URL of the subscription service to use (required for registering a
235
+ # system with the "Spacewalk Server", "Red Hat Satellite" or "Red Hat Network Classic").
236
+ # The configuration name is mapped to the `--serverUrl` option of rhnreg_ks command.
237
+ #
238
+ # The serverurl is mandatory and if you do not provide a value,
239
+ # you will be prompted for them in the "up process."
240
+ config.registration.serverurl
241
+
242
+ # A path to a CA certificate file (optional)
243
+ # The configuration name is mapped to the `--sslCACert` option of rhnreg_ks command.
244
+ #
245
+ # The CA certificate file is be uploaded to /usr/share/rhn/<ca_file_name> in guest
246
+ # and the configuration in `/etc/sysconfig/rhn/up2date` is updated to:
247
+ # `sslCACert=/usr/share/rhn/<ca_file_name>`
248
+ #
249
+ # As default only the configuration in `/etc/sysconfig/rhn/up2date` is updated
250
+ # to point to the CA certificate file that is present on Fedora, CentOS and RHEL:
251
+ # `sslCACert=/usr/share/rhn/RHNS-CA-CERT`
252
+ config.registration.ca_cert
253
+
254
+ # Give the organization to which to join the system (required, except for
255
+ # hosted environments)
256
+ # The configuration name is mapped to the `--systemorgid` option of rhnreg_ks command.
257
+ config.registration.org
258
+
259
+ # Name of the subscribed system (optional, defaults to hostname if unset)
260
+ # The configuration name is mapped to the `--profilename` option of rhnreg_ks command.
261
+ config.registration.name
262
+
263
+ # Attach existing subscriptions as part of the registration process (optional)
264
+ config.registration.activationkey
265
+
266
+ # Subscribe this system to the EUS channel tied to the system's redhat-release (optional)
267
+ config.registration.use_eus_channel
268
+
269
+ # Do not probe or upload any hardware info (optional)
270
+ config.registration.nohardware
271
+
272
+ # Do not profile or upload any package info (optional)
273
+ config.registration.nopackages
274
+
275
+ # Do not upload any virtualization info (optional)
276
+ config.registration.novirtinfo
277
+
278
+ # Do not start rhnsd after completion (optional)
279
+ config.registration.norhnsd
280
+
281
+ # Force the registration (optional, force if true, defaults to true)
282
+ config.registration.force
283
+
284
+ # Skip the registration (optional, skip if true, defaults to false)
285
+ config.registration.skip
286
+ ```
287
+
171
288
  ## Tests
172
289
 
173
- Tests currently test the plugin with `subscription-manager` on RHEL 7.1 guest
174
- and Fedora host. You need an imported RHEL 7.1 Vagrant box named `rhel-7.1`.
290
+ Tests currently test the plugin with `subscription-manager` and `rhn_register` on RHEL 7.1 guest and Fedora host. You need an imported RHEL 7.1 Vagrant box named `rhel-7.1`.
175
291
 
176
292
  To run them:
177
293
 
178
294
  ```
295
+ export VAGRANT_REGISTRATION_MANAGER=
179
296
  export VAGRANT_REGISTRATION_USERNAME=
180
297
  export VAGRANT_REGISTRATION_PASSWORD=
181
298
  export VAGRANT_REGISTRATION_ORG=
182
299
  export VAGRANT_REGISTRATION_ACTIVATIONKEY=
300
+ export VAGRANT_REGISTRATION_SERVERURL=
301
+ export VAGRANT_REGISTRATION_CA_CERT=
183
302
  ./tests/run.sh
303
+ ./tests/run_rhn_register.sh
304
+ ```
305
+
306
+ To show the Vagrant output on the console during the tests run, set the `DEBUG`
307
+ environment variable on `1` before executing the test script:
308
+
309
+ ```
310
+ export DEBUG=1
184
311
  ```
185
312
 
186
313
  ## Acknowledgements
187
314
 
188
- 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.
315
+ 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), [goern](https://github.com/goern), [iconoeugen](https://github.com/iconoeugen) and [pvalena](https://github.com/pvalena) (in no particular order) for their contributions of ideas, code and testing for this project.
@@ -12,6 +12,6 @@ module VagrantPlugins
12
12
  end
13
13
 
14
14
  # Temporally load the extra capability files for Red Hat
15
- load(File.join(self.source_root, 'plugins/guests/redhat/plugin.rb'))
15
+ load(File.join(source_root, 'plugins/guests/redhat/plugin.rb'))
16
16
  end
17
17
  end
@@ -1,4 +1,4 @@
1
- require "log4r"
1
+ require 'log4r'
2
2
 
3
3
  module VagrantPlugins
4
4
  module Registration
@@ -11,14 +11,17 @@ module VagrantPlugins
11
11
  end
12
12
 
13
13
  def call(env)
14
- @app.call(env)
14
+ # Vbguest plugin (if present) is called next. Therefore registration
15
+ # needs to be done first. This does not work with the default
16
+ # 'action_register' hook.
17
+ @app.call(env) unless Plugin.vbguest_plugin?
15
18
 
16
19
  # Configuration from Vagrantfile
17
20
  config = env[:machine].config.registration
18
21
  machine = env[:machine]
19
22
  guest = env[:machine].guest
20
23
 
21
- if should_register?(machine)
24
+ if should_register?(machine, env[:ui])
22
25
  env[:ui].info('Registering box with vagrant-registration...')
23
26
  check_configuration_options(machine, env[:ui])
24
27
 
@@ -38,15 +41,17 @@ module VagrantPlugins
38
41
  end
39
42
 
40
43
  @logger.debug('Registration is skipped due to the configuration') if config.skip
44
+
45
+ @app.call(env) if Plugin.vbguest_plugin?
41
46
  end
42
47
 
43
48
  private
44
49
 
45
50
  # Shall we register the box?
46
- def should_register?(machine)
51
+ def should_register?(machine, ui)
47
52
  !machine.config.registration.skip &&
48
53
  capabilities_provided?(machine.guest) &&
49
- manager_installed?(machine.guest) &&
54
+ manager_installed?(machine.guest, ui) &&
50
55
  !machine.guest.capability(:registration_registered?)
51
56
  end
52
57
 
@@ -58,8 +63,8 @@ module VagrantPlugins
58
63
  options = machine.config.registration.conf.each_pair.map { |pair| pair[0] }
59
64
 
60
65
  if unsupported_options_provided?(manager, available_options, options, ui)
61
- ui.warn("WARNING: #{manager} supports only the following options:" +
62
- "\nWARNING: " + available_options.join(', '))
66
+ ui.warn("WARNING: #{manager} supports only the following options:" \
67
+ "\nWARNING: #{available_options.join(', ')}")
63
68
  end
64
69
  end
65
70
 
@@ -68,7 +73,7 @@ module VagrantPlugins
68
73
  warned = false
69
74
  options.each do |option|
70
75
  unless available_options.include? option
71
- ui.warn("WARNING: #{option} option is not supported for " + manager)
76
+ ui.warn("WARNING: #{option} option is not supported for #{manager}")
72
77
  warned = true
73
78
  end
74
79
  end
@@ -88,8 +93,8 @@ module VagrantPlugins
88
93
  end
89
94
 
90
95
  # Check if selected registration manager is installed
91
- def manager_installed?(guest)
92
- if guest.capability(:registration_manager_installed)
96
+ def manager_installed?(guest, ui)
97
+ if guest.capability(:registration_manager_installed, ui)
93
98
  true
94
99
  else
95
100
  @logger.debug('Registration manager not found on guest')
@@ -1,4 +1,4 @@
1
- require "log4r"
1
+ require 'log4r'
2
2
 
3
3
  module VagrantPlugins
4
4
  module Registration
@@ -20,7 +20,7 @@ module VagrantPlugins
20
20
  end
21
21
 
22
22
  @logger.debug('Unregistration is skipped due to the configuration') if config.skip
23
- @logger.debug('Unregistration is skipped on halt due to the configuration') if !config.unregister_on_halt
23
+ @logger.debug('Unregistration is skipped on halt due to the configuration') unless config.unregister_on_halt
24
24
  @app.call(env)
25
25
 
26
26
  # Guest might not be available after halting, so log the exception and continue
@@ -1,5 +1,5 @@
1
- require "vagrant"
2
- require "ostruct"
1
+ require 'vagrant'
2
+ require 'ostruct'
3
3
 
4
4
  module VagrantPlugins
5
5
  module Registration
@@ -34,9 +34,11 @@ module VagrantPlugins
34
34
  @conf = OpenStruct.new if @conf == UNSET_VALUE
35
35
  end
36
36
 
37
+ # Serialize strings, nil and boolean values, symbols, arrays and hashes
38
+ # to be used within eval()
37
39
  def adjust_arguments(args)
38
40
  return '' if args.size < 1
39
- args.map { |a| a.is_a?(String) ? "'#{a}'" : a }.join(',')
41
+ args.inspect[1..-2]
40
42
  end
41
43
  end
42
44
  end
@@ -14,10 +14,22 @@ module VagrantPlugins
14
14
  module Registration
15
15
  class Plugin < Vagrant.plugin('2')
16
16
  class << self
17
+
18
+ # Vbguest plugin updates GuestAdditions for VirtualBox before
19
+ # '::Vagrant::Action::Builtin::SyncedFolders' and therefore needs
20
+ # to be registered. Prepending Vbguest hook ensures that, but this
21
+ # is done only with Vbguest plugin and VirtualBox provider. In other
22
+ # cases the behavior is unchanged.
17
23
  def register(hook)
18
24
  setup_logging
19
- hook.after(::Vagrant::Action::Builtin::SyncedFolders,
20
- VagrantPlugins::Registration::Action.action_register)
25
+
26
+ if vbguest_plugin?
27
+ hook.before(::VagrantVbguest::Middleware,
28
+ VagrantPlugins::Registration::Action.action_register)
29
+ else
30
+ hook.after(::Vagrant::Action::Builtin::SyncedFolders,
31
+ VagrantPlugins::Registration::Action.action_register)
32
+ end
21
33
  end
22
34
 
23
35
  def unregister_on_halt(hook)
@@ -74,6 +86,14 @@ module VagrantPlugins
74
86
  logger = nil
75
87
  end
76
88
  end
89
+
90
+ # Determines if both VirtualBox provider and Vbguest plugin are present.
91
+ def self.vbguest_plugin?
92
+ @@vbguest_plugin ||= (
93
+ defined?(VagrantPlugins::ProviderVirtualBox::Provider) &&
94
+ defined?(VagrantVbguest::Middleware)
95
+ )
96
+ end
77
97
  end
78
98
  end
79
99
  end
@@ -1,6 +1,6 @@
1
1
  module VagrantPlugins
2
2
  # Registration plugin to auto-register guests on `vagrant up`
3
3
  module Registration
4
- VERSION = '1.0.1'
4
+ VERSION = '1.1.0'
5
5
  end
6
6
  end
@@ -2,7 +2,7 @@ module VagrantPlugins
2
2
  module GuestRedHat
3
3
  module Cap
4
4
  # Common configuration options for all managers
5
- DEFAULT_CONFIGURATION_OPTIONS = [:skip, :unregister_on_halt]
5
+ DEFAULT_CONFIGURATION_OPTIONS = [:manager, :skip, :unregister_on_halt]
6
6
 
7
7
  # This provides registration capabilities for vagrant-registration
8
8
  #
@@ -12,7 +12,7 @@ module VagrantPlugins
12
12
  class Registration
13
13
  # Is the machine already registered?
14
14
  def self.registration_registered?(machine)
15
- cap = "#{self.registration_manager(machine).to_s}_registered?".to_sym
15
+ cap = "#{registration_manager(machine)}_registered?".to_sym
16
16
  if machine.guest.capability?(cap)
17
17
  machine.guest.capability(cap)
18
18
  else
@@ -22,7 +22,7 @@ module VagrantPlugins
22
22
 
23
23
  # Register the given machine
24
24
  def self.registration_register(machine, ui)
25
- cap = "#{self.registration_manager(machine).to_s}_register".to_sym
25
+ cap = "#{registration_manager(machine)}_register".to_sym
26
26
  if machine.guest.capability?(cap)
27
27
  machine.guest.capability(cap, ui)
28
28
  else
@@ -32,7 +32,7 @@ module VagrantPlugins
32
32
 
33
33
  # Unregister the given machine
34
34
  def self.registration_unregister(machine)
35
- cap = "#{self.registration_manager(machine).to_s}_unregister".to_sym
35
+ cap = "#{registration_manager(machine)}_unregister".to_sym
36
36
  if machine.guest.capability?(cap)
37
37
  machine.guest.capability(cap)
38
38
  else
@@ -41,13 +41,14 @@ module VagrantPlugins
41
41
  end
42
42
 
43
43
  # Check that the machine has the selected registration manager installed
44
- def self.registration_manager_installed(machine)
45
- cap = "#{self.registration_manager(machine).to_s}".to_sym
46
- if machine.guest.capability?(cap)
47
- machine.guest.capability(cap)
48
- else
49
- false
44
+ # and warn if the user specifically selected a manager that is not available
45
+ def self.registration_manager_installed(machine, ui)
46
+ cap = "#{registration_manager(machine)}".to_sym
47
+ return machine.guest.capability(cap) if machine.guest.capability?(cap)
48
+ if machine.config.registration.manager != ''
49
+ ui.error("WARNING: Selected registration manager #{machine.config.registration.manager} is not available, skipping.")
50
50
  end
51
+ false
51
52
  end
52
53
 
53
54
  # Required configuration options of the registration manager
@@ -57,7 +58,7 @@ module VagrantPlugins
57
58
  #
58
59
  # e.g. [[:username, :password]]
59
60
  def self.registration_credentials(machine)
60
- cap = "#{self.registration_manager(machine).to_s}_credentials".to_sym
61
+ cap = "#{registration_manager(machine)}_credentials".to_sym
61
62
  if machine.guest.capability?(cap)
62
63
  machine.guest.capability(cap)
63
64
  else
@@ -68,7 +69,7 @@ module VagrantPlugins
68
69
  # Return all available options for a given registration manager together
69
70
  # with general options available to any.
70
71
  def self.registration_options(machine)
71
- cap = "#{self.registration_manager(machine).to_s}_options".to_sym
72
+ cap = "#{registration_manager(machine)}_options".to_sym
72
73
  if machine.guest.capability?(cap)
73
74
  DEFAULT_CONFIGURATION_OPTIONS + machine.guest.capability(cap)
74
75
  else
@@ -78,7 +79,7 @@ module VagrantPlugins
78
79
 
79
80
  # Return secret options for the registration manager
80
81
  def self.registration_secrets(machine)
81
- cap = "#{self.registration_manager(machine).to_s}_secrets".to_sym
82
+ cap = "#{registration_manager(machine)}_secrets".to_sym
82
83
  if machine.guest.capability?(cap)
83
84
  machine.guest.capability(cap)
84
85
  else
@@ -0,0 +1,139 @@
1
+ module VagrantPlugins
2
+ module GuestRedHat
3
+ module Cap
4
+ class RhnRegister
5
+ # Test that the machine is already registered
6
+ def self.rhn_register_registered?(machine)
7
+ true if machine.communicate.execute('/usr/sbin/rhn_check', sudo: true)
8
+ rescue
9
+ false
10
+ end
11
+
12
+ # Test that we have rhn installed
13
+ def self.rhn_register(machine)
14
+ machine.communicate.test('/usr/sbin/rhn_check --version', sudo: true) &&
15
+ machine.communicate.test('/usr/sbin/rhnreg_ks --version', sudo: true)
16
+ end
17
+
18
+ # Register the machine using 'rhnreg_ks' command, config is (Open)Struct
19
+ def self.rhn_register_register(machine, ui)
20
+ rhn_register_upload_certificate(machine, ui)
21
+ rhn_register_server_url(machine, ui) if machine.config.registration.serverurl
22
+ command = "rhnreg_ks #{configuration_to_options(machine.config.registration)}"
23
+
24
+ # Handle exception to avoid displaying password
25
+ begin
26
+ error = String.new
27
+ machine.communicate.sudo(registration_command(command)) do |type, data|
28
+ error += "#{data}" if type == :stderr
29
+ end
30
+ rescue Vagrant::Errors::VagrantError
31
+ raise Vagrant::Errors::VagrantError.new, error.strip
32
+ end
33
+ end
34
+
35
+ # Unregister the machine using 'rhn_unregister.py' resource script
36
+ def self.rhn_register_unregister(machine)
37
+ machine.communicate.tap do |comm|
38
+ tmp = '/tmp/rhn_unregister'
39
+ system_id = '/etc/sysconfig/rhn/systemid'
40
+ server_url = machine.config.registration.serverurl
41
+ # Generate the API URL
42
+ server_url = server_url.sub(/XMLRPC$/, 'rpc/api')
43
+ comm.sudo("rm -f #{tmp}", error_check: false)
44
+ comm.upload(resource('rhn_unregister.py'), tmp)
45
+ comm.sudo("python #{tmp} -s #{server_url} -f #{system_id}")
46
+ comm.sudo("rm -f #{tmp}")
47
+ # Guest still thinks it is a part of RHN network until systemdid file is removed
48
+ comm.sudo("rm -f #{system_id}")
49
+ end
50
+ end
51
+
52
+ # Return required configuration options for rhn register
53
+ #
54
+ # For rhn_register the Server URL is mandatory and must be always
55
+ # provided together with the credentials
56
+ def self.rhn_register_credentials(machine)
57
+ [[:username, :password, :serverurl], [:org, :activationkey, :serverurl]]
58
+ end
59
+
60
+ # Return all available options for rhn register
61
+ def self.rhn_register_options(machine)
62
+ [:name, :username, :password, :org, :serverurl, :ca_cert,
63
+ :activationkey, :use_eus_channel, :nohardware, :nopackages,
64
+ :novirtinfo, :norhnsd, :force]
65
+ end
66
+
67
+ # Return secret options for rhreg_ks
68
+ def self.rhn_register_secrets(manager)
69
+ [:password]
70
+ end
71
+
72
+ private
73
+
74
+ # Upload provided SSL CA cert to the standard /usr/share/rhn/ path on the guest
75
+ # and configure the correct path in `up2date` system configuration
76
+ def self.rhn_register_upload_certificate(machine, ui)
77
+ # Set as the default CA certificate file that is present on Fedora, CentOS and RHEL
78
+ cert_file_name = 'RHNS-CA-CERT'
79
+ if machine.config.registration.ca_cert
80
+ ui.info("Uploading CA certificate from #{machine.config.registration.ca_cert}...")
81
+ if File.exist?(machine.config.registration.ca_cert)
82
+ # Make sure the provided CA certificate file will be configured
83
+ cert_file_name = File.basename(machine.config.registration.ca_cert)
84
+ cert_file_content = File.read(machine.config.registration.ca_cert, tmp)
85
+ machine.communicate.execute("echo '#{cert_file_content}' > /usr/share/rhn/#{cert_file_name}", sudo: true)
86
+ else
87
+ ui.warn("WARNING: Provided CA certificate file #{machine.config.registration.ca_cert} does not exist, skipping")
88
+ end
89
+ end
90
+ # Make sure the correct CA certificate file is always configured
91
+ ui.info("Updating CA certificate to /usr/share/rhn/#{cert_file_name}`...")
92
+ machine.communicate.execute("sed -i 's|^sslCACert\s*=.*$|sslCACert=/usr/share/rhn/#{cert_file_name}|g' /etc/sysconfig/rhn/up2date", sudo: true)
93
+ end
94
+
95
+ # Build registration command that skips registration if the system is registered
96
+ def self.registration_command(command)
97
+ "cmd=$(#{command}); if [ \"$?\" != \"0\" ]; then echo $cmd | grep 'This system is already registered' || (echo $cmd 1>&2 && exit 1) ; fi"
98
+ end
99
+
100
+ # Update configuration file '/etc/sysconfig/rhn/up2date' with
101
+ # provided server URL
102
+ def self.rhn_register_server_url(machine, ui)
103
+ ui.info("Update server URL to #{machine.config.registration.serverurl}...")
104
+ machine.communicate.execute("sed -i 's|^serverURL=.*$|serverURL=/usr/share/rhn/#{machine.config.registration.serverurl}|' /etc/sysconfig/rhn/up2date", sudo: true)
105
+ end
106
+
107
+ # The absolute path to the resource file
108
+ def self.resource(name)
109
+ File.join(resource_root, name)
110
+ end
111
+
112
+ # The absolute path to the resource directory
113
+ def self.resource_root
114
+ File.expand_path('../../../../../resources', __FILE__)
115
+ end
116
+
117
+ # Build additional rhreg_ks options based on the plugin configuration
118
+ def self.configuration_to_options(config)
119
+ config.force = true unless config.force
120
+
121
+ options = []
122
+ options << "--profilename='#{config.name}'" if config.name
123
+ options << "--username='#{config.username}'" if config.username
124
+ options << "--password='#{config.password}'" if config.password
125
+ options << "--systemorgid='#{config.org}'" if config.org
126
+ options << "--serverUrl='#{config.serverurl}'" if config.serverurl
127
+ options << "--activationkey='#{config.activationkey}'" if config.activationkey
128
+ options << '--use-eus-channel' if config.use_eus_channel
129
+ options << '--nohardware' if config.nohardware
130
+ options << '--nopackages' if config.nopackages
131
+ options << '--novirtinfo' if config.novirtinfo
132
+ options << '--norhnsd' if config.norhnsd
133
+ options << '--force' if config.force
134
+ options.join(' ')
135
+ end
136
+ end
137
+ end
138
+ end
139
+ end
@@ -11,37 +11,28 @@ module VagrantPlugins
11
11
 
12
12
  # Test that we have subscription-manager installed
13
13
  def self.subscription_manager(machine)
14
- machine.communicate.test("/usr/sbin/subscription-manager", sudo: true)
14
+ machine.communicate.test('/usr/sbin/subscription-manager', sudo: true)
15
15
  end
16
16
 
17
17
  # Register the machine using 'register' option, config is (Open)Struct
18
18
  def self.subscription_manager_register(machine, ui)
19
19
  subscription_manager_upload_certificate(machine, ui) if machine.config.registration.ca_cert
20
20
  command = "subscription-manager register #{configuration_to_options(machine.config.registration)}"
21
- machine.communicate.execute("cmd=$(#{command}); if [ \"$?\" != \"0\" ]; then echo $cmd | grep 'This system is already registered' || (echo $cmd 1>&2 && exit 1) ; fi", sudo: true)
22
- end
23
21
 
24
- # Upload provided CA cert to the standard /etc/rhsm/ca path on the guest
25
- #
26
- # Since subscription-manager recognizes only .pem files, we rename those
27
- # files not ending with '.pem' extension.
28
- def self.subscription_manager_upload_certificate(machine, ui)
29
- ui.info("Uploading CA certificate from #{machine.config.registration.ca_cert}...")
30
- if File.exist?(machine.config.registration.ca_cert)
31
- cert_file_content = File.read(machine.config.registration.ca_cert)
32
- cert_file_name = File.basename(machine.config.registration.ca_cert)
33
- cert_file_name = "#{cert_file_name}.pem" unless cert_file_name.end_with? '.pem'
34
- machine.communicate.execute("echo '#{cert_file_content}' > /etc/rhsm/ca/#{cert_file_name}", sudo: true)
35
- ui.info('Setting repo_ca_cert option in /etc/rhsm/rhsm.conf...')
36
- machine.communicate.execute("sed -i 's|^repo_ca_cert\s*=.*|repo_ca_cert = /etc/rhsm/ca/#{cert_file_name}|g' /etc/rhsm/rhsm.conf", sudo: true)
37
- else
38
- ui.warn("WARNING: Provided CA certificate file #{machine.config.registration.ca_cert} does not exist, skipping")
22
+ # Handle exception to avoid displaying password
23
+ begin
24
+ error = String.new
25
+ machine.communicate.sudo(registration_command(command)) do |type, data|
26
+ error += "#{data}" if type == :stderr
27
+ end
28
+ rescue Vagrant::Errors::VagrantError
29
+ raise Vagrant::Errors::VagrantError.new, error.strip
39
30
  end
40
- end
31
+ end
41
32
 
42
33
  # Unregister the machine using 'unregister' option
43
34
  def self.subscription_manager_unregister(machine)
44
- machine.communicate.execute("subscription-manager unregister || :", sudo: true)
35
+ machine.communicate.execute('subscription-manager unregister || :', sudo: true)
45
36
  end
46
37
 
47
38
  # Return required configuration options for subscription-manager
@@ -66,6 +57,29 @@ module VagrantPlugins
66
57
 
67
58
  private
68
59
 
60
+ # Upload provided CA cert to the standard /etc/rhsm/ca path on the guest
61
+ #
62
+ # Since subscription-manager recognizes only .pem files, we rename those
63
+ # files not ending with '.pem' extension.
64
+ def self.subscription_manager_upload_certificate(machine, ui)
65
+ ui.info("Uploading CA certificate from #{machine.config.registration.ca_cert}...")
66
+ if File.exist?(machine.config.registration.ca_cert)
67
+ cert_file_content = File.read(machine.config.registration.ca_cert)
68
+ cert_file_name = File.basename(machine.config.registration.ca_cert)
69
+ cert_file_name = "#{cert_file_name}.pem" unless cert_file_name.end_with? '.pem'
70
+ machine.communicate.execute("echo '#{cert_file_content}' > /etc/rhsm/ca/#{cert_file_name}", sudo: true)
71
+ ui.info('Setting repo_ca_cert option in /etc/rhsm/rhsm.conf...')
72
+ machine.communicate.execute("sed -i 's|^repo_ca_cert\s*=.*|repo_ca_cert = /etc/rhsm/ca/#{cert_file_name}|g' /etc/rhsm/rhsm.conf", sudo: true)
73
+ else
74
+ ui.warn("WARNING: Provided CA certificate file #{machine.config.registration.ca_cert} does not exist, skipping")
75
+ end
76
+ end
77
+
78
+ # Build registration command that skips registration if the system is registered
79
+ def self.registration_command(command)
80
+ "cmd=$(#{command}); if [ \"$?\" != \"0\" ]; then echo $cmd | grep 'This system is already registered' || (echo $cmd 1>&2 && exit 1) ; fi"
81
+ end
82
+
69
83
  # Build additional subscription-manager options based on plugin configuration
70
84
  def self.configuration_to_options(config)
71
85
  config.force = true unless config.force
@@ -85,11 +99,11 @@ module VagrantPlugins
85
99
  options << "--org='#{config.org}'" if config.org
86
100
  options << "--environment='#{config.environment}'" if config.environment
87
101
  options << "--name='#{config.name}'" if config.name
88
- options << "--auto-attach" if config.auto_attach
102
+ options << '--auto-attach' if config.auto_attach
89
103
  options << "--activationkey='#{config.activationkey}'" if config.activationkey
90
104
  options << "--servicelevel='#{config.servicelevel}'" if config.servicelevel
91
105
  options << "--release='#{config.release}'" if config.release
92
- options << "--force" if config.force
106
+ options << '--force' if config.force
93
107
  options << "--type='#{config.type}'" if config.type
94
108
  options.join(' ')
95
109
  end
@@ -59,7 +59,7 @@ module VagrantPlugins
59
59
  end
60
60
 
61
61
  guest_capability('redhat', 'subscription_manager_upload_certificate') do
62
- require_relative "cap/subscription_manager"
62
+ require_relative 'cap/subscription_manager'
63
63
  Cap::SubscriptionManager
64
64
  end
65
65
 
@@ -82,6 +82,41 @@ module VagrantPlugins
82
82
  require_relative 'cap/subscription_manager'
83
83
  Cap::SubscriptionManager
84
84
  end
85
+
86
+ guest_capability('redhat', 'rhn_register') do
87
+ require_relative 'cap/rhn_register'
88
+ Cap::RhnRegister
89
+ end
90
+
91
+ guest_capability('redhat', 'rhn_register_registered?') do
92
+ require_relative 'cap/rhn_register'
93
+ Cap::RhnRegister
94
+ end
95
+
96
+ guest_capability('redhat', 'rhn_register_register') do
97
+ require_relative 'cap/rhn_register'
98
+ Cap::RhnRegister
99
+ end
100
+
101
+ guest_capability('redhat', 'rhn_register_unregister') do
102
+ require_relative 'cap/rhn_register'
103
+ Cap::RhnRegister
104
+ end
105
+
106
+ guest_capability('redhat', 'rhn_register_credentials') do
107
+ require_relative 'cap/rhn_register'
108
+ Cap::RhnRegister
109
+ end
110
+
111
+ guest_capability('redhat', 'rhn_register_options') do
112
+ require_relative 'cap/rhn_register'
113
+ Cap::RhnRegister
114
+ end
115
+
116
+ guest_capability('redhat', 'rhn_register_secrets') do
117
+ require_relative 'cap/rhn_register'
118
+ Cap::RhnRegister
119
+ end
85
120
  end
86
121
  end
87
122
  end
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/python
2
+ import argparse
3
+ import xmlrpclib
4
+ import os.path
5
+ import sys
6
+
7
+ def main():
8
+ parser = argparse.ArgumentParser(description="Unregister the system from Spacewalk Server, Red Hat Satellite or Red Hat Network Classic.")
9
+ parser.add_argument("-s", "--serverurl", dest="server_url", type=str, required=True,
10
+ help="Specify a URL to as the server.")
11
+ parser.add_argument("-f", "--file", dest="system_id", type=str, default='/etc/sysconfig/rhn/systemid',
12
+ help="Specify a path to the RHN systemid file.")
13
+
14
+ args = parser.parse_args()
15
+
16
+ try:
17
+ if not os.path.exists(args.system_id):
18
+ print "System is not registered to RHN"
19
+ return 1
20
+ client = xmlrpclib.Server(args.server_url)
21
+ client.system.delete_system(open(args.system_id).read())
22
+ except xmlrpclib.ProtocolError as err:
23
+ print "A fault occurred"
24
+ print "Fault string: %s" % err
25
+ return 1
26
+ except xmlrpclib.Fault as err:
27
+ print "A fault occurred"
28
+ print "Fault code: %d" % err.faultCode
29
+ print "Fault string: %s" % err.faultString
30
+ return 1
31
+ except IOError as err:
32
+ print "A fault occurred"
33
+ print "Fault string: %s" % err
34
+ return 1
35
+ except Exception as e:
36
+ print "A fault occurred"
37
+ print "Fault: %s" % e
38
+ return 1
39
+ print "Unregister successful"
40
+ return 0
41
+
42
+ if __name__ == "__main__":
43
+ sys.exit(main())
@@ -16,11 +16,12 @@ Gem::Specification.new do |s|
16
16
  # Note that the entire gitignore(5) syntax is not supported, specifically
17
17
  # the '!' syntax, but it should mostly work correctly.
18
18
  root_path = File.dirname(__FILE__)
19
- all_files = Dir.chdir(root_path) {
19
+ all_files = Dir.chdir(root_path) do
20
20
  Dir.glob('lib/**/{*,.*}') +
21
21
  Dir.glob('plugins/**/{*,.*}') +
22
+ Dir.glob('resources/**/{*,.*}') +
22
23
  ['Rakefile', 'Gemfile', 'README.md', 'CHANGELOG.md', 'LICENSE.md', 'vagrant-registration.gemspec']
23
- }
24
+ end
24
25
  all_files.reject! { |file| ['.', '..'].include?(File.basename(file)) }
25
26
  gitignore_path = File.join(root_path, '.gitignore')
26
27
  gitignore = File.readlines(gitignore_path)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-registration
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Langdon White
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-11-26 00:00:00.000000000 Z
13
+ date: 2015-12-10 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: yard
@@ -49,8 +49,10 @@ files:
49
49
  - lib/vagrant-registration/plugin.rb
50
50
  - lib/vagrant-registration/version.rb
51
51
  - plugins/guests/redhat/cap/registration.rb
52
+ - plugins/guests/redhat/cap/rhn_register.rb
52
53
  - plugins/guests/redhat/cap/subscription_manager.rb
53
54
  - plugins/guests/redhat/plugin.rb
55
+ - resources/rhn_unregister.py
54
56
  - vagrant-registration.gemspec
55
57
  homepage: https://github.com/projectatomic/adb-vagrant-registration
56
58
  licenses: