kontena-cli 0.15.5 → 0.16.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (207) hide show
  1. checksums.yaml +4 -4
  2. data/Dockerfile +0 -3
  3. data/Gemfile +3 -0
  4. data/LOGO +8 -0
  5. data/VERSION +1 -1
  6. data/kontena-cli.gemspec +2 -3
  7. data/lib/kontena/callback.rb +57 -0
  8. data/lib/kontena/callbacks/.gitkeep +0 -0
  9. data/lib/kontena/callbacks/auth/01_list_and_select_grid_after_master_auth.rb +27 -0
  10. data/lib/kontena/callbacks/master/01_clear_current_master_after_terminate.rb +20 -0
  11. data/lib/kontena/callbacks/master/deploy/01_show_logo_before_deploy.rb +15 -0
  12. data/lib/kontena/callbacks/master/deploy/05_before_deploy_configuration_wizard.rb +124 -0
  13. data/lib/kontena/callbacks/master/deploy/50_authenticate_after_deploy.rb +53 -0
  14. data/lib/kontena/callbacks/master/deploy/55_create_initial_grid_after_deploy.rb +32 -0
  15. data/lib/kontena/callbacks/master/deploy/60_configure_auth_provider_after_deploy.rb +49 -0
  16. data/lib/kontena/callbacks/master/deploy/90_suggest_inviting_yourself_after_deploy.rb +24 -0
  17. data/lib/kontena/cli/app_command.rb +2 -1
  18. data/lib/kontena/cli/apps/build_command.rb +1 -1
  19. data/lib/kontena/cli/apps/common.rb +6 -1
  20. data/lib/kontena/cli/apps/config_command.rb +1 -1
  21. data/lib/kontena/cli/apps/deploy_command.rb +1 -1
  22. data/lib/kontena/cli/apps/init_command.rb +3 -5
  23. data/lib/kontena/cli/apps/list_command.rb +1 -1
  24. data/lib/kontena/cli/apps/logs_command.rb +1 -1
  25. data/lib/kontena/cli/apps/monitor_command.rb +1 -1
  26. data/lib/kontena/cli/apps/remove_command.rb +2 -3
  27. data/lib/kontena/cli/apps/restart_command.rb +1 -1
  28. data/lib/kontena/cli/apps/scale_command.rb +1 -1
  29. data/lib/kontena/cli/apps/show_command.rb +1 -1
  30. data/lib/kontena/cli/apps/start_command.rb +1 -1
  31. data/lib/kontena/cli/apps/stop_command.rb +1 -1
  32. data/lib/kontena/cli/apps/yaml/reader.rb +3 -13
  33. data/lib/kontena/cli/apps/yaml/validator.rb +0 -4
  34. data/lib/kontena/cli/apps/yaml/validator_v2.rb +1 -5
  35. data/lib/kontena/cli/certificate/authorize_command.rb +1 -1
  36. data/lib/kontena/cli/certificate/get_command.rb +1 -1
  37. data/lib/kontena/cli/certificate/register_command.rb +1 -1
  38. data/lib/kontena/cli/certificate_command.rb +1 -1
  39. data/lib/kontena/cli/cloud/login_command.rb +128 -0
  40. data/lib/kontena/cli/cloud/master/add_command.rb +54 -0
  41. data/lib/kontena/cli/cloud/master/delete_command.rb +20 -0
  42. data/lib/kontena/cli/cloud/master/list_command.rb +29 -0
  43. data/lib/kontena/cli/cloud/master/show_command.rb +23 -0
  44. data/lib/kontena/cli/cloud/master/update_command.rb +58 -0
  45. data/lib/kontena/cli/cloud/master_command.rb +21 -0
  46. data/lib/kontena/cli/cloud_command.rb +10 -0
  47. data/lib/kontena/cli/common.rb +230 -88
  48. data/lib/kontena/cli/config.rb +537 -0
  49. data/lib/kontena/cli/container_command.rb +1 -1
  50. data/lib/kontena/cli/containers/exec_command.rb +1 -1
  51. data/lib/kontena/cli/containers/inspect_command.rb +1 -1
  52. data/lib/kontena/cli/etcd/get_command.rb +1 -1
  53. data/lib/kontena/cli/etcd/list_command.rb +1 -1
  54. data/lib/kontena/cli/etcd/mkdir_command.rb +1 -1
  55. data/lib/kontena/cli/etcd/remove_command.rb +1 -1
  56. data/lib/kontena/cli/etcd/set_command.rb +1 -1
  57. data/lib/kontena/cli/etcd_command.rb +1 -1
  58. data/lib/kontena/cli/external_registries/add_command.rb +1 -1
  59. data/lib/kontena/cli/external_registries/delete_command.rb +1 -1
  60. data/lib/kontena/cli/external_registries/list_command.rb +1 -1
  61. data/lib/kontena/cli/external_registries/remove_command.rb +1 -1
  62. data/lib/kontena/cli/external_registry_command.rb +1 -1
  63. data/lib/kontena/cli/grid_command.rb +1 -1
  64. data/lib/kontena/cli/grids/audit_log_command.rb +6 -5
  65. data/lib/kontena/cli/grids/cloud_config_command.rb +1 -1
  66. data/lib/kontena/cli/grids/common.rb +1 -1
  67. data/lib/kontena/cli/grids/create_command.rb +8 -4
  68. data/lib/kontena/cli/grids/current_command.rb +1 -1
  69. data/lib/kontena/cli/grids/env_command.rb +1 -1
  70. data/lib/kontena/cli/grids/list_command.rb +35 -10
  71. data/lib/kontena/cli/grids/logs_command.rb +1 -1
  72. data/lib/kontena/cli/grids/remove_command.rb +2 -2
  73. data/lib/kontena/cli/grids/show_command.rb +1 -1
  74. data/lib/kontena/cli/grids/trusted_subnet_command.rb +1 -1
  75. data/lib/kontena/cli/grids/trusted_subnets/add_command.rb +1 -1
  76. data/lib/kontena/cli/grids/trusted_subnets/list_command.rb +1 -1
  77. data/lib/kontena/cli/grids/trusted_subnets/remove_command.rb +1 -1
  78. data/lib/kontena/cli/grids/update_command.rb +1 -1
  79. data/lib/kontena/cli/grids/use_command.rb +11 -6
  80. data/lib/kontena/cli/grids/user_command.rb +1 -1
  81. data/lib/kontena/cli/grids/users/add_command.rb +1 -1
  82. data/lib/kontena/cli/grids/users/list_command.rb +1 -1
  83. data/lib/kontena/cli/grids/users/remove_command.rb +1 -1
  84. data/lib/kontena/cli/localhost_web_server.rb +93 -0
  85. data/lib/kontena/cli/login_command.rb +5 -118
  86. data/lib/kontena/cli/logout_command.rb +33 -2
  87. data/lib/kontena/cli/master/audit_log_command.rb +19 -0
  88. data/lib/kontena/cli/master/config/export_command.rb +47 -0
  89. data/lib/kontena/cli/master/config/get_command.rb +24 -0
  90. data/lib/kontena/cli/master/config/import_command.rb +69 -0
  91. data/lib/kontena/cli/master/config/set_command.rb +19 -0
  92. data/lib/kontena/cli/master/config/unset_command.rb +20 -0
  93. data/lib/kontena/cli/master/config_command.rb +24 -0
  94. data/lib/kontena/cli/master/create_command.rb +76 -0
  95. data/lib/kontena/cli/master/current_command.rb +10 -2
  96. data/lib/kontena/cli/master/join_command.rb +20 -0
  97. data/lib/kontena/cli/master/list_command.rb +4 -4
  98. data/lib/kontena/cli/master/login_command.rb +274 -0
  99. data/lib/kontena/cli/master/use_command.rb +8 -19
  100. data/lib/kontena/cli/master/users/invite_command.rb +33 -6
  101. data/lib/kontena/cli/master/users/list_command.rb +2 -2
  102. data/lib/kontena/cli/master/users/remove_command.rb +1 -1
  103. data/lib/kontena/cli/master/users/role_command.rb +1 -1
  104. data/lib/kontena/cli/master/users/roles/add_command.rb +18 -16
  105. data/lib/kontena/cli/master/users/roles/remove_command.rb +1 -1
  106. data/lib/kontena/cli/master/users_command.rb +1 -1
  107. data/lib/kontena/cli/master_command.rb +21 -1
  108. data/lib/kontena/cli/node_command.rb +1 -1
  109. data/lib/kontena/cli/nodes/label_command.rb +1 -1
  110. data/lib/kontena/cli/nodes/labels/add_command.rb +1 -1
  111. data/lib/kontena/cli/nodes/labels/remove_command.rb +1 -1
  112. data/lib/kontena/cli/nodes/list_command.rb +1 -1
  113. data/lib/kontena/cli/nodes/remove_command.rb +1 -1
  114. data/lib/kontena/cli/nodes/show_command.rb +1 -1
  115. data/lib/kontena/cli/nodes/ssh_command.rb +1 -1
  116. data/lib/kontena/cli/nodes/update_command.rb +1 -1
  117. data/lib/kontena/cli/plugin_command.rb +1 -1
  118. data/lib/kontena/cli/plugins/install_command.rb +2 -2
  119. data/lib/kontena/cli/plugins/list_command.rb +2 -2
  120. data/lib/kontena/cli/plugins/search_command.rb +1 -1
  121. data/lib/kontena/cli/plugins/uninstall_command.rb +2 -2
  122. data/lib/kontena/cli/registry/create_command.rb +2 -4
  123. data/lib/kontena/cli/registry/delete_command.rb +1 -1
  124. data/lib/kontena/cli/registry/remove_command.rb +1 -1
  125. data/lib/kontena/cli/registry_command.rb +1 -1
  126. data/lib/kontena/cli/service_command.rb +1 -1
  127. data/lib/kontena/cli/services/container_command.rb +1 -1
  128. data/lib/kontena/cli/services/containers_command.rb +1 -1
  129. data/lib/kontena/cli/services/create_command.rb +1 -1
  130. data/lib/kontena/cli/services/delete_command.rb +1 -1
  131. data/lib/kontena/cli/services/deploy_command.rb +1 -1
  132. data/lib/kontena/cli/services/env_command.rb +1 -1
  133. data/lib/kontena/cli/services/envs/add_command.rb +1 -1
  134. data/lib/kontena/cli/services/envs/list_command.rb +1 -1
  135. data/lib/kontena/cli/services/envs/remove_command.rb +1 -1
  136. data/lib/kontena/cli/services/link_command.rb +1 -1
  137. data/lib/kontena/cli/services/list_command.rb +1 -1
  138. data/lib/kontena/cli/services/logs_command.rb +1 -1
  139. data/lib/kontena/cli/services/monitor_command.rb +1 -1
  140. data/lib/kontena/cli/services/remove_command.rb +1 -1
  141. data/lib/kontena/cli/services/restart_command.rb +1 -1
  142. data/lib/kontena/cli/services/scale_command.rb +1 -1
  143. data/lib/kontena/cli/services/secret_command.rb +1 -1
  144. data/lib/kontena/cli/services/secrets/link_command.rb +1 -1
  145. data/lib/kontena/cli/services/secrets/unlink_command.rb +1 -1
  146. data/lib/kontena/cli/services/services_helper.rb +6 -3
  147. data/lib/kontena/cli/services/show_command.rb +1 -1
  148. data/lib/kontena/cli/services/start_command.rb +1 -1
  149. data/lib/kontena/cli/services/stats_command.rb +1 -1
  150. data/lib/kontena/cli/services/stop_command.rb +1 -1
  151. data/lib/kontena/cli/services/unlink_command.rb +1 -1
  152. data/lib/kontena/cli/services/update_command.rb +1 -1
  153. data/lib/kontena/cli/spinner.rb +122 -0
  154. data/lib/kontena/cli/stack_command.rb +1 -1
  155. data/lib/kontena/cli/stacks/create_command.rb +1 -1
  156. data/lib/kontena/cli/stacks/deploy_command.rb +1 -1
  157. data/lib/kontena/cli/stacks/list_command.rb +1 -1
  158. data/lib/kontena/cli/stacks/remove_command.rb +1 -1
  159. data/lib/kontena/cli/stacks/show_command.rb +1 -1
  160. data/lib/kontena/cli/stacks/update_command.rb +1 -1
  161. data/lib/kontena/cli/vault/list_command.rb +1 -1
  162. data/lib/kontena/cli/vault/read_command.rb +1 -1
  163. data/lib/kontena/cli/vault/remove_command.rb +1 -1
  164. data/lib/kontena/cli/vault/update_command.rb +1 -1
  165. data/lib/kontena/cli/vault/write_command.rb +1 -1
  166. data/lib/kontena/cli/vault_command.rb +1 -1
  167. data/lib/kontena/cli/version.rb +1 -1
  168. data/lib/kontena/cli/version_command.rb +1 -1
  169. data/lib/kontena/cli/vpn/config_command.rb +1 -1
  170. data/lib/kontena/cli/vpn/create_command.rb +2 -4
  171. data/lib/kontena/cli/vpn/delete_command.rb +1 -1
  172. data/lib/kontena/cli/vpn/remove_command.rb +1 -1
  173. data/lib/kontena/cli/vpn_command.rb +1 -1
  174. data/lib/kontena/cli/whoami_command.rb +16 -13
  175. data/lib/kontena/client.rb +410 -90
  176. data/lib/kontena/command.rb +172 -0
  177. data/lib/kontena/main_command.rb +7 -8
  178. data/lib/kontena/presets/github_auth_provider.yml +11 -0
  179. data/lib/kontena/presets/kontena_auth_provider.yml +11 -0
  180. data/lib/kontena_cli.rb +51 -1
  181. data/spec/kontena/cli/app/deploy_command_spec.rb +14 -44
  182. data/spec/kontena/cli/app/scale_spec.rb +1 -1
  183. data/spec/kontena/cli/app/yaml/reader_spec.rb +0 -48
  184. data/spec/kontena/cli/common_spec.rb +63 -59
  185. data/spec/kontena/cli/grids/use_command_spec.rb +43 -0
  186. data/spec/kontena/cli/master/current_command_spec.rb +3 -24
  187. data/spec/kontena/cli/master/use_command_spec.rb +2 -27
  188. data/spec/kontena/cli/master/users/invite_command_spec.rb +4 -18
  189. data/spec/kontena/cli/master/users/roles/add_command_spec.rb +2 -16
  190. data/spec/kontena/cli/master/users/roles/remove_command_spec.rb +2 -13
  191. data/spec/kontena/cli/services/restart_command_spec.rb +1 -1
  192. data/spec/kontena/cli/services/update_command_spec.rb +5 -5
  193. data/spec/kontena/client_spec.rb +104 -35
  194. data/spec/kontena/config_spec.rb +65 -0
  195. data/spec/spec_helper.rb +25 -3
  196. data/spec/support/client_helpers.rb +10 -3
  197. data/spec/support/requirements_helper.rb +32 -0
  198. metadata +61 -48
  199. data/lib/kontena/cli/register_command.rb +0 -23
  200. data/lib/kontena/cli/user/forgot_password_command.rb +0 -16
  201. data/lib/kontena/cli/user/reset_password_command.rb +0 -23
  202. data/lib/kontena/cli/user/verify_command.rb +0 -20
  203. data/lib/kontena/cli/user_command.rb +0 -13
  204. data/spec/fixtures/kontena-malformed-yaml.yml +0 -6
  205. data/spec/fixtures/kontena-not-hash-service-config.yml +0 -3
  206. data/spec/kontena/cli/login_command_spec.rb +0 -32
  207. data/spec/kontena/cli/register_command_spec.rb +0 -57
