vagrant-subutai 1.0.3 → 1.1.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 +4 -4
- data/.gitignore +2 -1
- data/CHANGELOG.md +7 -0
- data/README.md +3 -2
- data/lib/vagrant-subutai.rb +33 -7
- data/lib/vagrant-subutai/blueprint/ansible_controller.rb +93 -0
- data/lib/vagrant-subutai/blueprint/environment_controller.rb +324 -0
- data/lib/vagrant-subutai/blueprint/variables_controller.rb +547 -0
- data/lib/vagrant-subutai/command.rb +84 -90
- data/lib/vagrant-subutai/config.rb +8 -43
- data/lib/vagrant-subutai/configs/configs.rb +179 -0
- data/lib/vagrant-subutai/models/ansible.rb +18 -0
- data/lib/vagrant-subutai/models/console/container.rb +27 -0
- data/lib/vagrant-subutai/models/console/environment.rb +16 -0
- data/lib/vagrant-subutai/models/container.rb +34 -0
- data/lib/vagrant-subutai/models/domain.rb +11 -0
- data/lib/vagrant-subutai/models/environment.rb +13 -0
- data/lib/vagrant-subutai/packer/subutai_config.rb +17 -1
- data/lib/vagrant-subutai/plugin.rb +10 -3
- data/lib/vagrant-subutai/provisioner.rb +63 -0
- data/lib/vagrant-subutai/put.rb +21 -0
- data/lib/vagrant-subutai/rest/bazaar.rb +141 -0
- data/lib/vagrant-subutai/rest/gorjun.rb +40 -0
- data/lib/vagrant-subutai/rest/subutai_console.rb +189 -0
- data/lib/vagrant-subutai/subutai_commands.rb +250 -122
- data/lib/vagrant-subutai/version.rb +1 -1
- metadata +18 -6
- data/Vagrantfile +0 -7
- data/lib/vagrant-subutai/models/resource_host.rb +0 -7
- data/lib/vagrant-subutai/rest.rb +0 -77
- data/lib/vagrant-subutai/rh_controller.rb +0 -32
@@ -0,0 +1,189 @@
|
|
1
|
+
require 'net/https'
|
2
|
+
require 'uri'
|
3
|
+
require_relative '../../vagrant-subutai'
|
4
|
+
require 'mime/types'
|
5
|
+
require 'json'
|
6
|
+
|
7
|
+
module VagrantSubutai
|
8
|
+
module Rest
|
9
|
+
class SubutaiConsole
|
10
|
+
# Subutai Console credentials username, password
|
11
|
+
# Subutai Console url
|
12
|
+
# login methods gets token
|
13
|
+
def self.token(url, username, password)
|
14
|
+
uri = URI.parse(url + Configs::SubutaiConsoleAPI::V1::TOKEN)
|
15
|
+
https = Net::HTTP.new(uri.host, uri.port)
|
16
|
+
https.use_ssl = true
|
17
|
+
https.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
18
|
+
https.read_timeout = 3600 # an hour
|
19
|
+
|
20
|
+
request = Net::HTTP::Post.new(uri.request_uri)
|
21
|
+
request.set_form_data('username' => username, 'password' => password)
|
22
|
+
|
23
|
+
https.request(request)
|
24
|
+
end
|
25
|
+
|
26
|
+
# Subutai Hub credentials email, password
|
27
|
+
# specify your peer_name
|
28
|
+
# peer_scope acceptable only like this "Public" : "Private"
|
29
|
+
def self.register(token, url, email, password, peer_name, peer_scope)
|
30
|
+
uri = URI.parse(url + Configs::SubutaiConsoleAPI::V1::REGISTER_HUB + token)
|
31
|
+
https = Net::HTTP.new(uri.host, uri.port)
|
32
|
+
https.use_ssl = true
|
33
|
+
https.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
34
|
+
https.read_timeout = 3600 # an hour
|
35
|
+
|
36
|
+
request = Net::HTTP::Post.new(uri.request_uri)
|
37
|
+
request.set_form_data({'email' => email, 'password' => password, 'peerName' => peer_name, 'peerScope' => peer_scope})
|
38
|
+
|
39
|
+
https.request(request)
|
40
|
+
end
|
41
|
+
|
42
|
+
# Approves Resource Host
|
43
|
+
def self.approve(token, url, id)
|
44
|
+
uri = URI.parse(url + Configs::SubutaiConsoleAPI::V1::APPROVE + "/#{id}/approve?sptoken?=" + token)
|
45
|
+
https = Net::HTTP.new(uri.host, uri.port)
|
46
|
+
https.use_ssl = true
|
47
|
+
https.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
48
|
+
https.read_timeout = 3600 # an hour
|
49
|
+
|
50
|
+
request = Net::HTTP::Post.new(uri.request_uri)
|
51
|
+
|
52
|
+
https.request(request)
|
53
|
+
end
|
54
|
+
|
55
|
+
# Gets Finger print Subutai Console
|
56
|
+
def self.fingerprint(url)
|
57
|
+
uri = URI.parse(url + Configs::SubutaiConsoleAPI::V1::FINGERPRINT)
|
58
|
+
https = Net::HTTP.new(uri.host, uri.port)
|
59
|
+
https.use_ssl = true
|
60
|
+
https.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
61
|
+
https.read_timeout = 3600 # an hour
|
62
|
+
|
63
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
64
|
+
|
65
|
+
response = https.request(request)
|
66
|
+
|
67
|
+
case response
|
68
|
+
when Net::HTTPOK
|
69
|
+
response.body
|
70
|
+
else
|
71
|
+
raise "Try again! #{response.body}"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
# Get Subutai Console RH requests
|
76
|
+
# method GET
|
77
|
+
def self.requests(url, token)
|
78
|
+
uri = URI.parse(url + Configs::SubutaiConsoleAPI::V1::REQUESTS + token)
|
79
|
+
https = Net::HTTP.new(uri.host, uri.port)
|
80
|
+
https.use_ssl = true
|
81
|
+
https.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
82
|
+
https.read_timeout = 3600 # an hour
|
83
|
+
|
84
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
85
|
+
|
86
|
+
https.request(request)
|
87
|
+
end
|
88
|
+
|
89
|
+
# Creates Environment
|
90
|
+
# method POST
|
91
|
+
def self.environment(url, token, params)
|
92
|
+
uri = URI.parse(url + Configs::SubutaiConsoleAPI::V1::ENVIRONMENT + token)
|
93
|
+
https = Net::HTTP.new(uri.host, uri.port)
|
94
|
+
https.use_ssl = true
|
95
|
+
https.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
96
|
+
https.read_timeout = 21600 # 6 hours
|
97
|
+
|
98
|
+
request = Net::HTTP::Post.new(uri.request_uri)
|
99
|
+
request.set_form_data({'topology' => params})
|
100
|
+
|
101
|
+
https.request(request)
|
102
|
+
end
|
103
|
+
|
104
|
+
# Gets Peer Os resources (disk, ram and cpu)
|
105
|
+
# method GET
|
106
|
+
def self.resource(url, token)
|
107
|
+
uri = URI.parse(url + Configs::SubutaiConsoleAPI::V1::RESOURCES + token)
|
108
|
+
https = Net::HTTP.new(uri.host, uri.port)
|
109
|
+
https.use_ssl = true
|
110
|
+
https.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
111
|
+
https.read_timeout = 3600 # an hour
|
112
|
+
|
113
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
114
|
+
|
115
|
+
https.request(request)
|
116
|
+
end
|
117
|
+
|
118
|
+
# List Environments
|
119
|
+
# method GET
|
120
|
+
def self.environments(url, token)
|
121
|
+
uri = URI.parse(url + Configs::SubutaiConsoleAPI::V1::ENVIRONMENTS + token)
|
122
|
+
https = Net::HTTP.new(uri.host, uri.port)
|
123
|
+
https.use_ssl = true
|
124
|
+
https.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
125
|
+
https.read_timeout = 3600 # an hour
|
126
|
+
|
127
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
128
|
+
|
129
|
+
https.request(request)
|
130
|
+
end
|
131
|
+
|
132
|
+
# Sends command to Subutai Console
|
133
|
+
# method POST
|
134
|
+
def self.command(cmd, hostId, path, timeOut, url, token)
|
135
|
+
uri = URI.parse(url + Configs::SubutaiConsoleAPI::COMMAND + token)
|
136
|
+
https = Net::HTTP.new(uri.host, uri.port)
|
137
|
+
https.use_ssl = true
|
138
|
+
https.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
139
|
+
https.read_timeout = 21600 # 6 hours
|
140
|
+
|
141
|
+
request = Net::HTTP::Post.new(uri.request_uri)
|
142
|
+
request.set_form_data({'command' => cmd, 'hostId' => hostId, 'path' => path, 'timeOut' => timeOut})
|
143
|
+
|
144
|
+
https.request(request)
|
145
|
+
end
|
146
|
+
|
147
|
+
# Gives logs of Blueprint Environment builds
|
148
|
+
# method GET
|
149
|
+
def self.log(url, token, tracker_id)
|
150
|
+
uri = URI.parse(url + Configs::SubutaiConsoleAPI::V1::LOG + "#{tracker_id}?sptoken=#{token}")
|
151
|
+
https = Net::HTTP.new(uri.host, uri.port)
|
152
|
+
https.use_ssl = true
|
153
|
+
https.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
154
|
+
https.read_timeout = 21600 # 6 hours
|
155
|
+
|
156
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
157
|
+
|
158
|
+
https.request(request)
|
159
|
+
end
|
160
|
+
|
161
|
+
# Add domain to Environment
|
162
|
+
def self.domain(url, token, env_id, domain)
|
163
|
+
uri = URI.parse("#{url}#{Configs::SubutaiConsoleAPI::V1::DOMAIN}#{env_id}/domains?sptoken=#{token}")
|
164
|
+
https = Net::HTTP.new(uri.host, uri.port)
|
165
|
+
https.use_ssl = true
|
166
|
+
https.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
167
|
+
https.read_timeout = 3600 # an hour
|
168
|
+
|
169
|
+
request = Net::HTTP::Post.new(uri.request_uri)
|
170
|
+
request.set_form([['file', ''], ['hostName', domain], ['strategy', 'NONE']], 'multipart/form-data')
|
171
|
+
|
172
|
+
https.request(request)
|
173
|
+
end
|
174
|
+
|
175
|
+
# Add port to container
|
176
|
+
def self.port(url, token, env_id, cont_id, port)
|
177
|
+
uri = URI.parse("#{url}#{Configs::SubutaiConsoleAPI::V1::DOMAIN}#{env_id}/containers/#{cont_id}/domainnport?state=true&port=#{port}&sptoken=#{token}")
|
178
|
+
https = Net::HTTP.new(uri.host, uri.port)
|
179
|
+
https.use_ssl = true
|
180
|
+
https.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
181
|
+
https.read_timeout = 3600 # an hour
|
182
|
+
|
183
|
+
request = Net::HTTP::Put.new(uri.request_uri)
|
184
|
+
|
185
|
+
https.request(request)
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
@@ -1,9 +1,7 @@
|
|
1
1
|
require_relative '../vagrant-subutai'
|
2
|
-
require_relative 'command'
|
3
2
|
require 'net/https'
|
4
3
|
require 'io/console'
|
5
4
|
require 'fileutils'
|
6
|
-
require_relative 'rh_controller'
|
7
5
|
|
8
6
|
module VagrantSubutai
|
9
7
|
class Commands < Vagrant.plugin('2', :command)
|
@@ -14,17 +12,17 @@ module VagrantSubutai
|
|
14
12
|
|
15
13
|
# show snap logs
|
16
14
|
def log
|
17
|
-
ssh(base + SubutaiAgentCommand::LOG)
|
15
|
+
ssh(base + Configs::SubutaiAgentCommand::LOG)
|
18
16
|
end
|
19
17
|
|
20
18
|
def base
|
21
19
|
env = SubutaiConfig.get(:SUBUTAI_ENV)
|
22
20
|
|
23
21
|
if env.nil?
|
24
|
-
SubutaiAgentCommand::BASE
|
22
|
+
Configs::SubutaiAgentCommand::BASE
|
25
23
|
else
|
26
|
-
if env.to_s ==
|
27
|
-
SubutaiAgentCommand::BASE
|
24
|
+
if env.to_s == 'prod'
|
25
|
+
Configs::SubutaiAgentCommand::BASE
|
28
26
|
else
|
29
27
|
"sudo /snap/bin/subutai-#{env.to_s}"
|
30
28
|
end
|
@@ -34,10 +32,9 @@ module VagrantSubutai
|
|
34
32
|
# info id
|
35
33
|
def info(arg)
|
36
34
|
with_target_vms(nil, single_target: true) do |vm|
|
37
|
-
vm.communicate.sudo("#{base} #{SubutaiAgentCommand::INFO} #{arg}") do |type, data|
|
35
|
+
vm.communicate.sudo("#{base} #{Configs::SubutaiAgentCommand::INFO} #{arg}") do |type, data|
|
38
36
|
if type == :stdout
|
39
37
|
result = data.split(/[\r\n]+/)
|
40
|
-
STDOUT.puts result.first
|
41
38
|
return result.first
|
42
39
|
end
|
43
40
|
end
|
@@ -46,164 +43,295 @@ module VagrantSubutai
|
|
46
43
|
|
47
44
|
# update Subutai rh or management
|
48
45
|
def update(name)
|
49
|
-
ssh(base + SubutaiAgentCommand::UPDATE + " #{name}")
|
46
|
+
ssh(base + Configs::SubutaiAgentCommand::UPDATE + " #{name}")
|
50
47
|
end
|
51
48
|
|
52
|
-
#
|
53
|
-
def
|
54
|
-
|
55
|
-
response =
|
49
|
+
# checks The Peer Os registered or not registered to Bazaar
|
50
|
+
def registered?(url)
|
51
|
+
fingerprint = Rest::SubutaiConsole.fingerprint(url)
|
52
|
+
response = Rest::Bazaar.registered(fingerprint)
|
56
53
|
|
57
54
|
case response
|
58
55
|
when Net::HTTPOK
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
case response
|
64
|
-
when Net::HTTPOK
|
65
|
-
STDOUT.puts "You peer: \"#{peer_name}\" successfully registered to hub."
|
66
|
-
else
|
67
|
-
STDOUT.puts "Try again! #{response.body}\n"
|
68
|
-
register(username, password)
|
69
|
-
end
|
56
|
+
return true
|
57
|
+
when Net::HTTPNotFound
|
58
|
+
return false
|
70
59
|
else
|
71
|
-
|
72
|
-
|
60
|
+
Put.error response.body
|
61
|
+
Put.error response.message
|
62
|
+
exit
|
73
63
|
end
|
74
64
|
end
|
75
65
|
|
76
|
-
#
|
77
|
-
def
|
78
|
-
|
79
|
-
|
66
|
+
# register Subutai Peer Os to Bazaar by username and password
|
67
|
+
def register(username, password, url)
|
68
|
+
if registered?(url)
|
69
|
+
Put.warn "\nThe Peer Os already registered to Bazaar.\n"
|
70
|
+
else
|
71
|
+
username, password = get_input_token if username.nil? && password.nil?
|
72
|
+
response = Rest::SubutaiConsole.token(url, username, password)
|
73
|
+
|
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)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
80
94
|
|
81
|
-
|
82
|
-
|
83
|
-
|
95
|
+
# register Subutai Peer Os to Bazaar by token
|
96
|
+
def register_by_token(token, url)
|
97
|
+
hub_email, hub_password, peer_name, peer_scope = get_input_register
|
98
|
+
response = Rest::SubutaiConsole.register(token, url, hub_email, hub_password, peer_name, peer_scope)
|
84
99
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
100
|
+
case response
|
101
|
+
when Net::HTTPOK
|
102
|
+
Put.success response.body
|
103
|
+
Put.success "\"#{peer_name}\" successfully registered to Bazaar."
|
104
|
+
[hub_email, hub_password]
|
105
|
+
else
|
106
|
+
Put.error "Error: #{response.body}\n"
|
107
|
+
register_by_token(token, url)
|
108
|
+
end
|
109
|
+
end
|
91
110
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
}
|
111
|
+
# Show Subutai Console finger print
|
112
|
+
def fingerprint(url)
|
113
|
+
peer_id = Rest::SubutaiConsole.fingerprint(url)
|
114
|
+
Put.info peer_id
|
115
|
+
end
|
98
116
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
end
|
104
|
-
}
|
117
|
+
# Get Subutai Peer Os credentials from input
|
118
|
+
def get_input_token
|
119
|
+
password = nil
|
120
|
+
username = nil
|
105
121
|
|
106
|
-
|
107
|
-
|
108
|
-
|
122
|
+
if SubutaiConfig.get(:SUBUTAI_USERNAME).nil?
|
123
|
+
Put.warn "\nPlease enter credentials Subutai Peer Os:\n"
|
124
|
+
Put.info "\nusername: "
|
125
|
+
username = STDIN.gets.chomp
|
126
|
+
else
|
127
|
+
username = SubutaiConfig.get(:SUBUTAI_USERNAME)
|
128
|
+
end
|
109
129
|
|
110
|
-
STDOUT.puts "Subutai Console(Peer)"
|
111
|
-
STDOUT.puts "ip: #{ip}"
|
112
|
-
STDOUT.puts "fingerprint: #{fingerprint}"
|
113
130
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
131
|
+
if SubutaiConfig.get(:SUBUTAI_PASSWORD).nil?
|
132
|
+
begin
|
133
|
+
Put.info "\npassword: "
|
134
|
+
password = STDIN.noecho(&:gets).chomp
|
135
|
+
rescue Errno::EBADF
|
136
|
+
Put.warn "\nStdin doesn't support echo less input. Stdin can't hide password\n"
|
137
|
+
password = STDIN.gets
|
138
|
+
end
|
139
|
+
else
|
140
|
+
password = SubutaiConfig.get(:SUBUTAI_PASSWORD)
|
141
|
+
end
|
119
142
|
|
120
|
-
|
121
|
-
|
122
|
-
Dir.chdir(peer_path){
|
123
|
-
r, w = IO.pipe
|
143
|
+
[username, password]
|
144
|
+
end
|
124
145
|
|
125
|
-
|
146
|
+
# Get Bazaar credentials from input
|
147
|
+
def get_input_login
|
126
148
|
|
127
|
-
|
128
|
-
|
129
|
-
}
|
149
|
+
email = nil
|
150
|
+
password = nil
|
130
151
|
|
131
|
-
|
132
|
-
|
152
|
+
if SubutaiConfig.get(:BAZAAR_EMAIL).nil?
|
153
|
+
# Bazaar email
|
154
|
+
Put.warn "\nPlease enter credentials Bazaar:\n"
|
155
|
+
Put.info "\nemail: "
|
156
|
+
email = STDIN.gets.chomp
|
157
|
+
else
|
158
|
+
email = SubutaiConfig.get(:BAZAAR_EMAIL)
|
159
|
+
end
|
133
160
|
|
134
|
-
if found.nil?
|
135
|
-
raise 'RH not send request to Subutai Console for approve'
|
136
|
-
else
|
137
|
-
# TODO send REST call for approve RH to Subutai Console
|
138
|
-
end
|
139
161
|
|
140
|
-
|
162
|
+
if SubutaiConfig.get(:BAZAAR_PASSWORD).nil?
|
163
|
+
# Bazaar password
|
164
|
+
begin
|
165
|
+
Put.info "\nEnter Bazaar password: "
|
166
|
+
password = STDIN.noecho(&:gets).chomp
|
167
|
+
rescue Errno::EBADF
|
168
|
+
Put.warn "\nStdin doesn't support echo less input. Stdin can't hide password\n"
|
169
|
+
password = STDIN.gets
|
170
|
+
end
|
171
|
+
else
|
172
|
+
password = SubutaiConfig.get(:BAZAAR_PASSWORD)
|
141
173
|
end
|
174
|
+
|
175
|
+
[email, password]
|
142
176
|
end
|
143
177
|
|
144
|
-
#
|
145
|
-
def
|
146
|
-
|
178
|
+
# Get Bazaar credentials and peer info
|
179
|
+
def get_input_register
|
180
|
+
Put.warn "\nRegister your peer to Bazaar:\n"
|
147
181
|
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
182
|
+
hub_password = nil
|
183
|
+
hub_email = nil
|
184
|
+
|
185
|
+
if SubutaiConfig.get(:BAZAAR_EMAIL).nil?
|
186
|
+
# Hub email
|
187
|
+
Put.info "\nEnter Bazaar email: "
|
188
|
+
hub_email = STDIN.gets.chomp
|
189
|
+
else
|
190
|
+
hub_email = SubutaiConfig.get(:BAZAAR_EMAIL)
|
191
|
+
end
|
192
|
+
|
193
|
+
|
194
|
+
if SubutaiConfig.get(:BAZAAR_PASSWORD).nil?
|
195
|
+
# Hub password
|
196
|
+
begin
|
197
|
+
Put.info "\nEnter Bazaar password: "
|
198
|
+
hub_password = STDIN.noecho(&:gets).chomp
|
199
|
+
rescue Errno::EBADF
|
200
|
+
Put.warn "\nStdin doesn't support echo less input. Stdin can't hide password\n"
|
201
|
+
hub_password = STDIN.gets
|
202
|
+
end
|
203
|
+
else
|
204
|
+
hub_password = SubutaiConfig.get(:BAZAAR_PASSWORD)
|
153
205
|
end
|
206
|
+
|
207
|
+
# Peer name
|
208
|
+
peer_name = SubutaiConfig.get(:SUBUTAI_NAME)
|
209
|
+
|
210
|
+
peer_scope = SubutaiConfig.get(:SUBUTAI_SCOPE)
|
211
|
+
|
212
|
+
[hub_email, hub_password, peer_name, peer_scope]
|
154
213
|
end
|
155
214
|
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
STDOUT.puts "username: "
|
160
|
-
username = STDIN.gets.chomp
|
161
|
-
puts "password: "
|
162
|
-
password = STDIN.noecho(&:gets).chomp
|
215
|
+
def list(arg)
|
216
|
+
ssh(base + "#{Configs::SubutaiAgentCommand::LIST} #{arg}")
|
217
|
+
end
|
163
218
|
|
164
|
-
|
219
|
+
def blueprint(url)
|
220
|
+
variable = VagrantSubutai::Blueprint::VariablesController.new(0, 0, nil)
|
221
|
+
|
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)
|
249
|
+
end
|
250
|
+
end
|
165
251
|
end
|
166
252
|
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
253
|
+
def peer(url, resource)
|
254
|
+
Put.success "\n--------------------------------------"
|
255
|
+
Put.success "| Blueprint provisioning via Peer Os |"
|
256
|
+
Put.success "--------------------------------------\n"
|
257
|
+
|
258
|
+
username = SubutaiConfig.get(:SUBUTAI_USERNAME)
|
259
|
+
password = SubutaiConfig.get(:SUBUTAI_PASSWORD)
|
260
|
+
|
261
|
+
username, password = get_input_token if username.nil? && password.nil?
|
262
|
+
response = Rest::SubutaiConsole.token(url, username, password)
|
171
263
|
|
172
264
|
case response
|
173
265
|
when Net::HTTPOK
|
174
|
-
|
266
|
+
rh_id = info('id')
|
267
|
+
peer_id = Rest::SubutaiConsole.fingerprint(url)
|
268
|
+
|
269
|
+
env = Blueprint::EnvironmentController.new
|
270
|
+
env.check_free_quota(resource)
|
271
|
+
env.build(url, response.body, rh_id, peer_id, Configs::Blueprint::MODE::PEER)
|
175
272
|
else
|
176
|
-
|
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"
|
177
275
|
end
|
178
276
|
end
|
179
277
|
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
#
|
189
|
-
|
190
|
-
|
278
|
+
def bazaar(url)
|
279
|
+
Put.success "\n-------------------------------------"
|
280
|
+
Put.success "| Blueprint provisioning via Bazaar |"
|
281
|
+
Put.success "-------------------------------------\n"
|
282
|
+
|
283
|
+
email = SubutaiConfig.get(:BAZAAR_EMAIL)
|
284
|
+
password = SubutaiConfig.get(:BAZAAR_PASSWORD)
|
285
|
+
|
286
|
+
# Register Peer Os to Bazaar
|
287
|
+
unless registered?(url)
|
288
|
+
username = SubutaiConfig.get(:SUBUTAI_USERNAME)
|
289
|
+
pwd = SubutaiConfig.get(:SUBUTAI_PASSWORD)
|
290
|
+
|
291
|
+
username, pwd = get_input_token if username.nil? && pwd.nil?
|
292
|
+
response = Rest::SubutaiConsole.token(url, username, pwd)
|
293
|
+
|
294
|
+
case response
|
295
|
+
when Net::HTTPOK
|
296
|
+
email, password = register_by_token(response.body, url)
|
297
|
+
else
|
298
|
+
Put.error response.body
|
299
|
+
Put.error response.message
|
300
|
+
end
|
301
|
+
end
|
191
302
|
|
192
|
-
|
193
|
-
STDOUT.puts "Enter peer name: "
|
194
|
-
peer_name = STDIN.gets.chomp
|
303
|
+
email, password = get_input_login if email.nil? && password.nil?
|
195
304
|
|
196
|
-
|
197
|
-
STDOUT.puts "1. Public"
|
198
|
-
STDOUT.puts "2. Private"
|
199
|
-
STDOUT.puts "Choose your peer scope (1 or 2): "
|
200
|
-
peer_scope = STDIN.gets.chomp.to_i
|
305
|
+
response = Rest::Bazaar.login(email, password)
|
201
306
|
|
202
|
-
|
307
|
+
case response
|
308
|
+
when Net::HTTPOK
|
309
|
+
all_cookies = response.get_fields('set-cookie')
|
310
|
+
cookies_array = Array.new
|
311
|
+
all_cookies.each { | cookie |
|
312
|
+
cookies_array.push(cookie.split('; ')[0])
|
313
|
+
}
|
314
|
+
cookies = cookies_array.join('; ')
|
315
|
+
|
316
|
+
rh_id = info('id')
|
317
|
+
peer_id = Rest::SubutaiConsole.fingerprint(url)
|
318
|
+
|
319
|
+
env = Blueprint::EnvironmentController.new
|
320
|
+
env.build(url, cookies, rh_id, peer_id, Configs::Blueprint::MODE::BAZAAR)
|
321
|
+
else
|
322
|
+
Put.error response.body
|
323
|
+
end
|
203
324
|
end
|
204
325
|
|
205
|
-
|
206
|
-
|
326
|
+
# opens browser
|
327
|
+
def open(link)
|
328
|
+
if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
|
329
|
+
system "start #{link}"
|
330
|
+
elsif RbConfig::CONFIG['host_os'] =~ /darwin/
|
331
|
+
system "open #{link}"
|
332
|
+
elsif RbConfig::CONFIG['host_os'] =~ /linux|bsd/
|
333
|
+
system "xdg-open #{link}"
|
334
|
+
end
|
207
335
|
end
|
208
336
|
|
209
337
|
def ssh(command)
|