pec 0.8.2 → 0.8.3

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: 8eb4403d10f4c56f3ebe9579a6781d9662290fae
4
- data.tar.gz: ce22808214b007b7d600831e449711ce2f69a860
3
+ metadata.gz: 6164ca7dc80a1d9c45e2cd334571988a4acc2709
4
+ data.tar.gz: 846f134bc1adceb7d2d22dc023706581e036a734
5
5
  SHA512:
6
- metadata.gz: 115c5030eb6b25458e07dfc52f2ffc6c1a86c6afe5415d544b9c35b898cc91f99e89b15effb09ccce586de5f01c7099f987c74c44c0068f2d4c271e3208d5437
7
- data.tar.gz: efae8dddff91bd333ec472c8ecfca4a2ea00219b750691b4f0a33b447685427b1e53923c2bf709787b153283d35697f1e4759e7229c7918b1c4a1fb1a172f0c6
6
+ metadata.gz: 19e33afa2cd99d003104942ce7213c65cba276339e3589a058efd8d767165d5d8a31f401695c390fbec2417a258da533a674de73111b4e12e520d546dae4f5f7
7
+ data.tar.gz: 1b16fab8f5419394243d01853053381028f90d2d4c91e5df6370d46b06c340a41a588ddb344a4b2a9a8d034d8b468948ea395306dcff4f001807511f27731e58
data/README.md CHANGED
@@ -38,6 +38,7 @@ support format yaml,erb
38
38
  _default_: &def
39
39
  os_type: centos
40
40
  tenant: your_tenant
41
+ tenant_id: your_tenan_id(using a member roll)
41
42
  image: centos-7.1_chef-12.3_puppet-3.7
42
43
  flavor: m1.small
43
44
  availability_zone: nova
data/lib/pec.rb CHANGED
@@ -34,8 +34,8 @@ module Pec
34
34
 
35
35
  def self.load_config(config_name="Pec.yaml")
36
36
  @_configure ||= []
37
- ConfigFile.new(config_name).load.to_hash.reject {|k,v| k[0].match(/\_/) || k.match(/^includes$/) }.each do |host|
38
- @_configure << Pec::Configure.new(host)
37
+ ConfigFile.new(config_name).load.to_hash.reject {|k,v| k[0].match(/\_/) || k.match(/^includes$/) }.each do |config|
38
+ @_configure << Pec::Configure.new(config)
39
39
  end
40
40
  rescue => e
41
41
  Pec::Logger.critical "configure error!"
@@ -60,21 +60,13 @@ module Pec
60
60
  server_list(config).find {|s|s.name == config.name}
61
61
  end
62
62
 
63
- def self.fetch_tenant_by_id(server)
64
- tenant_list.find {|tenant| tenant.id == server.tenant_id}
65
- end
66
-
67
- def self.fetch_tenant_by_name(config)
68
- tenant_list.find {|tenant| tenant.name == config.tenant}
69
- end
70
-
71
- def self.fetch_flavor(server)
72
- flavor_list(server).find {|f|f.id == server.flavor['id']}
63
+ def self.get_tenant_id(config)
64
+ config.tenant_id || tenant_list.find {|tenant| tenant.name == config.tenant}.id
73
65
  end
74
66
 
75
67
  def self.server_list(config)
76
68
  @_server_list ||= {}
77
- @_server_list[config.tenant] ||= Yao::Server.list_detail({tenant_id: fetch_tenant_by_name(config).id})
69
+ @_server_list[config.tenant] ||= Yao::Server.list_detail({tenant_id: get_tenant_id(config)})
78
70
  end
79
71
 
80
72
  def self.tenant_list
@@ -2,12 +2,12 @@ module Pec::Command
2
2
  class Status < Base
3
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
5
+ tenant_name = safe_was_delete(config.name, config.tenant, :tenant) do
6
+ fetch_tenant(server).name
7
7
  end
8
8
 
9
- flavor_name = safe_delete(config.name, config.flavor, :flavor) do
10
- Pec.fetch_flavor(server).name
9
+ flavor_name = safe_was_delete(config.name, config.flavor, :flavor) do
10
+ fetch_flavor(server).name
11
11
  end
12
12
 
13
13
  puts sprintf(
@@ -29,6 +29,14 @@ module Pec::Command
29
29
  end
30
30
  end
31
31
 
32
+ def self.fetch_tenant(server)
33
+ Pec.tenant_list.find {|tenant| tenant.id == server.tenant_id}
34
+ end
35
+
36
+ def self.fetch_flavor(server)
37
+ Pec.flavor_list(server).find {|f|f.id == server.flavor['id']}
38
+ end
39
+
32
40
  def self.ip_addresses(server)
33
41
  server.addresses.map do |ethers|
34
42
  ethers[1].map do |ether|
@@ -46,7 +54,7 @@ module Pec::Command
46
54
  Pec::Logger.warning @_error.join("\n") if @_error
47
55
  end
48
56
 
49
- def self.safe_delete(host_name, default ,resource_name, &blk)
57
+ def self.safe_was_delete(host_name, default ,resource_name, &blk)
50
58
  begin
51
59
  blk.call
52
60
  rescue
@@ -23,14 +23,14 @@ module Pec
23
23
  @_config[1][method.to_s]
24
24
  end
25
25
 
26
- def validate(host)
26
+ def validate(config)
27
27
  %w(
28
28
  tenant
29
29
  image
30
30
  flavor
31
31
  networks
32
32
  ).each do |k|
33
- raise "#{host[0]}:host key #{k} is require" unless host[1][k]
33
+ raise "#{config[0]}:host key #{k} is require" unless config[1][k]
34
34
  end
35
35
  end
36
36
  end
@@ -3,10 +3,10 @@ module Pec::Handler
3
3
  extend Pec::Core
4
4
  self.kind = 'availability_zone'
5
5
 
6
- def self.build(host)
7
- Pec::Logger.notice "availability_zone is #{host.availability_zone}"
6
+ def self.build(config)
7
+ Pec::Logger.notice "availability_zone is #{config.availability_zone}"
8
8
  {
9
- availability_zone: host.availability_zone
9
+ availability_zone: config.availability_zone
10
10
  }
11
11
  end
12
12
  end
@@ -3,14 +3,14 @@ module Pec::Handler
3
3
  extend Pec::Core
4
4
  self.kind = 'image'
5
5
 
6
- def self.build(host)
7
- Pec::Logger.notice "flavor is #{host.flavor}"
8
- flavor_id = Yao::Flavor.list.find {|flavor| flavor.name == host.flavor}.id
6
+ def self.build(config)
7
+ Pec::Logger.notice "flavor is #{config.flavor}"
8
+ flavor_id = Yao::Flavor.list.find {|flavor| flavor.name == config.flavor}.id
9
9
  {
10
10
  flavorRef: flavor_id
11
11
  }
12
12
  rescue
13
- raise Pec::ConfigError, "flavor name=#{host.flavor} does not exist"
13
+ raise Pec::ConfigError, "flavor name=#{config.flavor} does not exist"
14
14
  end
15
15
  end
16
16
  end
@@ -3,14 +3,14 @@ module Pec::Handler
3
3
  extend Pec::Core
4
4
  self.kind = 'image'
5
5
 
6
- def self.build(host)
7
- Pec::Logger.notice "image is #{host.image}"
8
- image_id = Yao::Image.list.find {|image| image.name == host.image}.id
6
+ def self.build(config)
7
+ Pec::Logger.notice "image is #{config.image}"
8
+ image_id = Yao::Image.list.find {|image| image.name == config.image}.id
9
9
  {
10
10
  imageRef: image_id
11
11
  }
12
12
  rescue
13
- raise Pec::ConfigError, "image name=#{host.image} does not exist"
13
+ raise Pec::ConfigError, "image name=#{config.image} does not exist"
14
14
  end
15
15
  end
16
16
  end
@@ -3,17 +3,17 @@ module Pec::Handler
3
3
  extend Pec::Core
4
4
  self.kind = 'keypair'
5
5
 
6
- def self.build(host)
7
- return({}) unless host.keypair
6
+ def self.build(config)
7
+ return({}) unless config.keypair
8
8
 
9
- Pec::Logger.notice "keypair is #{host.keypair}"
10
- keypair = Yao::Keypair.list.find {|k| k.name == host.keypair }
9
+ Pec::Logger.notice "keypair is #{config.keypair}"
10
+ keypair = Yao::Keypair.list.find {|k| k.name == config.keypair }
11
11
  if keypair
12
12
  {
13
13
  key_name: keypair.name,
14
14
  }
15
15
  else
16
- raise Pec::ConfigError, "keypair name=#{host.keypair} does not exist"
16
+ raise Pec::ConfigError, "keypair name=#{config.keypair} does not exist"
17
17
  end
18
18
  end
19
19
  end
@@ -9,12 +9,12 @@ module Pec::Handler
9
9
  NAME = 0
10
10
  CONFIG = 1
11
11
 
12
- def build(host)
12
+ def build(config)
13
13
  ports = []
14
- host.networks.each do |network|
14
+ config.networks.each do |network|
15
15
  validate(network)
16
16
  Pec::Logger.notice "port create start : #{network[NAME]}"
17
- port = create_port(host, network)
17
+ port = create_port(config, network)
18
18
  Pec::Logger.notice "assgin ip : #{port.fixed_ips.first["ip_address"]}"
19
19
  ports << port
20
20
  end
@@ -45,12 +45,12 @@ module Pec::Handler
45
45
  end
46
46
  end
47
47
 
48
- def create_port(host, network)
49
- attribute = gen_port_attribute(host, network)
48
+ def create_port(config, network)
49
+ attribute = gen_port_attribute(config, network)
50
50
  Yao::Port.create(attribute)
51
51
  end
52
52
 
53
- def gen_port_attribute(host, network)
53
+ def gen_port_attribute(config, network)
54
54
  ip = IP.new(network[CONFIG]['ip_address'])
55
55
  subnet = Yao::Subnet.list.find {|s|s.cidr == ip.network.to_s}
56
56
  attribute = {
@@ -59,8 +59,8 @@ module Pec::Handler
59
59
  }
60
60
 
61
61
  attribute.merge!(
62
- security_group(host)
63
- ) if host.security_group
62
+ security_group(config)
63
+ ) if config.security_group
64
64
 
