vagrant-subutai 1.1.0 → 1.1.1

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: 4105a1ad3b5e5d3f61465aa910e4e876297e5309
4
- data.tar.gz: 4261d2ba9fe00f7e61e5edb060ebd5c561d18b2f
3
+ metadata.gz: 96dfff84ab3bb322ef149071dd0ff43fbf0b16a2
4
+ data.tar.gz: 6724ea41bcfb8f01916a5b7deb3b48c395e1bf0e
5
5
  SHA512:
6
- metadata.gz: 04eb8cb919fac5be3a5e6dee6a31570a95b583d992a263133d00c84f831fd1d11b215669b22fce837e97a14ea5c1cad37bca92aa8147c6a81983fa1524666e13
7
- data.tar.gz: ecc183b0935f57facd0131b9ebcc7465e28e52ed6646a8aee38190362ff63a28d50cdee25ffdbe01a39431a6f8c7f70d6ee662a59694984c534afa94a3264b93
6
+ metadata.gz: d1c7f508d9b766ec48507e53618f939170ee1f0723460807657bfdfbd52f339ffd76220de7449ca912dddf34e5601b82576ff905d54428392a5787124288d6f2
7
+ data.tar.gz: 78acf8c97c92e3dcb7c0446329ebbc6f37752eea8c5892f06dbc1f51cbd822155ede144ff36eacc24e1b7dad070786839681d1e786121fedc726f6c92540162a
data/CHANGELOG.md CHANGED
@@ -4,4 +4,9 @@ FEATURES:
4
4
 
5
5
  - Blueprint provisioning in two modes bazaar and peer
6
6
  - Open command PeerOS in browser
7
-
7
+
8
+ ## 1.1.1 (March 15, 2018)
9
+
10
+ BUG FIXES:
11
+
12
+ - Blueprint provisioning check for ready PeerOS
data/build.sh CHANGED
@@ -1,10 +1,10 @@
1
1
  #!/bin/bash
2
2
 
3
- rm vagrant-subutai-1.1.0.gem
3
+ rm vagrant-subutai-1.1.1.gem
4
4
  gem build vagrant-subutai.gemspec
5
5
 
6
6
  gem uninstall vagrant-subutai
7
- gem install ./vagrant-subutai-1.1.0.gem
7
+ gem install ./vagrant-subutai-1.1.1.gem
8
8
 
9
9
  vagrant plugin uninstall vagrant-subutai
10
- vagrant plugin install ./vagrant-subutai-1.1.0.gem
10
+ vagrant plugin install ./vagrant-subutai-1.1.1.gem
@@ -31,7 +31,7 @@ module VagrantSubutai
31
31
  when 'open'
32
32
  subutai_cli.open(check_subutai_console_url(subutai_cli))
33
33
  when 'blueprint'
34
- subutai_cli.blueprint(check_subutai_console_url(subutai_cli))
34
+ subutai_cli.blueprint(check_subutai_console_url(subutai_cli), 1)
35
35
  when '-h'
36
36
  STDOUT.puts cli_info
37
37
  when '--help'
@@ -54,7 +54,7 @@ module VagrantSubutai
54
54
  ip = subutai_cli.info(Configs::VagrantCommand::ARG_IP_ADDR)
55
55
 
56
56
  if ip.nil?
57
- STDOUT.puts 'We can\'t detect your Subutai Console ip address!'
57
+ STDOUT.puts 'We can\'t detect your PeerOS ip address!'
58
58
  exit
59
59
  end
60
60
  "https://#{ip}:#{Configs::SubutaiConsoleAPI::PORT}"
@@ -122,7 +122,10 @@ module VagrantSubutai
122
122
  LOG = '/rest/v1/tracker/operations/ENVIRONMENT%20MANAGER/'.freeze
123
123
  RESOURCES = '/rest/v1/peer/resources?sptoken='.freeze
124
124
  DOMAIN = '/rest/ui/environments/'.freeze
125
+ READY = '/rest/v1/peer/ready'.freeze
125
126
  end
127
+ LOGIN = '/login'.freeze
128
+ DEFAULT_PASSWORDS = 'secret'.freeze
126
129
  end
127
130
 
128
131
  module Gorjun
