vagrant-registration 0.0.6 → 0.0.7

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: 97fa20b1599696327a619635fe9b1b9a512a2d1f
4
- data.tar.gz: 46bfe62a920cff799b56e4fcd9584d17d5fc3454
3
+ metadata.gz: 6673cf990018e4be8aed666a506fa295fb63a221
4
+ data.tar.gz: 80a90d9201751177b443eca21bf20e6bfdcf7e3e
5
5
  SHA512:
6
- metadata.gz: 4bb56047885aae33c1036337689583b4c845980bcc458f843d76a0a1d8025766ac81861aa4db0f8004249acaba882275066faf7d054138738f2bff320b38a216
7
- data.tar.gz: b77a8c2831a1e9598d7d2af170f6020394d06c195546a30da2d0ededa3c78cb3d55ba4f4c4c14f4d579d33edd65b6b3e696d729788af4e3623222b95f501b3de
6
+ metadata.gz: f2b228f77a49268c994f244dc19d52143a69eeea2f628d54b5fb6034744c53b73e70f3388615fe3c1a7cb3c39b12e26e738bbd60ddad7c4f576cf62ab8013d9c
7
+ data.tar.gz: 04a31284b9b4369eb32d895ce35030ef34a1d93d3773e4172e2575564fbea74b3f3cb865779cdbc5fe4b23ffabcf3051d3381432554b07f3c938c2788ce42bca
data/.gitignore CHANGED
@@ -8,7 +8,7 @@
8
8
  /test/tmp/
9
9
  /test/version_tmp/
10
10
  /tmp/
11
-
11
+ .idea/
12
12
  ## Specific to RubyMotion:
13
13
  .dat*
14
14
  .repl_history
data/README.md CHANGED
@@ -28,5 +28,15 @@ If you prefer not to store your username/password on your filesystem, you can op
28
28
  config.registration.subscriber_username = ENV['SUB_USERNAME']
29
29
  config.registration.subscriber_password = ENV['SUB_PASSWORD']
30
30
 
31
+ Finally, 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).
32
+
33
+ You can also skip registration altogether if you would prefer but don't want to remove the plugin. If you want this function, please use
34
+
35
+ config.registration.skip = true
36
+
37
+ RHEL Subscription Manager will fail if you attempt to register a registered machine (see the man page for why). In order to not slow boot time, we now, by default, pass the "--force" flag when we try to subscribe. If you want to disable this feature:
38
+
39
+ config.registration.force = false
40
+
31
41
  ## Support
32
42
  Currently, "capabilities" are only provided for Red Hat's Subscription Manager. To add others, one just needs to add a new guest plugin, then a cap directory with register.rb and unregister.rb. See the redhat guest for an example.
data/ides.sh ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env bash
2
+
3
+ yum update -y
4
+
@@ -15,6 +15,8 @@ module VagrantPlugins
15
15
  @source_root ||= Pathname.new(File.expand_path("../../", __FILE__))
16
16
  end
17
17
 
18
+ # Temporally load the extra capability files for Fedora
19
+ load(File.join(self.source_root, 'plugins/guests/fedora/plugin.rb'))
18
20
  # Temporally load the extra capability files for Red Hat
19
21
  load(File.join(self.source_root, 'plugins/guests/redhat/plugin.rb'))
20
22
  end
@@ -17,7 +17,13 @@ module VagrantPlugins
17
17
  guest = env[:machine].guest
18
18
  @logger.info("Testing for registration_register capability on ")
19
19
 
20
- if guest.capability?(:register)
20
+ if guest.capability?(:register) && guest.capability?(:subscription_manager)
21
+
22
+ unless guest.capability(:subscription_manager)
23
+ config.skip=true
24
+ @logger.info("subscription-manager not found on guest")
25
+ end
26
+
21
27
  unless config.skip
22
28
  env[:ui].info("Registering box with vagrant-registration...")
23
29
 
@@ -35,7 +41,7 @@ module VagrantPlugins
35
41
  config.subscriber_username, config.subscriber_password = register_on_screen(env[:ui])
36
42
  end
37
43
  end
38
-
44
+ @logger.info("Registration is forced") if config.force
39
45
  result = guest.capability(:register) unless config.skip
40
46
  else
