Skip to content

Commit 2a6ee4a

Browse files
committed
OVS: working with isolated networks on KVM
1 parent d162005 commit 2a6ee4a

File tree

3 files changed

+32
-16
lines changed

3 files changed

+32
-16
lines changed

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtOvsFetchInterfaceCommandWrapper.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package com.cloud.hypervisor.kvm.resource.wrapper;
2121

22+
import com.google.common.base.Strings;
2223
import org.apache.log4j.Logger;
2324

2425
import com.cloud.agent.api.Answer;
@@ -40,9 +41,18 @@ public Answer execute(final OvsFetchInterfaceCommand command, final LibvirtCompu
4041

4142
s_logger.debug("Will look for network with name-label:" + label);
4243
try {
43-
final String ipadd = Script.runSimpleBashScript("ifconfig " + label + " | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'");
44-
final String mask = Script.runSimpleBashScript("ifconfig " + label + " | grep 'inet addr:' | cut -d: -f4");
45-
final String mac = Script.runSimpleBashScript("ifconfig " + label + " | grep HWaddr | awk -F \" \" '{print $5}'");
44+
String ipadd = Script.runSimpleBashScript("ifconfig " + label + " | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}'");
45+
if (Strings.isNullOrEmpty(ipadd)) {
46+
ipadd = Script.runSimpleBashScript("ifconfig " + label + " | grep ' inet ' | awk '{ print $2}'");
47+
}
48+
String mask = Script.runSimpleBashScript("ifconfig " + label + " | grep 'inet addr:' | cut -d: -f4");
49+
if (Strings.isNullOrEmpty(mask)) {
50+
mask = Script.runSimpleBashScript("ifconfig " + label + " | grep ' inet ' | awk '{ print $4}'");
51+
}
52+
String mac = Script.runSimpleBashScript("ifconfig " + label + " | grep HWaddr | awk -F \" \" '{print $5}'");
53+
if (Strings.isNullOrEmpty(mac)) {
54+
mac = Script.runSimpleBashScript("ifconfig " + label + " | grep ' ether ' | awk '{ print $2}'");
55+
}
4656
return new OvsFetchInterfaceAnswer(command, true, "Interface " + label
4757
+ " retrieved successfully", ipadd, mask, mac);
4858

scripts/vm/network/vnet/cloudstack_pluginlib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def do_cmd(cmd):
104104
"%s (stderr output:%s)" % (ret_code, err))
105105
raise PluginError(err)
106106
output = proc.stdout.read()
107-
if output.endswith('\n'):
107+
if output.endswith(b'\n'):
108108
output = output[:-1]
109109
return output
110110

scripts/vm/network/vnet/ovstunnel.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/python
1+
#!/usr/bin/python3
22
# Licensed to the Apache Software Foundation (ASF) under one
33
# or more contributor license agreements. See the NOTICE file
44
# distributed with this work for additional information
@@ -37,7 +37,7 @@ def setup_ovs_bridge(bridge, key, cs_host_id):
3737
res = lib.check_switch()
3838
if res != "SUCCESS":
3939
#return "FAILURE:%s" % res
40-
return 'false'
40+
return 'false'
4141

4242
logging.debug("About to manually create the bridge:%s" % bridge)
4343
#set gre_key to bridge
@@ -50,19 +50,19 @@ def setup_ovs_bridge(bridge, key, cs_host_id):
5050
logging.debug("Bridge has been manually created:%s" % res)
5151
if res:
5252
# result = "FAILURE:%s" % res
53-
result = 'false'
53+
result = 'false'
5454
else:
5555
# Verify the bridge actually exists, with the gre_key properly set
5656
res = lib.do_cmd([lib.VSCTL_PATH, "get", "bridge",
5757
bridge, "other_config:gre_key"])
58-
if key in res:
58+
if key in str(res):
5959
# result = "SUCCESS:%s" % bridge
6060
result = 'true'
6161
else:
6262
# result = "FAILURE:%s" % res
6363
result = 'false'
6464

65-
lib.do_cmd([lib.VSCTL_PATH, "set", "bridge", bridge, "other_config:is-ovs-tun-network=True"])
65+
lib.do_cmd([lib.VSCTL_PATH, "set", "bridge", bridge, "other_config:is-ovs-tun-network=True"])
6666
#get list of hosts using this bridge
6767
conf_hosts = lib.do_cmd([lib.VSCTL_PATH, "get","bridge", bridge,"other_config:ovs-host-setup"])
6868
#add cs_host_id to list of hosts using this bridge
@@ -162,7 +162,7 @@ def create_tunnel(bridge, remote_ip, key, src_host, dst_host):
162162
wait = [lib.VSCTL_PATH, "--timeout=30", "wait-until", "bridge",
163163
bridge, "--", "get", "bridge", bridge, "name"]
164164
res = lib.do_cmd(wait)
165-
if bridge not in res:
165+
if bridge not in str(res):
166166
logging.debug("WARNING:Can't find bridge %s for creating " +
167167
"tunnel!" % bridge)
168168
# return "FAILURE:NO_BRIDGE"
@@ -185,7 +185,7 @@ def create_tunnel(bridge, remote_ip, key, src_host, dst_host):
185185
# Expecting python-style list as output
186186
iface_list = []
187187
if len(res) > 2:
188-
iface_list = res.strip()[1:-1].split(',')
188+
iface_list = res.strip()[1:-1].split(b',')
189189
if len(iface_list) != 1:
190190
logging.debug("WARNING: Unexpected output while verifying " +
191191
"port %s on bridge %s" % (name, bridge))
@@ -202,7 +202,7 @@ def create_tunnel(bridge, remote_ip, key, src_host, dst_host):
202202
key_validation = lib.do_cmd(verify_interface_key)
203203
ip_validation = lib.do_cmd(verify_interface_ip)
204204

205-
if not key in key_validation or not remote_ip in ip_validation:
205+
if not key in str(key_validation) or not remote_ip in str(ip_validation):
206206
logging.debug("WARNING: Unexpected output while verifying " +
207207
"interface %s on bridge %s" % (name, bridge))
208208
# return "FAILURE:VERIFY_INTERFACE_FAILED"
@@ -213,12 +213,18 @@ def create_tunnel(bridge, remote_ip, key, src_host, dst_host):
213213
iface_uuid, "ofport"]
214214
tun_ofport = lib.do_cmd(cmd_tun_ofport)
215215
# Ensure no trailing LF
216-
if tun_ofport.endswith('\n'):
216+
if tun_ofport.endswith(b'\n'):
217217
tun_ofport = tun_ofport[:-1]
218218

219-
ovs_tunnel_network = lib.do_cmd([lib.VSCTL_PATH, "get", "bridge", bridge, "other_config:is-ovs-tun-network"])
220-
ovs_vpc_distributed_vr_network = lib.do_cmd([lib.VSCTL_PATH, "get", "bridge", bridge,
221-
"other_config:is-ovs_vpc_distributed_vr_network"])
219+
try:
220+
ovs_tunnel_network = lib.do_cmd([lib.VSCTL_PATH, "get", "bridge", bridge, "other_config:is-ovs-tun-network"])
221+
except:
222+
ovs_tunnel_network = 'False'
223+
try:
224+
ovs_vpc_distributed_vr_network = lib.do_cmd([lib.VSCTL_PATH, "get", "bridge", bridge,
225+
"other_config:is-ovs_vpc_distributed_vr_network"])
226+
except:
227+
ovs_vpc_distributed_vr_network = 'False'
222228

223229
if ovs_tunnel_network == 'True':
224230
# add flow entryies for dropping broadcast coming in from gre tunnel

0 commit comments

Comments
 (0)