vagrant-turbo 0.0.1.pre-x86-mingw32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9da0e1e6b667c0770942f47f7be4835b2b380420
4
+ data.tar.gz: 5a2763df19767646a53b4b4404f6bff7cd784bde
5
+ SHA512:
6
+ metadata.gz: 455d00d19f379470967136760f379270202945004afc8ccec948400ef0d4ab2b1eab438d855599be3d2d5a036fdb86f7802d13ccb510d4ee1beff1c10e29575d
7
+ data.tar.gz: ab7c1e9fd36a6446e559a1024f4811b7381e17ff58584d50f240a4376cb8ab8f2a7944a429d021d6cc026f93782e293b6cb1e262dbdd50b55e6a921e312e3534
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ # Bundler/Rubygems
2
+ *.gem
3
+ .bundle
4
+ pkg/*
5
+ tags
6
+ Gemfile.lock
7
+
8
+ # Vagrant
9
+ .vagrant
10
+ Vagrantfile
11
+ images
12
+
13
+ # RVM files for gemset/ruby setting
14
+ .ruby-*
15
+ .rvmrc
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+
3
+ group :development do
4
+ gem "vagrant", git: "https://github.com/mitchellh/vagrant.git"
5
+ end
6
+
7
+ group :plugins do
8
+ gemspec
9
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Michael Kalygin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # Vagrant::Turbo
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/vagrant/turbo`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'vagrant-turbo'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install vagrant-turbo
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ Build locally
34
+ ```
35
+ gem build vagrant-turbo.gemspec
36
+ ```
37
+
38
+ Run local build in Vagrant context
39
+ ```
40
+ bundle exec <vagrant command>
41
+ ```
42
+
43
+ ## Contributing
44
+
45
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/vagrant-turbo. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
46
+
47
+ ## License
48
+
49
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
50
+
data/Rakefile ADDED
@@ -0,0 +1,21 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'rspec/core/rake_task'
4
+
5
+ # Immediately sync all stdout so that tools like buildbot can
6
+ # immediately load in the output.
7
+ $stdout.sync = true
8
+ $stderr.sync = true
9
+
10
+ # Change to the directory of this file.
11
+ Dir.chdir(File.expand_path("../", __FILE__))
12
+
13
+ # This installs the tasks that help with gem creation and
14
+ # publishing.
15
+ Bundler::GemHelper.install_tasks
16
+
17
+ # Install the `spec` task so that we can run tests.
18
+ RSpec::Core::RakeTask.new
19
+
20
+ # Default task is to run the unit tests
21
+ task :default => "spec"
@@ -0,0 +1,19 @@
1
+ module VagrantPlugins
2
+ module Turbo
3
+ module Cap
4
+ module Windows
5
+ module TurboInstall
6
+ INSTALLER_URL = "\"http://start.spoon.net/install/?&brand=turbo\""
7
+ INSTALLER_PATH = "\"$env:temp\\installer.exe\""
8
+
9
+ def self.turbo_install(machine)
10
+ # TODO: use Vagrant utility to download files
11
+ machine.communicate.sudo("(new-object System.Net.WebClient).DownloadFile(#{INSTALLER_URL}, #{INSTALLER_PATH})")
12
+ # Turbo installer may return non-zero code, when it is not really failed
13
+ machine.communicate.sudo("& #{INSTALLER_PATH} | Out-Null; exit 0")
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,14 @@
1
+ module VagrantPlugins
2
+ module Turbo
3
+ module Cap
4
+ module Windows
5
+ module TurboInstalled
6
+ def self.turbo_installed(machine)
7
+ command = "if ((& turbo version) -Match 'Version: *') { exit 0 } else { exit 1 }"
8
+ machine.communicate.test(command, sudo: true)
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,53 @@
1
+ require 'rexml/document'
2
+
3
+ module VagrantPlugins
4
+ module Turbo
5
+ module Cap
6
+ module Windows
7
+ class Quota
8
+ def initialize(name, limit, source)
9
+ @__name = name
10
+ @__limit = limit
11
+ @__source = source
12
+ end
13
+
14
+ def name
15
+ @__name
16
+ end
17
+
18
+ def is_group_policy
19
+ 'gpo'.casecmp(@__source) == 0
20
+ end
21
+
22
+ def limit
23
+ @__limit
24
+ end
25
+ end
26
+
27
+ module WinrmGetQuota
28
+ def self.winrm_get_quota(machine, quota_name)
29
+ output = ''
30
+ machine.communicate.execute('winrm get winrm/config/Winrs -format:xml') do |type, data|
31
+ if type == :stdout
32
+ output << data
33
+ end
34
+ end
35
+ doc = REXML::Document.new(output)
36
+ quota_node = REXML::XPath.first(doc, "//cfg:Winrs/cfg:#{quota_name}")
37
+ if quota_node
38
+ limit = quota_node.text.to_i
39
+ source = quota_node.attribute('Source')
40
+ source_value = if source
41
+ source.value
42
+ else
43
+ ''
44
+ end
45
+ return Quota.new(quota_name, limit, source_value)
46
+ end
47
+ nil
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,13 @@
1
+ module VagrantPlugins
2
+ module Turbo
3
+ module Cap
4
+ module Windows
5
+ module WinrmSetQuota
6
+ def self.winrm_set_quota(machine, quota_name, limit)
7
+ machine.communicate.sudo("winrm set winrm/config/winrs '@{#{quota_name}=\"#{limit}\"}'")
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,155 @@
1
+ module VagrantPlugins
2
+ module Turbo
3
+ class Client
4
+ def initialize(machine)
5
+ @machine = machine
6
+ @logger = Log4r::Logger.new('vagrant::provisioners::turbo::client')
7
+ end
8
+
9
+ def login(config)
10
+ @machine.ui.info(I18n.t('vagrant_turbo.login', username: config.username))
11
+ run_with_output("turbo login #{config.username} #{config.password} --format=json")
12
+ end
13
+
14
+ def import(config)
15
+ @machine.ui.info(I18n.t('vagrant_turbo.import_image', path: config.path))
16
+ command = "turbo import #{config.type}"
17
+ command << " --name=#{config.name}" if config.name
18
+ command << ' --overwrite' if config.overwrite
19
+ command << ' ' << config.path
20
+
21
+ @machine.ui.info(I18n.t('vagrant_turbo.execute_command', command: command))
22
+ run_with_output(command)
23
+ end
24
+
25
+ def run(config)
26
+ command = 'turbo run'
27
+ command << " --name=#{config.name}" if config.name
28
+ command << ' --temp' if config.temp
29
+ # HACK - list of images must be passed in quotes. Otherwise Vagrant will split the command.
30
+ command << ' ' << "\"#{config.images.join(',')}\""
31
+ command << " --using=\"#{config.using.join(',')}\"" if config.using.any?
32
+ command << " --isolate=#{config.isolate}" if config.isolate
33
+ command << " --mount \"#{config.script_dir}\"=\"#{config.script_dir}\"" if config.script_dir
34
+
35
+ if config.startup_file
36
+ startup_file = config.startup_file
37
+ startup_file = "c:#{startup_file}" if startup_file.start_with?("\\")
38
+ command << " --startup-file=\"#{startup_file}\""
39
+ end
40
+
41
+ command << ' --pull' if config.pull
42
+ command << ' --no-stream' if config.no_stream
43
+ command << ' --admin' if config.admin
44
+
45
+ command << " --trigger=\"#{config.trigger}\"" if config.trigger
46
+ command << " --vm=#{config.vm}" if config.vm
47
+ command << " --with-root=\"#{with_root}\"" if config.with_root
48
+
49
+ command << ' --attach' if config.attach
50
+ command << ' --detach' if config.detach
51
+ command << " --format=#{config.format}" if config.format
52
+ command << ' --diagnostic' if config.diagnostic
53
+
54
+ command << flat_with_prefix('--enable=', config.enable) if config.enable
55
+ command << flat_with_prefix('--disable=', config.disable) if config.disable
56
+ command << ' --disable-sync' if config.disable_sync
57
+ command << flat_with_prefix('--env=', config.env) if config.env
58
+ command << " --env-file=\"#{config.env_file}\"" if config.env_file
59
+
60
+ command << ' --private' if config.private
61
+ command << ' --public' if config.public
62
+ command << ' --enable-log-stream' if config.enable_log_stream
63
+ command << ' --enable-screencast' if config.enable_screencast
64
+ command << ' --enable-sync' if config.enable_sync
65
+
66
+ command << flat_with_prefix('--mount=', config.mount) if config.mount
67
+ command << ' --install' if config.install
68
+
69
+ command << " --network=#{config.network}" if config.network
70
+ command << flat_with_prefix('--hosts=', config.hosts) if config.hosts
71
+ command << flat_with_prefix('--link=', config.link) if config.link
72
+ command << flat_with_prefix('--route-add=', config.route_add) if config.route_add
73
+ command << flat_with_prefix('--route-block=', config.route_block) if config.route_block
74
+
75
+ @machine.ui.info(I18n.t('vagrant_turbo.execute_command', command: command))
76
+ run_with_output(command)
77
+ end
78
+
79
+ def shell(config)
80
+ with_pretty_print do |output|
81
+ @machine.communicate.execute("tsh \"#{config.path}\"") do |type, data|
82
+ output.append(type, data)
83
+ end
84
+ end
85
+ end
86
+
87
+ private
88
+
89
+ def flat_with_prefix(prefix, array)
90
+ args_with_prefix = array.map { |value| prefix + value }
91
+ ' ' << args_with_prefix.join(' ')
92
+ end
93
+
94
+ def run_with_output(command)
95
+ with_pretty_print do |output|
96
+ @machine.communicate.execute(command) do |type, data|
97
+ output.append(type, data)
98
+ end
99
+ end
100
+ end
101
+
102
+ def log_communication(type, data)
103
+ if [:stderr, :stdout].include?(type)
104
+ @logger.info(data)
105
+ end
106
+ end
107
+
108
+ def with_pretty_print
109
+ pretty_print = PrettyPrint.new(@machine, @logger)
110
+ yield pretty_print
111
+ pretty_print.flush
112
+ end
113
+ end
114
+
115
+ class PrettyPrint
116
+ def initialize(machine, logger)
117
+ @machine = machine
118
+ @logger = logger
119
+ @buffer = []
120
+ end
121
+
122
+ def append(type, output)
123
+ unless [:stderr, :stdout].include?(type)
124
+ return
125
+ end
126
+
127
+ @logger.info(output)
128
+
129
+ # Clear out the newline since we add one
130
+ line = output.chomp
131
+ return if line.empty?
132
+
133
+ # Remove progress marquee
134
+ return if '-\|/'.include?(line)
135
+
136
+ if line.length > 1
137
+ if @buffer
138
+ prefix = @buffer.join('')
139
+ line = prefix << line
140
+ @buffer.clear
141
+ end
142
+ @machine.ui.info(line)
143
+ else
144
+ @buffer << line
145
+ end
146
+ end
147
+
148
+ def flush
149
+ if @buffer
150
+ @machine.ui.info(@buffer.join(''))
151
+ end
152
+ end
153
+ end
154
+ end
155
+ end
@@ -0,0 +1,395 @@
1
+ require 'pathname'
2
+
3
+ module VagrantPlugins
4
+ module Turbo
5
+ class ConfigUtils
6
+ def self.validate_path(path, machine, errors)
7
+ errors << I18n.t('vagrant_turbo.invalid_type', param: 'path', type: 'String') unless path.is_a?(String)
8
+ expanded_path = Pathname.new(path).expand_path(machine.env.root_path)
9
+ if expanded_path.file?
10
+ data = expanded_path.read(16)
11
+ if data && !data.valid_encoding?
12
+ errors << I18n.t(
13
+ 'vagrant_turbo.invalid_encoding',
14
+ actual: data.encoding.to_s,
15
+ default: Encoding.default_external.to_s,
16
+ path: expanded_path.to_s)
17
+ end
18
+ else
19
+ errors << I18n.t('vagrant_turbo.path_invalid', path: expanded_path)
20
+ end
21
+ end
22
+ end
23
+
24
+ class Config < Vagrant.plugin('2', :config)
25
+ attr_accessor :max_memory_per_shell
26
+
27
+ def initialize
28
+ super
29
+
30
+ @max_memory_per_shell = UNSET_VALUE
31
+ @__command_names = []
32
+ @__commands = {}
33
+ end
34
+
35
+ def finalize!
36
+ @max_memory_per_shell = nil if @max_memory_per_shell == UNSET_VALUE
37
+
38
+ commands.each { |c| c.finalize! }
39
+ end
40
+
41
+ def validate(machine)
42
+ errors = _detected_errors
43
+
44
+ errors << I18n.t('vagrant_turbo.invalid_type', param: 'max_memory_per_shell', type: 'Integer') if max_memory_per_shell && !max_memory_per_shell.is_a?(Integer)
45
+
46
+ commands.each do |command|
47
+ command.validate(machine).each do |key, local_errors|
48
+ local_errors.select { |msg| msg != nil }.each do |msg|
49
+ errors << "#{key} => #{msg}"
50
+ end
51
+ end
52
+ end
53
+
54
+ {'turbo provisioner' => errors}
55
+ end
56
+
57
+ def commands
58
+ @__command_names.map { |name| @__commands[name] }
59
+ end
60
+
61
+ def login(name, **options, &block)
62
+ _add_command(name, LoginConfig, **options, &block)
63
+ end
64
+
65
+ def import(name, **options, &block)
66
+ _add_command(name, ImportConfig, **options, &block)
67
+ end
68
+
69
+ def run(name, **options, &block)
70
+ _add_command(name, RunConfig, **options, &block)
71
+ end
72
+
73
+ def shell(name, **options, &block)
74
+ _add_command(name, TurboShellConfig, **options, &block)
75
+ end
76
+
77
+ private
78
+
79
+ def _add_command(name, type, **_options, &block)
80
+ name_to_use = name || "__default_#{type.name}"
81
+ command = @__commands[name_to_use]
82
+ unless command
83
+ command = type.new
84
+ @__commands[name_to_use] = command
85
+ @__command_names << name_to_use
86
+ end
87
+
88
+ block.call(command) if block_given?
89
+ nil
90
+ end
91
+ end
92
+
93
+ class LoginConfig < Vagrant.plugin('2', :config)
94
+ attr_accessor :username
95
+ attr_accessor :password
96
+
97
+ def initialize
98
+ @username = UNSET_VALUE
99
+ @password = UNSET_VALUE
100
+ end
101
+
102
+ def validate(_machine)
103
+ errors = _detected_errors
104
+
105
+ # Check login and password
106
+ if username && !username.is_a?(String)
107
+ I18n.t('vagrant_turbo.invalid_type', param: 'username', type: 'String')
108
+ end
109
+
110
+ if password && password.is_a?(String)
111
+ I18n.t('vagrant_turbo.invalid_type', param: 'password', type: 'String')
112
+ end
113
+
114
+ errors << I18n.t('vagrant_turbo.login_required') if !username || !password
115
+
116
+ {'turbo login' => errors}
117
+ end
118
+
119
+ def finalize!
120
+ @username = nil if @username == UNSET_VALUE
121
+ @password = nil if @password == UNSET_VALUE
122
+ end
123
+ end
124
+
125
+ class ImportConfig < Vagrant.plugin('2', :config)
126
+ attr_accessor :name
127
+ attr_accessor :path
128
+ attr_accessor :type
129
+ attr_accessor :overwrite
130
+
131
+ def initialize
132
+ super
133
+ @path = UNSET_VALUE
134
+ @name = UNSET_VALUE
135
+ @type = UNSET_VALUE
136
+ @overwrite = UNSET_VALUE
137
+ end
138
+
139
+ def validate(_machine)
140
+ end
141
+
142
+ def finalize!
143
+ @name = nil if @name == UNSET_VALUE
144
+ @type = 'SVM' if @type == UNSET_VALUE
145
+ @overwrite = true if @overwrite == UNSET_VALUE
146
+ end
147
+ end
148
+
149
+ class RunConfig < Vagrant.plugin('2', :config)
150
+ attr_accessor :inline
151
+ attr_accessor :path
152
+ attr_accessor :script_dir
153
+ attr_accessor :powershell_args
154
+
155
+ attr_accessor :name
156
+ attr_accessor :temp
157
+ attr_accessor :images
158
+ attr_accessor :using
159
+ attr_accessor :isolate
160
+ attr_accessor :startup_file
161
+ attr_accessor :pull
162
+ attr_accessor :no_stream
163
+ attr_accessor :admin
164
+
165
+ attr_accessor :trigger
166
+ attr_accessor :vm
167
+ attr_accessor :with_root
168
+
169
+ attr_accessor :attach
170
+ attr_accessor :detach
171
+ attr_accessor :format
172
+ attr_accessor :diagnostic
173
+
174
+ attr_accessor :enable
175
+ attr_accessor :disable
176
+ attr_accessor :disable_sync
177
+ attr_accessor :env
178
+ attr_accessor :env_file
179
+
180
+ attr_accessor :private
181
+ attr_accessor :public
182
+ attr_accessor :enable_log_stream
183
+ attr_accessor :enable_screencast
184
+ attr_accessor :enable_sync
185
+
186
+ attr_accessor :mount
187
+ attr_accessor :install
188
+
189
+ attr_accessor :network
190
+ attr_accessor :hosts
191
+ attr_accessor :link
192
+ attr_accessor :route_add
193
+ attr_accessor :route_block
194
+
195
+ def initialize
196
+ @inline = UNSET_VALUE
197
+ @path = UNSET_VALUE
198
+ @script_dir = UNSET_VALUE
199
+ @powershell_args = UNSET_VALUE
200
+
201
+ @name = UNSET_VALUE
202
+ @temp = UNSET_VALUE
203
+ @images = UNSET_VALUE
204
+ @using = UNSET_VALUE
205
+ @isolate = UNSET_VALUE
206
+ @startup_file = UNSET_VALUE
207
+ @pull = UNSET_VALUE
208
+ @no_stream = UNSET_VALUE
209
+ @admin = UNSET_VALUE
210
+
211
+ @trigger = UNSET_VALUE
212
+ @vm = UNSET_VALUE
213
+ @with_root = UNSET_VALUE
214
+
215
+ @attach = UNSET_VALUE
216
+ @detach = UNSET_VALUE
217
+ @format = UNSET_VALUE
218
+ @diagnostic = UNSET_VALUE
219
+
220
+ @enable = UNSET_VALUE
221
+ @disable = UNSET_VALUE
222
+ @env = UNSET_VALUE
223
+ @env_file = UNSET_VALUE
224
+
225
+ @private = UNSET_VALUE
226
+ @public = UNSET_VALUE
227
+ @enable_log_stream = UNSET_VALUE
228
+ @enable_screencast = UNSET_VALUE
229
+ @enable_sync = UNSET_VALUE
230
+ @disable_sync = UNSET_VALUE
231
+
232
+ @mount = UNSET_VALUE
233
+ @install = UNSET_VALUE
234
+
235
+ @network = UNSET_VALUE
236
+ @hosts = UNSET_VALUE
237
+ @link = UNSET_VALUE
238
+ @route_add = UNSET_VALUE
239
+ @route_block = UNSET_VALUE
240
+ end
241
+
242
+ def validate(machine)
243
+ errors = _detected_errors
244
+
245
+ # Check script parameters
246
+ errors << require_string('inline', inline)
247
+ ConfigUtils.validate_path(path, machine, errors) if path
248
+ errors << I18n.t('vagrant_turbo.path_and_inline_set') if path && inline
249
+ errors << require_string('powershell_args', powershell_args)
250
+ errors << require_string('script_dir', script_dir)
251
+
252
+ # Check run parameters
253
+ errors << require_string('name', name)
254
+ errors << require_bool('temp', temp)
255
+ errors << require_array('images', images)
256
+ errors << require_array('using', using)
257
+ if isolate
258
+ if !isolate.is_a?(String)
259
+ errors << I18n.t('vagrant_turbo.invalid_type', param: 'isolate', type: 'String')
260
+ elsif !%w(full write-copy merge).include?(isolate.downcase)
261
+ errors << I18n.t('vagrant_turbo.invalid_parameter', param: 'isolate', values: 'full, write-copy, merge')
262
+ end
263
+ end
264
+ errors << require_string('startup_file', startup_file)
265
+ errors << require_bool('no_stream', no_stream)
266
+ errors << require_bool('admin', admin)
267
+ errors << require_bool('pull', pull)
268
+
269
+ errors << require_string('trigger', trigger)
270
+ errors << require_string('vm', vm)
271
+ errors << require_string('with_root', with_root)
272
+
273
+ errors << require_bool('detach', detach)
274
+ errors << require_bool('attach', attach)
275
+ errors << require_string('format', format)
276
+ errors << require_bool('diagnostic', diagnostic)
277
+
278
+ errors << require_array('enable', enable)
279
+ errors << require_array('disable', disable)
280
+ errors << require_array('env', env)
281
+ errors << require_string('env_file', env_file)
282
+
283
+ errors << require_bool('private', private)
284
+ errors << require_bool('public', public)
285
+ errors << require_bool('enable_log_stream', enable_log_stream)
286
+ errors << require_bool('enable_screencast', enable_screencast)
287
+ errors << require_bool('enable_sync', enable_sync)
288
+ errors << require_bool('disable_sync', disable_sync)
289
+
290
+ errors << require_array('mount', mount)
291
+ errors << require_bool('install', install)
292
+
293
+ errors << require_string('network', network)
294
+ errors << require_array('hosts', hosts)
295
+ errors << require_array('link', link)
296
+ errors << require_array('route_add', route_add)
297
+ errors << require_array('route_block', route_block)
298
+
299
+ errors << I18n.t('vagrant_turbo.startup_file_with_path_or_inline') if startup_file && (path || inline)
300
+
301
+ {'turbo run' => errors}
302
+ end
303
+
304
+ def finalize!
305
+ @inline = nil if @inline == UNSET_VALUE
306
+ @path = nil if @path == UNSET_VALUE
307
+ @script_dir = 'C:\\tmp\\vagrant-turbo' if @script_dir == UNSET_VALUE
308
+ @powershell_args = nil if @powershell_args == UNSET_VALUE
309
+
310
+ @name = nil if @name == UNSET_VALUE
311
+ @temp = false if @temp == UNSET_VALUE
312
+ @images = [] if @images == UNSET_VALUE
313
+ @using = [] if @using == UNSET_VALUE
314
+ @isolate = nil if @isolate == UNSET_VALUE
315
+ @startup_file = nil if @startup_file == UNSET_VALUE
316
+ @pull = false if @pull == UNSET_VALUE
317
+ @no_stream = false if @no_stream == UNSET_VALUE
318
+ @admin = false if @admin == UNSET_VALUE
319
+
320
+ @trigger = nil if @trigger == UNSET_VALUE
321
+ @vm = nil if @vm == UNSET_VALUE
322
+ @with_root = nil if @with_root == UNSET_VALUE
323
+
324
+ @detach = false if @detach == UNSET_VALUE
325
+ @attach = false if @attach == UNSET_VALUE
326
+ @format = nil if @format == UNSET_VALUE
327
+ @diagnostic = false if @diagnostic == UNSET_VALUE
328
+
329
+ @enable = [] if @enable == UNSET_VALUE
330
+ @disable = [] if @disable == UNSET_VALUE
331
+ @env = [] if @env == UNSET_VALUE
332
+ @env_file = nil if @env_file == UNSET_VALUE
333
+
334
+ @private = false if @private == UNSET_VALUE
335
+ @public = false if @public == UNSET_VALUE
336
+ @enable_log_stream = false if @enable_log_stream == UNSET_VALUE
337
+ @enable_screencast = false if @enable_screencast == UNSET_VALUE
338
+ @enable_sync = false if @enable_sync == UNSET_VALUE
339
+ @disable_sync = false if @disable_sync == UNSET_VALUE
340
+
341
+ @mount = [] if @mount == UNSET_VALUE
342
+ @install = false if @install == UNSET_VALUE
343
+
344
+ @network = nil if @network == UNSET_VALUE
345
+ @hosts = [] if @hosts == UNSET_VALUE
346
+ @link = [] if @link == UNSET_VALUE
347
+ @route_add = [] if @route_add == UNSET_VALUE
348
+ @route_block = [] if @route_block == UNSET_VALUE
349
+ end
350
+
351
+ private
352
+
353
+ def require_bool(param_name, value)
354
+ I18n.t('vagrant_turbo.invalid_type', param: param_name, type: 'Boolean') unless !!value == value
355
+ end
356
+
357
+ def require_string(param_name, value)
358
+ errors << I18n.t('vagrant_turbo.invalid_type', param: param_name, type: 'String') if value && !value.is_a?(String)
359
+ end
360
+
361
+ def require_array(param_name, value)
362
+ errors << I18n.t('vagrant_turbo.invalid_type', param: param_name, type: 'Array') if value && !value.is_a?(Array)
363
+ end
364
+ end
365
+
366
+ class TurboShellConfig < Vagrant.plugin('2', :config)
367
+ attr_accessor :inline
368
+ attr_accessor :path
369
+ attr_accessor :script_dir
370
+
371
+ def initialize
372
+ @inline = UNSET_VALUE
373
+ @path = UNSET_VALUE
374
+ @script_dir = UNSET_VALUE
375
+ end
376
+
377
+ def validate(machine)
378
+ errors = _detected_errors
379
+ errors << I18n.t('vagrant_turbo.invalid_type', param: 'inline', type: 'String') if inline && !inline.is_a?(String)
380
+ ConfigUtils.validate_path(path, machine, errors) if path
381
+
382
+ errors << I18n.t('vagrant_turbo.path_and_inline_set') if path && inline
383
+ errors << I18n.t('vagrant_turbo.path_and_inline_set') if path && inline
384
+
385
+ {'turbo shell' => errors}
386
+ end
387
+
388
+ def finalize!
389
+ @script_dir = 'C:\\tmp\\vagrant-turbo' if @script_dir == UNSET_VALUE
390
+ @path = nil if @path == UNSET_VALUE
391
+ @inline = nil if @inline == UNSET_VALUE
392
+ end
393
+ end
394
+ end
395
+ end
@@ -0,0 +1,22 @@
1
+ module VagrantPlugins
2
+ module Turbo
3
+ class Installer
4
+ def initialize(machine)
5
+ @machine = machine
6
+ end
7
+
8
+ def ensure_installed
9
+ @machine.ui.info(I18n.t('vagrant_turbo.check_install'))
10
+
11
+ unless @machine.guest.capability(:turbo_installed)
12
+ @machine.ui.info(I18n.t('vagrant_turbo.not_installed'))
13
+ @machine.guest.capability(:turbo_install)
14
+
15
+ unless @machine.guest.capability(:turbo_installed)
16
+ raise TurboError, :install_failed
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,42 @@
1
+ require 'vagrant'
2
+
3
+ module VagrantPlugins
4
+ module Turbo
5
+ class Plugin < Vagrant.plugin(2)
6
+ name 'turbo'
7
+ description <<-DESC
8
+ Provides support for Turbo
9
+ DESC
10
+
11
+ config(:turbo, :provisioner) do
12
+ require_relative 'config'
13
+ Config
14
+ end
15
+
16
+ guest_capability(:windows, :turbo_installed) do
17
+ require_relative 'cap/windows/turbo_installed'
18
+ Cap::Windows::TurboInstalled
19
+ end
20
+
21
+ guest_capability(:windows, :turbo_install) do
22
+ require_relative 'cap/windows/turbo_install'
23
+ Cap::Windows::TurboInstall
24
+ end
25
+
26
+ guest_capability(:windows, :winrm_get_quota) do
27
+ require_relative 'cap/windows/winrm_get_quota'
28
+ Cap::Windows::WinrmGetQuota
29
+ end
30
+
31
+ guest_capability(:windows, :winrm_set_quota) do
32
+ require_relative 'cap/windows/winrm_set_quota'
33
+ Cap::Windows::WinrmSetQuota
34
+ end
35
+
36
+ provisioner(:turbo) do
37
+ require_relative 'provisioner'
38
+ Provisioner
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,207 @@
1
+ require 'log4r'
2
+ require 'pathname'
3
+ require 'tempfile'
4
+ require_relative 'client'
5
+ require_relative 'installer'
6
+ require_relative 'config'
7
+
8
+ module VagrantPlugins
9
+ module Turbo
10
+ class TurboError < Vagrant::Errors::VagrantError
11
+ error_namespace('vagrant_turbo')
12
+ end
13
+
14
+ class Provisioner < Vagrant.plugin(2, :provisioner)
15
+ def initialize(machine, config, client = nil, installer = nil)
16
+ super(machine, config)
17
+
18
+ @client = client || Client.new(machine)
19
+ @installer = installer || Installer.new(machine)
20
+ @logger = Log4r::Logger.new('vagrant::provisioners::turbo')
21
+ end
22
+
23
+ def provision
24
+ setup_max_memory_per_shell
25
+
26
+ @logger.info('Ensure turbo installed')
27
+ @installer.ensure_installed
28
+
29
+ config.commands.each do |command|
30
+ if command.is_a?(ImportConfig)
31
+ import(command)
32
+ next
33
+ end
34
+
35
+ if command.is_a?(LoginConfig)
36
+ login(command)
37
+ next
38
+ end
39
+
40
+ if command.is_a?(RunConfig)
41
+ run(command)
42
+ next
43
+ end
44
+
45
+ if command.is_a?(TurboShellConfig)
46
+ shell(command)
47
+ end
48
+ end
49
+ end
50
+
51
+ private
52
+
53
+ def setup_max_memory_per_shell
54
+ quota_name = 'MaxMemoryPerShellMB'
55
+ recommended_limit = 1024
56
+
57
+ machine.ui.info(I18n.t('vagrant_turbo.check_quota', quota_name: quota_name))
58
+ quota = machine.guest.capability(:winrm_get_quota, quota_name)
59
+ if quota
60
+ @logger.info("#{quota_name} was initially set to #{quota.limit}")
61
+
62
+ if config.max_memory_per_shell
63
+ if quota.is_group_policy && quota.limit != config.max_memory_per_shell
64
+ raise TurboError, :quota_protected_by_group_policy_increase_info
65
+ end
66
+ machine.guest.capability(:winrm_set_quota, quota_name, config.max_memory_per_shell)
67
+ machine.ui.info(I18n.t('vagrant_turbo.quota_set_to', quota_name: quota_name, quota_limit: config.max_memory_per_shell))
68
+ elsif quota.limit < recommended_limit
69
+ machine.ui.warn(I18n.t('vagrant_turbo.quota_below_recommended_limit', quota_name: quota_name, quota_limit: quota.limit, recommended_limit: recommended_limit))
70
+ if quota.is_group_policy
71
+ machine.ui.warn(I18n.t('vagrant_turbo.quota_protected_by_group_policy_increase_info'))
72
+ else
73
+ machine.ui.warn(I18n.t('vagrant_turbo.quota_increase_info', quota_name: quota_name, recommended_limit: recommended_limit))
74
+ end
75
+ machine.ui.warn(I18n.t('vagrant_turbo.small_quota_warning'))
76
+ end
77
+ else
78
+ @logger.info("Failed to get #{quota_name} quota limit")
79
+ end
80
+ end
81
+
82
+ def login (login_config)
83
+ @logger.info('Login to the hub')
84
+ @client.login(login_config)
85
+ end
86
+
87
+ def run(run_config)
88
+ run_config.startup_file = build_startup_file(run_config)
89
+ @client.run(run_config)
90
+ end
91
+
92
+ def import(import_config)
93
+ import_config.path = expand_guest_path(import_config.path)
94
+ @client.import(import_config)
95
+ end
96
+
97
+ def shell(shell_config)
98
+ with_script_file(shell_config) do |path|
99
+ machine.communicate.tap do |comm|
100
+ machine.ui.info(I18n.t('vagrant_turbo.running', script: shell_config.path || 'inline Turbo script'))
101
+ comm.upload(path, shell_config.script_dir)
102
+ shell_config.path = File.join(shell_config.script_dir, File.basename(path))
103
+ @client.shell(shell_config)
104
+ end
105
+ end
106
+ end
107
+
108
+ def build_startup_file(config)
109
+ machine.communicate.tap do |comm|
110
+ dir_to_use = expand_guest_path(config.script_dir)
111
+
112
+ # Make sure the remote path exists
113
+ comm.execute("mkdir '#{dir_to_use}'")
114
+
115
+ if config.path
116
+ file_to_upload = File.expand_path(config.path)
117
+
118
+ @logger.info("Uploading #{file_to_upload} to #{dir_to_use}")
119
+ comm.upload(file_to_upload, dir_to_use)
120
+
121
+ if File.extname(file_to_upload).casecmp('.ps1') == 0
122
+ # Hack create bat script to launch Powershell
123
+ launch_command = 'powershell'
124
+ if config.powershell_args
125
+ launch_command << ' -ExecutionPolicy Bypass' if config.powershell_args !~ /[-\/]ExecutionPolicy/i
126
+ launch_command << ' -OutputFormat Text' if config.powershell_args !~ /[-\/]OutputFormat/i
127
+ launch_command << ' ' << config.powershell_args
128
+ else
129
+ launch_command << ' -ExecutionPolicy Bypass -OutputFormat Text'
130
+ end
131
+ launch_command << " -File \"#{File.join(dir_to_use, File.basename(file_to_upload))}\""
132
+
133
+ return upload_startup_file(comm, dir_to_use, launch_command)
134
+ else
135
+ return File.join(dir_to_use, File.basename(config.path))
136
+ end
137
+ else
138
+ return upload_startup_file(comm, dir_to_use, config.inline)
139
+ end
140
+ end
141
+ end
142
+
143
+ def cleanup
144
+ end
145
+
146
+ def upload_startup_file(comm, guest_dir, *lines)
147
+ file_name = 'turbo-launch.bat'
148
+ startup_file = File.join(guest_dir, file_name)
149
+
150
+ @logger.info("Creating startup file #{startup_file}")
151
+ temp_file = Tempfile.new(file_name)
152
+ begin
153
+ temp_file.puts(lines)
154
+ temp_file.close
155
+ comm.upload(File.expand_path(temp_file.path), startup_file)
156
+ ensure
157
+ temp_file.close
158
+ temp_file.unlink
159
+ end
160
+
161
+ startup_file
162
+ end
163
+
164
+ # Expand the guest path if the guest has the capability
165
+ def expand_guest_path(destination)
166
+ if machine.guest.capability?(:shell_expand_guest_path)
167
+ machine.guest.capability(:shell_expand_guest_path, destination)
168
+ else
169
+ destination.to_s.gsub('/', "\\")
170
+ end
171
+ end
172
+
173
+ def with_script_file(config)
174
+ script = if config.path
175
+ # Read the content of the script
176
+ Pathname.new(config.path).expand_path(machine.env.root_path).read
177
+ else
178
+ # The script is just the inline code
179
+ config.inline
180
+ end
181
+
182
+ # Create temp file for the script
183
+ file = Tempfile.new(%w(vagrant-turbo .tsh))
184
+ file.binmode
185
+
186
+ begin
187
+ file.write(script)
188
+ file.fsync
189
+ file.close
190
+ yield file.path.gsub('/', "\\")
191
+ ensure
192
+ file.close
193
+ file.unlink
194
+ end
195
+ end
196
+
197
+ def handle_comm(type, data)
198
+ if [:stderr, :stdout].include?(type)
199
+ data = data.chomp
200
+ options = {:color => type == :stdout ? :green : :red}
201
+ return if data.empty? || !(data =~ /\||\\|\/|\-/).nil?
202
+ machine.ui.info(data, options)
203
+ end
204
+ end
205
+ end
206
+ end
207
+ end
@@ -0,0 +1,5 @@
1
+ module VagrantPlugins
2
+ module Turbo
3
+ VERSION = '0.0.1.pre'
4
+ end
5
+ end
@@ -0,0 +1,18 @@
1
+ require 'vagrant-turbo/plugin'
2
+
3
+ module VagrantPlugins
4
+ module Turbo
5
+ LOCALES_PATH = 'locales/en.yml'
6
+
7
+ def self.root
8
+ File.expand_path '../..', __FILE__
9
+ end
10
+
11
+ def self.setup_locales
12
+ I18n.load_path << File.expand_path(LOCALES_PATH, root)
13
+ I18n.reload!
14
+ end
15
+
16
+ setup_locales
17
+ end
18
+ end
data/locales/en.yml ADDED
@@ -0,0 +1,33 @@
1
+ en:
2
+ vagrant_turbo:
3
+ invalid_type: "Invalid value of `%{param}`. It must be of type %{type}."
4
+ login_required: "Turbo.net login credentials must be specified via `username` and `password`."
5
+ no_path_or_inline: "One of `path` or `inline` must be set."
6
+ path_and_inline_set: "Only one of `path` or `inline` may be set."
7
+ path_invalid: "`path` for Turbo provisioner does not exist on the host system: %{path}"
8
+ images_folders_invalid: "`images_folder` for Turbo provisioner does not exist on the host system: %{path}"
9
+ invalid_encoding: |-
10
+ Invalid encoding '%{actual}' for script at '%{path}'.
11
+ Must be '%{default}' or UTF-8.
12
+
13
+ check_install: "Checking Turbo installation..."
14
+ already_installed: "Turbo is installed on this machine. Skipping installation..."
15
+ not_installed: "Turbo is not installed on this machine. Installing..."
16
+ install_failed: "Turbo installation failed. Something went terribly wrong. Login to the guest machine and install it manually."
17
+
18
+ no_images_to_run: "No images specified to run in the container"
19
+
20
+ no_images: "There are no images exist in the directory on the host system, skipping it: %{path}"
21
+ import_image: "Importing image on the guest system: %{path}..."
22
+
23
+ login: "Login as %{username}..."
24
+ running: "Running %{script}..."
25
+ invalid_parameter: "Unknown `%{param}` value. Use one of valid values: %{values}"
26
+ startup_file_with_path_or_inline: "Startup file cannot be set if path or inline are used"
27
+ check_quota: "Checking %{quota_name} quota"
28
+ quota_protected_by_group_policy_increase_info: "Quota is protected by Group Policy and must be changed manually. For more information visit https://msdn.microsoft.com/en-us/library/windows/desktop/ee309367(v=vs.85).aspx"
29
+ small_quota_warning: "Small quota may cause provisioning failure with`System.OutOfMemoryException` or `System.StackOverflowException`"
30
+ quota_below_recommended_limit: "%{quota_name} is below the recommended threshold of %{recommended_limit}MB (current value: %{quota_limit}MB)."
31
+ quota_increase_info: "To increase the quota set a new value using 'max_memory_per_shell' key in turbo provisioner or execute the following command on guest machine:\n\nwinrm set winrm/config/winrs @{%{quota_name}=\"%{recommended_limit}\"}"
32
+ quota_set_to: "Quota %{quota_name} set to %{quota_limit}"
33
+ execute_command: "Executing command: %{command}"
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
2
+ require "vagrant-turbo"
@@ -0,0 +1,24 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'vagrant-turbo/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'vagrant-turbo'
7
+ s.version = VagrantPlugins::Turbo::VERSION
8
+ s.platform = Gem::Platform::CURRENT
9
+ s.authors = 'Turbo.net'
10
+ s.email = 'support@turbo.net'
11
+ s.summary = 'Enables Vagrant to manage Turbo containers'
12
+ s.description = 'Enables Vagrant to manage Turbo containers'
13
+ s.homepage = 'https://github.com/turboapps/vagrant'
14
+ s.license = 'MIT'
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
19
+ s.require_paths = %w[lib]
20
+
21
+ s.add_development_dependency 'bundler', '~> 1.10'
22
+ s.add_development_dependency 'rake', '~> 10.0'
23
+ s.add_development_dependency 'rspec', '~> 3.3'
24
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-turbo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.pre
5
+ platform: x86-mingw32
6
+ authors:
7
+ - Turbo.net
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-11-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.3'
55
+ description: Enables Vagrant to manage Turbo containers
56
+ email: support@turbo.net
57
+ executables: []
58
+ extensions: []
59
+ extra_rdoc_files: []
60
+ files:
61
+ - ".gitignore"
62
+ - ".rspec"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - lib/vagrant-turbo.rb
68
+ - lib/vagrant-turbo/cap/windows/turbo_install.rb
69
+ - lib/vagrant-turbo/cap/windows/turbo_installed.rb
70
+ - lib/vagrant-turbo/cap/windows/winrm_get_quota.rb
71
+ - lib/vagrant-turbo/cap/windows/winrm_set_quota.rb
72
+ - lib/vagrant-turbo/client.rb
73
+ - lib/vagrant-turbo/config.rb
74
+ - lib/vagrant-turbo/installer.rb
75
+ - lib/vagrant-turbo/plugin.rb
76
+ - lib/vagrant-turbo/provisioner.rb
77
+ - lib/vagrant-turbo/version.rb
78
+ - locales/en.yml
79
+ - spec/spec_helper.rb
80
+ - vagrant-turbo.gemspec
81
+ homepage: https://github.com/turboapps/vagrant
82
+ licenses:
83
+ - MIT
84
+ metadata: {}
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">"
97
+ - !ruby/object:Gem::Version
98
+ version: 1.3.1
99
+ requirements: []
100
+ rubyforge_project:
101
+ rubygems_version: 2.4.5.1
102
+ signing_key:
103
+ specification_version: 4
104
+ summary: Enables Vagrant to manage Turbo containers
105
+ test_files: []