nex_client 0.10.0 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3d9e6166df47119dad5f9ed37162f90dc09fed76
4
- data.tar.gz: ba61368242bbc4c1226dfe31c7e0c1b9252134ac
3
+ metadata.gz: 1adedef202faa3b3708d8ddef5f23ca366e6f46b
4
+ data.tar.gz: cca86cabe36af8d1a17e5168ba70a09bc2c59723
5
5
  SHA512:
6
- metadata.gz: c3f09ff9d2cff8c5bda7c140f2f2b5bca6eab183948dc1835ee83c211e4742717ae0b314e236884dd68ca501489816433aad2044bc24ab980d357c0d1e3c0079
7
- data.tar.gz: 438a36987ec311f99257200e643d389129397565fe0e67bdb80e3b179a8e9bb14fa37641831721c0c675b4fbee942bc4495bd55cf80a51881f5bf1e6fc5ad50e
6
+ metadata.gz: 9e800785f3a84c6f20a84404a9e78b9f45b589e40464b3cff53c574895f5141d14349f763ba1387caca509802c9ceee05bbe69516ca6e21f702e251c972f87ec
7
+ data.tar.gz: 6f4ac9c0027199406a5a1765b3edbedd456e111d35ffeef198ded12ce099d0d6b39c85f069ecb5d512cdbf16014d6d87b62a806a16f1aabe60b5ae786b557152
@@ -111,6 +111,8 @@ module NexClient
111
111
  c.option '--ssl', 'list all apps with SSL enabled'
112
112
  c.option '--storage', 'list all apps with persistent storage'
113
113
  c.option '--owner HANDLE', 'list all apps for the specified owner'
114
+ c.option '--image IMAGE', 'list the app with this image'
115
+
114
116
  c.action do |args, options|
115
117
  NexClient::Commands::Apps.list(args,options)
116
118
  end
@@ -250,9 +252,12 @@ module NexClient
250
252
  c.example 'list all env variables for myapp', 'nex-cli apps:vars myapp'
251
253
  c.example 'Add env variables to myapp', 'nex-cli apps:vars myapp --add MYVAR1=VAL1,MYVAR2=VAL2'
252
254
  c.example 'Delete env variables from myapp', 'nex-cli apps:vars myapp --delete MYVAR,MYVAR'
255
+ c.example 'Add env variables to myapp from file', 'nex-cli apps:vars myapp --env-file ~/myenvfile'
256
+ c.example 'Add env variables to myapp from file and prefix all vars with foo (foo_myvar)', 'nex-cli apps:vars myapp --env-file ~/myenvfile --env-prefix foo'
253
257
  c.option '--add MYVAR=value,MYVAR2=value,...', Array, 'comma separated list of env variables'
254
258
  c.option '--delete MYVAR,MYVAR2,...', Array, 'comma separated list of env variables'
255
- c.option '--env-file FILE', String, 'newline separated list of env variables (MYVAR=1) or YAML file'
259
+ c.option '--env-file FILE', String, 'newline separated list of env variables (MYVAR=1) or YAML file. Note that YAML parsing is recursive.'
260
+ c.option '--env-prefix PREFIX', String, 'prefix all variables contained in the env file with the specified prefix (PREFIX_MYVAR)'
256
261
  c.action do |args, options|
257
262
  NexClient::Commands::Apps.manage_vars(args,options)
258
263
  end
@@ -10,7 +10,7 @@ module NexClient
10
10
 
11
11
  def self.list(args,opts)
12
12
  filters = {}
13
- filters[:status] = opts.status || 'active'
13
+ filters[:status] = opts.status || ['active','restarting']
14
14
  filters[:service] = opts.service if opts.service.present?
15
15
 
16
16
  # All option
@@ -18,10 +18,11 @@ module NexClient
18
18
 
19
19
  def self.list(args,opts)
20
20
  filters = {}
21
- filters[:status] = [opts.status || 'active']
21
+ filters[:status] = opts.status || ['active','restarting']
22
22
  filters[:ssl_enabled] = opts.ssl if opts.ssl.present?
23
23
  filters[:persistent_storage] = opts.storage if opts.storage.present?
24
24
  filters[:'owner.handle'] = opts.owner || '@self'
25
+ filters[:image] = opts.image if opts.image.present?
25
26
 
26
27
  # All option
27
28
  filters = {} if opts.all
