Revision da5374c5 src/vnm_mad/remotes/lib/vnm_driver.rb
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 |
Also available in: Unified diff