nex_client 0.7.0 → 0.8.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: 98eeac822300b75e82e9d06c1f0f28f43b388442
4
- data.tar.gz: 5083a27ba0b31ec42f42459be7135c453ebc737e
3
+ metadata.gz: e7e474dbd2d706429e88588528a051b2a6ad13b9
4
+ data.tar.gz: 752ea05fe2035617a3109c9f40561f608c22b358
5
5
  SHA512:
6
- metadata.gz: ef9341d6e6d4e1b43ffbf2feb83843ee961997636e2d2568ce3bd24ac92b9c22c35bb004866f4f0d9139d952b91d7648869e760ff78510911f423667ad919425
7
- data.tar.gz: b19f819f976eeabdd559b2fcea4efde5acc5877161d969cf3582dbb603b7a77583fd968747508572e107edbcbf3f0caa3949a0d15bf529a9de7c36ab084a04da
6
+ metadata.gz: ddb0bde5e0b11d5638d11813c6e09f88fd8a57821ab1a2c1e1eb2c6aef91f56274b676f70ad62552344a662b4fd907c8f576c6bab2a5450395efa8e75da9d556
7
+ data.tar.gz: 61194baa999f2fdf7cedbb34b981f8bc0bbc28369ec534e7eff9a0f0f02d511f34f0bb05e5ea0a2f97d993a65d61ab3edec90dab7e579267cb4ee445f0785061
@@ -4,7 +4,16 @@ module NexClient
4
4
  property :created_at, type: :time
5
5
  property :updated_at, type: :time
6
6
 
7
- # GET <api_root>/apps/:id/logs
7
+ # PATCH <api_root>/addons/:id/restart
8
+ custom_endpoint :restart, on: :member, request_method: :patch
9
+
10
+ # GET <api_root>/addons/:id/logs
8
11
  custom_endpoint :logs, on: :member, request_method: :get
12
+
13
+ # PATCH <api_root>/addons/:id/scale_up
14
+ custom_endpoint :scale_up, on: :member, request_method: :patch
15
+
16
+ # PATCH <api_root>/addons/:id/scale_down
17
+ custom_endpoint :scale_down, on: :member, request_method: :patch
9
18
  end
10
19
  end
@@ -33,7 +33,7 @@ module NexClient
33
33
  command :'addons:create' do |c|
34
34
  c.syntax = 'nex-cli addons:create SERVICE APP_NAME'
35
35
  c.summary = 'Create addons'
36
- c.description = 'Create addons for your apps'
36
+ c.description = 'Create addons for your apps. Available addons: mysql | redis | mongo26'
37
37
  c.example 'create mysql addon for myapp', 'nex-cli addons:create mysql myapp'
38
38
  c.example 'create redis addon for myapp', 'nex-cli addons:create redis myapp'
39
39
  c.action do |args, options|
@@ -51,6 +51,18 @@ module NexClient
51
51
  end
52
52
  end
53
53
 
54
+ command :'addons:down' do |c|
55
+ c.syntax = 'nex-cli addons:down ADDON_NAME [options]'
56
+ c.summary = 'Scale addons down'
57
+ c.description = 'Bring nodes down for a given addon'
58
+ c.example 'scale myaddon down by removing one node', 'nex-cli addons:down myaddon'
59
+ c.example 'scale myaddon down by removing two nodes', 'nex-cli addons:down myaddon --count 2'
60
+ c.option '--count NUMBER', String, 'number of nodes to bring down'
61
+ c.action do |args, options|
62
+ NexClient::Commands::Addons.scale(:down,args,options)
63
+ end
64
+ end
65
+
54
66
  command :'addons:logs' do |c|
55
67
  c.syntax = 'nex-cli addons:logs ADDON_NAME [options]'
56
68
  c.summary = 'Gather addon logs'
@@ -73,6 +85,18 @@ module NexClient
73
85
  end
74
86
  end
75
87
 
88
+ command :'addons:up' do |c|
89
+ c.syntax = 'nex-cli addons:up ADDON_NAME [options]'
90
+ c.summary = 'Scale addons up'
91
+ c.description = 'Add nodes to a given addon'
92
+ c.example 'scale myaddon up by adding one node', 'nex-cli addons:up myaddon'
93
+ c.example 'scale myaddon up by adding two nodes', 'nex-cli addons:up myaddon --count 2'
94
+ c.option '--count NUMBER', String, 'number of nodes to bring up'
95
+ c.action do |args, options|
96
+ NexClient::Commands::Addons.scale(:up,args,options)
97
+ end
98
+ end
99
+
76
100
  command :apps do |c|
77
101
  c.syntax = 'nex-cli apps [options]'
78
102
  c.summary = 'Manage apps'
@@ -4,8 +4,9 @@ module NexClient
4
4
  module Addons
5
5
  extend Helpers
6
6
 
7
+ SCALING_DIRECTIONS = [:up,:down]
7
8
  ADDONS_TITLE = "Addons".colorize(:red)
8
- ADDONS_HEADERS = ['id','name','status','service','app'].map(&:upcase)
9
+ ADDONS_HEADERS = ['id','name','status','service','nodes','app'].map(&:upcase)
9
10
 
10
11
  def self.list(args,opts)
11
12
  filters = {}
@@ -105,6 +106,35 @@ module NexClient
105
106
  success("Successfully destroyed addon: #{name}")
106
107
  end
107
108
 
109
+ def self.scale(direction,args,opts)
110
+ return false unless SCALING_DIRECTIONS.include?(direction.to_sym)
111
+ name = args.first
112
+ e = NexClient::Addon.find(name: name).first
113
+
114
+ # Display error
115
+ unless e
116
+ error("Error! Could not find addon: #{name}")
117
+ return false
118
+ end
119
+
120
+ # Scaling attributes
121
+ attrs = {}
122
+ count = opts.count || 1
123
+ attrs[:count] = count
124
+ attrs[:preferred_region] = opts.region if opts.region.present?
125
+
126
+ # Perform
127
+ e.send("scale_#{direction}",{data: { attributes: attrs } })
128
+
129
+ # Display errors if any
130
+ if e.errors.any?
131
+ display_record_errors(e)
132
+ return false
133
+ end
134
+
135
+ success("Successfully requested to scale #{name} #{direction} by #{count} #{'node'.pluralize(count)}...")
136
+ end
137
+
108
138
  def self.display_addons(list)
109
139
  table = Terminal::Table.new title: ADDONS_TITLE, headings: ADDONS_HEADERS do |t|
110
140
  [list].flatten.compact.each do |e|
@@ -117,11 +147,13 @@ module NexClient
117
147
 
118
148
  def self.format_record(record)
119
149
  app = self.format_app(record)
150
+ node_count = self.format_node_count(record)
120
151
  [
121
152
  record.id,
122
153
  record.name,
123
154
  record.status,
124
155
  record.service,
156
+ node_count,
125
157
  app
126
158
  ]
127
159
  end
@@ -130,6 +162,11 @@ module NexClient
130
162
  return '-' unless a = record.app
131
163
  a.name
132
164
  end
165
+
166
+ def self.format_node_count(record)
167
+ return '-' unless record.node_count && record.max_node_count
168
+ "#{record.node_count}/#{record.max_node_count}"
169
+ end
133
170
  end
134
171
  end
135
172
  end
@@ -1,3 +1,3 @@
1
1
  module NexClient
2
- VERSION = '0.7.0'
2
+ VERSION = '0.8.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.7.0
4
+ version: 0.8.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-22 00:00:00.000000000 Z
11
+ date: 2016-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json_api_client