pec 0.7.2 → 0.7.3

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: 5e8eba0965d155a9f519d921295e942b6b106775
4
- data.tar.gz: fa6a457c9dd23058705d20369890c3b772a251ee
3
+ metadata.gz: de4afe55b26feafd85e2735f85bfd4bcf7cfd765
4
+ data.tar.gz: c0bc229e8eb45d455d0a724aab16d0b360258a2d
5
5
  SHA512:
6
- metadata.gz: 2f3e85aa04e43cc5f40f8dda96e5b7aa00455741ab24ebcd19a5c04c9861b952e6162cdd2ed37e49f29077cf2d24209a477d1408d270abcfe51c8b3722eff3ff
7
- data.tar.gz: 0ba33459b7b1528d83f9cb10320240cc62eb8e91b940965d134596ec0a7f8bf6a14d53a69b4d193ce07c4a0347bce83be21894ae4aeea8861f692c2ba3a48046
6
+ metadata.gz: 397bde231b31ac5ea69cddacb767b4dfd05cfc9d6532ea58e98ce42b7c0b25d29ef55f854715fbd1ce018958f05e6d603528b0d6127b7b5e6fcd9adef67fb65d
7
+ data.tar.gz: 18c9cd6461af6ed0f80841bf8e07bb5165479c52a0c8098ab57326a81c7c9a4f2ac1f49e37982a6cd9fe32b9131f45ec19619b767b0209d0aded1fc73c103a15
data/README.md CHANGED
@@ -29,11 +29,14 @@ create - /user_data/web_server.yaml.sample
29
29
  ### Configure
30
30
  #### Pec.yaml
31
31
  ```
32
+ # merge of yaml
32
33
  _default_: &def
33
34
  tenant: your_tenant
34
35
  image: centos-7.1_chef-12.3_puppet-3.7
35
36
  flavor: m1.small
36
37
  availability_zone: nova
38
+
39
+ # vm config
37
40
  pyama-test001:
38
41
  <<: *def
39
42
  networks:
@@ -61,6 +64,11 @@ pyama-test002:
61
64
  <<: *def
62
65
  ・・・
63
66
 
67
+ # include config
68
+ inludes:
69
+ - path/to/a.yaml
70
+ - path/to/b.yaml
71
+
64
72
  ```
65
73
  ##### Detail
66
74
 
@@ -89,5 +97,18 @@ pyama-test002:
89
97
  ※ bootproto=static is required
90
98
  Items other than the above are output to the configuration file with `KEY = value` format
91
99
 
100
+ #### Includes
101
+ ```yaml
102
+ # example
103
+ inludes:
104
+ - path/to/a.yaml
105
+ - path/to/b.yaml
106
+ ```
107
+
108
+ Read order is this as
109
+ 1.Pec.yaml
110
+ 2.path/to/a.yaml
111
+ 3.path/to/b.yaml
112
+
92
113
  ## Author
93
114
  * pyama86
data/lib/pec.rb CHANGED
@@ -14,7 +14,6 @@ require "pec/sample"
14
14
  require "pec/init"
15
15
  require "pec/cli"
16
16
 
17
-
18
17
  module Pec
19
18
  def self.init_yao(_tenant_name=nil)
20
19
  check_env
@@ -26,24 +25,33 @@ module Pec
26
25
  end
27
26
  end
28
27
 
29
- def self.load_config(file_name=nil)
30
- file_name ||= 'Pec.yaml'
31
- @_configure = []
32
- YAML.load_file(file_name).to_hash.reject {|c| c[0].to_s.match(/^_/)}.each do |host|
28
+ def self.load_config(config_name=nil)
29
+ @_configure ||= []
30
+ config_name ||= 'Pec.yaml'
31
+ merge_config(config_name).to_hash.reject {|k,v| k[0].match(/\_/) || k.match(/^includes$/) }.each do |host|
33
32
  @_configure << Pec::Configure.new(host)
34
33
  end
35
34
  end
36
35
 
36
+ def self.merge_config(config_name)
37
+ base_config = YAML.load_file(config_name)
38
+ if include_files = base_config.to_hash.find{|k,v| k.match(/^includes$/) && !v.nil? }
39
+ YAML.load(File.read(config_name) + include_files[1].map {|f|File.read(f)}.join("\n"))
40
+ else
41
+ base_config
42
+ end
43
+ end
44
+
37
45
  def self.configure
38
46
  load_config unless @_configure
39
47
  @_configure
40
48
  end
41
49
 
42
- def self.servers(hosts)
50
+ def self.servers(hosts, options, fetch=false)
43
51
  self.configure.each do |config|