@@ -150,6 +153,7 @@ module VagrantSubutai
150
153
 
151
154
  module Blueprint
152
155
  FILE_NAME = 'Subutai.json'.freeze
156
+ ATTEMPT = 10.freeze
153
157
  end
154
158
 
155
159
  module EnvironmentState
@@ -82,6 +82,7 @@ module SubutaiConfig
82
82
  SUBUTAI_CPU: 2, # virtual CPU's assign to the vm
83
83
  SUBUTAI_NAME: 'My Peer', # PeerOS name
84
84
  SUBUTAI_SCOPE: 'Public', # PeerOS scope
85
+ SUBUTAI_USERNAME: 'admin', # PeerOS default username
85
86
 
86
87
  # Configuration parameters below have not been implemented
87
88
  SUBUTAI_SNAP: nil, # alternative snap to provision
@@ -45,12 +45,12 @@ module VagrantSubutai
45
45
  ip = subutai_cli.info(Configs::VagrantCommand::ARG_IP_ADDR)
46
46
 
47
47
  if ip.nil?
48
- STDOUT.puts 'We can\'t detect your Subutai Console ip address!'
48
+ STDOUT.puts 'We can\'t detect your PeerOS ip address!'
49
49
  exit
50
50
  end
51
51
  url = "https://#{ip}:#{Configs::SubutaiConsoleAPI::PORT}"
52
52
 
53
- subutai_cli.blueprint(url)
53
+ subutai_cli.blueprint(url, 1)
54
54
  end
55
55
  end
56
56
 
@@ -23,6 +23,20 @@ module VagrantSubutai
23
23
  https.request(request)
24
24
  end
25
25
 
26
+ # Change password
27
+ def self.password(url, username, password, new_password)
28
+ uri = URI.parse(url + Configs::SubutaiConsoleAPI::LOGIN)
29
+ https = Net::HTTP.new(uri.host, uri.port)
30
+ https.use_ssl = true
31
+ https.verify_mode = OpenSSL::SSL::VERIFY_NONE
32
+ https.read_timeout = 3600 # an hour
33
+
34
+ request = Net::HTTP::Post.new(uri.request_uri)
35
+ request.set_form_data('username' => username, 'password' => password, 'newpassword' => new_password)
36
+
37
+ https.request(request)
38
+ end
39
+
26
40
  # Subutai Hub credentials email, password
27
41
  # specify your peer_name
28
42
  # peer_scope acceptable only like this "Public" : "Private"
@@ -52,6 +66,18 @@ module VagrantSubutai
52
66
  https.request(request)
53
67
  end
54
68
 
69
+ def self.ready(url)
70
+ uri = URI.parse(url + Configs::SubutaiConsoleAPI::V1::READY)
71
+ https = Net::HTTP.new(uri.host, uri.port)
72
+ https.use_ssl = true
73
+ https.verify_mode = OpenSSL::SSL::VERIFY_NONE
74
+ https.read_timeout = 3600 # an hour
75
+
76
+ request = Net::HTTP::Get.new(uri.request_uri)
77
+
78
+ https.request(request)
79
+ end
80
+
55
81
  # Gets Finger print Subutai Console
56
82
  def self.fingerprint(url)
57
83
  uri = URI.parse(url + Configs::SubutaiConsoleAPI::V1::FINGERPRINT)
@@ -48,46 +48,60 @@ module VagrantSubutai
48
48
 
49
49
  # checks The Peer Os registered or not registered to Bazaar
50
50
  def registered?(url)
51
- fingerprint = Rest::SubutaiConsole.fingerprint(url)
52
- response = Rest::Bazaar.registered(fingerprint)
51
+ begin
52
+ fingerprint = Rest::SubutaiConsole.fingerprint(url)
53
+ response = Rest::Bazaar.registered(fingerprint)
53
54
 
54
- case response
55
- when Net::HTTPOK
56
- return true
57
- when Net::HTTPNotFound
58
- return false
59
- else
60
- Put.error response.body
61
- Put.error response.message
62
- exit
55
+ case response
56
+ when Net::HTTPOK
57
+ return true
58
+ when Net::HTTPNotFound
59
+ return false
60
+ else
61
+ Put.error response.body
62
+ Put.error response.message
63
+ exit
64
+ end
65
+ rescue Net::OpenTimeout => e
66
+ Put.error e
63
67
  end