@@ -1,7 +1,7 @@
1
1
  require_relative 'containers/exec_command'
2
2
  require_relative 'containers/inspect_command'
3
3
 
4
- class Kontena::Cli::ContainerCommand < Clamp::Command
4
+ class Kontena::Cli::ContainerCommand < Kontena::Command
5
5
 
6
6
  subcommand "exec", "Execute command inside a container", Kontena::Cli::Containers::ExecCommand
7
7
  subcommand "inspect", "Inspect the container", Kontena::Cli::Containers::InspectCommand
@@ -2,7 +2,7 @@ require_relative '../grid_options'
2
2
  require_relative './containers_helper'
3
3
 
4
4
  module Kontena::Cli::Containers
5
- class ExecCommand < Clamp::Command
5
+ class ExecCommand < Kontena::Command
6
6
  include Kontena::Cli::Common
7
7
  include Kontena::Cli::GridOptions
8
8
  include ContainersHelper
@@ -1,5 +1,5 @@
1
1
  module Kontena::Cli::Containers
2
- class InspectCommand < Clamp::Command
2
+ class InspectCommand < Kontena::Command
3
3
  include Kontena::Cli::Common
4
4
  include Kontena::Cli::GridOptions
5
5
 
@@ -1,7 +1,7 @@
1
1
  require_relative 'common'
