vagrant-subutai 1.1.2 → 1.1.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e85448afa09e694451410e4f71f30e8124723d48
4
- data.tar.gz: 8417f914901d15c0652decffdacd9985b5670429
3
+ metadata.gz: d85530987aa29ed8ea34ba2f14f62b0f353610b7
4
+ data.tar.gz: e0052e2f1e16a49dacca29f63c93a257011a4bc4
5
5
  SHA512:
6
- metadata.gz: 768dba9dc41d0d159c60365b5f94758ccc226a43de94d3d0f1a62b8d31165ca351fc4cc622ec20b0296440dca43dd97b9bca511a9f6615cc3d34a7c3b5dadf19
7
- data.tar.gz: e781b7fb725b7747e37449dc0fea0363483278405b9cb3981d47815cbc1d1a950754e3f747c7d97937ca4023cc6fa034caad7c6294704ad31b3c6e25ef3079a6
6
+ metadata.gz: 6eb58cb2f067c894be6d8746bffcefd2c74ee8113587e39e0763be00db480e1cd9a5393c6fb86fb9d27f7178f62e8d6ad4fb724ea6f35921245a39577a023801
7
+ data.tar.gz: 84a85a6eddceed3ccb77df4577604e95159ff2504432b227eba8f7f39c0f72bfbeb527927e2932dc136c2d1c459469ab1e3ee2a537b5c946c77c2735116aaa63
data/CHANGELOG.md CHANGED
@@ -15,4 +15,15 @@ BUG FIXES:
15
15
 
16
16
  BUG FIXES:
17
17
 
18
- - [Windows] Blueprint provisioning run first vagrant up
18
+ - [Windows] Blueprint provisioning run first vagrant up
19
+
20
+ ## 1.1.3 (March 23, 2018)
21
+
22
+ BUG FIXES:
23
+
24
+ - [Linux] arp command replaces with ip
25
+ - Long running ansible playbook error fixed
26
+
27
+ FEATURES:
28
+
29
+ - VM Disk Path variable added to conf file (SUBUTAI_DISK_PATH)
@@ -31,10 +31,17 @@ module VagrantSubutai
31
31
  Put.info "Adding hosts #{container.containerName} to group [#{group['name']}]"
32
32
 
33
33
  if group.key?('python-interpreter')
34
- response = Rest::SubutaiConsole.command("echo \"#{container.containerName} ansible_user=root template=#{hostname} ansible_ssh_host=#{container.ip} ansible_python_interpreter=#{group['python-interpreter']}\" >> /etc/ansible/hosts", @environment.ansible_host_id, "/root","360000", @url, @token)
34
+ response = Rest::SubutaiConsole.command("echo \"#{container.containerName} ansible_user=root template=#{hostname} ansible_ssh_host=#{container.ip} ansible_python_interpreter=#{group['python-interpreter']}\" >> /etc/ansible/hosts",
35
+ @environment.ansible_host_id,
36
+ "/root",
37
+ "360000",
38
+ @url, @token)
35
39
  status(response)
36
40
  else
37
- response = Rest::SubutaiConsole.command("echo \"#{container.containerName} ansible_user=root template=#{hostname} ansible_ssh_host=#{container.ip}\" >> /etc/ansible/hosts", @environment.ansible_host_id, "/root","360000", @url, @token)
41
+ response = Rest::SubutaiConsole.command("echo \"#{container.containerName} ansible_user=root template=#{hostname} ansible_ssh_host=#{container.ip}\" >> /etc/ansible/hosts",
42
+ @environment.ansible_host_id,
43
+ "/root","360000",
44
+ @url, @token)
38
45
  status(response)
39
46
  end
40
47
  end
@@ -44,25 +51,117 @@ module VagrantSubutai
44
51
  # Downloads ansible source
45
52
  def download
46
53
  Put.info "\nStarted downloading ansible source...."
47
- #response = Rest::SubutaiConsole.command("ansible-playbook download.json -e 'ansible_python_interpreter=/usr/bin/python3' --extra-vars '{ \"source_url\": \"#{@ansible.source_url}\"}'", @environment.ansible_host_id, "/root","360000", @url, @token)
48
- response = Rest::SubutaiConsole.command("bash /root/get_unzip.sh #{@ansible.source_url}", @environment.ansible_host_id, "/root","360000", @url, @token)
54
+ response = Rest::SubutaiConsole.command_async("bash /root/get_unzip.sh #{@ansible.source_url}",
55
+ @environment.ansible_host_id,
56
+ "/root","360000",
57
+ @url, @token)
49
58
 
