kontena-plugin-digitalocean 0.3.0 → 0.3.1.rc1

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: 1bb6451500eb7cd117546fb2f5079745ea23773f
4
- data.tar.gz: 5383038aeb7fa4a3e638d40a4d93b9d4ecb2f9f4
3
+ metadata.gz: 159d041998037905df8bfaf653d921910f8ba2df
4
+ data.tar.gz: b49274c2e74cace9384aa6c25fde76e6c19edb41
5
5
  SHA512:
6
- metadata.gz: 071c61535e2a8ba9caf1f39a06ba95828b338bf69a61d937828f6c1d5592dd1853efe4adaa9d10661bb6a20b1837b0e905c126e0fe27159c056963321fd0d0c7
7
- data.tar.gz: 0d7d1e867703e1a800696d1421fa67062fc7663c38f161e4e67103b273b692fc29727c02d0594d03b46451fd8250bedc43f157cec823939c517c47ddbe96eb9d
6
+ metadata.gz: 88ebcc12587efa3c1edbd14f249dc6e5a4b6dbe051eb6f5e7d27a6ca2bbcf81f8941e6928cc148e4be37eeaa4e059451bf83a2cc812fbcb8439765e6feb3f097
7
+ data.tar.gz: 4608d8bc37fb630b12f91316a05a704106fa89717d106a64ae912438978cbf94dddb18777dc2476892270a4adc3ea2ed10a4c4ee67fb5b812015667deb0974e8
data/.travis.yml CHANGED
@@ -1,9 +1,9 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.0.0-p648
4
- - 2.1.8
5
- - 2.2.3
6
- - 2.3.1
3
+ - 2.1.10
4
+ - 2.2.6
5
+ - 2.3.3
6
+ - 2.4.1
7
7
  env:
8
8
  - secure: "HAJRG+iaNDuyOMlbYSsXNjA2jwTMQonYJ3fHhm4zDPmIMupNnM+Krx650rVqlMP2KpNIYg4BEWCaDobTU9HoOy0AApmPGc8gGHMCP6v3cSnoGHxmiFy8yB7szgltcBz27PLeJN+exxRCjWPk677jW7JaooyYVSD64dEgVUrFju7olWUrvR0a0hAfBfawXU6kiGgdLnIEtc4AK+mokN9J6fR2PJthuDirZNgDPtVPuBJNFErI9Rh200stcZDOE3F1QE80HyAbrsyfvN/9cosSYDhJS9G+awAw6S+BqeBFZTQlDkWqJgdGsaacasxAmB5bgpkFY5tuv8DdqksK4nXlvsGVurQOYyufuc0y7HllPFVBPkzETCyWaafzek9acfTriLKJIJ26sFYQpuGQlgmAT/KyKYqqzX1ZAk/qe+haT5dt19bXzCHQHWapnWIll11AU0F67TiastmfyaBhnO8d983rwyxIww+8n3AfGPJXZ2eEjw2Rr17yqPYIVtkRoy7ctvCVJTeC6nDGhCqgU5lfl59656fzmJaBI9nWkadK0hQY8WB/5sLJ72pnRZDBbv3xIddS+JnDqxQWheMaJ7Oz5MkbHzdmRo3EhuHGPYpsdPQoeMudqGXX6OTxkQcRbKqJOHDE58rQzz7cZPvY2fwYOkhCspjLWcUAytbaMDkrEVs="
9
9
  cache: bundler
@@ -14,3 +14,4 @@ deploy:
14
14
  gem: kontena-plugin-digitalocean
15
15
  on:
16
16
  tags: true
17
+ rvm: 2.4.1
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.require_paths = ["lib"]
19
19
 
20
20
  spec.add_runtime_dependency 'kontena-cli', '>= 1.0'
21
- spec.add_runtime_dependency 'droplet_kit', '~> 2.0', '>= 2.0.1'
21
+ spec.add_runtime_dependency 'droplet_kit', '~> 2.2'
22
22
  spec.add_runtime_dependency 'activesupport', '~> 4.0'
23
23
  spec.add_development_dependency "bundler", "~> 1.11"
24
24
  spec.add_development_dependency "rake", "~> 10.0"
@@ -18,11 +18,6 @@ module Kontena
18
18
  end
19
19
 
20
20
  def run!(opts)
