mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-22 18:50:08 +03:00
Feature #863: Change old net hooks to act as mad scripts
This commit is contained in:
parent
7efcb0e140
commit
bea7da7475
@ -14,6 +14,8 @@
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
require 'OpenNebulaNetwork'
|
||||
|
||||
class OpenNebulaHM < OpenNebulaNetwork
|
||||
def initialize(vm, hypervisor = nil)
|
||||
super(vm,hypervisor)
|
||||
@ -48,12 +50,8 @@ class OpenNebulaHM < OpenNebulaNetwork
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def deactivate
|
||||
vm_id = @vm['ID']
|
||||
process do |nic|
|
||||
end
|
||||
return 0
|
||||
end
|
||||
|
||||
def bridge_exists?(bridge)
|
||||
@ -61,7 +59,7 @@ class OpenNebulaHM < OpenNebulaNetwork
|
||||
end
|
||||
|
||||
def create_bridge(bridge)
|
||||
system("#{COMMANDS[:brctl]} addbr #{bridge}")
|
||||
exec_and_log("#{COMMANDS[:brctl]} addbr #{bridge}")
|
||||
end
|
||||
|
||||
def device_exists?(dev, vlan=nil)
|
||||
@ -70,7 +68,7 @@ class OpenNebulaHM < OpenNebulaNetwork
|
||||
end
|
||||
|
||||
def create_dev_vlan(dev, vlan)
|
||||
system("#{COMMANDS[:vconfig]} add #{dev} #{vlan}")
|
||||
exec_and_log("#{COMMANDS[:vconfig]} add #{dev} #{vlan}")
|
||||
end
|
||||
|
||||
def attached_bridge_dev?(bridge, dev, vlan=nil)
|
||||
@ -81,11 +79,11 @@ class OpenNebulaHM < OpenNebulaNetwork
|
||||
|
||||
def attach_brigde_dev(bridge, dev, vlan=nil)
|
||||
dev = "#{dev}.#{vlan}" if vlan
|
||||
system("#{COMMANDS[:brctl]} addif #{bridge} #{dev}")
|
||||
exec_and_log("#{COMMANDS[:brctl]} addif #{bridge} #{dev}")
|
||||
end
|
||||
|
||||
def ifup(dev, vlan=nil)
|
||||
dev = "#{dev}.#{vlan}" if vlan
|
||||
system("#{COMMANDS[:ip]} link set #{dev} up")
|
||||
exec_and_log("#{COMMANDS[:ip]} link set #{dev} up")
|
||||
end
|
||||
end
|
||||
|
19
src/vnm_mad/remotes/802.1Q/clean
Executable file
19
src/vnm_mad/remotes/802.1Q/clean
Executable file
@ -0,0 +1,19 @@
|
||||
#!/bin/bash
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
exit 0
|
19
src/vnm_mad/remotes/802.1Q/post
Executable file
19
src/vnm_mad/remotes/802.1Q/post
Executable file
@ -0,0 +1,19 @@
|
||||
#!/bin/bash
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
exit 0
|
25
src/vnm_mad/remotes/802.1Q/pre
Executable file
25
src/vnm_mad/remotes/802.1Q/pre
Executable file
@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
$: << File.dirname(__FILE__)
|
||||
$: << File.join(File.dirname(__FILE__), "..")
|
||||
|
||||
require 'HostManaged'
|
||||
|
||||
hm = OpenNebulaHM.from_base64(ARGV[0])
|
||||
exit hm.activate
|
@ -20,6 +20,7 @@ $: << File.dirname(__FILE__)
|
||||
|
||||
require 'rexml/document'
|
||||
require 'OpenNebulaNic'
|
||||
require 'base64'
|
||||
|
||||
CONF = {
|
||||
:start_vlan => 2
|
||||
@ -98,6 +99,11 @@ end
|
||||
class OpenNebulaNetwork
|
||||
attr_reader :hypervisor, :vm
|
||||
|
||||
def self.from_base64(vm_64, hypervisor=nil)
|
||||
vm_xml = Base64::decode64(vm_64)
|
||||
self.new(vm_xml, hypervisor)
|
||||
end
|
||||
|
||||
def initialize(vm_tpl, hypervisor=nil)
|
||||
if !hypervisor
|
||||
@hypervisor = detect_hypervisor
|
||||
|
19
src/vnm_mad/remotes/dummy/clean
Executable file
19
src/vnm_mad/remotes/dummy/clean
Executable file
@ -0,0 +1,19 @@
|
||||
#!/bin/bash
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
exit 0
|
19
src/vnm_mad/remotes/dummy/post
Executable file
19
src/vnm_mad/remotes/dummy/post
Executable file
@ -0,0 +1,19 @@
|
||||
#!/bin/bash
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
exit 0
|
19
src/vnm_mad/remotes/dummy/pre
Executable file
19
src/vnm_mad/remotes/dummy/pre
Executable file
@ -0,0 +1,19 @@
|
||||
#!/bin/bash
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
exit 0
|
@ -14,15 +14,19 @@
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
require 'OpenNebulaNetwork'
|
||||
|
||||
class EbtablesVLAN < OpenNebulaNetwork
|
||||
def initialize(vm, hypervisor = nil)
|
||||
super(vm,hypervisor)
|
||||
end
|
||||
|
||||
def ebtables(rule)
|
||||
system("#{COMMANDS[:ebtables]} -A #{rule}")
|
||||
exec_and_log("#{COMMANDS[:ebtables]} -A #{rule}")
|
||||
end
|
||||
|
||||
# Activates ebtables rules
|
||||
#
|
||||
def activate
|
||||
process do |nic|
|
||||
tap = nic[:tap]
|
||||
@ -42,6 +46,8 @@ class EbtablesVLAN < OpenNebulaNetwork
|
||||
ebtables(out_rule)
|
||||
end
|
||||
end
|
||||
|
||||
return 0
|
||||
end
|
||||
|
||||
def deactivate
|
||||
@ -59,6 +65,8 @@ class EbtablesVLAN < OpenNebulaNetwork
|
||||
end
|
||||
remove_rules(tap)
|
||||
end
|
||||
|
||||
return 0
|
||||
end
|
||||
|
||||
def rules
|
||||
@ -74,6 +82,6 @@ class EbtablesVLAN < OpenNebulaNetwork
|
||||
end
|
||||
|
||||
def remove_rule(rule)
|
||||
system("#{COMMANDS[:ebtables]} -D FORWARD #{rule}")
|
||||
exec_and_log("#{COMMANDS[:ebtables]} -D FORWARD #{rule}")
|
||||
end
|
||||
end
|
||||
|
@ -17,13 +17,12 @@
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
$: << File.dirname(__FILE__)
|
||||
$: << File.join(File.dirname(__FILE__), "..")
|
||||
|
||||
require 'base64'
|
||||
require 'OpenNebulaNetwork'
|
||||
require 'HostManaged'
|
||||
require 'Ebtables'
|
||||
|
||||
template = ARGV[0]
|
||||
vm_xml = Base64::decode64(template)
|
||||
|
||||
hm = OpenNebulaHM.new(vm_xml)
|
||||
hm.activate
|
||||
onevlan = EbtablesVLAN.from_base64(template)
|
||||
|
||||
exit onevlan.deactivate
|
@ -17,24 +17,14 @@
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
$: << File.dirname(__FILE__)
|
||||
$: << File.join(File.dirname(__FILE__), "..")
|
||||
|
||||
require 'base64'
|
||||
require 'OpenNebulaNetwork'
|
||||
require 'Ebtables'
|
||||
|
||||
action = ARGV[0]
|
||||
template = ARGV[1]
|
||||
|
||||
# Uncomment to act only on the listed bridges.
|
||||
#FILTERED_BRIDGES = ['br0']
|
||||
|
||||
vm_xml = Base64::decode64(template)
|
||||
onevlan = EbtablesVLAN.new(vm_xml)
|
||||
onevlan = EbtablesVLAN.from_base64(ARGV[0])
|
||||
|
||||
case action
|
||||
when "on"
|
||||
onevlan.filter(:bridge => FILTERED_BRIDGES) if defined? FILTERED_BRIDGES
|
||||
onevlan.activate
|
||||
when "off"
|
||||
onevlan.deactivate
|
||||
end
|
||||
onevlan.filter(:bridge => FILTERED_BRIDGES) if defined? FILTERED_BRIDGES
|
||||
exit onevlan.activate
|
19
src/vnm_mad/remotes/ebtables/pre
Executable file
19
src/vnm_mad/remotes/ebtables/pre
Executable file
@ -0,0 +1,19 @@
|
||||
#!/bin/bash
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
exit 0
|
@ -14,6 +14,8 @@
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
require 'OpenNebulaNetwork'
|
||||
|
||||
class OpenvSwitchVLAN < OpenNebulaNetwork
|
||||
def initialize(vm, hypervisor = nil)
|
||||
super(vm,hypervisor)
|
||||
@ -30,7 +32,9 @@ class OpenvSwitchVLAN < OpenNebulaNetwork
|
||||
cmd = "#{COMMANDS[:ovs_vsctl]} set Port #{nic[:tap]} "
|
||||
cmd << "tag=#{vlan}"
|
||||
|
||||
system(cmd)
|
||||
exec_and_log(cmd)
|
||||
end
|
||||
|
||||
return 0
|
||||
end
|
||||
end
|
||||
|
19
src/vnm_mad/remotes/ovswtich/clean
Executable file
19
src/vnm_mad/remotes/ovswtich/clean
Executable file
@ -0,0 +1,19 @@
|
||||
#!/bin/bash
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
exit 0
|
@ -18,12 +18,8 @@
|
||||
|
||||
$: << File.dirname(__FILE__)
|
||||
|
||||
require 'base64'
|
||||
require 'OpenNebulaNetwork'
|
||||
require 'OpenvSwitch'
|
||||
|
||||
template = ARGV[0]
|
||||
vm_xml = Base64::decode64(template)
|
||||
|
||||
onevlan = OpenvSwitchVLAN.new(vm_xml)
|
||||
onevlan.activate
|
||||
onevlan = OpenvSwitchVLAN.from_base64(ARGV[0])
|
||||
exit onevlan.activate()
|
19
src/vnm_mad/remotes/ovswtich/pre
Executable file
19
src/vnm_mad/remotes/ovswtich/pre
Executable file
@ -0,0 +1,19 @@
|
||||
#!/bin/bash
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org) #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
exit 0
|
Loading…
x
Reference in New Issue
Block a user