2
2
 
3
3
  module Kontena::Cli::Etcd
4
- class GetCommand < Clamp::Command
4
+ class GetCommand < Kontena::Command
5
5
  include Kontena::Cli::Common
6
6
  include Kontena::Cli::GridOptions
7
7
  include Common
@@ -1,7 +1,7 @@
1
1
  require_relative 'common'
2
2
 
3
3
  module Kontena::Cli::Etcd
4
- class ListCommand < Clamp::Command
4
+ class ListCommand < Kontena::Command
5
5
  include Kontena::Cli::Common
6
6
  include Kontena::Cli::GridOptions
7
7
  include Common
@@ -1,7 +1,7 @@
1
1
  require_relative 'common'
2
2
 
3
3
  module Kontena::Cli::Etcd
4
- class MkdirCommand < Clamp::Command
4
+ class MkdirCommand < Kontena::Command
5
5
  include Kontena::Cli::Common
6
6
  include Kontena::Cli::GridOptions
7
7
  include Common
@@ -1,7 +1,7 @@
1
1
  require_relative 'common'
2
2
 
3
3
  module Kontena::Cli::Etcd
4
- class RemoveCommand < Clamp::Command
4
+ class RemoveCommand < Kontena::Command
5
5
  include Kontena::Cli::Common