65
65
  Pec.processor_matching(network[CONFIG], Pec::Handler::Networks) do |klass|
66
66
  ops = klass.build(network)
@@ -70,10 +70,10 @@ module Pec::Handler
70
70
  attribute
71
71
  end
72
72
 
73
- def security_group(host)
74
- tenant = Yao::Tenant.list.find {|t| t.name == host.tenant }
75
- ids = host.security_group.map do |name|
76
- sg = Yao::SecurityGroup.list.find {|sg| sg.name == name && tenant.id == sg.tenant_id }
73
+ def security_group(config)
74
+ tenant_id = config.tenant_id || Yao::Tenant.list.find {|t| t.name == config.tenant }.id
75
+ ids = config.security_group.map do |name|
76
+ sg = Yao::SecurityGroup.list.find {|sg| sg.name == name && tenant_id == sg.tenant_id }
77
77
  raise "security group #{name} is not found" unless sg
78
78
  sg.id
79
79
  end
@@ -3,18 +3,18 @@ module Pec::Handler
3
3
  extend Pec::Core
4
4
  self.kind = 'templates'
5
5
  class << self
6
- def build(host)
7
- { user_data: load_template(host) }
6
+ def build(config)
7
+ { user_data: load_template(config) }
8
8
  end
9
9
 
10
- def load_template(host)
11
- host.templates.inject({}) do |merge_template, template|
10
+ def load_template(config)
11
+ config.templates.inject({}) do |merge_template, template|
12
12
  template.to_s.concat('.yaml') unless template.to_s.match(/.*\.yaml/)
13
13
  Pec::Logger.notice "load template #{template}"
14
14
 
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
- end if host.templates
17
+ end if config.templates
18
18
  end
19
19
  end
20
20
  end
@@ -4,15 +4,15 @@ module Pec::Handler
4
4
  autoload :Nic, "pec/handler/user_data/nic"
5
5
  self.kind = 'user_data'
6
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']
7
+ def self.build(config)
8
+ user_data = config.user_data || {}
9
+ user_data['fqdn'] = config.name if config.user_data && !config.user_data['fqdn']
10
10
  { user_data: user_data }
11
11
  end
12
12
 
13
- def self.post_build(host, attribute)
13
+ def self.post_build(config, attribute)
14
14
  Pec.processor_matching(attribute, Pec::Handler::UserData) do |klass|
15
- attribute = klass.post_build(host, attribute)
15
+ attribute = klass.post_build(config, attribute)
16
16
  end
17
17
  attribute[:user_data] = Base64.encode64("#cloud-config\n" + attribute[:user_data].to_yaml) if attribute[:user_data]
18
18
  attribute
@@ -7,10 +7,10 @@ module Pec::Handler
7
7
  self.kind = 'networks'
8
8
 
9
9
  class << self
10
- def post_build(host, attribute)
11
- nic = if host.os_type
10
+ def post_build(config, attribute)
11
+ nic = if config.os_type
12
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)
13
+ Object.const_get("Pec::Handler::UserData::Nic::#{c}").os_type.include?(config.os_type)
14
14
  end
15
15
  Object.const_get("Pec::Handler::UserData::Nic::#{os}")
16
16
  else
@@ -20,7 +20,7 @@ module Pec::Handler
20
20
  attribute.deep_merge(
21
21
  {
22
22
  user_data: {
23
- "write_files" => nic.gen_user_data(host.networks, ports(attribute))
23
+ "write_files" => nic.gen_user_data(config.networks, ports(attribute))
24
24
  }
25
25
  }
26
26
  )
@@ -1,3 +1,3 @@
1
1
  module Pec
2
- VERSION = "0.8.2"
2
+ VERSION = "0.8.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.8.2
4
+ version: 0.8.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-12-01 00:00:00.000000000 Z
11
+ date: 2015-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor