hazetug 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -2
- data/hazetug.gemspec +4 -4
- data/lib/hazetug/cli/bootstrap.rb +3 -2
- data/lib/hazetug/haze.rb +43 -33
- data/lib/hazetug/haze/cloud_server.rb +5 -9
- data/lib/hazetug/hazetug.rb +0 -7
- data/lib/hazetug/net_ssh.rb +40 -0
- data/lib/hazetug/tug.rb +7 -19
- data/lib/hazetug/tug/knife.rb +2 -7
- data/lib/hazetug/tug/knife_base.rb +5 -0
- data/lib/hazetug/tug/solo.rb +2 -16
- data/lib/hazetug/version.rb +1 -1
- metadata +11 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a6c00796640e6ece747e594b00ba9920a6eb274c
|
4
|
+
data.tar.gz: b4547334fbbf7886ec879ec28973741eda037ae0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c2fb703a1956871aae50be4bc4e4d4c8482b1dca282a01b6693f157f01c8eae04194d95d3a0b829aaa3c590d9ca24cd7ac905325ce2e17880389b136393da865
|
7
|
+
data.tar.gz: 6cde17df0db9ceafc66365aaaec3872a8d03f90f9c17323b1a1198b64433c23559659f1af2c3500e8b126f1807e7a03893ae4f48b9dde163bbd39ef4950f378f
|
data/README.md
CHANGED
@@ -97,7 +97,7 @@ Hazetug uses [fog cloud library](http://fog.io) to be able to easily append othe
|
|
97
97
|
<td><b>Default value</b></td>
|
98
98
|
</tr>
|
99
99
|
<tr>
|
100
|
-
<td><b><i>
|
100
|
+
<td><b><i>attributes</i></b></td>
|
101
101
|
<td>Hash of attributes prepared for chef-solo run. (It's merged with the run_list).</td>
|
102
102
|
<td><i>{}</i><td>
|
103
103
|
</tr>
|
@@ -217,7 +217,6 @@ bootstrap:
|
|
217
217
|
}
|
218
218
|
}
|
219
219
|
```
|
220
|
-
```
|
221
220
|
|
222
221
|
Merged *attributes* with the *run_list* form the input data for running **chef-solo** they are available inside bootstrap.erb as `hazetug[:attributes_json]`. Berksfile can be set specifically in the bootstrap task list or if it's not set local *Berksfile* is tried by default.
|
223
222
|
|
data/hazetug.gemspec
CHANGED
@@ -19,11 +19,11 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.5"
|
22
|
-
spec.add_development_dependency "rake", "~> 0"
|
23
|
-
spec.add_dependency "psych", "~> 0"
|
24
|
-
spec.add_dependency "fog", "~> 0"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_dependency "psych", "~> 2.0"
|
24
|
+
spec.add_dependency "fog", "~> 1.0"
|
25
25
|
spec.add_dependency "chef", "~> 11.0"
|
26
26
|
spec.add_dependency "gli", "~> 2.0"
|
27
|
-
spec.add_dependency "agent", "~> 0"
|
27
|
+
spec.add_dependency "agent", "~> 0.0"
|
28
28
|
spec.add_dependency "berkshelf", "~> 3.0"
|
29
29
|
end
|
@@ -25,8 +25,9 @@ class Hazetug
|
|
25
25
|
|
26
26
|
def provision_and_bootstrap(haze, tug, channel, waitgroup)
|
27
27
|
haze.provision
|
28
|
+
|
28
29
|
if haze.ready?
|
29
|
-
tug.
|
30
|
+
haze.update_access_settings tug.config
|
30
31
|
|
31
32
|
tug.bootstrap({
|
32
33
|
args: data[:args],
|
@@ -36,7 +37,7 @@ class Hazetug
|
|
36
37
|
end
|
37
38
|
rescue
|
38
39
|
# Exeception will be lost, since we run inside goproc,
|
39
|
-
# ie. as soon as waitgroup is empty all
|
40
|
+
# ie. as soon as waitgroup is empty and all processes died.
|
40
41
|
puts $!.inspect
|
41
42
|
puts $@
|
42
43
|
ensure
|
data/lib/hazetug/haze.rb
CHANGED
@@ -2,14 +2,17 @@ require 'hazetug/config'
|
|
2
2
|
require 'hazetug/compute'
|
3
3
|
require 'hazetug/ui'
|
4
4
|
require 'hazetug/tug'
|
5
|
+
require 'hazetug/net_ssh'
|
5
6
|
require 'chef/mash'
|
6
7
|
|
7
8
|
class Hazetug
|
8
9
|
class Haze
|
9
10
|
include Hazetug::UI::Mixin
|
11
|
+
include Hazetug::NetSSH::Mixin
|
12
|
+
|
13
|
+
attr_reader :config, :compute_name
|
10
14
|
|
11
15
|
RE_BITS = /-?x(32)$|-?x(64)$|(32)bit|(64)bit/i
|
12
|
-
attr_reader :config, :compute, :compute_name, :server
|
13
16
|
|
14
17
|
def initialize(config={})
|
15
18
|
@compute_name = Hazetug.leaf_klass_name(self.class)
|
@@ -23,8 +26,12 @@ class Hazetug
|
|
23
26
|
provision_server
|
24
27
|
wait_for_ssh
|
25
28
|
rescue Fog::Errors::Error
|
29
|
+
# Catch fog errors, don't abort further execution
|
30
|
+
ui.error "[#{compute_name}] #{$!.inspect}"
|
31
|
+
rescue
|
32
|
+
# For unknown exceptions, notify and exit
|
26
33
|
ui.error "[#{compute_name}] #{$!.inspect}"
|
27
|
-
ui.msg
|
34
|
+
ui.msg $@
|
28
35
|
exit(1)
|
29
36
|
end
|
30
37
|
|
@@ -32,31 +39,32 @@ class Hazetug
|
|
32
39
|
@ready
|
33
40
|
end
|
34
41
|
|
35
|
-
def
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
42
|
+
def public_ip_address
|
43
|
+
end
|
44
|
+
|
45
|
+
def private_ip_address
|
46
|
+
end
|
47
|
+
|
48
|
+
# Update hash with haze access settings only if any available
|
49
|
+
def update_access_settings(hash)
|
50
|
+
{
|
51
|
+
compute_name: compute_name.downcase,
|
52
|
+
public_ip_address: (public_ip_address ||
|
53
|
+
(server and server.ssh_ip_address)),
|
54
|
+
private_ip_address: private_ip_address
|
55
|
+
}.inject(hash) do |hsh, (k, v)|
|
56
|
+
hsh[k] = v if v
|
57
|
+
hsh
|
41
58
|
end
|
42
|
-
Mash.new(self.class.defaults.merge(config))
|
43
59
|
end
|
44
60
|
|
45
61
|
class << self
|
46
62
|
def requires(*args)
|
47
|
-
|
48
|
-
@requires
|
49
|
-
else
|
50
|
-
@requires = args.flatten.dup
|
51
|
-
end
|
63
|
+
args.empty? ? @requires : @requires = args.flatten.dup
|
52
64
|
end
|
53
65
|
|
54
66
|
def defaults(hash=nil)
|
55
|
-
|
56
|
-
@defaults
|
57
|
-
else
|
58
|
-
@defaults = hash
|
59
|
-
end
|
67
|
+
hash.nil? ? @defaults : @defaults = hash
|
60
68
|
end
|
61
69
|
|
62
70
|
def [](haze_name)
|
@@ -65,21 +73,9 @@ class Hazetug
|
|
65
73
|
end
|
66
74
|
end
|
67
75
|
|
68
|
-
def public_ip_address
|
69
|
-
end
|
70
|
-
|
71
|
-
def private_ip_address
|
72
|
-
end
|
73
|
-
|
74
|
-
def config_for_tug
|
75
|
-
{
|
76
|
-
compute_name: compute_name.downcase,
|
77
|
-
public_ip_address: (public_ip_address || server.ssh_ip_address rescue nil),
|
78
|
-
private_ip_address: private_ip_address
|
79
|
-
}
|
80
|
-
end
|
81
|
-
|
82
76
|
protected
|
77
|
+
attr_accessor :server
|
78
|
+
attr_reader :compute
|
83
79
|
|
84
80
|
def provision_server
|
85
81
|
ui.error "#{compute_name} Provisioning is not impemented"
|
@@ -89,5 +85,19 @@ class Hazetug
|
|
89
85
|
ui.error "#{compute_name} Waiting for shh is not impemented"
|
90
86
|
end
|
91
87
|
|
88
|
+
private
|
89
|
+
|
90
|
+
def configure(config)
|
91
|
+
input = config.keys.map(&:to_sym)
|
92
|
+
requires = self.class.requires
|
93
|
+
|
94
|
+
unless (norequired = requires.select {|r| not input.include?(r)}).empty?
|
95
|
+
ui.error "Required options missing: #{norequired.join(', ')}"
|
96
|
+
raise ArgumentError, "Haze options missing"
|
97
|
+
end
|
98
|
+
|
99
|
+
Mash.new(self.class.defaults.merge(config))
|
100
|
+
end
|
101
|
+
|
92
102
|
end
|
93
103
|
end
|
@@ -4,20 +4,16 @@ class Hazetug
|
|
4
4
|
|
5
5
|
def provision_server
|
6
6
|
ui.info "[#{compute_name}] creating server #{config[:name]}"
|
7
|
-
|
7
|
+
self.server = compute.servers.create(server_args)
|
8
8
|
server.wait_for { ready? }
|
9
9
|
ui.info "[#{compute_name}] server #{config[:name]} created, ip: #{server.ssh_ip_address}"
|
10
10
|
end
|
11
11
|
|
12
12
|
def wait_for_ssh
|
13
|
-
|
14
|
-
|
15
|
-
ssh_options
|
16
|
-
|
17
|
-
ssh_options[:keys] = ssh_opts[:ssh_keys] || Hazetug.ssh_keys(compute_name)
|
18
|
-
server.username = ssh_opts[:ssh_user] || 'root'
|
19
|
-
server.ssh_port = ssh_opts[:ssh_port]
|
20
|
-
server.ssh_options = ssh_options
|
13
|
+
server.username = config[:ssh_user] || 'root'
|
14
|
+
server.ssh_port = config[:ssh_port]
|
15
|
+
server.ssh_options = net_ssh_options
|
16
|
+
|
21
17
|
ui.info "[#{compute_name}] waiting for active ssh on #{server.ssh_ip_address}"
|
22
18
|
server.wait_for(30) { sshable? }
|
23
19
|
@ready = true
|
data/lib/hazetug/hazetug.rb
CHANGED
@@ -20,12 +20,5 @@ class Hazetug
|
|
20
20
|
klass.name.split('::').last
|
21
21
|
end
|
22
22
|
end
|
23
|
-
|
24
|
-
def ssh_keys(compute_name=nil)
|
25
|
-
ssh_attr = []
|
26
|
-
ssh_attr << "#{compute_name.downcase}_ssh_keys" if compute_name
|
27
|
-
ssh_attr << "ssh_keys"
|
28
|
-
Hazetug::Config[ssh_attr.find {|a| Hazetug::Config[a]}]
|
29
|
-
end
|
30
23
|
end
|
31
24
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
class Hazetug
|
2
|
+
module NetSSH
|
3
|
+
|
4
|
+
module Mixin
|
5
|
+
NET_SSH_OPTIONS = [
|
6
|
+
:ssh_password, :ssh_port, :ssh_host_key_verify, :ssh_keys ]
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def net_ssh_options
|
11
|
+
@net_ssh_options ||= begin
|
12
|
+
hash = {}
|
13
|
+
ssh_opts = pick_ssh_options
|
14
|
+
hash[:password] = ssh_opts[:ssh_password]
|
15
|
+
hash[:paranoid] = ssh_opts[:host_key_verify] || false
|
16
|
+
hash[:keys] = ssh_opts[:ssh_keys] || NetSSH.ssh_keys(config[:compute_name])
|
17
|
+
hash[:port] = ssh_opts[:ssh_port]
|
18
|
+
hash
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def pick_ssh_options
|
23
|
+
NET_SSH_OPTIONS.inject({}) do |hash, k|
|
24
|
+
if value = (config[k])
|
25
|
+
hash[k] = value
|
26
|
+
end
|
27
|
+
hash
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.ssh_keys(compute_name=nil)
|
33
|
+
ssh_attr = []
|
34
|
+
ssh_attr << "#{compute_name.downcase}_ssh_keys" if compute_name
|
35
|
+
ssh_attr << "ssh_keys"
|
36
|
+
Hazetug::Config[ssh_attr.find {|a| Hazetug::Config[a]}]
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
data/lib/hazetug/tug.rb
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
require 'hazetug/tug/knife'
|
2
2
|
require 'hazetug/tug/solo'
|
3
3
|
require 'hazetug/ui'
|
4
|
+
require 'hazetug/net_ssh'
|
4
5
|
require 'chef/mash'
|
5
6
|
|
6
7
|
class Hazetug
|
7
8
|
class Tug
|
8
9
|
include Hazetug::UI::Mixin
|
9
|
-
|
10
|
-
SSH_OPTIONS = [
|
11
|
-
:ssh_user, :ssh_password, :ssh_port,
|
12
|
-
:ssh_host_key_verify, :ssh_keys
|
13
|
-
]
|
14
|
-
LOGDIR = "#{Dir.pwd}/logs"
|
10
|
+
include Hazetug::NetSSH::Mixin
|
15
11
|
|
16
12
|
attr_reader :config, :options
|
17
13
|
|
14
|
+
LOGDIR = "#{Dir.pwd}/logs"
|
15
|
+
|
18
16
|
def initialize(config={})
|
19
17
|
@config = config
|
20
18
|
end
|
@@ -28,35 +26,25 @@ class Hazetug
|
|
28
26
|
ip = config[:public_ip_address]
|
29
27
|
|
30
28
|
ui.msg "[#{tug_name}] bootstraping server #{config[:name]}, ip: #{ip}"
|
29
|
+
|
31
30
|
exit_status = bootstrap_server
|
32
31
|
|
33
32
|
if exit_status.is_a?(Fixnum) && exit_status != 0
|
34
33
|
ui.error "[#{tug_name}] bootstraping server #{config[:name]} failed."
|
35
34
|
else
|
35
|
+
|
36
36
|
ui.msg "[#{tug_name}] bootstraping server #{config[:name]} done."
|
37
37
|
end
|
38
|
+
|
38
39
|
rescue Hazetug::Exception => e
|
39
40
|
ui.error "[#{config[:compute_name]}] #{e.message}"
|
40
41
|
end
|
41
42
|
|
42
|
-
def load_haze_config(hash)
|
43
|
-
@config.merge!(hash)
|
44
|
-
end
|
45
|
-
|
46
43
|
class << self
|
47
44
|
def [](symbol_or_string)
|
48
45
|
klass = Hazetug.camel_case_name(symbol_or_string)
|
49
46
|
const_get(klass)
|
50
47
|
end
|
51
|
-
|
52
|
-
def ssh_options_from(config)
|
53
|
-
SSH_OPTIONS.inject({}) do |hash, k|
|
54
|
-
if value = (config[k])
|
55
|
-
hash[k] = value
|
56
|
-
end
|
57
|
-
hash
|
58
|
-
end
|
59
|
-
end
|
60
48
|
end
|
61
49
|
|
62
50
|
protected
|
data/lib/hazetug/tug/knife.rb
CHANGED
@@ -8,18 +8,13 @@ class Hazetug
|
|
8
8
|
|
9
9
|
def initialize(config={}, haze=nil)
|
10
10
|
super
|
11
|
-
|
12
|
-
:environment,
|
13
|
-
:chef_server_url,
|
11
|
+
[ :chef_server_url,
|
14
12
|
:validation_key
|
15
|
-
]
|
13
|
+
].inject(@chef_option_list, :<<)
|
16
14
|
end
|
17
15
|
|
18
16
|
def bootstrap_config
|
19
17
|
super
|
20
|
-
@chef_option_list.each do |opt|
|
21
|
-
Chef::Config[opt] = bootstrap_options[opt]
|
22
|
-
end
|
23
18
|
check_bootstrap_files! :validation_key, :template_file
|
24
19
|
end
|
25
20
|
|
@@ -55,6 +55,7 @@ class Hazetug
|
|
55
55
|
:ssh_password,
|
56
56
|
:host_key_verify
|
57
57
|
]
|
58
|
+
@chef_option_list = [ :environment ]
|
58
59
|
end
|
59
60
|
|
60
61
|
# Bootstraps the remote server using knife bootstrap.
|
@@ -78,6 +79,10 @@ class Hazetug
|
|
78
79
|
knife.config[opt] = bootstrap_options[opt]
|
79
80
|
end
|
80
81
|
|
82
|
+
@chef_option_list.each do |opt|
|
83
|
+
Chef::Config[opt] = bootstrap_options[opt]
|
84
|
+
end
|
85
|
+
|
81
86
|
# Check ssh identity
|
82
87
|
cred = [
|
83
88
|
hazetug_identity, bootstrap_options[:identity_file],
|
data/lib/hazetug/tug/solo.rb
CHANGED
@@ -27,7 +27,7 @@ class Hazetug
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def bootstrap_cleanup
|
30
|
-
ssh = Fog::SSH.new(config[:public_ip_address], ssh_username,
|
30
|
+
ssh = Fog::SSH.new(config[:public_ip_address], ssh_username, net_ssh_options)
|
31
31
|
ssh.run("test -f #{@upload_dest} && rm #{@upload_dest}")
|
32
32
|
end
|
33
33
|
|
@@ -46,7 +46,7 @@ class Hazetug
|
|
46
46
|
|
47
47
|
def upload_berks_package
|
48
48
|
berks_package do |path|
|
49
|
-
scp = Fog::SCP.new(config[:public_ip_address], ssh_username,
|
49
|
+
scp = Fog::SCP.new(config[:public_ip_address], ssh_username, net_ssh_options)
|
50
50
|
scp.upload(path, @upload_dest)
|
51
51
|
end
|
52
52
|
end
|
@@ -67,20 +67,6 @@ class Hazetug
|
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
|
-
private
|
71
|
-
|
72
|
-
def ssh_options
|
73
|
-
@ssh_options ||= begin
|
74
|
-
ssh_options = {}
|
75
|
-
ssh_opts = Hazetug::Tug.ssh_options_from(config)
|
76
|
-
ssh_options[:password] = ssh_opts[:ssh_password]
|
77
|
-
ssh_options[:paranoid] = ssh_opts[:host_key_verify] || false
|
78
|
-
ssh_options[:keys] = ssh_opts[:ssh_keys] || Hazetug.ssh_keys(config[:compute_name])
|
79
|
-
ssh_options[:port] = ssh_opts[:ssh_port]
|
80
|
-
ssh_options
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
70
|
def ssh_username
|
85
71
|
config[:ssh_user] || 'root'
|
86
72
|
end
|
data/lib/hazetug/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hazetug
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Denis Barishev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -30,42 +30,42 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
33
|
+
version: '10.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
40
|
+
version: '10.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: psych
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
47
|
+
version: '2.0'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
54
|
+
version: '2.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: fog
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
61
|
+
version: '1.0'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
68
|
+
version: '1.0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: chef
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -100,14 +100,14 @@ dependencies:
|
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '0'
|
103
|
+
version: '0.0'
|
104
104
|
type: :runtime
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '0'
|
110
|
+
version: '0.0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: berkshelf
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -150,6 +150,7 @@ files:
|
|
150
150
|
- lib/hazetug/haze/digital_ocean.rb
|
151
151
|
- lib/hazetug/haze/linode.rb
|
152
152
|
- lib/hazetug/hazetug.rb
|
153
|
+
- lib/hazetug/net_ssh.rb
|
153
154
|
- lib/hazetug/task.rb
|
154
155
|
- lib/hazetug/tug.rb
|
155
156
|
- lib/hazetug/tug/knife.rb
|