pec 0.7.9 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +3 -2
- data/lib/pec.rb +17 -14
- data/lib/pec/command/base.rb +3 -2
- data/lib/pec/command/config.rb +4 -0
- data/lib/pec/command/destroy.rb +0 -1
- data/lib/pec/command/halt.rb +0 -1
- data/lib/pec/command/list.rb +4 -0
- data/lib/pec/command/status.rb +0 -1
- data/lib/pec/command/up.rb +10 -15
- data/lib/pec/config_file.rb +32 -0
- data/lib/pec/handler/networks.rb +9 -9
- data/lib/pec/handler/user_data.rb +2 -8
- data/lib/pec/handler/user_data/nic.rb +5 -6
- data/lib/pec/handler/user_data/nic/base.rb +1 -0
- data/lib/pec/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c127f2ce57f24e553a4a7a97e2e17a9b59e1d2f
|
4
|
+
data.tar.gz: 06ebdf5437d8f2bdb49525ce4b8adbec4863d830
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc8b80525f965822e16a933ce72a4bc49db5cc0d382d0f232081f9083b383ba1fc051b974c287823412128bafd3c63e4b171b98c44694b5c49c89f4abda4a938
|
7
|
+
data.tar.gz: 66bfed05fd07cf6700ff9137545934c0288dfbc2e87769e5f34884b8c7e33de71ce47155b497b53ac86f6e83225a684508e113d7e9b235dd9da12aa83e0104ea
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -31,7 +31,8 @@ create - /user_data/web_server.yaml.sample
|
|
31
31
|
$ pec config <hostname_regex> <hostname_regex>...
|
32
32
|
|
33
33
|
### Configure
|
34
|
-
#### Pec.yaml
|
34
|
+
#### Pec.yaml or Pec.yaml.erb
|
35
|
+
support format yaml,erb
|
35
36
|
```
|
36
37
|
# merge of yaml
|
37
38
|
_default_: &def
|
@@ -72,7 +73,7 @@ pyama-test002:
|
|
72
73
|
# include config
|
73
74
|
includes:
|
74
75
|
- path/to/a.yaml
|
75
|
-
- path/to/b.yaml
|
76
|
+
- path/to/b.yaml.erb
|
76
77
|
|
77
78
|
```
|
78
79
|
##### Detail
|
data/lib/pec.rb
CHANGED
@@ -6,6 +6,7 @@ require 'thor'
|
|
6
6
|
require 'ip'
|
7
7
|
require 'colorator'
|
8
8
|
require "pec/core"
|
9
|
+
require "pec/config_file"
|
9
10
|
require "pec/version"
|
10
11
|
require "pec/logger"
|
11
12
|
require "pec/configure"
|
@@ -31,21 +32,14 @@ module Pec
|
|
31
32
|
@_last_tenant = _tenant_name if _tenant_name != @_last_tenant
|
32
33
|
end
|
33
34
|
|
34
|
-
def self.load_config(config_name=
|
35
|
+
def self.load_config(config_name="Pec.yaml")
|
35
36
|
@_configure ||= []
|
36
|
-
config_name
|
37
|
-
merge_config(config_name).to_hash.reject {|k,v| k[0].match(/\_/) || k.match(/^includes$/) }.each do |host|
|
37
|
+
ConfigFile.new(config_name).load.to_hash.reject {|k,v| k[0].match(/\_/) || k.match(/^includes$/) }.each do |host|
|
38
38
|
@_configure << Pec::Configure.new(host)
|
39
39
|
end
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
base_config = YAML.load_file(config_name)
|
44
|
-
if include_files = base_config.to_hash.find{|k,v| k.match(/^includes$/) && !v.nil? }
|
45
|
-
YAML.load(File.read(config_name) + include_files[1].map {|f|File.read(f)}.join("\n"))
|
46
|
-
else
|
47
|
-
base_config
|
48
|
-
end
|
40
|
+
rescue => e
|
41
|
+
Pec::Logger.critical "configure error!"
|
42
|
+
raise e
|
49
43
|
end
|
50
44
|
|
51
45
|
def self.configure
|
@@ -53,11 +47,11 @@ module Pec
|
|
53
47
|
@_configure
|
54
48
|
end
|
55
49
|
|
56
|
-
def self.servers(hosts, options,
|
50
|
+
def self.servers(hosts, options, not_fetch)
|
57
51
|
self.configure.each do |config|
|
58
52
|
next if hosts.size > 0 && hosts.none? {|name| config.name.match(/^#{name}/)}
|
59
53
|
Pec.init_yao(config.tenant)
|
60
|
-
server = fetch_server(config)
|
54
|
+
server = fetch_server(config) unless not_fetch
|
61
55
|
yield(server, config)
|
62
56
|
end
|
63
57
|
end
|
@@ -102,6 +96,15 @@ module Pec
|
|
102
96
|
end
|
103
97
|
end
|
104
98
|
|
99
|
+
def self.processor_matching(source, klass)
|
100
|
+
source.keys.each do |k|
|
101
|
+
Object.const_get(klass.to_s).constants.each do |c|
|
102
|
+
object = Object.const_get("#{klass.to_s}::#{c}")
|
103
|
+
yield object if k.to_s == object.kind.to_s
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
105
108
|
def self.config_reset
|
106
109
|
@_configure = nil
|
107
110
|
end
|
data/lib/pec/command/base.rb
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
module Pec::Command
|
2
2
|
class Base
|
3
|
-
@fetch = false
|
4
3
|
def self.run(host_name, options)
|
5
4
|
before_do
|
6
|
-
Pec.servers(host_name, options,
|
5
|
+
Pec.servers(host_name, options, not_fetch) do |server,config|
|
7
6
|
task(host_name, options, server, config)
|
8
7
|
end
|
9
8
|
rescue => e
|
@@ -15,7 +14,9 @@ module Pec::Command
|
|
15
14
|
Pec::Logger.info("\t" + e.backtrace.join("\n\t"))
|
16
15
|
end
|
17
16
|
|
17
|
+
def self.not_fetch; end
|
18
18
|
def self.task(host_name, options, server, config); end
|
19
19
|
def self.before_do; end
|
20
|
+
|
20
21
|
end
|
21
22
|
end
|
data/lib/pec/command/config.rb
CHANGED
data/lib/pec/command/destroy.rb
CHANGED
data/lib/pec/command/halt.rb
CHANGED
data/lib/pec/command/list.rb
CHANGED
data/lib/pec/command/status.rb
CHANGED
data/lib/pec/command/up.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
module Pec::Command
|
2
2
|
class Up < Base
|
3
|
-
@fetch = true
|
4
3
|
def self.task(host_name, options, server, config)
|
5
4
|
case
|
6
5
|
when server.nil?
|
@@ -8,12 +7,16 @@ module Pec::Command
|
|
8
7
|
attribute = {name: config.name}
|
9
8
|
|
10
9
|
begin
|
11
|
-
processor_matching(config, Pec::Handler) do |klass|
|
12
|
-
|
10
|
+
Pec.processor_matching(config, Pec::Handler) do |klass|
|
11
|
+
if attr = klass.build(config)
|
12
|
+
attribute.deep_merge!(attr)
|
13
|
+
end
|
13
14
|
end
|
14
15
|
|
15
|
-
processor_matching(attribute, Pec::Handler) do |klass|
|
16
|
-
|
16
|
+
Pec.processor_matching(attribute, Pec::Handler) do |klass|
|
17
|
+
if attr = klass.post_build(config, attribute)
|
18
|
+
attribute.deep_merge!(attr)
|
19
|
+
end
|
17
20
|
end
|
18
21
|
|
19
22
|
Yao::Server.create(attribute)
|
@@ -22,8 +25,8 @@ module Pec::Command
|
|
22
25
|
Pec::Logger.critical(e)
|
23
26
|
Pec::Logger.warning "recovery start #{config.name}"
|
24
27
|
|
25
|
-
processor_matching(config, Pec::Handler) do |klass|
|
26
|
-
|
28
|
+
Pec.processor_matching(config, Pec::Handler) do |klass|
|
29
|
+
klass.recover(attribute)
|
27
30
|
end
|
28
31
|
Pec::Logger.warning "recovery success! #{config.name}"
|
29
32
|
end
|
@@ -36,13 +39,5 @@ module Pec::Command
|
|
36
39
|
end
|
37
40
|
end
|
38
41
|
|
39
|
-
def self.processor_matching(source, klass)
|
40
|
-
source.keys.each do |k|
|
41
|
-
Object.const_get(klass.to_s).constants.each do |c|
|
42
|
-
object = Object.const_get("#{klass.to_s}::#{c}")
|
43
|
-
yield object if k.to_s == object.kind.to_s
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
42
|
end
|
48
43
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'erb'
|
2
|
+
module Pec
|
3
|
+
class ConfigFile
|
4
|
+
attr_accessor :config_name
|
5
|
+
def initialize(config_name)
|
6
|
+
self.config_name = File.exist?("#{config_name}.erb") ? "#{config_name}.erb" : config_name
|
7
|
+
end
|
8
|
+
|
9
|
+
def load
|
10
|
+
base = read_file(config_name)
|
11
|
+
include_files = YAML.load(base).to_hash.find{|k,v| k.match(/^includes$/) && !v.nil? }
|
12
|
+
inc = include_files ? include_files[1].map {|f| read_file(f)}.join("\n") : ""
|
13
|
+
YAML.load(base + inc)
|
14
|
+
end
|
15
|
+
|
16
|
+
def read_file(file_name)
|
17
|
+
if File.exist?(file_name)
|
18
|
+
case
|
19
|
+
when file_name.match(/.erb$/)
|
20
|
+
erb = ERB.new(File.read(file_name), nil, '%-')
|
21
|
+
erb.result
|
22
|
+
when file_name.match(/.yaml$/) || file_name.match(/.yml$/)
|
23
|
+
File.read(file_name)
|
24
|
+
else
|
25
|
+
raise "not match file type must be yaml or erb"
|
26
|
+
end
|
27
|
+
else
|
28
|
+
raise "not file exiets! #{file_name}"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/pec/handler/networks.rb
CHANGED
@@ -24,10 +24,14 @@ module Pec::Handler
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def recover(attribute)
|
27
|
+
return unless attribute[:networks]
|
28
|
+
|
27
29
|
Pec::Logger.notice "start port recovery"
|
28
30
|
attribute[:networks].each do |port|
|
29
|
-
|
30
|
-
|
31
|
+
if port[:port]
|
32
|
+
Yao::Port.destroy(port[:port])
|
33
|
+
Pec::Logger.notice "port delete id:#{port[:port]}"
|
34
|
+
end
|
31
35
|
end
|
32
36
|
Pec::Logger.notice "complete port recovery"
|
33
37
|
end
|
@@ -58,13 +62,9 @@ module Pec::Handler
|
|
58
62
|
security_group(host)
|
59
63
|
) if host.security_group
|
60
64
|
|
61
|
-
network[CONFIG]
|
62
|
-
|
63
|
-
|
64
|
-
ops = Object.const_get("Pec::Handler::Networks::#{c}").build(network)
|
65
|
-
attribute.deep_merge!(ops)
|
66
|
-
end
|
67
|
-
end
|
65
|
+
Pec.processor_matching(network[CONFIG], Pec::Handler::Networks) do |klass|
|
66
|
+
ops = klass.build(network)
|
67
|
+
attribute.deep_merge!(ops) if ops
|
68
68
|
end
|
69
69
|
|
70
70
|
attribute
|
@@ -11,14 +11,8 @@ module Pec::Handler
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def self.post_build(host, attribute)
|
14
|
-
attribute
|
15
|
-
|
16
|
-
klass = Object.const_get("Pec::Handler::UserData::#{c}")
|
17
|
-
|
18
|
-
if klass.kind.to_s == k.to_s
|
19
|
-
attribute = klass.post_build(host, attribute)
|
20
|
-
end
|
21
|
-
end
|
14
|
+
Pec.processor_matching(attribute, Pec::Handler::UserData) do |klass|
|
15
|
+
attribute = klass.post_build(host, attribute)
|
22
16
|
end
|
23
17
|
attribute[:user_data] = Base64.encode64("#cloud-config\n" + attribute[:user_data].to_yaml) if attribute[:user_data]
|
24
18
|
attribute
|
@@ -8,12 +8,11 @@ module Pec::Handler
|
|
8
8
|
|
9
9
|
class << self
|
10
10
|
def post_build(host, attribute)
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
Object.const_get("Pec::Handler::UserData::Nic::#{_nic}")
|
11
|
+
nic = if host.os_type
|
12
|
+
os = Pec::Handler::UserData::Nic.constants.find do |c|
|
13
|
+
Object.const_get("Pec::Handler::UserData::Nic::#{c}").os_type.include?(host.os_type)
|
14
|
+
end
|
15
|
+
Object.const_get("Pec::Handler::UserData::Nic::#{os}")
|
17
16
|
else
|
18
17
|
Pec::Handler::UserData::Nic::Rhel
|
19
18
|
end
|
data/lib/pec/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kazuhiko yamashita
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-11-
|
11
|
+
date: 2015-11-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -152,6 +152,7 @@ files:
|
|
152
152
|
- lib/pec/command/status.rb
|
153
153
|
- lib/pec/command/up.rb
|
154
154
|
- lib/pec/config_error.rb
|
155
|
+
- lib/pec/config_file.rb
|
155
156
|
- lib/pec/configure.rb
|
156
157
|
- lib/pec/core.rb
|
157
158
|
- lib/pec/handler.rb
|