File tree 10 files changed +136
-30
lines changed
10 files changed +136
-30
lines changed Original file line number Diff line number Diff line change
1
+ module VagrantPlugins
2
+ module GuestCentos
3
+ module Cap
4
+ class Flavor
5
+ def self . flavor ( machine )
6
+ # Read the version file
7
+ output = ""
8
+ machine . communicate . sudo ( "cat /etc/centos-release" ) do |_ , data |
9
+ output = data
10
+ end
11
+
12
+ # Detect various flavors we care about
13
+ if output =~ /(CentOS)( .+)? 7/i
14
+ return :centos_7
15
+ elsif output =~ /(CentOS)( .+)? 8/i
16
+ return :centos_8
17
+ else
18
+ return :centos
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
Original file line number Diff line number Diff line change
1
+ module VagrantPlugins
2
+ module GuestCentos
3
+ class Guest < Vagrant . plugin ( "2" , :guest )
4
+ def detect? ( machine )
5
+ machine . communicate . test ( "cat /etc/centos-release" )
6
+ end
7
+ end
8
+ end
9
+ end
Original file line number Diff line number Diff line change
1
+ require "vagrant"
2
+
3
+ module VagrantPlugins
4
+ module GuestCentos
5
+ class Plugin < Vagrant . plugin ( "2" )
6
+ name "CentOS guest"
7
+ description "CentOS guest support."
8
+
9
+ guest ( :centos , :redhat ) do
10
+ require_relative "guest"
11
+ Guest
12
+ end
13
+
14
+ guest_capability ( :centos , :flavor ) do
15
+ require_relative "cap/flavor"
16
+ Cap ::Flavor
17
+ end
18
+ end
19
+ end
20
+ end
Original file line number Diff line number Diff line change @@ -10,8 +10,10 @@ def self.flavor(machine)
10
10
end
11
11
12
12
# Detect various flavors we care about
13
- if output =~ /(CentOS| Red Hat Enterprise|Scientific|Cloud|Virtuozzo)\s *Linux( .+)? release 7/i
13
+ if output =~ /(Red Hat Enterprise|Scientific|Cloud|Virtuozzo)\s *Linux( .+)? release 7/i
14
14
return :rhel_7
15
+ elsif output =~ /(Red Hat Enterprise|Scientific|Cloud|Virtuozzo)\s *Linux( .+)? release 8/i
16
+ return :rhel_8
15
17
else
16
18
return :rhel
17
19
end
Original file line number Diff line number Diff line change 1
1
module VagrantPlugins
2
2
module DockerProvisioner
3
3
module Cap
4
- module Redhat
4
+ module Centos
5
5
module DockerInstall
6
6
def self . docker_install ( machine )
7
7
machine . communicate . tap do |comm |
8
8
comm . sudo ( "yum -q -y update" )
9
9
comm . sudo ( "yum -q -y remove docker-io* || true" )
10
- comm . sudo ( "curl -sSL https://get.docker.com/ | sh" )
10
+ comm . sudo ( "yum install -y -q yum-utils" )
11
+ comm . sudo ( "yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo" )
12
+ comm . sudo ( "yum makecache" )
13
+ comm . sudo ( "yum install -y -q docker-ce" )
11
14
end
12
15
13
16
case machine . guest . capability ( "flavor" )
14
- when :rhel_7
15
- docker_enable_rhel7 ( machine )
17
+ when :centos
18
+ docker_enable_service ( machine )
16
19
else
17
- docker_enable_default ( machine )
20
+ docker_enable_systemctl ( machine )
18
21
end
19
22
end
20
23
21
- def self . docker_enable_rhel7 ( machine )
24
+ def self . docker_enable_systemctl ( machine )
22
25
machine . communicate . tap do |comm |
23
26
comm . sudo ( "systemctl start docker.service" )
24
27
comm . sudo ( "systemctl enable docker.service" )
25
28
end
26
29
end
27
30
28
- def self . docker_enable_default ( machine )
31
+ def self . docker_enable_service ( machine )
29
32
machine . communicate . tap do |comm |
30
33
comm . sudo ( "service docker start" )
31
34
comm . sudo ( "chkconfig docker on" )
Original file line number Diff line number Diff line change
1
+ module VagrantPlugins
2
+ module DockerProvisioner
3
+ module Cap
4
+ module Centos
5
+ module DockerStartService
6
+ def self . docker_start_service ( machine )
7
+ case machine . guest . capability ( "flavor" )
8
+ when :centos
9
+ machine . communicate . tap do |comm |
10
+ comm . sudo ( "service docker start" )
11
+ comm . sudo ( "chkconfig docker on" )
12
+ end
13
+ else
14
+ machine . communicate . tap do |comm |
15
+ comm . sudo ( "systemctl start docker.service" )
16
+ comm . sudo ( "systemctl enable docker.service" )
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -29,14 +29,14 @@ class Plugin < Vagrant.plugin("2")
29
29
Cap ::Fedora ::DockerInstall
30
30
end
31
31
32
- guest_capability ( "redhat " , "docker_install" ) do
32
+ guest_capability ( "centos " , "docker_install" ) do
33
33
require_relative "cap/redhat/docker_install"
34
- Cap ::Redhat ::DockerInstall
34
+ Cap ::Centos ::DockerInstall
35
35
end
36
36
37
- guest_capability ( "redhat " , "docker_start_service" ) do
37
+ guest_capability ( "centos " , "docker_start_service" ) do
38
38
require_relative "cap/redhat/docker_start_service"
39
- Cap ::Redhat ::DockerStartService
39
+ Cap ::Centos ::DockerStartService
40
40
end
41
41
42
42
guest_capability ( "linux" , "docker_installed" ) do
Original file line number Diff line number Diff line change
1
+ require_relative "../../../../base"
2
+
3
+ describe "VagrantPlugins::GuestCentos::Cap::Flavor" do
4
+ let ( :caps ) do
5
+ VagrantPlugins ::GuestCentos ::Plugin
6
+ . components
7
+ . guest_capabilities [ :centos ]
8
+ end
9
+
10
+ let ( :machine ) { double ( "machine" ) }
11
+ let ( :comm ) { VagrantTests ::DummyCommunicator ::Communicator . new ( machine ) }
12
+
13
+ before do
14
+ allow ( machine ) . to receive ( :communicate ) . and_return ( comm )
15
+ end
16
+
17
+ after do
18
+ comm . verify_expectations!
19
+ end
20
+
21
+ describe ".flavor" do
22
+ let ( :cap ) { caps . get ( :flavor ) }
23
+
24
+ {
25
+ "CentOS Linux 2.4 release 7" => :centos_7 ,
26
+ "CentOS Linux release 8.1.1911 (Core)" => :centos_8 ,
27
+
28
+ "CentOS" => :centos ,
29
+ "banana" => :centos ,
30
+ } . each do |str , expected |
31
+ it "returns #{ expected } for #{ str } " do
32
+ comm . stub_command ( "cat /etc/centos-release" , stdout : str )
33
+ expect ( cap . flavor ( machine ) ) . to be ( expected )
34
+ end
35
+ end
36
+ end
37
+ end
Original file line number Diff line number Diff line change 22
22
let ( :cap ) { caps . get ( :flavor ) }
23
23
24
24
{
25
- "CentOS Linux 2.4 release 7" => :rhel_7 ,
25
+ "Red Hat Enterprise Linux 2.4 release 7" => :rhel_7 ,
26
26
"Red Hat Enterprise Linux release 7" => :rhel_7 ,
27
27
"Scientific Linux release 7" => :rhel_7 ,
28
28
"CloudLinux release 7.2 (Valeri Kubasov)" => :rhel_7 ,
29
29
30
- "CentOS" => :rhel ,
30
+ "CloudLinux release 8.1.1911 (Valeri Kubasov)" => :rhel_8 ,
31
+ "Red Hat Enterprise Linux release 8" => :rhel_8 ,
32
+
33
+ "Red Hat Enterprise Linux" => :rhel ,
31
34
"RHEL 6" => :rhel ,
32
35
"banana" => :rhel ,
33
36
} . each do |str , expected |
You can’t perform that action at this time.
0 commit comments