44
- next if hosts && hosts.none? {|name| config.name.match(/^#{name}/)}
52
+ next if hosts.size > 0 && hosts.none? {|name| config.name.match(/^#{name}/)}
45
53
  Pec.init_yao(config.tenant)
46
- server = Yao::Server.list_detail.find {|s|s.name == config.name}
54
+ server = Yao::Server.list_detail.find {|s|s.name == config.name} if fetch
47
55
  yield(server, config)
48
56
  end
49
57
  end
@@ -70,3 +78,4 @@ class ::Hash
70
78
  self.merge!(deep_merge(second))
71
79
  end
72
80
  end
81
+
data/lib/pec/cli.rb CHANGED
@@ -7,18 +7,18 @@ module Pec
7
7
  _sub_command(nil, options)
8
8
  end
9
9
 
10
- desc 'up', 'create vm by Pec.yaml'
10
+ desc 'up [HOSTNAME1, HOSTNAME2, ...]', 'create vm by Pec.yaml'
11
11
  def up(*hosts)
12
12
  _sub_command(hosts, options)
13
13
  end
14
14
 
15
15
  option :force , type: :boolean, aliases: "-f"
16
- desc "destroy", "delete vm"
16
+ desc "destroy [HOSTNAME1, HOSTNAME2, ...]", "delete vm"
17
17
  def destroy(*hosts)
18
18
  _sub_command(hosts, options)
19
19
  end
20
20
 
21
- desc "status", "vm status"
21
+ desc "status [HOSTNAME1, HOSTNAME2, ...]", "vm status"
22
22
  def status(*hosts)
23
23
  _sub_command(hosts, options)
24
24
  end
@@ -28,7 +28,7 @@ module Pec
28
28
  _sub_command(nil, options)
29
29
  end
30
30
 
31
- desc "config", "show configure"
31
+ desc "config [HOSTNAME1, HOSTNAME2, ...]", "show configure"
32
32
  def config(*hosts)
33
33
  _sub_command(hosts, options)
34
34
  end
@@ -1,7 +1,9 @@
1
1
  module Pec::Command
2
2
  class Base
3
+ @fetch = false
3
4
  def self.run(host_name, options)
4
- Pec.servers(host_name) do |server,config|
5
+ before_do
6
+ Pec.servers(host_name, options, @fetch) do |server,config|
5
7
  task(host_name, options, server, config)
6
8
  end
7
9
  rescue => e
@@ -14,5 +16,6 @@ module Pec::Command
14
16
  end
15
17
 
16
18
  def self.task(host_name, options, server, config); end
19
+ def self.before_do; end
17
20
  end
18
21
  end
@@ -1,13 +1,7 @@
1
1
  module Pec::Command
2
2
  class Config < Base
3
- def self.run(hosts, options)
4
- puts YAML.dump(
5
- YAML.load_file("Pec.yaml").to_hash.reject {|c|
6
- c[0].to_s.match(/^_/) || (hosts && hosts.none? {|name| c.match(/^#{name}/)})
7
- }
8
- )
9
- rescue => e
10
- print_exception(e)
3
+ def self.task(host_name, options, server, config)
4
+ puts YAML.dump(config.inspect[0] => config.inspect[1])
11
5
  end
12
6
  end
13
7
  end
@@ -1,5 +1,6 @@
1
1
  module Pec::Command
2
2
  class Destroy < Base
3
+ @fetch = true
3
4
  def self.task(host_name, options, server, config)
4
5
  unless server
5
6
  Pec::Logger.notice "not be created #{config.name}"
@@ -1,13 +1,14 @@
1
1
  module Pec::Command
2
2
  class List < Base
3
- def self.run(host_name, options)
3
+ def self.task(host_name, options, server, config)
4
+ puts sprintf(
5
+ " %-35s",
6
+ config.name
7
+ )
8
+ end
9
+
10
+ def self.before_do
4
11
  Thor.new.say("vm list:", :yellow)
5
- Pec.configure.each do |host|
6
- puts sprintf(
7
- " %-35s",
8
- host.name,
9
- )
10
- end
11
12
  end
12
13
  end
13
14
  end
@@ -1,7 +1,7 @@
1
1
  module Pec::Command
2
2
  class Status < Base
3
+ @fetch = true
3
4
  def self.task(host_name, options, server, config)
4
- Thor.new.say("Current machine status:", :yellow)
5
5
  if server
6
6
  puts sprintf(
7
7
  " %-35s %-10s %-10s %-10s %-10s %-10s %-35s %-48s",
@@ -37,5 +37,9 @@ module Pec::Command
37
37
  end
38
38
  end.flatten.join(",")
39
39
  end
40
+
41
+ def self.before_do
42
+ Thor.new.say("Current machine status:", :yellow)
43
+ end
40
44
  end
41
45
  end
@@ -1,5 +1,6 @@
1
1
  module Pec::Command
2
2
  class Up < Base
3
+ @fetch = true
3
4
  def self.task(host_name, options, server, config)
4
5
  unless server
5
6
  Pec::Logger.info "make start #{config.name}"
data/lib/pec/configure.rb CHANGED
@@ -7,6 +7,10 @@ module Pec
7
7
  @_config = config
8
8
  end
9
9
 
10
+ def inspect
11
+ @_config
12
+ end
13
+
10
14
  def name
11
15
  @_config[0]
12
16
  end
@@ -2,7 +2,7 @@ module Pec::Handler
2
2
  class Templates < Base
3
3
  self.kind = 'templates'
4
4
  class << self
5
- def build(host)
5
+ def build(host)
6
6
  { user_data: load_template(host) }
7
7
  end
8
8
 
data/lib/pec/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pec
2
- VERSION = "0.7.2"
2
+ VERSION = "0.7.3"
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.2
4
+ version: 0.7.3
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-10-24 00:00:00.000000000 Z
11
+ date: 2015-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor