pec 0.2.5 → 0.2.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 +4 -4
- data/lib/pec/configure/ethernet.rb +47 -4
- data/lib/pec/configure/user_data.rb +1 -15
- data/lib/pec/network/port.rb +10 -2
- data/lib/pec/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 35cad45133a8df40934711c27364efb26b8508a1
|
4
|
+
data.tar.gz: 55cef3480870581c1b2eddc60fdfa805ce9216e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de7ec22cd43e85a97ecf264875c5c021bd2c99529ad4c455ab70a72f9d967c2775817319b5e4b861fa2dacab2ecb1a0ab5f725376bac967e378cbd9f031312f8
|
7
|
+
data.tar.gz: 7e34e2de84215bbf238a70eabeba9a23c2fd8363afbf21f423fc75424a2d4a3172954c5298bfd1a59a2e822697ffa510db90879475f31cf2be3bc0192788d418
|
@@ -6,13 +6,56 @@ module Pec
|
|
6
6
|
@name = config[0];
|
7
7
|
@bootproto = config[1]["bootproto"];
|
8
8
|
@ip_address = config[1]["ip_address"];
|
9
|
-
@options = config[1].
|
10
|
-
{ k => v } if k
|
9
|
+
@options = config[1].reject do |k,v|
|
10
|
+
{ k => v } if k == "bootproto" || k == "ip_address"
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
15
|
-
|
14
|
+
def get_port_content(ports)
|
15
|
+
base = {
|
16
|
+
"bootproto" => @bootproto,
|
17
|
+
"name" => config_name,
|
18
|
+
"device" => device_name,
|
19
|
+
"type" => type,
|
20
|
+
"onboot" => onboot,
|
21
|
+
"hwaddr" => mac_address(ports),
|
22
|
+
}
|
23
|
+
base.merge!({ "netmask" => netmask(ports), "ipaddr" => port_ip_address(ports) }) if static?
|
24
|
+
base.merge!(@options) if @options
|
25
|
+
base.map {|k,v| "#{k.upcase}=#{v}"}.join("\n")
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
def config_name
|
30
|
+
@options["name"] || @name
|
31
|
+
end
|
32
|
+
|
33
|
+
def device_name
|
34
|
+
@options["device"] || @name
|
35
|
+
end
|
36
|
+
|
37
|
+
def type
|
38
|
+
@options["type"] || 'Ethernet'
|
39
|
+
end
|
40
|
+
|
41
|
+
def onboot
|
42
|
+
@options["onboot"] || 'yes'
|
43
|
+
end
|
44
|
+
|
45
|
+
def mac_address(ports)
|
46
|
+
ports.find { |p| p.device_name == @name }.mac_address
|
47
|
+
end
|
48
|
+
|
49
|
+
def netmask(ports)
|
50
|
+
ports.find { |p| p.device_name == @name }.netmask
|
51
|
+
end
|
52
|
+
|
53
|
+
def port_ip_address(ports)
|
54
|
+
ports.find { |p| p.device_name == @name }.ip_address
|
55
|
+
end
|
56
|
+
|
57
|
+
def static?
|
58
|
+
@bootproto == "static"
|
16
59
|
end
|
17
60
|
|
18
61
|
class << self
|
@@ -21,23 +21,9 @@ module Pec
|
|
21
21
|
|
22
22
|
def make_port_content(config, ports)
|
23
23
|
config.networks.map do |ether|
|
24
|
-
ifcfg_content = {}
|
25
|
-
ifcfg_content["bootproto"] = ether.bootproto
|
26
|
-
ifcfg_content["name"] = ether.options["name"] || ether.name
|
27
|
-
ifcfg_content["device"] = ether.options["device"] || ether.name
|
28
|
-
ifcfg_content["type"] = ether.options['type'] ||'Ethernet'
|
29
|
-
ifcfg_content["onboot"] = ether.options['onboot'] || 'yes'
|
30
|
-
ifcfg_content["hwaddr"] = ether.find_port(ports).mac_address
|
31
|
-
if ether.bootproto == "static"
|
32
|
-
ifcfg_content["netmask"] = ether.find_port(ports).netmask
|
33
|
-
ifcfg_content["ipaddr"] = ether.find_port(ports).ip_address
|
34
|
-
end
|
35
|
-
|
36
|
-
ifcfg_content.merge!(ether.options)
|
37
|
-
|
38
24
|
path = ether.options['path'] || "/etc/sysconfig/network-scripts/ifcfg-#{ether.name}"
|
39
25
|
{
|
40
|
-
'content' =>
|
26
|
+
'content' => ether.get_port_content(ports),
|
41
27
|
'owner' => "root:root",
|
42
28
|
'path' => path,
|
43
29
|
'permissions' => "0644"
|
data/lib/pec/network/port.rb
CHANGED
@@ -27,8 +27,8 @@ module Pec
|
|
27
27
|
response = Pec::Resource.get.create_port(subnet["network_id"], options)
|
28
28
|
|
29
29
|
raise(Pec::Errors::Port, "ip:#{ip.to_addr} is not created!") unless response
|
30
|
+
append_assigned_ip(response)
|
30
31
|
|
31
|
-
@@use_ip_list << response.data[:body]["port"]["fixed_ips"][0]["ip_address"]
|
32
32
|
response.data[:body]["port"]
|
33
33
|
end
|
34
34
|
|
@@ -40,6 +40,14 @@ module Pec
|
|
40
40
|
ip.to_s != subnet["cidr"] ? options.merge({ fixed_ips: [{ subnet_id: subnet["id"], ip_address: ip.to_addr}]}) : options
|
41
41
|
end
|
42
42
|
|
43
|
+
def append_assigned_ip(response)
|
44
|
+
@@use_ip_list << response.data[:body]["port"]["fixed_ips"][0]["ip_address"]
|
45
|
+
end
|
46
|
+
|
47
|
+
def assigned_ip?(port)
|
48
|
+
@@use_ip_list.include?(port["fixed_ips"][0]["ip_address"])
|
49
|
+
end
|
50
|
+
|
43
51
|
def get_free_port_ip(ip, subnet)
|
44
52
|
port = fetch_free_port(subnet)
|
45
53
|
port ? IP.new("#{port["fixed_ips"][0]["ip_address"]}/#{ip.pfxlen}") : ip
|
@@ -67,7 +75,7 @@ module Pec
|
|
67
75
|
p["fixed_ips"][0]["subnet_id"] == subnet["id"] &&
|
68
76
|
p["device_owner"].empty? &&
|
69
77
|
p["admin_state_up"] &&
|
70
|
-
|
78
|
+
!assigned_ip?
|
71
79
|
end
|
72
80
|
end
|
73
81
|
end
|
data/lib/pec/version.rb
CHANGED