50
- status(response)
59
+ case response
60
+ when Net::HTTPOK
61
+ json = JSON.parse(response.body)
62
+ track(json['id'])
63
+ when Net::HTTPAccepted
64
+ json = JSON.parse(response.body)
65
+ track(json['id'])
66
+ else
67
+ Put.error response.body
68
+ Put.error response.message
69
+ end
70
+ end
71
+
72
+ # polls command log
73
+ #
74
+ # {
75
+ # "exitCode": 127,
76
+ # "stdOut": "",
77
+ # "stdErr": "bash: /root/get_unzip.sh: No such file or directory\n",
78
+ # "status": "FAILED"
79
+ # }
80
+ #
81
+ def track(command_id)
82
+ response = Rest::SubutaiConsole.command_log(@url, @token, command_id)
83
+
84
+ case response
85
+ when Net::HTTPOK
86
+ @log = JSON.parse response.body
87
+ @tmp = nil
88
+
89
+ until @log['status'] == Configs::CommandState::FAILED ||
90
+ @log['status'] == Configs::CommandState::KILLED ||
91
+ @log['status'] == Configs::CommandState::TIMEOUT ||
92
+ @log['status'] == Configs::CommandState::SUCCEEDED
93
+
94
+ res = Rest::SubutaiConsole.command_log(@url, @token, command_id)
95
+
96
+ begin
97
+ @log = JSON.parse res.body
98
+
99
+ if @tmp.nil?
100
+ Put.info @log['stdOut']
101
+ else
102
+ msg = @log['stdOut']
103
+
104
+ if @tmp.length < msg.length
105
+ msg = msg[(@tmp.length)..(msg.length-1)]
106
+ Put.info msg
107
+ end
108
+ end
109
+
110
+ @tmp = @log['stdOut']
111
+ rescue JSON::ParserError => e
112
+ Put.error e
113
+ end
114
+
115
+ sleep 5 # sleep 5 seconds
116
+ end
117
+
118
+ if @log['status'] == Configs::CommandState::SUCCEEDED
119
+ Put.success @log['status']
120
+ else
121
+ Put.error @log['status']
122
+ Put.error @log['stdErr']
123
+ end
124
+ else
125
+ Put.error response.body
126
+ Put.error response.message
127
+ end
51
128
  end
52
129
 
53
130
  # Runs ansible playbook
54
131
  def run
55
132
  Put.info "\nStarted running ansible playbook may be take too long time please wait......."
56
133
  if @ansible.extra_vars.empty?
57
- response = Rest::SubutaiConsole.command("cd /root/*master/;ansible-playbook #{@ansible.ansible_playbook}", @environment.ansible_host_id, "/root","360000", @url, @token)
58
- status(response)
134
+ response = Rest::SubutaiConsole.command_async("cd /root/*master/;ansible-playbook #{@ansible.ansible_playbook}", @environment.ansible_host_id, "/root","360000", @url, @token)
135
+
136
+ case response
137
+ when Net::HTTPOK
138
+ json = JSON.parse(response.body)
139
+ track(json['id'])
140
+ when Net::HTTPAccepted
141
+ json = JSON.parse(response.body)
142
+ track(json['id'])
143
+ else
144
+ Put.error response.body
145
+ Put.error response.message
146
+ end
59
147
  else
60
148
  extra_vars = {}
61
149
  @ansible.extra_vars.each do |extra_var|
62
150
  extra_var.map {|k, v| extra_vars[k] = v }
63
151
  end
64
- response = Rest::SubutaiConsole.command("cd /root/*master;ansible-playbook #{@ansible.ansible_playbook} --extra-vars '#{extra_vars.to_json}'", @environment.ansible_host_id, "/root","360000", @url, @token)
65
- status(response)
152
+ response = Rest::SubutaiConsole.command_async("cd /root/*master;ansible-playbook #{@ansible.ansible_playbook} --extra-vars '#{extra_vars.to_json}'", @environment.ansible_host_id, "/root","360000", @url, @token)
153
+
154
+ case response
155
+ when Net::HTTPOK
156
+ json = JSON.parse(response.body)
157
+ track(json['id'])
158
+ when Net::HTTPAccepted
159
+ json = JSON.parse(response.body)
160
+ track(json['id'])
161
+ else
162
+ Put.error response.body
163
+ Put.error response.message
164
+ end
66
165
  end
67
166
  end
68
167
 
@@ -323,7 +323,10 @@ module VagrantSubutai
323
323
 
324
324
  temp = nil
325
325
  validations.each_with_index do |validation, index|