21
- abort('Invalid ssh key') unless File.exists?(File.expand_path(opts[:ssh_key]))
22
-
23
- ssh_key = ssh_key(File.read(File.expand_path(opts[:ssh_key])).strip)
24
- abort('Ssh key does not exist in Digital Ocean') unless ssh_key
25
-
26
21
  if opts[:ssl_cert]
27
22
  abort('Invalid ssl cert') unless File.exists?(File.expand_path(opts[:ssl_cert]))
28
23
  ssl_cert = File.read(File.expand_path(opts[:ssl_cert]))
@@ -45,7 +40,7 @@ module Kontena
45
40
  size: opts[:size],
46
41
  private_networking: true,
47
42
  user_data: user_data(userdata_vars),
48
- ssh_keys: [ssh_key.id],
43
+ ssh_keys: [opts[:ssh_key_id]],
49
44
  tags: ['master']
50
45
  )
51
46
 
@@ -89,10 +84,6 @@ module Kontena
89
84
  erb(File.read(cloudinit_template), vars)
90
85
  end
91
86
 
92
- def ssh_key(public_key)
93
- client.ssh_keys.all.find{|key| key.public_key == public_key}
94
- end
95
-
96
87
  def master_running?
97
88
  http_client.get(path: '/').status == 200
98
89
  rescue
@@ -19,11 +19,6 @@ module Kontena
19
19
  end
20
20
 
21
21
  def run!(opts)
22
- abort('Invalid ssh key') unless File.exists?(File.expand_path(opts[:ssh_key]))
23
-
24
- ssh_key = ssh_key(File.read(File.expand_path(opts[:ssh_key])).strip)
25
- abort('Ssh key does not exist in Digital Ocean') unless ssh_key
26
-
27
22
  userdata_vars = {
28
23
  version: opts[:version],
29
24
  master_uri: opts[:master_uri],
@@ -39,7 +34,7 @@ module Kontena
39
34
  size: opts[:size],
40
35
  private_networking: true,
41
36
  user_data: user_data(userdata_vars),
42
- ssh_keys: [ssh_key.id],
37
+ ssh_keys: [opts[:ssh_key_id]],
43
38
  tags: [opts[:grid]]
44
39
  )
45
40
  created = client.droplets.create(droplet)
@@ -0,0 +1,31 @@
1
+ module Kontena
2
+ module Machine
3
+ module DigitalOcean
4
+ class SshKeyManager
5
+
6
+ attr_reader :client
7
+
8
+ # @param [String] token Digital Ocean API token
9
+ def initialize(token)
10
+ @client = DropletKit::Client.new(access_token: token)
11
+ end
12
+
13
+ def find_by_public_key(public_key)
14
+ list.find { |key| key.public_key == public_key }
15
+ end
16
+
17
+ def list
18
+ client.ssh_keys.all.to_a
19
+ end
20
+
21
+ def create(public_key)
22
+ client.ssh_keys.create(DropletKit::SSHKey.new(public_key: public_key, name: public_key.split(/\s+/).last))
23
+ end
24
+
25
+ def find_or_create_by_public_key(public_key)
26
+ find_by_public_key(public_key) || create(public_key)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -5,3 +5,4 @@ require_relative 'digital_ocean/node_provisioner'
5
5
  require_relative 'digital_ocean/node_destroyer'
6
6
  require_relative 'digital_ocean/master_provisioner'
7
7
  require_relative 'digital_ocean/master_destroyer'
8
+ require_relative 'digital_ocean/ssh_key_manager'
@@ -10,7 +10,7 @@ module Kontena::Plugin::DigitalOcean::Master
10
10
  option "--token", "TOKEN", "DigitalOcean API token", environment_variable: "DO_TOKEN"
11
11
  option "--region", "REGION", "Region"
12
12
  option "--size", "SIZE", "Droplet size"
13
- option "--ssh-key", "SSH_KEY", "Path to ssh public key", default: '~/.ssh/id_rsa.pub'
13
+ option "--ssh-key", "SSH_KEY", "Path to ssh public key"
14
14
  option "--ssl-cert", "SSL CERT", "SSL certificate file"
15
15
  option "--vault-secret", "VAULT_SECRET", "Secret key for Vault (optional)"
16
16
  option "--vault-iv", "VAULT_IV", "Initialization vector for Vault (optional)"
