vmc_knife 0.0.10 → 0.0.11
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/lib/vmc_knife/cli_extensions.rb +4 -10
- data/lib/vmc_knife/commands/knife_cmds.rb +28 -15
- data/lib/vmc_knife/data_services.rb +46 -28
- data/lib/vmc_knife/json_expander.rb +3 -3
- metadata +3 -3
@@ -25,13 +25,7 @@ class VMC::Cli::KnifeRunner < VMC::Cli::Runner
|
|
25
25
|
when 'expand-manifest'
|
26
26
|
usage('vmc_knife expand-manifest <path_to_json_manifest> <path_to_destination_expanded_manifest>')
|
27
27
|
@args.shift # consumes the argument.
|
28
|
-
|
29
|
-
set_cmd(:knife, :expand_manifest, 1)
|
30
|
-
elsif @args.size == 2
|
31
|
-
set_cmd(:knife, :expand_manifest, 2)
|
32
|
-
else
|
33
|
-
set_cmd(:knife, :expand_manifest)
|
34
|
-
end
|
28
|
+
set_cmd(:knife, :expand_manifest, @args.size)
|
35
29
|
when 'login', 'target'
|
36
30
|
usage('vmc_knife login [<path_to_json_manifest>]')
|
37
31
|
@args.shift # consumes the argument.
|
@@ -137,7 +131,7 @@ class VMC::Cli::KnifeRunner < VMC::Cli::Runner
|
|
137
131
|
set_cmd(:knifeapps, :delete_all, @args.size) # too many
|
138
132
|
end
|
139
133
|
when 'data-shell','psql','mongo'
|
140
|
-
usage('vmc_knife data-shell [<data-service-name>] [<app-name>]')
|
134
|
+
usage('vmc_knife data-shell [<data-service-name>] [<app-name>] [<cmd-file> or <quoted-cmd>]')
|
141
135
|
@args.shift # consumes the argument.
|
142
136
|
if @args.size <= 2
|
143
137
|
set_cmd(:knifeapps, :data_shell, @args.size)
|
@@ -177,7 +171,7 @@ class VMC::Cli::KnifeRunner < VMC::Cli::Runner
|
|
177
171
|
set_cmd(:knifeapps, :data_shrink, @args.size) # too many
|
178
172
|
end
|
179
173
|
when 'data-import'
|
180
|
-
usage('vmc_knife data-import [<data-service-name>] [<tables-collection-regexp>]')
|
174
|
+
usage('vmc_knife data-import [<data-service-name>] [<archive-file-name>] [<tables-collection-regexp>]')
|
181
175
|
@args.shift # consumes the argument.
|
182
176
|
if @args.size <= 3
|
183
177
|
set_cmd(:knifeapps, :data_import, @args.size)
|
@@ -185,7 +179,7 @@ class VMC::Cli::KnifeRunner < VMC::Cli::Runner
|
|
185
179
|
set_cmd(:knifeapps, :data_import, @args.size) # too many
|
186
180
|
end
|
187
181
|
when 'data-export'
|
188
|
-
usage('vmc_knife data-export [<data-service-name>] [<tables-collection-regexp>]')
|
182
|
+
usage('vmc_knife data-export [<data-service-name>] [<archive-file-name>] [<tables-collection-regexp>]')
|
189
183
|
@args.shift # consumes the argument.
|
190
184
|
if @args.size <= 3
|
191
185
|
set_cmd(:knifeapps, :data_export, @args.size)
|
@@ -38,17 +38,20 @@ module VMC::Cli::Command
|
|
38
38
|
include VMC::KNIFE::Cli
|
39
39
|
|
40
40
|
# expands the json manifest. outputs it in the destination path.
|
41
|
-
|
41
|
+
|
42
|
+
def expand_manifest(manifest_file_path=ENV['VMC_KNIFE_DEFAULT_RECIPE'], destination=nil)
|
42
43
|
res = VMC::KNIFE::JSON_EXPANDER.expand_json manifest_file_path
|
43
|
-
if destination
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
44
|
+
if destination
|
45
|
+
display "Expanding the manifest #{manifest_file_path} into #{destination}"
|
46
|
+
if VMC::Cli::Config.trace
|
47
|
+
display JSON.pretty_generate(res)
|
48
|
+
end
|
49
|
+
File.open(destination, 'w') {|f| f.write(JSON.pretty_generate(res)) }
|
50
|
+
else
|
51
|
+
STDERR.puts "Expanding the manifest #{manifest_file_path}"
|
52
|
+
STDOUT.puts JSON.pretty_generate(res)
|
50
53
|
end
|
51
|
-
|
54
|
+
|
52
55
|
end
|
53
56
|
|
54
57
|
# updates the cloud_controller
|
@@ -194,12 +197,12 @@ module VMC::Cli::Command
|
|
194
197
|
# nil means all apps for all recipes found in the manifest are configured.
|
195
198
|
# @param recipes The list of recipes: nil: search the apps in all recipes
|
196
199
|
# @param app_role_names The names of the apps in each recipe; nil: configure all apps found.
|
197
|
-
def configure(recipes_regexp=nil,app_names_regexp=nil,service_names_regexp=nil,manifest_file_path=nil)
|
200
|
+
def configure(recipes_regexp=nil,app_names_regexp=nil,service_names_regexp=nil,manifest_file_path=nil,opts=nil)
|
198
201
|
man = load_manifest(manifest_file_path)
|
199
202
|
recipes_regexp = as_regexp(recipes_regexp)
|
200
203
|
app_names_regexp = as_regexp(app_names_regexp)
|
201
204
|
service_names_regexp = as_regexp(service_names_regexp)
|
202
|
-
configurer = VMC::KNIFE::RecipesConfigurationApplier.new(man,client,recipes_regexp,app_names_regexp,service_names_regexp)
|
205
|
+
configurer = VMC::KNIFE::RecipesConfigurationApplier.new(man,client,recipes_regexp,app_names_regexp,service_names_regexp,opts)
|
203
206
|
if VMC::Cli::Config.trace
|
204
207
|
display "Pending updates"
|
205
208
|
display JSON.pretty_generate(configurer.updates_pending)
|
@@ -226,9 +229,19 @@ module VMC::Cli::Command
|
|
226
229
|
def delete_all(app_names_regexp=nil,manifest_file_path=nil)
|
227
230
|
recipe_configuror(:delete,nil,app_names_regexp,nil,manifest_file_path)
|
228
231
|
end
|
229
|
-
def data_shell(data_names_regexp=nil,manifest_file_path=nil)
|
232
|
+
def data_shell(data_names_regexp=nil,file_or_cmd=nil,app_name=nil,manifest_file_path=nil)
|
233
|
+
file_name = nil
|
234
|
+
cmd = nil
|
235
|
+
if file_or_cmd
|
236
|
+
if File.exist? file_or_cmd
|
237
|
+
file_name = file_or_cmd
|
238
|
+
else
|
239
|
+
cmd = file_or_cmd
|
240
|
+
cmd = cmd[1..-1] if cmd.start_with?('"') || cmd.start_with?("'")
|
241
|
+
end
|
242
|
+
end
|
230
243
|
recipe_configuror(:shell,nil,nil,data_names_regexp,manifest_file_path,
|
231
|
-
{:data_only=>true})
|
244
|
+
{:file_name=>file_name, :data_cmd=>cmd, :app_name=>app_name, :data_only=>true})
|
232
245
|
end
|
233
246
|
def data_credentials(data_names_regexp=nil,manifest_file_path=nil)
|
234
247
|
recipe_configuror(:credentials,nil,nil,data_names_regexp,manifest_file_path,
|
@@ -238,11 +251,11 @@ module VMC::Cli::Command
|
|
238
251
|
recipe_configuror(:apply_privileges,nil,nil,data_names_regexp,manifest_file_path,
|
239
252
|
{:data_only=>true})
|
240
253
|
end
|
241
|
-
def data_import(data_names_regexp=nil,
|
254
|
+
def data_import(data_names_regexp=nil,file_names=nil,app_name=nil,manifest_file_path=nil)
|
242
255
|
recipe_configuror(:import,nil,nil,data_names_regexp,manifest_file_path,
|
243
256
|
{:file_names=>file_names, :app_name=>app_name, :data_only=>true})
|
244
257
|
end
|
245
|
-
def data_export(data_names_regexp=nil,
|
258
|
+
def data_export(data_names_regexp=nil,file_names=nil,app_name=nil,manifest_file_path=nil)
|
246
259
|
recipe_configuror(:export,nil,nil,data_names_regexp,manifest_file_path,
|
247
260
|
{:file_names=>file_names, :app_name=>app_name, :data_only=>true})
|
248
261
|
end
|
@@ -119,7 +119,6 @@ module VMC
|
|
119
119
|
db_arg = "--db #{credentials_hash['db']}"
|
120
120
|
end
|
121
121
|
cmd = "#{mongo_shell} -u #{credentials_hash['username']} -p #{credentials_hash['password']} #{credentials_hash['hostname']}:#{credentials_hash['port']}#{db_arg}"
|
122
|
-
puts "Executing #{cmd}"
|
123
122
|
if commands_file
|
124
123
|
if mongo_shell == 'mongo'
|
125
124
|
if File.exists? commands_file
|
@@ -129,8 +128,11 @@ module VMC
|
|
129
128
|
commands_file = "--eval \"#{commands_file}\""
|
130
129
|
end
|
131
130
|
end
|
132
|
-
|
131
|
+
the_cmd = "#{cmd} #{commands_file}"
|
132
|
+
puts "#{the_cmd}" if VMC::Cli::Config.trace
|
133
|
+
puts `#{the_cmd}`
|
133
134
|
else
|
135
|
+
puts "#{cmd}" if VMC::Cli::Config.trace
|
134
136
|
# Replaces the current process.
|
135
137
|
exec cmd
|
136
138
|
end
|
@@ -142,8 +144,11 @@ module VMC
|
|
142
144
|
else
|
143
145
|
commands_file = "-c \"#{commands_file}\" #{PSQL_RAW_RES_ARGS}"
|
144
146
|
end
|
145
|
-
|
147
|
+
the_cmd = "#{cmd} #{commands_file}"
|
148
|
+
puts "#{the_cmd}" if VMC::Cli::Config.trace
|
149
|
+
puts `#{the_cmd}`
|
146
150
|
else
|
151
|
+
puts "#{cmd}" if VMC::Cli::Config.trace
|
147
152
|
# Replaces the current process.
|
148
153
|
exec cmd
|
149
154
|
end
|
@@ -173,9 +178,14 @@ module VMC
|
|
173
178
|
|
174
179
|
class RecipesConfigurationApplier
|
175
180
|
def shell()
|
181
|
+
app_name = @opts[:app_name] if @opts
|
182
|
+
file_name = @opts[:file_name] if @opts
|
183
|
+
data_cmd = @opts[:data_cmd] if @opts
|
184
|
+
if data_cmd
|
185
|
+
file_name = data_cmd
|
186
|
+
end
|
176
187
|
@data_services.each do |data_service|
|
177
|
-
|
178
|
-
data_service.shell(app_name)
|
188
|
+
data_service.shell(file_name)
|
179
189
|
end
|
180
190
|
end
|
181
191
|
def credentials()
|
@@ -196,8 +206,8 @@ module VMC
|
|
196
206
|
end
|
197
207
|
end
|
198
208
|
def export()
|
199
|
-
file_names = opts
|
200
|
-
app_name = opts
|
209
|
+
file_names = @opts[:file_names] if @opts
|
210
|
+
app_name = @opts[:app_name] if @opts
|
201
211
|
@data_services.each do |data_service|
|
202
212
|
data_service.export(app_name,file_names)
|
203
213
|
end
|
@@ -322,7 +332,7 @@ module VMC
|
|
322
332
|
base_dir=VMC::KNIFE.get_mongodb_base_dir()
|
323
333
|
instance_name=creds['name']
|
324
334
|
dbpath=File.join(base_dir, instance_name, 'data')
|
325
|
-
mongod_lock=File.join(dbpath,'
|
335
|
+
mongod_lock=File.join(dbpath,'mongod.lock')
|
326
336
|
|
327
337
|
if File.exists?(mongod_lock) && File.size(mongod_lock)>0
|
328
338
|
# the mongodb instance is currently working. connect to it and do the work.
|
@@ -350,13 +360,15 @@ module VMC
|
|
350
360
|
extension ||= "sql"
|
351
361
|
file = "#{name()}.#{extension}"
|
352
362
|
end
|
353
|
-
|
354
|
-
|
363
|
+
archive_unzipped=file
|
364
|
+
archive_unzipped="#{name()}.sql" unless /\.sql$/ =~ extension
|
365
|
+
`touch #{archive_unzipped}`
|
366
|
+
`chmod o+w #{archive_unzipped}`
|
355
367
|
puts "Exports the database #{credentials(app_name)['name']} in #{file}"
|
356
368
|
#sudo -u postgres env PGPASSWORD=intalio DBNAME=intalio DUMPFILE=intalio_dump.sql pg_dump --format=p --file=$DUMPFILE --no-owner --clean --blobs --no-acl --oid --no-tablespaces $DBNAME
|
357
369
|
#sudo -u postgres env PGPASSWORD=$PGPASSWORD DUMPFILE=$DUMPFILE pg_dump --format=p --file=$DUMPFILE --no-owner --clean --blobs --no-acl --oid --no-tablespaces $DBNAME
|
358
370
|
|
359
|
-
cmd = VMC::KNIFE.pg_connect_cmd(credentials(app_name), 'pg_dump', false, "--format=p --file=#{
|
371
|
+
cmd = VMC::KNIFE.pg_connect_cmd(credentials(app_name), 'pg_dump', false, "--format=p --file=#{archive_unzipped} --no-owner --clean --oids --blobs --no-acl --no-privileges --no-tablespaces")
|
360
372
|
puts cmd
|
361
373
|
puts `#{cmd}`
|
362
374
|
`chmod o-w #{file}`
|
@@ -374,29 +386,32 @@ module VMC
|
|
374
386
|
base_dir=VMC::KNIFE.get_mongodb_base_dir()
|
375
387
|
instance_name=creds['name']
|
376
388
|
dbpath=File.join(base_dir, instance_name, 'data')
|
377
|
-
mongod_lock=File.join(dbpath,'
|
389
|
+
mongod_lock=File.join(dbpath,'mongod.lock')
|
390
|
+
puts "looking at #{mongod_lock} exists? #{File.exists?(mongod_lock)} size #{File.size(mongod_lock)}"
|
378
391
|
if File.exists?(mongod_lock) && File.size(mongod_lock)>0
|
379
|
-
cmd = "#{mongodump_exec} -u #{
|
392
|
+
cmd = "#{mongodump_exec} -u #{creds['username']} -p #{creds['password']} --host #{creds['hostname']}:#{creds['port']} --db db"
|
380
393
|
else
|
381
394
|
cmd = "#{mongodump_exec} --dbpath #{dbpath}"
|
382
395
|
end
|
383
396
|
puts cmd
|
384
397
|
puts `#{cmd}`
|
398
|
+
archive_unzipped="dump"
|
399
|
+
end
|
385
400
|
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
`rm -rf dump`
|
401
|
+
|
402
|
+
# this produces a dump folder in the working directory.
|
403
|
+
# let's zip it:
|
404
|
+
if /\.zip$/ =~ file
|
405
|
+
# just zip
|
406
|
+
`zip -r #{file} #{archive_unzipped}`
|
407
|
+
elsif /\.tar$/ =~ file
|
408
|
+
# just tar
|
409
|
+
`tar -cvf #{file} #{archive_unzipped}`
|
410
|
+
else
|
411
|
+
# tar-gzip by default
|
412
|
+
`tar -czvf #{file} #{archive_unzipped}`
|
399
413
|
end
|
414
|
+
`rm -rf #{archive_unzipped}` if archive_unzipped != file
|
400
415
|
end
|
401
416
|
|
402
417
|
def is_postgresql()
|
@@ -416,7 +431,10 @@ module VMC
|
|
416
431
|
cmd_acl="GRANT CREATE ON SCHEMA PUBLIC TO PUBLIC;\
|
417
432
|
GRANT ALL ON ALL TABLES IN SCHEMA PUBLIC TO PUBLIC;\
|
418
433
|
GRANT ALL ON ALL FUNCTIONS IN SCHEMA PUBLIC TO PUBLIC;\
|
419
|
-
GRANT ALL ON ALL SEQUENCES IN SCHEMA PUBLIC TO PUBLIC
|
434
|
+
GRANT ALL ON ALL SEQUENCES IN SCHEMA PUBLIC TO PUBLIC;\
|
435
|
+
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON TABLES TO PUBLIC;\
|
436
|
+
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON SEQUENCES TO PUBLIC;\
|
437
|
+
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON FUNCTIONS TO PUBLIC;"
|
420
438
|
shell(cmd_acl,true)
|
421
439
|
end
|
422
440
|
end
|
@@ -429,7 +447,7 @@ module VMC
|
|
429
447
|
base_dir=VMC::KNIFE.get_mongodb_base_dir()
|
430
448
|
instance_name=creds['name']
|
431
449
|
dbpath=File.join(base_dir, instance_name, 'data')
|
432
|
-
mongod_lock=File.join(dbpath,'
|
450
|
+
mongod_lock=File.join(dbpath,'mongod.lock')
|
433
451
|
raise "Can't shrink #{name}; the mongodb is currently running" if File.exists?(mongod_lock) && File.size(mongod_lock)>0
|
434
452
|
mongodump_exec=VMC::KNIFE.get_mongo_exec('mongodump')
|
435
453
|
raise "Can't find mongodump" unless File.exist? mongodump_exec
|
@@ -35,11 +35,11 @@ module VMC
|
|
35
35
|
ip = ip_mask[0]
|
36
36
|
mask = ip_mask[1]
|
37
37
|
ip_segs = ip.split('.')
|
38
|
-
if mask
|
38
|
+
if mask.start_with? "255.255.255."
|
39
39
|
ip_segs[3]
|
40
|
-
elsif mask
|
40
|
+
elsif mask.start_with? "255.255"
|
41
41
|
"#{ip_segs[2]}-#{ip_segs[3]}"
|
42
|
-
elsif mask
|
42
|
+
elsif mask.start_with? "255."
|
43
43
|
"#{ip_segs[1]}-#{ip_segs[2]}-#{ip_segs[3]}"
|
44
44
|
else
|
45
45
|
#hum why are we here?
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vmc_knife
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 9
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 11
|
10
|
+
version: 0.0.11
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Intalio Pte
|