41
47
  @logger.debug("registration skipped due to configuration")
@@ -14,7 +14,7 @@ module VagrantPlugins
14
14
  def call(env)
15
15
  guest = env[:machine].guest
16
16
 
17
- if guest.capability?(:unregister)
17
+ if guest.capability?(:unregister) && guest.capability?(:subscription_manager)
18
18
  if !env[:machine].config.registration.skip
19
19
  env[:ui].info("Unregistering box with vagrant-registration...")
20
20
  @logger.info("registration_unregister capability exists on ")
@@ -18,16 +18,23 @@ module VagrantPlugins
18
18
  # @return [Bool]
19
19
  attr_accessor :skip
20
20
 
21
+ # Force the registration (skip if true)
22
+ #
23
+ # @return [Bool]
24
+ attr_accessor :force
25
+
21
26
  def initialize(region_specific=false)
22
27
  @subscriber_username = UNSET_VALUE
23
28
  @subscriber_password = UNSET_VALUE
24
29
  @skip = UNSET_VALUE
30
+ @force = true
25
31
  end
26
32
 
27
33
  def finalize!
28
34
  @subscriber_username = nil if @subscriber_username == UNSET_VALUE
29
35
  @subscriber_password = nil if @subscriber_password == UNSET_VALUE
30
36
  @skip = false if @skip == UNSET_VALUE
37
+ @force = true if @force == UNSET_VALUE
31
38
  end
32
39
  end
33
40
  end
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module Registration
3
- VERSION = "0.0.6"
3
+ VERSION = "0.0.7"
4
4
  end
5
5
  end
