1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-16 22:50:10 +03:00

Merge branch 'master' into feature-3748

This commit is contained in:
Daniel Molina 2015-06-23 18:21:46 +02:00
commit 3f74314808
6 changed files with 163 additions and 71 deletions

View File

@ -704,10 +704,12 @@ int Host::post_update_template(string& error)
string new_vm_mad;
string new_vn_mad;
erase_template_attribute("VCENTER_PASSWORD", vcenter_password);
get_template_attribute("VCENTER_PASSWORD", vcenter_password);
if (!vcenter_password.empty())
if (!vcenter_password.empty() && vcenter_password.size() <= 22)
{
erase_template_attribute("VCENTER_PASSWORD", vcenter_password);
Nebula& nd = Nebula::instance();
string one_key;
string * encrypted;

View File

@ -1 +0,0 @@
../fw/clean

View File

@ -0,0 +1,36 @@
#!/usr/bin/env ruby
# -------------------------------------------------------------------------- #
# Copyright 2002-2015, OpenNebula Project (OpenNebula.org), C12G Labs #
# #
# 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 'vnmmad'
require 'vlan_tag_driver'
template64 = ARGV[0]
begin
hm = VLANTagDriver.from_base64(template64)
hm.deactivate
filter_driver = VNMMAD::VNMDriver.filter_driver(template64)
filter_driver.deactivate
rescue Exception => e
OpenNebula.log_error(e.message)
OpenNebula.log_error(e.backtrace)
exit 1
end

View File

@ -30,10 +30,10 @@ class VLANTagDriver < VNMMAD::VLANDriver
XPATH_FILTER = "TEMPLATE/NIC[VLAN='YES']"
############################################################################
# Creatges the driver device operations are not locked
# Create driver device operations are locked
############################################################################
def initialize(vm, deploy_id = nil, hypervisor = nil)
@locking = false
@locking = true
super(vm, XPATH_FILTER, deploy_id, hypervisor)
end
@ -41,13 +41,13 @@ class VLANTagDriver < VNMMAD::VLANDriver
############################################################################
# This function creates and activate a VLAN device
############################################################################
def create_vlan_dev(options)
mtu = options[:mtu] ? "mtu #{options[:mtu]}" : ""
def create_vlan_dev
mtu = @nic[:mtu] ? "mtu #{@nic[:mtu]}" : ""
OpenNebula.exec_and_log("#{command(:ip)} link add link"\
" #{options[:phydev]} name #{options[:vlan_dev]} #{mtu} type vlan id"\
" #{options[:vlan_id]}")
" #{@nic[:phydev]} name #{@nic[:vlan_dev]} #{mtu} type vlan id"\
" #{@nic[:vlan_id]}")
OpenNebula.exec_and_log("#{command(:ip)} link set #{options[:vlan_dev]} up")
OpenNebula.exec_and_log("#{command(:ip)} link set #{@nic[:vlan_dev]} up")
end
end

View File

