kontena-plugin-cloud 1.2.0.pre1 → 1.2.0.pre2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/lib/kontena/plugin/cloud/node/common.rb +2 -10
- data/lib/kontena/plugin/cloud/node/create_command.rb +14 -1
- data/lib/kontena/plugin/cloud/node/list_command.rb +32 -4
- data/lib/kontena/plugin/cloud/node/platform_option.rb +11 -0
- data/lib/kontena/plugin/cloud/node/reboot_command.rb +35 -0
- data/lib/kontena/plugin/cloud/node/shell_command.rb +1 -0
- data/lib/kontena/plugin/cloud/node/terminate_command.rb +1 -0
- data/lib/kontena/plugin/cloud/node_command.rb +2 -1
- data/lib/kontena/plugin/cloud/platform/create_command.rb +30 -13
- data/lib/kontena/plugin/cloud/platform/list_command.rb +2 -1
- data/lib/kontena/plugin/cloud/platform/show_command.rb +1 -1
- data/lib/kontena/plugin/cloud.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e982c9ea1499f2618665e250c4f5c6e2b11511f96c14afc77ef0f288f4e2eaf5
|
4
|
+
data.tar.gz: 009906cfbb8b95082e41823fb62feaa5ed10105237a096fa9805be0628933319
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 93af9ac05619ca85c45af77e68eead3d048081e7e3d00b593c2bde695ca219a38fb651586bad1572d3f78b4e7e3111df07582262e99b04d51215a67199de3a8f
|
7
|
+
data.tar.gz: 03e5054dda9fc13beda51de24be52ca125e7b329d8a6fe1d3547441b4c8c433182c6894fd479e269e1aaf7b89944b816930c505aa7bb728fa9e608c8c026a3a0
|
@@ -1,17 +1,9 @@
|
|
1
1
|
require_relative '../../../cli/models/node'
|
2
2
|
require_relative '../../../cli/models/platform'
|
3
|
+
require_relative 'platform_option'
|
3
4
|
|
4
5
|
module Kontena::Plugin::Cloud::Node::Common
|
5
6
|
|
6
|
-
def self.included(base)
|
7
|
-
if base.respond_to?(:option)
|
8
|
-
base.option '--platform', 'PLATFORM', 'Specify Kontena Cloud platform to use' do |platform|
|
9
|
-
config.current_master = platform
|
10
|
-
config.current_grid = platform.split('/')[1]
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
7
|
def compute_client
|
16
8
|
@compute_client ||= Kontena::Client.new(compute_url, config.current_account.token, prefix: '/')
|
17
9
|
end
|
@@ -21,7 +13,7 @@ module Kontena::Plugin::Cloud::Node::Common
|
|
21
13
|
end
|
22
14
|
|
23
15
|
def compute_url
|
24
|
-
ENV['
|
16
|
+
ENV['KONTENA_COMPUTE_URL'] || 'https://compute.kontena.io'
|
25
17
|
end
|
26
18
|
|
27
19
|
def get_platform(org, id)
|
@@ -7,6 +7,7 @@ class Kontena::Plugin::Cloud::Node::CreateCommand < Kontena::Command
|
|
7
7
|
include Kontena::Cli::Common
|
8
8
|
include Kontena::Machine::RandomName
|
9
9
|
include Kontena::Plugin::Cloud::Node::Common
|
10
|
+
include Kontena::Plugin::Cloud::Node::PlatformOption
|
10
11
|
include Kontena::Plugin::Cloud::Organization::Common
|
11
12
|
include Kontena::Plugin::Cloud::Platform::Common
|
12
13
|
|
@@ -17,6 +18,7 @@ class Kontena::Plugin::Cloud::Node::CreateCommand < Kontena::Command
|
|
17
18
|
end
|
18
19
|
option "--type", "TYPE", "Node type", required: true
|
19
20
|
option "--region", "REGION", "Region (us-east-1, eu-west-1, defaults to current platform region)"
|
21
|
+
option "--ssh-key", "SSH_KEY", "Path to ssh public key"
|
20
22
|
|
21
23
|
def execute
|
22
24
|
org, platform = parse_platform_name(current_master.name)
|
@@ -31,6 +33,16 @@ class Kontena::Plugin::Cloud::Node::CreateCommand < Kontena::Command
|
|
31
33
|
name = "#{generate_name}-#{rand(1..999)}"
|
32
34
|
node_token = SecureRandom.hex(32)
|
33
35
|
target_region = self.region || platform.region
|
36
|
+
ssh_keys = []
|
37
|
+
if ssh_key
|
38
|
+
begin
|
39
|
+
key_path = File.realpath(ssh_key)
|
40
|
+
ssh_keys << File.read(key_path)
|
41
|
+
rescue Errno::ENOENT
|
42
|
+
exit_with_error "ssh key #{ssh_key} does not exist"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
34
46
|
spinner "Provisioning a node #{pastel.cyan(name)} to platform #{pastel.cyan(platform.to_path)}, region #{pastel.cyan(target_region)}" do
|
35
47
|
client.post("grids/#{current_grid}/nodes", {
|
36
48
|
name: name,
|
@@ -46,7 +58,8 @@ class Kontena::Plugin::Cloud::Node::CreateCommand < Kontena::Command
|
|
46
58
|
tokens: {
|
47
59
|
grid: token,
|
48
60
|
node: node_token
|
49
|
-
}
|
61
|
+
},
|
62
|
+
'ssh-keys': ssh_keys
|
50
63
|
},
|
51
64
|
relationships: {
|
52
65
|
platform: {
|
@@ -11,27 +11,55 @@ class Kontena::Plugin::Cloud::Node::ListCommand < Kontena::Command
|
|
11
11
|
|
12
12
|
requires_current_account_token
|
13
13
|
|
14
|
+
option ['--organization', '--org'], 'ORG', 'Organization', environment_variable: "KONTENA_ORGANIZATION"
|
15
|
+
option ['--quiet', '-q'], :flag, 'Output the identifying column only'
|
16
|
+
|
14
17
|
def execute
|
15
|
-
|
16
|
-
platform = require_platform("#{org}/#{platform}")
|
17
|
-
nodes = compute_client.get("/organizations/#{org}/nodes")['data']
|
18
|
+
nodes = compute_client.get("/organizations/#{self.organization}/nodes")['data']
|
18
19
|
nodes.delete_if { |n| n.dig('attributes', 'state') == 'terminated' }
|
20
|
+
if quiet?
|
21
|
+
puts nodes.map { |n| n.dig('attributes', 'name')}
|
22
|
+
return
|
23
|
+
end
|
24
|
+
platforms = fetch_platforms(nodes)
|
19
25
|
print_table(nodes) do |n|
|
20
26
|
node = Kontena::Cli::Models::Node.new(n)
|
21
27
|
n['name'] = "#{state_icon(node.state)} #{node.name}"
|
22
28
|
n['type'] = node.type
|
23
29
|
n['region'] = node.region
|
30
|
+
if platform = platforms[node.platform_id]
|
31
|
+
n['platform'] = platform.to_path
|
32
|
+
else
|
33
|
+
n['platform'] = pastel.red('<orphan>')
|
34
|
+
end
|
24
35
|
end
|
25
36
|
end
|
26
37
|
|
38
|
+
def fetch_platforms(nodes)
|
39
|
+
platform_ids = nodes.map { |n| Kontena::Cli::Models::Node.new(n).platform_id }.compact.uniq
|
40
|
+
platforms = {}
|
41
|
+
platform_ids.each { |id|
|
42
|
+
platform_data = cloud_client.get("/organizations/#{self.organization}/platforms/#{id}")['data'] rescue nil
|
43
|
+
if platform_data
|
44
|
+
platforms[id] = Kontena::Cli::Models::Platform.new(platform_data)
|
45
|
+
end
|
46
|
+
}
|
47
|
+
platforms
|
48
|
+
end
|
49
|
+
|
27
50
|
def default_organization
|
28
|
-
|
51
|
+
unless current_master
|
52
|
+
exit_with_error "Organization is required"
|
53
|
+
end
|
54
|
+
org, _ = parse_platform_name(current_master.name)
|
55
|
+
org
|
29
56
|
end
|
30
57
|
|
31
58
|
def fields
|
32
59
|
{
|
33
60
|
'name' => 'name',
|
34
61
|
'type' => 'type',
|
62
|
+
'platform' => 'platform',
|
35
63
|
'region' => 'region'
|
36
64
|
}
|
37
65
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Kontena::Plugin::Cloud::Node::PlatformOption
|
2
|
+
|
3
|
+
def self.included(base)
|
4
|
+
if base.respond_to?(:option)
|
5
|
+
base.option '--platform', 'PLATFORM', 'Specify Kontena Cloud platform to use' do |platform|
|
6
|
+
config.current_master = platform
|
7
|
+
config.current_grid = platform.split('/')[1]
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require_relative 'common'
|
2
|
+
require_relative '../organization/common'
|
3
|
+
require_relative '../platform/common'
|
4
|
+
|
5
|
+
class Kontena::Plugin::Cloud::Node::RebootCommand < Kontena::Command
|
6
|
+
include Kontena::Cli::Common
|
7
|
+
include Kontena::Plugin::Cloud::Platform::Common
|
8
|
+
include Kontena::Plugin::Cloud::Node::Common
|
9
|
+
|
10
|
+
requires_current_account_token
|
11
|
+
|
12
|
+
option ['--organization', '--org'], 'ORG', 'Organization', environment_variable: "KONTENA_ORGANIZATION"
|
13
|
+
parameter "NAME", "Node name"
|
14
|
+
|
15
|
+
def execute
|
16
|
+
node = find_node(name)
|
17
|
+
exit_with_error "Node not found" unless node
|
18
|
+
spinner "Sending reboot request to #{pastel.cyan(name)}" do
|
19
|
+
compute_client.post("/organizations/#{self.organization}/nodes/#{node.dig('id')}/reboot", {})
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def find_node(name)
|
24
|
+
nodes = compute_client.get("/organizations/#{self.organization}/nodes")['data']
|
25
|
+
nodes.find { |n| n.dig('attributes', 'name') == name }
|
26
|
+
end
|
27
|
+
|
28
|
+
def default_organization
|
29
|
+
unless current_master
|
30
|
+
exit_with_error "Organization is required"
|
31
|
+
end
|
32
|
+
org, _ = parse_platform_name(current_master.name)
|
33
|
+
org
|
34
|
+
end
|
35
|
+
end
|
@@ -5,6 +5,7 @@ require_relative '../platform/common'
|
|
5
5
|
class Kontena::Plugin::Cloud::Node::ShellCommand < Kontena::Command
|
6
6
|
include Kontena::Cli::Common
|
7
7
|
include Kontena::Plugin::Cloud::Platform::Common
|
8
|
+
include Kontena::Plugin::Cloud::Node::PlatformOption
|
8
9
|
include Kontena::Plugin::Cloud::Node::Common
|
9
10
|
|
10
11
|
requires_current_account_token
|
@@ -6,6 +6,7 @@ class Kontena::Plugin::Cloud::Node::TerminateCommand < Kontena::Command
|
|
6
6
|
include Kontena::Cli::Common
|
7
7
|
include Kontena::Plugin::Cloud::Platform::Common
|
8
8
|
include Kontena::Plugin::Cloud::Node::Common
|
9
|
+
include Kontena::Plugin::Cloud::Node::PlatformOption
|
9
10
|
|
10
11
|
requires_current_account_token
|
11
12
|
|
@@ -3,7 +3,8 @@ class Kontena::Plugin::Cloud::NodeCommand < Kontena::Command
|
|
3
3
|
subcommand ['list', 'ls'], 'List cloud nodes', load_subcommand('kontena/plugin/cloud/node/list_command')
|
4
4
|
subcommand ['shell'], 'Jump into node shell', load_subcommand('kontena/plugin/cloud/node/shell_command')
|
5
5
|
subcommand ['create'], 'Create cloud node', load_subcommand('kontena/plugin/cloud/node/create_command')
|
6
|
-
subcommand ['
|
6
|
+
subcommand ['reboot'], 'Reboot cloud node', load_subcommand('kontena/plugin/cloud/node/reboot_command')
|
7
|
+
subcommand ['terminate', 'rm'], 'Terminate cloud node', load_subcommand('kontena/plugin/cloud/node/terminate_command')
|
7
8
|
|
8
9
|
def execute
|
9
10
|
end
|
@@ -8,22 +8,31 @@ class Kontena::Plugin::Cloud::Platform::CreateCommand < Kontena::Command
|
|
8
8
|
parameter "[NAME]", "Platform name"
|
9
9
|
|
10
10
|
option ['--organization', '--org'], 'ORG', 'Organization name', environment_variable: 'KONTENA_ORGANIZATION'
|
11
|
+
option ['--type'], 'TYPE', 'Platform type (mini, standard)'
|
11
12
|
option ['--region'], 'region', 'Region (us-east-1, eu-west-1)'
|
12
13
|
option ['--initial-size', '-i'], 'SIZE', 'Initial size (number of nodes) for platform'
|
13
14
|
option '--[no-]use', :flag, 'Switch to use created platform', default: true
|
14
15
|
option '--version', 'VERSION', 'Platform version', visible: false
|
15
16
|
|
16
17
|
def execute
|
17
|
-
confirm("This will create managed platform to Kontena Cloud, proceed?")
|
18
|
-
|
19
18
|
self.name = prompt.ask("Name:") unless self.name
|
20
19
|
self.organization = prompt_organization unless self.organization
|
21
|
-
self.
|
22
|
-
self.
|
20
|
+
self.type = prompt_type unless self.type
|
21
|
+
if self.type == 'mini' && self.region
|
22
|
+
exit_with_error "mini does not support region selection"
|
23
|
+
elsif self.type == 'mini'
|
24
|
+
self.region = nil
|
25
|
+
self.initial_size = 1 unless self.initial_size
|
26
|
+
else
|
27
|
+
self.region = prompt_region unless self.region
|
28
|
+
self.initial_size = 3 unless self.initial_size
|
29
|
+
end
|
23
30
|
|
24
31
|
platform = nil
|
25
|
-
|
26
|
-
|
32
|
+
spinner_text = "Creating platform #{pastel.cyan(name)}"
|
33
|
+
spinner_text = spinner_text + " to region #{pastel.cyan(region)}" if region
|
34
|
+
spinner spinner_text do
|
35
|
+
platform = create_platform(name, organization, type, initial_size, region)
|
27
36
|
end
|
28
37
|
spinner "Waiting for platform #{pastel.cyan(name)} to come online" do
|
29
38
|
while !platform.online? do
|
@@ -32,6 +41,11 @@ class Kontena::Plugin::Cloud::Platform::CreateCommand < Kontena::Command
|
|
32
41
|
end
|
33
42
|
end
|
34
43
|
use_platform(platform) if use?
|
44
|
+
|
45
|
+
puts ""
|
46
|
+
puts " Platform #{pastel.cyan(name)} needs at least #{pastel.cyan(self.initial_size)} node(s) to be functional."
|
47
|
+
puts " You can add nodes from Kontena Cloud ('kontena cloud node create --count #{self.initial_size}') or you can bring your own nodes (https://www.kontena.io/docs/using-kontena/install-nodes/)."
|
48
|
+
puts ""
|
35
49
|
end
|
36
50
|
|
37
51
|
# @param [Kontena::Cli::Models::Platform] platform
|
@@ -62,17 +76,20 @@ class Kontena::Plugin::Cloud::Platform::CreateCommand < Kontena::Command
|
|
62
76
|
end
|
63
77
|
end
|
64
78
|
|
65
|
-
def
|
66
|
-
prompt.select("
|
67
|
-
menu.choice "
|
68
|
-
menu.choice "
|
69
|
-
menu.choice "5 (tolerates 2 initial node failures)", 5
|
79
|
+
def prompt_type
|
80
|
+
prompt.select("Platform type:") do |menu|
|
81
|
+
menu.choice "standard (high-availability, business critical services)", "standard"
|
82
|
+
menu.choice "mini (non-business critical services)", "mini"
|
70
83
|
end
|
71
84
|
end
|
72
85
|
|
73
|
-
def create_platform(name, organization, initial_size, region)
|
86
|
+
def create_platform(name, organization, type, initial_size, region)
|
74
87
|
data = {
|
75
|
-
attributes: {
|
88
|
+
attributes: {
|
89
|
+
"name" => name,
|
90
|
+
"initial-size" => initial_size,
|
91
|
+
"hosted-type" => type
|
92
|
+
},
|
76
93
|
relationships: {
|
77
94
|
region: {
|
78
95
|
"data" => { "type" => "region", "id" => region }
|
@@ -18,7 +18,7 @@ class Kontena::Plugin::Cloud::Platform::ListCommand < Kontena::Command
|
|
18
18
|
platform = Kontena::Cli::Models::Platform.new(p)
|
19
19
|
p['name'] = "#{state_icon(platform.state)} #{organization}/#{platform.name}"
|
20
20
|
p['organization'] = platform.organization
|
21
|
-
p['
|
21
|
+
p['hosted_type'] = platform.hosted_type
|
22
22
|
p['region'] = platform.region
|
23
23
|
end
|
24
24
|
end
|
@@ -30,6 +30,7 @@ class Kontena::Plugin::Cloud::Platform::ListCommand < Kontena::Command
|
|
30
30
|
def fields
|
31
31
|
{
|
32
32
|
name: 'name',
|
33
|
+
type: 'hosted_type',
|
33
34
|
region: 'region'
|
34
35
|
}
|
35
36
|
end
|
@@ -14,11 +14,11 @@ class Kontena::Plugin::Cloud::Platform::ShowCommand < Kontena::Command
|
|
14
14
|
require_platform(name)
|
15
15
|
|
16
16
|
platform = find_platform_by_name(current_platform, current_organization)
|
17
|
-
|
18
17
|
puts "#{name}:"
|
19
18
|
puts " name: #{platform.name}"
|
20
19
|
puts " organization: #{current_organization}"
|
21
20
|
puts " version: #{platform.version}"
|
21
|
+
puts " type: #{platform.hosted_type}"
|
22
22
|
puts " state: #{platform.state}"
|
23
23
|
puts " online: #{platform.online}"
|
24
24
|
puts " region: #{platform.region || '-'}"
|
data/lib/kontena/plugin/cloud.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kontena-plugin-cloud
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.0.
|
4
|
+
version: 1.2.0.pre2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kontena, Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-11-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: kontena-cli
|
@@ -78,6 +78,8 @@ files:
|
|
78
78
|
- lib/kontena/plugin/cloud/node/common.rb
|
79
79
|
- lib/kontena/plugin/cloud/node/create_command.rb
|
80
80
|
- lib/kontena/plugin/cloud/node/list_command.rb
|
81
|
+
- lib/kontena/plugin/cloud/node/platform_option.rb
|
82
|
+
- lib/kontena/plugin/cloud/node/reboot_command.rb
|
81
83
|
- lib/kontena/plugin/cloud/node/shell_command.rb
|
82
84
|
- lib/kontena/plugin/cloud/node/terminate_command.rb
|
83
85
|
- lib/kontena/plugin/cloud/node_command.rb
|
@@ -133,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
133
135
|
version: 1.3.1
|
134
136
|
requirements: []
|
135
137
|
rubyforge_project:
|
136
|
-
rubygems_version: 2.
|
138
|
+
rubygems_version: 2.7.1
|
137
139
|
signing_key:
|
138
140
|
specification_version: 4
|
139
141
|
summary: Kontena Cloud management for Kontena CLI
|