64
68
  end
65
69
 
66
70
  # register Subutai Peer Os to Bazaar by username and password
67
71
  def register(username, password, url)
68
72
  if registered?(url)
69
- Put.warn "\nThe Peer Os already registered to Bazaar.\n"
73
+ Put.warn "\nThe PeerOs already registered to Bazaar.\n"
70
74
  else
71
- username, password = get_input_token if username.nil? && password.nil?
72
- response = Rest::SubutaiConsole.token(url, username, password)
75
+ begin
76
+ username, password = get_input_token if username.nil? || password.nil?
73
77
 
74
- case response
75
- when Net::HTTPOK
76
- hub_email, hub_password, peer_name, peer_scope = get_input_register
77
- peer_scope = peer_scope == 1 ? 'Public':'Private'
78
- response = Rest::SubutaiConsole.register(response.body, url, hub_email, hub_password, peer_name, peer_scope)
79
-
80
- case response
81
- when Net::HTTPOK
82
- Put.success response.body
83
- Put.success "\"#{peer_name}\" successfully registered to Bazaar."
84
- else
85
- Put.error "Error: #{response.body}\n"
86
- register(username, password, url)
87
- end
88
- else
89
- Put.error "Error: #{response.body}\n"
90
- register(nil, nil, url)
78
+ res = Rest::SubutaiConsole.password(url, username, Configs::SubutaiConsoleAPI::DEFAULT_PASSWORDS, password)
79
+
80
+ case res
81
+ when Net::HTTPOK
82
+ Put.info "\nSuccessfully changed default password.\n"
83
+ end
84
+
85
+ response = Rest::SubutaiConsole.token(url, username, password)
86
+
87
+ case response
88
+ when Net::HTTPOK
89
+ hub_email, hub_password, peer_name, peer_scope = get_input_register
90
+
91
+ response = Rest::SubutaiConsole.register(response.body, url, hub_email, hub_password, peer_name, peer_scope)
92
+
93
+ case response
94
+ when Net::HTTPOK
95
+ Put.success response.body
96
+ Put.success "\"#{peer_name}\" successfully registered to Bazaar."
97
+ else
98
+ Put.error "Error: #{response.body}\n"
99
+ end
100
+ else
101
+ Put.error "Error: #{response.body}\n"
102
+ end
103
+ rescue Net::OpenTimeout => e
104
+ Put.error e
91
105
  end
92
106
  end
93
107
  end
@@ -104,14 +118,17 @@ module VagrantSubutai
104
118
  [hub_email, hub_password]
105
119
  else
106
120
  Put.error "Error: #{response.body}\n"
107
- register_by_token(token, url)
108
121
  end
109
122
  end
110
123
 
111
124
  # Show Subutai Console finger print
112
125
  def fingerprint(url)
113
- peer_id = Rest::SubutaiConsole.fingerprint(url)
114
- Put.info peer_id
126
+ begin
127
+ peer_id = Rest::SubutaiConsole.fingerprint(url)
128
+ Put.info peer_id
129
+ rescue Net::OpenTimeout => e
130
+ Put.error e
131
+ end
115
132
  end
116
133
 
117
134
  # Get Subutai Peer Os credentials from input
@@ -121,7 +138,7 @@ module VagrantSubutai
121
138
 
122
139
  if SubutaiConfig.get(:SUBUTAI_USERNAME).nil?
123
140
  Put.warn "\nPlease enter credentials Subutai Peer Os:\n"
124
- Put.info "\nusername: "
141
+ Put.info "\nPeerOS username: "
125
142
  username = STDIN.gets.chomp
126
143
  else
127
144
  username = SubutaiConfig.get(:SUBUTAI_USERNAME)
@@ -130,7 +147,7 @@ module VagrantSubutai
130
147
 
131
148
  if SubutaiConfig.get(:SUBUTAI_PASSWORD).nil?
132
149
  begin
133
- Put.info "\npassword: "
150
+ Put.info "\nPeerOS password: "
134
151
  password = STDIN.noecho(&:gets).chomp
135
152
  rescue Errno::EBADF
136
153
  Put.warn "\nStdin doesn't support echo less input. Stdin can't hide password\n"
@@ -177,7 +194,7 @@ module VagrantSubutai
177
194
 
178
195
  # Get Bazaar credentials and peer info
179
196
  def get_input_register
180
- Put.warn "\nRegister your peer to Bazaar:\n"
197
+ Put.warn "\nRegister your PeerOS to Bazaar:\n"
181
198
 
182
199
  hub_password = nil
183
200
  hub_email = nil
@@ -216,37 +233,77 @@ module VagrantSubutai
216
233
  ssh(base + "#{Configs::SubutaiAgentCommand::LIST} #{arg}")
217
234
  end
218
235
 
219
- def blueprint(url)
220
- variable = VagrantSubutai::Blueprint::VariablesController.new(0, 0, nil)
236
+ def blueprint(url, attempt)
237
+ begin
238
+ response = Rest::SubutaiConsole.ready(url)
221
239
 
222
- resource = info('system')
223
-
224
- if variable.validate && variable.check_quota?(resource)
225
- mode = SubutaiConfig.get(:SUBUTAI_ENV_TYPE)
226
-
227
- if mode.nil?
228
- # check smart defaults
229
- fingerprint = Rest::SubutaiConsole.fingerprint(url)
230
- response = Rest::Bazaar.registered(fingerprint)
231
-
232
- case response
233
- when Net::HTTPOK
234
- # [MODE] The blueprint provisioning via Bazaar
235
- bazaar(url)
236
- when Net::HTTPNotFound
237
- # [MODE] blueprint provisioning via Peer Os (local)
238
- peer(url, resource)
239
- else
240
- Put.error response.message
241
- Put.error response.body
242
- end
243
- elsif mode == Configs::Blueprint::MODE::PEER
244
- # [MODE] blueprint provisioning via Peer Os (local)
245
- peer(url, resource)
246
- elsif mode == Configs::Blueprint::MODE::BAZAAR
247
- # [MODE] The blueprint provisioning via Bazaar
248
- bazaar(url)
240
+ case response
241
+ when Net::HTTPOK # 200 Ready
242
+ # start provisioning
243
+ variable = VagrantSubutai::Blueprint::VariablesController.new(0, 0, nil)
244
+
245
+ resource = info('system')
246
+
247
+ if variable.validate && variable.check_quota?(resource)
248
+ mode = SubutaiConfig.get(:SUBUTAI_ENV_TYPE)
249
+
250
+ if mode.nil?
251
+ # check smart defaults
252
+ fingerprint = Rest::SubutaiConsole.fingerprint(url)
253
+ response = Rest::Bazaar.registered(fingerprint)
254
+
255
+ case response
256
+ when Net::HTTPOK
257
+ # [MODE] The blueprint provisioning via Bazaar
258
+ bazaar(url)
259
+ when Net::HTTPNotFound
260
+ # [MODE] blueprint provisioning via Peer Os (local)
261
+ peer(url, resource)
262
+ else
263
+ Put.error response.message
264
+ Put.error response.body
265
+ end
266
+ elsif mode == Configs::Blueprint::MODE::PEER
267
+ # [MODE] blueprint provisioning via Peer Os (local)
268
+ peer(url, resource)
269
+ elsif mode == Configs::Blueprint::MODE::BAZAAR
270
+ # [MODE] The blueprint provisioning via Bazaar
271
+ bazaar(url)
272
+ end
273
+ end
274
+ when response.code == 503
275
+ if attempt < VagrantSubutai::Configs::Blueprint::ATTEMPT
276
+ sleep(2**attempt) #
277
+ blueprint(url, attempt+1)
278
+ end
279
+ when Net::HTTPNotFound
280
+ if attempt < VagrantSubutai::Configs::Blueprint::ATTEMPT
281
+ sleep(2**attempt) #
282
+ blueprint(url, attempt+1)
283
+ end
284
+ when response.code == 500 # management happened something wrong
285
+ Put.error "PeerOS failed to run!"
286
+ else
287
+ # PeerOs not ready
288
+ Put.error "PeerOS failed to run"
289
+ end
290
+ rescue Net::OpenTimeout => timeout
291
+ if attempt < VagrantSubutai::Configs::Blueprint::ATTEMPT
292
+ sleep(2**attempt) #
293
+ blueprint(url, attempt+1)
249
294
  end