@@ -0,0 +1,75 @@
1
+ module VagrantPlugins
2
+ module GuestFedora
3
+ module Cap
4
+ class ChangeHostName
5
+ def self.change_host_name(machine, name)
6
+ new(machine, name).change!
7
+ end
8
+
9
+ attr_reader :machine, :new_hostname
10
+
11
+ def initialize(machine, new_hostname)
12
+ @machine = machine
13
+ @new_hostname = new_hostname
14
+ end
15
+
16
+ def change!
17
+ return unless should_change?
18
+
19
+ update_etc_hostname
20
+ update_etc_hosts
21
+ refresh_hostname_service
22
+ end
23
+
24
+ def should_change?
25
+ new_hostname != current_hostname
26
+ end
27
+
28
+ def current_hostname
29
+ @current_hostname ||= get_current_hostname
30
+ end
31
+
32
+ def get_current_hostname
33
+ hostname = ""
34
+ sudo "hostname -f" do |type, data|
35
+ hostname = data.chomp if type == :stdout && hostname.empty?
36
+ end
37
+
38
+ hostname
39
+ end
40
+
41
+ def update_etc_hostname
42
+ sudo("echo '#{short_hostname}' > /etc/hostname")
43
+ end
44
+
45
+ # /etc/hosts should resemble:
46
+ # 127.0.0.1 localhost
47
+ # 127.0.1.1 host.fqdn.com host.fqdn host
48
+ def update_etc_hosts
49
+ ip_address = '([0-9]{1,3}\.){3}[0-9]{1,3}'
50
+ search = "^(#{ip_address})\\s+#{Regexp.escape(current_hostname)}(\\s.*)?$"
51
+ replace = "\\1 #{fqdn} #{short_hostname}"
52
+ expression = ['s', search, replace, 'g'].join('@')
53
+
54
+ sudo("sed -ri '#{expression}' /etc/hosts")
55
+ end
56
+
57
+ def refresh_hostname_service
58
+ sudo("hostname -F /etc/hostname")
59
+ end
60
+
61
+ def fqdn
62
+ new_hostname
63
+ end
64
+
65
+ def short_hostname
66
+ new_hostname.split('.').first
67
+ end
68
+
69
+ def sudo(cmd, &block)
70
+ machine.communicate.sudo(cmd, &block)
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,98 @@
1
+ require "set"
2
+ require "tempfile"
3
+
4
+ require "vagrant/util/retryable"
5
+ require "vagrant/util/template_renderer"
6
+
7
+ module VagrantPlugins
8
+ module GuestFedora
9
+ module Cap
10
+ class ConfigureNetworks
11
+ extend Vagrant::Util::Retryable
12
+ include Vagrant::Util
13
+
14
+ def self.configure_networks(machine, networks)
15
+ network_scripts_dir = machine.guest.capability("network_scripts_dir")
16
+
17
+ virtual = false
18
+ interface_names = Array.new
19
+ machine.communicate.sudo("/usr/sbin/biosdevname; echo $?") do |_, result|
20
+ virtual = true if result.chomp == '4'
21
+ end
22
+
23
+ if virtual
24
+ machine.communicate.sudo("ls /sys/class/net | grep -v lo") do |_, result|
25
+ interface_names = result.split("\n")
26
+ end
27
+
28
+ interface_names = networks.map do |network|
29
+ "#{interface_names[network[:interface]]}"
30
+ end
31
+ else
32
+ machine.communicate.sudo("/usr/sbin/biosdevname -d | grep Kernel | cut -f2 -d: | sed -e 's/ //;'") do |_, result|
33
+ interface_names = result.split("\n")
34
+ end
35
+
36
+ interface_name_pairs = Array.new
37
+ interface_names.each do |interface_name|
38
+ machine.communicate.sudo("/usr/sbin/biosdevname --policy=all_ethN -i #{interface_name}") do |_, result|
39
+ interface_name_pairs.push([interface_name, result.gsub("\n", "")])
40
+ end
41
+ end
42
+
43
+ setting_interface_names = networks.map do |network|
44
+ "eth#{network[:interface]}"
45
+ end
46
+
47
+ interface_name_pairs.each do |interface_name, previous_interface_name|
48
+ if setting_interface_names.index(previous_interface_name) == nil
49
+ interface_names.delete(interface_name)
50
+ end
51
+ end
52
+ end
53
+
54
+ # Accumulate the configurations to add to the interfaces file as well
55
+ # as what interfaces we're actually configuring since we use that later.
56
+ interfaces = Set.new
57
+ networks.each do |network|
58
+ interface = interface_names[network[:interface]-1]
59
+ interfaces.add(interface)
60
+ network[:device] = interface
61
+
62
+ # Remove any previous vagrant configuration in this network
63
+ # interface's configuration files.
64
+ machine.communicate.sudo("touch #{network_scripts_dir}/ifcfg-#{interface}")
65
+ machine.communicate.sudo("sed -e '/^#VAGRANT-BEGIN/,/^#VAGRANT-END/ d' #{network_scripts_dir}/ifcfg-#{interface} > /tmp/vagrant-ifcfg-#{interface}")
66
+ machine.communicate.sudo("cat /tmp/vagrant-ifcfg-#{interface} > #{network_scripts_dir}/ifcfg-#{interface}")
67
+ machine.communicate.sudo("rm -f /tmp/vagrant-ifcfg-#{interface}")
68
+
69
+ # Render and upload the network entry file to a deterministic
70
+ # temporary location.
71
+ entry = TemplateRenderer.render("guests/fedora/network_#{network[:type]}",
72
+ options: network)
73
+
74
+ temp = Tempfile.new("vagrant")
75
+ temp.binmode
76
+ temp.write(entry)
77
+ temp.close
78
+
79
+ machine.communicate.upload(temp.path, "/tmp/vagrant-network-entry_#{interface}")
80
+ end
81
+
82
+ # Bring down all the interfaces we're reconfiguring. By bringing down
83
+ # each specifically, we avoid reconfiguring p7p (the NAT interface) so
84
+ # SSH never dies.
85
+ interfaces.each do |interface|
86
+ retryable(on: Vagrant::Errors::VagrantError, tries: 3, sleep: 2) do
87
+ machine.communicate.sudo("cat /tmp/vagrant-network-entry_#{interface} >> #{network_scripts_dir}/ifcfg-#{interface}")
88
+ machine.communicate.sudo("/sbin/ifdown #{interface}", error_check: true)
89
+ machine.communicate.sudo("/sbin/ifup #{interface}")
90
+ end
91
+
92
+ machine.communicate.sudo("rm -f /tmp/vagrant-network-entry_#{interface}")
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,21 @@
1
+ module VagrantPlugins
2
+ module GuestFedora
3
+ module Cap
4
+ class Flavor
5
+ def self.flavor(machine)
6
+ # Read the version file
7
+ machine.communicate.sudo("grep VERSION_ID /etc/os-release") do |type, data|
8
+ version = data.split("=")[1].chomp.to_i if type == :stdout
9
+ end
10
+
11
+ # Detect various flavors we care about
12
+ if version >= 20
13
+ return :"fedora_#{version}"
14
+ else
15
+ return :fedora
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,15 @@
1
+ module VagrantPlugins
2
+ module GuestFedora
3
+ module Cap
4
+ class NetworkScriptsDir
5
+ # The path to the directory with the network configuration scripts.
6
+ # This is pulled out into its own directory since there are other
7
+ # operating systems (SUSE) which behave similarly but with a different
8
+ # path to the network scripts.
9
+ def self.network_scripts_dir(machine)
10
+ "/etc/sysconfig/network-scripts"
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ module VagrantPlugins
2
+ module GuestFedora
3
+ module Cap
4
+ class NFSClient
5
+ def self.nfs_client_install(machine)
6
+ machine.communicate.sudo("yum -y install nfs-utils nfs-utils-lib")
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require "vagrant"
2
+
3
+ module VagrantPlugins
4
+ module GuestFedora
5
+ class Guest < Vagrant.plugin("2", :guest)
6
+ def detect?(machine)
7
+ machine.communicate.test("grep 'Fedora release [12][67890]' /etc/redhat-release")
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,41 @@
1
+ require "vagrant"
2
+
3
+ module VagrantPlugins
4
+ module GuestFedora
5
+ class Plugin < Vagrant.plugin("2")
6
+ name "Fedora guest"
7
+ description "Fedora guest support."
8
+
9
+ guest("fedora", "redhat") do
10
+ require File.expand_path("../guest", __FILE__)
11
+ Guest
12
+ end
13
+
14
+ guest_capability("fedora", "change_host_name") do
15
+ require_relative "cap/change_host_name"
16
+ Cap::ChangeHostName
17
+ end
18
+
19
+ guest_capability("fedora", "configure_networks") do
20
+ require_relative "cap/configure_networks"
21
+ Cap::ConfigureNetworks
22
+ end
23
+
24
+ guest_capability("fedora", "network_scripts_dir") do
25
+ require_relative "cap/network_scripts_dir"
26
+ Cap::NetworkScriptsDir
27
+ end
28
+
29
+ guest_capability("fedora", "flavor") do
30
+ require_relative "cap/flavor"
31
+ Cap::Flavor
32
+ end
33
+
34
+ guest_capability("fedora", "nfs_client_install") do
35
+ require_relative "cap/nfs_client"
36
+ Cap::NFSClient
37
+ end
38
+
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,11 @@
1
+ module VagrantPlugins
2
+ module GuestRedHat
3
+ module Cap
4
+ class ContainerProbeTool
5
+ def self.container_probe_tool(machine)
6
+ machine.communicate.test("/usr/bin/container-probe-tool", sudo: true)
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -4,8 +4,8 @@ module VagrantPlugins
4
4
  class Register