@@ -48,6 +49,9 @@ module NexClient
48
49
  return false
49
50
  end
50
51
 
52
+ # Display app id
53
+ self.display_id(e)
54
+
51
55
  # Display app details
52
56
  self.display_apps(e)
53
57
 
@@ -112,7 +116,7 @@ module NexClient
112
116
  # Env variables from file
113
117
  if opts.env_file.present?
114
118
  attrs[:vars] ||= {}
115
- self.vars_from_file(opts.env_file) do |key,val|
119
+ vars_from_file(opts.env_file) do |key,val|
116
120
  attrs[:vars][key] = val
117
121
  end
118
122
  end
@@ -292,7 +296,7 @@ module NexClient
292
296
 
293
297
  # Add vars from file
294
298
  if opts.env_file.present?
295
- self.vars_from_file(opts.env_file) do |key,val|
299
+ vars_from_file(opts.env_file,opts.env_prefix) do |key,val|
296
300
  vars[key] = val
297
301
  end
298
302
  end
@@ -341,6 +345,14 @@ module NexClient
341
345
  self.display_scm(e.scm)
342
346
  end
343
347
 
348
+ def self.display_id(e)
349
+ table = Terminal::Table.new do |t|
350
+ t.add_row(['APP ID',e.id])
351
+ end
352
+ puts table
353
+ puts "\n"
354
+ end
355
+
344
356
  def self.display_apps(list)
345
357
  table = Terminal::Table.new title: APPS_TITLE, headings: APPS_HEADERS do |t|
346
358
  [list].flatten.compact.each do |e|
@@ -396,24 +408,6 @@ module NexClient
396
408
  return '-' unless record.node_count && record.max_node_count
397
409
  "#{record.node_count}/#{record.max_node_count}"
398
410
  end
399
-
400
- def self.vars_from_file(file,&block)
401
- # YAML file
402
- if file =~ /(\.yml|\.yaml)$/
403
- vars = YAML.load_file(file)
404
- vars.each do |k,v|
405
- yield(k,v)
406
- end
407
- else
408
- f = File.read(file)
409
- f.split("\n").each do |e|
410
- line = e.strip
411
- next if line.empty? || line.start_with?('#')
412
- key,val = e.split('=',2)
413
- yield(key,val)
414
- end
415
- end
416
- end
417
411
  end
418
412
  end
419
413
  end
@@ -42,7 +42,7 @@ module NexClient
42
42
  end
43
43
 
44
44
  # Get SSH details
45
- username = me.handle
45
+ username = me.handle.downcase
46
46
  pv_key = me.private_key
47
47
 
48
48
  # Create SSH Key
@@ -60,6 +60,41 @@ module NexClient
60
60
  pv_key_file.unlink # delete tmp file
61
61
  end
62
62
  end
63
+
64
+ # Parse plain or yaml file
65
+ def vars_from_file(file,prefix = nil,&block)
66
+ # YAML file
67
+ if file =~ /(\.yml|\.yaml)$/
68
+ vars_from_yaml_file(file,prefix,&block)
69
+ else
70
+ vars_from_plain_file(file,prefix,&block)
71
+ end
72
+ end
73
+
74
+ # Accept a path to a file or a hash
75
+ def vars_from_yaml_file(file,prefix = nil,&block)
76
+ vars = file.is_a?(Hash) ? file : YAML.load_file(file)
77
+
78
+ vars.each do |k,v|
79
+ key = prefix.present? ? "#{prefix}_#{k}" : k
80
+ if v.is_a?(Hash)
81
+ self.vars_from_yaml_file(v,key,&block)
82
+ else
83
+ yield(key,v)
84
+ end
85
+ end
86
+ end
87
+
88
+ def vars_from_plain_file(file,prefix = nil,&block)
89
+ f = File.read(file)
90
+ f.split("\n").each do |e|
91
+ line = e.strip
92
+ next if line.empty? || line.start_with?('#')
93
+ key,val = e.split('=',2)
94
+ key = prefix.present? ? "#{prefix}_#{key}" : key
95
+ yield(key,val)
96
+ end
97
+ end
63
98
  end
64
99
  end
65
100
  end
@@ -1,3 +1,3 @@
1
1
  module NexClient
2
- VERSION = '0.10.0'
2
+ VERSION ||= '0.11.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nex_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arnaud Lachaume
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-28 00:00:00.000000000 Z
11
+ date: 2016-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json_api_client