326
- if @available_ram >= Configs::Quota::RESOURCE[validation.strip.to_sym][:RAM] && @available_disk >= Configs::Quota::RESOURCE[validation.strip.to_sym][:DISK]
326
+ if Configs::Blueprint::CONTAINER_SIZES.include?(validation) && @available_ram >= Configs::Quota::RESOURCE[validation.strip.to_sym][:RAM] && @available_disk >= Configs::Quota::RESOURCE[validation.strip.to_sym][:DISK]
327
+ Put.info " #{index}. #{validation}"
328
+ temp = index
329
+ else
327
330
  Put.info " #{index}. #{validation}"
328
331
  temp = index
329
332
  end
@@ -32,6 +32,8 @@ module VagrantSubutai
32
32
  subutai_cli.open(check_subutai_console_url(subutai_cli))
33
33
  when 'blueprint'
34
34
  subutai_cli.blueprint(check_subutai_console_url(subutai_cli), 1)
35
+ when 'finger'
36
+ subutai_cli.finger(check_subutai_console_url(subutai_cli))
35
37
  when '-h'
36
38
  STDOUT.puts cli_info
37
39
  when '--help'
@@ -109,6 +109,8 @@ module VagrantSubutai
109
109
  module SubutaiConsoleAPI
110
110
  PORT = '8443'.freeze
111
111
  COMMAND = '/rest/ui/commands?sptoken='.freeze
112
+ COMMAND_ASYNC = '/rest/ui/commands/async?sptoken='.freeze
113
+ COMMAND_LOG = '/rest/ui/commands/async/{COMMAND_ID}?sptoken='.freeze
112
114
 
113
115
  module V1
114
116
  TOKEN = '/rest/v1/identity/gettoken'.freeze
@@ -163,6 +165,13 @@ module VagrantSubutai
163
165
  UNHEALTHY = 'UNHEALTHY'.freeze
164
166
  end
165
167
 
168
+ module CommandState
169
+ SUCCEEDED = 'SUCCEEDED'.freeze
170
+ FAILED = 'FAILED'.freeze
171
+ KILLED = 'KILLED'.freeze
172
+ TIMEOUT = 'TIMEOUT'.freeze
173
+ end
174
+
166
175
  module ApplicationState
167
176
  INSTALLING = 'INSTALLING'.freeze
168
177
  INSTALLED = 'INSTALLED'.freeze
@@ -43,6 +43,7 @@ module SubutaiConfig
43
43
  USER_VARIABLES
44
44
  BAZAAR_EMAIL
45
45
  BAZAAR_PASSWORD
46
+ SUBUTAI_DISK_PATH
46
47
  ].freeze
47
48
 