@@ -19,17 +19,19 @@ module Kontena::Plugin::DigitalOcean::Master
19
19
 
20
20
 
21
21
  def execute
22
+ suppress_warnings # until DO merges resource_kit pr #32
22
23
  do_token = ask_do_token
23
24
 
24
25
  require_relative '../../../machine/digital_ocean'
25
26
 
26
27
  do_region = ask_droplet_region(do_token)
27
28
  do_size = ask_droplet_size(do_token, do_region)
29
+ do_ssh_key_id = ask_ssh_key(do_token)
28
30
 
29
31
  provisioner = provisioner(do_token)
30
32
  provisioner.run!(
31
33
  name: name,
32
- ssh_key: ssh_key,
34
+ ssh_key_id: do_ssh_key_id,
33
35
  ssl_cert: ssl_cert,
34
36
  size: do_size,
35
37
  region: do_region,
@@ -39,6 +41,8 @@ module Kontena::Plugin::DigitalOcean::Master
39
41
  initial_admin_code: SecureRandom.hex(16),
40
42
  mongodb_uri: mongodb_uri
41
43
  )
44
+ ensure
45
+ resume_warnings
42
46
  end
43
47
 
44
48
  # @param [String] token
@@ -9,12 +9,15 @@ module Kontena::Plugin::DigitalOcean::Master
9
9
  option "--force", :flag, "Force remove", default: false, attribute_name: :forced
10
10
 
11
11
  def execute
12
+ suppress_warnings # until DO merges resource_kit pr #32
12
13
  do_token = ask_do_token
13
14
  confirm_command(name) unless forced?
14
15
 
15
16
  require_relative '../../../machine/digital_ocean'
16
17
  destroyer = destroyer(do_token)
17
18
  destroyer.run!(name)
19
+ ensure
20
+ resume_warnings
18
21
  end
19
22
 
20
23
  # @param [String] token
@@ -9,13 +9,14 @@ module Kontena::Plugin::DigitalOcean::Nodes
9
9
  parameter "[NAME]", "Node name"
10
10
  option "--token", "TOKEN", "DigitalOcean API token", environment_variable: 'DO_TOKEN'
11
11
  option "--region", "REGION", "Region"
12
- option "--ssh-key", "SSH_KEY", "Path to ssh public key", default: '~/.ssh/id_rsa.pub'
12
+ option "--ssh-key", "SSH_KEY", "Path to ssh public key"
13
13
  option "--size", "SIZE", "Droplet size"
14
14
  option "--count", "COUNT", "How many droplets to create"
15
15
  option "--version", "VERSION", "Define installed Kontena version", default: 'latest'
16
16
  option "--channel", "CHANNEL", "Define CoreOS image channel"
17
17
 
18
18
  def execute
19
+ suppress_warnings # until DO merges resource_kit pr #32
19
20
  require_api_url
20
21
  require_current_grid
21
22
 
@@ -27,6 +28,7 @@ module Kontena::Plugin::DigitalOcean::Nodes
27
28
  coreos_channel = self.channel || ask_channel
28
29
  do_size = ask_droplet_size(do_token, do_region)
29
30
  do_count = ask_droplet_count
31
+ do_ssh_key_id = ask_ssh_key(do_token)
30
32
 
31
33
  grid = fetch_grid
32
34
  provisioner = provisioner(client(require_token), do_token)
@@ -34,7 +36,7 @@ module Kontena::Plugin::DigitalOcean::Nodes
34
36
  master_uri: api_url,
35
37
  grid_token: grid['token'],
36
38
  grid: current_grid,
37
- ssh_key: ssh_key,
39
+ ssh_key_id: do_ssh_key_id,
38
40
  name: name,
39
41
  size: do_size,
40
42
  count: do_count,
@@ -42,11 +44,13 @@ module Kontena::Plugin::DigitalOcean::Nodes
42
44
  version: version,
43
45
  channel: coreos_channel
44
46
  )
47
+ ensure
48
+ resume_warnings
45
49
  end
46
50
 
47
51
  def ask_droplet_count
48
52
  if self.count.nil?
49
- prompt.ask('How many droplets?: ', default: 1)
53
+ prompt.ask('How many droplets?:', default: 1)
50
54
  else
51
55
  self.count
52
56
  end
@@ -10,6 +10,7 @@ module Kontena::Plugin::DigitalOcean::Nodes
10
10
  option "--token", "TOKEN", "DigitalOcean API token", environment_variable: "DO_TOKEN"
11
11
 
12
12
  def execute
13
+ suppress_warnings # until DO merges resource_kit pr #32
13
14
  require_api_url
14
15
  require_current_grid
15
16
  do_token = ask_do_token
@@ -27,6 +28,8 @@ module Kontena::Plugin::DigitalOcean::Nodes
27
28
  else
28
29
  exit_with_error "Cannot find droplet #{pastel.cyan(name)} in DigitalOcean"
29
30
  end
31
+ ensure
32
+ resume_warnings
30
33
  end
31
34
  end
32
35
  end
@@ -11,6 +11,7 @@ module Kontena::Plugin::DigitalOcean::Nodes
11
11
  option "--force", :flag, "Force remove", default: false, attribute_name: :forced
12
12
 
13
13
  def execute
14
+ suppress_warnings # until DO merges resource_kit pr #32
14
15
  require_api_url
15
16
  require_current_grid
16
17
  token = require_token
@@ -22,6 +23,8 @@ module Kontena::Plugin::DigitalOcean::Nodes
22
23
  grid = client(require_token).get("grids/#{current_grid}")
23
24
  destroyer = destroyer(client(token), do_token)
24
25
  destroyer.run!(grid, node_name)
26
+ ensure
27
+ resume_warnings
25
28
  end
26
29
 
27
30
  # @param [Kontena::Client] client
@@ -1,7 +1,56 @@
1
1
  module Kontena::Plugin::DigitalOcean::Prompts
2
+
3
+ # Until DO merges https://github.com/digitalocean/resource_kit/pull/32
4
+ def suppress_warnings
5
+ @original_verbosity = $VERBOSE
6
+ $VERBOSE = nil
7
+ end
8
+
9
+ def resume_warnings
10
+ $VERBOSE = @original_verbosity
11
+ end
12
+
13
+ def ask_ssh_key(do_token)
14
+ manager = Kontena::Machine::DigitalOcean::SshKeyManager.new(do_token)
15
+
16
+ if self.ssh_key
17
+ puts self.ssh_key.inspect
18
+ public_key = File.read(self.ssh_key).strip
19
+ else
20
+ keys = manager.list
21
+ key_id = :new
22
+
23
+ default_path = File.join(Dir.home, '.ssh', 'id_rsa.pub')
24
+ default = File.exist?(default_path) ? File.read(default_path).strip : nil
25
+
26
+ unless keys.empty?
27
+ key = prompt.select("Choose SSH key:") do |menu|
28
+ i = 1
29
+ keys.each do |item|
30
+ menu.choice "#{item.name} (#{item.fingerprint})" , item
31
+ menu.default i if item.public_key == default
32
+ i += 1
33
+ end
34
+ menu.choice "Create new SSH key", :new
35
+ end
36
+ end
37
+
38
+ if key == :new
39
+
40
+ public_key = prompt.ask('SSH public key: (enter an ssh key in OpenSSH format "ssh-xxx xxxxx key_name")', default: default) do |q|
41
+ q.validate /^ssh-rsa \S+ \S+$/
42
+ end
43
+ else
44
+ public_key = key.public_key
45
+ end
46
+
47
+ manager.find_or_create_by_public_key(public_key).id
48
+ end
49
+ end
50
+
2
51
  def ask_do_token
3
52
  if self.token.nil?
4
- prompt.ask('DigitalOcean API token: ', echo: false)
53
+ prompt.ask('DigitalOcean API token:', echo: false)
5
54
  else
6
55
  self.token
7
56
  end
@@ -9,7 +58,7 @@ module Kontena::Plugin::DigitalOcean::Prompts
9
58
 
10
59
  def ask_droplet_region(do_token)
11
60
  if self.region.nil?
12
- prompt.select("Choose a datacenter region: ") do |menu|
61
+ prompt.select("Choose a datacenter region:") do |menu|
13
62
  do_client = DropletKit::Client.new(access_token: do_token)
