pec 0.8.0 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4c127f2ce57f24e553a4a7a97e2e17a9b59e1d2f
4
- data.tar.gz: 06ebdf5437d8f2bdb49525ce4b8adbec4863d830
3
+ metadata.gz: 8e7978ae9aa271cb3d4eda126f8945a7393f1b2e
4
+ data.tar.gz: 7f4ff934b5ec8aaa6e788f8b8b74c4e374b39f99
5
5
  SHA512:
6
- metadata.gz: bc8b80525f965822e16a933ce72a4bc49db5cc0d382d0f232081f9083b383ba1fc051b974c287823412128bafd3c63e4b171b98c44694b5c49c89f4abda4a938
7
- data.tar.gz: 66bfed05fd07cf6700ff9137545934c0288dfbc2e87769e5f34884b8c7e33de71ce47155b497b53ac86f6e83225a684508e113d7e9b235dd9da12aa83e0104ea
6
+ metadata.gz: 214dce3511f37d2b170e5f167d2953ac80497c741459a20dc597709c7f8080cf94280f7cd1aaa58b756ce9682c6fdb860e8a65045be1e86778f6791497c902d8
7
+ data.tar.gz: 3bc0861d03adcbd7f12dbf5b45c486605fd43ff31897914806b0af551900a1953bce6ccb88a477a456d2c64cdc1d171e47f3463665de14ec853390e9358e9f81
data/lib/pec.rb CHANGED
@@ -47,9 +47,9 @@ module Pec
47
47
  @_configure
48
48
  end
49
49
 
50
- def self.servers(hosts, options, not_fetch)
50
+ def self.servers(filter_hosts, not_fetch)
51
51
  self.configure.each do |config|
