nex_client 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/nex_client.rb +1 -0
- data/lib/nex_client/cli.rb +10 -0
- data/lib/nex_client/commands/racks.rb +49 -0
- data/lib/nex_client/me.rb +14 -0
- data/lib/nex_client/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03c927e21aeea01504d624b3ccf9b33a73e206d7
|
4
|
+
data.tar.gz: 57a595c1175ff1e51ac26444802266d6a02a57f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b6b1cc1026c4ee4e250084584724db87156fbe321f88da0808d1eccc1055f939b1ba6001e0f5c1e2159f773d881831e9c4373afc87e678dcfcb31c1a1eb62a63
|
7
|
+
data.tar.gz: 53820cb2245d5a5613e65ed6d901dd84d802f37660dbaf119707cee58d5360467e5082e34f9dcef6b784447ba3b3c55c95a8dc8a19b93f70ee1d6e0ae8d323cf
|
data/lib/nex_client.rb
CHANGED
@@ -12,6 +12,7 @@ module NexClient
|
|
12
12
|
autoload :CubeTemplate, 'nex_client/cube_template'
|
13
13
|
autoload :Domain, 'nex_client/domain'
|
14
14
|
autoload :GatewayRack, 'nex_client/gateway_rack'
|
15
|
+
autoload :Me, 'nex_client/me'
|
15
16
|
autoload :Organization, 'nex_client/organization'
|
16
17
|
autoload :RoutingRack, 'nex_client/routing_rack'
|
17
18
|
autoload :SslCertificate, 'nex_client/ssl_certificate'
|
data/lib/nex_client/cli.rb
CHANGED
@@ -329,6 +329,16 @@ module NexClient
|
|
329
329
|
end
|
330
330
|
end
|
331
331
|
|
332
|
+
command :'racks:ssh' do |c|
|
333
|
+
c.syntax = 'nex-cli racks:ssh IP_ADDRESS [options]'
|
334
|
+
c.summary = 'SSH to racks [platform admin]'
|
335
|
+
c.description = 'Initiate an SSH session to a given rack'
|
336
|
+
c.example 'ssh to rack with ip 10.1.2.3', 'nex-cli racks:ssh 10.1.2.3'
|
337
|
+
c.action do |args, options|
|
338
|
+
NexClient::Commands::Racks.ssh(args,options)
|
339
|
+
end
|
340
|
+
end
|
341
|
+
|
332
342
|
command :certs do |c|
|
333
343
|
c.syntax = 'nex-cli certs [APP_NAME] [options]'
|
334
344
|
c.summary = 'Manage certs'
|
@@ -1,4 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
require 'tempfile'
|
3
|
+
|
2
4
|
module NexClient
|
3
5
|
module Commands
|
4
6
|
module Racks
|
@@ -78,6 +80,53 @@ module NexClient
|
|
78
80
|
end
|
79
81
|
end
|
80
82
|
|
83
|
+
def self.ssh(args,opts)
|
84
|
+
# Find server
|
85
|
+
id = args.first
|
86
|
+
rack = nil
|
87
|
+
[
|
88
|
+
NexClient::ComputeRack,
|
89
|
+
NexClient::GatewayRack,
|
90
|
+
NexClient::RoutingRack,
|
91
|
+
NexClient::StorageRack
|
92
|
+
].each do |server_type|
|
93
|
+
rack ||= server_type.where(private_ip_address: id).first ||
|
94
|
+
server_type.where(ip_address: id).first
|
95
|
+
end
|
96
|
+
|
97
|
+
# Display error
|
98
|
+
unless rack
|
99
|
+
error("Error! Could not find rack: #{id}")
|
100
|
+
return false
|
101
|
+
end
|
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
|
128
|
+
end
|
129
|
+
|
81
130
|
def self.display_compute_racks(list)
|
82
131
|
table = Terminal::Table.new title: COMPUTE_RACKS_TITLE, headings: RACKS_HEADERS do |t|
|
83
132
|
[list].flatten.compact.each do |e|
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module NexClient
|
3
|
+
class Me < BaseResource
|
4
|
+
property :created_at, type: :time
|
5
|
+
property :updated_at, type: :time
|
6
|
+
property :api_only, type: :boolean
|
7
|
+
|
8
|
+
# This is a singleton resource
|
9
|
+
def self.table_name
|
10
|
+
"me"
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
data/lib/nex_client/version.rb
CHANGED
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.
|
4
|
+
version: 0.6.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-
|
11
|
+
date: 2016-08-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json_api_client
|
@@ -140,6 +140,7 @@ files:
|
|
140
140
|
- lib/nex_client/cube_template.rb
|
141
141
|
- lib/nex_client/domain.rb
|
142
142
|
- lib/nex_client/gateway_rack.rb
|
143
|
+
- lib/nex_client/me.rb
|
143
144
|
- lib/nex_client/organization.rb
|
144
145
|
- lib/nex_client/resource_workflow.rb
|
145
146
|
- lib/nex_client/routing_rack.rb
|