14
63
  do_client.regions.all.sort_by{|r| r.slug }.each{ |region|
15
64
  menu.choice region.name, region.slug
@@ -22,12 +71,13 @@ module Kontena::Plugin::DigitalOcean::Prompts
22
71
 
23
72
  def ask_droplet_size(do_token, do_region)
24
73
  if self.size.nil?
25
- prompt.select("Choose droplet size: ") do |menu|
74
+ prompt.select("Choose droplet size:") do |menu|
26
75
  do_client = DropletKit::Client.new(access_token: do_token)
27
76
  do_client.sizes.all.to_a.select{ |s| s.memory > 1000 }.sort_by{|s| s.memory }.each{ |size|
77
+ #p size
28
78
  if size.regions.include?(do_region)
29
79
  memory = size.memory.to_i / 1024
30
- menu.choice "#{memory}GB/#{size.vcpus}CPU/#{size.disk}GB ($#{size.price_monthly.to_i}/mo)", size.slug
80
+ menu.choice "#{size.slug}: #{memory}GB/#{size.vcpus}CPU/#{size.disk}GB ($#{size.price_monthly.to_i}/mo)", size.slug
31
81
  end
32
82
  }
33
83
  end
@@ -43,7 +93,7 @@ module Kontena::Plugin::DigitalOcean::Prompts
43
93
  n['labels'] && n['labels'].include?('provider=digitalocean'.freeze)
44
94
  }
45
95
  raise "Did not find any nodes with label provider=digitalocean" if nodes.size == 0
46
- prompt.select("Select node: ") do |menu|
96
+ prompt.select("Select node:") do |menu|
47
97
  nodes.sort_by{|n| n['node_number'] }.reverse.each do |node|
48
98
  initial = node['initial_member'] ? '(initial) ' : ''
49
99
  menu.choice "#{node['name']} #{initial}", node['name']
@@ -55,7 +105,7 @@ module Kontena::Plugin::DigitalOcean::Prompts
55
105
  end
56
106
 
57
107
  def ask_channel
58
- prompt.select('Select CoreOS channel') do |menu|
108
+ prompt.select('Select Container Linux channel:') do |menu|
59
109
  menu.choice 'Stable', 'stable'
60
110
  menu.choice 'Beta', 'beta'
61
111
  menu.choice 'Alpha', 'alpha'
@@ -1,7 +1,7 @@
1
1
  module Kontena
2
2
  module Plugin
3
3
  module DigitalOcean
4
- VERSION = "0.3.0"
4
+ VERSION = "0.3.1.rc1"
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kontena-plugin-digitalocean
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1.rc1
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-02-14 00:00:00.000000000 Z
11
+ date: 2017-08-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kontena-cli
@@ -30,20 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '2.0'
34
- - - ">="
35
- - !ruby/object:Gem::Version
36
- version: 2.0.1
33
+ version: '2.2'
37
34
  type: :runtime
38
35
  prerelease: false
39
36
  version_requirements: !ruby/object:Gem::Requirement
40
37
  requirements:
41
38
  - - "~>"
42
39
  - !ruby/object:Gem::Version
43
- version: '2.0'
44
- - - ">="
45
- - !ruby/object:Gem::Version
46
- version: 2.0.1
40
+ version: '2.2'
47
41
  - !ruby/object:Gem::Dependency
48
42
  name: activesupport
49
43
  requirement: !ruby/object:Gem::Requirement
@@ -108,6 +102,7 @@ files:
108
102
  - lib/kontena/machine/digital_ocean/master_provisioner.rb
109
103
  - lib/kontena/machine/digital_ocean/node_destroyer.rb
110
104
  - lib/kontena/machine/digital_ocean/node_provisioner.rb
105
+ - lib/kontena/machine/digital_ocean/ssh_key_manager.rb
111
106
  - lib/kontena/plugin/digital_ocean.rb
112
107
  - lib/kontena/plugin/digital_ocean/master/create_command.rb
113
108
  - lib/kontena/plugin/digital_ocean/master/terminate_command.rb
@@ -134,12 +129,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
134
129
  version: '0'
135
130
  required_rubygems_version: !ruby/object:Gem::Requirement
136
131
  requirements:
137
- - - ">="
132
+ - - ">"
138
133
  - !ruby/object:Gem::Version
139
- version: '0'
134
+ version: 1.3.1
140
135
  requirements: []
141
136
  rubyforge_project:
142
- rubygems_version: 2.4.5
137
+ rubygems_version: 2.6.11
143
138
  signing_key:
144
139
  specification_version: 4
145
140
  summary: Kontena DigitalOcean plugin