nex_client 0.6.0 → 0.7.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: 03c927e21aeea01504d624b3ccf9b33a73e206d7
4
- data.tar.gz: 57a595c1175ff1e51ac26444802266d6a02a57f7
3
+ metadata.gz: 98eeac822300b75e82e9d06c1f0f28f43b388442
4
+ data.tar.gz: 5083a27ba0b31ec42f42459be7135c453ebc737e
5
5
  SHA512:
6
- metadata.gz: b6b1cc1026c4ee4e250084584724db87156fbe321f88da0808d1eccc1055f939b1ba6001e0f5c1e2159f773d881831e9c4373afc87e678dcfcb31c1a1eb62a63
7
- data.tar.gz: 53820cb2245d5a5613e65ed6d901dd84d802f37660dbaf119707cee58d5360467e5082e34f9dcef6b784447ba3b3c55c95a8dc8a19b93f70ee1d6e0ae8d323cf
6
+ metadata.gz: ef9341d6e6d4e1b43ffbf2feb83843ee961997636e2d2568ce3bd24ac92b9c22c35bb004866f4f0d9139d952b91d7648869e760ff78510911f423667ad919425
7
+ data.tar.gz: b19f819f976eeabdd559b2fcea4efde5acc5877161d969cf3582dbb603b7a77583fd968747508572e107edbcbf3f0caa3949a0d15bf529a9de7c36ab084a04da
@@ -52,7 +52,7 @@ module NexClient
52
52
  end
53
53
 
54
54
  command :'addons:logs' do |c|
55
- c.syntax = 'nex-cli addons:logs APP_NAME [options]'
55
+ c.syntax = 'nex-cli addons:logs ADDON_NAME [options]'
56
56
  c.summary = 'Gather addon logs'
57
57
  c.description = 'Gather container logs for a given addon'
58
58
  c.example 'gather logs for myaddon', 'nex-cli addons:logs myaddon'
@@ -63,6 +63,16 @@ module NexClient
63
63
  end
64
64
  end
65
65
 
66
+ command :'addons:ssh' do |c|
67
+ c.syntax = 'nex-cli addons:ssh ADDON_NAME [options]'
68
+ c.summary = 'SSH to an addon container [platform admin]'
69
+ c.description = 'Initiate an SSH session to a given addon container'
70
+ c.example 'ssh to addon myaddon', 'nex-cli addons:ssh myaddon'
71
+ c.action do |args, options|
72
+ NexClient::Commands::Addons.ssh(args,options)
73
+ end
74
+ end
75
+
66
76
  command :apps do |c|
67
77
  c.syntax = 'nex-cli apps [options]'
68
78
  c.summary = 'Manage apps'
@@ -163,6 +173,16 @@ module NexClient
163
173
  end
164
174
  end
165
175
 
176
+ command :'apps:ssh' do |c|
177
+ c.syntax = 'nex-cli apps:ssh APP_NAME [options]'
178
+ c.summary = 'SSH to an app container [platform admin]'
179
+ c.description = 'Initiate an SSH session to a given app container'
180
+ c.example 'ssh to app myapp', 'nex-cli apps:ssh myapp'
181
+ c.action do |args, options|
182
+ NexClient::Commands::Apps.ssh(args,options)
183
+ end
184
+ end
185
+
166
186
  command :'apps:transfer' do |c|
167
187
  c.syntax = 'nex-cli apps:transfer APP_NAME OWNER_HANDLE [options]'
168
188
  c.summary = 'Transfer app ownership'
@@ -224,7 +244,7 @@ module NexClient
224
244
  end
225
245
 
226
246
  command :'cubes:restart' do |c|
227
- c.syntax = 'nex-cli cubes:restart CUBE_NAME'
247
+ c.syntax = 'nex-cli cubes:restart CUBE_ID'
228
248
  c.summary = 'Restart a cube'
229
249
  c.description = 'Restart a cube'