295
+ rescue Errno::ECONNRESET
296
+ if attempt < VagrantSubutai::Configs::Blueprint::ATTEMPT
297
+ sleep(2**attempt) #
298
+ blueprint(url, attempt+1)
299
+ end
300
+ rescue OpenSSL::OpenSSLError # generic openssl error
301
+ if attempt < VagrantSubutai::Configs::Blueprint::ATTEMPT
302
+ sleep(2**attempt) #
303
+ blueprint(url, attempt+1)
304
+ end
305
+ rescue => e
306
+ Put.error e
250
307
  end
251
308
  end
252
309
 
@@ -258,7 +315,15 @@ module VagrantSubutai
258
315
  username = SubutaiConfig.get(:SUBUTAI_USERNAME)
259
316
  password = SubutaiConfig.get(:SUBUTAI_PASSWORD)
260
317
 
261
- username, password = get_input_token if username.nil? && password.nil?
318
+ username, password = get_input_token if username.nil? || password.nil?
319
+
320
+ res = Rest::SubutaiConsole.password(url, username, Configs::SubutaiConsoleAPI::DEFAULT_PASSWORDS, password)
321
+
322
+ case res
323
+ when Net::HTTPOK
324
+ Put.info "\nSuccessfully changed default password.\n"
325
+ end
326
+
262
327
  response = Rest::SubutaiConsole.token(url, username, password)
263
328
 
264
329
  case response
@@ -270,8 +335,7 @@ module VagrantSubutai
270
335
  env.check_free_quota(resource)
271
336
  env.build(url, response.body, rh_id, peer_id, Configs::Blueprint::MODE::PEER)
272
337
  else
273
- Put.error "Error: #{response.body}"
274
- Put.warn "\n[WARNING] if you have a new PeerOS make sure you have to change the default UI console password. It’s default credentials are ‘admin’ / ‘secret’.\n"
338
+ Put.error "PeerOS: Error #{response.body}"
275
339
  end
276
340
  end
277
341
 
@@ -288,19 +352,28 @@ module VagrantSubutai
288
352
  username = SubutaiConfig.get(:SUBUTAI_USERNAME)
289
353
  pwd = SubutaiConfig.get(:SUBUTAI_PASSWORD)
290
354
 
291
- username, pwd = get_input_token if username.nil? && pwd.nil?
355
+ username, pwd = get_input_token if username.nil? || pwd.nil?
356
+
357
+ res = Rest::SubutaiConsole.password(url, username, Configs::SubutaiConsoleAPI::DEFAULT_PASSWORDS, pwd)
358
+
359
+ case res
360
+ when Net::HTTPOK
361
+ Put.info "\nSuccessfully changed default password.\n"
362
+ end
363
+
292
364
  response = Rest::SubutaiConsole.token(url, username, pwd)
293
365
 
294
366
  case response
295
367
  when Net::HTTPOK
296
368
  email, password = register_by_token(response.body, url)
297
369
  else
298
- Put.error response.body
370
+ Put.error "PeerOS: #{response.body}"
299
371
  Put.error response.message
372
+ return
300
373
  end
301
374
  end
302
375
 
303
- email, password = get_input_login if email.nil? && password.nil?
376
+ email, password = get_input_login if email.nil? || password.nil?
304
377
 
305
378
  response = Rest::Bazaar.login(email, password)
306
379
 
@@ -319,7 +392,7 @@ module VagrantSubutai
319
392
  env = Blueprint::EnvironmentController.new
320
393
  env.build(url, cookies, rh_id, peer_id, Configs::Blueprint::MODE::BAZAAR)
321
394
  else
322
- Put.error response.body
395
+ Put.error "Bazaar: #{response.body}"
323
396
  end
324
397
  end
325
398
 
@@ -1,3 +1,3 @@
1
1
  module VagrantSubutai
2
- VERSION = '1.1.0'
2
+ VERSION = '1.1.1'
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.0
4
+ version: 1.1.1
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-13 00:00:00.000000000 Z
11
+ date: 2018-03-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler