pec 0.7.4 → 0.7.6

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: 392f342e2b27871767f7fe5948146787f87980a0
4
- data.tar.gz: baf04990a37528b744de4c363dab705d10148148
3
+ metadata.gz: dd6ea4a1fa6340313d44899c220566c6fa5e4cae
4
+ data.tar.gz: 16e51f3871ddb5afa37965e5ffb46e92fe3ecd59
5
5
  SHA512:
6
- metadata.gz: eeb3951cf5e8aa8842f4a7c781b84146703c97b96f28ded998129ab7d3fbb1a5a916e2f8d0e13998d26aa8310c9d3a50f7e7906705fe68de8875102ae60decde
7
- data.tar.gz: 0f1f0ab20596024f81aa30acb57c898ae8e6d2871e4221c63ea39b26630528bfb54414260a45ef1399a79ff1387b67a9ab54d4f8b0c2882792189a115de5e31d
6
+ metadata.gz: e1a5519d1c253561ad6a6fa9f78b759def366c4a77da4b90a38825c41897cf4816939521c5b9fa6fbf44019f57f6d50edbe7ec114621779b53c48d13d3dbaebb
7
+ data.tar.gz: fe38e105be95783a070f21d1718c09b1f07c59aaca42e8bd92a7b015e1870b03a64aee4edfd95c68bb355ebfede97d56f49fc383156f300c1da702b5d7240315
data/README.md CHANGED
@@ -66,7 +66,7 @@ pyama-test002:
66
66
  ・・・
67
67
 
68
68
  # include config
69
- inludes:
69
+ includes:
70
70
  - path/to/a.yaml
71
71
  - path/to/b.yaml
72
72
 
@@ -103,7 +103,7 @@ Items other than the above are output to the configuration file with `KEY = valu
103
103
  #### Includes
104
104
  ```yaml
105
105
  # example
106
- inludes:
106
+ includes:
107
107
  - path/to/a.yaml
108
108
  - path/to/b.yaml
