Revision da5374c5

View differences:

src/vnm_mad/remotes/lib/vnm_driver.rb
14 14
# limitations under the License.                                             #
15 15
#--------------------------------------------------------------------------- #
16 16

  
17
require 'shellwords'
18

  
17 19
################################################################################
18 20
# The VNMMAD module provides the basic abstraction to implement custom
19 21
# virtual network drivers. The VNMAD module includes:
......
68 70

  
69 71
        # Executes the given block on each NIC
70 72
        def process(&block)
71
            @vm.each_nic(block)
73
            blk = lambda do |nic|
74
                add_nic_conf(nic)
75

  
76
                block.call(nic)
77
            end
78

  
79
            @vm.each_nic(blk)
80
        end
81

  
82
        # Parse network configuration and add it to the nic
83
        def add_nic_conf(nic)
84
            default_conf = CONF || {}
85
            nic_conf = {}
86

  
87
            if nic[:conf]
88
                parse_options(nic[:conf]).each do |opt|
89
                    value = opt[:value]
90

  
91
                    case value.downcase
92
                    when 'true', 'yes'
93
                        value = true
94
                    when 'false', 'no'
95
                        value = false
96
                    end
97

  
98
                    nic_conf[opt[:option].to_sym] = value
99
                end
100
            end
101

  
102
            nic[:conf] = default_conf.merge(nic_conf)
72 103
        end
73 104

  
74 105
        # Returns a filter object based on the contents of the template
......
89 120

  
90 121
            return cmd_str
91 122
        end
123

  
124
        def parse_options(string)
125
            self.class.parse_options(string)
126
        end
127

  
128
        def self.parse_options(string)
129
            return [] if !string
130

  
131
            string.split(',').map do |op|
132
                m = op.match(/^\s*(?<option>[^=]+)\s*=\s*(?<value>.*?)\s*$/)
133

  
134
                if m
135
                    {
136
                        :option => Shellwords.escape(m['option']),
137
                        :value  => Shellwords.escape(m['value'])
138
                    }
139
                else
140
                    nil
141
                end
142
            end.flatten
143
        end
92 144
    end
93 145
end
src/vnm_mad/remotes/ovswitch/OpenvSwitch.rb
56 56
            end
57 57

  
58 58
            # Prevent ARP Cache Poisoning
59
            arp_cache_poisoning if CONF[:arp_cache_poisoning] && @nic[:ip]
59
            if @nic[:conf][:arp_cache_poisoning] && @nic[:ip]
60
                arp_cache_poisoning
61
            end
60 62

  
61 63
            # Prevent Mac-spoofing
62 64
            mac_spoofing if nic[:filter_mac_spoofing] =~ /yes/i
src/vnm_mad/remotes/vxlan/vxlan_driver.rb
43 43
    # This function creates and activate a VLAN device
44 44
    ############################################################################
45 45
    def create_vlan_dev
46
        mc  = VNMMAD::VNMNetwork::IPv4.to_i(CONF[:vxlan_mc]) + @nic[:vlan_id].to_i
46
        mc  = VNMMAD::VNMNetwork::IPv4.to_i(@nic[:conf][:vxlan_mc]) +
47
                @nic[:vlan_id].to_i
47 48
        mcs = VNMMAD::VNMNetwork::IPv4.to_s(mc)
48 49
        mtu = @nic[:mtu] ? "mtu #{@nic[:mtu]}" : ""
49
        ttl = CONF[:vxlan_ttl] ? "ttl #{CONF[:vxlan_ttl]}" : ""
50
        ttl = @nic[:conf][:vxlan_ttl] ? "ttl #{@nic[:conf][:vxlan_ttl]}" : ""
50 51

  
51 52
        OpenNebula.exec_and_log("#{command(:ip)} link add #{@nic[:vlan_dev]}"\
52 53
            " #{mtu} type vxlan id #{@nic[:vlan_id]} group #{mcs} #{ttl}"\

Also available in: Unified diff