vagrant-service-manager 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ci/ansible/roles/centos/tasks/main.yml +3 -2
- data/.ci/jenkins-execute-script.py +6 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +13 -0
- data/.rubocop_todo.yml +55 -0
- data/CHANGELOG.md +22 -1
- data/CONTRIBUTING.adoc +6 -6
- data/Gemfile +12 -4
- data/README.adoc +104 -70
- data/Rakefile +235 -66
- data/features/box-command.feature +26 -1
- data/features/env-command.feature +20 -3
- data/features/help-command.feature +4 -1
- data/features/install-cli.feature +58 -0
- data/features/openshift.feature +2 -1
- data/features/service-operation.feature +76 -3
- data/features/support/env.rb +26 -10
- data/lib/vagrant-service-manager.rb +7 -2
- data/lib/vagrant-service-manager/action/setup_network.rb +0 -2
- data/lib/vagrant-service-manager/archive_handlers/tar_handler.rb +26 -0
- data/lib/vagrant-service-manager/archive_handlers/zip_handler.rb +25 -0
- data/lib/vagrant-service-manager/binary_handlers/adb_binary_handler.rb +55 -0
- data/lib/vagrant-service-manager/binary_handlers/adb_docker_binary_handler.rb +38 -0
- data/lib/vagrant-service-manager/binary_handlers/adb_openshift_binary_handler.rb +49 -0
- data/lib/vagrant-service-manager/binary_handlers/binary_handler.rb +119 -0
- data/lib/vagrant-service-manager/binary_handlers/cdk_binary_handler.rb +33 -0
- data/lib/vagrant-service-manager/binary_handlers/cdk_docker_binary_handler.rb +9 -0
- data/lib/vagrant-service-manager/binary_handlers/cdk_openshift_binary_handler.rb +9 -0
- data/lib/vagrant-service-manager/command.rb +90 -15
- data/lib/vagrant-service-manager/config.rb +8 -8
- data/lib/vagrant-service-manager/installer.rb +49 -0
- data/lib/vagrant-service-manager/plugin.rb +2 -2
- data/lib/vagrant-service-manager/plugin_logger.rb +2 -2
- data/lib/vagrant-service-manager/plugin_util.rb +29 -6
- data/lib/vagrant-service-manager/service.rb +4 -3
- data/lib/vagrant-service-manager/service_base.rb +11 -0
- data/lib/vagrant-service-manager/services/docker.rb +29 -29
- data/lib/vagrant-service-manager/services/kubernetes.rb +7 -7
- data/lib/vagrant-service-manager/services/open_shift.rb +42 -41
- data/lib/vagrant-service-manager/version.rb +1 -1
- data/locales/en.yml +42 -4
- data/plugins/guests/redhat/cap/machine_ip.rb +2 -1
- data/plugins/guests/redhat/plugin.rb +1 -1
- data/plugins/hosts/darwin/cap/os_arch.rb +11 -0
- data/plugins/hosts/darwin/plugin.rb +13 -0
- data/plugins/hosts/linux/cap/os_arch.rb +11 -0
- data/plugins/hosts/linux/plugin.rb +13 -0
- data/plugins/hosts/windows/cap/os_arch.rb +18 -0
- data/plugins/hosts/windows/plugin.rb +13 -0
- data/test/test_data/docker-1.10.0.tar.gz +0 -0
- data/test/test_data/docker-1.11.0.tgz +0 -0
- data/test/test_data/docker-1.9.1.zip +0 -0
- data/test/test_data/openshift-origin-client-tools-v1.2.0-2e62fab-linux-64bit.tar.gz +0 -0
- data/test/test_data/openshift-origin-client-tools-v1.2.0-2e62fab-linux-64bit.zip +0 -0
- data/test/test_data/openshift-origin-client-tools-v1.2.0-2e62fab-mac.zip +0 -0
- data/test/test_helper.rb +121 -0
- data/test/vagrant-service-manager/archive_handler_test.rb +49 -0
- data/test/vagrant-service-manager/binary_handlers/adb_docker_binary_handler_test.rb +111 -0
- data/test/vagrant-service-manager/binary_handlers/adb_openshift_binary_handler_test.rb +107 -0
- data/test/vagrant-service-manager/installer_test.rb +96 -0
- data/vagrant-service-manager.gemspec +4 -3
- metadata +43 -16
- data/TODO +0 -24
- data/Vagrantfile +0 -29
- data/lib/vagrant-service-manager/os.rb +0 -22
- data/vagrant-service-manager.spec +0 -215
@@ -0,0 +1,49 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module ServiceManager
|
3
|
+
class ADBOpenshiftBinaryHandler < ADBBinaryHandler
|
4
|
+
OC_BINARY_BASE_URL = 'https://github.com/openshift/origin/releases'.freeze
|
5
|
+
OC_FILE_PREFIX = 'openshift-origin-client-tools'.freeze
|
6
|
+
|
7
|
+
def initialize(machine, env, options)
|
8
|
+
super(machine, env, options)
|
9
|
+
end
|
10
|
+
|
11
|
+
def build_download_url
|
12
|
+
download_base_path = "#{OC_BINARY_BASE_URL}/download/v#{@version}/"
|
13
|
+
file = "#{OC_FILE_PREFIX}-v#{@version}-#{version_sha}-#{archive_ext}"
|
14
|
+
@url = download_base_path + file
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def version_sha
|
20
|
+
tag_url = "#{OC_BINARY_BASE_URL}/tag/v#{@version}"
|
21
|
+
data = Net::HTTP.get(URI(tag_url))
|
22
|
+
tokens = data.match("-v#{@version}-(.*)-#{archive_ext}").captures
|
23
|
+
tokens.first unless tokens.empty?
|
24
|
+
rescue StandardError => e
|
25
|
+
@ui.error e.message
|
26
|
+
exit 126
|
27
|
+
end
|
28
|
+
|
29
|
+
def os_type
|
30
|
+
if Vagrant::Util::Platform.windows?
|
31
|
+
'windows'
|
32
|
+
elsif Vagrant::Util::Platform.linux?
|
33
|
+
'linux'
|
34
|
+
elsif Vagrant::Util::Platform.darwin?
|
35
|
+
'mac'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def arch
|
40
|
+
arch = @machine.env.host.capability(:os_arch)
|
41
|
+
arch == 'x86_64' ? '64' : '32'
|
42
|
+
end
|
43
|
+
|
44
|
+
def archive_ext
|
45
|
+
os_type + (os_type == 'linux' ? "-#{arch}bit.tar.gz" : '.zip')
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,119 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
3
|
+
module VagrantPlugins
|
4
|
+
module ServiceManager
|
5
|
+
class URLValidationError < Vagrant::Errors::VagrantError
|
6
|
+
error_key(:url_validation_error)
|
7
|
+
end
|
8
|
+
|
9
|
+
class BinaryHandler
|
10
|
+
BINARY_ARCHIVE_FORMATS = ['.tgz', '.tar.gz', '.gz', '.zip'].freeze
|
11
|
+
BINARY_NAME = {
|
12
|
+
docker: 'docker', openshift: 'oc'
|
13
|
+
}.freeze
|
14
|
+
VERSION_CMD = {
|
15
|
+
docker: "docker version --format '{{.Server.Version}}'",
|
16
|
+
openshift: "oc version | grep 'oc' | grep -oE '[0-9.]+'"
|
17
|
+
}.freeze
|
18
|
+
BINARY_REGEX = {
|
19
|
+
windows: { docker: %r{\/docker.exe$}, openshift: /oc.exe$/ },
|
20
|
+
unix: { docker: %r{\/docker$}, openshift: /oc$/ }
|
21
|
+
}.freeze
|
22
|
+
ARCHIVE_MAP = {
|
23
|
+
'.tgz' => 'Tar', '.tar.gz' => 'Tar', '.gz' => 'Tar', '.zip' => 'Zip'
|
24
|
+
}.freeze
|
25
|
+
LABEL = 'servicemanager.commands.install_cli.message'.freeze
|
26
|
+
|
27
|
+
attr_accessor :path, :version, :type, :url,
|
28
|
+
:binary_exists, :skip_download, :archive_file_path
|
29
|
+
|
30
|
+
def initialize(machine, env, options)
|
31
|
+
@machine = machine
|
32
|
+
@ui = env.ui
|
33
|
+
@url = ''
|
34
|
+
@binary_exists = true
|
35
|
+
@skip_download = false
|
36
|
+
@archive_file_path = ''
|
37
|
+
@options = options
|
38
|
+
@type = options[:type]
|
39
|
+
@version = options['--cli-version'] || PluginUtil.execute_once(@machine, @ui, VERSION_CMD[@type])
|
40
|
+
@path = options['--path'] || binary_path
|
41
|
+
@temp_bin_dir = "#{ServiceManager.temp_dir}/#{@type}"
|
42
|
+
end
|
43
|
+
|
44
|
+
def install
|
45
|
+
build_download_url
|
46
|
+
validate_url
|
47
|
+
build_archive_path
|
48
|
+
ensure_binary_and_temp_directories
|
49
|
+
download_archive
|
50
|
+
prepare_binary
|
51
|
+
end
|
52
|
+
|
53
|
+
def build_download_url
|
54
|
+
end
|
55
|
+
|
56
|
+
def build_archive_path
|
57
|
+
end
|
58
|
+
|
59
|
+
def ensure_binary_and_temp_directories
|
60
|
+
end
|
61
|
+
|
62
|
+
def download_archive
|
63
|
+
end
|
64
|
+
|
65
|
+
def prepare_binary
|
66
|
+
end
|
67
|
+
|
68
|
+
def print_message
|
69
|
+
end
|
70
|
+
|
71
|
+
def archive_dir_name
|
72
|
+
@archive_file_path.sub(Regexp.new(BINARY_ARCHIVE_FORMATS.join('|')), '')
|
73
|
+
end
|
74
|
+
|
75
|
+
def archive_handler_class
|
76
|
+
Object.const_get("#{ServiceManager.name}::#{archive_handler_name}")
|
77
|
+
end
|
78
|
+
|
79
|
+
def binary_name
|
80
|
+
BINARY_NAME[@type] + binary_ext
|
81
|
+
end
|
82
|
+
|
83
|
+
def binary_ext
|
84
|
+
Vagrant::Util::Platform.windows? ? '.exe' : ''
|
85
|
+
end
|
86
|
+
|
87
|
+
def bin_dir
|
88
|
+
File.dirname(@path)
|
89
|
+
end
|
90
|
+
|
91
|
+
def file_regex
|
92
|
+
os_type = Vagrant::Util::Platform.windows? ? :windows : :unix
|
93
|
+
BINARY_REGEX[os_type][@type]
|
94
|
+
end
|
95
|
+
|
96
|
+
# Checks if url is accessible or not
|
97
|
+
def validate_url
|
98
|
+
url = URI.parse(@url)
|
99
|
+
req = Net::HTTP.new(url.host, url.port)
|
100
|
+
req.use_ssl = true if url.scheme == 'https'
|
101
|
+
res = req.request_head(url.path)
|
102
|
+
|
103
|
+
unless res.code == '200'
|
104
|
+
raise URLValidationError, I18n.t('servicemanager.commands.install_cli.url_validation_error')
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
private
|
109
|
+
|
110
|
+
def archive_handler_name
|
111
|
+
ARCHIVE_MAP[File.extname(@url)] + 'Handler'
|
112
|
+
end
|
113
|
+
|
114
|
+
def binary_path
|
115
|
+
"#{ServiceManager.bin_dir}/#{@type}/#{@version}/#{binary_name}"
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module ServiceManager
|
3
|
+
class CDKBinaryHandler < BinaryHandler
|
4
|
+
def initialize(machine, env, options = {})
|
5
|
+
super(machine, env, options)
|
6
|
+
end
|
7
|
+
|
8
|
+
# TODO
|
9
|
+
def build_download_url
|
10
|
+
end
|
11
|
+
|
12
|
+
# TODO
|
13
|
+
def build_archive_path
|
14
|
+
end
|
15
|
+
|
16
|
+
# TODO
|
17
|
+
def ensure_binary_and_temp_directories
|
18
|
+
end
|
19
|
+
|
20
|
+
# TODO
|
21
|
+
def download_archive
|
22
|
+
end
|
23
|
+
|
24
|
+
# TODO
|
25
|
+
def prepare_binary
|
26
|
+
end
|
27
|
+
|
28
|
+
# TODO
|
29
|
+
def print_message
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -1,25 +1,50 @@
|
|
1
|
-
require_relative 'os'
|
2
1
|
require 'digest'
|
3
2
|
require_relative 'plugin_util'
|
4
3
|
require_relative 'plugin_logger'
|
4
|
+
require_relative 'installer'
|
5
|
+
require_relative 'archive_handlers/tar_handler'
|
6
|
+
require_relative 'archive_handlers/zip_handler'
|
7
|
+
require_relative 'binary_handlers/binary_handler'
|
8
|
+
require_relative 'binary_handlers/adb_binary_handler'
|
9
|
+
require_relative 'binary_handlers/cdk_binary_handler'
|
10
|
+
require_relative 'binary_handlers/adb_docker_binary_handler'
|
11
|
+
require_relative 'binary_handlers/adb_openshift_binary_handler'
|
12
|
+
require_relative 'binary_handlers/cdk_docker_binary_handler'
|
13
|
+
require_relative 'binary_handlers/cdk_openshift_binary_handler'
|
5
14
|
|
6
15
|
module VagrantPlugins
|
7
16
|
module ServiceManager
|
8
|
-
DOCKER_PATH = '/home/vagrant/.docker'
|
9
|
-
SUPPORTED_SERVICES =
|
17
|
+
DOCKER_PATH = '/home/vagrant/.docker'.freeze
|
18
|
+
SUPPORTED_SERVICES = %w(docker openshift kubernetes).freeze
|
10
19
|
KUBE_SERVICES = [
|
11
20
|
'etcd', 'kube-apiserver', 'kube-controller-manager', 'kube-scheduler',
|
12
21
|
'kubelet', 'kube-proxy', 'docker'
|
13
|
-
]
|
22
|
+
].freeze
|
14
23
|
# NOTE: SERVICES_MAP[<service>] will give fully-qualified service class name
|
15
24
|
# Eg: SERVICES_MAP['docker'] gives Vagrant::ServiceManager::Docker
|
16
25
|
SERVICES_MAP = {
|
17
26
|
'docker' => Docker, 'openshift' => OpenShift,
|
18
27
|
'kubernetes' => Kubernetes
|
19
|
-
}
|
28
|
+
}.freeze
|
29
|
+
|
30
|
+
def self.bin_dir
|
31
|
+
@bin_dir
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.temp_dir
|
35
|
+
@temp_dir
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.bin_dir=(path)
|
39
|
+
@bin_dir = path
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.temp_dir=(path)
|
43
|
+
@temp_dir = path
|
44
|
+
end
|
20
45
|
|
21
46
|
class Command < Vagrant.plugin(2, :command)
|
22
|
-
OS_RELEASE_FILE = '/etc/os-release'
|
47
|
+
OS_RELEASE_FILE = '/etc/os-release'.freeze
|
23
48
|
|
24
49
|
def self.synopsis
|
25
50
|
I18n.t('servicemanager.synopsis')
|
@@ -37,11 +62,14 @@ module VagrantPlugins
|
|
37
62
|
end
|
38
63
|
|
39
64
|
def execute
|
65
|
+
ServiceManager.bin_dir = "#{@env.data_dir}/service-manager/bin"
|
66
|
+
ServiceManager.temp_dir = "#{@env.data_dir}/service-manager/tmp"
|
67
|
+
|
40
68
|
argv = ARGV.dup
|
41
69
|
# Don't propagate --debug argument to case operation
|
42
70
|
if ARGV.include? '--debug'
|
43
71
|
PluginLogger.enable_debug_mode
|
44
|
-
PluginLogger.
|
72
|
+
PluginLogger.logger = @logger
|
45
73
|
argv.delete('--debug')
|
46
74
|
end
|
47
75
|
|
@@ -100,6 +128,8 @@ module VagrantPlugins
|
|
100
128
|
case option
|
101
129
|
when nil
|
102
130
|
display_box_ip
|
131
|
+
when '--script-readable'
|
132
|
+
display_box_ip(true)
|
103
133
|
when '--help', '-h'
|
104
134
|
print_help(type: command)
|
105
135
|
else
|
@@ -118,6 +148,19 @@ module VagrantPlugins
|
|
118
148
|
else
|
119
149
|
perform_service(command, subcommand)
|
120
150
|
end
|
151
|
+
when 'install-cli'
|
152
|
+
exit_if_machine_not_running
|
153
|
+
# Transform hyphen into underscore which is valid char in method
|
154
|
+
command = command.tr('-', '_')
|
155
|
+
# Get options as Hash which are preceeded with -- like --version
|
156
|
+
options = Hash[ARGV.drop(3).each_slice(2).to_a]
|
157
|
+
|
158
|
+
case subcommand
|
159
|
+
when '--help', '-h'
|
160
|
+
print_help(type: command)
|
161
|
+
else
|
162
|
+
execute_install_cli(subcommand, options)
|
163
|
+
end
|
121
164
|
when '--help', '-h', 'help'
|
122
165
|
print_help
|
123
166
|
else
|
@@ -127,7 +170,7 @@ module VagrantPlugins
|
|
127
170
|
|
128
171
|
def execute_service(name, options = {})
|
129
172
|
with_target_vms(nil, single_target: true) do |machine|
|
130
|
-
PluginUtil.service_class(name).
|
173
|
+
PluginUtil.service_class(name).new(machine, @env).info(options)
|
131
174
|
end
|
132
175
|
end
|
133
176
|
|
@@ -142,16 +185,15 @@ module VagrantPlugins
|
|
142
185
|
def execute_status_display(service = nil)
|
143
186
|
with_target_vms(nil, single_target: true) do |machine|
|
144
187
|
if service && SUPPORTED_SERVICES.include?(service)
|
145
|
-
PluginUtil.service_class(service).
|
188
|
+
PluginUtil.service_class(service).new(machine, @env).status
|
146
189
|
elsif service.nil?
|
147
190
|
@env.ui.info I18n.t('servicemanager.commands.status.nil')
|
148
191
|
SUPPORTED_SERVICES.each do |s|
|
149
|
-
PluginUtil.service_class(s).
|
192
|
+
PluginUtil.service_class(s).new(machine, @env).status
|
150
193
|
end
|
151
194
|
else
|
152
195
|
@env.ui.error I18n.t('servicemanager.commands.status.unsupported_service',
|
153
|
-
|
154
|
-
services: SUPPORTED_SERVICES.join(', ') + ' etc')
|
196
|
+
service: service, services: SUPPORTED_SERVICES.join(', ') + ' etc')
|
155
197
|
exit 126
|
156
198
|
end
|
157
199
|
end
|
@@ -169,7 +211,7 @@ module VagrantPlugins
|
|
169
211
|
end
|
170
212
|
# since we do not have feature to show the Kube connection information
|
171
213
|
unless service == 'kubernetes'
|
172
|
-
service_class.
|
214
|
+
service_class.new(machine, @env).info(options)
|
173
215
|
end
|
174
216
|
end
|
175
217
|
|
@@ -207,9 +249,42 @@ module VagrantPlugins
|
|
207
249
|
end
|
208
250
|
end
|
209
251
|
|
210
|
-
def display_box_ip
|
252
|
+
def display_box_ip(script_readable = false)
|
253
|
+
options = { script_readable: script_readable }
|
254
|
+
|
255
|
+
with_target_vms(nil, single_target: true) do |machine|
|
256
|
+
@env.ui.info machine.guest.capability(:machine_ip, options)
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
def execute_install_cli(service, options = {})
|
261
|
+
help_msg = I18n.t('servicemanager.commands.help.install_cli')
|
262
|
+
|
263
|
+
if service.nil?
|
264
|
+
service_missing_msg = I18n.t('servicemanager.commands.operation.service_missing')
|
265
|
+
@env.ui.error help_msg.gsub(/Install the client side tool for the service/, service_missing_msg)
|
266
|
+
exit 126
|
267
|
+
end
|
268
|
+
|
269
|
+
unless SUPPORTED_SERVICES.include?(service)
|
270
|
+
@env.ui.error "Unknown service '#{service}'."
|
271
|
+
@env.ui.error help_msg.gsub(/Install the client side tool for the service\n/, '')
|
272
|
+
exit 126
|
273
|
+
end
|
274
|
+
|
211
275
|
with_target_vms(nil, single_target: true) do |machine|
|
212
|
-
@env
|
276
|
+
args = [service.to_sym, machine, @env, options]
|
277
|
+
|
278
|
+
begin
|
279
|
+
args.last[:box_version] = machine.guest.capability(:os_variant)
|
280
|
+
Installer.new(*args).install
|
281
|
+
rescue Vagrant::Errors::GuestCapabilityNotFound
|
282
|
+
@env.ui.info 'Not a supported box.'
|
283
|
+
exit 126
|
284
|
+
rescue StandardError => e
|
285
|
+
@env.ui.error e.message
|
286
|
+
exit 126
|
287
|
+
end
|
213
288
|
end
|
214
289
|
end
|
215
290
|
end
|
@@ -2,18 +2,18 @@ require 'set'
|
|
2
2
|
|
3
3
|
module VagrantPlugins
|
4
4
|
module ServiceManager
|
5
|
-
SERVICES =
|
6
|
-
CONFIG_KEYS
|
5
|
+
SERVICES = %w(docker openshift).freeze
|
6
|
+
CONFIG_KEYS = [
|
7
7
|
:services, :openshift_docker_registry,
|
8
8
|
:openshift_image_name, :openshift_image_tag
|
9
|
-
]
|
9
|
+
].freeze
|
10
10
|
|
11
11
|
class Config < Vagrant.plugin('2', :config)
|
12
12
|
attr_accessor(*CONFIG_KEYS)
|
13
13
|
|
14
14
|
DEFAULTS = {
|
15
15
|
services: ''
|
16
|
-
}
|
16
|
+
}.freeze
|
17
17
|
|
18
18
|
def initialize
|
19
19
|
super
|
@@ -28,10 +28,10 @@ module VagrantPlugins
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
-
def validate(
|
31
|
+
def validate(_machine)
|
32
32
|
errors = _detected_errors
|
33
33
|
errors.concat(validate_services)
|
34
|
-
{
|
34
|
+
{ 'servicemanager' => errors }
|
35
35
|
end
|
36
36
|
|
37
37
|
private
|
@@ -39,7 +39,7 @@ module VagrantPlugins
|
|
39
39
|
def validate_services
|
40
40
|
errors = []
|
41
41
|
|
42
|
-
unless
|
42
|
+
unless supported_services?
|
43
43
|
errors << I18n.t('servicemanager.config.supported_devices',
|
44
44
|
services: SERVICES.inspect)
|
45
45
|
end
|
@@ -47,7 +47,7 @@ module VagrantPlugins
|
|
47
47
|
errors
|
48
48
|
end
|
49
49
|
|
50
|
-
def
|
50
|
+
def supported_services?
|
51
51
|
@services.split(',').map(&:strip).to_set.subset?(SERVICES.to_set)
|
52
52
|
end
|
53
53
|
end
|