pec 0.3.3 → 0.4.0
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 +4 -4
- data/lib/pec/configure.rb +3 -2
- data/lib/pec/configure/ethernet.rb +16 -19
- data/lib/pec/configure/host.rb +22 -28
- data/lib/pec/director.rb +2 -0
- data/lib/pec/director/helper.rb +6 -4
- data/lib/pec/version.rb +1 -1
- data/pec.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 51d1f4a559c7dc366bb4c442104d9760484bef59
|
4
|
+
data.tar.gz: 437e6972dc94cbe1ac4b972206973b08156a1919
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc363157a8f5b2c33e1fbf32460aae9d4abde925ca46f7dea1ca37585f10db1a176e0ca70b36d7a16b45b997d461019c8f13421d7e45951c1e01110386a2d5a1
|
7
|
+
data.tar.gz: 5cecc2df45db91965807350748c6a60d12c7891d0eac9c4c74a87140379391a42927ad3d4c4a8aaa6ac01c827ef683a9c4663fae1bd5a6993bafd2a398ea58a8
|
data/lib/pec/configure.rb
CHANGED
@@ -4,6 +4,8 @@ module Pec
|
|
4
4
|
include Enumerable
|
5
5
|
|
6
6
|
def initialize(file_name)
|
7
|
+
@configure = []
|
8
|
+
|
7
9
|
if file_name.is_a?(Hash)
|
8
10
|
hash = file_name
|
9
11
|
else
|
@@ -11,8 +13,7 @@ module Pec
|
|
11
13
|
end
|
12
14
|
|
13
15
|
hash.each do |config|
|
14
|
-
host = Pec::Configure::Host.
|
15
|
-
@configure ||= []
|
16
|
+
host = Pec::Configure::Host.new(config)
|
16
17
|
@configure << host if host
|
17
18
|
end
|
18
19
|
rescue Psych::SyntaxError,NoMethodError => e
|
@@ -2,7 +2,10 @@ module Pec
|
|
2
2
|
class Configure
|
3
3
|
class Ethernet
|
4
4
|
attr_reader :name, :bootproto, :ip_address, :options
|
5
|
-
def initialize(config)
|
5
|
+
def initialize(name, config)
|
6
|
+
check_require_key(name, config)
|
7
|
+
check_network_key(name, config)
|
8
|
+
|
6
9
|
@name = config[0];
|
7
10
|
@bootproto = config[1]["bootproto"];
|
8
11
|
@ip_address = config[1]["ip_address"];
|
@@ -58,26 +61,20 @@ module Pec
|
|
58
61
|
@bootproto == "static"
|
59
62
|
end
|
60
63
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
def check_require_key(name, config)
|
67
|
-
raise(Pec::Errors::Ethernet, "skip! #{name}: bootproto is required!") if config[1]["bootproto"].nil?
|
68
|
-
true
|
69
|
-
end
|
64
|
+
def check_require_key(name, config)
|
65
|
+
raise(Pec::Errors::Ethernet, "skip! #{name}: bootproto is required!") if config[1]["bootproto"].nil?
|
66
|
+
true
|
67
|
+
end
|
70
68
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
end
|
79
|
-
true
|
69
|
+
def check_network_key(name, config)
|
70
|
+
net = config[1]
|
71
|
+
case
|
72
|
+
when (net["bootproto"] == "static" && net["ip_address"].nil?)
|
73
|
+
raise(Pec::Errors::Ethernet, "skip! #{name}: ip_address is required by bootproto static")
|
74
|
+
when (net["bootproto"] != "static" && net["bootproto"] != "dhcp")
|
75
|
+
raise(Pec::Errors::Ethernet, "skip! #{name}: bootproto set the value dhcp or static")
|
80
76
|
end
|
77
|
+
true
|
81
78
|
end
|
82
79
|
end
|
83
80
|
end
|
data/lib/pec/configure/host.rb
CHANGED
@@ -3,42 +3,36 @@ module Pec
|
|
3
3
|
class Host
|
4
4
|
attr_reader :name, :image, :flavor,:security_group, :user_data, :networks, :templates, :tenant
|
5
5
|
def initialize(config)
|
6
|
-
|
7
|
-
|
8
|
-
@
|
6
|
+
check_format(config)
|
7
|
+
append_network(config[1])
|
8
|
+
@name = config[0];
|
9
|
+
@image = config[1]["image"];
|
10
|
+
@flavor = config[1]["flavor"];
|
9
11
|
@security_group = config[1]["security_group"];
|
10
|
-
@user_data
|
11
|
-
@templates
|
12
|
-
@tenant
|
12
|
+
@user_data = config[1]["user_data"];
|
13
|
+
@templates = config[1]["templates"]
|
14
|
+
@tenant = config[1]["tenant"]
|
13
15
|
end
|
14
16
|
|
15
|
-
def append_network(
|
17
|
+
def append_network(config)
|
16
18
|
@networks ||= []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
class << self
|
21
|
-
def load(config)
|
22
|
-
host = self.new(config) if check_format(config)
|
19
|
+
config["networks"].each do |net|
|
20
|
+
raise(Pec::Errors::Ethernet, "please! network interface format is Array") unless net.kind_of?(Array)
|
23
21
|
|
24
|
-
config
|
25
|
-
|
22
|
+
if ethernet = Pec::Configure::Ethernet.new(config, net)
|
23
|
+
@networks << ethernet
|
24
|
+
end
|
26
25
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
end if host && config[1]["networks"]
|
31
|
-
host
|
32
|
-
end
|
26
|
+
end if config["networks"]
|
27
|
+
end
|
33
28
|
|
34
|
-
|
35
|
-
|
36
|
-
|
29
|
+
def check_format(config)
|
30
|
+
err = %w(image flavor tenant).find {|r| !config[1].key?(r) || config[1][r].nil? }
|
31
|
+
raise(Pec::Errors::Host,"skip! #{config[0]}: #{err} is required!") unless err.nil?
|
37
32
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
end
|
33
|
+
err = %w(security_group templates).find {|r| config[1].key?(r) && !config[1][r].kind_of?(Array) }
|
34
|
+
raise(Pec::Errors::Host,"#{config[0]}: please! #{err} format is Array!") unless err.nil?
|
35
|
+
true
|
42
36
|
end
|
43
37
|
end
|
44
38
|
end
|
data/lib/pec/director.rb
CHANGED
@@ -10,6 +10,8 @@ class Director
|
|
10
10
|
director.execute!(host) if director.do_it?(host)
|
11
11
|
rescue Pec::Errors::Error => e
|
12
12
|
director.err_message(e, host)
|
13
|
+
rescue Excon::Errors::SocketError => e
|
14
|
+
err_message(e)
|
13
15
|
rescue Excon::Errors::Error => e
|
14
16
|
excon_err_message(e)
|
15
17
|
end
|
data/lib/pec/director/helper.rb
CHANGED
@@ -7,11 +7,13 @@ module Pec
|
|
7
7
|
host.networks.map do |ether|
|
8
8
|
ip = IP.new(ether.ip_address)
|
9
9
|
|
10
|
-
port_subnet = Pec::Network::Subnet.fetch_by_cidr(ip.network.to_s)
|
11
|
-
|
10
|
+
unless port_subnet = Pec::Network::Subnet.fetch_by_cidr(ip.network.to_s)
|
11
|
+
raise(Pec::Errors::Subnet, "subnet:#{ip.network.to_s} is not fond!")
|
12
|
+
end
|
12
13
|
|
13
|
-
port = Pec::Network::Port.assign(ether.name, ip, port_subnet, get_security_group_id(host.security_group))
|
14
|
-
|
14
|
+
unless port = Pec::Network::Port.assign(ether.name, ip, port_subnet, get_security_group_id(host.security_group))
|
15
|
+
raise(Pec::Errors::Port, "ip addess:#{ip.to_addr} can't create port!")
|
16
|
+
end
|
15
17
|
|
16
18
|
puts "#{host.name}: assingn ip #{port.ip_address}".green
|
17
19
|
port
|
data/lib/pec/version.rb
CHANGED
data/pec.gemspec
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
spec.add_dependency 'thor', '~> 0.19.1'
|
21
|
-
spec.add_dependency 'fog', '~> 1.
|
21
|
+
spec.add_dependency 'fog', '~> 1.32.0'
|
22
22
|
spec.add_dependency 'ruby-ip', '~> 0.9.3'
|
23
23
|
spec.add_dependency 'activesupport', '~> 4.2.1'
|
24
24
|
spec.add_dependency 'colorator', '~> 0.1'
|
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.
|
4
|
+
version: 0.4.0
|
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-07-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 1.
|
33
|
+
version: 1.32.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 1.
|
40
|
+
version: 1.32.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: ruby-ip
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|