wakame-vdc-dcmgr 11.06.0 → 11.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (136) hide show
  1. data/Rakefile +19 -31
  2. data/bin/collector +6 -1
  3. data/config/db/migrations/0001_v1110_origin.rb +446 -0
  4. data/config/dcmgr.conf.example +51 -0
  5. data/lib/dcmgr.rb +99 -22
  6. data/lib/dcmgr/cli/base.rb +34 -1
  7. data/lib/dcmgr/cli/host.rb +24 -20
  8. data/lib/dcmgr/cli/image.rb +38 -19
  9. data/lib/dcmgr/cli/keypair.rb +16 -12
  10. data/lib/dcmgr/cli/network.rb +189 -81
  11. data/lib/dcmgr/cli/quota.rb +2 -2
  12. data/lib/dcmgr/cli/security_group.rb +106 -0
  13. data/lib/dcmgr/cli/spec.rb +144 -39
  14. data/lib/dcmgr/cli/storage.rb +16 -15
  15. data/lib/dcmgr/cli/tag.rb +20 -14
  16. data/lib/dcmgr/cli/vlan.rb +5 -5
  17. data/lib/dcmgr/drivers/backing_store.rb +32 -0
  18. data/lib/dcmgr/drivers/comstar.rb +81 -0
  19. data/lib/dcmgr/drivers/iijgio_storage.rb +9 -19
  20. data/lib/dcmgr/drivers/iscsi_target.rb +41 -0
  21. data/lib/dcmgr/drivers/kvm.rb +161 -28
  22. data/lib/dcmgr/drivers/linux_iscsi.rb +60 -0
  23. data/lib/dcmgr/drivers/local_storage.rb +24 -0
  24. data/lib/dcmgr/drivers/lxc.rb +167 -125
  25. data/lib/dcmgr/drivers/raw.rb +74 -0
  26. data/lib/dcmgr/drivers/s3_storage.rb +7 -19
  27. data/lib/dcmgr/drivers/snapshot_storage.rb +18 -28
  28. data/lib/dcmgr/drivers/storage_initiator.rb +28 -0
  29. data/lib/dcmgr/drivers/sun_iscsi.rb +32 -0
  30. data/lib/dcmgr/drivers/zfs.rb +77 -0
  31. data/lib/dcmgr/endpoints/core_api.rb +315 -263
  32. data/lib/dcmgr/endpoints/errors.rb +21 -10
  33. data/lib/dcmgr/endpoints/metadata.rb +360 -23
  34. data/lib/dcmgr/helpers/cli_helper.rb +6 -3
  35. data/lib/dcmgr/helpers/ec2_metadata_helper.rb +9 -0
  36. data/lib/dcmgr/helpers/nic_helper.rb +11 -0
  37. data/lib/dcmgr/helpers/snapshot_storage_helper.rb +34 -0
  38. data/lib/dcmgr/models/account.rb +0 -6
  39. data/lib/dcmgr/models/account_resource.rb +0 -4
  40. data/lib/dcmgr/models/base_new.rb +14 -2
  41. data/lib/dcmgr/models/dhcp_range.rb +38 -0
  42. data/lib/dcmgr/models/frontend_system.rb +0 -6
  43. data/lib/dcmgr/models/history.rb +0 -11
  44. data/lib/dcmgr/models/host_node.rb +131 -0
  45. data/lib/dcmgr/models/hostname_lease.rb +0 -8
  46. data/lib/dcmgr/models/image.rb +31 -18
  47. data/lib/dcmgr/models/instance.rb +137 -143
  48. data/lib/dcmgr/models/instance_nic.rb +52 -29
  49. data/lib/dcmgr/models/instance_security_group.rb +9 -0
  50. data/lib/dcmgr/models/instance_spec.rb +163 -31
  51. data/lib/dcmgr/models/ip_lease.rb +10 -21
  52. data/lib/dcmgr/models/mac_lease.rb +30 -11
  53. data/lib/dcmgr/models/network.rb +148 -27
  54. data/lib/dcmgr/models/physical_network.rb +18 -0
  55. data/lib/dcmgr/models/quota.rb +0 -10
  56. data/lib/dcmgr/models/request_log.rb +3 -18
  57. data/lib/dcmgr/models/security_group.rb +66 -0
  58. data/lib/dcmgr/models/security_group_rule.rb +145 -0
  59. data/lib/dcmgr/models/ssh_key_pair.rb +16 -19
  60. data/lib/dcmgr/models/{storage_pool.rb → storage_node.rb} +35 -25
  61. data/lib/dcmgr/models/tag.rb +0 -14
  62. data/lib/dcmgr/models/tag_mapping.rb +1 -7
  63. data/lib/dcmgr/models/vlan_lease.rb +2 -8
  64. data/lib/dcmgr/models/volume.rb +49 -37
  65. data/lib/dcmgr/models/volume_snapshot.rb +15 -17
  66. data/lib/dcmgr/node_modules/hva_collector.rb +69 -28
  67. data/lib/dcmgr/node_modules/instance_ha.rb +23 -12
  68. data/lib/dcmgr/node_modules/instance_monitor.rb +16 -2
  69. data/lib/dcmgr/node_modules/openflow_controller.rb +784 -0
  70. data/lib/dcmgr/node_modules/scheduler.rb +189 -0
  71. data/lib/dcmgr/node_modules/service_netfilter.rb +452 -227
  72. data/lib/dcmgr/node_modules/service_openflow.rb +731 -0
  73. data/lib/dcmgr/node_modules/sta_collector.rb +20 -0
  74. data/lib/dcmgr/node_modules/sta_tgt_initializer.rb +35 -0
  75. data/lib/dcmgr/rack/request_logger.rb +11 -6
  76. data/lib/dcmgr/rpc/hva_handler.rb +256 -110
  77. data/lib/dcmgr/rpc/sta_handler.rb +244 -0
  78. data/lib/dcmgr/scheduler.rb +122 -8
  79. data/lib/dcmgr/scheduler/host_node/exclude_same.rb +24 -0
  80. data/lib/dcmgr/scheduler/host_node/find_first.rb +12 -0
  81. data/lib/dcmgr/scheduler/host_node/least_usage.rb +28 -0
  82. data/lib/dcmgr/scheduler/host_node/per_instance.rb +18 -0
  83. data/lib/dcmgr/scheduler/host_node/specify_node.rb +26 -0
  84. data/lib/dcmgr/scheduler/network/flat_single.rb +23 -0
  85. data/lib/dcmgr/scheduler/network/nat_one_to_one.rb +23 -0
  86. data/lib/dcmgr/scheduler/network/per_instance.rb +39 -0
  87. data/lib/dcmgr/scheduler/network/vif_template.rb +19 -0
  88. data/lib/dcmgr/scheduler/storage_node/find_first.rb +13 -0
  89. data/lib/dcmgr/scheduler/storage_node/least_usage.rb +23 -0
  90. data/lib/dcmgr/storage_service.rb +39 -40
  91. data/lib/dcmgr/tags.rb +3 -3
  92. data/lib/dcmgr/version.rb +1 -1
  93. data/lib/dcmgr/vnet.rb +105 -0
  94. data/lib/dcmgr/vnet/factories.rb +141 -0
  95. data/lib/dcmgr/vnet/isolators/by_securitygroup.rb +21 -0
  96. data/lib/dcmgr/vnet/isolators/dummy.rb +17 -0
  97. data/lib/dcmgr/vnet/netfilter/cache.rb +51 -0
  98. data/lib/dcmgr/vnet/netfilter/chain.rb +66 -0
  99. data/lib/dcmgr/vnet/netfilter/controller.rb +193 -0
  100. data/lib/dcmgr/vnet/netfilter/ebtables_rule.rb +53 -0
  101. data/lib/dcmgr/vnet/netfilter/iptables_rule.rb +45 -0
  102. data/lib/dcmgr/vnet/netfilter/task_manager.rb +459 -0
  103. data/lib/dcmgr/vnet/tasks/accept_all_dns.rb +19 -0
  104. data/lib/dcmgr/vnet/tasks/accept_arp_broadcast.rb +24 -0
  105. data/lib/dcmgr/vnet/tasks/accept_arp_from_friends.rb +34 -0
  106. data/lib/dcmgr/vnet/tasks/accept_arp_from_gateway.rb +21 -0
  107. data/lib/dcmgr/vnet/tasks/accept_arp_to_host.rb +30 -0
  108. data/lib/dcmgr/vnet/tasks/accept_ip_from_friends.rb +26 -0
  109. data/lib/dcmgr/vnet/tasks/accept_ip_from_gateway.rb +23 -0
  110. data/lib/dcmgr/vnet/tasks/accept_ip_to_anywhere.rb +18 -0
  111. data/lib/dcmgr/vnet/tasks/accept_related_established.rb +45 -0
  112. data/lib/dcmgr/vnet/tasks/accept_wakame_dhcp_only.rb +33 -0
  113. data/lib/dcmgr/vnet/tasks/accept_wakame_dns_only.rb +33 -0
  114. data/lib/dcmgr/vnet/tasks/debug_iptables.rb +21 -0
  115. data/lib/dcmgr/vnet/tasks/drop_arp_forwarding.rb +27 -0
  116. data/lib/dcmgr/vnet/tasks/drop_arp_to_host.rb +24 -0
  117. data/lib/dcmgr/vnet/tasks/drop_ip_from_anywhere.rb +18 -0
  118. data/lib/dcmgr/vnet/tasks/drop_ip_spoofing.rb +34 -0
  119. data/lib/dcmgr/vnet/tasks/drop_mac_spoofing.rb +33 -0
  120. data/lib/dcmgr/vnet/tasks/exclude_from_nat.rb +47 -0
  121. data/lib/dcmgr/vnet/tasks/security_group.rb +37 -0
  122. data/lib/dcmgr/vnet/tasks/static_nat.rb +54 -0
  123. data/lib/dcmgr/vnet/tasks/translate_metadata_address.rb +32 -0
  124. data/web/metadata/config.ru +1 -1
  125. metadata +174 -89
  126. data/lib/dcmgr/cli/group.rb +0 -101
  127. data/lib/dcmgr/endpoints/core_api_mock.rb +0 -865
  128. data/lib/dcmgr/models/host_pool.rb +0 -122
  129. data/lib/dcmgr/models/instance_netfilter_group.rb +0 -16
  130. data/lib/dcmgr/models/netfilter_group.rb +0 -89
  131. data/lib/dcmgr/models/netfilter_rule.rb +0 -21
  132. data/lib/dcmgr/scheduler/find_last.rb +0 -16
  133. data/lib/dcmgr/scheduler/find_random.rb +0 -16
  134. data/lib/dcmgr/stm/instance.rb +0 -25
  135. data/lib/dcmgr/stm/snapshot_context.rb +0 -33
  136. data/lib/dcmgr/stm/volume_context.rb +0 -65
