I can't figure out where JsonReader and JsonWriter come from. I know that
they must exist, because I (and others) have used ovsdbmonitor before, but
I can't find them now.
Switch to using ovs.json, which is part of Open vSwitch so we know that
it exists. At the same time, we have to start translating the Unicode
strings that ovs.json outputs into standard Python strings; otherwise
the "twisted conch" ssh implementation craps out because it tries to
concatenate this Unicode string with a standard string that contains
non-ASCII characters.
+# Copyright (c) 2011 Nicira Networks.
# Copyright (c) 2010 Citrix Systems, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# Copyright (c) 2010 Citrix Systems, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
from OVEStandard import *
from OVELogger import *
from OVEStandard import *
from OVELogger import *
+import ovs.json
+
+def str_recursive(x):
+ t = type(x)
+ if t == unicode:
+ return str(x)
+ elif t == list:
+ return [str_recursive(_) for _ in x]
+ elif t == dict:
+ out = {}
+ for k,v in x.iteritems():
+ out[str_recursive(k)] = str_recursive(v)
+ return out
+ else:
+ return x
class OVEConfig(QtCore.QObject):
instance = None
class OVEConfig(QtCore.QObject):
instance = None
def saveConfig(self):
settings = QtCore.QSettings()
def saveConfig(self):
settings = QtCore.QSettings()
- settings.setValue('config/hosts', QVariant(json.JsonWriter().write(self.hosts)))
+ settings.setValue('config/hosts', QVariant(ovs.json.to_string((self.hosts))))
settings.setValue('config/logTraffic', QVariant(self.logTraffic))
settings.setValue('config/truncateUuids', QVariant(self.truncateUuids))
settings.setValue('config/logTraffic', QVariant(self.logTraffic))
settings.setValue('config/truncateUuids', QVariant(self.truncateUuids))
- settings.setValue('config/ssgList', QVariant(json.JsonWriter().write(self.ssgList)))
+ settings.setValue('config/ssgList', QVariant(ovs.json.to_string(self.ssgList)))
settings.sync()
self.emitUpdated()
settings.sync()
self.emitUpdated()
def loadConfig(self):
settings = QtCore.QSettings()
jsonText = unicode(settings.value('config/hosts', QVariant('[]')).toString())
def loadConfig(self):
settings = QtCore.QSettings()
jsonText = unicode(settings.value('config/hosts', QVariant('[]')).toString())
- self.hosts = json.JsonReader().read(str(jsonText))
+ self.hosts = str_recursive(ovs.json.from_string(str(jsonText)))
self.logTraffic = settings.value('config/logTraffic', QVariant(False)).toBool()
self.truncateUuids = settings.value('config/truncateUuids', QVariant(False)).toBool()
jsonText = unicode(settings.value('config/ssgList', QVariant('[]')).toString())
self.logTraffic = settings.value('config/logTraffic', QVariant(False)).toBool()
self.truncateUuids = settings.value('config/truncateUuids', QVariant(False)).toBool()
jsonText = unicode(settings.value('config/ssgList', QVariant('[]')).toString())
- self.ssgList = json.JsonReader().read(str(jsonText))
+ self.ssgList = ovs.json.from_string(str(jsonText))
if len(self.ssgList) == 0:
self.ssgList = [
r'in_port0000',
if len(self.ssgList) == 0:
self.ssgList = [
r'in_port0000',
+# Copyright (c) 2011 Nicira Networks.
# Copyright (c) 2010 Citrix Systems, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# Copyright (c) 2010 Citrix Systems, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
from OVEStandard import *
from OVEConfig import *
from OVELogger import *
from OVEStandard import *
from OVEConfig import *
from OVELogger import *
# This sequence installs the qt4reactor before twisted gets a chance to install its reactor
import qt4reactor
# This sequence installs the qt4reactor before twisted gets a chance to install its reactor
import qt4reactor
if self.commandType == 'JSON':
try:
# Decode the JSON data, to confirm that we have all of the data
if self.commandType == 'JSON':
try:
# Decode the JSON data, to confirm that we have all of the data
- self._jsonValues = json.read(str(self._data)) # FIXME: Should handle unicode
+ self._jsonValues = ovs.json.from_string(str(self._data)) # FIXME: Should handle unicode
self.sendResult()
except:
pass # Wait for more data
self.sendResult()
except:
pass # Wait for more data
+# Copyright (c) 2011 Nicira Networks.
# Copyright (c) 2010 Citrix Systems, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# Copyright (c) 2010 Citrix Systems, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
globalForcePySide = False
try:
globalForcePySide = False
try:
- print('+++ Python JSON module is required\n')
+ print('+++ OVS JSON module is required\n')