kontena-plugin-upcloud 0.2.5 → 0.3.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: 1e47dc978aaba2e0fa7b92c722e42c877bfea8dd
4
- data.tar.gz: ca0d47f5807a4b43cf73d060928db67dee651ef4
3
+ metadata.gz: 2c4c7355ad5cb678eae3164eab3d4e7a431737b0
4
+ data.tar.gz: f2cacd22c569d7f9c71ea3dbfa10d54d385dc36a
5
5
  SHA512:
6
- metadata.gz: fae8d0e61d3b92cdc9127bdb0c5e072bed6919cbe648fd62efb3070c6b2ccce9d033b23202d425ecedb19c49be62b0a5962eaef526add7b3cd890fc1d5f717d4
7
- data.tar.gz: e8978798fcb8ead2e3a48f20a8248eba3f0a7d3acc09bf52fe572745cf35fb532b380df86dee85fdcba291f7cac77f6b390018b6952fa6241aea56c4e4e9cc7a
6
+ metadata.gz: 6ab242dc67aa75f27f53bae70f0c2cd1ccebc5d139e286ffdb725950a074982b6c45fef817d33f7cd6e21abb030595971f45461d2c57785732ffe2777f73ef84
7
+ data.tar.gz: 7ea9fb517948d7225fe869a542fcc0e7b742f1695f1147cb3846784c780384d6bf1318e17e8bb25bbf1c6cf0e0c15ee5938bac92a10279e22ede1a70d7b83138
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: "SWp7F0Gu07m6DYXYNMTL746xXsS1oGmv68XSf/6Af/gdEEPLfllJ0hsHK7D0tiXvtvUFlQ+zQr7WVSYavvdkoaPjTAICD3pL5U7yMla4v6MQl4Mohwr2LwUx9YC18Ij6HIjSsk2EUSqxTyANOqxcRi820nZZUtZeGpUsP0aO/yCyBQOQdLSGOVHi7oUMrKfCjjl9vjrKAOHvsvlM4XvB4EzRM2m2hoxkQBOFWVGRbZXWQUzMuLW1kh1WIScul2ObFWFMz8zBFkizIiEHktwlaqWst66w1464WRv/JcvUrEombyvvoJbeeByguhoa3Y614t1ESYDKH65oUVNQUhlAr1+iUqUJvdulIh2WAuyer3rHytEdXVfs8kbPLcVhqToPTUAV4mzJ1jFWttguDHUh5R4Y6UTw9jVbh+d7lfuE4y3ghwTvciCCdkYTHRHJIzDkOW6pKpOxW0cDaX3J/7Gh8lJ7asLsP16uqbrC3W0gpFBWmMnielDfXzWkrfPlZtR8N75SyHgw/fPHfcqvw1IadrZ8tsyAIHj7afdIhcBrd86UCvGW7feF0RUYlXevxs2aesAnujpJatTp23fCUBsbJywI7DmvuvWLwbTBumI1mEvyAbQh+lIy2oqeK1/3lUtmDkWey21fRt06hippKf40DiAXK4Gzn0HuYkQotc9GHeo="
9
9
  cache: bundler
@@ -13,4 +13,5 @@ deploy:
13
13
  api_key: $GEM_TOKEN
14
14
  gem: kontena-plugin-upcloud
15
15
  on:
16
- tags: true
16
+ tags: true
17
+ rvm: 2.4.1
@@ -27,10 +27,25 @@ write_files:
27
27
  nameserver 8.8.4.4
28
28
  coreos:
29
29
  units:
30
+ - name: update-on-boot.service
31
+ command: start
32
+ enable: true
33
+ content: |
34
+ [Unit]
35
+ Description=Trigger OS update on boot
36
+ After=update_engine.service
37
+ ConditionPathExists=!/etc/update-on-boot.lock
38
+ [Service]
39
+ Type=oneshot
40
+ TimeoutStartSec=0
41
+ ExecStart=/usr/bin/update_engine_client -update
42
+ ExecStart=/bin/touch /etc/update-on-boot.lock
43
+ ExecStartPost=/usr/sbin/reboot
30
44
  - name: etcd2.service