@@ -0,0 +1,21 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ module Dcmgr
4
+ module VNet
5
+ module Isolators
6
+
7
+ # Isolates instances based on security groups
8
+ # Access to instances in another security group is blocked
9
+ class BySecurityGroup < Isolator
10
+ def determine_friends(me,others)
11
+ #TODO: make sure that me and others are vnic maps
12
+ others.dup.delete_if { |other|
13
+ # Delete if we are not in the same security group
14
+ me[:security_groups].find {|my_group| other[:security_groups].member?(my_group) }.nil?
15
+ }
16
+ end
17
+ end
18
+
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,17 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ module Dcmgr
4
+ module VNet
5
+ module Isolators
6
+
7
+ # This isolator just returns an empty array as friends
8
+ # This means all instances will be isolated from each other
9
+ class DummyIsolator < Isolator
10
+ def determine_friends(me,others)
11
+ []
12
+ end
13
+ end
14
+
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,51 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ module Dcmgr
4
+ module VNet
5
+ module Netfilter
6
+
7
+ class NetfilterCache < Cache
8
+ include Dcmgr::Logger
9
+
10
+ def initialize(node)
11
+ # Initialize the values needed to do rpc requests
12
+ @node = node
13
+ @rpc ||= Isono::NodeModules::RpcChannel.new(@node)
14
+ end
15
+
16
+ # Makes a call to the database and updates the Cache
17
+ def update
18
+ logger.info "updating cache from database"
19
+ @cache = @rpc.request('hva-collector', 'get_netfilter_data', @node.node_id)
20
+ end
21
+
22
+ # Returns the cache
23
+ # if _force_update_ is set to true, the cache will be updated from the database
24
+ def get(force_update = false)
25
+ self.update if @cache.nil? || force_update
26
+
27
+ # Always return a duplicate of the cache. We don't want any external program messing with the original contents.
28
+ #TODO: Do this in a faster way than marshall
29
+ Marshal.load( Marshal.dump(@cache) )
30
+ end
31
+
32
+ # Adds a newly started instance to the existing cache
33
+ def add_instance(inst_map)
34
+ if @cache.is_a? Hash
35
+ logger.info "adding instance '#{inst_map[:uuid]} to cache'"
36
+ @cache << inst_map
37
+ else
38
+
39
+ end
40
+ end
41
+
42
+ # Removes a terminated instance from the existing cache
43
+ def remove_instance(inst_id)
44
+ logger.info "removing Instance '#{inst_id}' from cache"
45
+ @cache[:instances].delete_if {|inst_map| inst_map[:uuid] == inst_id }
46
+ end
47
+ end
48
+
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,66 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ module Dcmgr
4
+ module VNet
5
+ module Netfilter
6
+
7
+ class Chain
8
+ attr_reader :name
9
+ attr_reader :table
10
+
11
+ def initialize(table,name)
12
+ @table = table
13
+ @name = name
14
+ end
15
+ end
16
+
17
+ #IptablesPreMadeChains = {
18
+ #:filter => [:input,:output,:forward],
19
+ #:nat => [:prerouting,:postrouting,:output],
20
+ #:mangle => [:prerouting,:output,:input,:postrouting],
21
+ #:raw => [:prerouting, :output]
22
+ #}
23
+
24
+ class IptablesChain < Chain
25
+ def initialize(table,name)
26
+ raise ArgumentError, "table #{table} doesn't exist. Existing tables are '#{self.class.pre_made.keys.join(",")}'." unless self.class.pre_made.keys.member?(table)
27
+ raise ArgumentError, "name can not be any of the following: '#{self.class.pre_made[table].join(",")}'." if self.class.pre_made[table].member?(name)
28
+
29
+ super
30
+ end
31
+
32
+ def self.pre_made
33
+ {
34
+ :filter => [:input,:output,:forward],
35
+ :nat => [:prerouting,:postrouting,:output],
36
+ :mangle => [:prerouting,:output,:input,:postrouting],
37
+ :raw => [:prerouting, :output]
38
+ }
39
+ end
40
+ end
41
+
42
+ #EbtablesPreMadeChains = {
43
+ #:filter => [:input,:output,:forward],
44
+ #:nat => [:prerouting,:postrouting,:output],
45
+ #:broute => [:brouting]
46
+ #}
47
+
48
+ class EbtablesChain < Chain
49
+ def initialize(table,name)
50
+ raise ArgumentError, "table #{table} doesn't exist. Existing tables are '#{self.class.pre_made.keys.join(",")}'." unless self.class.pre_made.keys.member?(table)
51
+ raise ArgumentError, "name can not be any of the following: '#{self.class.pre_made[table].join(",")}'." if self.class.pre_made[table].member?(name)
52
+
53
+ super
54
+ end
55
+
56
+ def self.pre_made
57
+ {
58
+ :filter => [:input,:output,:forward],
59
+ :nat => [:prerouting,:postrouting,:output],
60
+ :broute => [:brouting]
61
+ }
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,193 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ module Dcmgr
4
+ module VNet
5
+ module Netfilter
6
+
7
+ class NetfilterController < Controller
8
+ include Dcmgr::Logger
9
+ attr_accessor :task_manager
10
+ attr_reader :node
11
+
12
+ # This controller should use a cache
13
+
14
+ def initialize(node)
15
+ logger.info "initializing controller"
16
+ super()
17
+ @node = node
18
+
19
+ @cache = NetfilterCache.new(@node)
20
+
21
+ @isolator = IsolatorFactory.create_isolator
22
+
23
+ self.task_manager = TaskManagerFactory.create_task_manager(node)
24
+ raise "#{self.task_manager} must be a NetfilterTaskManager" unless self.task_manager.is_a?(NetfilterTaskManager)
25
+
26
+ # Initialize Netfilter configuration
27
+ cmds = []
28
+ cmds << init_iptables if node.manifest.config.enable_iptables
29
+ cmds << init_ebtables if node.manifest.config.enable_ebtables
30
+ cmds.flatten!
31
+
32
+ puts cmds.join("\n") if node.manifest.config.verbose_netfilter
33
+ system(cmds.join("\n"))
34
+
35
+ self.task_manager.apply_tasks([DebugIptables.new]) if node.manifest.config.debug_iptables
36
+
37
+ # Apply the current instances if there are any
38
+ @cache.get[:instances].each { |inst_map|
39
+ logger.info "initializing instance '#{inst_map[:uuid]}'"
40
+ self.init_instance(inst_map)
41
+ }
42
+ end
43
+
44
+ def apply_instance(instance)
45
+ if instance.is_a? String
46
+ # We got a uuid. Find it in the cache.
47
+ inst_map = @cache.get[:instances].find { |inst| inst[:uuid] == instance}
48
+
49
+ # If we couldn't find this instance's uuid in the cache, we update the cache and try again
50
+ if inst_map.nil?
51
+ @cache.update
52
+ inst_map = @cache.get[:instances].find { |inst| inst[:uuid] == instance}
53
+ end
54
+ elsif instance.is_a? Hash
55
+ inst_map = instance
56
+ else
57
+ raise ArgumentError, "instance must be either a uuid or an instance's hash map" unless instance.is_a? Hash
58
+ end
59
+
60
+ logger.info "applying instance '#{inst_map[:uuid]}'"
61
+
62
+ # Create all the rules for this instance
63
+ init_instance(inst_map)
64
+
65
+ # Apply isolation tasks for this new instance to its friends
66
+ inst_map[:vif].each { |vnic|
67
+ other_vnics = get_other_vnics(vnic,@cache)
68
+ # Determine which vnics need to be isolated from this one
69
+ friends = @isolator.determine_friends(vnic, other_vnics)
70
+
71
+ friends.each { |friend|
72
+ # Remove the drop rules so the isolation rules don't ger applied after them
73
+ #self.task_manager.remove_vnic_tasks(friend,TaskFactory.create_drop_tasks_for_vnic(friend,self.node))
74
+
75
+ # Put in the new isolation rules
76
+ self.task_manager.apply_vnic_tasks(friend,TaskFactory.create_tasks_for_isolation(friend,[vnic],self.node))
77
+ # Put the drop rules back
78
+ #self.task_manager.apply_vnic_tasks(friend,TaskFactory.create_drop_tasks_for_vnic(friend,self.node))
79
+ }
80
+ }
81
+ end
82
+
83
+ def get_other_vnics(vnic,cache)
84
+ cache.get[:instances].map { |inst_map|
85
+ inst_map[:vif].delete_if { |other_vnic|
86
+ other_vnic == vnic
87
+ }
88
+ }.flatten
89
+ end
90
+
91
+ def init_instance(inst_map)
92
+ # Call the factory to create all tasks for each vnic. Then apply them
93
+ inst_map[:vif].each { |vnic|
94
+ # Get a list of all other vnics in this host
95
+ other_vnics = get_other_vnics(vnic,@cache)
96
+
97
+ # Determine which vnics need to be isolated from this one
98
+ friends = @isolator.determine_friends(vnic, other_vnics)
99
+
100
+ # Determine the security group rules for this vnic
101
+ security_groups = @cache.get[:security_groups].delete_if { |group|
102
+ not vnic[:security_groups].member? group[:uuid]
103
+ }
104
+
105
+ self.task_manager.apply_vnic_chains(vnic)
106
+ self.task_manager.apply_vnic_tasks(vnic,TaskFactory.create_tasks_for_vnic(vnic,friends,security_groups,node))
107
+ }
108
+ end
109
+
110
+ def remove_instance(inst_id)
111
+ logger.info "removing instance '#{inst_id}'"
112
+ # Find the instance in the cache
113
+ inst_map = @cache.get[:instances].find { |inst| inst[:uuid] == inst_id}
114
+
115
+ #Clean up the isolation tasks in friends' chains
116
+ inst_map[:vif].each { |vnic|
117
+ other_vnics = get_other_vnics(vnic,@cache)
118
+ friends = @isolator.determine_friends(vnic, other_vnics)
119
+
120
+ friends.each { |friend|
121
+ self.task_manager.remove_vnic_tasks(friend,TaskFactory.create_tasks_for_isolation(friend,[vnic],self.node))
122
+ }
123
+ }
124
+
125
+ inst_map[:vif].each { |vnic|
126
+ # Removing the nat tasks separately because they include an arp reply
127
+ # that isn't put in a separate chain
128
+ other_vnics = get_other_vnics(vnic,@cache)
129
+ # Determine which vnics need to be isolated from this one
130
+ friends = @isolator.determine_friends(vnic, other_vnics)
131
+
132
+ self.task_manager.remove_vnic_tasks(vnic, TaskFactory.create_nat_tasks_for_vnic(vnic,self.node) )
133
+ self.task_manager.remove_vnic_chains(vnic)
134
+ }
135
+
136
+ # Remove the terminated instance from the cache
137
+ @cache.remove_instance(inst_id)
138
+ end
139
+
140
+ def update_security_group(group)
141
+ logger.info "updating security group '#{group}'"
142
+ # Get the old security group info from the cache
143
+ old_cache = @cache.get
144
+
145
+ # Get a list of vnics that are in this security group
146
+ vnics = old_cache[:instances].map {|inst_map| inst_map[:vif].delete_if { |vnic| not vnic[:security_groups].member?(group) } }.flatten
147
+ unless vnics.empty?
148
+ # Get the rules for this security group
149
+ old_group = old_cache[:security_groups].find {|sg| sg[:uuid] == group}
150
+
151
+ # Get the new info from the cache
152
+ new_cache = @cache.get(true)
153
+ new_group = new_cache[:security_groups].find {|sg| sg[:uuid] == group}
154
+
155
+ vnics.each { |vnic_map|
156
+ # Remove the old security group tasks
157
+ self.task_manager.remove_vnic_tasks(vnic_map, TaskFactory.create_tasks_for_secgroup(old_group))
158
+
159
+ # Remove the drop tasks so the new group's tasks don't get applied behind it
160
+ #self.task_manager.remove_vnic_tasks(vnic_map, TaskFactory.create_drop_tasks_for_vnic(vnic_map,self.node))
161
+ # Add the new security group tasks
162
+ self.task_manager.apply_vnic_tasks(vnic_map, TaskFactory.create_tasks_for_secgroup(new_group))
163
+ # Put the drop tasks back in place
164
+ #self.task_manager.apply_vnic_tasks(vnic_map, TaskFactory.create_drop_tasks_for_vnic(vnic_map,self.node))
165
+ }
166
+ end
167
+ end
168
+
169
+ private
170
+ def init_iptables
171
+ [
172
+ "iptables -t nat -F",
173
+ "iptables -t nat -X",
174
+ "iptables -t nat -Z",
175
+ "iptables -t filter -F",
176
+ "iptables -t filter -X",
177
+ "iptables -t filter -Z",
178
+ #"iptables -t filter -P FORWARD DROP"
179
+ ]
180
+ end
181
+
182
+ def init_ebtables
183
+ [
184
+ "ebtables -t nat --init-table",
185
+ "ebtables -t filter --init-table",
186
+ #"ebtables -t filter -P FORWARD DROP"
187
+ ]
188
+ end
189
+ end
190
+
191
+ end
192
+ end
193
+ end
@@ -0,0 +1,53 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ module Dcmgr
4
+ module VNet
5
+ module Netfilter
6
+
7
+ class EbtablesRule < Rule
8
+ attr_accessor :table
9
+ attr_accessor :chain
10
+ attr_accessor :rule
11
+ # Should be either :incoming or :outgoing
12
+ attr_accessor :bound
13
+ attr_accessor :protocol
14
+
15
+ def initialize(table = nil, chain = nil, protocol = nil, bound = nil, rule = nil)
16
+ super()
17
+ raise ArgumentError, "table does not exist: #{table}" unless EbtablesChain.pre_made.keys.member?(table)
18
+ self.table = table
19
+ self.chain = chain
20
+ self.protocol = protocol
21
+ self.bound = bound
22
+ self.rule = rule
23
+ end
24
+
25
+ # Override the chain getter to allow us to handle premade chains
26
+ # with symbols instead of all caps strings. ie, :forward instead of "FORWARD"
27
+ def chain
28
+ if EbtablesChain.pre_made[self.table].member?(@chain)
29
+ @chain.to_s.upcase
30
+ else
31
+ @chain
32
+ end
33
+ end
34
+
35
+ # Little static method that returns the part of an ebtables rule required for logging arp
36
+ def self.log_arp(prefix)
37
+ "--log-ip --log-arp --log-prefix '#{prefix}'"
38
+ end
39
+
40
+ # Getter for a hashmap of ebtables protocols
41
+ def self.protocols
42
+ {
43
+ 'ip4' => 'ip4',
44
+ 'arp' => 'arp',
45
+ #'ip6' => 'ip6',
46
+ #'rarp' => '0x8035',
47
+ }
48
+ end
49
+ end
50
+
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,45 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ module Dcmgr
4
+ module VNet
5
+ module Netfilter
6
+
7
+ class IptablesRule < Rule
8
+ attr_accessor :table
9
+ attr_accessor :chain
10
+ attr_accessor :rule
11
+ # Should be either :incoming or :outgoing
12
+ attr_accessor :bound
13
+ attr_accessor :protocol
14
+
15
+ def initialize(table = nil, chain = nil, protocol = nil, bound = nil, rule = nil)
16
+ super()
17
+ raise ArgumentError, "table does not exist: #{table}" unless IptablesChain.pre_made.keys.member?(table)
18
+ self.table = table
19
+ self.chain = chain
20
+ self.protocol = protocol
21
+ self.bound = bound
22
+ self.rule = rule
23
+ end
24
+
25
+ def chain
26
+ if IptablesChain.pre_made[self.table].member?(@chain)
27
+ @chain.to_s.upcase
28
+ else
29
+ @chain
30
+ end
31
+ end
32
+
33
+ # Getter for the protocols iptables supports
34
+ def self.protocols
35
+ {
36
+ 'tcp' => 'tcp',
37
+ 'udp' => 'udp',
38
+ 'icmp' => 'icmp',
39
+ }
40
+ end
41
+ end
42
+
43
+ end
44
+ end
45
+ end