6
6
  include Kontena::Cli::GridOptions
7
7
  include Common
@@ -1,7 +1,7 @@
1
1
  require_relative 'common'
2
2
 
3
3
  module Kontena::Cli::Etcd
4
- class SetCommand < Clamp::Command
4
+ class SetCommand < Kontena::Command
5
5
  include Kontena::Cli::Common
6
6
  include Kontena::Cli::GridOptions
7
7
  include Common
@@ -4,7 +4,7 @@ require_relative 'etcd/mkdir_command'
4
4
  require_relative 'etcd/list_command'
5
5
  require_relative 'etcd/remove_command'
6
6
 
7
- class Kontena::Cli::EtcdCommand < Clamp::Command
7
+ class Kontena::Cli::EtcdCommand < Kontena::Command
8
8
 
9
9
  subcommand "get", "Get the current value for a single key", Kontena::Cli::Etcd::GetCommand
10
10
  subcommand "set", "Set a value on the specified key", Kontena::Cli::Etcd::SetCommand
@@ -1,5 +1,5 @@
1
1
  module Kontena::Cli::ExternalRegistries
2
- class AddCommand < Clamp::Command
2
+ class AddCommand < Kontena::Command
3
3
  include Kontena::Cli::Common
4
4
  include Kontena::Cli::GridOptions