48
49
  GENERATED_PARAMETERS = %i[
@@ -257,6 +258,14 @@ module SubutaiConfig
257
258
  if key.to_sym == :SUBUTAI_ENV
258
259
  set_env(key.to_sym, temp[key].to_sym)
259
260
  elsif !temp[key].nil?
261
+ # TODO add double checks type
262
+
263
+ if temp[key] == 'true'
264
+ temp[key] = true
265
+ elsif temp[key] == 'false'
266
+ temp[key] = false
267
+ end
268
+
260
269
  @config.store(key.to_sym, temp[key])
261
270
  end
262
271
  end
@@ -50,6 +50,23 @@ module SubutaiDisk
50
50
  def self.file(grow_by)
51
51
  disk_port = port
52
52
 
53
- "./#{DISK_NAME}-#{disk_port.to_i}-#{grow_by}.#{DISK_FORMAT}"
53
+ # get disk path from conf file
54
+ if SubutaiConfig.get(:SUBUTAI_DISK_PATH).nil?
55
+ "./#{DISK_NAME}-#{disk_port.to_i}-#{grow_by}.#{DISK_FORMAT}"
56
+ else
57
+ # Check is directory exist
58
+ if File.directory?(SubutaiConfig.get(:SUBUTAI_DISK_PATH).to_s)
59
+ # check permission
60
+ if File.writable?(SubutaiConfig.get(:SUBUTAI_DISK_PATH).to_s)
61
+ File.join(SubutaiConfig.get(:SUBUTAI_DISK_PATH).to_s, "#{DISK_NAME}-#{disk_port.to_i}-#{grow_by}.#{DISK_FORMAT}")
62
+ else
63
+ Put.warn "No write permission: #{SubutaiConfig.get(:SUBUTAI_DISK_PATH)}"
64
+ "./#{DISK_NAME}-#{disk_port.to_i}-#{grow_by}.#{DISK_FORMAT}"
65
+ end
66
+ else
67
+ Put.warn "Invalid path: #{SubutaiConfig.get(:SUBUTAI_DISK_PATH)}"
68
+ "./#{DISK_NAME}-#{disk_port.to_i}-#{grow_by}.#{DISK_FORMAT}"
69
+ end
70
+ end
54
71
  end
55
72
  end
@@ -72,18 +72,33 @@ end
72
72
  def arp_table
73
73
  broadcast_ping(2)
74
74
  arp_table = {}
75
- `arp -a`.split("\n").each do |line|
76
- matches = /.*(\d+\.\d+\.\d+.\d+)[[:space:]]((([a-f]|[0-9]){1,2}:){5}([a-f]|[0-9]){1,2})[[:space:]].*/.match(line) \
75
+
76
+ if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin|darwin/
77
+ `arp -a`.split("\n").each do |line|
78
+ matches = /.*(\d+\.\d+\.\d+.\d+)[[:space:]]((([a-f]|[0-9]){1,2}:){5}([a-f]|[0-9]){1,2})[[:space:]].*/.match(line) \
77
79
  if (RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/)
78
- matches = /.*\((\d+\.\d+\.\d+.\d+)\) at ((([a-f]|[0-9]){1,2}:){5}([a-f]|[0-9]){1,2}) .*/.match(line) \
79
- if (RbConfig::CONFIG['host_os'] =~ /darwin|linux/)
80
+ matches = /.*\((\d+\.\d+\.\d+.\d+)\) at ((([a-f]|[0-9]){1,2}:){5}([a-f]|[0-9]){1,2}) .*/.match(line) \
81
+ if (RbConfig::CONFIG['host_os'] =~ /darwin/)
80
82
 
81
- if ! matches.nil? && ! matches[2].nil?
82
- key_mac = zero_pad_mac(matches[2])
83
- value_ip = matches[1]
84
- arp_table.store(key_mac, value_ip)
83
+ if ! matches.nil? && ! matches[2].nil?
84
+ key_mac = zero_pad_mac(matches[2])
85
+ value_ip = matches[1]
86
+ arp_table.store(key_mac, value_ip)
87
+ end
88
+ end
89
+ elsif RbConfig::CONFIG['host_os'] =~ /linux|bsd/
90
+ `ip n | awk '{print $1,$5}'`.split("\n").each do |line|
91
+ ip, mac = line.split(' ')
92
+
93
+ if ! line.nil? && ! mac.nil?
94
+
95
+ key_mac = zero_pad_mac(mac)
96
+ value_ip = ip
97
+ arp_table.store(key_mac, value_ip)
98
+ end
85
99
  end
86
100
  end
101
+
87
102
  arp_table
88
103
  end
89
104
 
@@ -157,7 +157,7 @@ module VagrantSubutai
157
157
 
158
158
  # Sends command to Subutai Console
159
159
  # method POST
160
- def self.command(cmd, hostId, path, timeOut, url, token)
160
+ def self.command(cmd, hostid, path, timeout, url, token)
161
161
  uri = URI.parse(url + Configs::SubutaiConsoleAPI::COMMAND + token)
162
162
  https = Net::HTTP.new(uri.host, uri.port)
163
163
  https.use_ssl = true
@@ -165,7 +165,34 @@ module VagrantSubutai
165
165
  https.read_timeout = 21600 # 6 hours
166
166
 
167
167
  request = Net::HTTP::Post.new(uri.request_uri)
168
- request.set_form_data({'command' => cmd, 'hostId' => hostId, 'path' => path, 'timeOut' => timeOut})
168
+ request.set_form_data({'command' => cmd, 'hostid' => hostid, 'path' => path, 'timeout' => timeout})
169
+
170
+ https.request(request)
171
+ end
172
+
173
+ # Sends async request to Subutai Console
174
+ # method POST
175
+ def self.command_async(cmd, hostid, path, timeout, url, token)
176
+ uri = URI.parse(url + Configs::SubutaiConsoleAPI::COMMAND_ASYNC + token)
177
+ https = Net::HTTP.new(uri.host, uri.port)
178
+ https.use_ssl = true
179
+ https.verify_mode = OpenSSL::SSL::VERIFY_NONE
180
+ https.read_timeout = 21600 # 6 hours
181
+
182
+ request = Net::HTTP::Post.new(uri.request_uri)
183
+ request.set_form_data({'command' => cmd, 'hostid' => hostid, 'path' => path, 'timeout' => timeout})
184
+
185
+ https.request(request)
186
+ end
187
+
188
+ def self.command_log(url, token, command_id)
189
+ uri = URI.parse(url + Configs::SubutaiConsoleAPI::COMMAND_LOG.gsub('{COMMAND_ID}', command_id) + token)
190
+ https = Net::HTTP.new(uri.host, uri.port)
191
+ https.use_ssl = true
192
+ https.verify_mode = OpenSSL::SSL::VERIFY_NONE
193
+ https.read_timeout = 21600 # 6 hours
194
+
195
+ request = Net::HTTP::Get.new(uri.request_uri)
169
196
 
170
197
  https.request(request)
171
198
  end
@@ -131,6 +131,20 @@ module VagrantSubutai
131
131
  end
132
132
  end
133
133
 
134
+ def finger(url)
135
+ begin
136
+ peer_id = Rest::SubutaiConsole.fingerprint(url)
137
+ ip = info('ipaddr')
138
+
139
+ Put.info ip
140
+ Put.info peer_id
141
+ rescue Net::OpenTimeout => e
142
+ Put.error e
143
+ rescue => e
144
+ Put.error e
145
+ end
146
+ end
147
+
134
148
  # Get Subutai Peer Os credentials from input
135
149
  def get_input_token
136
150
  password = nil
@@ -239,6 +253,7 @@ module VagrantSubutai
239
253
 
240
254
  case response
241
255
  when Net::HTTPOK # 200 Ready
256
+ #Put.info "http::ok #{attempt}"
242
257
  # start provisioning
243
258
  variable = VagrantSubutai::Blueprint::VariablesController.new(0, 0, nil)
244
259
 
@@ -273,11 +288,13 @@ module VagrantSubutai
273
288
  end
274
289
  when response.code == 503
275
290
  if attempt < VagrantSubutai::Configs::Blueprint::ATTEMPT
291
+ #Put.info "status code 503 attempt: #{attempt}"
276
292
  sleep(2**attempt) #
277
293
  blueprint(url, attempt+1)
278
294
  end
279
295
  when Net::HTTPNotFound
280
296
  if attempt < VagrantSubutai::Configs::Blueprint::ATTEMPT
297
+ #Put.info "net::httpnotfound attempt: #{attempt}"
281
298
  sleep(2**attempt) #
282
299
  blueprint(url, attempt+1)
283
300
  end
@@ -287,33 +304,39 @@ module VagrantSubutai
287
304
  # PeerOs not ready
288
305
  Put.error "PeerOS failed to run"
289
306
  end
290
- rescue Net::OpenTimeout => timeout
307
+ rescue Net::OpenTimeout
291
308
  if attempt < VagrantSubutai::Configs::Blueprint::ATTEMPT
292
- sleep(2**attempt) #
309
+ #Put.info "net::opentimeout attempt: #{attempt}"
310
+ sleep(2**attempt)
293
311
  blueprint(url, attempt+1)
294
312
  end
295
313
  rescue Errno::ECONNRESET
296
314
  if attempt < VagrantSubutai::Configs::Blueprint::ATTEMPT
315
+ #Put.info "errno::econnreset attempt: #{attempt}"
297
316
  sleep(2**attempt) #
298
317
  blueprint(url, attempt+1)
299
318
  end
300
319
  rescue Errno::ECONNABORTED
301
320
  if attempt < VagrantSubutai::Configs::Blueprint::ATTEMPT
321
+ #Put.info "errno::econnaborted attempt: #{attempt}"
302
322
  sleep(2**attempt) #
303
323
  blueprint(url, attempt+1)
304
324
  end
305
325
  rescue OpenSSL::OpenSSLError # generic openssl error
306
326
  if attempt < VagrantSubutai::Configs::Blueprint::ATTEMPT
327
+ #Put.info "openssl::opensslerror attempt: #{attempt}"
307
328
  sleep(2**attempt) #
308
329
  blueprint(url, attempt+1)
309
330
  end
310
331
  rescue OpenSSL::SSL::SSLError
311
332
  if attempt < VagrantSubutai::Configs::Blueprint::ATTEMPT
333
+ #Put.info "openssl::ssl::sslerror attempt: #{attempt}"
312
334
  sleep(2**attempt) #
313
335
  blueprint(url, attempt+1)
314
336
  end
315
337
  rescue => e
316
- if attempt == 1 # fails first attempt then try
338
+ if attempt == 1 && ARGV[0] == 'up' # fails first attempt then try
339
+ #Put.info "e attempt: #{attempt} error: #{e} arg: #{ARGV[0]}"
317
340
  sleep(10)
318
341
  blueprint(url, attempt+1)
319
342
  else
@@ -1,3 +1,3 @@
1
1
  module VagrantSubutai
2
- VERSION = '1.1.2'
2
+ VERSION = '1.1.3'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-subutai
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Subutai
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-15 00:00:00.000000000 Z
11
+ date: 2018-03-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler