2
0
mirror of https://github.com/openvswitch/ovs synced 2025-10-29 15:28:56 +00:00

xenserver: Allow use first class datamodel field for controller IP

Starting in XenServer 5.6.0, a "vswitch_controller" key is available to
store the controller's IP address in the "pool" table of XAPI.  Older
versions must still use the "vSwitchController" key in "other_config".

Based on commits 37fee7 and 0ebd737 from the xs5.7 branch written by
Ian Campbell.
This commit is contained in:
Justin Pettit
2010-04-09 08:10:34 -07:00
parent a7de953d18
commit 8085488086
2 changed files with 27 additions and 10 deletions

View File

@@ -47,6 +47,11 @@ def update(session, args):
raise XenAPIPlugin.Failure("MORE_THAN_ONE_POOL_FOR_HOST", []) raise XenAPIPlugin.Failure("MORE_THAN_ONE_POOL_FOR_HOST", [])
pool = session.xenapi.pool.get_record(pools[0]) pool = session.xenapi.pool.get_record(pools[0])
try: try:
try:
controller = pool["vswitch_controller"]
except KeyError:
# On systems older than XenServer 5.6.0, we needed to store
# the key in "other_config".
controller = pool["other_config"]["vSwitchController"] controller = pool["other_config"]["vSwitchController"]
except KeyError, e: except KeyError, e:
controller = "" controller = ""

View File

@@ -99,9 +99,13 @@ class VSwitchControllerDialogue(Dialogue):
self.hostsInPool = 0 self.hostsInPool = 0
self.hostsUpdated = 0 self.hostsUpdated = 0
self.xs_version = data.host.software_version.product_version('')
pool = data.GetPoolForThisHost() pool = data.GetPoolForThisHost()
if pool is not None: if pool is not None:
if self.xs_version == "5.5.0":
self.controller = pool.get("other_config", {}).get("vSwitchController", "") self.controller = pool.get("other_config", {}).get("vSwitchController", "")
else:
self.controller = pool.get("vswitch_controller", "")
else: else:
self.controller = "" self.controller = ""
@@ -222,14 +226,15 @@ class VSwitchControllerDialogue(Dialogue):
def SetController(self, ip): def SetController(self, ip):
self.hostsInPool = 0 self.hostsInPool = 0
self.hostsUpdated = 0 self.hostsUpdated = 0
Task.Sync(lambda s: self._modifyPoolConfig(s, "vSwitchController", ip)) Task.Sync(lambda s: self._modifyPoolConfig(s, ip or ""))
# Should be done asynchronously, maybe with an external script? # Should be done asynchronously, maybe with an external script?
Task.Sync(lambda s: self._updateActiveServers(s)) Task.Sync(lambda s: self._updateActiveServers(s))
def _modifyPoolConfig(self, session, key, value): def _modifyPoolConfig(self, session, value):
"""Modify pool configuration. """Modify pool configuration.
If value == None then delete key, otherwise set key to value.""" If value == "" then delete configuration, otherwise set to value.
"""
pools = session.xenapi.pool.get_all() pools = session.xenapi.pool.get_all()
# We assume there is only ever one pool... # We assume there is only ever one pool...
if len(pools) == 0: if len(pools) == 0:
@@ -238,9 +243,13 @@ class VSwitchControllerDialogue(Dialogue):
if len(pools) > 1: if len(pools) > 1:
XSLogFatal(Lang("More than one pool for host.")) XSLogFatal(Lang("More than one pool for host."))
return return
if self.xs_version == "5.5.0":
key = "vSwitchController"
session.xenapi.pool.remove_from_other_config(pools[0], key) session.xenapi.pool.remove_from_other_config(pools[0], key)
if value != None: if value != None:
session.xenapi.pool.add_to_other_config(pools[0], key, value) session.xenapi.pool.add_to_other_config(pools[0], key, value)
else:
session.xenapi.pool.set_vswitch_controller(value)
Data.Inst().Update() Data.Inst().Update()
def _updateActiveServers(self, session): def _updateActiveServers(self, session):
@@ -265,6 +274,7 @@ class XSFeatureVSwitch:
@classmethod @classmethod
def StatusUpdateHandler(cls, inPane): def StatusUpdateHandler(cls, inPane):
data = Data.Inst() data = Data.Inst()
xs_version = data.host.software_version.product_version('')
inPane.AddTitleField(Lang("Open vSwitch")) inPane.AddTitleField(Lang("Open vSwitch"))
@@ -277,7 +287,10 @@ class XSFeatureVSwitch:
pool = data.GetPoolForThisHost() pool = data.GetPoolForThisHost()
if pool is not None: if pool is not None:
if (xs_version == "5.5.0"):
dbController = pool.get("other_config", {}).get("vSwitchController", "") dbController = pool.get("other_config", {}).get("vSwitchController", "")
else:
dbController = pool.get("vswitch_controller", "")
else: else:
dbController = "" dbController = ""
@@ -300,7 +313,6 @@ class XSFeatureVSwitch:
VSwitchService.Inst("openvswitch", "ovsdb-server").status()) VSwitchService.Inst("openvswitch", "ovsdb-server").status())
# Only XenServer 5.5.0 runs ovs-brcompatd # Only XenServer 5.5.0 runs ovs-brcompatd
xs_version = data.host.software_version.product_version('')
if (xs_version == "5.5.0"): if (xs_version == "5.5.0"):
inPane.AddStatusField(Lang("ovs-brcompatd status", 20), inPane.AddStatusField(Lang("ovs-brcompatd status", 20),
VSwitchService.Inst("openvswitch", "ovs-brcompatd").status()) VSwitchService.Inst("openvswitch", "ovs-brcompatd").status())