Class: Kakine::Resource::OpenStack
- Inherits:
-
Object
- Object
- Kakine::Resource::OpenStack
- Defined in:
- lib/kakine/resource/openstack.rb
Class Method Summary collapse
- .format_security_group_rules(security_group) ⇒ Object
- .load_security_group ⇒ Object
- .port_hash(rule) ⇒ Object
- .remote_hash(rule) ⇒ Object
- .security_group(tenant_name, security_group_name) ⇒ Object
- .security_groups_hash ⇒ Object
- .security_groups_on_tenant(tenant_name) ⇒ Object
Class Method Details
.format_security_group_rules(security_group) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/kakine/resource/openstack.rb', line 30 def format_security_group_rules(security_group) security_group.rules.map do |rule| rule_hash = {} rule_hash["id"] = rule['id'] rule_hash["direction"] = rule['direction'] rule_hash["protocol"] = rule['protocol'] rule_hash["ethertype"] = rule['ethertype'] rule_hash.merge!(port_hash(rule)) rule_hash.merge!(remote_hash(rule)) end end |
.load_security_group ⇒ Object
5 6 7 8 9 |
# File 'lib/kakine/resource/openstack.rb', line 5 def load_security_group security_groups_hash.map do |sg| Kakine::SecurityGroup.new(Kakine::Option.tenant_name, sg) end end |
.port_hash(rule) ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/kakine/resource/openstack.rb', line 42 def port_hash(rule) case when rule['protocol'] == "icmp" { "type" => rule['port_range_min'], "code" => rule['port_range_max'] } when rule['port_range_max'] == rule['port_range_min'] { "port" => rule['port_range_max'] } else { "port_range_min" => rule['port_range_min'], "port_range_max" => rule['port_range_max'] } end end |
.remote_hash(rule) ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/kakine/resource/openstack.rb', line 53 def remote_hash(rule) case when rule['remote_group_id'] response = Kakine::Adapter.instance.get_security_group(rule['remote_group_id']) { "remote_group" => response.name } else { "remote_ip" => rule['remote_ip_prefix'] } end end |
.security_group(tenant_name, security_group_name) ⇒ Object
11 12 13 |
# File 'lib/kakine/resource/openstack.rb', line 11 def security_group(tenant_name, security_group_name) security_groups_on_tenant(tenant_name).detect{|sg| sg.name == security_group_name} end |
.security_groups_hash ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/kakine/resource/openstack.rb', line 19 def security_groups_hash sg_hash = Hash.new { |h,k| h[k] = {} } security_groups_on_tenant(Kakine::Option.tenant_name).each do |sg| sg_hash[sg.name]["rules"] = format_security_group_rules(sg) sg_hash[sg.name]["id"] = sg.id sg_hash[sg.name]["description"] = sg.description end sg_hash end |