From bea7da7475f7c6ab9ecb0395d805526ba99fdd86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Fri, 11 Nov 2011 17:09:26 +0100 Subject: [PATCH] Feature #863: Change old net hooks to act as mad scripts --- src/vnm_mad/remotes/802.1Q/HostManaged.rb | 16 ++++++------ src/vnm_mad/remotes/802.1Q/clean | 19 ++++++++++++++ src/vnm_mad/remotes/802.1Q/post | 19 ++++++++++++++ src/vnm_mad/remotes/802.1Q/pre | 25 +++++++++++++++++++ src/vnm_mad/remotes/OpenNebulaNetwork.rb | 6 +++++ src/vnm_mad/remotes/dummy/clean | 19 ++++++++++++++ src/vnm_mad/remotes/dummy/post | 19 ++++++++++++++ src/vnm_mad/remotes/dummy/pre | 19 ++++++++++++++ src/vnm_mad/remotes/ebtables/Ebtables.rb | 12 +++++++-- .../{802.1Q/hm-vlan => ebtables/clean} | 11 ++++---- .../remotes/ebtables/{ebtables-vlan => post} | 18 +++---------- src/vnm_mad/remotes/ebtables/pre | 19 ++++++++++++++ src/vnm_mad/remotes/ovswtich/OpenvSwitch.rb | 6 ++++- src/vnm_mad/remotes/ovswtich/clean | 19 ++++++++++++++ .../ovswtich/{openvswitch-vlan => post} | 8 ++---- src/vnm_mad/remotes/ovswtich/pre | 19 ++++++++++++++ 16 files changed, 216 insertions(+), 38 deletions(-) create mode 100755 src/vnm_mad/remotes/802.1Q/clean create mode 100755 src/vnm_mad/remotes/802.1Q/post create mode 100755 src/vnm_mad/remotes/802.1Q/pre create mode 100755 src/vnm_mad/remotes/dummy/clean create mode 100755 src/vnm_mad/remotes/dummy/post create mode 100755 src/vnm_mad/remotes/dummy/pre rename src/vnm_mad/remotes/{802.1Q/hm-vlan => ebtables/clean} (89%) rename src/vnm_mad/remotes/ebtables/{ebtables-vlan => post} (80%) create mode 100755 src/vnm_mad/remotes/ebtables/pre create mode 100755 src/vnm_mad/remotes/ovswtich/clean rename src/vnm_mad/remotes/ovswtich/{openvswitch-vlan => post} (90%) create mode 100755 src/vnm_mad/remotes/ovswtich/pre diff --git a/src/vnm_mad/remotes/802.1Q/HostManaged.rb b/src/vnm_mad/remotes/802.1Q/HostManaged.rb index bda6286ef1..631d4ec2dc 100644 --- a/src/vnm_mad/remotes/802.1Q/HostManaged.rb +++ b/src/vnm_mad/remotes/802.1Q/HostManaged.rb @@ -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 diff --git a/src/vnm_mad/remotes/802.1Q/clean b/src/vnm_mad/remotes/802.1Q/clean new file mode 100755 index 0000000000..44337c50d2 --- /dev/null +++ b/src/vnm_mad/remotes/802.1Q/clean @@ -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 \ No newline at end of file diff --git a/src/vnm_mad/remotes/802.1Q/post b/src/vnm_mad/remotes/802.1Q/post new file mode 100755 index 0000000000..44337c50d2 --- /dev/null +++ b/src/vnm_mad/remotes/802.1Q/post @@ -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 \ No newline at end of file diff --git a/src/vnm_mad/remotes/802.1Q/pre b/src/vnm_mad/remotes/802.1Q/pre new file mode 100755 index 0000000000..c7ce885d28 --- /dev/null +++ b/src/vnm_mad/remotes/802.1Q/pre @@ -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 diff --git a/src/vnm_mad/remotes/OpenNebulaNetwork.rb b/src/vnm_mad/remotes/OpenNebulaNetwork.rb index c837e88214..fc49236d73 100644 --- a/src/vnm_mad/remotes/OpenNebulaNetwork.rb +++ b/src/vnm_mad/remotes/OpenNebulaNetwork.rb @@ -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 diff --git a/src/vnm_mad/remotes/dummy/clean b/src/vnm_mad/remotes/dummy/clean new file mode 100755 index 0000000000..44337c50d2 --- /dev/null +++ b/src/vnm_mad/remotes/dummy/clean @@ -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 \ No newline at end of file diff --git a/src/vnm_mad/remotes/dummy/post b/src/vnm_mad/remotes/dummy/post new file mode 100755 index 0000000000..44337c50d2 --- /dev/null +++ b/src/vnm_mad/remotes/dummy/post @@ -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 \ No newline at end of file diff --git a/src/vnm_mad/remotes/dummy/pre b/src/vnm_mad/remotes/dummy/pre new file mode 100755 index 0000000000..44337c50d2 --- /dev/null +++ b/src/vnm_mad/remotes/dummy/pre @@ -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 \ No newline at end of file diff --git a/src/vnm_mad/remotes/ebtables/Ebtables.rb b/src/vnm_mad/remotes/ebtables/Ebtables.rb index 71f9bb1e8e..860a56fb0a 100644 --- a/src/vnm_mad/remotes/ebtables/Ebtables.rb +++ b/src/vnm_mad/remotes/ebtables/Ebtables.rb @@ -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 diff --git a/src/vnm_mad/remotes/802.1Q/hm-vlan b/src/vnm_mad/remotes/ebtables/clean similarity index 89% rename from src/vnm_mad/remotes/802.1Q/hm-vlan rename to src/vnm_mad/remotes/ebtables/clean index 63f1dc53e1..0aaefc7e02 100755 --- a/src/vnm_mad/remotes/802.1Q/hm-vlan +++ b/src/vnm_mad/remotes/ebtables/clean @@ -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 diff --git a/src/vnm_mad/remotes/ebtables/ebtables-vlan b/src/vnm_mad/remotes/ebtables/post similarity index 80% rename from src/vnm_mad/remotes/ebtables/ebtables-vlan rename to src/vnm_mad/remotes/ebtables/post index d4e72abe34..e69f291c26 100755 --- a/src/vnm_mad/remotes/ebtables/ebtables-vlan +++ b/src/vnm_mad/remotes/ebtables/post @@ -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 diff --git a/src/vnm_mad/remotes/ebtables/pre b/src/vnm_mad/remotes/ebtables/pre new file mode 100755 index 0000000000..44337c50d2 --- /dev/null +++ b/src/vnm_mad/remotes/ebtables/pre @@ -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 \ No newline at end of file diff --git a/src/vnm_mad/remotes/ovswtich/OpenvSwitch.rb b/src/vnm_mad/remotes/ovswtich/OpenvSwitch.rb index 2ba84ca1ea..fdbf91c21e 100644 --- a/src/vnm_mad/remotes/ovswtich/OpenvSwitch.rb +++ b/src/vnm_mad/remotes/ovswtich/OpenvSwitch.rb @@ -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 diff --git a/src/vnm_mad/remotes/ovswtich/clean b/src/vnm_mad/remotes/ovswtich/clean new file mode 100755 index 0000000000..44337c50d2 --- /dev/null +++ b/src/vnm_mad/remotes/ovswtich/clean @@ -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 \ No newline at end of file diff --git a/src/vnm_mad/remotes/ovswtich/openvswitch-vlan b/src/vnm_mad/remotes/ovswtich/post similarity index 90% rename from src/vnm_mad/remotes/ovswtich/openvswitch-vlan rename to src/vnm_mad/remotes/ovswtich/post index 1cd64fcf1b..5a1bb54a76 100755 --- a/src/vnm_mad/remotes/ovswtich/openvswitch-vlan +++ b/src/vnm_mad/remotes/ovswtich/post @@ -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() diff --git a/src/vnm_mad/remotes/ovswtich/pre b/src/vnm_mad/remotes/ovswtich/pre new file mode 100755 index 0000000000..44337c50d2 --- /dev/null +++ b/src/vnm_mad/remotes/ovswtich/pre @@ -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 \ No newline at end of file