vagrant-nodemaster 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/Rakefile +1 -0
- data/lib/vagrant-nodemaster.rb +26 -0
- data/lib/vagrant-nodemaster/apidesc.rb +220 -0
- data/lib/vagrant-nodemaster/node/nodeadd.rb +33 -0
- data/lib/vagrant-nodemaster/node/nodedbmanager.rb +176 -0
- data/lib/vagrant-nodemaster/node/nodelist.rb +34 -0
- data/lib/vagrant-nodemaster/node/noderemove.rb +43 -0
- data/lib/vagrant-nodemaster/node/nodestatus.rb +73 -0
- data/lib/vagrant-nodemaster/node/nodeupdate.rb +43 -0
- data/lib/vagrant-nodemaster/nodecommand.rb +102 -0
- data/lib/vagrant-nodemaster/remote/remotebackupcommand.rb +90 -0
- data/lib/vagrant-nodemaster/remote/remotebackuplog.rb +62 -0
- data/lib/vagrant-nodemaster/remote/remotebackuptake.rb +50 -0
- data/lib/vagrant-nodemaster/remote/remoteboxadd.rb +35 -0
- data/lib/vagrant-nodemaster/remote/remoteboxcommand.rb +98 -0
- data/lib/vagrant-nodemaster/remote/remoteboxdelete.rb +40 -0
- data/lib/vagrant-nodemaster/remote/remoteboxlist.rb +32 -0
- data/lib/vagrant-nodemaster/remote/remotedestroy.rb +66 -0
- data/lib/vagrant-nodemaster/remote/remotehalt.rb +48 -0
- data/lib/vagrant-nodemaster/remote/remoteprovision.rb +43 -0
- data/lib/vagrant-nodemaster/remote/remoteresume.rb +32 -0
- data/lib/vagrant-nodemaster/remote/remotesnapshotcommand.rb +93 -0
- data/lib/vagrant-nodemaster/remote/remotesnapshotlist.rb +60 -0
- data/lib/vagrant-nodemaster/remote/remotesnapshotrestore.rb +34 -0
- data/lib/vagrant-nodemaster/remote/remotesnapshottake.rb +31 -0
- data/lib/vagrant-nodemaster/remote/remotessh.rb +55 -0
- data/lib/vagrant-nodemaster/remote/remotesuspend.rb +32 -0
- data/lib/vagrant-nodemaster/remote/remoteup.rb +43 -0
- data/lib/vagrant-nodemaster/remote/remotevmstatus.rb +43 -0
- data/lib/vagrant-nodemaster/remotecommand.rb +155 -0
- data/lib/vagrant-nodemaster/requestcontroller.rb +344 -0
- data/lib/vagrant-nodemaster/version.rb +5 -0
- data/vagrant-nodemaster.gemspec +29 -0
- metadata +157 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "vagrant-nodemaster/version"
|
2
|
+
|
3
|
+
module Vagrant
|
4
|
+
module NodeMaster
|
5
|
+
class Plugin < Vagrant.plugin("2")
|
6
|
+
|
7
|
+
name "remote"
|
8
|
+
description <<-DESC
|
9
|
+
Este es mi primer plugin y estoy probando la estructura
|
10
|
+
DESC
|
11
|
+
|
12
|
+
|
13
|
+
command ('remote') do
|
14
|
+
require_relative "vagrant-nodemaster/remotecommand"
|
15
|
+
Command
|
16
|
+
end
|
17
|
+
|
18
|
+
command ('node') do
|
19
|
+
require_relative "vagrant-nodemaster/nodecommand"
|
20
|
+
Command
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,220 @@
|
|
1
|
+
module RestRoutes
|
2
|
+
#FIXME Figure how to manage remote port
|
3
|
+
# REMOTE_PORT = 3333
|
4
|
+
|
5
|
+
class RouteManager
|
6
|
+
|
7
|
+
def self.box_list_route
|
8
|
+
BOX_LIST_ROUTE
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.box_delete_route
|
12
|
+
BOX_DELETE_ROUTE
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.box_add_route
|
16
|
+
BOX_ADD_ROUTE
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.vm_up_route
|
20
|
+
VM_UP_ROUTE
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.vm_suspend_route
|
24
|
+
VM_SUSPEND_ROUTE
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.vm_resume_route
|
28
|
+
VM_RESUME_ROUTE
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.vm_halt_route
|
32
|
+
VM_HALT_ROUTE
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.vm_destroy_route
|
36
|
+
VM_DESTROY_ROUTE
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.vm_status_route
|
40
|
+
VM_STATUS_ROUTE
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.vm_provision_route
|
44
|
+
VM_PROVISION_ROUTE
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.vm_status_all_route
|
48
|
+
VM_STATUS_ALL_ROUTE
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.vm_sshconfig_route
|
52
|
+
SSH_CONFIG_ROUTE
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.snapshots_all_route
|
56
|
+
SNAPSHOTS_ALL_ROUTE
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.vm_snapshots_route
|
60
|
+
VM_SNAPSHOTS_ROUTE
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.vm_snapshot_take_route
|
64
|
+
VM_SNAPSHOT_TAKE_ROUTE
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.vm_snapshot_restore_route
|
68
|
+
VM_SNAPSHOT_RESTORE_ROUTE
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.node_backup_log_route
|
72
|
+
NODE_BACKUP_LOG_ROUTE
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.vm_backup_log_route
|
76
|
+
VM_BACKUP_LOG_ROUTE
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
def self.box_list_url(host,port)
|
81
|
+
"http://#{host}:#{port}#{box_list_route}"
|
82
|
+
end
|
83
|
+
|
84
|
+
def self.box_add_url(host,port)
|
85
|
+
"http://#{host}:#{port}#{box_add_route}"
|
86
|
+
end
|
87
|
+
|
88
|
+
def self.box_delete_url(host,port,box,provider)
|
89
|
+
|
90
|
+
url=String.new(box_delete_route)
|
91
|
+
url[":box"]=box
|
92
|
+
url[":provider"]=provider
|
93
|
+
url="http://#{host}:#{port}#{url}"
|
94
|
+
|
95
|
+
url
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
def self.vm_up_url(host,port)
|
102
|
+
"http://#{host}:#{port}#{vm_up_route}"
|
103
|
+
end
|
104
|
+
|
105
|
+
def self.vm_halt_url(host,port)
|
106
|
+
"http://#{host}:#{port}#{vm_halt_route}"
|
107
|
+
end
|
108
|
+
|
109
|
+
def self.vm_destroy_url(host,port)
|
110
|
+
"http://#{host}:#{port}#{vm_destroy_route}"
|
111
|
+
end
|
112
|
+
|
113
|
+
def self.vm_suspend_url(host,port)
|
114
|
+
"http://#{host}:#{port}#{vm_suspend_route}"
|
115
|
+
end
|
116
|
+
|
117
|
+
def self.vm_resume_url(host,port)
|
118
|
+
"http://#{host}:#{port}#{vm_resume_route}"
|
119
|
+
end
|
120
|
+
|
121
|
+
def self.vm_provision_url(host,port)
|
122
|
+
"http://#{host}:#{port}#{vm_provision_route}"
|
123
|
+
end
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
|
128
|
+
def self.vm_status_url(host,port,vmname=nil)
|
129
|
+
url="http://#{host}:#{port}#{vm_status_all_route}"
|
130
|
+
|
131
|
+
if (vmname!=nil)
|
132
|
+
url=String.new(vm_status_route)
|
133
|
+
url[":vm"]=vmname
|
134
|
+
url="http://#{host}:#{port}#{url}"
|
135
|
+
end
|
136
|
+
|
137
|
+
url
|
138
|
+
|
139
|
+
end
|
140
|
+
|
141
|
+
def self.vm_sshconfig_url(host,port,vmname)
|
142
|
+
url=String.new(vm_sshconfig_route)
|
143
|
+
url[":vm"]=vmname
|
144
|
+
|
145
|
+
"http://#{host}:#{port}#{url}"
|
146
|
+
|
147
|
+
end
|
148
|
+
|
149
|
+
def self.snapshot_list_url(host,port,vmname=nil)
|
150
|
+
url="http://#{host}:#{port}#{snapshots_all_route}"
|
151
|
+
|
152
|
+
if (vmname!=nil)
|
153
|
+
url=String.new(vm_snapshots_route)
|
154
|
+
url[":vm"]=vmname
|
155
|
+
url="http://#{host}:#{port}#{url}"
|
156
|
+
end
|
157
|
+
|
158
|
+
url
|
159
|
+
|
160
|
+
end
|
161
|
+
|
162
|
+
def self.vm_snapshot_take_url(host,port,vmname)
|
163
|
+
url=String.new(vm_snapshot_take_route)
|
164
|
+
url[":vm"]=vmname
|
165
|
+
url="http://#{host}:#{port}#{url}"
|
166
|
+
|
167
|
+
url
|
168
|
+
|
169
|
+
end
|
170
|
+
|
171
|
+
def self.vm_snapshot_restore_url(host,port,vmname)
|
172
|
+
url=String.new(vm_snapshot_restore_route)
|
173
|
+
url[":vm"]=vmname
|
174
|
+
url="http://#{host}:#{port}#{url}"
|
175
|
+
|
176
|
+
url
|
177
|
+
|
178
|
+
end
|
179
|
+
|
180
|
+
def self.backup_log_url(host,port,vmname=nil)
|
181
|
+
url="http://#{host}:#{port}#{node_backup_log_route}"
|
182
|
+
|
183
|
+
if (vmname!=nil)
|
184
|
+
url=String.new(vm_backup_log_route)
|
185
|
+
url[":vm"]=vmname
|
186
|
+
url="http://#{host}:#{port}#{url}"
|
187
|
+
end
|
188
|
+
|
189
|
+
url
|
190
|
+
|
191
|
+
end
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
private
|
196
|
+
BOX_LIST_ROUTE = "/api/box/list"
|
197
|
+
BOX_DELETE_ROUTE = "/api/box/:box/:provider/delete"
|
198
|
+
BOX_ADD_ROUTE = "/api/box/add"
|
199
|
+
|
200
|
+
VM_UP_ROUTE = "/api/vm/up"
|
201
|
+
VM_HALT_ROUTE = "/api/vm/halt"
|
202
|
+
VM_DESTROY_ROUTE = "/api/vm/destroy"
|
203
|
+
VM_SUSPEND_ROUTE = "/api/vm/suspend"
|
204
|
+
VM_RESUME_ROUTE = "/api/vm/resume"
|
205
|
+
VM_PROVISION_ROUTE = "/api/vm/provision"
|
206
|
+
VM_STATUS_ALL_ROUTE = "/api/vm/status"
|
207
|
+
VM_STATUS_ROUTE = "/api/vm/:vm/status"
|
208
|
+
SSH_CONFIG_ROUTE = "/api/vm/:vm/sshconfig"
|
209
|
+
|
210
|
+
SNAPSHOTS_ALL_ROUTE = "/api/vm/snapshots"
|
211
|
+
VM_SNAPSHOTS_ROUTE = "/api/vm/:vm/snapshots"
|
212
|
+
VM_SNAPSHOT_TAKE_ROUTE = "/api/vm/:vm/take"
|
213
|
+
VM_SNAPSHOT_RESTORE_ROUTE = "/api/vm/:vm/restore"
|
214
|
+
|
215
|
+
VM_BACKUP_LOG_ROUTE = "/api/vm/:vm/backuplog"
|
216
|
+
NODE_BACKUP_LOG_ROUTE = "/api/backuplog"
|
217
|
+
|
218
|
+
end
|
219
|
+
|
220
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'vagrant-nodemaster/node/nodedbmanager'
|
2
|
+
|
3
|
+
module Vagrant
|
4
|
+
module NodeMaster
|
5
|
+
|
6
|
+
class NodeAdd < Vagrant.plugin(2, :command)
|
7
|
+
|
8
|
+
def execute
|
9
|
+
|
10
|
+
options = {}
|
11
|
+
|
12
|
+
opts = OptionParser.new do |opts|
|
13
|
+
opts.banner = "Usage: vagrant node add <node-name> <node-address> <node-port> --hostname"
|
14
|
+
opts.on("--hostname", "Address in dns format") do |d|
|
15
|
+
options[:dns] = d
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
argv = parse_options(opts)
|
20
|
+
return if !argv
|
21
|
+
raise Vagrant::Errors::CLIInvalidUsage, :help => opts.help.chomp if argv.length != 3
|
22
|
+
|
23
|
+
dbmanager=DB::NodeDBManager.new
|
24
|
+
|
25
|
+
dbmanager.add_node(argv[0],argv[1],argv[2].to_i,options[:dns])
|
26
|
+
|
27
|
+
0
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,176 @@
|
|
1
|
+
require 'sqlite3'
|
2
|
+
|
3
|
+
module Vagrant
|
4
|
+
module NodeMaster
|
5
|
+
module DB
|
6
|
+
class NodeDBManager
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@db=check_database
|
10
|
+
end
|
11
|
+
|
12
|
+
def add_node(node_name,node_address,node_port,dnsformat)
|
13
|
+
|
14
|
+
if (!portvalid?(node_port))
|
15
|
+
raise "Node port must be above 1023"
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
if (!namevalid?(node_name))
|
20
|
+
raise "Node name Invalid (Spectial characters allowed: '_' and '-')."
|
21
|
+
end
|
22
|
+
|
23
|
+
if (dnsformat && !dnsvalid?(node_address)) ||
|
24
|
+
(!dnsformat && !ipvalid?(node_address))
|
25
|
+
|
26
|
+
raise "Invalid ip or dns address."
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
sql="INSERT INTO #{TABLE_NAME} VALUES ( ? , ? , ?)"
|
32
|
+
@db.execute(sql,node_name,node_address,node_port)
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
def update_node(node_name,node_address,node_port,dnsformat)
|
37
|
+
|
38
|
+
if (!portvalid?(node_port))
|
39
|
+
|
40
|
+
raise "Node port must be above 1023"
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
if (dnsformat && !dnsvalid?(node_address)) ||
|
45
|
+
(!dnsformat && !ipvalid?(node_address))
|
46
|
+
|
47
|
+
raise "Invalid ip or dns address."
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
sql="UPDATE #{TABLE_NAME} SET #{NODE_ADDRESS_COLUMN} = ?,#{NODE_PORT_COLUMN} = ? WHERE #{NODE_NAME_COLUMN}= ?"
|
52
|
+
@db.execute(sql,node_address,node_port,node_name)
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
def remove_node(node_name)
|
60
|
+
sql="DELETE FROM #{TABLE_NAME} WHERE #{NODE_NAME_COLUMN}=?"
|
61
|
+
@db.execute(sql,node_name)
|
62
|
+
end
|
63
|
+
|
64
|
+
def remove_nodes
|
65
|
+
sql="DELETE FROM #{TABLE_NAME}"
|
66
|
+
@db.execute(sql)
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
def get_node_names
|
71
|
+
sql="SELECT #{NODE_NAME_COLUMN} FROM #{TABLE_NAME}"
|
72
|
+
return @db.execute(sql);
|
73
|
+
end
|
74
|
+
|
75
|
+
def get_nodes
|
76
|
+
sql="SELECT * FROM #{TABLE_NAME}"
|
77
|
+
rows=@db.execute(sql);
|
78
|
+
nodes = []
|
79
|
+
rows.each do |row|
|
80
|
+
node = {}
|
81
|
+
node[:name]=row[0]
|
82
|
+
node[:address]=row[1]
|
83
|
+
node[:port]=row[2]
|
84
|
+
nodes << node
|
85
|
+
end
|
86
|
+
|
87
|
+
return nodes
|
88
|
+
end
|
89
|
+
|
90
|
+
def get_node(node_name)
|
91
|
+
sql="SELECT * FROM #{TABLE_NAME} WHERE #{NODE_NAME_COLUMN}=?"
|
92
|
+
raise "Node not found" if (nodear=@db.execute(sql,node_name)).empty?
|
93
|
+
node = {}
|
94
|
+
node[:name]=nodear[0][0]
|
95
|
+
node[:address]=nodear[0][1]
|
96
|
+
node[:port]=nodear[0][2]
|
97
|
+
return node
|
98
|
+
end
|
99
|
+
|
100
|
+
private
|
101
|
+
|
102
|
+
TABLE_NAME='node_table'
|
103
|
+
NODE_NAME_COLUMN = 'node_name'
|
104
|
+
NODE_ADDRESS_COLUMN = 'node_address'
|
105
|
+
NODE_PORT_COLUMN = 'node_port'
|
106
|
+
|
107
|
+
def check_database
|
108
|
+
#Creates and/or open the database
|
109
|
+
db = SQLite3::Database.new( "/tmp/test.db" )
|
110
|
+
|
111
|
+
if db.execute("SELECT name FROM sqlite_master
|
112
|
+
WHERE type='table' AND name='#{TABLE_NAME}';").length==0
|
113
|
+
# db.execute( "create table '#{TABLE_NAME}' (id INTEGER PRIMARY KEY AUTOINCREMENT,
|
114
|
+
# {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);" )
|
118
|
+
end
|
119
|
+
return db
|
120
|
+
end
|
121
|
+
|
122
|
+
def ipvalid?(node_address)
|
123
|
+
|
124
|
+
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
|
+
|
126
|
+
|
127
|
+
ipregex = Regexp.new(ipreg)
|
128
|
+
|
129
|
+
|
130
|
+
if (node_address =~ ipregex)
|
131
|
+
return true
|
132
|
+
end
|
133
|
+
|
134
|
+
return false
|
135
|
+
|
136
|
+
end
|
137
|
+
|
138
|
+
def dnsvalid?(node_address)
|
139
|
+
|
140
|
+
|
141
|
+
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])$'
|
142
|
+
|
143
|
+
|
144
|
+
hregex = Regexp.new(hostreg)
|
145
|
+
|
146
|
+
if (node_address =~ hregex)
|
147
|
+
return true
|
148
|
+
end
|
149
|
+
|
150
|
+
return false
|
151
|
+
|
152
|
+
end
|
153
|
+
|
154
|
+
|
155
|
+
def namevalid?(node_name)
|
156
|
+
#only allowing '_' and '-'
|
157
|
+
namereg = '^[a-z0-9_-]*$'
|
158
|
+
nameregex = Regexp.new(namereg)
|
159
|
+
if (node_name =~nameregex)
|
160
|
+
return true
|
161
|
+
end
|
162
|
+
return false
|
163
|
+
|
164
|
+
end
|
165
|
+
|
166
|
+
def portvalid?(node_port)
|
167
|
+
if (node_port>=1024)
|
168
|
+
return true
|
169
|
+
end
|
170
|
+
return false
|
171
|
+
end
|
172
|
+
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|