vagrant-subutai 1.0.0

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: 2d6d2a8545054356ac7b25e47d3d8645da0ef26a
4
+ data.tar.gz: 32d23a3c72eb1e0acbed5739e96208466dcec272
5
+ SHA512:
6
+ metadata.gz: 35680eed7399518c665f5aacff2890f6990d84fc8256d331aeb35fddf1db76ae619a095342053a2556021b88cb7d435f7bcc23f181b907ed7b70453a51f8b2ff
7
+ data.tar.gz: 347b417244213eb2616e99895b1c936dcf6bfb084c561ac311f0179ea430c306f4184aa85372395c9ad75a108ef33cb040e515c278eeee41b0f2340fd36db269
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ /.bundle/
2
+ .idea/
3
+ .vagrant/
4
+ /.yardoc
5
+ /Gemfile.lock
6
+ /_yardoc/
7
+ /coverage/
8
+ /doc/
9
+ /pkg/
10
+ /spec/reports/
11
+ /tmp/
12
+ *.bundle
13
+ *.so
14
+ *.o
15
+ *.a
16
+ mkmf.log
17
+ *.swp
18
+ *.gem
19
+ pkg
20
+ Gemfile.lock
21
+ build.sh
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ group :development do
6
+ gem "vagrant", :git => "git://github.com/mitchellh/vagrant.git"
7
+ end
data/README.md ADDED
@@ -0,0 +1,52 @@
1
+ # Vagrant Subutai CLI
2
+
3
+ Vagrant Subutai CLI - executes Subutai scripts in target hosts
4
+
5
+ ## Installation
6
+
7
+ $ vagrant plugin install vagrant-subutai
8
+
9
+ ## Usage
10
+ ```
11
+ Usage: vagrant subutai command [command options] [arguments...]
12
+
13
+ COMMANDS:
14
+ attach - attach to Subutai container
15
+ backup - backup Subutai container
16
+ batch - batch commands execution
17
+ checkpoint - checkpoint/restore in user space
18
+ clone - clone Subutai container
19
+ cleanup - clean Subutai environment
20
+ config - edit container config
21
+ daemon - start Subutai agent
22
+ demote - demote Subutai container
23
+ destroy - destroy Subutai container
24
+ export - export Subutai container
25
+ import - import Subutai template
26
+ info - information about host system
27
+ hostname - Set hostname of container or host
28
+ list - list Subutai container
29
+ log - print application logs
30
+ map - Subutai port mapping
31
+ metrics - list Subutai container
32
+ migrate - migrate Subutai container
33
+ p2p - P2P network operations
34
+ promote - promote Subutai container
35
+ proxy - Subutai reverse proxy
36
+ quota - set quotas for Subutai container
37
+ rename - rename Subutai container
38
+ restore - restore Subutai container
39
+ stats - statistics from host
40
+ start - start Subutai container
41
+ stop - stop Subutai container
42
+ tunnel - SSH tunnel management
43
+ update - update Subutai management, container or Resource host
44
+ vxlan - VXLAN tunnels operation
45
+ register - register Subutai Peer to Hub
46
+ fingerprint - shows fingerprint Subutai Console
47
+ disk - manage Subutai disk
48
+
49
+ GLOBAL OPTIONS:
50
+ -h, --help - show help
51
+ ```
52
+
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require 'rake/testtask'
2
+ require "bundler/gem_tasks"
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << 'test'
6
+ end
7
+
8
+ desc "Run tests"
9
+ task :default => :test
data/Vagrantfile ADDED
@@ -0,0 +1,7 @@
1
+ # Vagrant.plugin "subutai_cli"
2
+
3
+ Vagrant::Config.run do |config|
4
+ config.vm.box = "theritty/test-fai"
5
+ config.ssh.username = "root"
6
+ config.ssh.password = "fai"
7
+ end
@@ -0,0 +1,12 @@
1
+ require 'vagrant'
2
+ require 'vagrant-subutai/command'
3
+ require 'vagrant-subutai/config'
4
+ require 'vagrant-subutai/plugin'
5
+ require 'vagrant-subutai/rest'
6
+ require 'vagrant-subutai/subutai_commands'
7
+ require 'vagrant-subutai/version'
8
+ require 'vagrant-subutai/rh_controller'
9
+ require 'vagrant-subutai/models/resource_host'
10
+ require 'vagrant-subutai/packer/subutai_config'
11
+ require 'vagrant-subutai/packer/subutai_hooks'
12
+ require 'vagrant-subutai/packer/subutai_net'
@@ -0,0 +1,142 @@
1
+ require_relative '../vagrant-subutai'
2
+ require 'optparse'
3
+ require 'io/console'
4
+ require 'net/https'
5
+ require_relative 'subutai_commands'
6
+ require 'fileutils'
7
+
8
+ module VagrantSubutai
9
+ module Subutai
10
+ class Command < Vagrant.plugin('2', :command)
11
+ # shows description when `vagrant list-commands` is triggered
12
+ def self.synopsis
13
+ 'Vagrant Subutai CLI - executes Subutai scripts in target hosts'
14
+ end
15
+
16
+ def execute
17
+ cli_info
18
+
19
+ # Gets Subutai console url and box name from Vagrantfile
20
+ with_target_vms(nil, single_target: true) do |machine|
21
+ $SUBUTAI_BOX_NAME = machine.config.vm.box
22
+ end
23
+
24
+ subutai_cli = VagrantSubutai::Commands.new(ARGV, @env)
25
+
26
+ case ARGV[1]
27
+ when 'register'
28
+ check_subutai_console_url(subutai_cli)
29
+ subutai_cli.register(nil, nil)
30
+ when 'fingerprint'
31
+ check_subutai_console_url(subutai_cli)
32
+ subutai_cli.fingerprint($SUBUTAI_CONSOLE_URL)
33
+ when 'disk'
34
+ OptionParser.new do |opt|
35
+ opt.banner = 'Usage: vagrant subutai disk [options]'
36
+
37
+ opt.on('-s', '--size NUMBER', 'set your disk size') do |num|
38
+ disk = num.to_i
39
+
40
+ generated_disk = SubutaiConfig.get(:_SUBUTAI_DISK)
41
+
42
+ if generated_disk.nil?
43
+ grow_by = disk - 100 # default Subutai disk is 100 gigabytes
44
+ else
45
+ grow_by = disk - (generated_disk.to_i + 100) # HERE Applied math BEDMAS rule
46
+ end
47
+
48
+ if grow_by > 0
49
+ SubutaiConfig.put(:SUBUTAI_DISK, num, true)
50
+ STDOUT.puts " \e[33mWarning the disk change cannot be applied until a restart of the VM.\e[0m"
51
+ else
52
+ STDOUT.puts " \e[33mWarning the operation will be ignored because it shrink operations are not supported.\e[0m"
53
+ end
54
+ end
55
+
56
+ opt.on('-i', '--info', 'shows Subutai disk capacity') do
57
+ disk = SubutaiConfig.get(:SUBUTAI_DISK)
58
+
59
+ if disk.nil?
60
+ STDOUT.puts " \e[32mSubutai disk capacity is 100 gb.\e[0m"
61
+ else
62
+ STDOUT.puts " \e[32mSubutai disk capacity is #{disk} gb.\e[0m"
63
+ end
64
+ end
65
+ end.parse!
66
+ when '-h'
67
+ STDOUT.puts cli_info
68
+ when '--help'
69
+ STDOUT.puts cli_info
70
+ else
71
+ # All Agent CLI commands implemented here
72
+
73
+ command = ARGV
74
+ command.shift
75
+
76
+ if command.empty?
77
+ STDOUT.puts cli_info
78
+ else
79
+ subutai_cli.ssh("#{subutai_cli.base} #{command.join(' ')}")
80
+ end
81
+ end
82
+ end
83
+
84
+ def check_subutai_console_url(subutai_cli)
85
+ ip = subutai_cli.info(VagrantCommand::ARG_IP_ADDR)
86
+
87
+ if ip.nil?
88
+ STDOUT.puts "We can't detect your Subutai Console ip address!"
89
+ exit
90
+ end
91
+ $SUBUTAI_CONSOLE_URL = "https://#{ip}:#{SubutaiConsoleAPI::PORT}"
92
+ end
93
+
94
+ def cli_info
95
+ commands = <<-EOF
96
+
97
+ Usage: vagrant subutai command [command options] [arguments...]
98
+
99
+ COMMANDS:
100
+ attach - attach to Subutai container
101
+ backup - backup Subutai container
102
+ batch - batch commands execution
103
+ checkpoint - checkpoint/restore in user space
104
+ clone - clone Subutai container
105
+ cleanup - clean Subutai environment
106
+ config - edit container config
107
+ daemon - start Subutai agent
108
+ demote - demote Subutai container
109
+ destroy - destroy Subutai container
110
+ export - export Subutai container
111
+ import - import Subutai template
112
+ info - information about host system
113
+ hostname - Set hostname of container or host
114
+ list - list Subutai container
115
+ log - print application logs
116
+ map - Subutai port mapping
117
+ metrics - list Subutai container
118
+ migrate - migrate Subutai container
119
+ p2p - P2P network operations
120
+ promote - promote Subutai container
121
+ proxy - Subutai reverse proxy
122
+ quota - set quotas for Subutai container
123
+ rename - rename Subutai container
124
+ restore - restore Subutai container
125
+ stats - statistics from host
126
+ start - start Subutai container
127
+ stop - stop Subutai container
128
+ tunnel - SSH tunnel management
129
+ update - update Subutai management, container or Resource host
130
+ vxlan - VXLAN tunnels operation
131
+ register - register Subutai Peer to Hub
132
+ fingerprint - shows fingerprint Subutai Console
133
+ disk - manage Subutai disk
134
+
135
+ GLOBAL OPTIONS:
136
+ -h, --help - show help
137
+ EOF
138
+ commands
139
+ end
140
+ end
141
+ end
142
+ end
@@ -0,0 +1,52 @@
1
+ require_relative '../vagrant-subutai'
2
+
3
+ module SubutaiAgentCommand
4
+ BASE = "sudo /snap/bin/subutai"
5
+ UPDATE = " update" # arg required
6
+ LOG = " log"
7
+ INFO = " info" # arg required
8
+ TEMPLATE_IMPORT = " import ubuntu16"
9
+ TEMPLATE_CLONE = " clone ubuntu16" # arg required
10
+ TEMPLATE_ATTACH = " attach" # arg required
11
+ TEMPLATE_EXPORT = " export" # arg required
12
+ LIST = " list"
13
+ end
14
+
15
+ module SubutaiConsoleAPI
16
+ PORT = "8443"
17
+ module V1
18
+ TOKEN = "/rest/v1/identity/gettoken"
19
+ REGISTER_HUB = "/rest/v1/hub/register?sptoken="
20
+ APPROVE = "/rest/v1/registration/requests"
21
+ FINGERPRINT = "/rest/v1/security/keyman/getpublickeyfingerprint"
22
+ REQUESTS = "/rest/v1/registration/requests?sptoken="
23
+ end
24
+ end
25
+
26
+ module VagrantSubutai
27
+ module Subutai
28
+ RH_FOLDER_NAME = "RH"
29
+
30
+ class Config < Vagrant.plugin('2', :config)
31
+ attr_accessor :url
32
+
33
+ def initialize
34
+ super
35
+ @url = UNSET_VALUE
36
+ end
37
+
38
+ def finalize!
39
+ @url = "" if @url == UNSET_VALUE
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ module VagrantCommand
46
+ INIT = "vagrant init"
47
+ UP = "vagrant up"
48
+ RH_UP = "SUBUTAI_PEER=false vagrant up"
49
+ PROVISION = "vagrant provision"
50
+ SUBUTAI_ID = "vagrant subutai --info id"
51
+ ARG_IP_ADDR = "ipaddr"
52
+ end
@@ -0,0 +1,7 @@
1
+ module VagrantSubutai
2
+ module Models
3
+ class Rh
4
+ attr_accessor :id, :hostname, :status, :isManagement, :isConnected
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,380 @@
1
+ require 'yaml'
2
+ require 'digest'
3
+ require 'net/http'
4
+ require 'json'
5
+
6
+ require_relative 'subutai_net'
7
+ require_relative 'subutai_hooks'
8
+
9
+ # Vagrant Driven Subutai Configuration
10
+ # noinspection RubyTooManyMethodsInspection
11
+ module SubutaiConfig
12
+ LOG_MODES = %i[debug info warn error].freeze
13
+ PARENT_DIR = './.vagrant'.freeze
14
+ GENERATED_FILE = PARENT_DIR + '/generated.yml'.freeze
15
+ CONF_FILE = File.expand_path('./vagrant-subutai.yml').freeze
16
+ USER_CONF_FILE = File.expand_path('~/.vagrant-subutai/vagrant-subutai.yml').freeze
17
+ SUBUTAI_ENVIRONMENTS = %i[prod master dev sysnet].freeze
18
+
19
+ # Without a variable key listed here it will not get pulled in from
20
+ # the environment, or from any of the vagrant-subutai.yml conf files
21
+ USER_PARAMETERS = %i[
22
+ DESIRED_CONSOLE_PORT
23
+ DESIRED_SSH_PORT
24
+ ALLOW_INSECURE
25
+ SUBUTAI_ENV
26
+ SUBUTAI_CPU
27
+ SUBUTAI_RAM
28
+ SUBUTAI_PEER
29
+ SUBUTAI_SNAP
30
+ SUBUTAI_DESKTOP
31
+ SUBUTAI_MAN_TMPL
32
+ APT_PROXY_URL
33
+ PROVISION
34
+ BRIDGE
35
+ AUTHORIZED_KEYS
36
+ PASSWORD_OVERRIDE
37
+ SUBUTAI_DISK
38
+ ].freeze
39
+
40
+ GENERATED_PARAMETERS = %i[
41
+ _BRIDGED
42
+ _CONSOLE_PORT
43
+ _BASE_MAC
44
+ _SSH_PORT
45
+ _LOG_MODE
46
+ _ALT_SNAP
47
+ _ALT_SNAP_MD5
48
+ _ALT_SNAP_MD5_LAST
49
+ _ALT_MANAGEMENT
50
+ _ALT_MANAGEMENT_MD5
51
+ _ALT_MANAGEMENT_MD5_LAST
52
+ _SUBUTAI_DISK
53
+ _SUBUTAI_DISK_PORT
54
+ ].freeze
55
+
56
+ # Used for testing
57
+ @conf_file_override = nil
58
+
59
+ # Vagrant command currently being executed, must not be nil
60
+ @cmd = nil
61
+
62
+ # Hash of generated/calculated settings preserved through commands
63
+ @generated = {}
64
+
65
+ # Smart defaults to use for configuration settings
66
+ @defaults = {
67
+ # Implemented configuration parameters
68
+ DESIRED_CONSOLE_PORT: 9999, # integer for console port
69
+ DESIRED_SSH_PORT: 4567, # integer for console port
70
+ ALLOW_INSECURE: false, # boolean to enable insecure CDN and snap
71
+ SUBUTAI_ENV: :prod, # subutai environment to use
72
+ SUBUTAI_PEER: true, # to provision or not console (peer)
73
+ SUBUTAI_RAM: 4096, # RAM memory assigned to the vm
74
+ SUBUTAI_CPU: 2, # virtual CPU's assign to the vm
75
+
76
+ # Configuration parameters below have not been implemented
77
+ SUBUTAI_SNAP: nil, # alternative snap to provision
78
+ SUBUTAI_DESKTOP: false, # install desktop with tray and p2p client
79
+ SUBUTAI_MAN_TMPL: nil, # provision alternative management template
80
+ APT_PROXY_URL: nil, # configure apt proxy URL
81
+ PROVISION: true # to provision or not to
82
+ }
83
+
84
+ # User provided configuration settings
85
+ @config = @defaults.clone
86
+
87
+ @logging = nil
88
+
89
+ @bridged = false
90
+
91
+ @url_of_cdn = 'https://cdn.subut.ai:8338/kurjun/rest'
92
+
93
+ def self.write?
94
+ raise 'SubutaiConfig.cmd not set' if @cmd.nil?
95
+ @cmd == 'up'
96
+ end
97
+
98
+ def self.delete?
99
+ raise 'SubutaiConfig.cmd not set' if @cmd.nil?
100
+ @cmd == 'destroy'
101
+ end
102
+
103
+ def self.read?
104
+ raise 'SubutaiConfig.cmd not set' if @cmd.nil?
105
+ @cmd != 'up'
106
+ end
107
+
108
+ def self.generated?(key)
109
+ GENERATED_PARAMETERS.include? key
110
+ end
111
+
112
+ def self.boolean?(key)
113
+ if get(key.to_sym) == 'true' || get(key.to_sym) == true
114
+ true
115
+ elsif get(key.to_sym) == 'false' || get(key.to_sym) == false
116
+ false
117
+ elsif get(key.to_sym).nil?
118
+ false
119
+ else
120
+ raise "#{key} value #{get(key.to_sym)} is not a boolean"
121
+ end
122
+ end
123
+
124
+ def self.provision_snap?
125
+ return false unless boolean?(:PROVISION)
126
+ return false if get(:_ALT_SNAP).nil?
127
+ return false if get(:_ALT_SNAP_MD5) == get(:_ALT_SNAP_MD5_LAST)
128
+ return false unless %w[up provision].include?(@cmd)
129
+ true
130
+ end
131
+
132
+ def self.snap_provisioned!
133
+ put(:_ALT_SNAP_MD5_LAST, get(:_ALT_SNAP_MD5), true) if provision_snap?
134
+ end
135
+
136
+ def self.bridged!
137
+ @bridged = true
138
+ end
139
+
140
+ def self.provision_management?
141
+ return false unless boolean?(:PROVISION)
142
+ return false if get(:_ALT_MANAGEMENT).nil?
143
+ return false if get(:_ALT_MANAGEMENT_MD5) == get(:_ALT_MANAGEMENT_MD5_LAST)
144
+ return false unless %w[up provision].include?(@cmd)
145
+ true
146
+ end
147
+
148
+ def self.management_provisioned!
149
+ put(:_ALT_MANAGEMENT_MD5_LAST, get(:_ALT_MANAGEMENT_MD5), true)\
150
+ if provision_management?
151
+ end
152
+
153
+ def self.cmd
154
+ @cmd
155
+ end
156
+
157
+ def self.config
158
+ @config
159
+ end
160
+
161
+ def self.get_grow_by
162
+ disk = get(:SUBUTAI_DISK)
163
+ if disk.nil?
164
+ nil
165
+ else
166
+ disk = disk.to_i
167
+ generated_disk = get(:_SUBUTAI_DISK)
168
+ grow_by = 0
169
+
170
+ if generated_disk.nil?
171
+ grow_by = disk - 100 # default Subutai disk is 100 gigabytes
172
+ else
173
+ grow_by = disk - (generated_disk.to_i + 100) # HERE Applied math BEDMAS rule
174
+ end
175
+ grow_by
176
+ end
177
+ end
178
+
179
+ def self.url_of_cdn
180
+ @url_of_cdn
181
+ end
182
+ def self.override_conf_file(filepath)
183
+ @conf_file_override = filepath
184
+ end
185
+
186
+ def self.conf_file
187
+ return CONF_FILE if @conf_file_override.nil?
188
+ @conf_file_override
189
+ end
190
+
191
+ def self.get(key)
192
+ key_sym = key.to_sym
193
+
194
+ if key_sym == :SUBUTAI_ENV
195
+ env = @config[key_sym].to_sym
196
+ raise "#{env} invalid SUBUTAI_ENV" \
197
+ unless SUBUTAI_ENVIRONMENTS.include?(env)
198
+ end
199
+
200
+ @config[key_sym]
201
+ end
202
+
203
+ # Write through to save configuration values
204
+ def self.put(key, value, do_store)
205
+ raise "Undefined configuration parameter: #{key}" \
206
+ unless USER_PARAMETERS.include?(key.to_sym) \
207
+ || GENERATED_PARAMETERS.include?(key.to_sym)
208
+ @config.store(key.to_sym, value)
209
+ @generated.store(key.to_sym, value) if generated? key
210
+
211
+ store if do_store
212
+ value
213
+ end
214
+
215
+ # Load generated values preserved across vagrant commands
216
+ def self.load_generated
217
+ return false unless File.exist?(GENERATED_FILE)
218
+ temp = YAML.load_file(GENERATED_FILE)
219
+ temp.each do |key, value|
220
+ @generated.store(key.to_sym, value)
221
+ @config.store(key.to_sym, value)
222
+ end
223
+ end
224
+
225
+ # Stores ONLY generated configuration from YAML files
226
+ def self.store
227
+ FileUtils.mkdir_p(PARENT_DIR) unless Dir.exist?(PARENT_DIR)
228
+ stringified = Hash[@generated.map { |k, v| [k.to_s, v.to_s] }]
229
+ File.open(GENERATED_FILE, 'w') { |f| f.write stringified.to_yaml }
230
+
231
+ stringified = Hash.new
232
+ @config.map do |k, v|
233
+ unless generated?(k)
234
+ if !k.nil? && !v.nil?
235
+ stringified.store(k.to_s, v.to_s)
236
+ end
237
+ end
238
+ end
239
+ File.open(CONF_FILE, 'w') { |f| f.write stringified.to_yaml }
240
+ true
241
+ end
242
+
243
+ def self.set_env(key, value)
244
+ raise "Invalid #{key} value of #{value}: use prod, master, or dev" \
245
+ unless SUBUTAI_ENVIRONMENTS.include?(value)
246
+ @config.store(key, value)
247
+ end
248
+
249
+ def self.load_config_file(config_file)
250
+ temp = YAML.load_file(config_file)
251
+ temp.each_key do |key|
252
+ raise "Invalid key in YAML file: '#{key}'" \
253
+ unless USER_PARAMETERS.include?(key.to_sym)
254
+
255
+ if key.to_sym == :SUBUTAI_ENV
256
+ set_env(key.to_sym, temp[key].to_sym)
257
+ elsif !temp[key].nil?
258
+ @config.store(key.to_sym, temp[key])
259
+ end
260
+ end
261
+ end
262
+
263
+ def self.do_handlers
264
+ return false unless %w[up provision].include? @cmd
265
+ file = snap_handler(get(:SUBUTAI_SNAP))
266
+ unless file.nil?
267
+ put(:_ALT_SNAP, file, true) if provision_snap?
268
+ put(:_ALT_SNAP_MD5, Digest::MD5.file(file).to_s, true) if provision_snap?
269
+ end
270
+
271
+ file = management_handler(get(:SUBUTAI_MAN_TMPL))
272
+ unless file.nil?
273
+ put(:_ALT_MANAGEMENT, file, true) if provision_management?
274
+ put(:_ALT_MANAGEMENT_MD5, Digest::MD5.file(file).to_s, true) \
275
+ if provision_management?
276
+ end
277
+ true
278
+ end
279
+
280
+ # NOTE: Console port ONLY needed in nat mode
281
+ # NOTE: SSH port only needed in bridged mode
282
+ def self.do_network(provider)
283
+ # set the next available console port if provisioning a peer in nat mode
284
+ put(:_CONSOLE_PORT, find_port(get(:DESIRED_CONSOLE_PORT)), true) \
285
+ if boolean?(:SUBUTAI_PEER) && get(:_CONSOLE_PORT).nil? && write?
286
+
287
+ # set the SSH port if we are using bridged mode
288
+ put(:_SSH_PORT, find_port(get(:DESIRED_SSH_PORT)), true) \
289
+ if @bridged && get(:_SSH_PORT).nil? && write?
290
+
291
+ put(:_BASE_MAC, find_mac(provider), true) \
292
+ if @bridged && get(:_BASE_MAC).nil? && write?
293
+
294
+ put(:_BRIDGED, @bridged, true) if write?
295
+ end
296
+
297
+ # Loads the generated and user configuration from YAML files
298
+ def self.load_config(cmd, provider)
299
+ raise 'SubutaiConfig.cmd not set' if cmd.nil?
300
+ @cmd = cmd
301
+
302
+ # Load YAML based user and local configuration if they exist
303
+ load_config_file(USER_CONF_FILE) if File.exist?(USER_CONF_FILE)
304
+ load_config_file(CONF_FILE) if File.exist?(CONF_FILE)
305
+ load_generated
306
+
307
+ # Load overrides from the environment, and generated configurations
308
+ ENV.each do |key, value|
309
+ put(key.to_sym, value, false) if USER_PARAMETERS.include? key.to_sym
310
+ end
311
+ do_handlers
312
+ do_network(provider)
313
+ end
314
+
315
+ def self.reset
316
+ @cmd = nil
317
+ @config = @defaults.clone
318
+ @generated = {}
319
+ @conf_file_override = nil
320
+ end
321
+
322
+ # Destroys the generated file if vagrant destroy is used
323
+ def self.cleanup
324
+ cleanup! if delete?
325
+ end
326
+
327
+ def self.cleanup!
328
+ reset
329
+ File.delete GENERATED_FILE if File.exist?(GENERATED_FILE)
330
+ end
331
+
332
+ def self.logging!(mode)
333
+ return (@logging = nil) if mode.nil?
334
+ raise "Invalid logging mode #{mode}" unless LOG_MODES.include?(mode)
335
+ @logging = mode
336
+ puts "Logging mode set to #{mode}"
337
+ end
338
+
339
+ def self.log(cmds, message)
340
+ return if @logging.nil?
341
+ puts message if !cmds.nil? && cmds.include?(@cmd)
342
+ end
343
+
344
+ def self.log_mode(modes, cmds, message)
345
+ return if @logging.nil?
346
+ puts message if cmds.include?(@cmd) && modes.include?(@logging)
347
+ end
348
+
349
+ def self.print
350
+ return if @logging.nil?
351
+ puts
352
+ puts ' ==> User provided configuration: '
353
+ puts ' --------------------------------------------------------------------'
354
+
355
+ @config.each do |key, value|
356
+ puts "#{(' ' + key.to_s).ljust(29)} => #{value}" \
357
+ unless generated? key
358
+ end
359
+
360
+ puts
361
+ puts ' ==> Generated settings preserved across command runs:'
362
+ puts ' --------------------------------------------------------------------'
363
+
364
+ @config.each do |key, value|
365
+ puts "#{(' + ' + key.to_s).ljust(29)} => #{value}" if generated? key
366
+ end
367
+ end
368
+
369
+ def self.get_latest_id_artifact(owner, artifact_name)
370
+ url = url_of_cdn + '/raw/info?owner=' + owner + '&name=' + artifact_name
371
+ uri = URI(url)
372
+ response = Net::HTTP.get(uri)
373
+ result = JSON.parse(response)
374
+ result[0]['id']
375
+ end
376
+ end
377
+
378
+ at_exit do
379
+ SubutaiConfig.cleanup unless SubutaiConfig.cmd.nil?
380
+ end