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
@@ -1,65 +1,74 @@
|
|
1
|
-
require 'sqlite3'
|
1
|
+
#require 'sqlite3'
|
2
2
|
require 'digest/md5'
|
3
|
+
require 'vagrant-node/exceptions.rb'
|
4
|
+
require 'mysql2'
|
5
|
+
require 'yaml'
|
6
|
+
|
3
7
|
module Vagrant
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
8
|
+
module Node
|
9
|
+
module DB
|
10
|
+
class DBManager
|
11
|
+
|
12
|
+
DOWNLOAD_ERROR=-1
|
13
|
+
DOWNLOAD_PROCESS=0
|
14
|
+
DOWNLOAD_SUCCESS=0
|
15
|
+
|
16
|
+
def initialize(data_dir)
|
17
|
+
@db=check_database(data_dir)
|
18
|
+
@data_dir=data_dir
|
19
|
+
end
|
20
|
+
|
21
|
+
def get_backup_log_entries(vmname)
|
22
|
+
sql="SELECT * FROM #{BACKUP_TABLE_NAME}"
|
23
|
+
sql = sql + " WHERE #{BACKUP_VM_NAME_COLUMN} = \"#{vmname}\"" if vmname
|
24
|
+
|
25
|
+
#return rows
|
26
|
+
@db.query(sql)
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
def add_backup_log_entry(date,vmname,status)
|
31
|
+
sql="INSERT INTO #{BACKUP_TABLE_NAME} VALUES ( '#{date}' , '#{vmname}' , '#{status}' )"
|
32
|
+
@db.query(sql)
|
33
|
+
end
|
34
|
+
|
35
|
+
def update_backup_log_entry(date,vmname,status)
|
36
|
+
sql="UPDATE #{BACKUP_TABLE_NAME} SET #{BACKUP_STATUS_COLUMN} = '#{status}' WHERE #{BACKUP_DATE_COLUMN}= '#{date}' AND #{BACKUP_VM_NAME_COLUMN}= '#{vmname}'"
|
37
|
+
@db.query(sql)
|
38
|
+
end
|
39
|
+
|
40
|
+
def node_password_set?
|
41
|
+
sql="SELECT Count(*) FROM #{PASSWORD_TABLE};"
|
42
|
+
|
43
|
+
return @db.query(sql).size!=0
|
44
|
+
|
45
|
+
end
|
38
46
|
|
39
47
|
def node_check_password?(old_password)
|
40
48
|
sql="SELECT #{PASSWORD_COLUMN} FROM #{PASSWORD_TABLE} LIMIT 1;"
|
41
|
-
stored_pwd=@db.
|
49
|
+
stored_pwd=@db.query(sql)
|
50
|
+
|
51
|
+
return (stored_pwd.size!=0 && (stored_pwd.first[PASSWORD_COLUMN]==Digest::MD5.hexdigest(old_password)))
|
42
52
|
|
43
|
-
return (stored_pwd.length!=0 && (stored_pwd.first[0]==Digest::MD5.hexdigest(old_password)))
|
44
|
-
#return true
|
45
53
|
end
|
46
54
|
|
47
55
|
def node_password
|
48
56
|
sql="SELECT #{PASSWORD_COLUMN} FROM #{PASSWORD_TABLE} LIMIT 1;"
|
49
|
-
stored_pwd=@db.
|
50
|
-
|
57
|
+
stored_pwd=@db.query(sql)
|
58
|
+
|
59
|
+
stored_pwd.first[PASSWORD_COLUMN]
|
51
60
|
end
|
52
61
|
|
53
62
|
def node_password_set(new_password,raw=false)
|
63
|
+
password=((raw)? new_password:Digest::MD5.hexdigest(new_password))
|
64
|
+
|
54
65
|
if node_password_set? || !node_default_password_set?
|
55
|
-
sql="UPDATE #{PASSWORD_TABLE} SET #{PASSWORD_COLUMN} =
|
66
|
+
sql="UPDATE #{PASSWORD_TABLE} SET #{PASSWORD_COLUMN} = '#{password}' "
|
56
67
|
else
|
57
|
-
sql="INSERT INTO #{PASSWORD_TABLE} VALUES (
|
68
|
+
sql="INSERT INTO #{PASSWORD_TABLE} VALUES ('#{password}')"
|
58
69
|
end
|
59
70
|
|
60
|
-
@db.
|
61
|
-
((raw)? new_password:
|
62
|
-
Digest::MD5.hexdigest(new_password)))
|
71
|
+
@db.query(sql)
|
63
72
|
|
64
73
|
end
|
65
74
|
|
@@ -69,108 +78,276 @@ module Vagrant
|
|
69
78
|
|
70
79
|
|
71
80
|
def create_queued_process(id)
|
72
|
-
|
73
|
-
|
81
|
+
tactual = Time.now.strftime("%Y-%m-%d")
|
82
|
+
texp = Time.now.to_i
|
83
|
+
sql="INSERT INTO #{OPERATION_QUEUE_TABLE_NAME} VALUES (#{id}, '#{tactual}', '#{texp}', #{PROCESS_IN_PROGRESS}, '')"
|
84
|
+
#@db.execute(sql,id,Time.now.strftime("%Y-%m-%d") ,Time.now.to_i,PROCESS_IN_PROGRESS,"")
|
85
|
+
@db.query(sql)
|
74
86
|
end
|
75
87
|
|
76
88
|
def set_queued_process_result(id,result)
|
77
|
-
sql="UPDATE #{OPERATION_QUEUE_TABLE_NAME} SET #{OPERATION_STATUS_COLUMN} =
|
78
|
-
|
89
|
+
sql="UPDATE #{OPERATION_QUEUE_TABLE_NAME} SET #{OPERATION_STATUS_COLUMN} = #{PROCESS_SUCCESS},#{OPERATION_RESULT_COLUMN} = '#{result}' WHERE #{OPERATION_ID_COLUMN}= #{id}"
|
90
|
+
#@db.execute(sql,PROCESS_SUCCESS,result,id)
|
91
|
+
@db.query(sql)
|
79
92
|
end
|
80
93
|
|
81
94
|
def set_queued_process_error(id,exception)
|
82
|
-
|
83
|
-
|
95
|
+
|
96
|
+
errlog = []
|
97
|
+
|
98
|
+
errcode=PROCESS_ERROR
|
99
|
+
|
100
|
+
# decoded=exception.message.to_s.tr("\n"," ")
|
101
|
+
# puts exception.message.to_s
|
102
|
+
# pp exception.message.to_s
|
103
|
+
# pp decoded
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
if (exception.class==VMActionException)
|
108
|
+
errlog << {"vmname" => exception.vmname,"provider"=>exception.provider,"status" => exception.message.to_s.tr("\'","\"")}
|
109
|
+
elsif (exception.class==RestException)
|
110
|
+
errcode=exception.code
|
111
|
+
errlog << {"status" => exception.message.to_s.tr("\'","\"")}
|
112
|
+
else
|
113
|
+
errlog << {"status" => exception.message.to_s.tr("\'","\"")}
|
114
|
+
end
|
115
|
+
|
116
|
+
|
117
|
+
|
118
|
+
sql="UPDATE #{OPERATION_QUEUE_TABLE_NAME} SET #{OPERATION_STATUS_COLUMN} = #{errcode},#{OPERATION_RESULT_COLUMN} = '#{errlog.to_json}' WHERE #{OPERATION_ID_COLUMN}= #{id}"
|
119
|
+
|
120
|
+
|
121
|
+
#errlog << {"vmname" => "TODO","status" => exception.message.to_s}
|
122
|
+
|
123
|
+
#@db.execute(sql,errcode,errlog.to_json,id)
|
124
|
+
@db.query(sql)
|
84
125
|
end
|
85
126
|
|
86
|
-
def get_queued_process_result(id)
|
87
|
-
|
88
|
-
|
89
|
-
@db.
|
127
|
+
def get_queued_process_result(id)
|
128
|
+
check_operation_timeout
|
129
|
+
sql="SELECT #{OPERATION_STATUS_COLUMN},#{OPERATION_RESULT_COLUMN} FROM #{OPERATION_QUEUE_TABLE_NAME} WHERE #{OPERATION_ID_COLUMN}= #{id};"
|
130
|
+
@db.query(sql)
|
90
131
|
end
|
91
132
|
|
92
133
|
def get_queued_last
|
134
|
+
check_operation_timeout
|
93
135
|
sql="SELECT #{OPERATION_STATUS_COLUMN},#{OPERATION_RESULT_COLUMN} FROM #{OPERATION_QUEUE_TABLE_NAME};"
|
94
|
-
@db.
|
136
|
+
@db.query(sql)
|
95
137
|
end
|
96
138
|
|
97
139
|
|
98
140
|
def remove_queued_processes
|
99
141
|
sql="DELETE FROM #{OPERATION_QUEUE_TABLE_NAME}"
|
100
|
-
@db.
|
142
|
+
@db.query(sql)
|
101
143
|
end
|
102
144
|
|
145
|
+
def add_box_download_info(box_name,box_url)
|
146
|
+
sql="INSERT INTO #{DOWNLOAD_BOX_TABLE}(#{DOWNLOAD_BOX_COLUMN},#{DOWNLOAD_URL_COLUMN},#{DOWNLOAD_PROGRESS_COLUMN},#{DOWNLOAD_REMAINING_COLUMN},#{DOWNLOAD_STATUS_COLUMN}) VALUES ('#{box_name}','#{box_url}','0%','--:--:--',#{DOWNLOAD_PROCESS})"
|
147
|
+
@db.query(sql)
|
148
|
+
last_id=@db.query("SELECT LAST_INSERT_ID() as last")
|
149
|
+
last_id.first["last"]
|
150
|
+
end
|
103
151
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
152
|
+
def get_box_download
|
153
|
+
sql="SELECT * FROM #{DOWNLOAD_BOX_TABLE}"
|
154
|
+
@db.query(sql)
|
155
|
+
end
|
156
|
+
|
157
|
+
def delete_box_download(id)
|
158
|
+
sql="DELETE FROM #{DOWNLOAD_BOX_TABLE} WHERE #{DOWNLOAD_ID_COLUMN}=#{id}"
|
159
|
+
@db.query(sql)
|
160
|
+
end
|
161
|
+
|
162
|
+
def clear_box_downloads
|
163
|
+
sql="DELETE FROM #{DOWNLOAD_BOX_TABLE}"
|
164
|
+
@db.query(sql)
|
165
|
+
end
|
166
|
+
|
167
|
+
def set_box_download_error(id)
|
168
|
+
sql="UPDATE #{DOWNLOAD_BOX_TABLE} SET #{DOWNLOAD_STATUS_COLUMN} = #{DOWNLOAD_ERROR}, #{DOWNLOAD_PROGRESS_COLUMN} = 'ERROR' WHERE #{DOWNLOAD_ID_COLUMN}=#{id}"
|
169
|
+
@db.query(sql)
|
170
|
+
end
|
171
|
+
|
172
|
+
def update_box_download_info(id,progress,remaining)
|
173
|
+
sql="UPDATE #{DOWNLOAD_BOX_TABLE} SET #{DOWNLOAD_PROGRESS_COLUMN}= '#{progress}',#{DOWNLOAD_REMAINING_COLUMN}= '#{remaining}' WHERE #{DOWNLOAD_ID_COLUMN}=#{id}"
|
174
|
+
|
175
|
+
@db.query(sql)
|
176
|
+
end
|
177
|
+
|
178
|
+
def add_box_uncompression(box_name,box_url)
|
179
|
+
sql="INSERT INTO #{DOWNLOAD_BOX_TABLE}(#{DOWNLOAD_BOX_COLUMN},#{DOWNLOAD_URL_COLUMN},#{DOWNLOAD_PROGRESS_COLUMN},#{DOWNLOAD_REMAINING_COLUMN},#{DOWNLOAD_STATUS_COLUMN}) VALUES ('#{box_name}','#{box_url}','Uncompressing','Uncompressing',#{DOWNLOAD_PROCESS})"
|
180
|
+
#@db.execute(sql,box_name,box_url,DOWNLOAD_PROCESS)
|
181
|
+
@db.query(sql)
|
182
|
+
|
183
|
+
last_id=@db.query("SELECT LAST_INSERT_ID() as last")
|
184
|
+
last_id.first["last"]
|
185
|
+
end
|
186
|
+
|
187
|
+
def set_box_uncompression_error(id)
|
188
|
+
sql="UPDATE #{DOWNLOAD_BOX_TABLE} SET #{DOWNLOAD_STATUS_COLUMN} = #{DOWNLOAD_ERROR}, WHERE #{DOWNLOAD_ID_COLUMN}!=#{id}"
|
189
|
+
#@db.execute(sql,DOWNLOAD_ERROR,id)
|
190
|
+
@db.query(sql)
|
191
|
+
end
|
192
|
+
|
193
|
+
def clear_box_uncompression(id)
|
194
|
+
sql="DELETE FROM #{DOWNLOAD_BOX_TABLE} WHERE #{DOWNLOAD_STATUS_COLUMN}!=#{id}"
|
195
|
+
@db.query(sql)
|
196
|
+
end
|
197
|
+
|
198
|
+
def self.create_config_file(dir,dbhost,dbname,dbpuser,dbppassword,dbuser='',dbpassword='')
|
199
|
+
config = Hash.new
|
200
|
+
config[CONFIG_DBHOSTNAME]=dbhost
|
201
|
+
config[CONFIG_DBNAME]=dbname
|
202
|
+
config[CONFIG_DBUSER]=dbpuser
|
203
|
+
config[CONFIG_DBPASSWORD]=dbppassword
|
204
|
+
|
205
|
+
File.open(dir.to_s + "/config.yml", 'w') {|f| f.write config.to_yaml }
|
206
|
+
end
|
207
|
+
|
208
|
+
def self.delete_config_file(data_dir)
|
209
|
+
File.delete(data_dir.to_s + "/config.yml") if DBManager.check_config_file(data_dir)
|
210
|
+
end
|
211
|
+
|
212
|
+
def self.check_config_file(data_dir)
|
213
|
+
File.file?(data_dir.to_s + "/config.yml")
|
214
|
+
end
|
215
|
+
|
216
|
+
|
217
|
+
def close_db_connection
|
218
|
+
@db.close
|
219
|
+
end
|
220
|
+
|
221
|
+
|
222
|
+
private
|
223
|
+
|
224
|
+
def check_operation_timeout
|
225
|
+
sql="SELECT #{OPERATION_ID_COLUMN},#{OPERATION_TIME_COLUMN} from #{OPERATION_QUEUE_TABLE_NAME} WHERE #{OPERATION_STATUS_COLUMN}= #{PROCESS_IN_PROGRESS}"
|
226
|
+
ops=@db.query(sql)
|
227
|
+
rexception=RestException.new(504,"OPERATION CANCELLED BY TIMEOUT")
|
228
|
+
|
229
|
+
tnow=Time.now.to_i
|
230
|
+
ops.each do |entry|
|
231
|
+
#if timeout update db
|
232
|
+
if (tnow > (entry["operation_time"] + OPERATION_TIMEOUT))
|
233
|
+
set_queued_process_error(entry["operation_id"],rexception)
|
234
|
+
end
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
OPERATION_TIMEOUT = 600 #In second (10 minutes)
|
239
|
+
PROCESS_IN_PROGRESS = 100;
|
240
|
+
PROCESS_SUCCESS = 200;
|
241
|
+
PROCESS_ERROR = 500;
|
242
|
+
|
243
|
+
BACKUP_TABLE_NAME='node_table'
|
244
|
+
BACKUP_DATE_COLUMN = 'date'
|
245
|
+
BACKUP_VM_NAME_COLUMN = 'vm_name'
|
246
|
+
BACKUP_STATUS_COLUMN = 'backup_status'
|
247
|
+
PASSWORD_TABLE = 'node_password_table'
|
248
|
+
PASSWORD_COLUMN = 'node_password'
|
249
|
+
DEFAULT_NODE_PASSWORD = 'catedrasaesumu'
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
OPERATION_QUEUE_TABLE_NAME='operation_queue_table'
|
254
|
+
OPERATION_CMD_COLUMN = 'operation_cmd'
|
255
|
+
OPERATION_STATUS_COLUMN = 'operation_status'
|
256
|
+
OPERATION_RESULT_COLUMN = 'operation_result'
|
257
|
+
OPERATION_ID_COLUMN = 'operation_id'
|
258
|
+
OPERATION_DATE_COLUMN = 'operation_date'
|
259
|
+
OPERATION_TIME_COLUMN = 'operation_time'
|
260
|
+
|
261
|
+
DOWNLOAD_BOX_TABLE = 'download_box_table'
|
262
|
+
DOWNLOAD_ID_COLUMN = 'id'
|
263
|
+
DOWNLOAD_BOX_COLUMN = 'box_name'
|
264
|
+
DOWNLOAD_URL_COLUMN = 'box_url'
|
265
|
+
DOWNLOAD_STATUS_COLUMN = 'download_status'
|
266
|
+
DOWNLOAD_PROGRESS_COLUMN = 'download_progress'
|
267
|
+
DOWNLOAD_REMAINING_COLUMN = 'download_remaining'
|
268
|
+
CONFIG_DBUSER = 'dbuser'
|
269
|
+
CONFIG_DBPASSWORD = 'dbpassword'
|
270
|
+
CONFIG_DBHOSTNAME = 'dbhostname'
|
271
|
+
CONFIG_DBNAME = 'dbname'
|
272
|
+
|
273
|
+
|
274
|
+
|
275
|
+
|
276
|
+
def check_database(data_dir)
|
277
|
+
|
278
|
+
begin
|
279
|
+
|
280
|
+
raise "The config file \""+data_dir.to_s + "/config.yml"+"\" doesn't exist" if !File.file?(data_dir.to_s + "/config.yml")
|
109
281
|
|
110
|
-
|
111
|
-
BACKUP_DATE_COLUMN = 'date'
|
112
|
-
BACKUP_VM_NAME_COLUMN = 'vm_name'
|
113
|
-
BACKUP_STATUS_COLUMN = 'backup_status'
|
114
|
-
PASSWORD_TABLE = 'node_password_table'
|
115
|
-
PASSWORD_COLUMN = 'node_password'
|
116
|
-
DEFAULT_NODE_PASSWORD = 'catedrasaesumu'
|
282
|
+
config = YAML.load_file(data_dir.to_s + "/config.yml")
|
117
283
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
OPERATION_ID_COLUMN = 'operation_id'
|
123
|
-
OPERATION_DATE_COLUMN = 'operation_date'
|
124
|
-
OPERATION_TIME_COLUMN = 'operation_time'
|
125
|
-
|
126
|
-
def check_database(data_dir)
|
127
|
-
#Creates and/or open the database
|
128
|
-
|
129
|
-
db = SQLite3::Database.new( data_dir.to_s + "/node.db" )
|
130
|
-
#Trying to avoid the sqlite3::busyexception
|
131
|
-
db.busy_timeout=100;
|
284
|
+
raise 'Invalid configuration file' if (!config.has_key?(CONFIG_DBUSER) ||
|
285
|
+
!config.has_key?(CONFIG_DBPASSWORD) ||
|
286
|
+
!config.has_key?(CONFIG_DBHOSTNAME)
|
287
|
+
!config.has_key?(CONFIG_DBNAME))
|
132
288
|
|
133
|
-
if db.execute("SELECT name FROM sqlite_master
|
134
|
-
WHERE type='table' AND name='#{BACKUP_TABLE_NAME}';").length==0
|
135
|
-
db.execute( "create table '#{BACKUP_TABLE_NAME}' (#{BACKUP_DATE_COLUMN} TEXT NOT NULL,
|
136
|
-
#{BACKUP_VM_NAME_COLUMN} TEXT PRIMARY_KEY,
|
137
|
-
#{BACKUP_STATUS_COLUMN} TEXT NOT NULL);" )
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
end
|
143
|
-
|
144
|
-
|
145
|
-
if db.execute("SELECT name FROM sqlite_master
|
146
|
-
WHERE type='table' AND name='#{PASSWORD_TABLE}';").length==0
|
147
|
-
db.execute("create table '#{PASSWORD_TABLE}' (#{PASSWORD_COLUMN} TEXT NOT NULL);" )
|
148
|
-
db.execute("INSERT INTO #{PASSWORD_TABLE} VALUES (\"#{DEFAULT_NODE_PASSWORD}\");");
|
149
|
-
end
|
150
|
-
|
151
|
-
if db.execute("SELECT name FROM sqlite_master
|
152
|
-
WHERE type='table' AND name='#{OPERATION_QUEUE_TABLE_NAME}';").length==0
|
153
|
-
|
154
|
-
# db.execute( "create table '#{OPERATION_QUEUE_TABLE_NAME}' (#{OPERATION_ID_COLUMN} INTEGER PRIMARY_KEY,
|
155
|
-
# #{OPERATION_CMD_COLUMN} TEXT NOT NULL,
|
156
|
-
# #{OPERATION_DATE_COLUMN} TEXT NOT NULL,
|
157
|
-
# #{OPERATION_TIME_COLUMN} INTEGER NOT NULL,
|
158
|
-
# #{OPERATION_STATUS_COLUMN} TEXT NOT NULL,
|
159
|
-
# #{OPERATION_RESULT_COLUMN} TEXT NOT NULL);" )
|
160
|
-
db.execute( "create table '#{OPERATION_QUEUE_TABLE_NAME}' (#{OPERATION_ID_COLUMN} INTEGER PRIMARY_KEY,
|
161
|
-
#{OPERATION_DATE_COLUMN} TEXT NOT NULL,
|
162
|
-
#{OPERATION_TIME_COLUMN} INTEGER NOT NULL,
|
163
|
-
#{OPERATION_STATUS_COLUMN} INTEGER NOT NULL,
|
164
|
-
#{OPERATION_RESULT_COLUMN} TEXT NOT NULL);" )
|
165
|
-
|
166
|
-
end
|
167
|
-
|
168
|
-
|
169
|
-
db
|
170
|
-
|
171
|
-
end
|
172
|
-
|
173
289
|
end
|
290
|
+
|
291
|
+
|
292
|
+
db =Mysql2::Client.new(:host => config[CONFIG_DBHOSTNAME],
|
293
|
+
:username => config[CONFIG_DBUSER],
|
294
|
+
:password => config[CONFIG_DBPASSWORD],
|
295
|
+
:flags => Mysql2::Client::MULTI_STATEMENTS)
|
296
|
+
|
297
|
+
#Checking if database exists
|
298
|
+
results = db.query("SHOW DATABASES LIKE '"+config[CONFIG_DBNAME]+"'")
|
299
|
+
|
300
|
+
if (results.size==0)
|
301
|
+
results = db.query("CREATE DATABASE "+config[CONFIG_DBNAME])
|
302
|
+
end
|
303
|
+
|
304
|
+
db.query("use "+config[CONFIG_DBNAME])
|
305
|
+
|
306
|
+
db.query("CREATE TABLE IF NOT EXISTS `#{BACKUP_TABLE_NAME}` (
|
307
|
+
`#{BACKUP_DATE_COLUMN}` text NOT NULL,
|
308
|
+
`#{BACKUP_VM_NAME_COLUMN}` varchar(255) NOT NULL,
|
309
|
+
`#{BACKUP_STATUS_COLUMN}` text NOT NULL,
|
310
|
+
PRIMARY KEY (`#{BACKUP_VM_NAME_COLUMN}`)
|
311
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;")
|
312
|
+
|
313
|
+
|
314
|
+
db.query("CREATE TABLE IF NOT EXISTS `#{DOWNLOAD_BOX_TABLE}` (
|
315
|
+
`#{DOWNLOAD_ID_COLUMN}` int(11) NOT NULL AUTO_INCREMENT,
|
316
|
+
`#{DOWNLOAD_BOX_COLUMN}` varchar(128) NOT NULL,
|
317
|
+
`#{DOWNLOAD_URL_COLUMN}` text NOT NULL,
|
318
|
+
`#{DOWNLOAD_PROGRESS_COLUMN}` VARCHAR(10),
|
319
|
+
`#{DOWNLOAD_STATUS_COLUMN}` int(11) NOT NULL,
|
320
|
+
`#{DOWNLOAD_REMAINING_COLUMN}` VARCHAR(10),
|
321
|
+
PRIMARY KEY (`#{DOWNLOAD_ID_COLUMN}`)
|
322
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;")
|
323
|
+
|
324
|
+
|
325
|
+
db.query("CREATE TABLE IF NOT EXISTS `#{PASSWORD_TABLE}` (
|
326
|
+
`#{PASSWORD_COLUMN}` varchar(128) NOT NULL,
|
327
|
+
PRIMARY KEY (`#{PASSWORD_COLUMN}`)
|
328
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;")
|
329
|
+
|
330
|
+
results=db.query("SELECT * from #{PASSWORD_TABLE}")
|
331
|
+
|
332
|
+
if (results.size==0)
|
333
|
+
db.query("INSERT INTO #{PASSWORD_TABLE} VALUES (\"#{DEFAULT_NODE_PASSWORD}\");");
|
334
|
+
end
|
335
|
+
|
336
|
+
db.query("CREATE TABLE IF NOT EXISTS `#{OPERATION_QUEUE_TABLE_NAME}` (
|
337
|
+
`#{OPERATION_ID_COLUMN}` int(11) NOT NULL AUTO_INCREMENT,
|
338
|
+
`#{OPERATION_DATE_COLUMN}` text NOT NULL,
|
339
|
+
`#{OPERATION_TIME_COLUMN}` int(11) NOT NULL,
|
340
|
+
`#{OPERATION_STATUS_COLUMN}` int(11) NOT NULL,
|
341
|
+
`#{OPERATION_RESULT_COLUMN}` text NOT NULL,
|
342
|
+
PRIMARY KEY (`#{OPERATION_ID_COLUMN}`)
|
343
|
+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;")
|
344
|
+
|
345
|
+
|
346
|
+
db
|
347
|
+
|
174
348
|
end
|
349
|
+
|
175
350
|
end
|
176
351
|
end
|
352
|
+
end
|
353
|
+
end
|