37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
# File 'lib/fog/oraclecloud/models/compute/security_list.rb', line 37
def add_rule (port, list, rule_name=nil)
if !rule_name then rule_name = "#{name}_#{port}_#{list}" end
if port.is_a? Numeric then
secapps = Fog::Compute[:oraclecloud].security_applications.all_public
public_app = secapps.detect { |app|
Float(app.dport || 0) == port }
if public_app then
secapp = public_app.name
else
begin
custom_app = Fog::Compute[:oraclecloud].security_applications.get("#{name}_#{port}")
rescue Fog::Compute::OracleCloud::NotFound
custom_app = Fog::Compute[:oraclecloud].security_applications.create(
:name => "#{name}_#{port}",
:protocol => 'tcp',
:dport => port
)
end
secapp = custom_app.name
end
else
secapp = '/oracle/public/' + port
end
block = /\d{,2}|1\d{2}|2[0-4]\d|25[0-5]/
re = /\A#{block}\.#{block}\.#{block}\.#{block}\z/
if re =~ list then
begin
seclist = Fog::Compute[:oraclecloud].security_ip_lists.get("#{name}_#{list}")
rescue Fog::Compute::OracleCloud::NotFound
Fog::Logger.debug "Creating Security IP List for #{list}"
seclist = Fog::Compute[:oraclecloud].security_ip_lists.create(
:name => "#{name}_#{list}",
:secipentries => [list]
)
end
list_name = "seciplist:#{name}_#{list}"
else
list_name = list
end
begin
rule = Fog::Compute[:oraclecloud].security_rules.get(rule_name)
rescue Fog::Compute::OracleCloud::NotFound
Fog::Logger.debug "Creating Security Rule for #{list_name} to #{name} (app:#{port})"
rule = Fog::Compute[:oraclecloud].security_rules.create(
:application => secapp,
:name => rule_name,
:src_list => list_name,
:dst_list => "seclist:#{name}"
)
end
rule
end
|