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 +4 -4
- data/README.md +85 -15
- data/Rakefile +6 -0
- data/lib/vagrant-registration/action/register.rb +70 -35
- data/lib/vagrant-registration/action/unregister.rb +29 -14
- data/lib/vagrant-registration/config.rb +18 -109
- data/lib/vagrant-registration/plugin.rb +3 -2
- data/lib/vagrant-registration/version.rb +1 -1
- data/plugins/guests/redhat/cap/registration.rb +67 -0
- data/plugins/guests/redhat/cap/subscription_manager.rb +48 -1
- data/plugins/guests/redhat/plugin.rb +46 -6
- data/tests/helpers.sh +124 -0
- data/tests/run.sh +53 -0
- data/tests/vagrantfiles/Vagrantfile.rhel_multi_machine +19 -0
- data/tests/vagrantfiles/Vagrantfile.rhel_wrong_credentials +14 -0
- data/vagrant-registration.gemspec +2 -1
- data/vagrant-registration.spec +90 -0
- metadata +64 -12
- data/lib/vagrant-registration/env.rb +0 -21
- data/lib/vagrant-registration/errors.rb +0 -19
- data/locales/en.yml +0 -2
- data/plugins/guests/redhat/cap/register.rb +0 -33
- data/plugins/guests/redhat/cap/unregister.rb +0 -11
- data/tests/shell-scripts/test-rhel-eco-ident/Vagrantfile.centos +0 -14
- data/tests/shell-scripts/test-rhel-eco-ident/Vagrantfile.fedora +0 -14
- data/tests/shell-scripts/test-rhel-eco-ident/Vagrantfile.rhel +0 -14
- data/tests/shell-scripts/test-rhel-eco-ident/test-identification.sh +0 -114
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d50591b44df73fbaf5754f6a5ad19b2d42116ab
|
4
|
+
data.tar.gz: f0414f8fa9bda6a5a74cefbd96f4c6315c888cb1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bfac4d465549f33f0798691dc2e7569d372b3bca7a6983f6fc373854cf5268f24dc8f50c86f5b4cef30a509cbbb0f638c1bd48afedc8f5531cc996b1352fdc01
|
7
|
+
data.tar.gz: ff6e8aab4cbb1882dfe7bd62168d42f39f03c3a744fff7155258f06ae40c8eb1cfb7a71aa08c51963ab99d49758c5432b461c46baa55f6887547f7d4fd9ac13d
|
data/README.md
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
# vagrant-registration
|
2
2
|
|
3
|
-
|
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
|
-
|
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
|
-
|
34
|
-
|
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
|
-
|
47
|
-
|
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"
|
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
|
-
|
77
|
+
config.registration.auto_attach = false
|
57
78
|
```
|
58
79
|
|
59
|
-
|
80
|
+
#### subscription-manager Options Reference
|
60
81
|
|
61
82
|
```ruby
|
62
|
-
|
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
@@ -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
|
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
|
-
|
23
|
-
|
24
|
-
|
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
|
-
|
28
|
-
|
39
|
+
@logger.debug("Registration is skipped due to the configuration") if config.skip
|
40
|
+
end
|
29
41
|
|
30
|
-
|
31
|
-
unless credentials_provided? config
|
32
|
-
@logger.debug("credentials for registration not provided")
|
42
|
+
private
|
33
43
|
|
34
|
-
|
35
|
-
|
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
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
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("
|
59
|
+
@logger.debug("Registration manager not found on guest")
|
60
|
+
false
|
51
61
|
end
|
52
62
|
end
|
53
63
|
|
54
|
-
|
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
|
-
#
|
57
|
-
def
|
58
|
-
|
59
|
-
|
60
|
-
|
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
|
-
#
|
64
|
-
|
65
|
-
|
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
|
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
|
18
|
-
|
19
|
-
|
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("
|
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
|
-
@
|
85
|
-
@
|
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
|
-
@
|
104
|
-
@
|
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
|