31
45
  command: start
32
46
  enable: true
33
47
  content: |
48
+ [Unit]
34
49
  Description=etcd 2.0
35
50
  After=docker.service
36
51
  [Service]
@@ -82,3 +97,4 @@ coreos:
82
97
  -v=/etc/kontena-agent.env:/etc/kontena.env \
83
98
  --net=host \
84
99
  kontena/agent:${KONTENA_VERSION}
100
+ ExecStop=/usr/bin/docker stop kontena-agent
@@ -50,7 +50,7 @@ module Kontena
50
50
  server_name = hostname.sub('kontena-master-', '')
51
51
  end
52
52
 
53
- server_name = opts[:name]
53
+ server_name = opts[:name]
54
54
  hostname = opts[:name] || generate_name
55
55
 
56
56
  userdata_vars = opts.merge(
@@ -61,7 +61,7 @@ module Kontena
61
61
  device_data = {
62
62
  server: {
63
63
  zone: opts[:zone],
64
- title: "Kontena Master #{server_name}",
64
+ title: server_name,
65
65
  hostname: hostname,
66
66
  plan: plan[:name],
67
67
  vnc: 'off',
@@ -26,19 +26,19 @@ module Kontena
26
26
  end
27
27
 
28
28
  server = servers[:servers][:server].find{|s| s[:hostname] == name}
29
-
30
- abort "Cannot find node #{name.colorize(:cyan)} in Upcloud" unless server
29
+
30
+ abort "Cannot find node #{name.colorize(:cyan)} in UpCloud" unless server
31
31
 
32
32
  server_data = get("server/#{server[:uuid]}")
33
33
 
34
34
  storage_devices = server_data.fetch(:server, {}).fetch(:storage_devices, {}).fetch(:storage_device, [])
35
35
  storage_uuids = storage_devices.map{|s| s[:storage]}
36
36
 
37
- abort('No storage devices found for Upcloud node') if storage_uuids.empty?
37
+ abort('No storage devices found for UpCloud node') if storage_uuids.empty?
38
38
 
39
39
  if server
40
40
  unless server[:state].eql?('stopped')
41
- spinner "Shutting down Upcloud node #{name.colorize(:cyan)} " do
41
+ spinner "Shutting down UpCloud node #{name.colorize(:cyan)} " do
42
42
  device_data = post(
43
43
  "server/#{server[:uuid]}/stop", body: {
44
44
  stop_server: {
@@ -55,26 +55,26 @@ module Kontena
55
55
  end
56
56
  end
57
57
 
58
- spinner "Terminating Upcloud node #{name.colorize(:cyan)} " do
58
+ spinner "Terminating UpCloud node #{name.colorize(:cyan)} " do
59
59
  response = delete("server/#{server[:uuid]}")
60
60
  abort "Cannot delete node #{name.colorize(:cyan)} in Upcloud" unless response[:success]
61
61
  end
62
62
 
63
63
  storage_uuids.each do |uuid|
64
- spinner "Deleting Upcloud storage device '#{uuid.colorize(:cyan)}' " do
64
+ spinner "Deleting UpCloud storage device '#{uuid.colorize(:cyan)}' " do
65
65
  response = delete("storage/#{uuid}")
66
66
  unless response[:success]
67
- puts "#{"WARNING".colorize(:red)}: Couldn't delete Upcloud storage '#{uuid.colorize(:cyan)}', check manually."
67
+ puts "#{"WARNING".colorize(:red)}: Couldn't delete UpCloud storage '#{uuid.colorize(:cyan)}', check manually."
68
68
  end
69
69
  end
70
70
  end
71
71
  else
72
- abort "Cannot find node #{name.colorize(:cyan)} in Upcloud"
72
+ abort "Cannot find node #{name.colorize(:cyan)} in UpCloud"
73
73
  end
74
74
  node = api_client.get("grids/#{grid['id']}/nodes")['nodes'].find{|n| n['name'] == name}
75
75
  if node
76
76
  spinner "Removing node #{name.colorize(:cyan)} from grid #{grid['name'].colorize(:cyan)} " do
77
- api_client.delete("grids/#{grid['id']}/nodes/#{name}")
77
+ api_client.delete("nodes/#{grid['id']}/#{node['id']}")
78
78
  end
79
79
  end
80
80
  end
@@ -28,6 +28,7 @@ module Kontena
28
28
 
29
29
  abort('Invalid ssh key') unless ssh_key && ssh_key.start_with?('ssh-')
30
30
 
31
+ count = opts[:count].to_i
31
32
  userdata_vars = {
32
33
  version: opts[:version],
33
34
  master_uri: opts[:master_uri],
@@ -35,63 +36,68 @@ module Kontena
35
36
  }
36
37
 
37
38
  abort_unless_api_access
38
-
39
+
39
40
  abort('CoreOS template not found on Upcloud') unless coreos_template = find_template('CoreOS Stable')
40
41
  abort('Server plan not found on Upcloud') unless plan = find_plan(opts[:plan])
41
42
  abort('Zone not found on Upcloud') unless zone_exist?(opts[:zone])
42
43
 
43
- hostname = generate_name
44
-
45
- device_data = {
46
- server: {
47
- zone: opts[:zone],
48
- title: "Kontena Grid #{opts[:grid]} Node #{hostname}",
49
- hostname: hostname,
50
- plan: plan[:name],
51
- vnc: 'off',
52
- timezone: 'UTC',
53
- user_data: user_data(userdata_vars),
54
- firewall: 'off',
55
- storage_devices: {
56
- storage_device: [
57
- {
58
- action: 'clone',
59
- storage: coreos_template[:uuid],
60
- title: "From template #{coreos_template[:title]}",
61
- size: plan[:storage_size],
62
- tier: 'maxiops'
44
+ count.times do |i|
45
+ if opts[:name]
46
+ hostname = count == 1 ? opts[:name] : "#{opts[:name]}-#{i + 1}"
47
+ else
48
+ hostname = generate_name
49
+ end
50
+ device_data = {
51
+ server: {
52
+ zone: opts[:zone],
53
+ title: "#{opts[:grid]}/#{hostname}",
54
+ hostname: hostname,
55
+ plan: plan[:name],
56
+ vnc: 'off',
57
+ timezone: 'UTC',
58
+ user_data: user_data(userdata_vars),
59
+ firewall: 'off',
60
+ storage_devices: {
61
+ storage_device: [
62
+ {
63
+ action: 'clone',
64
+ storage: coreos_template[:uuid],
65
+ title: "From template #{coreos_template[:title]}",
66
+ size: plan[:storage_size],
67
+ tier: 'maxiops'
68
+ }
69
+ ]
70
+ },
71
+ login_user: {
72
+ create_password: 'no',
73
+ username: 'root',
74
+ ssh_keys: {
75
+ ssh_key: [ssh_key]
63
76
  }
64
- ]
65
- },
66
- login_user: {
67
- create_password: 'no',
68
- username: 'root',
69
- ssh_keys: {
70
- ssh_key: [ssh_key]
71
77
  }
72
78
  }
73
- }
74
- }.to_json
79
+ }.to_json
75
80
 
76
- spinner "Creating Upcloud node #{hostname.colorize(:cyan)} " do
77
- response = post('server', body: device_data)
81
+ spinner "Creating UpCloud node #{hostname.colorize(:cyan)} " do
82
+ response = post('server', body: device_data)
78
83
 
79
- if response.has_key?(:error)
80
- abort("\nUpcloud server creation failed (#{response[:error].fetch(:error_message, '')})")
81
- end
82
- device_data = response[:server]
84
+ if response.has_key?(:error)
85
+ abort("\nUpCloud server creation failed (#{response[:error].fetch(:error_message, '')})")
86
+ end
87
+ device_data = response[:server]
83
88
 
84
- until device_data && device_data.fetch(:state, nil).to_s == 'maintenance'
85
- device_data = get("server/#{device[:uuid]}").fetch(:server, {}) rescue nil
86
- sleep 5
89
+ until device_data && device_data.fetch(:state, nil).to_s == 'maintenance'
90
+ device_data = get("server/#{device[:uuid]}").fetch(:server, {}) rescue nil
91
+ sleep 5
92
+ end
87
93
  end
88
- end
89
94
 
90
- node = nil
91
- spinner "Waiting for node #{hostname.colorize(:cyan)} join to grid #{opts[:grid].colorize(:cyan)} " do
92
- sleep 2 until node = node_exists_in_grid?(opts[:grid], hostname)
95
+ node = nil
96
+ spinner "Waiting for node #{hostname.colorize(:cyan)} join to grid #{opts[:grid].colorize(:cyan)} " do
97
+ sleep 2 until node = node_exists_in_grid?(opts[:grid], hostname)
98
+ end
99
+ set_labels(node, ["region=#{opts[:zone]}", "provider=upcloud"])
93
100
  end
94
- set_labels(node, ["region=#{opts[:zone]}", "provider=upcloud"])
95
101
  end
96
102
 
97
103
  def user_data(vars)
@@ -113,7 +119,7 @@ module Kontena
113
119
 
114
120
  def set_labels(node, labels)
115
121
  data = {labels: labels}
116
- api_client.put("nodes/#{node['id']}", data, {}, {'Kontena-Grid-Token' => node['grid']['token']})
122
+ api_client.put("nodes/#{node['grid']['id']}/#{node['id']}", data)
117
123
  end
118
124
  end
119
125
  end
@@ -26,7 +26,7 @@ module Kontena
26
26
  server = servers[:servers][:server].find{|s| s[:hostname] == name}
27
27
 
28
28
  if server
29
- spinner "Restarting Upcloud node #{name.colorize(:cyan)} " do
29
+ spinner "Restarting UpCloud node #{name.colorize(:cyan)} " do
30
30
  result = post(
31
31
  "server/#{server[:uuid]}/restart", body: {
32
32
  restart_server: {
@@ -38,11 +38,10 @@ module Kontena
38
38
  )
39
39
  end
40
40
  else
41
- abort "Cannot find node #{name.colorize(:cyan)} in Upcloud"
41
+ abort "Cannot find node #{name.colorize(:cyan)} in UpCloud"
42
42
  end
43
43
  end
44
44
  end
45
45
  end
46
46
  end
47
47
  end
48
-
@@ -1,7 +1,23 @@
1
1
  module Kontena
2
2
  module Plugin
3
3
  module Upcloud
4
- VERSION = "0.2.5"
4
+ VERSION = "0.3.0"
5
+
6
+ ZONES = {
7
+ 'nl-ams1' => 'Amsterdam #1',
8
+ 'us-chi1' => 'Chicago #1',
9
+ 'de-fra1' => 'Frankfurt #1',
10
+ 'fi-hel1' => 'Helsinki #1',
11
+ 'uk-lon1' => 'London #1',
12
+ 'sg-sin1' => 'Singapore #1'
13
+ }.freeze
14
+
15
+ PLANS = {
16
+ '1xCPU-1GB' => '1024MB / 1 CPU, 30GB MaxIOPS disk, 2048GB transfer',
17
+ '2xCPU-2GB' => '2048MB / 2 CPU, 50GB MaxIOPS disk, 3072GB transfer',
18
+ '4xCPU-4GB' => '4096MB / 4 CPU, 100GB MaxIOPS disk, 4096GB transfer',
19
+ '6xCPU-8GB' => '8192MB / 6 CPU, 200GB MaxIOPS disk, 8192GB transfer'
20
+ }.freeze
5
21
  end
6
22
  end
7
23
  end
@@ -5,22 +5,20 @@ module Kontena::Plugin::Upcloud::Master
5
5
  include Kontena::Cli::Common
6
6
 
7
7
  option "--name", "[NAME]", "Set Kontena Master name"
8
- option "--username", "USER", "Upcloud username", required: true
9
- option "--password", "PASS", "Upcloud password", required: true
10
- option "--ssh-key", "SSH_KEY", "Path to ssh public key", required: true
8
+ option "--username", "USER", "Upcloud username", required: true, environment_variable: 'UPCLOUD_USERNAME'
9
+ option "--password", "PASS", "Upcloud password", required: true, environment_variable: 'UPCLOUD_PASSWORD'
10
+ option "--ssh-key", "SSH_KEY", "Path to ssh public key", default: '~/.ssh/id_rsa.pub'
11
11
  option "--ssl-cert", "SSL CERT", "SSL certificate file (optional)"
12
- option "--plan", "PLAN", "Server plan", default: '1xCPU-1GB'
13
- option "--zone", "ZONE", "Zone", default: 'fi-hel1'
12
+ option "--plan", "PLAN", "Server plan", required: true
13
+ option "--zone", "ZONE", "Zone", required: true
14
14
  option "--vault-secret", "VAULT_SECRET", "Secret key for Vault (optional)"
15
15
  option "--vault-iv", "VAULT_IV", "Initialization vector for Vault (optional)"
16
16
  option "--mongodb-uri", "URI", "External MongoDB uri (optional)"
17
17
  option "--version", "VERSION", "Define installed Kontena version", default: 'latest'
18
18
 
19
19
  def execute
20
-
21
20
  require_relative '../../../machine/upcloud'
22
21
 
23
- provisioner = Kontena::Machine::Upcloud::MasterProvisioner.new(username, password)
24
22
  provisioner.run!(
25
23
  name: self.name,
26
24
  ssh_key: ssh_key,
@@ -35,5 +33,32 @@ module Kontena::Plugin::Upcloud::Master
35
33
  )
36
34
  end
37
35
 
36
+ def provisioner
37
+ Kontena::Machine::Upcloud::MasterProvisioner.new(username, password)
38
+ end
39
+
40
+ def default_username
41
+ prompt.ask('UpCloud username:', echo: true)
42
+ end
43
+
44
+ def default_password
45
+ prompt.ask('UpCloud password:', echo: false)
46
+ end
47
+
48
+ def default_plan
49
+ prompt.select("Choose plan:") do |menu|
50
+ Kontena::Plugin::Upcloud::PLANS.each do |plan, name|
51
+ menu.choice name, plan
52
+ end
53
+ end
54
+ end
55
+
56
+ def default_zone
57
+ prompt.select("Choose availability zone:") do |menu|
58
+ Kontena::Plugin::Upcloud::ZONES.each do |zone, name|
59
+ menu.choice name, zone
60
+ end
61
+ end
62
+ end
38
63
  end
39
64
  end
@@ -4,11 +4,12 @@ module Kontena::Plugin::Upcloud::Nodes
4
4
  include Kontena::Cli::GridOptions
5
5
 
6
6
  parameter "[NAME]", "Node name"
7
- option "--username", "USER", "Upcloud username", required: true
8
- option "--password", "PASS", "Upcloud password", required: true
9
- option "--ssh-key", "SSH_KEY", "Path to ssh public key", required: true
10
- option "--plan", "PLAN", "Server size", default: '1xCPU-1GB'
11
- option "--zone", "ZONE", "Zone", default: 'fi-hel1'
7
+ option "--username", "USER", "Upcloud username", required: true, environment_variable: 'UPCLOUD_USERNAME'
8
+ option "--password", "PASS", "Upcloud password", required: true, environment_variable: 'UPCLOUD_PASSWORD'
9
+ option "--ssh-key", "SSH_KEY", "Path to ssh public key", default: '~/.ssh/id_rsa.pub'
10
+ option "--count", "COUNT", "How many nodes should be created"
11
+ option "--zone", "ZONE", "Zone", required: true
12
+ option "--plan", "PLAN", "Server size", required: true
12
13
  option "--version", "VERSION", "Define installed Kontena version", default: 'latest'
13
14
 
14
15
  requires_current_master_token
@@ -22,6 +23,7 @@ module Kontena::Plugin::Upcloud::Nodes
22
23
  grid_token: grid['token'],
23
24
  grid: current_grid,
24
25
  ssh_key: ssh_key,
26
+ count: count,
25
27
  name: name,
26
28
  plan: plan,
27
29
  zone: zone,
@@ -35,5 +37,33 @@ module Kontena::Plugin::Upcloud::Nodes
35
37
  client.get("grids/#{current_grid}")
36
38
  end
37
39
 
40
+
41
+ def default_username
42
+ prompt.ask('UpCloud username:', echo: true)
43
+ end
44
+
45
+ def default_password
46
+ prompt.ask('UpCloud password:', echo: false)
47
+ end
48
+
49
+ def default_count
50
+ prompt.ask('How many servers:', default: 1)
51
+ end
52
+
53
+ def default_plan
54
+ prompt.select("Choose plan:") do |menu|
55
+ Kontena::Plugin::Upcloud::PLANS.each do |plan, name|
56
+ menu.choice name, plan
57
+ end
58
+ end
59
+ end
60
+
61
+ def default_zone
62
+ prompt.select("Choose availability zone:") do |menu|
63
+ Kontena::Plugin::Upcloud::ZONES.each do |zone, name|
64
+ menu.choice name, zone
65
+ end
66
+ end
67
+ end
38
68
  end
39
69
  end
@@ -4,8 +4,8 @@ module Kontena::Plugin::Upcloud::Nodes
4
4
  include Kontena::Cli::GridOptions
5
5
 
6
6
  parameter "NAME", "Node name"
7
- option "--username", "USER", "Upcloud username", required: true
8
- option "--password", "PASS", "Upcloud password", required: true
7
+ option "--username", "USER", "Upcloud username", required: true, environment_variable: 'UPCLOUD_USERNAME'
8
+ option "--password", "PASS", "Upcloud password", required: true, environment_variable: 'UPCLOUD_PASSWORD'
9
9
 
10
10
  def execute
11
11
  require_api_url
@@ -3,9 +3,9 @@ module Kontena::Plugin::Upcloud::Nodes
3
3
  include Kontena::Cli::Common
4
4
  include Kontena::Cli::GridOptions
5
5
 
6
- parameter "NAME", "Node name"
7
- option "--username", "USER", "Upcloud username", required: true
8
- option "--password", "PASS", "Upcloud password", required: true
6
+ parameter "[NAME]", "Node name"
7
+ option "--username", "USER", "Upcloud username", required: true, environment_variable: 'UPCLOUD_USERNAME'
8
+ option "--password", "PASS", "Upcloud password", required: true, environment_variable: 'UPCLOUD_PASSWORD'
9
9
 
10
10
  option '--force', :flag, "Force terminate", attribute_name: :forced
11
11
 
@@ -18,5 +18,27 @@ module Kontena::Plugin::Upcloud::Nodes
18
18
  destroyer = Kontena::Machine::Upcloud::NodeDestroyer.new(client, username, password)
19
19
  destroyer.run!(grid, name)
20
20
  end
21
+
22
+ def default_username
23
+ prompt.ask('UpCloud username:', echo: true)
24
+ end
25
+
26
+ def default_password
27
+ prompt.ask('UpCloud password:', echo: false)
28
+ end
29
+
30
+ def default_name
31
+ nodes = client.get("grids/#{current_grid}/nodes")
32
+ nodes = nodes['nodes'].select{ |n|
33
+ n['labels'] && n['labels'].include?('provider=upcloud'.freeze)
34
+ }
35
+ raise "Did not find any nodes with label provider=upcloud" if nodes.size == 0
36
+ prompt.select("Select node: ") do |menu|
37
+ nodes.sort_by{|n| n['node_number'] }.reverse.each do |node|
38
+ initial = node['initial_member'] ? '(initial) ' : ''
39
+ menu.choice "#{node['name']} #{initial}", node['name']
40
+ end
41
+ end
42
+ end
21
43
  end
22
44
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kontena-plugin-upcloud
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.3.0
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-01-03 00:00:00.000000000 Z
11
+ date: 2017-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kontena-cli