52
- next if hosts.size > 0 && hosts.none? {|name| config.name.match(/^#{name}/)}
52
+ next if filter_hosts.size > 0 && filter_hosts.none? {|name| config.name.match(/^#{name}/)}
53
53
  Pec.init_yao(config.tenant)
54
54
  server = fetch_server(config) unless not_fetch
55
55
  yield(server, config)
@@ -106,7 +106,20 @@ module Pec
106
106
  end
107
107
 
108
108
  def self.config_reset
109
- @_configure = nil
109
+ %w(
110
+ _configure
111
+ _tenant_list
112
+ _server_list
113
+ _flavor_list
114
+ ).each do |name|
115
+ instance_variable_set("@#{name}".to_sym, nil)
116
+ end
117
+ end
118
+
119
+ def self.options(opt=nil)
120
+ @_opt ||= {}
121
+ @_opt = opt if opt
122
+ @_opt
110
123
  end
111
124
  end
112
125
 
data/lib/pec/cli.rb CHANGED
@@ -8,24 +8,24 @@ module Pec
8
8
  end
9
9
 
10
10
  desc 'up [HOSTNAME1, HOSTNAME2, ...]', 'create vm by Pec.yaml'
11
- def up(*hosts)
12
- _sub_command(hosts, options)
11
+ def up(*filter_hosts)
12
+ _sub_command(filter_hosts, options)
13
13
  end
14
14
 
15
15
  option :force , type: :boolean, aliases: "-f"
16
16
  desc "destroy [HOSTNAME1, HOSTNAME2, ...]", "delete vm"
17
- def destroy(*hosts)
18
- _sub_command(hosts, options)
17
+ def destroy(*filter_hosts)
18
+ _sub_command(filter_hosts, options)
19
19
  end
20
20
 
21
21
  desc "halt [HOSTNAME1, HOSTNAME2, ...]", "halt vm"
22
- def halt(*hosts)
23
- _sub_command(hosts, options)
22
+ def halt(*filter_hosts)
23
+ _sub_command(filter_hosts, options)
24
24
  end
25
25
 
26
26
  desc "status [HOSTNAME1, HOSTNAME2, ...]", "vm status"
27
- def status(*hosts)
28
- _sub_command(hosts, options)
27
+ def status(*filter_hosts)
28
+ _sub_command(filter_hosts, options)
29
29
  end
30
30
 
31
31
  desc "list", "vm list"
@@ -34,8 +34,8 @@ module Pec
34
34
  end
35
35
 
36
36
  desc "config [HOSTNAME1, HOSTNAME2, ...]", "show configure"
37
- def config(*hosts)
38
- _sub_command(hosts, options)
37
+ def config(*filter_hosts)
38
+ _sub_command(filter_hosts, options)
39
39
  end
40
40
 
41
41
  map %w[--version -v] => :__print_version
@@ -45,8 +45,9 @@ module Pec
45
45
  end
46
46
 
47
47
  no_commands do
48
- def _sub_command(hosts, options)
49
- Object.const_get("Pec::Command::#{caller[0][/`([^']*)'/, 1].capitalize}").run(hosts, options)
48
+ def _sub_command(filter_hosts, options)
49
+ Pec.options options
50
+ Object.const_get("Pec::Command::#{caller[0][/`([^']*)'/, 1].capitalize}").run(filter_hosts)
50
51
  end
51
52
  end
52
53
  end
@@ -1,10 +1,11 @@
1
1
  module Pec::Command
2
2
  class Base
3
- def self.run(host_name, options)
3
+ def self.run(filter_hosts)
4
4
  before_do
5
- Pec.servers(host_name, options, not_fetch) do |server,config|
6
- task(host_name, options, server, config)
5
+ Pec.servers(filter_hosts, not_fetch) do |server,config|
6
+ task(server, config)
7
7
  end
8
+ after_do
8
9
  rescue => e
9
10
  print_exception(e)
10
11
  end
@@ -15,8 +16,9 @@ module Pec::Command
15
16
  end
16
17
 
17
18
  def self.not_fetch; end
18
- def self.task(host_name, options, server, config); end
19
+ def self.task(server, config); end
19
20
  def self.before_do; end
21
+ def self.after_do; end
20
22
 
21
23
  end
22
24
  end
@@ -1,6 +1,6 @@
1
1
  module Pec::Command
2
2
  class Config < Base
3
- def self.task(host_name, options, server, config)
3
+ def self.task(server, config)
4
4
  puts YAML.dump(config.inspect[0] => config.inspect[1])
5
5
  end
6
6
 
@@ -1,10 +1,10 @@
1
1
  module Pec::Command
2
2
  class Destroy < Base
3
- def self.task(host_name, options, server, config)
3
+ def self.task(server, config)
4
4
  unless server
5
5
  Pec::Logger.notice "not be created #{config.name}"
6
6
  else
7
- if options[:force] || Thor.new.yes?("#{config.name}: Are you sure you want to destroy the '#{config.name}' VM? [y/N]")
7
+ if Pec.options[:force] || Thor.new.yes?("#{config.name}: Are you sure you want to destroy the '#{config.name}' VM? [y/N]")
8
8
  Yao::Server.destroy(server.id)
9
9
  Pec::Logger.info "#{config.name} is deleted!"
10
10
  end
@@ -1,6 +1,6 @@
1
1
  module Pec::Command
2
2
  class Halt < Base
3
- def self.task(host_name, options, server, config)
3
+ def self.task(server, config)
4
4
  case
5
5
  when server.nil?
6
6
  Pec::Logger.notice "not be created #{config.name}"
@@ -1,6 +1,6 @@
1
1
  module Pec::Command
2
2
  class Init < Base
3
- def self.run(host_name, options)
3
+ def self.run
4
4
  Pec::Init.show_env_setting
5
5
  Pec::Init.create_template_dir
6
6
  Pec::Init.create_sample_config
@@ -1,6 +1,6 @@
1
1
  module Pec::Command
2
2
  class List < Base
3
- def self.task(host_name, options, server, config)
3
+ def self.task(server, config)
4
4
  puts sprintf(
5
5
  " %-35s",
6
6
  config.name
@@ -1,13 +1,21 @@
1
1
  module Pec::Command
2
2
  class Status < Base
3
- def self.task(host_name, options, server, config)
3
+ def self.task(server, config)
4
4
  if server
5
+ tenant_name = safe_delete(config.name, config.tenant, :tenant) do
6
+ Pec.fetch_tenant_by_id(server).name
7
+ end
8
+
9
+ flavor_name = safe_delete(config.name, config.flavor, :flavor) do
10
+ Pec.fetch_flavor(server).name
11
+ end
12
+
5
13
  puts sprintf(
6
14
  " %-35s %-10s %-10s %-10s %-10s %-10s %-35s %-48s",
7
15
  config.name,
8
16
  server.status,
9
- Pec.fetch_tenant_by_id(server).name,
10
- Pec.fetch_flavor(server).name,
17
+ tenant_name,
18
+ flavor_name,
11
19
  server.availability_zone,
12
20
  server.key_name,
13
21
  server.ext_srv_attr_host,
@@ -30,7 +38,22 @@ module Pec::Command
30
38
  end
31
39
 
32
40
  def self.before_do
33
- Thor.new.say("Current machine status:", :yellow)
41
+ @_error = nil
42
+ Pec::Logger.warning "Current machine status:"
43
+ end
44
+
45
+ def self.after_do
46
+ Pec::Logger.warning @_error.join("\n") if @_error
47
+ end
48
+
49
+ def self.safe_delete(host_name, default ,resource_name, &blk)
50
+ begin
51
+ blk.call
52
+ rescue
53
+ @_error ||= []
54
+ @_error << "#{host_name}:#{resource_name} is unmatch id. may be id has changed"
55
+ default
56
+ end
34
57
  end
35
58
  end
36
59
  end
@@ -1,23 +1,14 @@
1
1
  module Pec::Command
2
2
  class Up < Base
3
- def self.task(host_name, options, server, config)
3
+ def self.task(server, config)
4
4
  case
5
5
  when server.nil?
6
6
  Pec::Logger.info "make start #{config.name}"
7
7
  attribute = {name: config.name}
8
8
 
9
9
  begin
10
- Pec.processor_matching(config, Pec::Handler) do |klass|
11
- if attr = klass.build(config)
12
- attribute.deep_merge!(attr)
13
- end
14
- end
15
-
16
- Pec.processor_matching(attribute, Pec::Handler) do |klass|
17
- if attr = klass.post_build(config, attribute)
18
- attribute.deep_merge!(attr)
19
- end
20
- end
10
+ attribute = build(config, attribute)
11
+ attribute = post_build(config, attribute)
21
12
 
22
13
  Yao::Server.create(attribute)
23
14
  Pec::Logger.info "create success! #{config.name}"
@@ -39,5 +30,28 @@ module Pec::Command
39
30
  end
40
31
  end
41
32
 
33
+ class << self
34
+ %i(
35
+ build
36
+ post_build
37
+ ).each do |name|
38
+ define_method(name) do |config,attribute|
39
+ source = config
40
+ input = [config]
41
+
42
+ if name == :post_build
43
+ source = attribute
44
+ input = [config, attribute]
45
+ end
46
+
47
+ Pec.processor_matching(source, Pec::Handler) do |klass|
48
+ if attr = klass.send(name, *input)
49
+ attribute.deep_merge!(attr)
50
+ end
51
+ end
52
+ attribute
53
+ end
54
+ end
55
+ end
42
56
  end
43
57
  end
@@ -15,7 +15,7 @@ module Pec::Handler
15
15
  raise "#{template} not fond!" unless FileTest.exist?("user_data/#{template}")
16
16
  merge_template.deep_merge!(YAML.load_file("user_data/#{template}").to_hash)
17
17
  end if host.templates
18
- end
18
+ end
19
19
  end
20
20
  end
21
21
  end
data/lib/pec/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pec
2
- VERSION = "0.8.0"
2
+ VERSION = "0.8.1"
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.8.0
4
+ version: 0.8.1
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-28 00:00:00.000000000 Z
11
+ date: 2015-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor