vagrant-nodemaster 0.0.2 → 1.0.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.
- data/README.md +95 -0
- data/lib/vagrant-nodemaster.rb +4 -2
- data/lib/vagrant-nodemaster/apidesc.rb +105 -1
- data/lib/vagrant-nodemaster/node/nodeadd.rb +4 -4
- data/lib/vagrant-nodemaster/node/nodedbmanager.rb +49 -33
- data/lib/vagrant-nodemaster/node/nodelist.rb +2 -2
- data/lib/vagrant-nodemaster/node/nodeoperationcommand.rb +85 -0
- data/lib/vagrant-nodemaster/node/nodeoperationlast.rb +47 -0
- data/lib/vagrant-nodemaster/node/nodeoperationshow.rb +39 -0
- data/lib/vagrant-nodemaster/node/noderemove.rb +3 -3
- data/lib/vagrant-nodemaster/node/nodestatus.rb +2 -2
- data/lib/vagrant-nodemaster/node/nodeupdate.rb +2 -2
- data/lib/vagrant-nodemaster/node/nodeupdatepw.rb +72 -0
- data/lib/vagrant-nodemaster/nodecommand.rb +14 -0
- data/lib/vagrant-nodemaster/remote/configmanager.rb +16 -0
- data/lib/vagrant-nodemaster/remote/remoteboxadd.rb +11 -8
- data/lib/vagrant-nodemaster/remote/remoteconfigaddvm.rb +46 -0
- data/lib/vagrant-nodemaster/remote/remoteconfigcommand.rb +110 -0
- data/lib/vagrant-nodemaster/remote/remoteconfigdeletevm.rb +37 -0
- data/lib/vagrant-nodemaster/remote/remoteconfigshow.rb +31 -0
- data/lib/vagrant-nodemaster/remote/remoteconfigupload.rb +34 -0
- data/lib/vagrant-nodemaster/remote/remotehalt.rb +14 -5
- data/lib/vagrant-nodemaster/remote/remoteprovision.rb +31 -23
- data/lib/vagrant-nodemaster/remote/remoteresume.rb +16 -9
- data/lib/vagrant-nodemaster/remote/remotesnapshotcommand.rb +8 -3
- data/lib/vagrant-nodemaster/remote/remotesnapshotdelete.rb +31 -0
- data/lib/vagrant-nodemaster/remote/remotesnapshotlist.rb +1 -0
- data/lib/vagrant-nodemaster/remote/remotesnapshotrestore.rb +17 -9
- data/lib/vagrant-nodemaster/remote/remotesnapshottake.rb +16 -6
- data/lib/vagrant-nodemaster/remote/remotesuspend.rb +15 -7
- data/lib/vagrant-nodemaster/remote/remoteup.rb +18 -22
- data/lib/vagrant-nodemaster/remote/remotevmstatus.rb +1 -1
- data/lib/vagrant-nodemaster/remotecommand.rb +18 -5
- data/lib/vagrant-nodemaster/requestcontroller.rb +321 -69
- data/lib/vagrant-nodemaster/version.rb +1 -1
- data/vagrant-nodemaster.gemspec +7 -2
- metadata +18 -7
- data/Readme.md +0 -0
data/README.md
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
vagrant-nodemaster
|
2
|
+
==================
|
3
|
+
This plugin allows you to control centralizely remote virtual environments configured with the plugin [Vagrant-Node](https://github.com/fjsanpedro/vagrant-nodemaster/tree/master/lib/vagrant-node).
|
4
|
+
|
5
|
+
|
6
|
+
This plugin has been developed in the context of the [Catedra SAES](http://www.catedrasaes.org) of the University of Murcia(Spain).
|
7
|
+
|
8
|
+
##Installation
|
9
|
+
Requires Vagrant 1.2 and libsqlite3-dev
|
10
|
+
|
11
|
+
```bash
|
12
|
+
$ vagrant plugin install vagrant-nodemaster
|
13
|
+
```
|
14
|
+
|
15
|
+
##Usage
|
16
|
+
This plugin provides two main commands: `vagrant remote` and `vagrant node`.
|
17
|
+
|
18
|
+
The command `Vagrant node` allows you to manage a set of computers as *nodes*. This set is composed by the an id of the node, the ip address/dns name and the port where it is listening.
|
19
|
+
|
20
|
+
This command is composed by the following subcommands:
|
21
|
+
|
22
|
+
* `vagrant node add <node-name> <node-address> <node-port> --hostname`:
|
23
|
+
Adds a node identified by node-name, with the ip node-address (or dns name if `--hostname` parameter is present) and the node-port where the node is listening.
|
24
|
+
|
25
|
+
* `vagrant node remove [node-name] --clean`: Removes a node identified by its *node-name* from the set of nodes. Also you can use the parameter --clean to remove all nodes from the list.
|
26
|
+
|
27
|
+
* `vagrant node update <node-name> <node-address> <node-port> --hostname`: Updates the information of the node identified by its *node-name*.
|
28
|
+
|
29
|
+
* `vagrant node updatepw <node-name> --remote`: Updates the password stored locally to login into the node. Furthermore you can update the password in the node using the `--remote`option.
|
30
|
+
|
31
|
+
* `vagrant node status`: Shows the list of nodes and its status, e.g. if they are listening.
|
32
|
+
|
33
|
+
* `vagrant node list`: Shows the list of nodes and its configurations
|
34
|
+
|
35
|
+
* `vagrant node operation last <node-name>`: Shows the last operations performed in the nodes and its result.
|
36
|
+
|
37
|
+
* `vagrant node operation show <node-name> <operation-id>`: Shows the result of the operation with the identifier operation-id.
|
38
|
+
|
39
|
+
|
40
|
+
The command `Vagrant remote` enables you to execute in remote nodes those commands that you can use locally. Also, some new ones have been added. Commands are performed, by default, asynchronous.
|
41
|
+
|
42
|
+
* `vagrant remote box`
|
43
|
+
* `vagrant remote box add <node-name> <box-name> <url> [--synchronous]`: Executes `vagrant box add <box-name> <url>` in node identified by *node-name*.
|
44
|
+
|
45
|
+
* `vagrant remote box list <node-name>`: Executes `vagrant box list` in node identified by *node-name*.
|
46
|
+
|
47
|
+
* `vagrant remote box remove <node-name> <box-name> <box-provider>`: Executes `vagrant box remove <box-name> <box-provider>` in node identified by *node-name*.
|
48
|
+
|
49
|
+
* `vagrant remote destroy <node-name> [vm_name] [--force]`: Executes `vagrant destroy [vm_name] [--force]` in node identified by *node-name*.
|
50
|
+
|
51
|
+
* `vagrant remote halt <node-name> [vm_name] [--force] [--synchronous]`: Executes `vagrant halt [vm_name] [--force]` in node identified by *node-name*.
|
52
|
+
|
53
|
+
* `vagrant remote provision <node-name> [vm_name] [--synchronous]`: Executes `vagrant provision [vm_name]` in node identified by *node-name* .
|
54
|
+
|
55
|
+
* `vagrant remote resume <node-name> [vm_name] [--synchronous]`: Executes `vagrant resume [vm_name]` in node identified by *node-name* .
|
56
|
+
|
57
|
+
* `vagrant remote status <node-name> [vm_name]`: Executes `vagrant status [vm_name]` in node identified by *node-name*.
|
58
|
+
|
59
|
+
* `vagrant remote up <node-name> [vm_name] [--synchronous]`: Executes `vagrant up [vm_name]` in node identified by *node-name*.
|
60
|
+
|
61
|
+
* `vagrant remote suspend <node-name> [vm_name] [--synchronous]`: Executes `vagrant suspend [vm_name]` in node identified by *node-name*.
|
62
|
+
|
63
|
+
* `vagrant remote ssh <node-name> <vm_name>`: Executes `vagrant ssh <vm_name>` in node identified by *node-name*. This command enables you to connect by ssh to every vm in remote nodes.
|
64
|
+
|
65
|
+
|
66
|
+
* `vagrant remote snapshot` (New command)
|
67
|
+
|
68
|
+
* `vagrant remote snapshot take <node-name> <vmname> <name> [description] [--synchronous]`: Takes a snapshot of the current state of the virtual machine *vmname* in remote node *node-name*. This snapshot is identified by *name* and optionally can have a *description*.
|
69
|
+
|
70
|
+
* `vagrant remote snapshot restore <node-name> <vmname> <snapshot-uuid|snapshot-name]> [--synchronous]`: Restores the snapshot identified by its *snapshot-uuid* or by its *snapshot-name* of the virtual machine *vmname* in remote node *node-name*.
|
71
|
+
|
72
|
+
* `vagrant remote snapshot list <node-name> [vmname]`: Shows the list of snapshots of the virtual machine *vmname* in remote *node-name*. This list also shows the current snapshot that is in use.
|
73
|
+
|
74
|
+
|
75
|
+
* `vagrant remote backup` (New command)
|
76
|
+
|
77
|
+
* `vagrant remote backup take [node-name] [vmname] [--download target_directory][--background]`: This command allows you to make a backup of the virtual machine *vmname* in remote node *node-name*. This backup includes all the virtual machine images, and it is stored in a fixed place of the remote node. Also you can use the parameter `--download` to download the backup at the same time that is is taking. With parameter `--background`, this operation is donde in background.
|
78
|
+
|
79
|
+
* `vagrant remote backup log <node-name> [vmname]`: Shows the log of backup operations done in virtual machine *vmname* in remote node *node-name*.
|
80
|
+
|
81
|
+
|
82
|
+
* `vagrant remote config` (New command)
|
83
|
+
|
84
|
+
* `vagrant remote config addvm <node-name> <vm_config_file> [--rename]`: Adds the machines configured in `vm_config_file`to the remote node. To avoid name collision you can use the `--rename` option to rename them automatically.
|
85
|
+
|
86
|
+
* `vagrant remote config deletevm <node-name> <vm_name> [--remove]`: Deletes the machine with name `vm_name`from the remote node config file. Also, if the parameter `--remove` is used, all the virtual machine information and data will be removed.
|
87
|
+
|
88
|
+
* `vagrant remote config show <node-name>`: Downloads the remote node config file.
|
89
|
+
|
90
|
+
* `vagrant remote config upload <node-name> <config_file>`: Uploads a config file to the remote node overwritting the current one.
|
91
|
+
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
|
data/lib/vagrant-nodemaster.rb
CHANGED
@@ -1,15 +1,17 @@
|
|
1
1
|
require "vagrant-nodemaster/version"
|
2
|
-
|
2
|
+
require 'vagrant-nodemaster/node/nodedbmanager'
|
3
3
|
module Vagrant
|
4
4
|
module NodeMaster
|
5
5
|
class Plugin < Vagrant.plugin("2")
|
6
6
|
|
7
|
+
|
7
8
|
name "remote"
|
8
9
|
description <<-DESC
|
9
10
|
Este es mi primer plugin y estoy probando la estructura
|
10
11
|
DESC
|
11
12
|
|
12
|
-
|
13
|
+
|
14
|
+
|
13
15
|
command ('remote') do
|
14
16
|
require_relative "vagrant-nodemaster/remotecommand"
|
15
17
|
Command
|
@@ -36,6 +36,10 @@ module RestRoutes
|
|
36
36
|
VM_DESTROY_ROUTE
|
37
37
|
end
|
38
38
|
|
39
|
+
def self.vm_add_route
|
40
|
+
VM_ADD_ROUTE
|
41
|
+
end
|
42
|
+
|
39
43
|
def self.vm_status_route
|
40
44
|
VM_STATUS_ROUTE
|
41
45
|
end
|
@@ -64,6 +68,14 @@ module RestRoutes
|
|
64
68
|
VM_SNAPSHOT_TAKE_ROUTE
|
65
69
|
end
|
66
70
|
|
71
|
+
def self.vm_snapshot_delete_route
|
72
|
+
VM_SNAPSHOT_DELETE_ROUTE
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.vm_delete_route
|
76
|
+
VM_DELETE_ROUTE
|
77
|
+
end
|
78
|
+
|
67
79
|
def self.vm_snapshot_restore_route
|
68
80
|
VM_SNAPSHOT_RESTORE_ROUTE
|
69
81
|
end
|
@@ -72,11 +84,42 @@ module RestRoutes
|
|
72
84
|
NODE_BACKUP_LOG_ROUTE
|
73
85
|
end
|
74
86
|
|
87
|
+
def self.node_password_change_route
|
88
|
+
NODE_PASSWORD_CHANGE
|
89
|
+
end
|
90
|
+
|
91
|
+
|
92
|
+
|
75
93
|
def self.vm_backup_log_route
|
76
94
|
VM_BACKUP_LOG_ROUTE
|
77
95
|
end
|
78
96
|
|
79
97
|
|
98
|
+
def self.config_show_route
|
99
|
+
NODE_CONFIG_SHOW_ROUTE
|
100
|
+
end
|
101
|
+
|
102
|
+
def self.config_upload_route
|
103
|
+
NODE_CONFIG_UPLOAD_ROUTE
|
104
|
+
end
|
105
|
+
|
106
|
+
|
107
|
+
def self.login_route
|
108
|
+
LOGIN_ROUTE
|
109
|
+
end
|
110
|
+
|
111
|
+
def self.node_queue_route
|
112
|
+
NODE_QUEUE_ROUTE
|
113
|
+
end
|
114
|
+
|
115
|
+
def self.node_queue_last_route
|
116
|
+
NODE_QUEUE_LAST_ROUTE
|
117
|
+
end
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
|
122
|
+
|
80
123
|
def self.box_list_url(host,port)
|
81
124
|
"http://#{host}:#{port}#{box_list_route}"
|
82
125
|
end
|
@@ -95,8 +138,20 @@ module RestRoutes
|
|
95
138
|
url
|
96
139
|
|
97
140
|
end
|
98
|
-
|
99
141
|
|
142
|
+
def self.node_queue_url(host,port,id)
|
143
|
+
url=String.new(node_queue_route)
|
144
|
+
url[":id"] = id
|
145
|
+
url="http://#{host}:#{port}#{url}"
|
146
|
+
end
|
147
|
+
|
148
|
+
def self.node_queue_last_url(host,port)
|
149
|
+
"http://#{host}:#{port}#{node_queue_last_route}"
|
150
|
+
end
|
151
|
+
|
152
|
+
def self.login_url(host,port)
|
153
|
+
"http://#{host}:#{port}#{login_route}"
|
154
|
+
end
|
100
155
|
|
101
156
|
def self.vm_up_url(host,port)
|
102
157
|
"http://#{host}:#{port}#{vm_up_route}"
|
@@ -110,6 +165,10 @@ module RestRoutes
|
|
110
165
|
"http://#{host}:#{port}#{vm_destroy_route}"
|
111
166
|
end
|
112
167
|
|
168
|
+
def self.vm_add_url(host,port)
|
169
|
+
"http://#{host}:#{port}#{vm_add_route}"
|
170
|
+
end
|
171
|
+
|
113
172
|
def self.vm_suspend_url(host,port)
|
114
173
|
"http://#{host}:#{port}#{vm_suspend_route}"
|
115
174
|
end
|
@@ -168,6 +227,16 @@ module RestRoutes
|
|
168
227
|
|
169
228
|
end
|
170
229
|
|
230
|
+
def self.vm_snapshot_delete_url(host,port,vmname,snapid)
|
231
|
+
url=String.new(vm_snapshot_delete_route)
|
232
|
+
url[":vm"]=vmname
|
233
|
+
url[":snapid"]=snapid
|
234
|
+
url="http://#{host}:#{port}#{url}"
|
235
|
+
|
236
|
+
url
|
237
|
+
|
238
|
+
end
|
239
|
+
|
171
240
|
def self.vm_snapshot_restore_url(host,port,vmname)
|
172
241
|
url=String.new(vm_snapshot_restore_route)
|
173
242
|
url[":vm"]=vmname
|
@@ -177,6 +246,17 @@ module RestRoutes
|
|
177
246
|
|
178
247
|
end
|
179
248
|
|
249
|
+
def self.vm_delete_url(host,port,vmname)
|
250
|
+
url=String.new(vm_delete_route)
|
251
|
+
url[":vm"]=vmname
|
252
|
+
url="http://#{host}:#{port}#{url}"
|
253
|
+
|
254
|
+
url
|
255
|
+
end
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
|
180
260
|
def self.backup_log_url(host,port,vmname=nil)
|
181
261
|
url="http://#{host}:#{port}#{node_backup_log_route}"
|
182
262
|
|
@@ -190,6 +270,17 @@ module RestRoutes
|
|
190
270
|
|
191
271
|
end
|
192
272
|
|
273
|
+
def self.config_show_url(host,port)
|
274
|
+
"http://#{host}:#{port}#{config_show_route}"
|
275
|
+
end
|
276
|
+
|
277
|
+
def self.node_password_change_url(host,port)
|
278
|
+
"http://#{host}:#{port}#{node_password_change_route}"
|
279
|
+
end
|
280
|
+
|
281
|
+
def self.config_upload_url(host,port)
|
282
|
+
"http://#{host}:#{port}#{config_upload_route}"
|
283
|
+
end
|
193
284
|
|
194
285
|
|
195
286
|
private
|
@@ -200,6 +291,8 @@ module RestRoutes
|
|
200
291
|
VM_UP_ROUTE = "/api/vm/up"
|
201
292
|
VM_HALT_ROUTE = "/api/vm/halt"
|
202
293
|
VM_DESTROY_ROUTE = "/api/vm/destroy"
|
294
|
+
VM_DELETE_ROUTE = "/api/vm/:vm/delete"
|
295
|
+
VM_ADD_ROUTE = "/api/vm/add"
|
203
296
|
VM_SUSPEND_ROUTE = "/api/vm/suspend"
|
204
297
|
VM_RESUME_ROUTE = "/api/vm/resume"
|
205
298
|
VM_PROVISION_ROUTE = "/api/vm/provision"
|
@@ -210,11 +303,22 @@ module RestRoutes
|
|
210
303
|
SNAPSHOTS_ALL_ROUTE = "/api/vm/snapshots"
|
211
304
|
VM_SNAPSHOTS_ROUTE = "/api/vm/:vm/snapshots"
|
212
305
|
VM_SNAPSHOT_TAKE_ROUTE = "/api/vm/:vm/take"
|
306
|
+
VM_SNAPSHOT_DELETE_ROUTE = "/api/vm/:vm/:snapid/delete"
|
213
307
|
VM_SNAPSHOT_RESTORE_ROUTE = "/api/vm/:vm/restore"
|
214
308
|
|
215
309
|
VM_BACKUP_LOG_ROUTE = "/api/vm/:vm/backuplog"
|
216
310
|
NODE_BACKUP_LOG_ROUTE = "/api/backuplog"
|
217
311
|
|
312
|
+
NODE_CONFIG_SHOW_ROUTE = "/api/config/show"
|
313
|
+
NODE_CONFIG_UPLOAD_ROUTE = "/api/config/upload"
|
314
|
+
|
315
|
+
NODE_PASSWORD_CHANGE = "/api/password/change"
|
316
|
+
|
317
|
+
NODE_QUEUE_ROUTE = "/api/queue/:id"
|
318
|
+
NODE_QUEUE_LAST_ROUTE = "/api/queuelast"
|
319
|
+
|
320
|
+
LOGIN_ROUTE = "/api/login"
|
321
|
+
|
218
322
|
end
|
219
323
|
|
220
324
|
end
|
@@ -10,7 +10,7 @@ module Vagrant
|
|
10
10
|
options = {}
|
11
11
|
|
12
12
|
opts = OptionParser.new do |opts|
|
13
|
-
opts.banner = "Usage: vagrant node add <node-name> <node-address> <node-port> --hostname"
|
13
|
+
opts.banner = "Usage: vagrant node add <node-name> <node-address> <node-port> <node-password> --hostname"
|
14
14
|
opts.on("--hostname", "Address in dns format") do |d|
|
15
15
|
options[:dns] = d
|
16
16
|
end
|
@@ -18,11 +18,11 @@ module Vagrant
|
|
18
18
|
|
19
19
|
argv = parse_options(opts)
|
20
20
|
return if !argv
|
21
|
-
raise Vagrant::Errors::CLIInvalidUsage, :help => opts.help.chomp if argv.length !=
|
21
|
+
raise Vagrant::Errors::CLIInvalidUsage, :help => opts.help.chomp if argv.length != 4
|
22
22
|
|
23
|
-
dbmanager=DB::NodeDBManager.new
|
23
|
+
#dbmanager=DB::NodeDBManager.new
|
24
24
|
|
25
|
-
|
25
|
+
DB::NodeDBManager.add_node(argv[0],argv[1],argv[2].to_i,argv[3],options[:dns])
|
26
26
|
|
27
27
|
0
|
28
28
|
end
|
@@ -5,11 +5,17 @@ module Vagrant
|
|
5
5
|
module DB
|
6
6
|
class NodeDBManager
|
7
7
|
|
8
|
-
def initialize
|
9
|
-
|
8
|
+
def initialize(data_dir=nil)
|
9
|
+
|
10
|
+
@@db=check_database(data_dir) if data_dir
|
11
|
+
|
10
12
|
end
|
11
13
|
|
12
|
-
def
|
14
|
+
def self.get_reference
|
15
|
+
@@db
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.add_node(node_name,node_address,node_port,node_password,dnsformat)
|
13
19
|
|
14
20
|
if (!portvalid?(node_port))
|
15
21
|
raise "Node port must be above 1023"
|
@@ -28,12 +34,12 @@ module Vagrant
|
|
28
34
|
end
|
29
35
|
|
30
36
|
|
31
|
-
sql="INSERT INTO #{TABLE_NAME} VALUES ( ? , ? ,
|
32
|
-
|
37
|
+
sql="INSERT INTO #{TABLE_NAME} VALUES ( ? , ? , ?,?)"
|
38
|
+
@@db.execute(sql,node_name,node_address,node_port,Digest::MD5.hexdigest(node_password))
|
33
39
|
|
34
40
|
end
|
35
41
|
|
36
|
-
def update_node(node_name,node_address,node_port,dnsformat)
|
42
|
+
def self.update_node(node_name,node_address,node_port,dnsformat)
|
37
43
|
|
38
44
|
if (!portvalid?(node_port))
|
39
45
|
|
@@ -49,52 +55,60 @@ module Vagrant
|
|
49
55
|
end
|
50
56
|
|
51
57
|
sql="UPDATE #{TABLE_NAME} SET #{NODE_ADDRESS_COLUMN} = ?,#{NODE_PORT_COLUMN} = ? WHERE #{NODE_NAME_COLUMN}= ?"
|
52
|
-
|
58
|
+
@@db.execute(sql,node_address,node_port,node_name)
|
53
59
|
|
54
60
|
end
|
55
61
|
|
56
62
|
|
63
|
+
def self.update_node_password(node_name,password)
|
64
|
+
sql="UPDATE #{TABLE_NAME} SET #{NODE_PASSWORD_COLUMN} = ? WHERE #{NODE_NAME_COLUMN}= ?"
|
65
|
+
@@db.execute(sql,Digest::MD5.hexdigest(password),node_name)
|
66
|
+
end
|
57
67
|
|
58
68
|
|
59
|
-
def remove_node(node_name)
|
69
|
+
def self.remove_node(node_name)
|
60
70
|
sql="DELETE FROM #{TABLE_NAME} WHERE #{NODE_NAME_COLUMN}=?"
|
61
|
-
|
71
|
+
@@db.execute(sql,node_name)
|
62
72
|
end
|
63
73
|
|
64
|
-
def remove_nodes
|
74
|
+
def self.remove_nodes
|
65
75
|
sql="DELETE FROM #{TABLE_NAME}"
|
66
|
-
|
76
|
+
@@db.execute(sql)
|
67
77
|
end
|
68
78
|
|
69
79
|
|
70
|
-
def get_node_names
|
80
|
+
def self.get_node_names
|
71
81
|
sql="SELECT #{NODE_NAME_COLUMN} FROM #{TABLE_NAME}"
|
72
|
-
|
82
|
+
@@db.execute(sql);
|
73
83
|
end
|
74
84
|
|
75
|
-
def get_nodes
|
85
|
+
def self.get_nodes
|
76
86
|
sql="SELECT * FROM #{TABLE_NAME}"
|
77
|
-
rows
|
87
|
+
rows=@@db.execute(sql);
|
78
88
|
nodes = []
|
79
89
|
rows.each do |row|
|
80
90
|
node = {}
|
81
91
|
node[:name]=row[0]
|
82
92
|
node[:address]=row[1]
|
83
93
|
node[:port]=row[2]
|
94
|
+
node[:password]=row[3]
|
84
95
|
nodes << node
|
85
96
|
end
|
86
97
|
|
87
|
-
|
98
|
+
nodes
|
99
|
+
|
88
100
|
end
|
89
101
|
|
90
|
-
def get_node(node_name)
|
102
|
+
def self.get_node(node_name)
|
91
103
|
sql="SELECT * FROM #{TABLE_NAME} WHERE #{NODE_NAME_COLUMN}=?"
|
92
|
-
raise "Node not found" if (nodear
|
104
|
+
raise "Node not found" if (nodear=@@db.execute(sql,node_name)).empty?
|
93
105
|
node = {}
|
94
106
|
node[:name]=nodear[0][0]
|
95
107
|
node[:address]=nodear[0][1]
|
96
108
|
node[:port]=nodear[0][2]
|
97
|
-
|
109
|
+
node[:password]=nodear[0][3]
|
110
|
+
node
|
111
|
+
|
98
112
|
end
|
99
113
|
|
100
114
|
private
|
@@ -103,23 +117,24 @@ module Vagrant
|
|
103
117
|
NODE_NAME_COLUMN = 'node_name'
|
104
118
|
NODE_ADDRESS_COLUMN = 'node_address'
|
105
119
|
NODE_PORT_COLUMN = 'node_port'
|
120
|
+
NODE_PASSWORD_COLUMN = 'node_password'
|
106
121
|
|
107
|
-
def check_database
|
122
|
+
def check_database(data_dir)
|
108
123
|
#Creates and/or open the database
|
109
|
-
db = SQLite3::Database.new( "/
|
124
|
+
db = SQLite3::Database.new( data_dir.to_s + "/nodemaster.db" )
|
110
125
|
|
111
126
|
if db.execute("SELECT name FROM sqlite_master
|
112
127
|
WHERE type='table' AND name='#{TABLE_NAME}';").length==0
|
113
128
|
# db.execute( "create table '#{TABLE_NAME}' (id INTEGER PRIMARY KEY AUTOINCREMENT,
|
114
129
|
# {NODE_NAME_COLUMN} TEXT, #{NODE_ADDRESS_COLUMN} TEXT);" )
|
115
|
-
db.execute( "create table '#{TABLE_NAME}' (#{NODE_NAME_COLUMN} TEXT PRIMARY KEY
|
116
|
-
#{NODE_ADDRESS_COLUMN} TEXT NOT NULL,
|
117
|
-
#{NODE_PORT_COLUMN} INTEGER NOT NULL);" )
|
130
|
+
db.execute( "create table '#{TABLE_NAME}' (#{NODE_NAME_COLUMN} TEXT PRIMARY KEY,#{NODE_ADDRESS_COLUMN} TEXT NOT NULL,#{NODE_PORT_COLUMN} INTEGER NOT NULL,#{NODE_PASSWORD_COLUMN} VARCHAR(64) NOT NULL);" )
|
118
131
|
end
|
119
|
-
|
132
|
+
|
133
|
+
db
|
134
|
+
|
120
135
|
end
|
121
136
|
|
122
|
-
def ipvalid?(node_address)
|
137
|
+
def self.ipvalid?(node_address)
|
123
138
|
|
124
139
|
ipreg= '^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$'
|
125
140
|
|
@@ -131,11 +146,11 @@ module Vagrant
|
|
131
146
|
return true
|
132
147
|
end
|
133
148
|
|
134
|
-
|
149
|
+
false
|
135
150
|
|
136
151
|
end
|
137
152
|
|
138
|
-
def dnsvalid?(node_address)
|
153
|
+
def self.dnsvalid?(node_address)
|
139
154
|
|
140
155
|
|
141
156
|
hostreg='^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$'
|
@@ -147,27 +162,28 @@ module Vagrant
|
|
147
162
|
return true
|
148
163
|
end
|
149
164
|
|
150
|
-
|
165
|
+
false
|
151
166
|
|
152
167
|
end
|
153
168
|
|
154
169
|
|
155
|
-
def namevalid?(node_name)
|
170
|
+
def self.namevalid?(node_name)
|
156
171
|
#only allowing '_' and '-'
|
157
172
|
namereg = '^[a-z0-9_-]*$'
|
158
173
|
nameregex = Regexp.new(namereg)
|
159
174
|
if (node_name =~nameregex)
|
160
175
|
return true
|
161
176
|
end
|
162
|
-
|
177
|
+
|
178
|
+
false
|
163
179
|
|
164
180
|
end
|
165
181
|
|
166
|
-
def portvalid?(node_port)
|
182
|
+
def self.portvalid?(node_port)
|
167
183
|
if (node_port>=1024)
|
168
184
|
return true
|
169
185
|
end
|
170
|
-
|
186
|
+
false
|
171
187
|
end
|
172
188
|
|
173
189
|
end
|