pec 0.8.2 → 0.8.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/lib/pec.rb +5 -13
- data/lib/pec/command/status.rb +13 -5
- data/lib/pec/configure.rb +2 -2
- data/lib/pec/handler/availability_zone.rb +3 -3
- data/lib/pec/handler/flavor.rb +4 -4
- data/lib/pec/handler/image.rb +4 -4
- data/lib/pec/handler/keypair.rb +5 -5
- data/lib/pec/handler/networks.rb +12 -12
- data/lib/pec/handler/templates.rb +5 -5
- data/lib/pec/handler/user_data.rb +5 -5
- data/lib/pec/handler/user_data/nic.rb +4 -4
- data/lib/pec/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6164ca7dc80a1d9c45e2cd334571988a4acc2709
|
4
|
+
data.tar.gz: 846f134bc1adceb7d2d22dc023706581e036a734
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 19e33afa2cd99d003104942ce7213c65cba276339e3589a058efd8d767165d5d8a31f401695c390fbec2417a258da533a674de73111b4e12e520d546dae4f5f7
|
7
|
+
data.tar.gz: 1b16fab8f5419394243d01853053381028f90d2d4c91e5df6370d46b06c340a41a588ddb344a4b2a9a8d034d8b468948ea395306dcff4f001807511f27731e58
|
data/README.md
CHANGED
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 |
|
38
|
-
@_configure << Pec::Configure.new(
|
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.
|
64
|
-
tenant_list.find {|tenant| tenant.
|
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:
|
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
|
data/lib/pec/command/status.rb
CHANGED
@@ -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 =
|
6
|
-
|
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 =
|
10
|
-
|
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.
|
57
|
+
def self.safe_was_delete(host_name, default ,resource_name, &blk)
|
50
58
|
begin
|
51
59
|
blk.call
|
52
60
|
rescue
|
data/lib/pec/configure.rb
CHANGED
@@ -23,14 +23,14 @@ module Pec
|
|
23
23
|
@_config[1][method.to_s]
|
24
24
|
end
|
25
25
|
|
26
|
-
def validate(
|
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 "#{
|
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(
|
7
|
-
Pec::Logger.notice "availability_zone is #{
|
6
|
+
def self.build(config)
|
7
|
+
Pec::Logger.notice "availability_zone is #{config.availability_zone}"
|
8
8
|
{
|
9
|
-
availability_zone:
|
9
|
+
availability_zone: config.availability_zone
|
10
10
|
}
|
11
11
|
end
|
12
12
|
end
|
data/lib/pec/handler/flavor.rb
CHANGED
@@ -3,14 +3,14 @@ module Pec::Handler
|
|
3
3
|
extend Pec::Core
|
4
4
|
self.kind = 'image'
|
5
5
|
|
6
|
-
def self.build(
|
7
|
-
Pec::Logger.notice "flavor is #{
|
8
|
-
flavor_id = Yao::Flavor.list.find {|flavor| flavor.name ==
|
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=#{
|
13
|
+
raise Pec::ConfigError, "flavor name=#{config.flavor} does not exist"
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
data/lib/pec/handler/image.rb
CHANGED
@@ -3,14 +3,14 @@ module Pec::Handler
|
|
3
3
|
extend Pec::Core
|
4
4
|
self.kind = 'image'
|
5
5
|
|
6
|
-
def self.build(
|
7
|
-
Pec::Logger.notice "image is #{
|
8
|
-
image_id = Yao::Image.list.find {|image| image.name ==
|
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=#{
|
13
|
+
raise Pec::ConfigError, "image name=#{config.image} does not exist"
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
data/lib/pec/handler/keypair.rb
CHANGED
@@ -3,17 +3,17 @@ module Pec::Handler
|
|
3
3
|
extend Pec::Core
|
4
4
|
self.kind = 'keypair'
|
5
5
|
|
6
|
-
def self.build(
|
7
|
-
return({}) unless
|
6
|
+
def self.build(config)
|
7
|
+
return({}) unless config.keypair
|
8
8
|
|
9
|
-
Pec::Logger.notice "keypair is #{
|
10
|
-
keypair = Yao::Keypair.list.find {|k| k.name ==
|
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=#{
|
16
|
+
raise Pec::ConfigError, "keypair name=#{config.keypair} does not exist"
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
data/lib/pec/handler/networks.rb
CHANGED
@@ -9,12 +9,12 @@ module Pec::Handler
|
|
9
9
|
NAME = 0
|
10
10
|
CONFIG = 1
|
11
11
|
|
12
|
-
def build(
|
12
|
+
def build(config)
|
13
13
|
ports = []
|
14
|
-
|
14
|
+
config.networks.each do |network|
|
15
15
|
validate(network)
|
16
16
|
Pec::Logger.notice "port create start : #{network[NAME]}"
|
17
|
-
port = create_port(
|
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(
|
49
|
-
attribute = gen_port_attribute(
|
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(
|
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(
|
63
|
-
) if
|
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(
|
74
|
-
|
75
|
-
ids =
|
76
|
-
sg = Yao::SecurityGroup.list.find {|sg| sg.name == name &&
|
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(
|
7
|
-
{ user_data: load_template(
|
6
|
+
def build(config)
|
7
|
+
{ user_data: load_template(config) }
|
8
8
|
end
|
9
9
|
|
10
|
-
def load_template(
|
11
|
-
|
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
|
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(
|
8
|
-
user_data =
|
9
|
-
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(
|
13
|
+
def self.post_build(config, attribute)
|
14
14
|
Pec.processor_matching(attribute, Pec::Handler::UserData) do |klass|
|
15
|
-
attribute = klass.post_build(
|
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(
|
11
|
-
nic = if
|
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?(
|
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(
|
23
|
+
"write_files" => nic.gen_user_data(config.networks, ports(attribute))
|
24
24
|
}
|
25
25
|
}
|
26
26
|
)
|
data/lib/pec/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2015-12-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|