230
250
  c.example 'restart cube xyz', 'nex-cli cubes:restart xyz'
@@ -234,7 +254,7 @@ module NexClient
234
254
  end
235
255
 
236
256
  command :'cubes:start' do |c|
237
- c.syntax = 'nex-cli cubes:start CUBE_NAME'
257
+ c.syntax = 'nex-cli cubes:start CUBE_ID'
238
258
  c.summary = 'Start a cube'
239
259
  c.description = 'Start a cube'
240
260
  c.example 'start cube xyz', 'nex-cli cubes:start xyz'
@@ -244,7 +264,7 @@ module NexClient
244
264
  end
245
265
 
246
266
  command :'cubes:stop' do |c|
247
- c.syntax = 'nex-cli cubes:stop CUBE_NAME'
267
+ c.syntax = 'nex-cli cubes:stop CUBE_ID'
248
268
  c.summary = 'Stop a cube'
249
269
  c.description = 'Stop a cube'
250
270
  c.example 'stop cube xyz', 'nex-cli cubes:stop xyz'
@@ -253,6 +273,16 @@ module NexClient
253
273
  end
254
274
  end
255
275
 
276
+ command :'cubes:ssh' do |c|
277
+ c.syntax = 'nex-cli cubes:ssh APP_NAME [options]'
278
+ c.summary = 'SSH to a specific container [platform admin]'
279
+ c.description = 'Initiate an SSH session to a given container'
280
+ c.example 'ssh to cube some-uuid', 'nex-cli cubes:ssh some-uuid'
281
+ c.action do |args, options|
282
+ NexClient::Commands::CubeInstances.ssh(args,options)
283
+ end
284
+ end
285
+
256
286
  command :cube_templates do |c|
257
287
  c.syntax = 'nex-cli cube_templates [options]'
258
288
  c.summary = 'Manage cube_templates [platform admin][legacy]'
@@ -24,7 +24,7 @@ module NexClient
24
24
 
25
25
  # Loop through results
26
26
  while (list.pages.links||{})['next']
27
- ask("Press enter for next page")
27
+ return true if ask("Press enter for next page ('q' to quit)") =~ /q/
28
28
  list = list.pages.next
29
29
  self.display_addons(list)
30
30
  end
@@ -45,6 +45,21 @@ module NexClient
45
45
  self.display_logs(logs.log_ret)
46
46
  end
47
47
 
48
+ # SSH to the addon
49
+ def self.ssh(args,opts)
50
+ name = args.first
51
+ e = NexClient::Addon.find(name: name).first
52
+
53
+ # Display error
54
+ unless e
55
+ error("Error! Could not find addon: #{name}")
56
+ return false
57
+ end
58
+
59
+ # Perform command
60
+ perform_ssh_cmd(e.ssh_cmd_template)
61
+ end
62
+
48
63
  def self.create(args,opts)
49
64
  svc_name,app_name = args
50
65
  app = NexClient::App.find(name: app_name).first
@@ -31,7 +31,7 @@ module NexClient
31
31
 
32
32
  # Loop through results
33
33
  while (list.pages.links||{})['next']
34
- ask("Press enter for next page")
34
+ return true if ask("Press enter for next page ('q' to quit)") =~ /q/
35
35
  list = list.pages.next
36
36
  self.display_apps(list)
37
37
  end
@@ -75,6 +75,21 @@ module NexClient
75
75
  self.display_logs(logs.log_ret)
76
76
  end
77
77
 
78
+ # SSH to the app
79
+ def self.ssh(args,opts)
80
+ name = args.first
81
+ e = NexClient::App.find(name: name).first
82
+
83
+ # Display error
84
+ unless e
85
+ error("Error! Could not find app: #{name}")
86
+ return false
87
+ end
88
+
89
+ # Perform command
90
+ perform_ssh_cmd(e.ssh_cmd_template)
91
+ end
92
+
78
93
  def self.create(args,opts)
79
94
  image_info = args.first.split(':')
80
95
  attrs = { image: image_info[0], image_tag: image_info[1] }
@@ -28,19 +28,19 @@ module NexClient
28
28
 
29
29
  # Loop through results
30
30
  while (list.pages.links||{})['next']
31
- ask("Press enter for next page")
31
+ return true if ask("Press enter for next page ('q' to quit)") =~ /q/
32
32
  list = list.pages.next
33
33
  self.display_cubes(list)
34
34
  end
35
35
  end
36
36
 
37
37
  def self.trigger_action(action,args,opts)
38
- name = args.first
39
- e = NexClient::CubeInstance.find(name: name).first
38
+ id = args.first
39
+ e = NexClient::CubeInstance.find(uuid: id).first
40
40
 
41
41
  # Display error
42
42
  unless e
43
- error("Error! Could not find cube: #{name}")
43
+ error("Error! Could not find cube: #{id}")
44
44
  return false
45
45
  end
46
46
 
@@ -53,7 +53,22 @@ module NexClient
53
53
  return false
54
54
  end
55
55
 
56
- success("Initiated #{action} for cube #{name}...")
56
+ success("Initiated #{action} for cube #{id}...")
57
+ end
58
+
59
+ # SSH to the addon
60
+ def self.ssh(args,opts)
61
+ id = args.first
62
+ e = NexClient::CubeInstance.find(uuid: id).first
63
+
64
+ # Display error
65
+ unless e
66
+ error("Error! Could not find cube: #{id}")
67
+ return false
68
+ end
69
+
70
+ # Perform command
71
+ perform_ssh_cmd(e.ssh_cmd_template)
57
72
  end
58
73
 
59
74
  def self.display_cubes(list)
@@ -70,7 +85,7 @@ module NexClient
70
85
  dns = self.format_dns(record)
71
86
  cluster = self.format_cluster(record)
72
87
  [
73
- record.id,
88
+ record.uuid,
74
89
  record.status,
75
90
  record.region,
76
91
  record.ssl_enabled,
@@ -19,7 +19,7 @@ module NexClient
19
19
 
20
20
  # Loop through results
21
21
  while (list.pages.links||{})['next']
22
- ask("Press enter for next page")
22
+ return true if ask("Press enter for next page ('q' to quit)") =~ /q/
23
23
  list = list.pages.next
24
24
  self.display_templates(list)
25
25
  end
@@ -17,7 +17,7 @@ module NexClient
17
17
 
18
18
  # Loop through results
19
19
  while (list.pages.links||{})['next']
20
- ask("Press enter for next page")
20
+ return true if ask("Press enter for next page ('q' to quit)") =~ /q/
21
21
  list = list.pages.next
22
22
  self.display_domains(list)
23
23
  end
@@ -30,6 +30,36 @@ module NexClient
30
30
  end
31
31
  puts "\n"
32
32
  end
33
+
34
+ # Perform an SSH command based on a template
35
+ # Fetch current user key and username
36
+ def perform_ssh_cmd(ssh_cmd_template)
37
+ # Fetch user
38
+ me = NexClient::Me.find.first
39
+ if me.api_only
40
+ error("Error! Cannot SSH with an api-only user")
41
+ return false
42
+ end
43
+
44
+ # Get SSH details
45
+ username = me.handle
46
+ pv_key = me.private_key
47
+
48
+ # Create SSH Key
49
+ pv_key_file = Tempfile.new('nex.sshkey')
50
+ pv_key_file.write(pv_key)
51
+ pv_key_file.close
52
+
53
+ # Format command
54
+ ssh_cmd = ssh_cmd_template.gsub("{{certfile}}",pv_key_file.path).gsub("{{username}}",username)
55
+
56
+ # Launch SSH session
57
+ begin
58
+ system(ssh_cmd)
59
+ ensure
60
+ pv_key_file.unlink # delete tmp file
61
+ end
62
+ end
33
63
  end
34
64
  end
35
65
  end
@@ -14,7 +14,7 @@ module NexClient
14
14
 
15
15
  # Loop through results
16
16
  while (list.pages.links||{})['next']
17
- ask("Press enter for next page")
17
+ return true if ask("Press enter for next page ('q' to quit)") =~ /q/
18
18
  list = list.pages.next
19
19
  self.display_organizations(list)
20
20
  end
@@ -37,7 +37,7 @@ module NexClient
37
37
 
38
38
  # Loop through results
39
39
  while (list.pages.links||{})['next']
40
- ask("Press enter for next page")
40
+ return true if ask("Press enter for next page ('q' to quit)") =~ /q/
41
41
  list = list.pages.next
42
42
  self.display_compute_racks(list)
43
43
  end
@@ -49,7 +49,7 @@ module NexClient
49
49
 
50
50
  # Loop through results
51
51
  while (list.pages.links||{})['next']
52
- ask("Press enter for next page")
52
+ return true if ask("Press enter for next page ('q' to quit)") =~ /q/
53
53
  list = list.pages.next
54
54
  self.display_storage_racks(list)
55
55
  end
@@ -61,7 +61,7 @@ module NexClient
61
61
 
62
62
  # Loop through results
63
63
  while (list.pages.links||{})['next']
64
- ask("Press enter for next page")
64
+ return true if ask("Press enter for next page ('q' to quit)") =~ /q/
65
65
  list = list.pages.next
66
66
  self.display_routing_racks(list)
67
67
  end
@@ -73,7 +73,7 @@ module NexClient
73
73
 
74
74
  # Loop through results
75
75
  while (list.pages.links||{})['next']
76
- ask("Press enter for next page")
76
+ return true if ask("Press enter for next page ('q' to quit)") =~ /q/
77
77
  list = list.pages.next
78
78
  self.display_gateway_racks(list)
79
79
  end
@@ -100,31 +100,8 @@ module NexClient
100
100
  return false
101
101
  end
102
102
 
103
- # Fetch user
104
- me = NexClient::Me.find.first
105
- if me.api_only
106
- error("Error! Cannot SSH with an api-only user")
107
- return false
108
- end
109
-
110
- # Get SSH details
111
- username = me.handle
112
- pv_key = me.private_key
113
-
114
- # Create SSH Key
115
- pv_key_file = Tempfile.new('nex.sshkey')
116
- pv_key_file.write(pv_key)
117
- pv_key_file.close
118
-
119
- # Format command
120
- ssh_cmd = rack.ssh_cmd_template.gsub("{{certfile}}",pv_key_file.path).gsub("{{username}}",username)
121
-
122
- # Launch SSH session
123
- begin
124
- system(ssh_cmd)
125
- ensure
126
- pv_key_file.unlink # delete tmp file
127
- end
103
+ # Perform command
104
+ perform_ssh_cmd(rack.ssh_cmd_template)
128
105
  end
129
106
 
130
107
  def self.display_compute_racks(list)
@@ -17,7 +17,7 @@ module NexClient
17
17
 
18
18
  # Loop through results
19
19
  while (list.pages.links||{})['next']
20
- ask("Press enter for next page")
20
+ return true if ask("Press enter for next page ('q' to quit)") =~ /q/
21
21
  list = list.pages.next
22
22
  self.display_certs(list)
23
23
  end
@@ -21,7 +21,7 @@ module NexClient
21
21
 
22
22
  # Loop through results
23
23
  while (list.pages.links||{})['next']
24
- ask("Press enter for next page")
24
+ return true if ask("Press enter for next page ('q' to quit)") =~ /q/
25
25
  list = list.pages.next
26
26
  self.display_users(list)
27
27
  end
@@ -1,3 +1,3 @@
1
1
  module NexClient
2
- VERSION = '0.6.0'
2
+ VERSION = '0.7.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.6.0
4
+ version: 0.7.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-21 00:00:00.000000000 Z
11
+ date: 2016-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json_api_client