5
5
  def self.register(machine)
6
6
  username = machine.config.registration.subscriber_username
7
- password = machine.config.registration.subscriber_password
8
- command = "subscription-manager register --username=#{username} --password=#{password} --auto-attach"
7
+ password = machine.config.registration.subscriber_password
8
+ command = "subscription-manager register --username=#{username} --password=#{password} --auto-attach #{"--force" if machine.config.registration.force}"
9
9
  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)
10
10
  end
11
11
  end
@@ -0,0 +1,11 @@
1
+ module VagrantPlugins
2
+ module GuestRedHat
3
+ module Cap
4
+ class SubscriptionManager
5
+ def self.subscription_manager(machine)
6
+ machine.communicate.test("/sbin/subscription-manager", sudo: true)
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -4,13 +4,23 @@ module VagrantPlugins
4
4
  module GuestRedHat
5
5
  class Plugin < Vagrant.plugin("2")
6
6
  guest_capability("redhat", "register") do
7
- require_relative "cap/register"
8
- Cap::Register
7
+ require_relative "cap/register"
8
+ Cap::Register
9
9
  end
10
-
10
+
11
11
  guest_capability("redhat", "unregister") do
12
- require_relative "cap/unregister"
13
- Cap::Unregister
12
+ require_relative "cap/unregister"
13
+ Cap::Unregister
14
+ end
15
+
16
+ guest_capability("redhat", "subscription_manager") do
17
+ require_relative "cap/subscription_manager"
18
+ Cap::SubscriptionManager
19
+ end
20
+
21
+ guest_capability("redhat", "container_probe_tool") do
22
+ require_relative "cap/container_probe_tool"
23
+ Cap::ContainerProbeTool
14
24
  end
