kontena-plugin-upcloud 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
- NmE3N2JkNzNjMWYwZDlhZjhjM2VmYmNiYjIzYjljNDUxMzY1Mjc0YQ==
4
+ MWJkMTY1MThhNDQ4ZmUyMzI0NTE1NTJkZjFhNGVmNTQ1MjY4NjA5YQ==
5
5
  data.tar.gz: !binary |-
6
- YmEwNTgzZjBiYzE0OTkxMWFjNjJjMzJhYWI5YzhlNjJmMTg3NjBkZg==
6
+ OWFhMWJkZWQyZmFlNTE5MmVkZTJiYTI3ZDYyYjE2M2JjYjEzZGIxMw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MTQ4MjNlNjM2Nzc2MzM4N2U4NzgyNTg0ZDgyYjYyZWVlODEzZTlmZjk4ZGU3
10
- ZWVjMmNjYjNjZjk0Y2ZjYzRkYmJjN2NjZDkzMzA0ODM1NzczMzEwZWI2MjY0
11
- NjQ1OWY0MTZhMjRmZGViM2ZmMGUyZDFmYzdhODg4ZmY4NDIxZDI=
9
+ ODNlNWQxOGNhMmQwNmI4MDhkMDkzMDBmNjJjYTYwN2ZiMDBkODg0ZGRjODVm
10
+ ZTM3OGNjYjE1NWQyYWMwMGMzMmNmYmViYjU1Y2MzZTY3YTIzM2I5NDMzZTQx
11
+ ZDY3ZTY4Njk0ZjRmOTkzNWIyOTE5YmJiMmE1MTliM2U3ZDA3MzA=
12
12
  data.tar.gz: !binary |-
13
- ZTk1YWQzNDc4YjIxNzEyNjY0MjZmN2Q3Y2YyMDBiY2IyZDE0OWYzYjNlNjBi
14
- Y2ZjNTc5MWM3N2I3YmMzOGUwYzkzZjUzOGVhYTNhMjc2ZjhiNjIzNjM2ZmFl
15
- OTUxODE0MWRiNGRmOTgwNDQ4OWRjMGI0ZDYzNTM5ODg3ZGVhZDA=
13
+ NDM0NTdkN2MyYzhiNzgzNTBlMmE4MzI5YjcyODdiM2I5MTY3YmY2YTM0Njdm
14
+ YmRjNGRlNzIyYzJkMjVhOTRkY2RiOTNkMjQ1MTJlOTZlMTk1ZjdjY2I1NGEy
15
+ OWQ3NWI5ZmEyY2VlMDg5OWViZjU3OWQzN2VjZWZmZDUwYmZlZDc=
@@ -89,11 +89,11 @@ coreos:
89
89
  --link kontena-server-mongo:mongodb \
90
90
  -e MONGODB_URI=mongodb://mongodb:27017/kontena_server \
91
91
  <% end -%>
92
- <% if server_name %>
93
- -e KONTENA_SERVER_NAME=<%= server_name %> \
92
+ <% if server_name -%>
93
+ -e SERVER_NAME=<%= server_name %> \
94
94
  <% end -%>
95
- <% if initial_admin_code %>
96
- -e KONTENA_INITIAL_ADMIN_CODE=<%= initial_admin_code %> \
95
+ <% if initial_admin_code -%>
96
+ -e INITIAL_ADMIN_CODE=<%= initial_admin_code %> \
97
97
  <% end -%>
98
98
  -e VAULT_KEY=${KONTENA_VAULT_KEY} -e VAULT_IV=${KONTENA_VAULT_IV} \
99
99
  kontena/server:${KONTENA_VERSION}
@@ -1,7 +1,6 @@
1
1
  require 'fileutils'
2
2
  require 'erb'
3
3
  require 'open3'
4
- require 'shell-spinner'
5
4
 
6
5
  module Kontena
7
6
  module Machine
@@ -10,7 +9,7 @@ module Kontena
10
9
  include RandomName
11
10
  include Machine::CertHelper
12
11
  include UpcloudCommon
13
- include Kontena::Cli::ShellSpinner
12
+ include Kontena::Cli::Common
14
13
 
15
14
  attr_reader :http_client, :username, :password
16
15
 
@@ -31,7 +30,7 @@ module Kontena
31
30
  abort('Invalid ssl cert') unless File.exists?(File.expand_path(opts[:ssl_cert]))
32
31
  ssl_cert = File.read(File.expand_path(opts[:ssl_cert]))
33
32
  else
34
- spinner "* Generating self-signed SSL certificate" do
33
+ spinner "Generating self-signed SSL certificate" do
35
34
  ssl_cert = generate_self_signed_cert
36
35
  end
37
36
  end
@@ -42,17 +41,26 @@ module Kontena
42
41
  abort('Server plan not found on Upcloud') unless plan = find_plan(opts[:plan])
43
42
  abort('Zone not found on Upcloud') unless zone_exist?(opts[:zone])
44
43
 
45
- hostname = generate_name
44
+ if opts[:name]
45
+ server_name = opts[:name]
46
+ hostname = opts[:name].start_with?('kontena-master') ? opts[:name] : "kontena-master-#{opts[:name]}"
47
+ else
48
+ hostname = generate_name
49
+ server_name = hostname.sub('kontena-master-', '')
50
+ end
51
+
52
+ server_name = opts[:name]
53
+ hostname = opts[:name] || generate_name
46
54
 
47
55
  userdata_vars = opts.merge(
48
56
  ssl_cert: ssl_cert,
49
- server_name: hostname.sub('kontena-master-', '')
57
+ server_name: server_name
50
58
  )
51
59
 
52
60
  device_data = {
53
61
  server: {
54
62
  zone: opts[:zone],
55
- title: "Kontena Master #{hostname}",
63
+ title: "Kontena Master #{server_name}",
56
64
  hostname: hostname,
57
65
  plan: plan[:name],
58
66
  vnc: 'off',
@@ -80,7 +88,7 @@ module Kontena
80
88
  }
81
89
  }.to_json
82
90
 
83
- spinner "* Creating Upcloud master #{hostname.colorize(:cyan)} " do
91
+ spinner "Creating Upcloud master #{hostname.colorize(:cyan)} " do
84
92
  response = post('server', body: device_data)
85
93
  if response.has_key?(:error)
86
94
  abort("\nUpcloud server creation failed (#{response[:error].fetch(:error_message, '')})")
@@ -103,16 +111,14 @@ module Kontena
103
111
  Excon.defaults[:ssl_verify_peer] = false
104
112
  @http_client = Excon.new("#{master_url}", :connect_timeout => 10)
105
113
 
106
- spinner "* Waiting for #{hostname.colorize(:cyan)} to start" do
107
- sleep 5 until master_running?
114
+ spinner "Waiting for #{hostname.colorize(:cyan)} to start" do
115
+ sleep 1 until master_running?
108
116
  end
109
117
 
110
- puts
111
- puts "Kontena Master is now running at #{master_url}".colorize(:green)
112
- puts
118
+ vfakespinner "Kontena Master is now running at #{master_url}"
113
119
 
114
120
  {
115
- name: hostname.sub('kontena-master-', ''),
121
+ name: server_name,
116
122
  public_ip: device_public_ip[:address],
117
123
  code: opts[:initial_admin_code]
118
124
  }
@@ -55,13 +55,13 @@ module Kontena
55
55
  end
56
56
  end
57
57
 
58
- ShellSpinner "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
- ShellSpinner "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
67
  puts "#{"WARNING".colorize(:red)}: Couldn't delete Upcloud storage '#{uuid.colorize(:cyan)}', check manually."
@@ -73,7 +73,7 @@ module Kontena
73
73
  end
74
74
  node = api_client.get("grids/#{grid['id']}/nodes")['nodes'].find{|n| n['name'] == name}
75
75
  if node
76
- ShellSpinner "Removing node #{name.colorize(:cyan)} from grid #{grid['name'].colorize(:cyan)} " do
76
+ spinner "Removing node #{name.colorize(:cyan)} from grid #{grid['name'].colorize(:cyan)} " do
77
77
  api_client.delete("grids/#{grid['id']}/nodes/#{name}")
78
78
  end
79
79
  end
@@ -9,8 +9,8 @@ module Kontena
9
9
  attr_reader :username
10
10
  attr_reader :password
11
11
 
