pec 0.7.3 → 0.7.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -0
- data/lib/pec.rb +5 -1
- data/lib/pec/command/up.rb +14 -6
- data/lib/pec/coordinate.rb +6 -0
- data/lib/pec/coordinate/base.rb +10 -0
- data/lib/pec/coordinate/user_data.rb +21 -0
- data/lib/pec/coordinate/user_data/base.rb +10 -0
- data/lib/pec/coordinate/user_data/nic.rb +43 -0
- data/lib/pec/coordinate/user_data/nic/base.rb +39 -0
- data/lib/pec/coordinate/user_data/nic/rhel.rb +29 -0
- data/lib/pec/coordinate/user_data/nic/ubuntu.rb +46 -0
- data/lib/pec/handler/networks.rb +1 -42
- data/lib/pec/version.rb +1 -1
- metadata +10 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 392f342e2b27871767f7fe5948146787f87980a0
|
4
|
+
data.tar.gz: baf04990a37528b744de4c363dab705d10148148
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eeb3951cf5e8aa8842f4a7c781b84146703c97b96f28ded998129ab7d3fbb1a5a916e2f8d0e13998d26aa8310c9d3a50f7e7906705fe68de8875102ae60decde
|
7
|
+
data.tar.gz: 0f1f0ab20596024f81aa30acb57c898ae8e6d2871e4221c63ea39b26630528bfb54414260a45ef1399a79ff1387b67a9ab54d4f8b0c2882792189a115de5e31d
|
data/README.md
CHANGED
@@ -31,6 +31,7 @@ create - /user_data/web_server.yaml.sample
|
|
31
31
|
```
|
32
32
|
# merge of yaml
|
33
33
|
_default_: &def
|
34
|
+
os_type: centos
|
34
35
|
tenant: your_tenant
|
35
36
|
image: centos-7.1_chef-12.3_puppet-3.7
|
36
37
|
flavor: m1.small
|
@@ -78,6 +79,7 @@ inludes:
|
|
78
79
|
| tenant | ○ | your_tenant |
|
79
80
|
| image | ○ | centos-7.1_chef-12.3_puppet-3.7 |
|
80
81
|
| flavor | ○ | m1.small |
|
82
|
+
| os_type | - | centos(centos or ubuntu |
|
81
83
|
| networks | - | [] |
|
82
84
|
| security_group | - | [default,ssh] |
|
83
85
|
| templates | - | [base.yaml,webserver.yaml] |
|
@@ -95,6 +97,7 @@ inludes:
|
|
95
97
|
| allowed_address_pairs | | [10.1.1.2/24] |
|
96
98
|
|
97
99
|
※ bootproto=static is required
|
100
|
+
|
98
101
|
Items other than the above are output to the configuration file with `KEY = value` format
|
99
102
|
|
100
103
|
#### Includes
|
data/lib/pec.rb
CHANGED
@@ -9,6 +9,7 @@ require "pec/version"
|
|
9
9
|
require "pec/logger"
|
10
10
|
require "pec/configure"
|
11
11
|
require "pec/handler"
|
12
|
+
require "pec/coordinate"
|
12
13
|
require "pec/command"
|
13
14
|
require "pec/sample"
|
14
15
|
require "pec/init"
|
@@ -56,7 +57,6 @@ module Pec
|
|
56
57
|
end
|
57
58
|
end
|
58
59
|
|
59
|
-
|
60
60
|
def self.check_env
|
61
61
|
%w(
|
62
62
|
OS_AUTH_URL
|
@@ -66,6 +66,10 @@ module Pec
|
|
66
66
|
raise "please set env #{name}" unless ENV[name]
|
67
67
|
end
|
68
68
|
end
|
69
|
+
|
70
|
+
def self.config_reset
|
71
|
+
@_configure = nil
|
72
|
+
end
|
69
73
|
end
|
70
74
|
|
71
75
|
class ::Hash
|
data/lib/pec/command/up.rb
CHANGED
@@ -6,14 +6,13 @@ module Pec::Command
|
|
6
6
|
Pec::Logger.info "make start #{config.name}"
|
7
7
|
|
8
8
|
attribute = {name: config.name}
|
9
|
-
config
|
10
|
-
|
11
|
-
_handler = Object.const_get("Pec::Handler::#{c}")
|
12
|
-
attribute.deep_merge!(_handler.build(config)) if _handler.kind == k
|
13
|
-
end
|
9
|
+
make_attribute(config, Pec::Handler) do |key, klass|
|
10
|
+
attribute.deep_merge!(klass.build(config))
|
14
11
|
end
|
15
12
|
|
16
|
-
attribute
|
13
|
+
make_attribute(attribute, Pec::Coordinate) do |key, klass|
|
14
|
+
attribute.deep_merge!(klass.build(config, attribute))
|
15
|
+
end
|
17
16
|
|
18
17
|
Yao::Server.create(attribute)
|
19
18
|
Pec::Logger.info "create success! #{config.name}"
|
@@ -21,5 +20,14 @@ module Pec::Command
|
|
21
20
|
Pec::Logger.notice "already server: #{config.name}"
|
22
21
|
end
|
23
22
|
end
|
23
|
+
|
24
|
+
def self.make_attribute(source, klass)
|
25
|
+
source.keys.each do |k|
|
26
|
+
Object.const_get(klass.to_s).constants.each do |c|
|
27
|
+
object = Object.const_get("#{klass.to_s}::#{c}")
|
28
|
+
yield k, object if k.to_s == object.kind.to_s
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
24
32
|
end
|
25
33
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Pec::Coordinate
|
2
|
+
class UserData < Base
|
3
|
+
autoload :Base, "pec/coordinate/user_data/base"
|
4
|
+
autoload :Nic, "pec/coordinate/user_data/nic"
|
5
|
+
self.kind = 'user_data'
|
6
|
+
|
7
|
+
def self.build(host, attribute)
|
8
|
+
attribute.keys.each do |k|
|
9
|
+
Pec::Coordinate::UserData.constants.each do |c|
|
10
|
+
klass = Object.const_get("Pec::Coordinate::UserData::#{c}")
|
11
|
+
|
12
|
+
if klass.kind.to_s == k.to_s
|
13
|
+
attribute = klass.build(host, attribute)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
attribute[:user_data] = Base64.encode64("#cloud-config\n" + attribute[:user_data].to_yaml) if attribute[:user_data]
|
18
|
+
attribute
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Pec::Coordinate
|
2
|
+
class UserData::Nic < Base
|
3
|
+
autoload :Base, "pec/coordinate/user_data/nic/base"
|
4
|
+
autoload :Rhel, "pec/coordinate/user_data/nic/rhel"
|
5
|
+
autoload :Ubuntu, "pec/coordinate/user_data/nic/ubuntu"
|
6
|
+
self.kind = 'networks'
|
7
|
+
|
8
|
+
class << self
|
9
|
+
NAME = 0
|
10
|
+
CONFIG = 1
|
11
|
+
def build(host, attribute)
|
12
|
+
_nic = Pec::Coordinate::UserData::Nic.constants.reject {|c|c.to_s.downcase == "base"}.find do |c|
|
13
|
+
host.os_type && Object.const_get("Pec::Coordinate::UserData::Nic::#{c}").os_type.include?(host.os_type)
|
14
|
+
end
|
15
|
+
|
16
|
+
nic = if _nic
|
17
|
+
Object.const_get("Pec::Coordinate::UserData::Nic::#{_nic}")
|
18
|
+
else
|
19
|
+
Pec::Coordinate::UserData::Nic::Rhel
|
20
|
+
end
|
21
|
+
|
22
|
+
attribute.deep_merge(
|
23
|
+
{
|
24
|
+
user_data: {
|
25
|
+
"write_files" => nic.gen_user_data(host.networks, ports(attribute))
|
26
|
+
}
|
27
|
+
}
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
31
|
+
def ports(attribute)
|
32
|
+
port_ids(attribute).map do |id|
|
33
|
+
Yao::Port.get(id)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def port_ids(attribute)
|
38
|
+
attribute[:networks].map {|n|n[:port]}
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Pec::Coordinate
|
2
|
+
class UserData::Nic::Base
|
3
|
+
class << self
|
4
|
+
NAME = 0
|
5
|
+
CONFIG = 1
|
6
|
+
attr_accessor :os_type
|
7
|
+
def gen_user_data(networks, ports)
|
8
|
+
networks.map do |network|
|
9
|
+
port = ports.find {|p|p.name == network[NAME]}
|
10
|
+
path = network[CONFIG]['path'] || default_path(port)
|
11
|
+
{
|
12
|
+
'content' => ifcfg_config(network, port),
|
13
|
+
'owner' => "root:root",
|
14
|
+
'path' => path,
|
15
|
+
'permissions' => "0644"
|
16
|
+
}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def safe_merge(base, network)
|
21
|
+
# delete option column
|
22
|
+
mask_column = Pec::Handler::Networks.constants.map {|c| Object.const_get("Pec::Handler::Networks::#{c}").kind }
|
23
|
+
mask_config = network[CONFIG].reject {|k,v| mask_column.include?(k)}
|
24
|
+
|
25
|
+
base.merge(
|
26
|
+
mask_config
|
27
|
+
)
|
28
|
+
end
|
29
|
+
|
30
|
+
def default_path(port)
|
31
|
+
raise "undfined method default_path"
|
32
|
+
end
|
33
|
+
|
34
|
+
def ifcfg_config(network, port)
|
35
|
+
raise "undfined method ifcfg_config"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Pec::Coordinate
|
2
|
+
class UserData::Nic
|
3
|
+
class Rhel < Base
|
4
|
+
self.os_type = %w(centos rhel)
|
5
|
+
class << self
|
6
|
+
def ifcfg_config(network, port)
|
7
|
+
base = {
|
8
|
+
"name" => port.name,
|
9
|
+
"device" => port.name,
|
10
|
+
"type" => 'Ethernet',
|
11
|
+
"onboot" => 'yes',
|
12
|
+
"hwaddr" => port.mac_address
|
13
|
+
}
|
14
|
+
base.merge!(
|
15
|
+
{
|
16
|
+
"netmask" => IP.new(network[CONFIG]['ip_address']).netmask.to_s,
|
17
|
+
"ipaddr" => port.fixed_ips.first['ip_address']
|
18
|
+
}
|
19
|
+
) if network[CONFIG]['bootproto'] == "static"
|
20
|
+
safe_merge(base, network).map {|k,v| "#{k.upcase}=#{v}"}.join("\n")
|
21
|
+
end
|
22
|
+
|
23
|
+
def default_path(port)
|
24
|
+
"/etc/sysconfig/network-scripts/ifcfg-#{port.name}"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Pec::Coordinate
|
2
|
+
class UserData::Nic
|
3
|
+
class Ubuntu < Base
|
4
|
+
self.os_type = %w(ubuntu)
|
5
|
+
class << self
|
6
|
+
def gen_user_data(networks, ports)
|
7
|
+
port_content = [
|
8
|
+
"auto lo\niface lo inet loopback"
|
9
|
+
]
|
10
|
+
|
11
|
+
networks.map do |network|
|
12
|
+
port = ports.find {|p|p.name == network[NAME]}
|
13
|
+
port_content << ifcfg_config(network, port)
|
14
|
+
end
|
15
|
+
[
|
16
|
+
{
|
17
|
+
'content' => port_content.join("\n"),
|
18
|
+
'owner' => "root:root",
|
19
|
+
'path' => networks.first[CONFIG]['path'] || default_path(nil),
|
20
|
+
'permissions' => "0644"
|
21
|
+
}
|
22
|
+
]
|
23
|
+
end
|
24
|
+
|
25
|
+
def ifcfg_config(network, port)
|
26
|
+
base = {
|
27
|
+
"auto" => port.name,
|
28
|
+
"iface #{port.name} inet" => network[CONFIG]['bootproto'],
|
29
|
+
}
|
30
|
+
base.merge!(
|
31
|
+
{
|
32
|
+
"address" => port.fixed_ips.first['ip_address'],
|
33
|
+
"netmask" => IP.new(network[CONFIG]['ip_address']).netmask.to_s,
|
34
|
+
"hwaddress ether" => port.mac_address
|
35
|
+
}
|
36
|
+
) if network[CONFIG]['bootproto'] == "static"
|
37
|
+
safe_merge(base, network).reject {|k,v| k == "bootproto"}.map {|k,v| "#{k} #{v}"}.join("\n")
|
38
|
+
end
|
39
|
+
|
40
|
+
def default_path(port)
|
41
|
+
"/etc/network/interfaces"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/lib/pec/handler/networks.rb
CHANGED
@@ -11,21 +11,15 @@ module Pec::Handler
|
|
11
11
|
|
12
12
|
def build(host)
|
13
13
|
ports = []
|
14
|
-
user_data = []
|
15
|
-
|
16
14
|
host.networks.each do |network|
|
17
15
|
validate(network)
|
18
16
|
Pec::Logger.notice "port create start : #{network[NAME]}"
|
19
17
|
port = create_port(host, network)
|
20
18
|
Pec::Logger.notice "assgin ip : #{port.fixed_ips.first["ip_address"]}"
|
21
19
|
ports << port
|
22
|
-
user_data << gen_user_data(network, port)
|
23
20
|
end
|
24
21
|
{
|
25
|
-
networks: ports.map {|port| { uuid: nil, port: port.id }}
|
26
|
-
user_data: {
|
27
|
-
'write_files' => user_data
|
28
|
-
}
|
22
|
+
networks: ports.map {|port| { uuid: nil, port: port.id }}
|
29
23
|
}
|
30
24
|
end
|
31
25
|
|
@@ -67,41 +61,6 @@ module Pec::Handler
|
|
67
61
|
attribute
|
68
62
|
end
|
69
63
|
|
70
|
-
def gen_user_data(network, port)
|
71
|
-
path = network[CONFIG]['path'] || "/etc/sysconfig/network-scripts/ifcfg-#{port.name}"
|
72
|
-
{
|
73
|
-
'content' => ifcfg_config(network, port),
|
74
|
-
'owner' => "root:root",
|
75
|
-
'path' => path,
|
76
|
-
'permissions' => "0644"
|
77
|
-
}
|
78
|
-
end
|
79
|
-
|
80
|
-
def ifcfg_config(network, port)
|
81
|
-
base = {
|
82
|
-
"name" => port.name,
|
83
|
-
"device" => port.name,
|
84
|
-
"type" => 'Ethernet',
|
85
|
-
"onboot" => 'yes',
|
86
|
-
"hwaddr" => port.mac_address
|
87
|
-
}
|
88
|
-
base.merge!(
|
89
|
-
{
|
90
|
-
"netmask" => IP.new(network[CONFIG]['ip_address']).netmask.to_s,
|
91
|
-
"ipaddr" => port.fixed_ips.first['ip_address']
|
92
|
-
}
|
93
|
-
) if network[CONFIG]['bootproto'] == "static"
|
94
|
-
|
95
|
-
# delete option column
|
96
|
-
mask_column = Pec::Handler::Networks.constants.map {|c| Object.const_get("Pec::Handler::Networks::#{c}").kind }
|
97
|
-
mask_config = network[CONFIG].select {|k,v| !mask_column.include?(k)}
|
98
|
-
|
99
|
-
base.merge!(
|
100
|
-
mask_config
|
101
|
-
)
|
102
|
-
base.map {|k,v| "#{k.upcase}=#{v}"}.join("\n")
|
103
|
-
end
|
104
|
-
|
105
64
|
def security_group(host)
|
106
65
|
tenant = Yao::Tenant.list.find {|t| t.name == host.tenant }
|
107
66
|
ids = host.security_group.map do |name|
|
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.7.
|
4
|
+
version: 0.7.4
|
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
|
+
date: 2015-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -152,6 +152,14 @@ files:
|
|
152
152
|
- lib/pec/command/up.rb
|
153
153
|
- lib/pec/config_error.rb
|
154
154
|
- lib/pec/configure.rb
|
155
|
+
- lib/pec/coordinate.rb
|
156
|
+
- lib/pec/coordinate/base.rb
|
157
|
+
- lib/pec/coordinate/user_data.rb
|
158
|
+
- lib/pec/coordinate/user_data/base.rb
|
159
|
+
- lib/pec/coordinate/user_data/nic.rb
|
160
|
+
- lib/pec/coordinate/user_data/nic/base.rb
|
161
|
+
- lib/pec/coordinate/user_data/nic/rhel.rb
|
162
|
+
- lib/pec/coordinate/user_data/nic/ubuntu.rb
|
155
163
|
- lib/pec/handler.rb
|
156
164
|
- lib/pec/handler/availability_zone.rb
|
157
165
|
- lib/pec/handler/base.rb
|