15
25
  end
16
26
  end
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: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Langdon White
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-01-13 00:00:00.000000000 Z
12
+ date: 2015-02-12 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Enables guests to have a registration capability, this is expecially
15
15
  useful on RHEL or SLES
@@ -18,32 +18,42 @@ executables: []
18
18
  extensions: []
19
19
  extra_rdoc_files: []
20
20
  files:
21
- - .gitignore
22
- - CHANGELOG.md
23
- - Gemfile
21
+ - locales/en.yml
22
+ - ides.sh
23
+ - vagrant-registration.gemspec
24
24
  - LICENSE.md
25
+ - tests/shell-scripts/test-rhel-eco-ident/Vagrantfile.fedora
26
+ - tests/shell-scripts/test-rhel-eco-ident/Vagrantfile.rhel
27
+ - tests/shell-scripts/test-rhel-eco-ident/Vagrantfile.centos
28
+ - tests/shell-scripts/test-rhel-eco-ident/test-identification.sh
29
+ - dummy.box
25
30
  - README.md
26
- - Rakefile
27
31
  - Vagrantfile
28
- - dummy.box
29
- - lib/vagrant-registration.rb
30
- - lib/vagrant-registration/action.rb
31
- - lib/vagrant-registration/action/register.rb
32
+ - lib/vagrant-registration/plugin.rb
33
+ - lib/vagrant-registration/errors.rb
32
34
  - lib/vagrant-registration/action/unregister.rb
35
+ - lib/vagrant-registration/action/register.rb
33
36
  - lib/vagrant-registration/config.rb
34
- - lib/vagrant-registration/env.rb
35
- - lib/vagrant-registration/errors.rb
36
- - lib/vagrant-registration/plugin.rb
37
37
  - lib/vagrant-registration/version.rb
38
- - locales/en.yml
39
- - plugins/guests/redhat/cap/register.rb
40
- - plugins/guests/redhat/cap/unregister.rb
38
+ - lib/vagrant-registration/env.rb
39
+ - lib/vagrant-registration/action.rb
40
+ - lib/vagrant-registration.rb
41
+ - CHANGELOG.md
42
+ - Rakefile
41
43
  - plugins/guests/redhat/plugin.rb
42
- - tests/shell-scripts/test-rhel-eco-ident/Vagrantfile.centos
43
- - tests/shell-scripts/test-rhel-eco-ident/Vagrantfile.fedora
44
- - tests/shell-scripts/test-rhel-eco-ident/Vagrantfile.rhel
45
- - tests/shell-scripts/test-rhel-eco-ident/test-identification.sh
46
- - vagrant-registration.gemspec
44
+ - plugins/guests/redhat/cap/container_probe_tool.rb
45
+ - plugins/guests/redhat/cap/unregister.rb
46
+ - plugins/guests/redhat/cap/register.rb
47
+ - plugins/guests/redhat/cap/subscription_manager.rb
48
+ - plugins/guests/fedora/plugin.rb
49
+ - plugins/guests/fedora/guest.rb
50
+ - plugins/guests/fedora/cap/flavor.rb
51
+ - plugins/guests/fedora/cap/nfs_client.rb
52
+ - plugins/guests/fedora/cap/configure_networks.rb
53
+ - plugins/guests/fedora/cap/change_host_name.rb
54
+ - plugins/guests/fedora/cap/network_scripts_dir.rb
55
+ - Gemfile
56
+ - .gitignore
47
57
  homepage:
48
58
  licenses:
49
59
  - GPL-2.0
@@ -64,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
64
74
  version: 1.3.6
65
75
  requirements: []
66
76
  rubyforge_project: vagrant-registration
67
- rubygems_version: 2.4.5
77
+ rubygems_version: 2.0.14
68
78
  signing_key:
69
79
  specification_version: 4
70
80
  summary: Enables guests to have a registration capability