kontena-plugin-digitalocean 0.2.0.pre1 → 0.2.0.pre2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZTZhZjg5NDVkYzI2ZjZmY2EyMTA0ZDk4YTRjMWU0ZjZhMGNiOGVkYQ==
4
+ NTdhMmE4ZTZmOGQzMmRiOWM5NGE3ZTI1YzZlOTVmNTMxZWNiYWQ4ZA==
5
5
  data.tar.gz: !binary |-
6
- NTVkMjYyZTA1Y2E1NmZiNDVlOThhYWExNWZlODFlOTM2ODFlZWVhZQ==
6
+ NDBlMmI3YTJmY2YxZjlmMjQ4M2MwYzZjMmY4ZjhhNTM5ZjNjYWY1Ng==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NGUxZjRmNWU3ODBmYjVlMTRkY2JjZWQ2NjRjYmE4YmJkNjJiYjc5ZjJkYTYx
10
- ZGYxOWU2MTBjYmI4NzMwN2ZkNTFmODNkNzhmNmQ5ZmRkZmQzY2Y1ZTBiOWM3
11
- ZDMzNzM4ZTg2NzM5YWExODFjNTIzNzBiZWM0YzBkNDQ0NDNmMWI=
9
+ NWJlZGYxOGZiODc0YjRjMzY3YWY0NWQ5NWVkMjFmYjdiMjA4Y2IzNDQ0NWZl
10
+ MDUyZjU1NjI5YjczNjE1MWUzMWVlZGQ1MjQ5OWU5YjAzZDcyYzBlZWYyYzIz
11
+ NDFmZDZjMjQyNzQxNTlhZGFkNTIzMGY3ZjEwNmNlMDA4NTYyNWI=
12
12
  data.tar.gz: !binary |-
13
- ZDdkY2I3N2I3OGQ0NzJiNDY5ZDEzNjkwOWYyYWMzNTY1MWY2ZGQzYjkwMGE2
14
- MzQyYTM5NzhkMjcwNDMwOGRmNTQwMDJhZGRmYWNlZDkyYmE0NDFjZjU1MjQ5
15
- ZDIzMDdmOGZhMmM0ZDg4NTQ0ZWExNzJhOWMyNzAzYjQ0MTY5OGU=
13
+ YmY2OTgxZWIwZDRjZDdkMjVjZmIwZTAwNzk2Yjk4OWVmNjFjNjQzOWI2MWY1
14
+ MDg4OWNjZTExNDQ5NGYxODQyNTljMmJiMWZhOGVlYjgyOGJkNDIyMjA0ZmY5
15
+ ZDliNzMxM2QyNWM5NThmY2RmZjQxMmU1OWRiOWM5NTM1NDM2Yjc=
@@ -63,3 +63,4 @@ coreos:
63
63
  -v=/etc/kontena-agent.env:/etc/kontena.env \
64
64
  --net=host \
65
65
  kontena/agent:${KONTENA_VERSION}
66
+ ExecStop=/usr/bin/docker stop kontena-agent
@@ -54,6 +54,7 @@ coreos:
54
54
  ExecStart=/usr/bin/docker run --name=kontena-server-mongo \
55
55
  --volumes-from=kontena-server-mongo-data \
56
56
  mongo:3.0 mongod --smallfiles
57
+ ExecStop=/usr/bin/docker stop kontena-server-mongo
57
58
  <% end -%>
58
59
  - name: kontena-server-api.service
59
60
  command: start
@@ -89,14 +90,15 @@ coreos:
89
90
  --link kontena-server-mongo:mongodb \
90
91
  -e MONGODB_URI=mongodb://mongodb:27017/kontena_server \
91
92
  <% end -%>
92
- <% if server_name %>
93
- -e KONTENA_SERVER_NAME=<%= server_name %> \
93
+ <% if server_name -%>
94
+ -e SERVER_NAME=<%= server_name %> \
94
95
  <% end -%>
95
- <% if initial_admin_code %>
96
- -e KONTENA_INITIAL_ADMIN_CODE=<%= initial_admin_code %> \
96
+ <% if initial_admin_code -%>
97
+ -e INITIAL_ADMIN_CODE=<%= initial_admin_code %> \
97
98
  <% end -%>
98
99
  -e VAULT_KEY=${KONTENA_VAULT_KEY} -e VAULT_IV=${KONTENA_VAULT_IV} \
99
100
  kontena/server:${KONTENA_VERSION}
101
+ ExecStop=/usr/bin/docker stop kontena-server-api
100
102
 
101
103
  - name: kontena-server-haproxy.service
102
104
  command: start
@@ -121,3 +123,4 @@ coreos:
121
123
  ExecStartPre=-/usr/bin/docker rm kontena-server-haproxy