109
109
  ```
data/lib/pec.rb CHANGED
@@ -5,6 +5,7 @@ require 'yaml'
5
5
  require 'thor'
6
6
  require 'ip'
7
7
  require 'colorator'
8
+ require "pec/core"
8
9
  require "pec/version"
9
10
  require "pec/logger"
10
11
  require "pec/configure"
@@ -16,16 +17,21 @@ require "pec/init"
16
17
  require "pec/cli"
17
18
 
18
19
  module Pec
19
- def self.init_yao(_tenant_name=nil)
20
+ def self.init_yao(_tenant_name)
21
+ return unless reload_yao?(_tenant_name)
20
22
  check_env
21
23
  Yao.configure do
22
24
  auth_url "#{ENV["OS_AUTH_URL"]}/tokens"
23
25
  username ENV["OS_USERNAME"]
24
26
  password ENV["OS_PASSWORD"]
25
- tenant_name _tenant_name || ENV["OS_TENANT_NAME"]
27
+ tenant_name _tenant_name
26
28
  end
27
29
  end
28
30
 
31
+ def self.reload_yao?(_tenant_name)
32
+ @_last_tenant = _tenant_name if _tenant_name != @_last_tenant
33
+ end
34
+
29
35
  def self.load_config(config_name=nil)
30
36
  @_configure ||= []
31
37
  config_name ||= 'Pec.yaml'
@@ -52,7 +58,7 @@ module Pec
52
58
  self.configure.each do |config|
53
59
  next if hosts.size > 0 && hosts.none? {|name| config.name.match(/^#{name}/)}
54
60
  Pec.init_yao(config.tenant)
55
- server = Yao::Server.list_detail.find {|s|s.name == config.name} if fetch
61
+ server = Yao::Server.list_detail("name" => config.name).first if fetch
56
62
  yield(server, config)
57
63
  end
58
64
  end
@@ -23,7 +23,12 @@ module Pec::Command
23
23
  end
24
24
 
25
25
  def self.tenant_name(server)
26
- Yao::Tenant.list.find {|tenant| tenant.id == server.tenant_id}.name
26
+ tenant_list.find {|tenant| tenant.id == server.tenant_id}.name
27
+ end
28
+
29
+ def self.tenant_list
30
+ @@_tenant_list ||= Yao::Tenant.list
31
+ @@_tenant_list
27
32
  end
28
33
 
29
34
  def self.flavor_name(server)
data/lib/pec/configure.rb CHANGED
@@ -30,7 +30,7 @@ module Pec
30
30
  flavor
31
31
  networks
32
32
  ).each do |k|
33
- raise "host key #{k} is require" unless host[1][k]
33
+ raise "#{host[0]}:host key #{k} is require" unless host[1][k]
34
34
  end
35
35
  end
36
36
  end
@@ -1,6 +1,5 @@
1
1
  module Pec
2
2
  module Coordinate
3
- autoload :Base, "pec/coordinate/base"
4
3
  autoload :UserData, "pec/coordinate/user_data"
5
4
  end
6
5
  end
@@ -1,6 +1,6 @@
1
1
  module Pec::Coordinate
2
- class UserData < Base
3
- autoload :Base, "pec/coordinate/user_data/base"
2
+ class UserData
3
+ extend Pec::Core
4
4
  autoload :Nic, "pec/coordinate/user_data/nic"
5
5
  self.kind = 'user_data'
6
6
 
@@ -1,13 +1,12 @@
1
1
  module Pec::Coordinate
2
- class UserData::Nic < Base
2
+ class UserData::Nic
3
+ extend Pec::Core
3
4
  autoload :Base, "pec/coordinate/user_data/nic/base"
4
5
  autoload :Rhel, "pec/coordinate/user_data/nic/rhel"
5
6
  autoload :Ubuntu, "pec/coordinate/user_data/nic/ubuntu"
6
7
  self.kind = 'networks'
7
8
 
8
9
  class << self
9
- NAME = 0
10
- CONFIG = 1
11
10
  def build(host, attribute)
12
11
  _nic = Pec::Coordinate::UserData::Nic.constants.reject {|c|c.to_s.downcase == "base"}.find do |c|
13
12
  host.os_type && Object.const_get("Pec::Coordinate::UserData::Nic::#{c}").os_type.include?(host.os_type)
data/lib/pec/core.rb ADDED
@@ -0,0 +1,7 @@
1
+ module Pec
2
+ module Core
3
+ attr_accessor :kind
4
+ def build(*args)
5
+ raise "#{self.class.name} not defined method build"
6
+ end
7
+ end
data/lib/pec/handler.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  module Pec
2
2
  module Handler
3
- autoload :Base, "pec/handler/base"
4
3
  autoload :AvailabilityZone, "pec/handler/availability_zone"
5
4
  autoload :Image, "pec/handler/image"
6
5
  autoload :Flavor, "pec/handler/flavor"
@@ -1,5 +1,6 @@
1
1
  module Pec::Handler
2
- class AvailabilityZone < Base
2
+ class AvailabilityZone
3
+ extend Pec::Core
3
4
  self.kind = 'availability_zone'
4
5
 
5
6
  def self.build(host)
@@ -1,12 +1,16 @@
1
1
  module Pec::Handler
2
- class Flavor < Base
2
+ class Flavor
3
+ extend Pec::Core
3
4
  self.kind = 'image'
4
5
 
5
6
  def self.build(host)
6
7
  Pec::Logger.notice "flavor is #{host.flavor}"
8
+ flavor_id = Yao::Flavor.list.find {|flavor| flavor.name == host.flavor}.id
7
9
  {
8
- flavorRef: Yao::Flavor.list.find {|flavor| flavor.name == host.flavor}.id
10
+ flavorRef: flavor_id
9
11
  }
12
+ rescue
13
+ raise Pec::ConfigError, "flavor name=#{host.flavor} does not exist"
10
14
  end
11
15
  end
12
16
  end
@@ -1,12 +1,16 @@
1
1
  module Pec::Handler
2
- class Image < Base
2
+ class Image
3
+ extend Pec::Core
3
4
  self.kind = 'image'
4
5
 
5
6
  def self.build(host)
6
7
  Pec::Logger.notice "image is #{host.image}"
8
+ image_id = Yao::Image.list.find {|image| image.name == host.image}.id
7
9
  {
8
- imageRef: Yao::Image.list.find {|image| image.name == host.image}.id
10
+ imageRef: image_id
9
11
  }
12
+ rescue
13
+ raise Pec::ConfigError, "image name=#{host.image} does not exist"
10
14
  end
11
15
  end
12
16
  end
@@ -1,5 +1,6 @@
1
1
  module Pec::Handler
2
- class Keypair < Base
2
+ class Keypair
3
+ extend Pec::Core
3
4
  self.kind = 'keypair'
4
5
 
5
6
  def self.build(host)
@@ -1,7 +1,7 @@
1
1
  module Pec::Handler
2
- class Networks < Base
2
+ class Networks
3
+ extend Pec::Core
3
4
  self.kind = 'networks'
4
- autoload :OptionBase, "pec/handler/networks/option_base"
5
5
  autoload :IpAddress, "pec/handler/networks/ip_address"
6
6
  autoload :AllowedAddressPairs, "pec/handler/networks/allowed_address_pairs"
7
7
 
@@ -1,6 +1,7 @@
1
1
  module Pec::Handler
2
2
  class Networks
3
- class AllowedAddressPairs< OptionBase
3
+ class AllowedAddressPairs
4
+ extend Pec::Core
4
5
  self.kind = 'allowed_address_pairs'
5
6
  class << self
6
7
  def build(network)
@@ -1,12 +1,12 @@
1
1
  module Pec::Handler
2
2
  class Networks
3
- class IpAddress < OptionBase
3
+ class IpAddress
4
+ extend Pec::Core
4
5
  self.kind = 'ip_address'
5
6
  class << self
6
7
  def build(network)
7
8
  ip = IP.new(network[1]['ip_address'])
8
9
  subnet = Yao::Subnet.list.find {|s|s.cidr == ip.network.to_s}
9
-
10
10
  if ip.to_s != subnet.cidr
11
11
  {
12
12
  fixed_ips: [
@@ -1,5 +1,6 @@
1
1
  module Pec::Handler
2
- class Templates < Base
2
+ class Templates
3
+ extend Pec::Core
3
4
  self.kind = 'templates'
4
5
  class << self
5
6
  def build(host)
@@ -1,5 +1,6 @@
1
1
  module Pec::Handler
2
- class UserData < Base
2
+ class UserData
3
+ extend Pec::Core
3
4
  self.kind = 'user_data'
4
5
  class << self
5
6
  def build(host)
data/lib/pec/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pec
2
- VERSION = "0.7.4"
2
+ VERSION = "0.7.6"
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.4
4
+ version: 0.7.6
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-04 00:00:00.000000000 Z
11
+ date: 2015-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -153,23 +153,20 @@ files:
153
153
  - lib/pec/config_error.rb
154
154
  - lib/pec/configure.rb
155
155
  - lib/pec/coordinate.rb
156
- - lib/pec/coordinate/base.rb
157
156
  - lib/pec/coordinate/user_data.rb
158
- - lib/pec/coordinate/user_data/base.rb
159
157
  - lib/pec/coordinate/user_data/nic.rb
160
158
  - lib/pec/coordinate/user_data/nic/base.rb
161
159
  - lib/pec/coordinate/user_data/nic/rhel.rb
162
160
  - lib/pec/coordinate/user_data/nic/ubuntu.rb
161
+ - lib/pec/core.rb
163
162
  - lib/pec/handler.rb
164
163
  - lib/pec/handler/availability_zone.rb
165
- - lib/pec/handler/base.rb
166
164
  - lib/pec/handler/flavor.rb
167
165
  - lib/pec/handler/image.rb
168
166
  - lib/pec/handler/keypair.rb
169
167
  - lib/pec/handler/networks.rb
170
168
  - lib/pec/handler/networks/allowed_address_pairs.rb
171
169
  - lib/pec/handler/networks/ip_address.rb
172
- - lib/pec/handler/networks/option_base.rb
173
170
  - lib/pec/handler/templates.rb
174
171
  - lib/pec/handler/user_data.rb
175
172
  - lib/pec/init.rb
@@ -1,10 +0,0 @@
1
- module Pec::Coordinate
2
- class Base
3
- class << self
4
- attr_accessor :kind
5
- def build(host, attribute)
6
- raise "not defined method"
7
- end
8
- end
9
- end
10
- end
@@ -1,10 +0,0 @@
1
- module Pec::Coordinate
2
- class UserData::Base
3
- class << self
4
- attr_accessor :kind
5
- def build
6
- raise "undefine method build"
7
- end
8
- end
9
- end
10
- end
@@ -1,10 +0,0 @@
1
- module Pec::Handler
2
- class Base
3
- class << self
4
- attr_accessor :kind
5
- def build
6
- raise "not defined method"
7
- end
8
- end
9
- end
10
- end
@@ -1,9 +0,0 @@
1
- module Pec::Handler
2
- class Networks
3
- class OptionBase
4
- class << self
5
- attr_accessor :kind
6
- end
7
- end
8
- end
9
- end