nex_client 0.14.0 → 0.15.0.pre1

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: b85a0da3bcdc2e97be481dea0a1d82c6734cfe55
4
- data.tar.gz: 226353cfb77a81de88917aa5004bc599499afd2b
3
+ metadata.gz: e6596e2a8eccfe2e5d1a0054ecf642bca67d6d56
4
+ data.tar.gz: bbf86956bcc6faac34a728b6db4278de2d93b213
5
5
  SHA512:
6
- metadata.gz: 0c97820ae8892d92b7dc605bf828998de377cb1b1dcf6c8f7e1c2ab0ddd6bc159d4d76821d58b74087e4b3e752909c18531b840303d8ec47896be036124853a7
7
- data.tar.gz: 0b0164bbbb7683305afeb91f4db7f3a2c19bf33cace71c159d7a1f7c9d1fc9ead289d4be8826fa94793b48fa54c2373f372bab0485768782ef03b93aa743328d
6
+ metadata.gz: 5e868e2ddcd3176f509aacfd58902ca31273ba97c998603242fff6875eff33d234abb4f177e93aeeefe2f574035023631c42ab2aa7b71aaa6b0e7638a6545775
7
+ data.tar.gz: 079862bc6e1112454e209b589fdb4ae167e5658bd381656a8e2551d644a531b84ad83aab4ce4c4c2e3ddb7bc8f465423011d8f89a5de48c7ecf59b8702d003a7
data/README.md CHANGED
@@ -24,9 +24,13 @@ gem update nex_client
24
24
 
25
25
  Configure your environment and get started with the tool
26
26
  ```bash
27
- # Set authentication and environment
28
- export NEX_API_KEY=my-nex-key
27
+ # Setup environment
29
28
  export NEX_ENV=<development|uat|production> # optional - defaulting to 'uat' at the moment
29
+ # OR
30
+ export NEX_ENDPOINT=https://api.somenexhost.com
31
+
32
+ # Set authentication
33
+ export NEX_API_KEY=my-nex-key
30
34
 
31
35
  # Display all available commands
32
36
  nex-cli --help
data/lib/nex_client.rb CHANGED
@@ -11,6 +11,7 @@ module NexClient
11
11
  autoload :CubeInstance, 'nex_client/cube_instance'
12
12
  autoload :CubeTemplate, 'nex_client/cube_template'
13
13
  autoload :Domain, 'nex_client/domain'
14
+ autoload :Event, 'nex_client/event'
14
15
  autoload :GatewayRack, 'nex_client/gateway_rack'
15
16
  autoload :Me, 'nex_client/me'
16
17
  autoload :Organization, 'nex_client/organization'
@@ -65,6 +65,19 @@ module NexClient
65
65
  end
66
66
  end
67
67
 
68
+ command :'addons:events' do |c|
69
+ c.syntax = 'nex-cli addons:events APP_NAME [options]'
70
+ c.summary = 'Gather system events'
71
+ c.description = 'Gather system events for a given addon'
72
+ c.example 'display events for myaddon', 'nex-cli addons:events myaddon'
73
+ c.example 'display 100 events for myaddon', 'nex-cli addons:events --tail 100 myaddon'
74
+ c.option '--tail NUMBER', String, 'number of events to retrieve (default: 50)'
75
+ c.option '--type TYPE', String, 'filter events on type (e.g. status, container)'
76
+ c.action do |args, options|
77
+ NexClient::Commands::Addons.events(args,options)
78
+ end
79
+ end
80
+
68
81
  command :'addons:info' do |c|
69
82
  c.syntax = 'nex-cli addons:info ADDON_NAME [options]'
70
83
  c.summary = 'Show information about an addon'
@@ -134,7 +147,7 @@ module NexClient
134
147
  c.option '--status <active|terminated>', String, 'list all apps in a given status'
135
148
  c.option '--ssl', 'list all apps with SSL enabled'
136
149
  c.option '--storage', 'list all apps with persistent storage'
137
- c.option '--owner HANDLE', 'list all apps for the specified owner'
150
+ c.option '--owner HANDLE', 'list all apps for the specified owner. Use "@self" to display your apps including any organization you are part of'
138
151
  c.option '--image IMAGE', 'list the app with this image'
139
152
  c.option '--tags TAG_LIST', Array, 'comma separated list of tags to filter on'
140
153
  c.action do |args, options|
@@ -184,6 +197,19 @@ module NexClient
184
197
  end
185
198
  end
186
199
 
200
+ command :'apps:events' do |c|
201
+ c.syntax = 'nex-cli apps:events APP_NAME [options]'
202
+ c.summary = 'Gather system events'
203
+ c.description = 'Gather system events for a given app'
204
+ c.example 'display events for myapp', 'nex-cli apps:events myapp'
205
+ c.example 'display 100 events for myapp', 'nex-cli apps:events --tail 100 myapp'
206
+ c.option '--tail NUMBER', String, 'number of events to retrieve (default: 50)'
207
+ c.option '--type TYPE', String, 'filter events on type (e.g. status, container)'
208
+ c.action do |args, options|
209
+ NexClient::Commands::Apps.events(args,options)
210
+ end
211
+ end
212
+
187
213
  command :'apps:info' do |c|
188
214
  c.syntax = 'nex-cli apps:info APP_NAME [options]'
189
215
  c.summary = 'Show information about an app'
@@ -336,8 +362,8 @@ module NexClient
336
362
  c.syntax = 'nex-cli cubes [options]'
337
363
  c.summary = 'Manage cubes [platform admin]'
338
364
  c.description = 'List, create, manage, scale and delete cubes'
339
- c.example 'list all running cubes', 'nex-cli cubes'
340
- c.example 'list all running cubes for owner myorg', 'nex-cli cubes --owner myorg'
365
+ c.example 'list all cubes', 'nex-cli cubes'
366
+ c.example 'list all cubes for owner myorg', 'nex-cli cubes --owner myorg'
341
367
  c.example 'list all terminated cubes', 'nex-cli cubes --status terminated'
342
368
  c.example 'list all terminated cubes for owner myorg', 'nex-cli cubes --status terminated --owner myorg'
343
369
  c.example 'list cube xyz.domain.co', 'nex-cli cubes --name xyz.domain.co'
@@ -356,6 +382,31 @@ module NexClient
356
382
  end
357
383
  end
358
384
 
385
+ command :'cubes:events' do |c|
386
+ c.syntax = 'nex-cli cubes:events APP_NAME [options]'
387
+ c.summary = 'Gather system events'
388
+ c.description = 'Gather system events for a given cube'
389
+ c.example 'display events for mycube', 'nex-cli cubes:events mycube'
390
+ c.example 'display 100 events for mycube', 'nex-cli cubes:events --tail 100 mycube'
391
+ c.option '--tail NUMBER', String, 'number of events to retrieve (default: 50)'
392
+ c.option '--type TYPE', String, 'filter events on type (e.g. status, container)'
393
+ c.action do |args, options|
394
+ NexClient::Commands::CubeInstances.events(args,options)
395
+ end
396
+ end
397
+
398
+ command :'cubes:logs' do |c|
399
+ c.syntax = 'nex-cli cubes:logs APP_NAME [options]'
400
+ c.summary = 'Gather cube logs'
401
+ c.description = 'Gather container logs for a given cube'
402
+ c.example 'gather logs for mycube', 'nex-cli cubes:logs mycube'
403
+ c.example 'gather logs for mycube with a tail of 50', 'nex-cli cubes:logs --tail 50 mycube'
404
+ c.option '--tail NUMBER', String, 'number of lines to retrieve (default: 30)'
405
+ c.action do |args, options|
406
+ NexClient::Commands::CubeInstances.logs(args,options)
407
+ end
408
+ end
409
+
359
410
  command :'cubes:restart' do |c|
360
411
  c.syntax = 'nex-cli cubes:restart CUBE_ID'
361
412
  c.summary = 'Restart a cube'
@@ -24,7 +24,7 @@ module NexClient
24
24
  filters[:status] = opts.status || ['active','restarting']
25
25
  filters[:ssl_enabled] = opts.ssl if opts.ssl.present?
26
26
  filters[:persistent_storage] = opts.storage if opts.storage.present?
27
- filters[:'owner.handle'] = opts.owner || '@self'
27
+ filters[:'owner.handle'] = opts.owner if opts.owner.present?
28
28
  filters[:image] = opts.image if opts.image.present?
29
29
  filters[:tags] = opts.tags if opts.tags.present?
30
30
 
@@ -78,6 +78,7 @@ module NexClient
78
78
  Addons.display_addons(e.addons.select { |a| a.status == 'active'})
79
79
  end
80
80
 
81
+ # Retrieve application logs from all containers
81
82
  def self.logs(args,opts)
82
83
  name = args.first
83
84
  e = NexClient::App.find(name: name).first
@@ -5,11 +5,11 @@ module NexClient
5
5
  extend Helpers
6
6
 
7
7
  CUBES_TITLE = "Cube Instances".colorize(:blue)
8
- CUBES_HEADERS = ['id','status','region','ssl','storage','SOA','ip','port','dns','cluster'].map(&:upcase)
8
+ CUBES_HEADERS = ['id','status','container','region','storage','ip','port','cluster'].map(&:upcase)
9
9
 
10
10
  def self.list(args,opts)
11
11
  filters = {}
12
- filters[:status] = opts.status || 'running'
12
+ filters[:status] = opts.status if opts.status.present?
13
13
  filters[:soa_enabled] = opts.soa if opts.soa.present?
14
14
  filters[:ssl_enabled] = opts.ssl if opts.ssl.present?
15
15
  filters[:persistent_storage] = opts.storage if opts.storage.present?
@@ -34,6 +34,22 @@ module NexClient
34
34
  end
35
35
  end
36
36
 
37
+ # Retrieve application logs from all containers
38
+ def self.logs(args,opts)
39
+ name = args.first
40
+ e = NexClient::CubeInstance.find(uuid: name).first
41
+
42
+ # Display error
43
+ unless e
44
+ error("Error! Could not find cube: #{name}")
45
+ return false
46
+ end
47
+
48
+ # Retrieve logs and display them
49
+ logs = e.logs(tail: opts.tail).first
50
+ self.display_logs(logs.log_ret)
51
+ end
52
+
37
53
  def self.trigger_action(action,args,opts)
38
54
  id = args.first
39
55
  e = NexClient::CubeInstance.find(uuid: id).first
@@ -87,13 +103,11 @@ module NexClient
87
103
  [
88
104
  record.uuid,
89
105
  record.status,
106
+ record.container_status,
90
107
  record.region,
91
- record.ssl_enabled,
92
108
  record.persistent_storage,
93
- record.soa_enabled,
94
109
  record.ip_address || '-',
95
110
  record.port || '-',
96
- dns,
97
111
  cluster
98
112
  ]
99
113
  end
@@ -106,6 +120,11 @@ module NexClient
106
120
  return '-' unless o = record.cluster
107
121
  "#{o.type.singularize}:#{o.name}"
108
122
  end
123
+
124
+ def self.display_logs(logs)
125
+ puts logs
126
+ puts "\n"
127
+ end
109
128
  end
110
129
  end
111
130
  end
@@ -31,6 +31,24 @@ module NexClient
31
31
  puts "\n"
32
32
  end
33
33
 
34
+ # Retrieve resource events
35
+ def events(args,opts)
36
+ filters = {}
37
+ filters[:'source.name'] = args.first
38
+ filters[:event] = opts.type if opts.type
39
+
40
+ events = NexClient::Event.paginate(per_page: opts.tail || 50).where(filters).order(created_at: :desc)
41
+ self.display_events(events.to_a)
42
+ end
43
+
44
+ # Display a list of events
45
+ def display_events(events)
46
+ events.sort_by { |e| e.id }.each do |e|
47
+ puts [e.created_at,e.event.ljust(12,' '),e.level.ljust(6,' '),e.message].join(" | ")
48
+ end
49
+ puts "\n"
50
+ end
51
+
34
52
  # Perform an SSH command based on a template
35
53
  # Fetch current user key and username
36
54
  def perform_ssh_cmd(ssh_cmd_template)
@@ -9,13 +9,16 @@ module NexClient
9
9
  property :persistent_storage, type: :boolean
10
10
  property :port, type: :int
11
11
 
12
- # PATCH <api_root>/apps/:id/restart
12
+ # GET <api_root>/cube_instances/:id/logs
13
+ custom_endpoint :logs, on: :member, request_method: :get
14
+
15
+ # PATCH <api_root>/cube_instances/:id/restart
13
16
  custom_endpoint :restart, on: :member, request_method: :patch
14
17
 
15
- # PATCH <api_root>/apps/:id/start
18
+ # PATCH <api_root>/cube_instances/:id/start
16
19
  custom_endpoint :start, on: :member, request_method: :patch
17
20
 
18
- # PATCH <api_root>/apps/:id/stop
21
+ # PATCH <api_root>/cube_instances/:id/stop
19
22
  custom_endpoint :stop, on: :member, request_method: :patch
20
23
  end
21
24
  end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+ module NexClient
3
+ class Event < BaseResource
4
+ property :created_at, type: :time
5
+ property :updated_at, type: :time
6
+ end
7
+ end
@@ -1,3 +1,3 @@
1
1
  module NexClient
2
- VERSION ||= '0.14.0'
2
+ VERSION ||= '0.15.0.pre1'
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.14.0
4
+ version: 0.15.0.pre1
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-10-10 00:00:00.000000000 Z
11
+ date: 2016-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json_api_client
@@ -139,6 +139,7 @@ files:
139
139
  - lib/nex_client/cube_instance.rb
140
140
  - lib/nex_client/cube_template.rb
141
141
  - lib/nex_client/domain.rb
142
+ - lib/nex_client/event.rb
142
143
  - lib/nex_client/gateway_rack.rb
143
144
  - lib/nex_client/me.rb
144
145
  - lib/nex_client/organization.rb
@@ -166,9 +167,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
166
167
  version: '0'
167
168
  required_rubygems_version: !ruby/object:Gem::Requirement
168
169
  requirements:
169
- - - ">="
170
+ - - ">"
170
171
  - !ruby/object:Gem::Version
171
- version: '0'
172
+ version: 1.3.1
172
173
  requirements: []
173
174
  rubyforge_project:
174
175
  rubygems_version: 2.5.1