12
- def client
13
- @client ||= Excon.new(
12
+ def upcloud_client
13
+ @upcloud_client ||= Excon.new(
14
14
  'https://api.upcloud.com',
15
15
  omit_default_port: true,
16
16
  user: username,
@@ -49,15 +49,13 @@ module Kontena
49
49
  end
50
50
 
51
51
  [:get, :post, :delete].each do |http_method|
52
- define_method http_method do |path, opts={}|
53
- response = client.send(
54
- http_method,
55
- opts.merge(
52
+ define_method http_method do |path, options={}|
53
+ response = upcloud_client.send(
54
+ http_method,
55
+ {
56
56
  path: File.join('/1.2', path),
57
- headers: {
58
- 'Content-Type': 'application/json'
59
- }
60
- )
57
+ headers: { 'Content-Type' => 'application/json' }
58
+ }.merge(options)
61
59
  )
62
60
  if response.body && response.body.start_with?('{')
63
61
  JSON.parse(response.body, symbolize_names: true)
@@ -1,9 +1,10 @@
1
1
  require 'securerandom'
2
2
 
3
3
  module Kontena::Plugin::Upcloud::Master
4
- class CreateCommand < Clamp::Command
4
+ class CreateCommand < Kontena::Command
5
5
  include Kontena::Cli::Common
6
-
6
+
7
+ option "--name", "[NAME]", "Set Kontena Master name"
7
8
  option "--username", "USER", "Upcloud username", required: true
8
9
  option "--password", "PASS", "Upcloud password", required: true
9
10
  option "--ssh-key", "SSH_KEY", "Path to ssh public key", required: true
@@ -17,10 +18,11 @@ module Kontena::Plugin::Upcloud::Master
17
18
 
18
19
  def execute
19
20
 
20
- require 'kontena/machine/upcloud'
21
+ require_relative '../../../machine/upcloud'
21
22
 
22
23
  provisioner = Kontena::Machine::Upcloud::MasterProvisioner.new(username, password)
23
24
  provisioner.run!(
25
+ name: self.name,
24
26
  ssh_key: ssh_key,
25
27
  ssl_cert: ssl_cert,
26
28
  plan: plan,
@@ -1,5 +1,5 @@
1
1
  module Kontena::Plugin::Upcloud::Nodes
2
- class CreateCommand < Clamp::Command
2
+ class CreateCommand < Kontena::Command
3
3
  include Kontena::Cli::Common
4
4
  include Kontena::Cli::GridOptions
5
5
 
@@ -11,13 +11,12 @@ module Kontena::Plugin::Upcloud::Nodes
11
11
  option "--zone", "ZONE", "Zone", default: 'fi-hel1'
12
12
  option "--version", "VERSION", "Define installed Kontena version", default: 'latest'
13
13
 
14
- def execute
15
- require_api_url
16
- require_current_grid
14
+ requires_current_master_token
17
15
 
18
- require 'kontena/machine/upcloud'
16
+ def execute
17
+ require_relative '../../../machine/upcloud'
19
18
  grid = fetch_grid
20
- provisioner = Kontena::Machine::Upcloud::NodeProvisioner.new(client(require_token), username, password)
19
+ provisioner = Kontena::Machine::Upcloud::NodeProvisioner.new(client, username, password)
21
20
  provisioner.run!(
22
21
  master_uri: api_url,
23
22
  grid_token: grid['token'],
@@ -33,7 +32,7 @@ module Kontena::Plugin::Upcloud::Nodes
33
32
  # @param [String] id
34
33
  # @return [Hash]
35
34
  def fetch_grid
36
- client(require_token).get("grids/#{current_grid}")
35
+ client.get("grids/#{current_grid}")
37
36
  end
38
37
 
39
38
  end
@@ -1,5 +1,5 @@
1
1
  module Kontena::Plugin::Upcloud::Nodes
2
- class RestartCommand < Clamp::Command
2
+ class RestartCommand < Kontena::Command
3
3
  include Kontena::Cli::Common
4
4
  include Kontena::Cli::GridOptions
5
5
 
@@ -1,5 +1,5 @@
1
1
  module Kontena::Plugin::Upcloud::Nodes
2
- class TerminateCommand < Clamp::Command
2
+ class TerminateCommand < Kontena::Command
3
3
  include Kontena::Cli::Common
4
4
  include Kontena::Cli::GridOptions
5
5
 
@@ -7,13 +7,12 @@ module Kontena::Plugin::Upcloud::Nodes
7
7
  option "--username", "USER", "Upcloud username", required: true
8
8
  option "--password", "PASS", "Upcloud password", required: true
9
9
 
10
- def execute
11
- require_api_url
12
- require_current_grid
10
+ requires_current_master_token
13
11
 
14
- require 'kontena/machine/upcloud'
15
- grid = client(require_token).get("grids/#{current_grid}")
16
- destroyer = Kontena::Machine::Upcloud::NodeDestroyer.new(client(require_token), username, password)
12
+ def execute
13
+ require_relative '../../../machine/upcloud'
14
+ grid = client.get("grids/#{current_grid}")
15
+ destroyer = Kontena::Machine::Upcloud::NodeDestroyer.new(client, username, password)
17
16
  destroyer.run!(grid, name)
18
17
  end
19
18
  end
@@ -1,7 +1,7 @@
1
1
  module Kontena
2
2
  module Plugin
3
3
  module Upcloud
4
- VERSION = "0.2.0.pre1"
4
+ VERSION = "0.2.0.pre2"
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-upcloud
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-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kontena-cli