@ -24,32 +24,39 @@ module VNMMAD
class VLANDriver < VNMMAD::VNMDriver
def initialize(vm_tpl, xpath_filter, deploy_id = nil, hypervisor = nil)
super(vm_tpl, xpath_filter, deploy_id, hypervisor)
@locking = true
lock
@bridges = get_bridges
unlock
super(vm_tpl, xpath_filter, deploy_id, hypervisor)
end
# Activate the driver and creates bridges and tags devices as needed.
def activate
lock
options = Hash.new
@bridges = get_bridges
process do |nic|
@nic = nic
options.clear
next if @nic[:phydev].nil?
options[:bridge] = nic[:bridge]
options[:phydev] = nic[:phydev]
options[:vlan_id] = nic[:vlan_id]
options[:network_id] = nic[:network_id]
options[:mtu] = nic[:mtu]
# Get the name of the vlan device.
get_vlan_dev_name
return if options[:phydev].nil?
# Create the bridge.
create_bridge
set_up_vlan(options)
# Return if vlan device is already in the bridge.
next if @bridges[@nic[:bridge]].include? @nic[:vlan_dev]
# Create vlan device.
create_vlan_dev
# Add vlan device to the bridge.
OpenNebula.exec_and_log("#{command(:brctl)} addif"\
" #{@nic[:bridge]} #{@nic[:vlan_dev]}")
@bridges[@nic[:bridge]] << @nic[:vlan_dev]
end
unlock
@ -57,56 +64,69 @@ module VNMMAD
return 0
end
# Set ups the VLAN for the VMs.
# @param options [Hash] including
# - :phydev Physical Device to bind the VLAN traffic to
# - :bridge Name of the bridge to attach the VMs and VLAN dev to
# - :network_id
def set_up_vlan(options)
if options[:vlan_id].nil?
options[:vlan_id] = CONF[:start_vlan] + options[:network_id].to_i
end
options[:vlan_dev] = "#{options[:phydev]}.#{options[:vlan_id]}"
create_bridge(options[:bridge])
return if @bridges[options[:bridge]].include? options[:vlan_dev]
create_vlan_dev(options)
OpenNebula.exec_and_log("#{command(:brctl)} addif"\
" #{options[:bridge]} #{options[:vlan_dev]}")
@bridges[options[:bridge]] << options[:vlan_dev]
end
# This function needs to be implemented by any VLAN driver to
# create the VLAN device. The device MUST be set up by this function
# Options is a driver specific hash. It includes
# :vlan_dev the name for the VLAN device
# :phydev Physical Device to bind the VLAN traffic to
# :vlan_id the VLAN ID
# : additional driver specific parameters
def create_vlan_dev(options)
def create_vlan_dev
OpenNebula.log_error("create_vlan_dev function not implemented.")
exit -1
end
# Deactivate the driver and delete bridges and tags devices as needed.
def deactivate
lock
@bridges = get_bridges
attach_nic_id = @vm['TEMPLATE/NIC[ATTACH="YES"]/NIC_ID']
process do |nic|
next if attach_nic_id && attach_nic_id != nic[:nic_id]
@nic = nic
next if @nic[:phydev].nil?
# Get the name of the vlan device.
get_vlan_dev_name
# Return if the vlan device is not the only left device in the bridge.
next if @bridges[@nic[:bridge]].length > 1 or !@bridges[@nic[:bridge]].include? @nic[:vlan_dev]
# Delete the vlan device.
OpenNebula.exec_and_log("#{command(:ip)} link delete"\
" #{@nic[:vlan_dev]}")
@bridges[@nic[:bridge]].delete(@nic[:vlan_dev])
# Delete the bridge.
OpenNebula.exec_and_log("#{command(:ip)} link delete"\
" #{@nic[:bridge]}")
@bridges.delete(@nic[:bridge])
end
unlock
end
private
# Generate the name of the vlan device which will be added to the bridge.
def get_vlan_dev_name
if @nic[:vlan_id].nil?
@nic[:vlan_id] = CONF[:start_vlan] + @nic[:network_id].to_i
end
@nic[:vlan_dev] = "#{@nic[:phydev]}.#{@nic[:vlan_id]}"
end
# Creates a bridge if it does not exists, and brings it up.
# This function IS FINAL, exits if action cannot be completed
# @param bridge [String] the bridge name
def create_bridge(bridge)
return if @bridges.keys.include? bridge
def create_bridge
return if @bridges.keys.include? @nic[:bridge]
OpenNebula.exec_and_log("#{command(:brctl)} addbr #{bridge}")
OpenNebula.exec_and_log("#{command(:brctl)} addbr #{@nic[:bridge]}")
@bridges[bridge] = Array.new
@bridges[@nic[:bridge]] = Array.new
OpenNebula.exec_and_log("#{command(:ip)} link set #{bridge} up")
OpenNebula.exec_and_log("#{command(:ip)} link set #{@nic[:bridge]} up")
end
# Get hypervisor bridges

View File

@ -1 +0,0 @@
../fw/clean

36
src/vnm_mad/remotes/vxlan/clean Executable file
View File

@ -0,0 +1,36 @@
#!/usr/bin/env ruby
# -------------------------------------------------------------------------- #
# Copyright 2002-2015, OpenNebula Project (OpenNebula.org), C12G Labs #
# #
# 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 'vnmmad'
require 'vxlan_driver'
template64 = ARGV[0]
begin
hm = VXLANDriver.from_base64(template64)
hm.deactivate
filter_driver = VNMMAD::VNMDriver.filter_driver(template64)
filter_driver.deactivate
rescue Exception => e
OpenNebula.log_error(e.message)
OpenNebula.log_error(e.backtrace)
exit 1
end

View File

@ -30,10 +30,10 @@ class VXLANDriver < VNMMAD::VLANDriver
XPATH_FILTER = "TEMPLATE/NIC[VLAN='YES']"
############################################################################
# Creatges the driver device operations are not locked
# Create driver device operations are locked
############################################################################
def initialize(vm, deploy_id = nil, hypervisor = nil)
@locking = false
@locking = true
super(vm, XPATH_FILTER, deploy_id, hypervisor)
end
@ -41,15 +41,15 @@ class VXLANDriver < VNMMAD::VLANDriver
############################################################################
# This function creates and activate a VLAN device
############################################################################
def create_vlan_dev(options)
mc = VNMMAD::VNMNetwork::IPv4.to_i(CONF[:vxlan_mc]) + options[:vlan_id].to_i
def create_vlan_dev
mc = VNMMAD::VNMNetwork::IPv4.to_i(CONF[:vxlan_mc]) + @nic[:vlan_id].to_i
mcs = VNMMAD::VNMNetwork::IPv4.to_s(mc)
mtu = options[:mtu] ? "mtu #{options[:mtu]}" : ""
mtu = @nic[:mtu] ? "mtu #{@nic[:mtu]}" : ""
OpenNebula.exec_and_log("#{command(:ip)} link add #{options[:vlan_dev]}"\
" #{mtu} type vxlan id #{options[:vlan_id]} group #{mcs}"\
" dev #{options[:phydev]}")
OpenNebula.exec_and_log("#{command(:ip)} link add #{@nic[:vlan_dev]}"\
" #{mtu} type vxlan id #{@nic[:vlan_id]} group #{mcs}"\
" dev #{@nic[:phydev]}")
OpenNebula.exec_and_log("#{command(:ip)} link set #{options[:vlan_dev]} up")
OpenNebula.exec_and_log("#{command(:ip)} link set #{@nic[:vlan_dev]} up")
end
end