vagrant-node 1.0.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/lib/vagrant-node/actions/boxadd.rb +110 -0
- data/lib/vagrant-node/actions/snapshot.rb +1 -1
- data/lib/vagrant-node/api.rb +303 -270
- data/lib/vagrant-node/apidesc.rb +47 -21
- data/lib/vagrant-node/clientcontroller.rb +658 -415
- data/lib/vagrant-node/configmanager.rb +266 -85
- data/lib/vagrant-node/dbmanager.rb +300 -123
- data/lib/vagrant-node/exceptions.rb +15 -0
- data/lib/vagrant-node/nodeserverpasswd.rb +109 -34
- data/lib/vagrant-node/nodeserverstart.rb +4 -3
- data/lib/vagrant-node/nodeserverstop.rb +2 -1
- data/lib/vagrant-node/obmanager.rb +123 -0
- data/lib/vagrant-node/server.rb +27 -21
- data/lib/vagrant-node/util/downloader.rb +182 -0
- data/lib/vagrant-node/version.rb +1 -1
- data/vagrant-node.gemspec +17 -3
- metadata +65 -22
- data/lib/vagrant-node/actions/.svn/entries +0 -62
- data/lib/vagrant-node/actions/.svn/text-base/snapshot.rb.svn-base +0 -310
@@ -0,0 +1,110 @@
|
|
1
|
+
require 'pp'
|
2
|
+
require 'rubygems'
|
3
|
+
require 'vagrant-node/util/downloader'
|
4
|
+
require "vagrant/util/platform"
|
5
|
+
require 'vagrant-node/obmanager'
|
6
|
+
|
7
|
+
module Vagrant
|
8
|
+
module Node
|
9
|
+
class BoxAddAction
|
10
|
+
def initialize(app, env)
|
11
|
+
@app = app
|
12
|
+
end
|
13
|
+
|
14
|
+
def call(env)
|
15
|
+
@temp_path = env[:tmp_path].join("box" + Time.now.to_i.to_s)
|
16
|
+
|
17
|
+
|
18
|
+
url = env[:box_url]
|
19
|
+
if File.file?(url) || url !~ /^[a-z0-9]+:.*$/i
|
20
|
+
file_path = File.expand_path(url)
|
21
|
+
file_path = Util::Platform.cygwin_windows_path(file_path)
|
22
|
+
url = "file:#{file_path}"
|
23
|
+
end
|
24
|
+
|
25
|
+
downloader_options = {}
|
26
|
+
downloader_options[:callback] = env[:callback]
|
27
|
+
downloader_options[:insecure] = env[:box_download_insecure]
|
28
|
+
downloader_options[:ui] = env[:ui]
|
29
|
+
downloader_options[:db] = env[:db]
|
30
|
+
downloader_options[:box_name] = env[:box_name]
|
31
|
+
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
# Download the box to a temporary path. We store the temporary
|
36
|
+
# path as an instance variable so that the `#recover` method can
|
37
|
+
# access it.
|
38
|
+
#env[:ui].info(I18n.t("vagrant.actions.box.download.downloading"))
|
39
|
+
|
40
|
+
|
41
|
+
begin
|
42
|
+
downloader = Util::Downloader.new(url, @temp_path, downloader_options)
|
43
|
+
downloader.download!
|
44
|
+
rescue Errors::DownloaderInterrupted
|
45
|
+
# The downloader was interrupted, so just return, because that
|
46
|
+
# means we were interrupted as well.
|
47
|
+
#env[:ui].info(I18n.t("vagrant.actions.box.download.interrupted"))
|
48
|
+
return
|
49
|
+
rescue Errors::DownloaderError => msg
|
50
|
+
#puts msg.message.split(/\r\n/).inspect.length
|
51
|
+
|
52
|
+
#puts "CONTROLAR ESTE MENSAJE DE ERROR"
|
53
|
+
|
54
|
+
|
55
|
+
return
|
56
|
+
end
|
57
|
+
|
58
|
+
# Add the box
|
59
|
+
#env[:ui].info I18n.t("vagrant.actions.box.add.adding", :name => env[:box_name])
|
60
|
+
added_box = nil
|
61
|
+
error=false
|
62
|
+
|
63
|
+
begin
|
64
|
+
|
65
|
+
#last_id=env[:db].add_box_uncompression(env[:box_name],url)
|
66
|
+
last_id=ObManager.instance.dbmanager.add_box_uncompression(env[:box_name],url)
|
67
|
+
|
68
|
+
added_box = env[:box_collection].add(
|
69
|
+
@temp_path, env[:box_name], env[:box_provider], env[:box_force])
|
70
|
+
|
71
|
+
error=false
|
72
|
+
rescue Vagrant::Errors::BoxUpgradeRequired
|
73
|
+
|
74
|
+
error=true
|
75
|
+
# Upgrade the box
|
76
|
+
#@db.set_box_uncompression_error(last_id)
|
77
|
+
|
78
|
+
env[:box_collection].upgrade(env[:box_name])
|
79
|
+
|
80
|
+
# Try adding it again
|
81
|
+
retry
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
#env[:db].clear_box_uncompression(last_id) if (error==false)
|
86
|
+
#env[:db].clear_box_uncompression(last_id)
|
87
|
+
ObManager.instance.dbmanager.clear_box_uncompression(last_id)
|
88
|
+
|
89
|
+
#env[:db].close_db_connection
|
90
|
+
# Call the 'recover' method in all cases to clean up the
|
91
|
+
# downloaded temporary file.
|
92
|
+
recover(env)
|
93
|
+
|
94
|
+
# Success, we added a box!
|
95
|
+
#env[:ui].success(
|
96
|
+
# I18n.t("vagrant.actions.box.add.added", name: added_box.name, provider: added_box.provider))
|
97
|
+
|
98
|
+
# Carry on!
|
99
|
+
@app.call(env)
|
100
|
+
end
|
101
|
+
|
102
|
+
def recover(env)
|
103
|
+
if @temp_path && File.exist?(@temp_path)
|
104
|
+
File.unlink(@temp_path)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
@@ -67,7 +67,7 @@ module Vagrant
|
|
67
67
|
#se produce un error y deja a la máquina en estado 'gurumeditating'
|
68
68
|
def driver.take_snapshot(name,description=" ")
|
69
69
|
|
70
|
-
|
70
|
+
raise RestException.new(400,"Snapshot name can't be emtpy") if name.empty?
|
71
71
|
|
72
72
|
#Snapshots with the same name are not allowed
|
73
73
|
begin
|
data/lib/vagrant-node/api.rb
CHANGED
@@ -2,43 +2,35 @@ require 'rubygems'
|
|
2
2
|
require 'sinatra'
|
3
3
|
require 'json'
|
4
4
|
require 'rack'
|
5
|
-
|
5
|
+
require_relative 'clientcontroller'
|
6
6
|
require 'vagrant-node/apidesc'
|
7
7
|
require 'vagrant-node/exceptions'
|
8
|
-
|
9
8
|
require 'cgi'
|
10
|
-
|
11
9
|
require 'pp'
|
10
|
+
require 'vagrant-node/obmanager'
|
11
|
+
|
12
|
+
|
13
|
+
|
12
14
|
module Vagrant
|
13
|
-
|
14
|
-
|
15
|
+
module Node
|
16
|
+
module ServerAPI
|
15
17
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
# post '/' do
|
33
|
-
# tempfile = params['file'][:tempfile]
|
34
|
-
# filename = params['file'][:filename]
|
35
|
-
# File.copy(tempfile.path, "./files/#{filename}")
|
36
|
-
# redirect '/'
|
37
|
-
#end
|
38
|
-
|
39
|
-
#before '^.*(^login).*' do
|
40
|
-
before %r{^(?!#{RouteManager.login_route}$)} do
|
41
|
-
content_type :json
|
18
|
+
class API < Sinatra::Base
|
19
|
+
include RestRoutes
|
20
|
+
COOKIE_TOKEN_ID = "TOKEN"
|
21
|
+
COOKIE_EXPIRATION_TIME = 5
|
22
|
+
|
23
|
+
def initialize
|
24
|
+
super
|
25
|
+
@session_table=Hash.new
|
26
|
+
#ObManager.instance.env=env
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
#before '^.*(^login).*' do
|
32
|
+
before %r{^(?!#{RouteManager.login_route}$)} do
|
33
|
+
content_type :json
|
42
34
|
#FIXME REMOVE
|
43
35
|
#puts "ENTRO BEFORE"
|
44
36
|
#pp request.env
|
@@ -46,7 +38,7 @@ module Vagrant
|
|
46
38
|
cookie = ""
|
47
39
|
|
48
40
|
#pp "TOKEN DESCAPADO = #{CGI::unescape(request.env['HTTP_CONTENT_MD5'])}"
|
49
|
-
|
41
|
+
|
50
42
|
|
51
43
|
cookie = request.cookies[COOKIE_TOKEN_ID]
|
52
44
|
token = CGI::unescape(request.env['HTTP_CONTENT_MD5']) if request.env['HTTP_CONTENT_MD5']!=nil
|
@@ -58,284 +50,325 @@ module Vagrant
|
|
58
50
|
# pp "TIENE COOKIE " if (@session_table.has_key?(cookie))
|
59
51
|
# pp "CONTIENE TOKEN " if (challenged?(token))
|
60
52
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
53
|
+
if (!@session_table.has_key?(cookie)||
|
54
|
+
!challenged?(token))
|
55
|
+
|
56
|
+
redirect to(RouteManager.login_route)
|
57
|
+
|
58
|
+
else
|
59
|
+
#raise RestException.new(401,"Not authorized") if !authorized?(cookie,token)
|
60
|
+
|
61
|
+
halt 401, "Not authorized\n" if !authorized?(cookie,token)
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
clear_session_table
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
after %r{^(?!#{RouteManager.login_route}$)} do
|
70
|
+
|
71
|
+
cookie=request.cookies[COOKIE_TOKEN_ID]
|
72
|
+
|
73
|
+
@session_table.delete(cookie) if cookie!=nil
|
74
|
+
|
75
|
+
end
|
80
76
|
|
81
|
-
######### FIXME DELETE #####################
|
82
|
-
get '/' do
|
83
|
-
"Hello World"
|
84
|
-
end
|
85
77
|
|
86
|
-
|
87
|
-
|
78
|
+
get RouteManager.login_route do
|
79
|
+
|
88
80
|
res = ClientController.send_challenge
|
89
|
-
#FIXME REMOVE
|
90
|
-
#puts "LOGIN"
|
91
|
-
|
92
|
-
|
93
|
-
#@session_table[res[:cookie]]={:expiration => Time::now.to_i,:challenge=>res[:challenge]}
|
94
|
-
#pp res[:cookie]
|
95
81
|
@session_table[res[:cookie]]={:expiration => Time::now.to_i+COOKIE_EXPIRATION_TIME,:challenge=>res[:challenge]}
|
96
|
-
#pp @session_table.inspect
|
97
|
-
|
98
82
|
response.set_cookie(COOKIE_TOKEN_ID, res[:cookie])
|
99
83
|
headers "Content_MD5" => res[:challenge]
|
84
|
+
|
100
85
|
status 200
|
101
86
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
end
|
109
|
-
|
110
|
-
delete RouteManager.box_delete_route do
|
111
|
-
#handle_response_result(ClientController.box_delete("params[:box]",params[:provider]))
|
112
|
-
execute(:box_delete,true,params[:box],params[:provider])
|
113
|
-
end
|
114
|
-
|
115
|
-
post RouteManager.box_add_route do
|
116
|
-
execute_async(:box_add,params[:box],params[:url])
|
117
|
-
end
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
get RouteManager.vm_status_all_route do
|
122
|
-
#handle_response_result(ClientController.vm_status(nil))
|
123
|
-
execute(:vm_status)
|
124
|
-
end
|
125
|
-
|
126
|
-
|
87
|
+
#handle_response_result(ClientController.send_challenge)
|
88
|
+
end
|
89
|
+
|
90
|
+
get RouteManager.node_info_route do
|
91
|
+
execute(:nodeinfo)
|
92
|
+
end
|
127
93
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
94
|
+
get RouteManager.box_list_route do
|
95
|
+
execute(:listboxes)
|
96
|
+
end
|
97
|
+
|
98
|
+
get RouteManager.box_download_route do
|
99
|
+
execute(:listdownloadboxes)
|
100
|
+
end
|
101
|
+
|
102
|
+
delete RouteManager.box_download_route do
|
103
|
+
execute(:cleardownloadboxes)
|
104
|
+
end
|
105
|
+
|
106
|
+
delete RouteManager.box_delete_route do
|
107
|
+
execute(:box_delete,true,params[:box],params[:provider])
|
108
|
+
end
|
109
|
+
|
110
|
+
post RouteManager.box_add_route do
|
111
|
+
execute_async(:box_add,params[:box],params[:url])
|
112
|
+
end
|
113
|
+
|
114
|
+
|
115
|
+
|
116
|
+
get RouteManager.vm_status_all_route do
|
117
|
+
#handle_response_result(ClientController.vm_status(nil))
|
118
|
+
execute(:vm_status,true,nil,((params[:verbose]==nil || params[:verbose]=="1" || params[:verbose]=="true")?true:false))
|
119
|
+
|
120
|
+
end
|
121
|
+
|
122
|
+
get RouteManager.vm_info_route do
|
123
|
+
execute(:vm_info,true,params[:vm])
|
124
|
+
end
|
144
125
|
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
126
|
+
|
127
|
+
get RouteManager.vm_status_route do
|
128
|
+
#handle_response_result(ClientController.vm_status(params[:vm]))
|
129
|
+
execute(:vm_status,true,params[:vm],((params[:verbose]==nil || params[:verbose]=="1" || params[:verbose]=="true")?true:false))
|
130
|
+
end
|
131
|
+
|
132
|
+
#accept :vmname as paramter. This parameter
|
133
|
+
#could be empty
|
134
|
+
post RouteManager.vm_up_route do
|
135
|
+
execute_async(:vm_up,params[:vmname])
|
136
|
+
end
|
137
|
+
|
138
|
+
#accept :vmname and :force as paramters
|
139
|
+
post RouteManager.vm_halt_route do
|
140
|
+
#handle_response_result(ClientController.vm_halt(params[:vmname],params[:force])
|
141
|
+
execute_async(:vm_halt,params[:vmname],params[:force])
|
142
|
+
end
|
143
|
+
|
144
|
+
#accept :vmname as paramter. This parameter
|
145
|
+
#could be empty
|
146
|
+
post RouteManager.vm_destroy_route do
|
147
|
+
#handle_response_result(ClientController.vm_confirmed_destroy(params[:vmname]))
|
148
|
+
execute(:vm_confirmed_destroy,true,params[:vmname])
|
149
|
+
end
|
151
150
|
|
152
|
-
|
151
|
+
put RouteManager.vm_add_route do
|
153
152
|
execute(:vm_add,false,params[:file],params[:rename])
|
154
|
-
|
153
|
+
end
|
155
154
|
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
#accept :vmname as paramter. This parameter
|
161
|
-
#could be empty
|
162
|
-
post RouteManager.vm_suspend_route do
|
163
|
-
#handle_response_result(ClientController.vm_suspend(params[:vmname]))
|
164
|
-
execute_async(:vm_suspend,params[:vmname])
|
165
|
-
end
|
166
|
-
|
167
|
-
#accept :vmname as paramter. This parameter
|
168
|
-
#could be empty
|
169
|
-
post RouteManager.vm_resume_route do
|
170
|
-
#handle_response_result(ClientController.vm_resume(params[:vmname]))
|
171
|
-
execute_async(:vm_resume,params[:vmname])
|
172
|
-
end
|
173
|
-
|
174
|
-
post RouteManager.vm_provision_route do
|
175
|
-
#handle_response_result(ClientController.vm_provision(params[:vmname]))
|
176
|
-
execute_async(:vm_provision,params[:vmname])
|
177
|
-
end
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
get RouteManager.vm_sshconfig_route do
|
182
|
-
#handle_response_result(ClientController.vm_ssh_config(params[:vm]))
|
183
|
-
execute(:vm_ssh_config,true,params[:vm])
|
184
|
-
end
|
155
|
+
delete RouteManager.vm_delete_route do
|
156
|
+
execute(:vm_delete,false,params[:vm],params[:remove])
|
157
|
+
end
|
185
158
|
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
159
|
+
#accept :vmname as paramter. This parameter
|
160
|
+
#could be empty
|
161
|
+
post RouteManager.vm_suspend_route do
|
162
|
+
#handle_response_result(ClientController.vm_suspend(params[:vmname]))
|
163
|
+
execute_async(:vm_suspend,params[:vmname])
|
164
|
+
end
|
165
|
+
|
166
|
+
#accept :vmname as paramter. This parameter
|
167
|
+
#could be empty
|
168
|
+
post RouteManager.vm_resume_route do
|
169
|
+
#handle_response_result(ClientController.vm_resume(params[:vmname]))
|
170
|
+
execute_async(:vm_resume,params[:vmname])
|
171
|
+
end
|
172
|
+
|
173
|
+
post RouteManager.vm_provision_route do
|
174
|
+
#handle_response_result(ClientController.vm_provision(params[:vmname]))
|
175
|
+
execute_async(:vm_provision,params[:vmname])
|
176
|
+
end
|
177
|
+
|
178
|
+
|
179
|
+
|
180
|
+
get RouteManager.vm_sshconfig_route do
|
181
|
+
#handle_response_result(ClientController.vm_ssh_config(params[:vm]))
|
182
|
+
execute(:vm_ssh_config,true,params[:vm])
|
183
|
+
end
|
184
|
+
|
185
|
+
get RouteManager.snapshots_all_route do
|
186
|
+
#handle_response_result(ClientController.vm_snapshots(nil))
|
187
|
+
execute(:vm_snapshots,true)
|
188
|
+
end
|
190
189
|
|
191
190
|
|
191
|
+
|
192
|
+
get RouteManager.vm_snapshots_route do
|
193
|
+
#handle_response_result(ClientController.vm_snapshots(params[:vm]))
|
194
|
+
execute(:vm_snapshots,true,params[:vm])
|
195
|
+
end
|
196
|
+
|
197
|
+
get RouteManager.vm_snapshot_take_route do
|
198
|
+
#result=ClientController.vm_snapshot_take_file(params[:vmname])
|
199
|
+
result=execute(:vm_snapshot_take_file,false,params[:vmname])
|
200
|
+
|
192
201
|
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
202
|
+
send_file "#{result[1]}", :filename => result[1],
|
203
|
+
:type => 'Application/octet-stream' if result[0]==200 && params[:download]=="true"
|
204
|
+
|
205
|
+
status result[0]
|
197
206
|
|
198
|
-
|
199
|
-
#result=ClientController.vm_snapshot_take_file(params[:vmname])
|
200
|
-
result=execute(:vm_snapshot_take_file,false,params[:vmname])
|
201
|
-
|
202
|
-
|
203
|
-
send_file "#{result[1]}", :filename => result[1],
|
204
|
-
:type => 'Application/octet-stream' if result[0]==200 && params[:download]=="true"
|
205
|
-
|
206
|
-
status result[0]
|
207
|
-
|
208
|
-
end
|
207
|
+
end
|
209
208
|
|
210
209
|
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
210
|
+
post RouteManager.vm_snapshot_take_route do
|
211
|
+
#handle_response_result(ClientController.vm_snapshot_take(params[:vmname],params[:name],params[:desc]))
|
212
|
+
execute_async(:vm_snapshot_take,params[:vmname],params[:name],params[:desc])
|
213
|
+
end
|
214
|
+
|
215
|
+
|
216
|
+
post RouteManager.vm_snapshot_restore_route do
|
217
|
+
#handle_response_result(ClientController.vm_snapshot_restore(params[:vmname],params[:snapid]))
|
218
|
+
execute_async(:vm_snapshot_restore,params[:vmname],params[:snapid])
|
219
|
+
end
|
221
220
|
|
222
|
-
|
221
|
+
delete RouteManager.vm_snapshot_delete_route do
|
223
222
|
execute(:vm_snapshot_delete,false,params[:vm],params[:snapid])
|
224
|
-
|
225
|
-
|
223
|
+
end
|
226
224
|
|
227
|
-
get RouteManager.vm_backup_log_route do
|
228
|
-
#handle_response_result(ClientController.backup_log(params[:vm]))
|
229
|
-
execute(:backup_log,true,params[:vm])
|
230
|
-
end
|
231
225
|
|
226
|
+
get RouteManager.vm_backup_log_route do
|
227
|
+
#handle_response_result(ClientController.backup_log(params[:vm]))
|
228
|
+
execute(:backup_log,true,params[:vm])
|
229
|
+
end
|
230
|
+
|
232
231
|
|
233
232
|
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
233
|
+
get RouteManager.node_backup_log_route do
|
234
|
+
#handle_response_result(ClientController.backup_log(nil))
|
235
|
+
execute(:backup_log,true)
|
236
|
+
end
|
238
237
|
|
239
238
|
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
239
|
+
get RouteManager.config_show_route do
|
240
|
+
result= execute(:config_show,false)
|
241
|
+
#result=ClientController.config_show
|
244
242
|
send_file(result, :disposition => 'attachment', :filename => result)
|
245
243
|
|
246
|
-
|
247
|
-
|
248
|
-
post RouteManager.node_password_change_route do
|
249
|
-
execute(:password_change,false,params[:password])
|
250
|
-
end
|
251
|
-
|
252
|
-
post RouteManager.config_upload_route do
|
253
|
-
execute(:config_upload,false,params[:file])
|
254
|
-
end
|
255
|
-
|
256
|
-
get RouteManager.node_queue_route do
|
257
|
-
execute(:operation_queued,true,params[:id])
|
258
|
-
end
|
244
|
+
end
|
259
245
|
|
260
|
-
|
261
|
-
|
262
|
-
|
246
|
+
post RouteManager.node_password_change_route do
|
247
|
+
execute(:password_change,false,params[:password])
|
248
|
+
end
|
249
|
+
|
250
|
+
post RouteManager.config_upload_route do
|
251
|
+
execute(:config_upload,false,params[:file])
|
252
|
+
end
|
253
|
+
|
254
|
+
get RouteManager.node_queue_route do
|
255
|
+
execute(:operation_queued,true,params[:id])
|
256
|
+
end
|
257
|
+
|
258
|
+
get RouteManager.node_queue_last_route do
|
259
|
+
execute(:operation_queued_last,true)
|
260
|
+
end
|
263
261
|
|
264
262
|
|
265
263
|
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
264
|
+
private
|
265
|
+
def clear_session_table
|
266
|
+
|
267
|
+
@session_table.delete_if {|key,value| Time::now.to_i >= value[:expiration]}
|
268
|
+
|
269
|
+
end
|
270
|
+
|
271
|
+
#FIXME Factorizar estos dos métodos
|
272
|
+
def execute_async(method,*params)
|
273
|
+
begin
|
274
|
+
|
275
|
+
if params.empty?
|
276
|
+
result=ClientController.send method.to_sym
|
277
|
+
else
|
278
|
+
result=ClientController.send method.to_sym,*params
|
279
|
+
end
|
280
|
+
|
281
|
+
|
282
|
+
#pp result
|
283
|
+
status 202
|
284
|
+
body "Location: #{result}"
|
285
|
+
# body "Location: #{result}".to_json
|
286
|
+
|
287
|
+
rescue => e
|
288
|
+
#FIXME DELETE PUTS
|
289
|
+
#puts "EN EXCEPCION"
|
290
|
+
puts e.class
|
291
|
+
puts e.message
|
292
|
+
|
293
|
+
|
294
|
+
exception = ((e.class==RestException)? e:ExceptionMutator.new(e))
|
295
|
+
|
296
|
+
halt exception.code,exception.message
|
297
|
+
end
|
298
|
+
|
299
|
+
end
|
299
300
|
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
301
|
+
#def execute(method,params = {} ,to_json = true)
|
302
|
+
def execute(method,to_json = true,*params)
|
303
|
+
begin
|
304
|
+
|
305
|
+
#raise Vagrant::Errors::VirtualBoxNotDetected
|
306
|
+
|
307
|
+
if params.empty?
|
308
|
+
result=ClientController.send method.to_sym
|
309
|
+
else
|
310
|
+
result=ClientController.send method.to_sym,*params
|
311
|
+
end
|
309
312
|
#puts "A JSON " if to_json
|
310
313
|
#puts "resultado #{result}"
|
311
314
|
return result.to_json if to_json
|
312
315
|
result
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
316
|
+
|
317
|
+
rescue => e
|
318
|
+
#puts "EN EXCEPCION1"
|
319
|
+
|
320
|
+
|
321
|
+
if (e.class==Vagrant::Errors::VirtualBoxNotDetected)
|
322
|
+
#puts "******* SE HA GENERADO LA EXCEPCION VIRTUALBOXNOTDETECTED ******"
|
323
|
+
|
324
|
+
|
325
|
+
restart_server
|
326
|
+
halt 503,"Node had a problem. Restarting. Try again in a few seconds"
|
327
|
+
return
|
328
|
+
#env[:machine].provider.driver
|
329
|
+
#system("vagrant nodeserver stop;sleep 10;vagrant nodeserver start")
|
330
|
+
end
|
331
|
+
|
332
|
+
puts e.class
|
333
|
+
puts e.message
|
334
|
+
|
335
|
+
exception = ((e.class==RestException)? e:ExceptionMutator.new(e))
|
336
|
+
|
337
|
+
halt exception.code,exception.message
|
338
|
+
end
|
339
|
+
|
340
|
+
end
|
326
341
|
|
342
|
+
|
343
|
+
def restart_server
|
344
|
+
|
345
|
+
#puts Process.pid
|
346
|
+
|
347
|
+
# pid = fork do
|
348
|
+
# #system( "vagrant nodeserver stop;sleep 10;vagrant nodeserver start" );
|
349
|
+
# #system("vagrant nodeserver stop;sleep 10;vagrant nodeserver start")
|
350
|
+
# system("sleep 15");
|
351
|
+
# end
|
352
|
+
# puts "EL PID ES #{pid}"
|
353
|
+
|
354
|
+
# Process.kill('KILL', 0)
|
355
|
+
Process.kill('USR1', 0)
|
356
|
+
end
|
327
357
|
|
328
358
|
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
def challenged?(token)
|
335
|
-
(token!=nil && token.size==32)
|
336
|
-
end
|
337
|
-
|
338
|
-
end
|
339
|
-
end
|
359
|
+
def authorized?(id,token)
|
360
|
+
|
361
|
+
@session_table[id][:challenge]
|
362
|
+
ClientController.authorized?(token,@session_table[id][:challenge]) if @session_table.has_key?(id)
|
340
363
|
end
|
341
|
-
|
364
|
+
|
365
|
+
def challenged?(token)
|
366
|
+
|
367
|
+
(token!=nil && token.size==32)
|
368
|
+
end
|
369
|
+
|
370
|
+
end # API CLASS
|
371
|
+
|
372
|
+
end #module Vagrant
|
373
|
+
end #module Node
|
374
|
+
end #module ServerAPI
|