122
124
  ExecStartPre=-/usr/bin/docker pull kontena/haproxy:latest
123
125
  ExecStart=/opt/bin/kontena-haproxy.sh
126
+ ExecStop=/usr/bin/docker stop kontena-server-haproxy
@@ -29,32 +29,37 @@ module Kontena
29
29
  master_uri: opts[:master_uri],
30
30
  grid_token: opts[:grid_token],
31
31
  }
32
-
33
- droplet = DropletKit::Droplet.new(
34
- name: opts[:name] || generate_name,
35
- region: opts[:region],
36
- image: 'coreos-stable',
37
- size: opts[:size],
38
- private_networking: true,
39
- user_data: user_data(userdata_vars),
40
- ssh_keys: [ssh_key.id]
41
- )
42
- created = client.droplets.create(droplet)
43
- spinner "Creating DigitalOcean droplet #{droplet.name.colorize(:cyan)} " do
44
- sleep 1 until client.droplets.find(id: created.id).status == 'active'
32
+ droplets = []
33
+ opts[:count].to_i.times do
34
+ droplet = DropletKit::Droplet.new(
35
+ name: opts[:name] || generate_name,
36
+ region: opts[:region],
37
+ image: 'coreos-stable',
38
+ size: opts[:size],
39
+ private_networking: true,
40
+ user_data: user_data(userdata_vars),
41
+ ssh_keys: [ssh_key.id]
42
+ )
43
+ created = client.droplets.create(droplet)
44
+ spinner "Creating DigitalOcean droplet #{droplet.name.colorize(:cyan)} " do
45
+ sleep 1 until client.droplets.find(id: created.id).status == 'active'
46
+ end
47
+ droplets << droplet
45
48
  end
46
- node = nil
47
- spinner "Waiting for node #{droplet.name.colorize(:cyan)} join to grid #{opts[:grid].colorize(:cyan)} " do
48
- sleep 1 until node = droplet_exists_in_grid?(opts[:grid], droplet)
49
+ droplets.each do |droplet|
50
+ node = nil
51
+ spinner "Waiting for node #{droplet.name.colorize(:cyan)} join to grid #{opts[:grid].colorize(:cyan)} " do
52
+ sleep 1 until node = droplet_exists_in_grid?(opts[:grid], droplet)
53
+ end
54
+ set_labels(
55
+ node,
56
+ [
57
+ "region=#{opts[:region]}",
58
+ "az=#{opts[:region]}",
59
+ "provider=digitalocean"
60
+ ]
61
+ )
49
62
  end
50
- set_labels(
51
- node,
52
- [
53
- "region=#{opts[:region]}",
54
- "az=#{opts[:region]}",
55
- "provider=digitalocean"
56
- ]
57
- )
58
63
  end
59
64
 
60
65
  def user_data(vars)
@@ -1,7 +1,7 @@
1
1
  module Kontena
2
2
  module Plugin
3
3
  module DigitalOcean
4
- VERSION = "0.2.0.pre1"
4
+ VERSION = "0.2.0.pre2"
5
5
  end
6
6
  end
7
7
  end
@@ -1,15 +1,17 @@
1
1
  require 'securerandom'
2
+ require_relative '../prompts'
2
3
 
3
4
  module Kontena::Plugin::DigitalOcean::Master
4
5
  class CreateCommand < Kontena::Command
5
6
  include Kontena::Cli::Common
7
+ include Kontena::Plugin::DigitalOcean::Prompts
6
8
 
7
9
  option "--name", "[NAME]", "Set master name"
8
- option "--token", "TOKEN", "DigitalOcean API token", required: true
10
+ option "--token", "TOKEN", "DigitalOcean API token", environment_variable: "DO_TOKEN"
11
+ option "--region", "REGION", "Region"
12
+ option "--size", "SIZE", "Droplet size"
9
13
  option "--ssh-key", "SSH_KEY", "Path to ssh public key", default: '~/.ssh/id_rsa.pub'
10
14
  option "--ssl-cert", "SSL CERT", "SSL certificate file"
11
- option "--size", "SIZE", "Droplet size", default: '1gb'
12
- option "--region", "REGION", "Region", default: 'ams2'
13
15
  option "--vault-secret", "VAULT_SECRET", "Secret key for Vault (optional)"
14
16
  option "--vault-iv", "VAULT_IV", "Initialization vector for Vault (optional)"
15
17
  option "--mongodb-uri", "URI", "External MongoDB uri (optional)"
@@ -17,14 +19,19 @@ module Kontena::Plugin::DigitalOcean::Master
17
19
 
18
20
 
19
21
  def execute
20
- require 'kontena/machine/digital_ocean'
22
+ do_token = ask_do_token
21
23
 
22
- provisioner = provisioner(token)
24
+ require_relative '../../../machine/digital_ocean'
25
+
26
+ do_region = ask_droplet_region(do_token)
27
+ do_size = ask_droplet_size(do_token, do_region)
28
+
29
+ provisioner = provisioner(do_token)
23
30
  provisioner.run!(
24
31
  ssh_key: ssh_key,
25
32
  ssl_cert: ssl_cert,
26
- size: size,
27
- region: region,
33
+ size: do_size,
34
+ region: do_region,
28
35
  version: version,
29
36
  vault_secret: vault_secret || SecureRandom.hex(24),
30
37
  vault_iv: vault_iv || SecureRandom.hex(24),
@@ -1,34 +1,54 @@
1
+ require_relative '../prompts'
2
+
1
3
  module Kontena::Plugin::DigitalOcean::Nodes
2
4
  class CreateCommand < Kontena::Command
3
5
  include Kontena::Cli::Common
4
6
  include Kontena::Cli::GridOptions
7
+ include Kontena::Plugin::DigitalOcean::Prompts
5
8
 
6
9
  parameter "[NAME]", "Node name"
7
- option "--token", "TOKEN", "DigitalOcean API token", required: true
10
+ option "--token", "TOKEN", "DigitalOcean API token", environment_variable: 'DO_TOKEN'
11
+ option "--region", "REGION", "Region"
8
12
  option "--ssh-key", "SSH_KEY", "Path to ssh public key", default: '~/.ssh/id_rsa.pub'
9
- option "--size", "SIZE", "Droplet size", default: '1gb'
10
- option "--region", "REGION", "Region", default: 'ams2'
13
+ option "--size", "SIZE", "Droplet size"
14
+ option "--count", "COUNT", "How many droplets to create"
11
15
  option "--version", "VERSION", "Define installed Kontena version", default: 'latest'
12
16
 
13
17
  def execute
14
18
  require_api_url
15
19
  require_current_grid
16
20
 
17
- require 'kontena/machine/digital_ocean'
21
+ do_token = ask_do_token
22
+
23
+ require_relative '../../../machine/digital_ocean'
24
+
25
+ do_region = ask_droplet_region(do_token)
26
+ do_size = ask_droplet_size(do_token, do_region)
27
+ do_count = ask_droplet_count
28
+
18
29
  grid = fetch_grid
19
- provisioner = provisioner(client(require_token), token)
30
+ provisioner = provisioner(client(require_token), do_token)
20
31
  provisioner.run!(
21
32
  master_uri: api_url,
22
33
  grid_token: grid['token'],
23
34
  grid: current_grid,
24
35
  ssh_key: ssh_key,
25
36
  name: name,
26
- size: size,
27
- region: region,
37
+ size: do_size,
38
+ count: do_count,
39
+ region: do_region,
28
40
  version: version
29
41
  )
30
42
  end
31
43
 
44
+ def ask_droplet_count
45
+ if self.count.nil?
46
+ prompt.ask('How many droplets?: ', default: 1)
47
+ else
48
+ self.count
49
+ end
50
+ end
51
+
32
52
  # @param [Kontena::Client] client
33
53
  # @param [String] token
34
54
  def provisioner(client, token)
@@ -1,26 +1,31 @@
1
+ require_relative '../prompts'
2
+
1
3
  module Kontena::Plugin::DigitalOcean::Nodes
2
4
  class RestartCommand < Kontena::Command
3
5
  include Kontena::Cli::Common
4
6
  include Kontena::Cli::GridOptions
7
+ include Kontena::Plugin::DigitalOcean::Prompts
5
8
 
6
- parameter "NAME", "Node name"
7
- option "--token", "TOKEN", "DigitalOcean API token", required: true
9
+ parameter "[NAME]", "Node name"
10
+ option "--token", "TOKEN", "DigitalOcean API token", environment_variable: "DO_TOKEN"
8
11
 
9
12
  def execute
10
13
  require_api_url
11
14
  require_current_grid
15
+ do_token = ask_do_token
12
16
 
13
- require 'kontena/machine/digital_ocean'
17
+ require_relative '../../../machine/digital_ocean'
14
18
 
15
- client = DropletKit::Client.new(access_token: token)
16
- droplet = client.droplets.all.find{|d| d.name == name}
19
+ node_name = ask_node(require_token)
20
+ client = DropletKit::Client.new(access_token: do_token)
21
+ droplet = client.droplets.all.find{|d| d.name == node_name}
17
22
  if droplet
18
- spinner "Restarting DigitalOcean droplet #{name.colorize(:cyan)} " do
23
+ spinner "Restarting DigitalOcean droplet #{pastel.cyan(name)} " do
19
24
  client.droplet_actions.reboot(droplet_id: droplet.id)
20
25
  sleep 1 until client.droplets.find(id: droplet.id).status == 'active'
21
26
  end
22
27
  else
23
- abort "Cannot find droplet #{name.colorize(:cyan)} in DigitalOcean"
28
+ exit_with_error "Cannot find droplet #{pastel.cyan(name)} in DigitalOcean"
24
29
  end
25
30
  end
26
31
  end
@@ -1,19 +1,27 @@
1
+ require_relative '../prompts'
2
+
1
3
  module Kontena::Plugin::DigitalOcean::Nodes
2
4
  class TerminateCommand < Kontena::Command
3
5
  include Kontena::Cli::Common
4
6
  include Kontena::Cli::GridOptions
7
+ include Kontena::Plugin::DigitalOcean::Prompts
5
8
 
6
- parameter "NAME", "Node name"
7
- option "--token", "TOKEN", "DigitalOcean API token", required: true
9
+ parameter "[NAME]", "Node name"
10
+ option "--token", "TOKEN", "DigitalOcean API token", environment_variable: "DO_TOKEN"
11
+ option "--force", :flag, "Force remove", default: false, attribute_name: :forced
8
12
 
9
13
  def execute
10
14
  require_api_url
11
15
  require_current_grid
16
+ token = require_token
17
+ node_name = ask_node(token)
18
+ do_token = ask_do_token
19
+ confirm_command(node_name) unless forced?
12
20
 
13
- require 'kontena/machine/digital_ocean'
21
+ require_relative '../../../machine/digital_ocean'
14
22
  grid = client(require_token).get("grids/#{current_grid}")
15
- destroyer = destroyer(client(require_token), token)
16
- destroyer.run!(grid, name)
23
+ destroyer = destroyer(client(token), do_token)
24
+ destroyer.run!(grid, node_name)
17
25
  end
18
26
 
19
27
  # @param [Kontena::Client] client
@@ -0,0 +1,56 @@
1
+ module Kontena::Plugin::DigitalOcean::Prompts
2
+ def ask_do_token
3
+ if self.token.nil?
4
+ prompt.ask('DigitalOcean API token: ', echo: false)
5
+ else
6
+ self.token
7
+ end
8
+ end
9
+
10
+ def ask_droplet_region(do_token)
11
+ if self.region.nil?
12
+ prompt.select("Choose a datacenter region: ") do |menu|
13
+ do_client = DropletKit::Client.new(access_token: do_token)
14
+ do_client.regions.all.sort_by{|r| r.slug }.each{ |region|
15
+ menu.choice region.name, region.slug
16
+ }
17
+ end
18
+ else
19
+ self.region
20
+ end
21
+ end
22
+
23
+ def ask_droplet_size(do_token, do_region)
24
+ if self.size.nil?
25
+ prompt.select("Choose droplet size: ") do |menu|
26
+ do_client = DropletKit::Client.new(access_token: do_token)
27
+ do_client.sizes.all.to_a.select{ |s| s.memory > 1000 }.sort_by{|s| s.memory }.each{ |size|
28
+ if size.regions.include?(do_region)
29
+ 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
31
+ end
32
+ }
33
+ end
34
+ else
35
+ self.size
36
+ end
37
+ end
38
+
39
+ def ask_node(token)
40
+ if self.name.nil?
41
+ nodes = client(token).get("grids/#{current_grid}/nodes")
42
+ nodes = nodes['nodes'].select{ |n|
43
+ n['labels'] && n['labels'].include?('provider=digitalocean'.freeze)
44
+ }
45
+ raise "Did not find any nodes with label provider=digitalocean" if nodes.size == 0
46
+ prompt.select("Select node: ") do |menu|
47
+ nodes.sort_by{|n| n['node_number'] }.reverse.each do |node|
48
+ initial = node['initial_member'] ? '(initial) ' : ''
49
+ menu.choice "#{node['name']} #{initial}", node['name']
50
+ end
51
+ end
52
+ else
53
+ self.name
54
+ end
55
+ end
56
+ 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.2.0.pre1
4
+ version: 0.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: 2016-09-29 00:00:00.000000000 Z
11
+ date: 2016-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kontena-cli
@@ -114,6 +114,7 @@ files:
114
114
  - lib/kontena/plugin/digital_ocean/nodes/create_command.rb
115
115
  - lib/kontena/plugin/digital_ocean/nodes/restart_command.rb
116
116
  - lib/kontena/plugin/digital_ocean/nodes/terminate_command.rb
117
+ - lib/kontena/plugin/digital_ocean/prompts.rb
117
118
  - lib/kontena/plugin/digital_ocean_command.rb
118
119
  - lib/kontena_cli_plugin.rb
119
120
  homepage: https://github.com/kontena/kontena-plugin-digitalocean