5
5
 
@@ -1,5 +1,5 @@
1
1
  module Kontena::Cli::ExternalRegistries
2
- class DeleteCommand < Clamp::Command
2
+ class DeleteCommand < Kontena::Command
3
3
  include Kontena::Cli::Common
4
4
  include Kontena::Cli::GridOptions
5
5
 
@@ -1,5 +1,5 @@
1
1
  module Kontena::Cli::ExternalRegistries
2
- class ListCommand < Clamp::Command
2
+ class ListCommand < Kontena::Command
3
3
  include Kontena::Cli::Common
4
4
  include Kontena::Cli::GridOptions
5
5
 
@@ -1,5 +1,5 @@
1
1
  module Kontena::Cli::ExternalRegistries
2
- class RemoveCommand < Clamp::Command
2
+ class RemoveCommand < Kontena::Command
3
3
  include Kontena::Cli::Common
4
4
 
5
5
  parameter "NAME", "External registry name to remove"
@@ -3,7 +3,7 @@ require_relative 'external_registries/list_command'
3
3
  require_relative 'external_registries/delete_command'
4
4
  require_relative 'external_registries/remove_command'
5
5
 
6
- class Kontena::Cli::ExternalRegistryCommand < Clamp::Command
6
+ class Kontena::Cli::ExternalRegistryCommand < Kontena::Command
7
7
 
8
8
  subcommand "add", "Add external Docker image registry", Kontena::Cli::ExternalRegistries::AddCommand
9
9
  subcommand ["list", "ls"], "List external Docker image registries", Kontena::Cli::ExternalRegistries::ListCommand
@@ -12,7 +12,7 @@ require_relative 'grids/user_command'
12
12
  require_relative 'grids/cloud_config_command'
13
13
  require_relative 'grids/trusted_subnet_command'
14
14
 
15
- class Kontena::Cli::GridCommand < Clamp::Command
15
+ class Kontena::Cli::GridCommand < Kontena::Command
16
16
 
17
17
  subcommand ["list","ls"], "List all grids", Kontena::Cli::Grids::ListCommand
18
18
  subcommand "create", "Create a new grid", Kontena::Cli::Grids::CreateCommand
@@ -1,17 +1,18 @@
1
1
  require_relative 'common'
2
2
 
3
3
  module Kontena::Cli::Grids
4
- class AuditLogCommand < Clamp::Command
4
+ class AuditLogCommand < Kontena::Command
5
5
  include Kontena::Cli::Common
6
6
  include Common
7
7
 
8
8
  option ["-l", "--lines"], "LINES", "Number of lines"
9
9
 
10
+ requires_current_master
11
+ requires_current_master_token
12
+ requires_current_grid
13
+
10
14
  def execute
11
- require_api_url
12
- require_current_grid
13
- token = require_token
14
- audit_logs = client(token).get("grids/#{current_grid}/audit_log", {limit: lines})
15
+ audit_logs = client.get("grids/#{current_grid}/audit_log", {limit: lines})
15
16
  puts '%-30.30s %-10s %-15s %-25s %-15s %-25s %-15s %-15s' % ['Time', 'Grid', 'Resource Type', 'Resource Name', 'Event Name', 'User', 'Source IP', 'User-Agent']
16
17
  audit_logs['logs'].each do |log|
17
18
  puts '%-30.30s %-10s %-15s %-25s %-15s %-25s %-15s %-15s' % [ log['time'], log['grid'], log['resource_type'], log['resource_name'], log['event_name'], log['user_identity']['email'], log['source_ip'], log['user_agent']]
@@ -1,7 +1,7 @@
1
1
  require_relative 'common'
2
2
 
3
3
  module Kontena::Cli::Grids
4
- class CloudConfigCommand < Clamp::Command
4
+ class CloudConfigCommand < Kontena::Command
5
5
  include Kontena::Cli::Common
6
6
  include Common
7
7
 
@@ -38,7 +38,7 @@ module Kontena::Cli::Grids
38
38
  end
39
39
 
40
40
  def grids
41
- @grids ||= client(require_token).get('grids')
41
+ @grids ||= client.get('grids')
42
42
  end
43
43
 
44
44
  # @param [Array<Hash>] nodes
@@ -1,12 +1,15 @@
1
1
  require_relative 'common'
2
2
 
3
3
  module Kontena::Cli::Grids
4
- class CreateCommand < Clamp::Command
4
+ class CreateCommand < Kontena::Command
5
5
  include Kontena::Cli::Common
6
6
  include Common
7
7
 
8
8
  parameter "NAME", "Grid name"
9
+
9
10
  option "--initial-size", "INITIAL_SIZE", "Initial grid size (number of nodes)", default: 1
11
+ option "--skip-use", :flag, "Do not switch to the created grid"
12
+ option "--silent", :flag, "Reduce output verbosity"
10
13
 
11
14
  def execute
12
15
  require_api_url
@@ -17,9 +20,10 @@ module Kontena::Cli::Grids
17
20
  }
18
21
  payload[:initial_size] = initial_size if initial_size
19
22
  grid = client(token).post('grids', payload)
20
- if grid
21
- self.current_grid = grid
22
- puts "Using grid: #{grid['name'].cyan}"
23
+ if grid && !self.skip_use?
24
+ config.current_grid = grid['name']
25
+ config.write
26
+ puts "Using grid: #{pastel.cyan(grid['name'])}"
23
27
  end
24
28
  end
25
29
  end
@@ -1,7 +1,7 @@
1
1
  require_relative 'common'
2
2
 
3
3
  module Kontena::Cli::Grids
4
- class CurrentCommand < Clamp::Command
4
+ class CurrentCommand < Kontena::Command
5
5
  include Kontena::Cli::Common
6
6
  include Common
7
7
 
@@ -1,7 +1,7 @@
1
1
  require_relative 'common'
2
2
 
3
3
  module Kontena::Cli::Grids
4
- class EnvCommand < Clamp::Command
4
+ class EnvCommand < Kontena::Command
5
5
  include Kontena::Cli::Common
6
6
  include Common
7
7
 
@@ -1,25 +1,50 @@
1
1
  require_relative 'common'
2
2
 
3
3
  module Kontena::Cli::Grids
4
- class ListCommand < Clamp::Command
4
+ class ListCommand < Kontena::Command
5
5
  include Kontena::Cli::Common
6
6
  include Common
7
7
 
8
+ option ['-u', '--use'], :flag, 'Automatically use first available grid sorted by user count', hidden: true
9
+ option ['-v', '--verbose'], :flag, 'Use a more verbose output', hidden: true
10
+
8
11
  def execute
9
12
  require_api_url
10
13
 
11
- if grids['grids'].size == 0
12
- puts "You don't have any grids yet. Create first one with 'kontena grid create' command".colorize(:yellow)
14
+ vputs
15
+
16
+ gridlist = []
17
+
18
+ vspinner "Retrieving a list of available grids" do
19
+ gridlist = grids['grids'].sort_by{|grid| grid['user_count']}
13
20
  end
14
21
 
15
- puts '%-30.30s %-8s %-12s %-10s' % ['Name', 'Nodes', 'Services', 'Users']
16
- grids['grids'].each do |grid|
17
- if grid['id'] == current_grid
18
- name = "#{grid['name']} *"
19
- else
20
- name = grid['name']
22
+ if gridlist.size == 0
23
+ self.verbose? && puts
24
+ puts "Kontena Master #{config.current_master.name} doesn't have any grids yet. Create one now using 'kontena grid create' command".colorize(:yellow)
25
+ self.verbose? && puts
26
+ else
27
+ vputs
28
+ vputs "You have access to the following grids:"
29
+ vputs
30
+
31
+ puts '%-30.30s %-8s %-12s %-10s' % ['Name', 'Nodes', 'Services', 'Users']
32
+ gridlist.each do |grid|
33
+ if grid['name'] == config.current_master.grid
34
+ name = "#{grid['name']} *"
35
+ else
36
+ name = grid['name']
37
+ end
38
+ puts '%-30.30s %-8s %-12s %-10s' % [name, grid['node_count'], grid['service_count'], grid['user_count']]
39
+ end
40
+
41
+ if self.use?
42
+ vputs
43
+ vspinner "* Selecting '#{gridlist.first['name']}' as the current grid" do
44
+ config.current_master.grid = gridlist.first['name']
45
+ config.write
46
+ end
21
47
  end
22
- puts '%-30.30s %-8s %-12s %-10s' % [name, grid['node_count'], grid['service_count'], grid['user_count']]
23
48
  end
24
49
  end
25
50
  end
@@ -1,7 +1,7 @@
1
1
  require_relative '../helpers/log_helper'
2
2
 
3
3
  module Kontena::Cli::Grids
4
- class LogsCommand < Clamp::Command
4
+ class LogsCommand < Kontena::Command
5
5
  include Kontena::Cli::Common
6
6
  include Kontena::Cli::Helpers::LogHelper
7
7
 
@@ -1,7 +1,7 @@
1
1
  require_relative 'common'
2
2
 
3
3
  module Kontena::Cli::Grids
4
- class RemoveCommand < Clamp::Command
4
+ class RemoveCommand < Kontena::Command
5
5
  include Kontena::Cli::Common
6
6
  include Common
7
7
 
@@ -18,7 +18,7 @@ module Kontena::Cli::Grids
18
18
  response = client(token).delete("grids/#{grid['id']}")
19
19
  if response
20
20
  clear_current_grid if grid['id'] == current_grid
21
- puts "removed #{grid['name'].cyan}"
21
+ puts "removed #{pastel.cyan(grid['name'])}"
22
22
  end
23
23
  else
24
24
  abort "Could not resolve grid by name [#{name}]. For a list of existing grids please run: kontena grid list".colorize(:red)
@@ -1,7 +1,7 @@
1
1
  require_relative 'common'
2
2
 
3
3
  module Kontena::Cli::Grids
4
- class ShowCommand < Clamp::Command
4
+ class ShowCommand < Kontena::Command
5
5
  include Kontena::Cli::Common
6
6
  include Common
7
7
 
@@ -4,7 +4,7 @@ module Kontena::Cli::Grids
4
4
  require_relative 'trusted_subnets/add_command'
5
5
  require_relative 'trusted_subnets/remove_command'
6
6
 
7
- class TrustedSubnetCommand < Clamp::Command
7
+ class TrustedSubnetCommand < Kontena::Command
8
8
  subcommand ["list", "ls"], "List trusted subnets", TrustedSubnets::ListCommand
9
9
  subcommand "add", "Add trusted subnet", TrustedSubnets::AddCommand
10
10
  subcommand ["remove", "rm"], "Remove trusted subnet", TrustedSubnets::RemoveCommand
@@ -1,5 +1,5 @@
1
1
  module Kontena::Cli::Grids::TrustedSubnets
2
- class AddCommand < Clamp::Command
2
+ class AddCommand < Kontena::Command
3
3
  include Kontena::Cli::Common
4
4
 
5
5
  parameter "NAME", "Grid name"
@@ -1,5 +1,5 @@
1
1
  module Kontena::Cli::Grids::TrustedSubnets
2
- class ListCommand < Clamp::Command
2
+ class ListCommand < Kontena::Command
3
3
  include Kontena::Cli::Common
4
4
 
5
5
  parameter "NAME", "Grid name"
@@ -1,5 +1,5 @@
1
1
  module Kontena::Cli::Grids::TrustedSubnets
2
- class RemoveCommand < Clamp::Command
2
+ class RemoveCommand < Kontena::Command
3
3
  include Kontena::Cli::Common
4
4
 
5
5
  parameter "NAME", "Grid name"
@@ -1,7 +1,7 @@
1
1
  require_relative 'common'
2
2
 
3
3
  module Kontena::Cli::Grids
4
- class UpdateCommand < Clamp::Command
4
+ class UpdateCommand < Kontena::Command
5
5
  include Kontena::Cli::Common
6
6
  include Common
7
7
 
@@ -1,21 +1,26 @@
1
1
  require_relative 'common'
2
2
 
3
3
  module Kontena::Cli::Grids
4
- class UseCommand < Clamp::Command
4
+ class UseCommand < Kontena::Command
5
5
  include Kontena::Cli::Common
6
6
  include Common
7
7
 
8
+ requires_current_master
9
+
8
10
  parameter "NAME", "Grid name to use"
9
11
 
12
+ option ['--silent'], :flag, 'Reduce output verbosity'
13
+
10
14
  def execute
11
- require_api_url
12
15
  grid = find_grid_by_name(name)
13
- if !grid.nil?
14
- self.current_grid = grid
15
- puts "Using grid: #{grid['name'].cyan}"
16
- else
16
+ unless grid
17
17
  abort "Could not resolve grid by name [#{name}]. For a list of existing grids please run: kontena grid list".colorize(:red)
18
18
  end
19
+ config.current_master.grid = grid['name']
20
+ config.write
21
+ unless self.silent?
22
+ puts "Using grid: #{pastel.cyan(grid['name'])}"
23
+ end
19
24
  end
20
25
  end
21
26
  end
@@ -4,7 +4,7 @@ module Kontena::Cli::Grids
4
4
  require_relative 'users/add_command'
5
5
  require_relative 'users/remove_command'
6
6
 
7
- class UserCommand < Clamp::Command
7
+ class UserCommand < Kontena::Command
8
8
  subcommand ["list", "ls"], "List grid users", Users::ListCommand
9
9
  subcommand "add", "Add user to grid", Users::AddCommand
10
10
  subcommand ["remove", "rm"], "Remove user from grid", Users::RemoveCommand
@@ -1,7 +1,7 @@
1
1
  require_relative '../common'
2
2
 
3
3
  module Kontena::Cli::Grids::Users
4
- class AddCommand < Clamp::Command
4
+ class AddCommand < Kontena::Command
5
5
  include Kontena::Cli::Common
6
6
  include Kontena::Cli::GridOptions
7
7
  include Kontena::Cli::Grids::Common
@@ -1,7 +1,7 @@
1
1
  require_relative '../common'
2
2
 
3
3
  module Kontena::Cli::Grids::Users
4
- class ListCommand < Clamp::Command
4
+ class ListCommand < Kontena::Command
5
5
  include Kontena::Cli::Common
6
6
  include Kontena::Cli::Grids::Common
7
7
 
@@ -1,7 +1,7 @@
1
1
  require_relative '../common'
2
2
 
3
3
  module Kontena::Cli::Grids::Users
4
- class RemoveCommand < Clamp::Command
4
+ class RemoveCommand < Kontena::Command
5
5
  include Kontena::Cli::Common
6
6
  include Kontena::Cli::GridOptions
7
7
  include Kontena::Cli::Grids::Common