cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ka...@apache.org
Subject git commit: updated refs/heads/master to a16b707
Date Mon, 27 May 2013 07:30:48 GMT
Updated Branches:
  refs/heads/master 6758d727a -> a16b70725


CLOUDSTACK-2327: make cloud-setup-agent ovs aware

Ovs brcompat will be obsolete, so if network.bridge.type was
set to openvswitch, we'll use ovs command explicitly.

Signed-off-by: Hiroaki KAWAI <kawai@stratosphere.co.jp>


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/a16b7072
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/a16b7072
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/a16b7072

Branch: refs/heads/master
Commit: a16b707250fde01f24c9ab6f11189b630dd70962
Parents: 6758d72
Author: Hiroaki KAWAI <kawai@stratosphere.co.jp>
Authored: Thu May 23 20:15:35 2013 +0900
Committer: Hiroaki KAWAI <kawai@stratosphere.co.jp>
Committed: Mon May 27 16:30:32 2013 +0900

----------------------------------------------------------------------
 agent/bindir/cloud-setup-agent.in      |    5 ++-
 python/lib/cloudutils/globalEnv.py     |    2 +
 python/lib/cloudutils/networkConfig.py |   14 +++++-
 python/lib/cloudutils/serviceConfig.py |   66 +++++++++++++++++++++-----
 4 files changed, 70 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a16b7072/agent/bindir/cloud-setup-agent.in
----------------------------------------------------------------------
diff --git a/agent/bindir/cloud-setup-agent.in b/agent/bindir/cloud-setup-agent.in
index 5e2ba09..d6f481d 100755
--- a/agent/bindir/cloud-setup-agent.in
+++ b/agent/bindir/cloud-setup-agent.in
@@ -95,6 +95,9 @@ if __name__ == '__main__':
     parser.add_option("--prvNic", dest="prvNic", help="Private traffic interface")
     parser.add_option("--guestNic", dest="guestNic", help="Guest traffic interface")
 
+    old_config = configFileOps("@AGENTSYSCONFDIR@/agent.properties")
+    glbEnv.bridgeType = old_config.getEntry("network.bridge.type").lower()
+
     (options, args) = parser.parse_args()
     if options.auto is None:
         userInputs = getUserInputs()
@@ -104,7 +107,7 @@ if __name__ == '__main__':
         glbEnv.pod = userInputs[3]
         glbEnv.cluster = userInputs[4]
         #generate UUID
-        glbEnv.uuid = configFileOps("@AGENTSYSCONFDIR@/agent.properties").getEntry("guid")
+        glbEnv.uuid = old_config.getEntry("guid")
         if glbEnv.uuid == "":
             glbEnv.uuid = bash("uuidgen").getStdout()
     else:

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a16b7072/python/lib/cloudutils/globalEnv.py
----------------------------------------------------------------------
diff --git a/python/lib/cloudutils/globalEnv.py b/python/lib/cloudutils/globalEnv.py
index 94d981f..867aa17 100644
--- a/python/lib/cloudutils/globalEnv.py
+++ b/python/lib/cloudutils/globalEnv.py
@@ -40,3 +40,5 @@ class globalEnv:
         self.privateNet = "cloudbr0"
         #distribution
         self.distribution = None
+        # bridgeType
+        self.bridgeType = "native"

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a16b7072/python/lib/cloudutils/networkConfig.py
----------------------------------------------------------------------
diff --git a/python/lib/cloudutils/networkConfig.py b/python/lib/cloudutils/networkConfig.py
index b6b729a..9e456e9 100644
--- a/python/lib/cloudutils/networkConfig.py
+++ b/python/lib/cloudutils/networkConfig.py
@@ -19,6 +19,7 @@ from cloudException import CloudRuntimeException, CloudInternalException
 import logging
 import os
 import re
+import subprocess
 
 class networkConfig:
     class devInfo:
@@ -85,15 +86,22 @@ class networkConfig:
 
     @staticmethod
     def isNetworkDev(devName):
-        return os.path.exists("/sys/class/net/%s"%devName)
+        return os.path.exists("/sys/class/net/%s" % devName)
 
     @staticmethod
     def isBridgePort(devName):
-        return os.path.exists("/sys/class/net/%s/brport"%devName)
+        return os.path.exists("/sys/class/net/%s/brport" % devName)
     
     @staticmethod
     def isBridge(devName):
-        return os.path.exists("/sys/class/net/%s/bridge"%devName)
+        return os.path.exists("/sys/class/net/%s/bridge" % devName)
+
+    @staticmethod
+    def isOvsBridge(devName):
+        try:
+            return 0==subprocess.check_call(("ovs-vsctl", "br-exists", devName))
+        except subprocess.CalledProcessError:
+            return False
 
     @staticmethod
     def getBridge(devName):

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/a16b7072/python/lib/cloudutils/serviceConfig.py
----------------------------------------------------------------------
diff --git a/python/lib/cloudutils/serviceConfig.py b/python/lib/cloudutils/serviceConfig.py
index 1e32d0f..d129e00 100755
--- a/python/lib/cloudutils/serviceConfig.py
+++ b/python/lib/cloudutils/serviceConfig.py
@@ -94,8 +94,10 @@ class networkConfigBase:
             if not self.netcfg.isNetworkDev(br):
                 logging.debug("%s is not a network device, is it down?"%br)
                 return False
-            if not self.netcfg.isBridge(br):
-                raise CloudInternalException("%s is not a bridge"%br)
+            if self.syscfg.env.bridgeType == "openvswitch" and not self.netcfg.isOvsBridge(br):
+                raise CloudInternalException("%s is not an openvswitch bridge" % br)
+            if self.syscfg.env.bridgeType == "native" and not self.netcfg.isBridge(br):
+                raise CloudInternalException("%s is not a bridge" % br)
             preCfged = True
 
         return preCfged
@@ -153,11 +155,28 @@ class networkConfigUbuntu(serviceCfgBase, networkConfigBase):
             match = re.match("^ *iface %s.*"%dev.name, line)
             if match is not None:
                 dev.method = self.getNetworkMethod(match.group(0))
-                bridgeCfg = "\niface %s inet manual\n \
-                             auto %s\n \
-                             iface %s inet %s\n \
-                             bridge_ports %s\n"%(dev.name, br, br, dev.method, dev.name)
                 cfo = configFileOps(self.netCfgFile, self)
+                if self.syscfg.env.bridgeType == "openvswitch":
+                    bridgeCfg = "\n".join(("",
+                        "iface {device} inet manual",
+                        "  ovs_type OVSPort",
+                        "  ovs_bridge {bridge}",
+                        "",
+                        "auto {bridge}",
+                        "allow-ovs {bridge}",
+                        "iface {bridge} inet {device_method}",
+                        "  ovs_type OVSBridge",
+                        "  ovs_ports {device}",
+                        "")).format(bridge=br, device=dev.name, device_method=dev.method)
+                    cfo.replace_line("^ *auto %s.*" % dev.name,
+                        "allow-{bridge} {device}".format(bridge=br, device=dev.name))
+                elif self.syscfg.env.bridgeType == "native":
+                    bridgeCfg = "\niface %s inet manual\n \
+                                 auto %s\n \
+                                 iface %s inet %s\n \
+                                 bridge_ports %s\n"%(dev.name, br, br, dev.method, dev.name)
+                else:
+                    raise CloudInternalException("Unknown network.bridge.type %s" % self.syscfg.env.bridgeType)
                 cfo.replace_line("^ *iface %s.*"%dev.name, bridgeCfg)
 
     def addDev(self, br, dev):
@@ -193,8 +212,9 @@ class networkConfigUbuntu(serviceCfgBase, networkConfigBase):
                 self.syscfg.svo.stopService("network-manager")
                 self.syscfg.svo.disableService("network-manager")
 
-            if not bash("ifup %s"%self.brName).isSuccess():
-                raise CloudInternalException("Can't start network:%s"%self.brName, bash.getErrMsg(self))
+            ifup_op = bash("ifup %s"%self.brName)
+            if not ifup_op.isSuccess():
+                raise CloudInternalException("Can't start network:%s %s" % (self.brName,
ifup_op.getErrMsg()))
 
             self.syscfg.env.nics.append(self.brName)
             self.syscfg.env.nics.append(self.brName)
@@ -222,8 +242,8 @@ class networkConfigRedhat(serviceCfgBase, networkConfigBase):
         networkConfigBase.__init__(self, syscfg)
 
     def writeToCfgFile(self, brName, dev):
-        self.devCfgFile = "/etc/sysconfig/network-scripts/ifcfg-%s"%dev.name
-        self.brCfgFile = "/etc/sysconfig/network-scripts/ifcfg-%s"%brName
+        self.devCfgFile = "/etc/sysconfig/network-scripts/ifcfg-%s" % dev.name
+        self.brCfgFile = "/etc/sysconfig/network-scripts/ifcfg-%s" % brName
 
         isDevExist = os.path.exists(self.devCfgFile)
         isBrExist = os.path.exists(self.brCfgFile)
@@ -241,7 +261,7 @@ class networkConfigRedhat(serviceCfgBase, networkConfigBase):
 
 
     def addBridge(self, brName, dev):
-        bash("ifdown %s"%dev.name)
+        bash("ifdown %s" % dev.name)
 
         if not os.path.exists(self.brCfgFile):
             shutil.copy(self.devCfgFile, self.brCfgFile)
@@ -250,14 +270,34 @@ class networkConfigRedhat(serviceCfgBase, networkConfigBase):
         cfo = configFileOps(self.devCfgFile, self)
         cfo.addEntry("NM_CONTROLLED", "no")
         cfo.addEntry("ONBOOT", "yes")
-        cfo.addEntry("BRIDGE", brName)
+        if self.syscfg.env.bridgeType == "openvswitch":
+            if cfo.getEntry("IPADDR"):
+                cfo.rmEntry("IPADDR", cfo.getEntry("IPADDR"))
+            cfo.addEntry("DEVICETYPE", "ovs")
+            cfo.addEntry("TYPE", "OVSPort")
+            cfo.addEntry("OVS_BRIDGE", brName)
+        elif self.syscfg.env.bridgeType == "native":
+            cfo.addEntry("BRIDGE", brName)
+        else:
+            raise CloudInternalException("Unknown network.bridge.type %s" % self.syscfg.env.bridgeType)
         cfo.save()
 
         cfo = configFileOps(self.brCfgFile, self)
         cfo.addEntry("NM_CONTROLLED", "no")
         cfo.addEntry("ONBOOT", "yes")
         cfo.addEntry("DEVICE", brName)
-        cfo.addEntry("TYPE", "Bridge")
+        if self.syscfg.env.bridgeType == "openvswitch":
+            if cfo.getEntry("HWADDR"):
+                cfo.rmEntry("HWADDR", cfo.getEntry("HWADDR"))
+            if cfo.getEntry("UUID"):
+                cfo.rmEntry("UUID", cfo.getEntry("UUID"))
+            cfo.addEntry("STP", "yes")
+            cfo.addEntry("DEVICETYPE", "ovs")
+            cfo.addEntry("TYPE", "OVSBridge")
+        elif self.syscfg.env.bridgeType == "native":
+            cfo.addEntry("TYPE", "Bridge")
+        else:
+            raise CloudInternalException("Unknown network.bridge.type %s" % self.syscfg.env.bridgeType)
         cfo.save()
 
     def config(self):


Mime
View raw message