Revision 4f2839dd share/hooks/OpenNebulaVLAN.rb

View differences:

share/hooks/OpenNebulaVLAN.rb
1 1
#!/usr/bin/env ruby
2 2

  
3
# -------------------------------------------------------------------------- #
4
# Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org)             #
5
#                                                                            #
6
# Licensed under the Apache License, Version 2.0 (the "License"); you may    #
7
# not use this file except in compliance with the License. You may obtain    #
8
# a copy of the License at                                                   #
9
#                                                                            #
10
# http://www.apache.org/licenses/LICENSE-2.0                                 #
11
#                                                                            #
12
# Unless required by applicable law or agreed to in writing, software        #
13
# distributed under the License is distributed on an "AS IS" BASIS,          #
14
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
15
# See the License for the specific language governing permissions and        #
16
# limitations under the License.                                             #
17
#--------------------------------------------------------------------------- #
18

  
3 19
require 'rexml/document'
4 20

  
5 21
CONF = {
......
100 116
        when "kvm"
101 117
            @vm_info[:dumpxml] = `#{COMMANDS[:virsh]} dumpxml #{@deploy_id}`
102 118
        when "xen"
119
            @vm_info[:domid]    =`#{CONF[:xm]} domid #{VM_NAME}`.strip
120
            @vm_info[:networks] =`#{CONF[:xm]} network-list #{vm_id}`
103 121
        end
104 122

  
105 123
        @nics = get_nics
......
179 197
    def activate
180 198
        process do |nic|
181 199
            cmd =   "#{COMMANDS[:ovs_vsctl]} set Port #{nic[:tap]} "
182
            cmd <<  "tap=#{nic[:network_id].to_i+CONF[:start_vlan]}"
200
            cmd <<  "tap=#{nic[:network_id].to_i + CONF[:start_vlan]}"
183 201

  
184 202
            #TODO: execute command
185 203
            puts cmd
......
192 210
    def initialize(vm, hypervisor = nil)
193 211
        super(vm,hypervisor)
194 212
    end
213

  
214
    def ebtables(rule)
215
        system "#{CONF[:ebtables]} -A #{rule}"
216
    end
217

  
218
    def activate
219
        process do |nic|
220
            tap = nic[:tap]
221
            iface_mac = nic[:mac]
222
         
223
            mac     = iface_mac.split(':')
224
            mac[-1] = '00'
225

  
226
            net_mac = mac.join(':')
227
         
228
            in_rule="FORWARD -s ! #{net_mac}/ff:ff:ff:ff:ff:00 -o #{tap} -j DROP"
229
            out_rule="FORWARD -s ! #{iface_mac} -i #{tap} -j DROP"
230
         
231
            ebtables(in_rule)
232
            ebtables(out_rule)
233
        end
234
    end
195 235
end

Also available in: Unified diff