pec 0.7.8 → 0.7.9

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: 1a615c6aea01b3e516f72fc1806e0915730ec4a8
4
- data.tar.gz: 45adb312f61ef71c5206bb00b2ebca11d6d563ef
3
+ metadata.gz: 6e289abbff98834305ea24c1bb20d3858d548fc9
4
+ data.tar.gz: 6a1187c24347f8783d03f84179c543a317a46b8c
5
5
  SHA512:
6
- metadata.gz: 124c0ca363138d554dcad5fad3248574025c85c96cd1d4ae579481799443fd152e392053deb54c6f288d56f245c5ef26358d9b7f96e72570e7c6adaee16b82da
7
- data.tar.gz: fc002a6b3b3d6bef233c4638aedc420c793471ac6f21f1000a4f32c9626c6b5589b7b97f2a6f692bcd745d1cbe986034a42fed689057a06eb84372240b088d9a
6
+ metadata.gz: 7e51d042af1b21821fd38a505d01ad2c82b9e970866b284dd0479f020bc54616b08656883788c0c38b97e2928e73169e4287830a80e6f1133e8ac35b30b3e31b
7
+ data.tar.gz: 9ae349b52e0cb7cc154cabb69c40dbda8a406f9ab2e44eb98a52bd9d65025e3a376c339b59999e97c46960818877a297344647f7940c792581c096d9cf26c688
data/lib/pec.rb CHANGED
@@ -10,7 +10,6 @@ require "pec/version"
10
10
  require "pec/logger"
11
11
  require "pec/configure"
12
12
  require "pec/handler"
13
- require "pec/coordinate"
14
13
  require "pec/command"
15
14
  require "pec/sample"
16
15
  require "pec/init"
@@ -5,18 +5,29 @@ module Pec::Command
5
5
  case
6
6
  when server.nil?
7
7
  Pec::Logger.info "make start #{config.name}"
8
-
9
8
  attribute = {name: config.name}
10
- make_attribute(config, Pec::Handler) do |key, klass|
11
- attribute.deep_merge!(klass.build(config))
12
- end
13
9
 
14
- make_attribute(attribute, Pec::Coordinate) do |key, klass|
15
- attribute.deep_merge!(klass.build(config, attribute))
10
+ begin
11
+ processor_matching(config, Pec::Handler) do |klass|
12
+ attribute.deep_merge!(klass.build(config))
13
+ end
14
+
15
+ processor_matching(attribute, Pec::Handler) do |klass|
16
+ attribute.deep_merge!(klass.post_build(config, attribute))
17
+ end
18
+
19
+ Yao::Server.create(attribute)
20
+ Pec::Logger.info "create success! #{config.name}"
21
+ rescue => e
22
+ Pec::Logger.critical(e)
23
+ Pec::Logger.warning "recovery start #{config.name}"
24
+
25
+ processor_matching(config, Pec::Handler) do |klass|
26
+ attribute.deep_merge!(klass.recover(attribute))
27
+ end
28
+ Pec::Logger.warning "recovery success! #{config.name}"
16
29
  end
17
30
 
18
- Yao::Server.create(attribute)
19
- Pec::Logger.info "create success! #{config.name}"
20
31
  when server.status == "SHUTOFF"
21
32
  Yao::Server.start(server.id)
22
33
  Pec::Logger.info "start server: #{config.name}"
@@ -25,11 +36,11 @@ module Pec::Command
25
36
  end
26
37
  end
27
38
 
28
- def self.make_attribute(source, klass)
39
+ def self.processor_matching(source, klass)
29
40
  source.keys.each do |k|
30
41
  Object.const_get(klass.to_s).constants.each do |c|
31
42
  object = Object.const_get("#{klass.to_s}::#{c}")
32
- yield k, object if k.to_s == object.kind.to_s
43
+ yield object if k.to_s == object.kind.to_s
33
44
  end
34
45
  end
35
46
  end
@@ -4,5 +4,9 @@ module Pec
4
4
  def build(*args)
5
5
  raise "#{self.class.name} not defined method build"
6
6
  end
7
+
8
+ def post_build(*args); end
9
+
10
+ def recover(*args); end
7
11
  end
8
12
  end
@@ -23,6 +23,15 @@ module Pec::Handler
23
23
  }
24
24
  end
25
25
 
26
+ def recover(attribute)
27
+ Pec::Logger.notice "start port recovery"
28
+ attribute[:networks].each do |port|
29
+ Yao::Port.destroy(port[:port])
30
+ Pec::Logger.notice "port delete id:#{port[:port]}"
31
+ end
32
+ Pec::Logger.notice "complete port recovery"
33
+ end
34
+
26
35
  def validate(network)
27
36
  %w(
28
37
  bootproto
@@ -1,14 +1,27 @@
1
1
  module Pec::Handler
2
2
  class UserData
3
3
  extend Pec::Core
4
+ autoload :Nic, "pec/handler/user_data/nic"
4
5
  self.kind = 'user_data'
5
- class << self
6
- def build(host)
7
- user_data = host.user_data || {}
8
- user_data['fqdn'] = host.name if host.user_data && !host.user_data['fqdn']
9
- { user_data: user_data }
6
+
7
+ def self.build(host)
8
+ user_data = host.user_data || {}
9
+ user_data['fqdn'] = host.name if host.user_data && !host.user_data['fqdn']
10
+ { user_data: user_data }
11
+ end
12
+
13
+ def self.post_build(host, attribute)
14
+ attribute.keys.each do |k|
15
+ Pec::Handler::UserData.constants.each do |c|
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
10
22
  end
23
+ attribute[:user_data] = Base64.encode64("#cloud-config\n" + attribute[:user_data].to_yaml) if attribute[:user_data]
24
+ attribute
11
25
  end
12
26
  end
13
27
  end
14
-
@@ -1,21 +1,21 @@
1
- module Pec::Coordinate
1
+ module Pec::Handler
2
2
  class UserData::Nic
3
3
  extend Pec::Core
4
- autoload :Base, "pec/coordinate/user_data/nic/base"
5
- autoload :Rhel, "pec/coordinate/user_data/nic/rhel"
6
- autoload :Ubuntu, "pec/coordinate/user_data/nic/ubuntu"
4
+ autoload :Base, "pec/handler/user_data/nic/base"
5
+ autoload :Rhel, "pec/handler/user_data/nic/rhel"
6
+ autoload :Ubuntu, "pec/handler/user_data/nic/ubuntu"
7
7
  self.kind = 'networks'
8
8
 
9
9
  class << self
10
- def build(host, attribute)
11
- _nic = Pec::Coordinate::UserData::Nic.constants.reject {|c|c.to_s.downcase == "base"}.find do |c|
12
- host.os_type && Object.const_get("Pec::Coordinate::UserData::Nic::#{c}").os_type.include?(host.os_type)
10
+ def post_build(host, attribute)
11
+ _nic = Pec::Handler::UserData::Nic.constants.reject {|c|c.to_s.downcase == "base"}.find do |c|
12
+ host.os_type && Object.const_get("Pec::Handler::UserData::Nic::#{c}").os_type.include?(host.os_type)
13
13
  end
14
14
 
15
15
  nic = if _nic
16
- Object.const_get("Pec::Coordinate::UserData::Nic::#{_nic}")
16
+ Object.const_get("Pec::Handler::UserData::Nic::#{_nic}")
17
17
  else
18
- Pec::Coordinate::UserData::Nic::Rhel
18
+ Pec::Handler::UserData::Nic::Rhel
19
19
  end
20
20
 
21
21
  attribute.deep_merge(
@@ -1,4 +1,4 @@
1
- module Pec::Coordinate
1
+ module Pec::Handler
2
2
  class UserData::Nic::Base
3
3
  class << self
4
4
  NAME = 0
@@ -1,4 +1,4 @@
1
- module Pec::Coordinate
1
+ module Pec::Handler
2
2
  class UserData::Nic
3
3
  class Rhel < Base
4
4
  self.os_type = %w(centos rhel)
@@ -1,4 +1,4 @@
1
- module Pec::Coordinate
1
+ module Pec::Handler
2
2
  class UserData::Nic
3
3
  class Ubuntu < Base
4
4
  self.os_type = %w(ubuntu)
@@ -1,3 +1,3 @@
1
1
  module Pec
2
- VERSION = "0.7.8"
2
+ VERSION = "0.7.9"
3
3
  end
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.7.8
4
+ version: 0.7.9
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-17 00:00:00.000000000 Z
11
+ date: 2015-11-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -153,12 +153,6 @@ files:
153
153
  - lib/pec/command/up.rb
154
154
  - lib/pec/config_error.rb
155
155
  - lib/pec/configure.rb
156
- - lib/pec/coordinate.rb
157
- - lib/pec/coordinate/user_data.rb
158
- - lib/pec/coordinate/user_data/nic.rb
159
- - lib/pec/coordinate/user_data/nic/base.rb
160
- - lib/pec/coordinate/user_data/nic/rhel.rb
161
- - lib/pec/coordinate/user_data/nic/ubuntu.rb
162
156
  - lib/pec/core.rb
163
157
  - lib/pec/handler.rb
164
158
  - lib/pec/handler/availability_zone.rb
@@ -170,6 +164,10 @@ files:
170
164
  - lib/pec/handler/networks/ip_address.rb
171
165
  - lib/pec/handler/templates.rb
172
166
  - lib/pec/handler/user_data.rb
167
+ - lib/pec/handler/user_data/nic.rb
168
+ - lib/pec/handler/user_data/nic/base.rb
169
+ - lib/pec/handler/user_data/nic/rhel.rb
170
+ - lib/pec/handler/user_data/nic/ubuntu.rb
173
171
  - lib/pec/init.rb
174
172
  - lib/pec/logger.rb
175
173
  - lib/pec/sample.rb
@@ -1,5 +0,0 @@
1
- module Pec
2
- module Coordinate
3
- autoload :UserData, "pec/coordinate/user_data"
4
- end
5
- end
@@ -1,21 +0,0 @@
1
- module Pec::Coordinate
2
- class UserData
3
- extend Pec::Core
4
- autoload :Nic, "pec/coordinate/user_data/nic"
5
- self.kind = 'user_data'
6
-
7
- def self.build(host, attribute)
8
- attribute.keys.each do |k|
9
- Pec::Coordinate::UserData.constants.each do |c|
10
- klass = Object.const_get("Pec::Coordinate::UserData::#{c}")
11
-
12
- if klass.kind.to_s == k.to_s
13
- attribute = klass.build(host, attribute)
14
- end
15
- end
16
- end
17
- attribute[:user_data] = Base64.encode64("#cloud-config\n" + attribute[:user_data].to_yaml) if attribute[:user_data]
18
- attribute
19
- end
20
- end
21
- end